Increase fudge factor at the boundary between audio signal and silence.
[dcpomatic.git] / test / player_test.cc
index 2be525d8888cb9a59afb8e2997785343cf30895c..30b1a56dde93083ce6488f79e838142af2e953dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -48,6 +48,7 @@ using std::pair;
 using boost::shared_ptr;
 using boost::bind;
 using boost::optional;
+using namespace dcpomatic;
 
 static shared_ptr<AudioBuffers> accumulated;
 
@@ -219,10 +220,10 @@ BOOST_AUTO_TEST_CASE (player_seek_test)
        for (int i = 0; i < 10; ++i) {
                DCPTime t = DCPTime::from_frames (i, 24);
                butler->seek (t, true);
-               pair<shared_ptr<PlayerVideo>, DCPTime> video = butler->get_video();
+               pair<shared_ptr<PlayerVideo>, DCPTime> video = butler->get_video(true, 0);
                BOOST_CHECK_EQUAL(video.second.get(), t.get());
                write_image(video.first->image(bind(PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true), String::compose("build/test/player_seek_test_%1.png", i), "RGB");
-               /* This 0.011 is empirically chosen (hopefully) to accept changes in rendering between the reference and a test machine
+               /* This 0.055 is empirically chosen (hopefully) to accept changes in rendering between the reference and a test machine
                   (17.10 and 16.04 seem to anti-alias a little differently) but to reject gross errors e.g. missing fonts or missing
                   text altogether.
                */
@@ -252,10 +253,10 @@ BOOST_AUTO_TEST_CASE (player_seek_test2)
        for (int i = 0; i < 10; ++i) {
                DCPTime t = DCPTime::from_seconds(5) + DCPTime::from_frames (i, 24);
                butler->seek (t, true);
-               pair<shared_ptr<PlayerVideo>, DCPTime> video = butler->get_video();
+               pair<shared_ptr<PlayerVideo>, DCPTime> video = butler->get_video(true, 0);
                BOOST_CHECK_EQUAL(video.second.get(), t.get());
                write_image(video.first->image(bind(PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true), String::compose("build/test/player_seek_test2_%1.png", i), "RGB");
-               check_image(String::compose("test/data/player_seek_test2_%1.png", i), String::compose("build/test/player_seek_test2_%1.png", i), 0.011);
+               check_image(String::compose("test/data/player_seek_test2_%1.png", i), String::compose("build/test/player_seek_test2_%1.png", i), 0.055);
        }
 }
 
@@ -332,14 +333,28 @@ BOOST_AUTO_TEST_CASE (player_trim_crash)
        shared_ptr<Butler> butler (new Butler(player, AudioMapping(), 6, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true));
 
        /* Wait for the butler to fill */
-       dcpomatic_sleep (5);
+       dcpomatic_sleep_seconds (5);
 
        boon->set_trim_start (ContentTime::from_seconds(5));
 
        butler->seek (DCPTime(), true);
 
        /* Wait for the butler to refill */
-       dcpomatic_sleep (5);
+       dcpomatic_sleep_seconds (5);
 
        butler->rethrow ();
 }
+
+/** Test a crash when the gap between the last audio and the start of a silent period is more than 1 sample */
+BOOST_AUTO_TEST_CASE (player_silence_crash)
+{
+       shared_ptr<Film> film = new_test_film2 ("player_silence_crash");
+       shared_ptr<Content> sine = content_factory("test/data/impulse_train.wav").front();
+       film->examine_and_add_content (sine);
+       BOOST_REQUIRE (!wait_for_jobs());
+
+       sine->set_video_frame_rate (23.976);
+       film->write_metadata ();
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs());
+}