Various work on the audio code.
[dcpomatic.git] / src / lib / audio_decoder.cc
index 9801a68da90a0c1cb8d9505451742940adf205e6..6a795f3ac1906c3bf0979c9623424ae36a588e41 100644 (file)
@@ -22,6 +22,8 @@
 #include "audio_buffers.h"
 #include "audio_decoder_stream.h"
 #include "audio_content.h"
+#include "log.h"
+#include "compose.hpp"
 #include <boost/foreach.hpp>
 #include <iostream>
 
 using std::cout;
 using std::map;
 using boost::shared_ptr;
+using boost::optional;
 
 AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content, shared_ptr<Log> log)
-       : DecoderPart (parent)
+       : DecoderPart (parent, log)
 {
        BOOST_FOREACH (AudioStreamPtr i, content->streams ()) {
                _streams[i] = shared_ptr<AudioDecoderStream> (new AudioDecoderStream (content, i, parent, this, log));
        }
 }
 
-ContentAudio
-AudioDecoder::get (AudioStreamPtr stream, Frame frame, Frame length, bool accurate)
-{
-       return _streams[stream]->get (frame, length, accurate);
-}
-
 void
-AudioDecoder::give (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time)
+AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time)
 {
        if (ignore ()) {
                return;
@@ -81,23 +78,34 @@ AudioDecoder::give (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data,
 void
 AudioDecoder::flush ()
 {
-       for (map<AudioStreamPtr, shared_ptr<AudioDecoderStream> >::const_iterator i = _streams.begin(); i != _streams.end(); ++i) {
+       for (StreamMap::const_iterator i = _streams.begin(); i != _streams.end(); ++i) {
                i->second->flush ();
        }
 }
 
 void
-AudioDecoder::seek (ContentTime t, bool accurate)
+AudioDecoder::set_fast ()
 {
-       for (map<AudioStreamPtr, shared_ptr<AudioDecoderStream> >::const_iterator i = _streams.begin(); i != _streams.end(); ++i) {
-               i->second->seek (t, accurate);
+       for (StreamMap::const_iterator i = _streams.begin(); i != _streams.end(); ++i) {
+               i->second->set_fast ();
        }
 }
 
-void
-AudioDecoder::set_fast ()
+optional<ContentTime>
+AudioDecoder::position () const
 {
-       for (map<AudioStreamPtr, shared_ptr<AudioDecoderStream> >::const_iterator i = _streams.begin(); i != _streams.end(); ++i) {
-               i->second->set_fast ();
+       optional<ContentTime> p;
+       for (map<AudioStreamPtr, ContentTime>::const_iterator i = _positions.begin(); i != _positions.end(); ++i) {
+               if (!p || i->second < *p) {
+                       p = i->second;
+               }
        }
+
+       return p;
+}
+
+void
+AudioDecoder::set_position (AudioStreamPtr stream, ContentTime time)
+{
+       _positions[stream] = time;
 }