From b20c4b11abff0bd57dab03174070ec8571bbe4d5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 22 Feb 2017 13:40:17 +0000 Subject: [PATCH] Fix pull timing; fix units of ReelWriter::total_written_audio_frames. --- src/lib/player.cc | 26 +++++++++++--------------- src/lib/player.h | 14 ++++++++++++++ src/lib/reel_writer.cc | 2 +- src/lib/transcoder.cc | 1 + src/lib/writer.cc | 5 ++--- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/lib/player.cc b/src/lib/player.cc index 7b1b08250..eeeef2cb3 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -548,24 +548,14 @@ Player::pass () /* Emit any audio that is ready */ - optional earliest_audio; - BOOST_FOREACH (shared_ptr i, _pieces) { - if (i->decoder->audio) { - DCPTime t = i->content->position() - + DCPTime (i->decoder->audio->position(), i->frc) - + DCPTime::from_seconds (i->content->audio->delay() / 1000.0); - - if (t < DCPTime()) { - t = DCPTime(); - } - - if (!earliest_audio || t < *earliest_audio) { - earliest_audio = t; - } + DCPTime pull_from = _playlist->length (); + for (map::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) { + if (!i->second.piece->done && i->second.last_push_end < pull_from) { + pull_from = i->second.last_push_end; } } - pair, DCPTime> audio = _audio_merger.pull (earliest_audio.get_value_or(DCPTime())); + pair, DCPTime> audio = _audio_merger.pull (pull_from); if (audio.first->frames() > 0) { DCPOMATIC_ASSERT (audio.second >= _last_audio_time); DCPTime t = _last_audio_time; @@ -751,6 +741,12 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a } _audio_merger.push (content_audio.audio, time); + + if (_stream_states.find (stream) == _stream_states.end ()) { + _stream_states[stream] = StreamState (piece, time); + } else { + _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate()); + } } void diff --git a/src/lib/player.h b/src/lib/player.h index c891ee85c..69149d039 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -140,6 +140,20 @@ private: AudioMerger _audio_merger; DCPTime _last_audio_time; + class StreamState { + public: + StreamState () {} + + StreamState (boost::shared_ptr p, DCPTime l) + : piece(p) + , last_push_end(l) + {} + + boost::shared_ptr piece; + DCPTime last_push_end; + }; + std::map _stream_states; + std::list > _subtitles; boost::shared_ptr _audio_processor; diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 5dd9f5d25..e008bf631 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -480,7 +480,7 @@ ReelWriter::write (shared_ptr audio) _sound_asset_writer->write (audio->data(), audio->frames()); } - ++_total_written_audio_frames; + _total_written_audio_frames += audio->frames (); } void diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index de2fb1d33..e2bbca98e 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -115,6 +115,7 @@ Transcoder::video (shared_ptr data, DCPTime time) void Transcoder::audio (shared_ptr data, DCPTime time) { + cout << "tx receives " << data->frames() << " @ " << to_string(time) << "\n"; _writer->write (data); shared_ptr job = _job.lock (); diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 88925cbbd..74e5e3ec0 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -229,7 +229,7 @@ Writer::fake_write (Frame frame, Eyes eyes) _empty_condition.notify_all (); } -/** Write one video frame's worth of audio frames to the DCP. +/** Write some audio frames to the DCP. * @param audio Audio data or 0 if there is no audio to be written here (i.e. it is referenced). * This method is not thread safe. */ @@ -243,8 +243,7 @@ Writer::write (shared_ptr audio) _audio_reel->write (audio); - /* written is in video frames, not audio frames */ - if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->video_frame_rate())) { + if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->audio_frame_rate())) { ++_audio_reel; } } -- 2.30.2