2 Copyright (C) 2012-2017 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 /* Set up _positions so that we have one for each stream */
40 BOOST_FOREACH (AudioStreamPtr i, content->streams ()) {
46 AudioDecoder::emit (AudioStreamPtr stream, shared_ptr<const AudioBuffers> data, ContentTime time)
52 if (_positions[stream] == 0) {
53 /* This is the first data we have received since initialisation or seek. Set
54 the position based on the ContentTime that was given. After this first time
55 we just count samples, as it seems that ContentTimes are unreliable from
56 FFmpegDecoder (not quite continuous; perhaps due to some rounding error).
58 _positions[stream] = time.frames_round (stream->frame_rate ());
61 Data (stream, ContentAudio (data, _positions[stream]));
62 _positions[stream] += data->frames();
66 AudioDecoder::position () const
68 optional<ContentTime> p;
69 for (map<AudioStreamPtr, Frame>::const_iterator i = _positions.begin(); i != _positions.end(); ++i) {
70 ContentTime const ct = ContentTime::from_frames (i->second, i->first->frame_rate ());
76 return p.get_value_or(ContentTime());
82 for (map<AudioStreamPtr, Frame>::iterator i = _positions.begin(); i != _positions.end(); ++i) {