Switch PlayerVideo::always_rgb to a new ::force and use it in FFmpegFileEncoder.
[dcpomatic.git] / test / player_test.cc
index d3b6df6da6221d40750ae0f29e8ee1b588a4459b..0c9b6f21f0a8c81f55b0e13e383ccc5802b3148b 100644 (file)
@@ -31,7 +31,7 @@
 #include "lib/player.h"
 #include "lib/video_content.h"
 #include "lib/image_content.h"
-#include "lib/text_caption_file_content.h"
+#include "lib/string_text_file_content.h"
 #include "lib/content_factory.h"
 #include "lib/dcp_content.h"
 #include "lib/text_content.h"
@@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE (player_interleave_test)
        film->examine_and_add_content (c);
        BOOST_REQUIRE (!wait_for_jobs ());
 
-       shared_ptr<TextCaptionFileContent> s (new TextCaptionFileContent (film, "test/data/subrip.srt"));
+       shared_ptr<StringTextFileContent> s (new StringTextFileContent (film, "test/data/subrip.srt"));
        film->examine_and_add_content (s);
        BOOST_REQUIRE (!wait_for_jobs ());
 
@@ -194,12 +194,6 @@ BOOST_AUTO_TEST_CASE (player_interleave_test)
        }
 }
 
-static void
-note_handler (dcp::NoteType, std::string)
-{
-
-}
-
 /** Test some seeks towards the start of a DCP with awkward subtitles; see mantis #1085
  *  and a number of others.  I thought this was a player seek bug but in fact it was
  *  caused by the subtitle starting just after the start of the video frame and hence
@@ -211,11 +205,11 @@ BOOST_AUTO_TEST_CASE (player_seek_test)
        shared_ptr<DCPContent> dcp (new DCPContent (film, private_data / "awkward_subs"));
        film->examine_and_add_content (dcp, true);
        BOOST_REQUIRE (!wait_for_jobs ());
-       dcp->subtitle->set_use (true);
+       dcp->only_text()->set_use (true);
 
        shared_ptr<Player> player (new Player (film, film->playlist()));
        player->set_fast ();
-       player->set_always_burn_subtitles (true);
+       player->set_always_burn_open_subtitles ();
        player->set_play_referenced ();
 
        shared_ptr<Butler> butler (new Butler (player, film->log(), AudioMapping(), 2));
@@ -226,7 +220,7 @@ BOOST_AUTO_TEST_CASE (player_seek_test)
                butler->seek (t, true);
                pair<shared_ptr<PlayerVideo>, DCPTime> video = butler->get_video();
                BOOST_CHECK_EQUAL(video.second.get(), t.get());
-               write_image(video.first->image(note_handler, PlayerVideo::always_rgb, false, true), String::compose("build/test/player_seek_test_%1.png", i), "RGB");
+               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
                   (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.
@@ -242,11 +236,11 @@ BOOST_AUTO_TEST_CASE (player_seek_test2)
        shared_ptr<DCPContent> dcp (new DCPContent (film, private_data / "awkward_subs2"));
        film->examine_and_add_content (dcp, true);
        BOOST_REQUIRE (!wait_for_jobs ());
-       dcp->subtitle->set_use (true);
+       dcp->only_text()->set_use (true);
 
        shared_ptr<Player> player (new Player (film, film->playlist()));
        player->set_fast ();
-       player->set_always_burn_subtitles (true);
+       player->set_always_burn_open_subtitles ();
        player->set_play_referenced ();
 
        shared_ptr<Butler> butler (new Butler (player, film->log(), AudioMapping(), 2));
@@ -259,7 +253,7 @@ BOOST_AUTO_TEST_CASE (player_seek_test2)
                butler->seek (t, true);
                pair<shared_ptr<PlayerVideo>, DCPTime> video = butler->get_video();
                BOOST_CHECK_EQUAL(video.second.get(), t.get());
-               write_image(video.first->image(note_handler, PlayerVideo::always_rgb, false, true), String::compose("build/test/player_seek_test2_%1.png", i), "RGB");
+               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);
        }
 }
@@ -282,3 +276,44 @@ BOOST_AUTO_TEST_CASE (player_trim_test)
        film->make_dcp ();
        BOOST_REQUIRE (!wait_for_jobs ());
 }
+
+struct Sub {
+       PlayerText text;
+       TextType type;
+       optional<DCPTextTrack> track;
+       DCPTimePeriod period;
+};
+
+static void
+store (list<Sub>* out, PlayerText text, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
+{
+       Sub s;
+       s.text = text;
+       s.type = type;
+       s.track = track;
+       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, _4));
+       while (!player->pass ()) {}
+
+       BOOST_CHECK_EQUAL (out.size(), 6);
+}