From: Carl Hetherington Date: Mon, 9 Oct 2017 22:04:36 +0000 (+0100) Subject: Fix logic of audio decoder positioning. X-Git-Tag: v2.11.25~2 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=660a286e004ca1ebd467f082947df007be4ef325 Fix logic of audio decoder positioning. --- diff --git a/src/lib/player.cc b/src/lib/player.cc index 11369b682..496153b0e 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -700,6 +700,9 @@ Player::video (weak_ptr wp, ContentVideo video) return true; } +/** @return Number of input frames that were `accepted'. This is the number of frames passed in + * unless some were discarded at the end of the block. + */ Frame Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_audio) { @@ -718,6 +721,12 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a /* And the end of this block in the DCP */ DCPTime end = time + DCPTime::from_frames(content_audio.audio->frames(), content->resampled_frame_rate()); + /* We consider frames trimmed off the beginning to nevertheless be `accepted'; it's only frames trimmed + off the end that are considered as discarded. This logic is necessary to ensure correct reel lengths, + although the precise details escape me at the moment. + */ + Frame accepted = content_audio.audio->frames(); + /* Remove anything that comes before the start or after the end of the content */ if (time < piece->content->position()) { pair, DCPTime> cut = discard_audio (content_audio.audio, time, piece->content->position()); @@ -738,6 +747,7 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a shared_ptr cut (new AudioBuffers (content_audio.audio->channels(), remaining_frames)); cut->copy_from (content_audio.audio.get(), remaining_frames, 0, 0); content_audio.audio = cut; + accepted = content_audio.audio->frames(); } DCPOMATIC_ASSERT (content_audio.audio->frames() > 0); @@ -765,7 +775,7 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a _audio_merger.push (content_audio.audio, time); DCPOMATIC_ASSERT (_stream_states.find (stream) != _stream_states.end ()); _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate()); - return content_audio.audio->frames(); + return accepted; } void diff --git a/test/torture_test.cc b/test/torture_test.cc index 8bf73974f..3736b3e65 100644 --- a/test/torture_test.cc +++ b/test/torture_test.cc @@ -39,8 +39,10 @@ #include #include #include +#include using std::list; +using std::cout; using boost::shared_ptr; using boost::dynamic_pointer_cast;