diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-02-22 13:40:17 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-04-19 23:04:32 +0100 |
| commit | b20c4b11abff0bd57dab03174070ec8571bbe4d5 (patch) | |
| tree | 305ac5e9e346a644743348173caefc7422fe179f /src/lib | |
| parent | 8edc349253daf5eb0d9ceb75f467cdbbc668f27a (diff) | |
Fix pull timing; fix units of ReelWriter::total_written_audio_frames.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/player.cc | 26 | ||||
| -rw-r--r-- | src/lib/player.h | 14 | ||||
| -rw-r--r-- | src/lib/reel_writer.cc | 2 | ||||
| -rw-r--r-- | src/lib/transcoder.cc | 1 | ||||
| -rw-r--r-- | 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<DCPTime> earliest_audio; - BOOST_FOREACH (shared_ptr<Piece> 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<AudioStreamPtr, StreamState>::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<shared_ptr<AudioBuffers>, DCPTime> audio = _audio_merger.pull (earliest_audio.get_value_or(DCPTime())); + pair<shared_ptr<AudioBuffers>, 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<Piece> 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<Piece> p, DCPTime l) + : piece(p) + , last_push_end(l) + {} + + boost::shared_ptr<Piece> piece; + DCPTime last_push_end; + }; + std::map<AudioStreamPtr, StreamState> _stream_states; + std::list<std::pair<PlayerSubtitles, DCPTimePeriod> > _subtitles; boost::shared_ptr<AudioProcessor> _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<const AudioBuffers> 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<PlayerVideo> data, DCPTime time) void Transcoder::audio (shared_ptr<AudioBuffers> data, DCPTime time) { + cout << "tx receives " << data->frames() << " @ " << to_string(time) << "\n"; _writer->write (data); shared_ptr<Job> 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<const AudioBuffers> 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; } } |
