Fix logic of audio decoder positioning.
authorCarl Hetherington <cth@carlh.net>
Mon, 9 Oct 2017 22:04:36 +0000 (23:04 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 9 Oct 2017 22:04:36 +0000 (23:04 +0100)
src/lib/player.cc
test/torture_test.cc

index 11369b682b97879e692b3b415b70978440f8841c..496153b0e445d001a416236c0ef57de10d057302 100644 (file)
@@ -700,6 +700,9 @@ Player::video (weak_ptr<Piece> 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<Piece> wp, AudioStreamPtr stream, ContentAudio content_audio)
 {
@@ -718,6 +721,12 @@ Player::audio (weak_ptr<Piece> 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<shared_ptr<AudioBuffers>, DCPTime> cut = discard_audio (content_audio.audio, time, piece->content->position());
@@ -738,6 +747,7 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
                shared_ptr<AudioBuffers> 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<Piece> 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
index 8bf73974f6c0f8e08b4e95f6dd2d102c59e60a16..3736b3e65c2bff132c6b4c8996fe8fb0587a0a26 100644 (file)
 #include <dcp/mono_picture_frame.h>
 #include <dcp/openjpeg_image.h>
 #include <boost/test/unit_test.hpp>
+#include <iostream>
 
 using std::list;
+using std::cout;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;