Add support for ignoring everything except text in the player.
authorCarl Hetherington <cth@carlh.net>
Thu, 26 Jul 2018 14:07:09 +0000 (15:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 26 Jul 2018 14:07:09 +0000 (15:07 +0100)
src/lib/player.cc
src/lib/player.h
test/player_test.cc

index 8b2ade1dc74b49510828695a80e274b1391b2282..790d9a7188d1ec4a3995fc24be8a777ee52f1b0a 100644 (file)
@@ -89,6 +89,7 @@ Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> 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 = 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<TextDecoder> 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
index 223db86b3d442e7cd7540d0c60442d1e426570bc..3d774e1d93630cc7a32e56bee752d25dd9d690e9 100644 (file)
@@ -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;
index 7cc846affec8bc344776f736ff6c49fa4defcab7..605f3bddd1a0fc9207c24a7e5c0ef03064cfa316 100644 (file)
@@ -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<Sub>* 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> film = new_test_film2 ("player_ignore_video_and_audio_test");
+       shared_ptr<Content> ff = content_factory(film, private_data / "boon_telly.mkv").front();
+       film->examine_and_add_content (ff);
+       shared_ptr<Content> 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> player (new Player(film, film->playlist()));
+       player->set_ignore_video ();
+       player->set_ignore_audio ();
+
+       list<Sub> out;
+       player->Text.connect (bind (&store, &out, _1, _2, _3));
+       while (!player->pass ()) {}
+
+       BOOST_CHECK_EQUAL (out.size(), 6);
+}