Add a load of explicit keywords.
[dcpomatic.git] / src / lib / audio_merger.h
index c9026b93eb99aedf131f0e68db54b148c839ee9f..dbc0c869103b44d69b5bbe301e9134bcdb752f02 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
+/** @file  src/audio_merger.h
+ *  @brief AudioMerger class.
+ */
+
 #include "audio_buffers.h"
 #include "dcpomatic_time.h"
 #include "util.h"
 
+/** @class AudioMerger.
+ *  @brief A class that can merge audio data from many sources.
+ */
 class AudioMerger
 {
 public:
-       AudioMerger (int channels, int frame_rate);
+       explicit AudioMerger (int frame_rate);
 
-       /** Pull audio up to a given time; after this call, no more data can be pushed
-        *  before the specified time.
-        */
-       std::pair<boost::shared_ptr<AudioBuffers>, DCPTime> pull (DCPTime time);
+       std::list<std::pair<boost::shared_ptr<AudioBuffers>, DCPTime> > pull (DCPTime time);
        void push (boost::shared_ptr<const AudioBuffers> audio, DCPTime time);
+       void clear ();
 
 private:
-       boost::shared_ptr<AudioBuffers> _buffers;
-       DCPTime _last_pull;
+       Frame frames (DCPTime t) const;
+
+       class Buffer
+       {
+       public:
+               /** @param c Channels
+                *  @param f Frames
+                *  @param t Time
+                *  @param r Frame rate.
+                */
+               Buffer (int c, int32_t f, DCPTime t, int r)
+                       : audio (new AudioBuffers (c, f))
+                       , time (t)
+                       , frame_rate (r)
+               {}
+
+               Buffer (boost::shared_ptr<AudioBuffers> a, DCPTime t, int r)
+                       : audio (a)
+                       , time (t)
+                       , frame_rate (r)
+               {}
+
+               boost::shared_ptr<AudioBuffers> audio;
+               DCPTime time;
+               int frame_rate;
+
+               DCPTimePeriod period () const {
+                       return DCPTimePeriod (time, time + DCPTime::from_frames (audio->frames(), frame_rate));
+               }
+       };
+
+       class BufferComparator
+       {
+       public:
+               bool operator() (AudioMerger::Buffer const & a, AudioMerger::Buffer const & b)
+               {
+                       return a.time < b.time;
+               }
+       };
+
+       std::list<Buffer> _buffers;
        int _frame_rate;
 };