X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Faudio_decoder.cc;h=b0d0cc22f87802de3f34162b44e1deb7deee1546;hb=0758d834992f0adb8aa8d4d9908a64ce8708f05c;hp=ade11cc3290ab0dcbb3d50628cad8689fe1aa034;hpb=49deab5be257f3a11f5b053224f4a3218fad8da3;p=dcpomatic.git diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc index ade11cc32..404c85466 100644 --- a/src/lib/audio_decoder.cc +++ b/src/lib/audio_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2016 Carl Hetherington 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 @@ -19,27 +19,84 @@ #include "audio_decoder.h" #include "audio_buffers.h" -#include "exceptions.h" -#include "log.h" +#include "audio_decoder_stream.h" +#include "audio_content.h" +#include +#include #include "i18n.h" -using std::stringstream; -using std::list; -using std::pair; using std::cout; -using boost::optional; +using std::map; using boost::shared_ptr; -AudioDecoder::AudioDecoder (shared_ptr f) - : Decoder (f) - , _audio_position (0) +AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr content, bool fast, shared_ptr log) + : _ignore (false) + , _fast (fast) { + BOOST_FOREACH (AudioStreamPtr i, content->streams ()) { + _streams[i] = shared_ptr (new AudioDecoderStream (content, i, parent, 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 data, ContentTime time) +{ + if (_ignore) { + return; + } + + if (_streams.find (stream) == _streams.end ()) { + + /* This method can be called with an unknown stream during the following sequence: + - Add KDM to some DCP content. + - Content gets re-examined. + - SingleStreamAudioContent::take_from_audio_examiner creates a new stream. + - Some content property change signal is delivered so Player::Changed is emitted. + - Film viewer to re-gets the frame. + - Player calls DCPDecoder pass which calls this method on the new stream. + + At this point the AudioDecoder does not know about the new stream. + + Then + - Some other property change signal is delivered which marks the player's pieces invalid. + - Film viewer re-gets again. + - Everything is OK. + + In this situation it is fine for us to silently drop the audio. + */ + + return; + } + + _streams[stream]->audio (data, time); +} + +void +AudioDecoder::flush () +{ + for (map >::const_iterator i = _streams.begin(); i != _streams.end(); ++i) { + i->second->flush (); + } +} + +void +AudioDecoder::seek (ContentTime t, bool accurate) +{ + for (map >::const_iterator i = _streams.begin(); i != _streams.end(); ++i) { + i->second->seek (t, accurate); + } +} + +/** Set this decoder never to produce any data */ void -AudioDecoder::audio (shared_ptr data, AudioContent::Frame frame) +AudioDecoder::set_ignore () { - Audio (data, frame); - _audio_position = frame + data->frames (); + _ignore = true; }