Fix length of player output so it can be either the film's length or playlist's lengt...
authorCarl Hetherington <cth@carlh.net>
Wed, 15 Apr 2020 14:17:01 +0000 (16:17 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 Apr 2020 14:17:01 +0000 (16:17 +0200)
20 files changed:
src/lib/analyse_audio_job.cc
src/lib/empty.cc
src/lib/empty.h
src/lib/encoder.cc
src/lib/hints.cc
src/lib/player.cc
src/lib/player.h
src/tools/server_test.cc
src/wx/film_viewer.cc
test/butler_test.cc
test/dcp_decoder_test.cc
test/dcp_playback_test.cc
test/empty_test.cc
test/ffmpeg_audio_only_test.cc
test/ffmpeg_audio_test.cc
test/ffmpeg_decoder_sequential_test.cc
test/player_test.cc
test/time_calculation_test.cc
test/upmixer_a_test.cc
test/vf_test.cc

index ad28dcfd40892695f211c36f06b65188651b20e5..1fc09b9055d0a9155960fc5d8470657a076e5428 100644 (file)
@@ -107,7 +107,7 @@ AnalyseAudioJob::json_name () const
 void
 AnalyseAudioJob::run ()
 {
-       shared_ptr<Player> player (new Player (_film, _playlist));
+       shared_ptr<Player> player (new Player(_film, _playlist, _playlist->length(_film)));
        player->set_ignore_video ();
        player->set_ignore_text ();
        player->set_fast ();
index 71bf3aa956072d27aa9f50bd40f14e6a971395d8..c145c231bc02c1cef932282602aa7f8e0b27ce5b 100644 (file)
@@ -36,7 +36,7 @@ using boost::dynamic_pointer_cast;
 using boost::function;
 using namespace dcpomatic;
 
-Empty::Empty (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, function<bool (shared_ptr<const Content>)> part)
+Empty::Empty (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, function<bool (shared_ptr<const Content>)> part, DCPTime length)
 {
        list<DCPTimePeriod> full;
        BOOST_FOREACH (shared_ptr<Content> i, playlist->content()) {
@@ -45,7 +45,7 @@ Empty::Empty (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist,
                }
        }
 
-       _periods = subtract (DCPTimePeriod(DCPTime(), playlist->length(film)), coalesce(full));
+       _periods = subtract (DCPTimePeriod(DCPTime(), length), coalesce(full));
 
        if (!_periods.empty ()) {
                _position = _periods.front().from;
index abd6fdef003bb63a875c58465a241bda9d8ba822..2368c4491f10fbd401c415b4dde9896151485cae 100644 (file)
@@ -35,7 +35,7 @@ class Empty
 {
 public:
        Empty () {}
-       Empty (boost::shared_ptr<const Film> film, boost::shared_ptr<const Playlist> playlist, boost::function<bool (boost::shared_ptr<const Content>)> part);
+       Empty (boost::shared_ptr<const Film> film, boost::shared_ptr<const Playlist> playlist, boost::function<bool (boost::shared_ptr<const Content>)> part, dcpomatic::DCPTime length);
 
        dcpomatic::DCPTime position () const {
                return _position;
index 535389a94932b4ab4eb5b466f9dfaedb7831f293..b52507ed1ede219ccd9d6a50e1624c608011c687 100644 (file)
@@ -41,7 +41,7 @@ using boost::shared_ptr;
 Encoder::Encoder (shared_ptr<const Film> film, weak_ptr<Job> job)
        : _film (film)
        , _job (job)
-       , _player (new Player (film, film->playlist ()))
+       , _player (new Player(film, film->playlist(), film->length()))
 {
 
 }
index 3edceeee371bbe4978765bf0f96b2aef14dd5102..68cf82b8409faf4227f8078012003269f44a77f2 100644 (file)
@@ -259,7 +259,7 @@ Hints::thread ()
 
        emit (bind(boost::ref(Progress), _("Examining closed captions")));
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->set_ignore_video ();
        player->set_ignore_audio ();
        player->Text.connect (bind(&Hints::text, this, _1, _2, _4));
index 3202c1b85dab30e7b9a0721abf983211402a2aba..ab05d42ada522c25627cf5c7381bf13a07c649fb 100644 (file)
@@ -84,7 +84,7 @@ int const PlayerProperty::FILM_CONTAINER = 702;
 int const PlayerProperty::FILM_VIDEO_FRAME_RATE = 703;
 int const PlayerProperty::DCP_DECODE_REDUCTION = 704;
 
-Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist)
+Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, DCPTime playback_length)
        : _film (film)
        , _playlist (playlist)
        , _suspended (0)
@@ -97,6 +97,7 @@ Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist
        , _play_referenced (false)
        , _audio_merger (_film->audio_frame_rate())
        , _shuffler (0)
+       , _playback_length (playback_length)
 {
        _film_changed_connection = _film->Change.connect (bind (&Player::film_change, this, _1, _2));
        /* The butler must hear about this first, so since we are proxying this through to the butler we must
@@ -237,15 +238,12 @@ Player::setup_pieces_unlocked ()
                }
        }
 
-       _black = Empty (_film, _playlist, bind(&have_video, _1));
-       _silent = Empty (_film, _playlist, bind(&have_audio, _1));
+       _black = Empty (_film, _playlist, bind(&have_video, _1), _playback_length);
+       _silent = Empty (_film, _playlist, bind(&have_audio, _1), _playback_length);
 
        _last_video_time = DCPTime ();
        _last_video_eyes = EYES_BOTH;
        _last_audio_time = DCPTime ();
-
-       /* Cached value to save recalculating it on every ::pass */
-       _film_length = _film->length ();
 }
 
 void
@@ -566,15 +564,14 @@ bool
 Player::pass ()
 {
        boost::mutex::scoped_lock lm (_mutex);
-       DCPOMATIC_ASSERT (_film_length);
 
        if (_suspended) {
                /* We can't pass in this state */
                return false;
        }
 
-       if (*_film_length == DCPTime()) {
-               /* Special case of an empty Film; just give one black frame */
+       if (_playback_length == DCPTime()) {
+               /* Special; just give one black frame */
                emit_video (black_player_video_frame(EYES_BOTH), DCPTime());
                return true;
        }
@@ -680,7 +677,7 @@ Player::pass ()
        /* Work out the time before which the audio is definitely all here.  This is the earliest last_push_end of one
           of our streams, or the position of the _silent.
        */
-       DCPTime pull_to = *_film_length;
+       DCPTime pull_to = _playback_length;
        for (map<AudioStreamPtr, StreamState>::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) {
                if (!i->second.piece->done && i->second.last_push_end < pull_to) {
                        pull_to = i->second.last_push_end;
index c2911bf1087e19dae86257c37c14ce9c1a864b21..5a1b08ecf74fef3d9abb4a0747d5191f986641f5 100644 (file)
@@ -68,7 +68,7 @@ public:
 class Player : public boost::enable_shared_from_this<Player>, public boost::noncopyable
 {
 public:
-       Player (boost::shared_ptr<const Film>, boost::shared_ptr<const Playlist> playlist);
+       Player (boost::shared_ptr<const Film>, boost::shared_ptr<const Playlist> playlist, dcpomatic::DCPTime playback_length);
        ~Player ();
 
        bool pass ();
@@ -207,8 +207,7 @@ private:
        ActiveText _active_texts[TEXT_COUNT];
        boost::shared_ptr<AudioProcessor> _audio_processor;
 
-       /* Cached stuff */
-       boost::optional<dcpomatic::DCPTime> _film_length;
+       dcpomatic::DCPTime _playback_length;
 
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _playlist_change_connection;
index 1dc6fa6ca8ffe559f6d6d1f06c658fbd4aa176d2..4c410eadeccf4c2081411c6a8c8e96bebb33540b 100644 (file)
@@ -145,7 +145,7 @@ main (int argc, char* argv[])
                film.reset (new Film (film_dir));
                film->read_metadata ();
 
-               shared_ptr<Player> player (new Player (film, film->playlist ()));
+               shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
                player->Video.connect (bind (&process_video, _1));
                while (!player->pass ()) {}
        } catch (std::exception& e) {
index bff2df0ffaf0b697b6794127cb64d4fb7688e1c0..cac6e8c28aebbb4687d5c21b3164c419b129be9f 100644 (file)
@@ -164,7 +164,7 @@ FilmViewer::set_film (shared_ptr<Film> film)
        }
 
        try {
-               _player.reset (new Player (_film, _film->playlist ()));
+               _player.reset (new Player(_film, _film->playlist(), _film->length()));
                _player->set_fast ();
                if (_dcp_decode_reduction) {
                        _player->set_dcp_decode_reduction (_dcp_decode_reduction);
index 7aeba78f952e8d13c95d8c7ef6b7a46dc5364dbd..13efc31313d1af876141abb597232a991c443b75 100644 (file)
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE (butler_test1)
                map.set (i, i, 1);
        }
 
-       Butler butler (shared_ptr<Player>(new Player(film, film->playlist())), map, 6, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, false);
+       Butler butler (shared_ptr<Player>(new Player(film, film->playlist(), film->length())), map, 6, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, false);
 
        BOOST_CHECK (butler.get_video(true, 0).second == DCPTime());
        BOOST_CHECK (butler.get_video(true, 0).second == DCPTime::from_frames(1, 24));
index 32eed9354cfcd09c99e4bec11d61dd161fed3ecc..36df09834ad4f4c932ba65c8fa11736743e5c793 100644 (file)
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE (check_reuse_old_data_test)
        ov_content.reset (new DCPContent(ov->dir(ov->dcp_name(false))));
        test->examine_and_add_content (ov_content);
        BOOST_REQUIRE (!wait_for_jobs());
-       shared_ptr<Player> player (new Player(test, test->playlist()));
+       shared_ptr<Player> player (new Player(test, test->playlist(), test->length()));
 
        shared_ptr<DCPDecoder> decoder = boost::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
        BOOST_REQUIRE (decoder);
@@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE (check_reuse_old_data_test)
        shared_ptr<DCPContent> vf_content (new DCPContent(vf->dir(vf->dcp_name(false))));
        test->examine_and_add_content (vf_content);
        BOOST_REQUIRE (!wait_for_jobs());
-       player.reset (new Player(test, test->playlist()));
+       player.reset (new Player(test, test->playlist(), test->length()));
 
        decoder = boost::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
        BOOST_REQUIRE (decoder);
@@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE (check_reuse_old_data_test)
        shared_ptr<DCPContent> encrypted_content (new DCPContent(encrypted->dir(encrypted->dcp_name(false))));
        test->examine_and_add_content (encrypted_content);
        BOOST_REQUIRE (!wait_for_jobs());
-       player.reset (new Player(test, test->playlist()));
+       player.reset (new Player(test, test->playlist(), test->length()));
 
        decoder = boost::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
        BOOST_REQUIRE (decoder);
index 78785737548db4536da3e5ae5a2c1012de36bd39..e8d91648702907b7dec20e5c7c95d1c491e0d5f9 100644 (file)
@@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE (dcp_playback_test)
 
        shared_ptr<Butler> butler (
                new Butler(
-                       shared_ptr<Player>(new Player(film, film->playlist())),
+                       shared_ptr<Player>(new Player(film, film->playlist(), film->length())),
                        AudioMapping(6, 6),
                        6,
                        bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24),
index 1a4d03300bf5a81740f7d1f987bb917a053c40d8..029e83966b85be624a189ef009e523838fc33269 100644 (file)
@@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE (empty_test1)
        contentB->video->set_length (1);
        contentB->set_position (film, DCPTime::from_frames (7, vfr));
 
-       Empty black (film, film->playlist(), bind(&has_video, _1));
+       Empty black (film, film->playlist(), bind(&has_video, _1), film->playlist()->length(film));
        BOOST_REQUIRE_EQUAL (black._periods.size(), 2);
        list<dcpomatic::DCPTimePeriod>::const_iterator i = black._periods.begin();
        BOOST_CHECK (i->from == DCPTime::from_frames(0, vfr));
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE (empty_test2)
        contentB->video->set_length (1);
        contentB->set_position (film, DCPTime::from_frames(7, vfr));
 
-       Empty black (film, film->playlist(), bind(&has_video, _1));
+       Empty black (film, film->playlist(), bind(&has_video, _1), film->playlist()->length(film));
        BOOST_REQUIRE_EQUAL (black._periods.size(), 1);
        BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(3, vfr));
        BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
@@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE (empty_test3)
 
        shared_ptr<Playlist> playlist (new Playlist);
        playlist->add (film, contentB);
-       Empty black (film, playlist, bind(&has_video, _1));
+       Empty black (film, playlist, bind(&has_video, _1), playlist->length(film));
        BOOST_REQUIRE_EQUAL (black._periods.size(), 1);
        BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(0, vfr));
        BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
index a8a7184c4e264883b7de730afec4adc3cc4c073c..df32cadd49e89da85cf4af378d7e1f5b9cd3141b 100644 (file)
@@ -92,7 +92,7 @@ test (boost::filesystem::path file)
        ref_buffer_size = info.samplerate * info.channels;
        ref_buffer = new float[ref_buffer_size];
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
 
        player->Audio.connect (bind (&audio, _1, info.channels));
        while (!player->pass ()) {}
index 8e0fd92801d3b695ae96021954796f9f48621c38..7a9aaf3463d131c6e064a9f0bb1bdcf68c60cbd5 100644 (file)
@@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_test2)
        film->examine_and_add_content (content);
        BOOST_REQUIRE (!wait_for_jobs ());
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        while (!player->pass ()) {}
 }
 
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_test3)
        film->examine_and_add_content (content);
        BOOST_REQUIRE (!wait_for_jobs ());
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->set_fast ();
        while (!player->pass ()) {}
 }
index cf841bcabcbd8d6343ee3334f0845fea2543fac4..041d976fe38cb74b35af8b465b48d8f0602a5b39 100644 (file)
@@ -65,7 +65,7 @@ ffmpeg_decoder_sequential_test_one (boost::filesystem::path file, float fps, int
        film->examine_and_add_content (content);
        BOOST_REQUIRE (!wait_for_jobs());
        film->write_metadata ();
-       shared_ptr<Player> player (new Player (film, film->playlist()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
 
        BOOST_REQUIRE (content->video_frame_rate());
        BOOST_CHECK_CLOSE (content->video_frame_rate().get(), fps, 0.01);
index a242d620bbe35bf97f73d3f4f7dff6d5bed8ab83..378e0af9b3f8ff44f789465c3e3952e5399f6d43 100644 (file)
@@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE (player_silence_padding_test)
 
        accumulated.reset (new AudioBuffers (film->audio_channels(), 0));
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->Audio.connect (bind (&accumulate, _1, _2));
        while (!player->pass ()) {}
        BOOST_REQUIRE (accumulated->frames() >= 48000);
@@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE (player_subframe_test)
        /* Length should be rounded up from B's length to the next video frame */
        BOOST_CHECK (film->length() == DCPTime::from_frames(3 * 24 + 1, 24));
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->setup_pieces ();
        BOOST_REQUIRE_EQUAL (player->_black._periods.size(), 1);
        BOOST_CHECK (player->_black._periods.front() == DCPTimePeriod(DCPTime::from_frames(3 * 24, 24), DCPTime::from_frames(3 * 24 + 1, 24)));
@@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE (player_interleave_test)
        film->examine_and_add_content (s);
        BOOST_REQUIRE (!wait_for_jobs ());
 
-       shared_ptr<Player> player (new Player(film, film->playlist()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->Video.connect (bind (&video, _1, _2));
        player->Audio.connect (bind (&audio, _1, _2));
        video_frames = audio_frames = 0;
@@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE (player_seek_test)
        BOOST_REQUIRE (!wait_for_jobs ());
        dcp->only_text()->set_use (true);
 
-       shared_ptr<Player> player (new Player (film, film->playlist()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->set_fast ();
        player->set_always_burn_open_subtitles ();
        player->set_play_referenced ();
@@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE (player_seek_test2)
        BOOST_REQUIRE (!wait_for_jobs ());
        dcp->only_text()->set_use (true);
 
-       shared_ptr<Player> player (new Player (film, film->playlist()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->set_fast ();
        player->set_always_burn_open_subtitles ();
        player->set_play_referenced ();
@@ -310,7 +310,7 @@ BOOST_AUTO_TEST_CASE (player_ignore_video_and_audio_test)
        text->only_text()->set_type (TEXT_CLOSED_CAPTION);
        text->only_text()->set_use (true);
 
-       shared_ptr<Player> player (new Player(film, film->playlist()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->set_ignore_video ();
        player->set_ignore_audio ();
 
@@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE (player_trim_crash)
        film->examine_and_add_content (boon);
        BOOST_REQUIRE (!wait_for_jobs());
 
-       shared_ptr<Player> player (new Player(film, film->playlist()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->set_fast ();
        shared_ptr<Butler> butler (new Butler(player, AudioMapping(), 6, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true));
 
index 968138f96adb35be43578c83c99ef98fcbb8c9b6..f6412d9de5e2c014464edb4541569609837fd698 100644 (file)
@@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test1)
        film->set_sequence (false);
        film->add_content (content);
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
 
        /* Position 0, no trim, content rate = DCP rate */
        content->set_position (film, DCPTime());
@@ -396,7 +396,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test2)
        film->set_sequence (false);
        film->add_content (content);
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
 
        /* Position 0, no trim, content rate = DCP rate */
        content->set_position (film, DCPTime());
@@ -573,7 +573,7 @@ BOOST_AUTO_TEST_CASE (player_time_calculation_test3)
        film->set_sequence (false);
        film->add_content (content);
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
 
        /* Position 0, no trim, video/audio content rate = video/audio DCP rate */
        content->set_position (film, DCPTime());
index 545f081bacaf2c40c8a8bac15f196bb264cfdf7d..a00a77addcde806b56eb985a7d7e3a165fbffc23 100644 (file)
@@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE (upmixer_a_test)
        Ls = sf_open ("build/test/upmixer_a_test/Ls.wav", SFM_WRITE, &info);
        Rs = sf_open ("build/test/upmixer_a_test/Rs.wav", SFM_WRITE, &info);
 
-       shared_ptr<Player> player (new Player (film, film->playlist ()));
+       shared_ptr<Player> player (new Player(film, film->playlist(), film->length()));
        player->Audio.connect (bind (&write, _1, _2));
        while (!player->pass()) {}
 
index 8cbf7a3457da5cb74e57a1b82cab60e19d70ef70..35c32e603f4e1eba37fd3487dce9306087ee76a6 100644 (file)
@@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE (vf_test5)
        BOOST_REQUIRE (!wait_for_jobs());
 
        /* Check that the selected reel assets are right */
-       shared_ptr<Player> player (new Player(vf, vf->playlist()));
+       shared_ptr<Player> player (new Player(vf, vf->playlist(), vf->length()));
        list<ReferencedReelAsset> a = player->get_reel_assets();
        BOOST_REQUIRE_EQUAL (a.size(), 4);
        list<ReferencedReelAsset>::const_iterator i = a.begin();