2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "audio_decoder.h"
22 #include "audio_buffers.h"
23 #include "audio_content.h"
25 #include "compose.hpp"
26 #include <boost/foreach.hpp>
33 using boost::shared_ptr;
34 using boost::optional;
36 AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content, shared_ptr<Log> log)
37 : DecoderPart (parent, log)
39 BOOST_FOREACH (AudioStreamPtr i, content->streams ()) {
45 AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time)
51 if (_positions[stream] == 0) {
52 _positions[stream] = time.frames_round (stream->frame_rate ());
55 Data (stream, ContentAudio (data, _positions[stream]));
56 _positions[stream] += data->frames();
60 AudioDecoder::position () const
62 optional<ContentTime> p;
63 for (map<AudioStreamPtr, Frame>::const_iterator i = _positions.begin(); i != _positions.end(); ++i) {
64 ContentTime const ct = ContentTime::from_frames (i->second, i->first->frame_rate ());
70 return p.get_value_or(ContentTime());
76 for (map<AudioStreamPtr, Frame>::iterator i = _positions.begin(); i != _positions.end(); ++i) {