Fix Player::dcp_to_content_video with similar but not equal content/DCP frame rates.
authorCarl Hetherington <cth@carlh.net>
Thu, 27 Aug 2015 14:54:13 +0000 (15:54 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 27 Aug 2015 14:54:13 +0000 (15:54 +0100)
src/lib/audio_decoder_stream.cc
src/lib/player.cc
src/lib/transcoder.cc
test/time_calculation_test.cc

index 2f12af19821d5cfc571c775ac3f4fd111873a857..365be336fdc896f2ca925f33af49d12b7857d6d8 100644 (file)
@@ -62,7 +62,7 @@ AudioDecoderStream::get (Frame frame, Frame length, bool accurate)
 {
        shared_ptr<ContentAudio> dec;
 
-       _content->film()->log()->log (String::compose ("ADS has request for %1 %2", frame, length), Log::TYPE_DEBUG_DECODE);
+       _content->film()->log()->log (String::compose ("-> ADS has request for %1 %2", frame, length), Log::TYPE_DEBUG_DECODE);
 
        Frame const end = frame + length - 1;
 
index d2ef1a5fffa6a6d61a6b47e187bd743a291a4f7a..d6e142c5e810ffd8dd5ec359345d4f35acb2590f 100644 (file)
@@ -524,10 +524,16 @@ Player::dcp_to_content_video (shared_ptr<const Piece> piece, DCPTime t) const
        shared_ptr<const VideoContent> vc = dynamic_pointer_cast<const VideoContent> (piece->content);
        DCPTime s = t - piece->content->position ();
        s = min (piece->content->length_after_trim(), s);
-       /* We're returning a frame index here so we need to floor() the conversion since we want to know the frame
-          that contains t, I think
+       s = max (DCPTime(), s + DCPTime (piece->content->trim_start(), piece->frc));
+
+       /* It might seem more logical here to convert s to a ContentTime (using the FrameRateChange)
+          then convert that ContentTime to frames at the content's rate.  However this fails for
+          situations like content at 29.9978733fps, DCP at 30fps.  The accuracy of the Time type is not
+          enough to distinguish between the two with low values of time (e.g. 3200 in Time units).
+
+          Instead we convert the DCPTime using the DCP video rate then account for any skip/repeat.
        */
-       return max (ContentTime (), ContentTime (s, piece->frc) + piece->content->trim_start ()).frames_floor (vc->video_frame_rate ());
+       return s.frames_floor (piece->frc.dcp) / piece->frc.factor ();
 }
 
 DCPTime
index ad8e4ab9be7c43f834eac17be7d4486827f82c7f..27e35ac528b37f0609f915be2d6ffb15ae309a5c 100644 (file)
@@ -32,6 +32,7 @@
 #include "player.h"
 #include "job.h"
 #include "writer.h"
+#include "compose.hpp"
 #include "subtitle_content.h"
 #include <boost/signals2.hpp>
 #include <boost/foreach.hpp>
index 9f91be584b88c2e4b2ff06194329e58514f84a01..f11f0dc28f5213d1dbedc248e8bd31fc6472f421 100644 (file)
@@ -330,6 +330,21 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test1)
        BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (3.00)),  72);
        BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (4.50)), 144);
        BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime::from_seconds (9.75)), 396);
+
+       /* Position 0s, no trim, content rate 29.9978733, DCP rate 30 */
+       content->set_position (DCPTime::from_seconds (0));
+       content->set_trim_start (ContentTime::from_seconds (0));
+       content->set_video_frame_rate (29.9978733);
+       film->set_video_frame_rate (30);
+       player->setup_pieces ();
+       BOOST_REQUIRE_EQUAL (player->_pieces.size(), 1);
+       piece = player->_pieces.front ();
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime ()), 0);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (3200)), 1);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (6400)), 2);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (9600)), 3);
+       BOOST_CHECK_EQUAL (player->dcp_to_content_video (piece, DCPTime (12800)), 4);
+
 }
 
 /** Test Player::content_video_to_dcp */