Fix mistaken clamp to length_after_trim after adding trim_start.
authorCarl Hetherington <cth@carlh.net>
Fri, 24 Jul 2015 21:14:31 +0000 (22:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 24 Jul 2015 21:14:31 +0000 (22:14 +0100)
ChangeLog
src/lib/player.cc
src/lib/video_decoder.cc
test/time_calculation_test.cc

index 60f49027b1ba83bdd51cb955238d4f590a0b9d31..7687e265de6afa4fbd50aee1b624dbf10f682739 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-07-24  Carl Hetherington  <cth@carlh.net>
+
+       * Fix problems when using large start trims relative
+       to content length.
+
 2015-07-22  Carl Hetherington  <cth@carlh.net>
 
        * Use NR for rating an in ISDCF name if none is specified.
index a44d916d814dc2f58551c2b80ecf2203511e72db..e7348110759fbd61157e095215e4830fd8e8daae 100644 (file)
@@ -538,9 +538,9 @@ Player::content_video_to_dcp (shared_ptr<const Piece> piece, Frame f) const
 Frame
 Player::dcp_to_resampled_audio (shared_ptr<const Piece> piece, DCPTime t) const
 {
-       DCPTime s = t - piece->content->position () + DCPTime (piece->content->trim_start (), piece->frc);
-       s = max (DCPTime (), min (piece->content->length_after_trim(), s));
-       return s.frames (_film->audio_frame_rate ());
+       DCPTime s = t - piece->content->position ();
+       s = min (piece->content->length_after_trim(), s);
+       return max (DCPTime (), DCPTime (piece->content->trim_start (), piece->frc) + s).frames (_film->audio_frame_rate ());
 }
 
 ContentTime
index cdf8bc12afa954205353f98f106960b23ce478fe..944b1b695b1d708cb800acd8e73f392f1d6be438 100644 (file)
@@ -285,14 +285,11 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, Frame frame)
                to = to_push.front().frame;
        }
 
-       /* It has been known that this method receives frames out of order; at this
-          point I'm not sure why, but we'll just ignore them.
+       /* If we've pre-rolled on a seek we may now receive out-of-order frames
+          (frames before the last seek time) which we can just ignore.
        */
 
        if (from && to && from.get() > to.get()) {
-               _video_content->film()->log()->log (
-                       String::compose ("Ignoring out-of-order decoded frame %1 after %2", to.get(), from.get()), Log::TYPE_WARNING
-                       );
                return;
        }
 
index 2be49f629c32398597aa77b92908ef027eee8c5f..9f91be584b88c2e4b2ff06194329e58514f84a01 100644 (file)
@@ -562,7 +562,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
        piece = player->_pieces.front ();
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 0);
-       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),   0);
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (0.50)),      0);
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
@@ -596,8 +596,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 324000);
 
        /* Position 3s, 1.6s trim, content rate 24, DCP rate 25, both audio rates still 48k.
-          Since the DCP is faster, and resampled audio is at the DCP rate, our 1.6s trim in
-          content time corresponds to 1.6 * 24 * 48000 / 25 audio samples.
+          1s of content is 46080 samples after resampling.
        */
        content->set_position (DCPTime::from_seconds (3));
        content->set_trim_start (ContentTime::from_seconds (1.6));
@@ -748,4 +747,15 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (3.00)),  72000);
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (4.50)), 144000);
        BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime::from_seconds (9.75)), 396000);
+
+       /* Check with a large start trim */
+       content->set_position (DCPTime::from_seconds (0));
+       content->set_trim_start (ContentTime::from_seconds (54143));
+       content->set_video_frame_rate (24);
+       film->set_video_frame_rate (24);
+       stream->_frame_rate = 48000;
+       player->setup_pieces ();
+       BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
+       piece = player->_pieces.front ();
+       BOOST_CHECK_EQUAL (player->dcp_to_resampled_audio (piece, DCPTime ()), 54143L * 48000);
 }