From 53e1b97984f7e8c7bf1b16a9f3a333578545ec10 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 26 Jul 2018 15:07:09 +0100 Subject: [PATCH] Add support for ignoring everything except text in the player. --- src/lib/player.cc | 18 ++++++++++++++++++ src/lib/player.h | 2 ++ test/player_test.cc | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/lib/player.cc b/src/lib/player.cc index 8b2ade1dc..790d9a718 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -89,6 +89,7 @@ Player::Player (shared_ptr film, shared_ptr playlist , _playlist (playlist) , _have_valid_pieces (false) , _ignore_video (false) + , _ignore_audio (false) , _ignore_text (false) , _always_burn_open_subtitles (false) , _fast (false) @@ -126,6 +127,11 @@ Player::setup_pieces () continue; } + if (_ignore_video && _ignore_audio && i->text.empty()) { + /* We're only interested in text and this content has none */ + continue; + } + shared_ptr decoder = decoder_factory (i, _film->log(), _fast); FrameRateChange frc (i->active_video_frame_rate(), _film->video_frame_rate()); @@ -138,6 +144,10 @@ Player::setup_pieces () decoder->video->set_ignore (true); } + if (decoder->audio && _ignore_audio) { + decoder->audio->set_ignore (true); + } + if (_ignore_text) { BOOST_FOREACH (shared_ptr i, decoder->text) { i->set_ignore (true); @@ -437,6 +447,14 @@ void Player::set_ignore_video () { _ignore_video = true; + _have_valid_pieces = false; +} + +void +Player::set_ignore_audio () +{ + _ignore_audio = true; + _have_valid_pieces = false; } void diff --git a/src/lib/player.h b/src/lib/player.h index 223db86b3..3d774e1d9 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -78,6 +78,7 @@ public: void set_video_container_size (dcp::Size); void set_ignore_video (); + void set_ignore_audio (); void set_ignore_text (); void set_always_burn_open_subtitles (); void set_fast (); @@ -154,6 +155,7 @@ private: /** true if the player should ignore all video; i.e. never produce any */ bool _ignore_video; + bool _ignore_audio; /** true if the player should ignore all text; i.e. never produce any */ bool _ignore_text; bool _always_burn_open_subtitles; diff --git a/test/player_test.cc b/test/player_test.cc index 7cc846aff..605f3bddd 100644 --- a/test/player_test.cc +++ b/test/player_test.cc @@ -282,3 +282,42 @@ BOOST_AUTO_TEST_CASE (player_trim_test) film->make_dcp (); BOOST_REQUIRE (!wait_for_jobs ()); } + +struct Sub { + PlayerText text; + TextType type; + DCPTimePeriod period; +}; + +static void +store (list* out, PlayerText text, TextType type, DCPTimePeriod period) +{ + Sub s; + s.text = text; + s.type = type; + s.period = period; + out->push_back (s); +} + +/** Test ignoring both video and audio */ +BOOST_AUTO_TEST_CASE (player_ignore_video_and_audio_test) +{ + shared_ptr film = new_test_film2 ("player_ignore_video_and_audio_test"); + shared_ptr ff = content_factory(film, private_data / "boon_telly.mkv").front(); + film->examine_and_add_content (ff); + shared_ptr text = content_factory(film, "test/data/subrip.srt").front(); + film->examine_and_add_content (text); + BOOST_REQUIRE (!wait_for_jobs()); + text->only_text()->set_type (TEXT_CLOSED_CAPTION); + text->only_text()->set_use (true); + + shared_ptr player (new Player(film, film->playlist())); + player->set_ignore_video (); + player->set_ignore_audio (); + + list out; + player->Text.connect (bind (&store, &out, _1, _2, _3)); + while (!player->pass ()) {} + + BOOST_CHECK_EQUAL (out.size(), 6); +} -- 2.30.2