2 Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file test/player_test.cc
23 * @brief Test Player class.
24 * @ingroup selfcontained
28 #include "lib/audio_buffers.h"
29 #include "lib/audio_content.h"
30 #include "lib/butler.h"
31 #include "lib/compose.hpp"
32 #include "lib/config.h"
33 #include "lib/content_factory.h"
34 #include "lib/cross.h"
35 #include "lib/dcp_content.h"
36 #include "lib/dcp_content_type.h"
37 #include "lib/dcpomatic_log.h"
38 #include "lib/ffmpeg_content.h"
40 #include "lib/image_content.h"
41 #include "lib/image_png.h"
42 #include "lib/player.h"
43 #include "lib/ratio.h"
44 #include "lib/string_text_file_content.h"
45 #include "lib/text_content.h"
46 #include "lib/video_content.h"
48 #include <boost/test/unit_test.hpp>
49 #include <boost/algorithm/string.hpp>
55 using std::shared_ptr;
56 using std::make_shared;
58 using boost::optional;
59 #if BOOST_VERSION >= 106100
60 using namespace boost::placeholders;
62 using namespace dcpomatic;
65 static shared_ptr<AudioBuffers> accumulated;
69 accumulate (shared_ptr<AudioBuffers> audio, DCPTime)
71 BOOST_REQUIRE (accumulated);
72 accumulated->append (audio);
76 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
77 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
79 auto film = new_test_film ("player_silence_padding_test");
80 film->set_name ("player_silence_padding_test");
81 auto c = std::make_shared<FFmpegContent>("test/data/test.mp4");
82 film->set_container (Ratio::from_id ("185"));
83 film->set_audio_channels (6);
85 film->examine_and_add_content (c);
86 BOOST_REQUIRE (!wait_for_jobs());
88 accumulated = std::make_shared<AudioBuffers>(film->audio_channels(), 0);
90 Player player(film, Image::Alignment::COMPACT);
91 player.Audio.connect(bind(&accumulate, _1, _2));
92 while (!player.pass()) {}
93 BOOST_REQUIRE (accumulated->frames() >= 48000);
94 BOOST_CHECK_EQUAL (accumulated->channels(), film->audio_channels ());
96 for (int i = 0; i < 48000; ++i) {
97 for (int c = 0; c < accumulated->channels(); ++c) {
98 BOOST_CHECK_EQUAL (accumulated->data()[c][i], 0);
104 /* Test insertion of black frames between separate bits of video content */
105 BOOST_AUTO_TEST_CASE (player_black_fill_test)
107 auto film = new_test_film ("black_fill_test");
108 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
109 film->set_name ("black_fill_test");
110 film->set_container (Ratio::from_id ("185"));
111 film->set_sequence (false);
112 film->set_interop (false);
113 auto contentA = std::make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
114 auto contentB = std::make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
116 film->examine_and_add_content (contentA);
117 film->examine_and_add_content (contentB);
118 BOOST_REQUIRE (!wait_for_jobs());
120 contentA->video->set_length (3);
121 contentA->set_position (film, DCPTime::from_frames(2, film->video_frame_rate()));
122 contentA->video->set_custom_ratio (1.85);
123 contentB->video->set_length (1);
124 contentB->set_position (film, DCPTime::from_frames(7, film->video_frame_rate()));
125 contentB->video->set_custom_ratio (1.85);
127 make_and_verify_dcp (
130 dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
131 dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
134 boost::filesystem::path ref;
137 ref /= "black_fill_test";
139 boost::filesystem::path check;
142 check /= "black_fill_test";
143 check /= film->dcp_name();
145 /* This test is concerned with the image, so we'll ignore any
146 * differences in sound between the DCP and the reference to avoid test
147 * failures for unrelated reasons.
149 check_dcp(ref.string(), check.string(), true);
153 /** Check behaviour with an awkward playlist whose data does not end on a video frame start */
154 BOOST_AUTO_TEST_CASE (player_subframe_test)
156 auto film = new_test_film ("reels_test7");
157 film->set_name ("reels_test7");
158 film->set_container (Ratio::from_id("185"));
159 film->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
160 auto A = content_factory("test/data/flat_red.png")[0];
161 film->examine_and_add_content (A);
162 BOOST_REQUIRE (!wait_for_jobs());
163 auto B = content_factory("test/data/awkward_length.wav")[0];
164 film->examine_and_add_content (B);
165 BOOST_REQUIRE (!wait_for_jobs());
166 film->set_video_frame_rate (24);
167 A->video->set_length (3 * 24);
169 BOOST_CHECK (A->full_length(film) == DCPTime::from_frames(3 * 24, 24));
170 BOOST_CHECK (B->full_length(film) == DCPTime(289920));
171 /* Length should be rounded up from B's length to the next video frame */
172 BOOST_CHECK (film->length() == DCPTime::from_frames(3 * 24 + 1, 24));
174 Player player(film, Image::Alignment::COMPACT);
175 player.setup_pieces();
176 BOOST_REQUIRE_EQUAL(player._black._periods.size(), 1U);
177 BOOST_CHECK(player._black._periods.front() == DCPTimePeriod(DCPTime::from_frames(3 * 24, 24), DCPTime::from_frames(3 * 24 + 1, 24)));
178 BOOST_REQUIRE_EQUAL(player._silent._periods.size(), 1U);
179 BOOST_CHECK(player._silent._periods.front() == DCPTimePeriod(DCPTime(289920), DCPTime::from_frames(3 * 24 + 1, 24)));
183 static Frame video_frames;
184 static Frame audio_frames;
188 video (shared_ptr<PlayerVideo>, DCPTime)
194 audio (shared_ptr<AudioBuffers> audio, DCPTime)
196 audio_frames += audio->frames();
200 /** Check with a video-only file that the video and audio emissions happen more-or-less together */
201 BOOST_AUTO_TEST_CASE (player_interleave_test)
203 auto film = new_test_film ("ffmpeg_transcoder_basic_test_subs");
204 film->set_name ("ffmpeg_transcoder_basic_test");
205 film->set_container (Ratio::from_id ("185"));
206 film->set_audio_channels (6);
208 auto c = std::make_shared<FFmpegContent>("test/data/test.mp4");
209 film->examine_and_add_content (c);
210 BOOST_REQUIRE (!wait_for_jobs ());
212 auto s = std::make_shared<StringTextFileContent>("test/data/subrip.srt");
213 film->examine_and_add_content (s);
214 BOOST_REQUIRE (!wait_for_jobs ());
216 Player player(film, Image::Alignment::COMPACT);
217 player.Video.connect(bind(&video, _1, _2));
218 player.Audio.connect(bind(&audio, _1, _2));
219 video_frames = audio_frames = 0;
220 while (!player.pass()) {
221 BOOST_CHECK (abs(video_frames - (audio_frames / 2000)) <= 8);
226 /** Test some seeks towards the start of a DCP with awkward subtitles; see mantis #1085
227 * and a number of others. I thought this was a player seek bug but in fact it was
228 * caused by the subtitle starting just after the start of the video frame and hence
231 BOOST_AUTO_TEST_CASE (player_seek_test)
233 auto film = std::make_shared<Film>(optional<boost::filesystem::path>());
234 auto dcp = std::make_shared<DCPContent>(TestPaths::private_data() / "awkward_subs");
235 film->examine_and_add_content (dcp, true);
236 BOOST_REQUIRE (!wait_for_jobs ());
237 dcp->only_text()->set_use (true);
239 Player player(film, Image::Alignment::COMPACT);
241 player.set_always_burn_open_subtitles();
242 player.set_play_referenced();
244 auto butler = std::make_shared<Butler>(
245 film, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::DISABLED
248 for (int i = 0; i < 10; ++i) {
249 auto t = DCPTime::from_frames (i, 24);
250 butler->seek (t, true);
251 auto video = butler->get_video(Butler::Behaviour::BLOCKING, 0);
252 BOOST_CHECK_EQUAL(video.second.get(), t.get());
253 write_image(video.first->image(bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true), String::compose("build/test/player_seek_test_%1.png", i));
254 /* This 14.08 is empirically chosen (hopefully) to accept changes in rendering between the reference and a test machine
255 (17.10 and 16.04 seem to anti-alias a little differently) but to reject gross errors e.g. missing fonts or missing
258 check_image(TestPaths::private_data() / String::compose("player_seek_test_%1.png", i), String::compose("build/test/player_seek_test_%1.png", i), 14.08);
263 /** Test some more seeks towards the start of a DCP with awkward subtitles */
264 BOOST_AUTO_TEST_CASE (player_seek_test2)
266 auto film = std::make_shared<Film>(optional<boost::filesystem::path>());
267 auto dcp = std::make_shared<DCPContent>(TestPaths::private_data() / "awkward_subs2");
268 film->examine_and_add_content (dcp, true);
269 BOOST_REQUIRE (!wait_for_jobs ());
270 dcp->only_text()->set_use (true);
272 Player player(film, Image::Alignment::COMPACT);
274 player.set_always_burn_open_subtitles();
275 player.set_play_referenced();
277 auto butler = std::make_shared<Butler>
278 (film, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::DISABLED
281 butler->seek(DCPTime::from_seconds(5), true);
283 for (int i = 0; i < 10; ++i) {
284 auto t = DCPTime::from_seconds(5) + DCPTime::from_frames (i, 24);
285 butler->seek (t, true);
286 auto video = butler->get_video(Butler::Behaviour::BLOCKING, 0);
287 BOOST_CHECK_EQUAL(video.second.get(), t.get());
289 video.first->image(bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true), String::compose("build/test/player_seek_test2_%1.png", i)
291 check_image(TestPaths::private_data() / String::compose("player_seek_test2_%1.png", i), String::compose("build/test/player_seek_test2_%1.png", i), 14.08);
296 /** Test a bug when trimmed content follows other content */
297 BOOST_AUTO_TEST_CASE (player_trim_test)
299 auto film = new_test_film2 ("player_trim_test");
300 auto A = content_factory("test/data/flat_red.png")[0];
301 film->examine_and_add_content (A);
302 BOOST_REQUIRE (!wait_for_jobs ());
303 A->video->set_length (10 * 24);
304 auto B = content_factory("test/data/flat_red.png")[0];
305 film->examine_and_add_content (B);
306 BOOST_REQUIRE (!wait_for_jobs ());
307 B->video->set_length (10 * 24);
308 B->set_position (film, DCPTime::from_seconds(10));
309 B->set_trim_start(film, ContentTime::from_seconds(2));
311 make_and_verify_dcp (film);
318 optional<DCPTextTrack> track;
319 DCPTimePeriod period;
324 store (list<Sub>* out, PlayerText text, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
335 /** Test ignoring both video and audio */
336 BOOST_AUTO_TEST_CASE (player_ignore_video_and_audio_test)
338 auto film = new_test_film2 ("player_ignore_video_and_audio_test");
339 auto ff = content_factory(TestPaths::private_data() / "boon_telly.mkv")[0];
340 film->examine_and_add_content (ff);
341 auto text = content_factory("test/data/subrip.srt")[0];
342 film->examine_and_add_content (text);
343 BOOST_REQUIRE (!wait_for_jobs());
344 text->only_text()->set_type (TextType::CLOSED_CAPTION);
345 text->only_text()->set_use (true);
347 Player player(film, Image::Alignment::COMPACT);
348 player.set_ignore_video();
349 player.set_ignore_audio();
352 player.Text.connect(bind (&store, &out, _1, _2, _3, _4));
353 while (!player.pass()) {}
355 BOOST_CHECK_EQUAL (out.size(), 6U);
359 /** Trigger a crash due to the assertion failure in Player::emit_audio */
360 BOOST_AUTO_TEST_CASE (player_trim_crash)
362 auto film = new_test_film2 ("player_trim_crash");
363 auto boon = content_factory(TestPaths::private_data() / "boon_telly.mkv")[0];
364 film->examine_and_add_content (boon);
365 BOOST_REQUIRE (!wait_for_jobs());
367 Player player(film, Image::Alignment::COMPACT);
369 auto butler = std::make_shared<Butler>(
370 film, player, AudioMapping(), 6, bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::COMPACT, true, false, Butler::Audio::ENABLED
373 /* Wait for the butler to fill */
374 dcpomatic_sleep_seconds (5);
376 boon->set_trim_start(film, ContentTime::from_seconds(5));
378 butler->seek (DCPTime(), true);
380 /* Wait for the butler to refill */
381 dcpomatic_sleep_seconds (5);
387 /** Test a crash when the gap between the last audio and the start of a silent period is more than 1 sample */
388 BOOST_AUTO_TEST_CASE (player_silence_crash)
390 auto film = new_test_film2 ("player_silence_crash");
391 auto sine = content_factory("test/data/impulse_train.wav")[0];
392 film->examine_and_add_content (sine);
393 BOOST_REQUIRE (!wait_for_jobs());
395 sine->set_video_frame_rate(film, 23.976);
396 film->write_metadata ();
397 make_and_verify_dcp (film, {dcp::VerificationNote::Code::MISSING_CPL_METADATA});
401 /** Test a crash when processing a 3D DCP */
402 BOOST_AUTO_TEST_CASE (player_3d_test_1)
404 auto film = new_test_film2 ("player_3d_test_1a");
405 auto left = content_factory("test/data/flat_red.png")[0];
406 film->examine_and_add_content (left);
407 auto right = content_factory("test/data/flat_blue.png")[0];
408 film->examine_and_add_content (right);
409 BOOST_REQUIRE (!wait_for_jobs());
411 left->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
412 left->set_position (film, DCPTime());
413 right->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
414 right->set_position (film, DCPTime());
415 film->set_three_d (true);
417 make_and_verify_dcp (film);
419 auto dcp = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
420 auto film2 = new_test_film2 ("player_3d_test_1b", {dcp});
422 film2->set_three_d (true);
423 make_and_verify_dcp (film2);
427 /** Test a crash when processing a 3D DCP as content in a 2D project */
428 BOOST_AUTO_TEST_CASE (player_3d_test_2)
430 auto left = content_factory("test/data/flat_red.png")[0];
431 auto right = content_factory("test/data/flat_blue.png")[0];
432 auto film = new_test_film2 ("player_3d_test_2a", {left, right});
434 left->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
435 left->set_position (film, DCPTime());
436 right->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
437 right->set_position (film, DCPTime());
438 film->set_three_d (true);
440 make_and_verify_dcp (film);
442 auto dcp = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
443 auto film2 = new_test_film2 ("player_3d_test_2b", {dcp});
445 make_and_verify_dcp (film2);
449 /** Test a crash when there is video-only content at the end of the DCP and a frame-rate conversion is happening;
452 BOOST_AUTO_TEST_CASE (player_silence_at_end_crash)
454 /* 25fps DCP with some audio */
455 auto content1 = content_factory("test/data/flat_red.png")[0];
456 auto film1 = new_test_film2 ("player_silence_at_end_crash_1", {content1});
457 content1->video->set_length (25);
458 film1->set_video_frame_rate (25);
459 make_and_verify_dcp (film1);
461 /* Make another project importing this DCP */
462 auto content2 = std::make_shared<DCPContent>(film1->dir(film1->dcp_name()));
463 auto film2 = new_test_film2 ("player_silence_at_end_crash_2", {content2});
465 /* and importing just the video MXF on its own at the end */
466 optional<boost::filesystem::path> video;
467 for (auto i: boost::filesystem::directory_iterator(film1->dir(film1->dcp_name()))) {
468 if (boost::starts_with(i.path().filename().string(), "j2c_")) {
473 BOOST_REQUIRE (video);
474 auto content3 = content_factory(*video)[0];
475 film2->examine_and_add_content (content3);
476 BOOST_REQUIRE (!wait_for_jobs());
477 content3->set_position (film2, DCPTime::from_seconds(1.5));
478 film2->set_video_frame_rate (24);
479 make_and_verify_dcp (film2);
484 BOOST_AUTO_TEST_CASE (encrypted_dcp_with_no_kdm_gives_no_butler_error)
486 auto content = content_factory("test/data/flat_red.png")[0];
487 auto film = new_test_film2 ("encrypted_dcp_with_no_kdm_gives_no_butler_error", { content });
488 int constexpr length = 24 * 25;
489 content->video->set_length(length);
490 film->set_encrypted (true);
491 make_and_verify_dcp (
494 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
497 auto content2 = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
498 auto film2 = new_test_film2 ("encrypted_dcp_with_no_kdm_gives_no_butler_error2", { content2 });
500 Player player(film, Image::Alignment::COMPACT);
501 Butler butler(film2, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED);
503 float buffer[2000 * 6];
504 for (int i = 0; i < length; ++i) {
505 butler.get_video(Butler::Behaviour::BLOCKING, 0);
506 butler.get_audio(Butler::Behaviour::BLOCKING, buffer, 2000);
509 BOOST_CHECK_NO_THROW(butler.rethrow());
513 BOOST_AUTO_TEST_CASE (interleaved_subtitle_are_emitted_correctly)
515 boost::filesystem::path paths[2] = {
516 "build/test/interleaved_subtitle_are_emitted_correctly1.srt",
517 "build/test/interleaved_subtitle_are_emitted_correctly2.srt"
520 dcp::File subs_file[2] = { dcp::File(paths[0], "w"), dcp::File(paths[1], "w") };
522 fprintf(subs_file[0].get(), "1\n00:00:01,000 -> 00:00:02,000\nSub 1/1\n\n");
523 fprintf(subs_file[0].get(), "2\n00:00:05,000 -> 00:00:06,000\nSub 1/2\n\n");
525 fprintf(subs_file[1].get(), "1\n00:00:00,500 -> 00:00:01,500\nSub 2/1\n\n");
526 fprintf(subs_file[1].get(), "2\n00:00:02,000 -> 00:00:03,000\nSub 2/2\n\n");
528 subs_file[0].close();
529 subs_file[1].close();
531 auto subs1 = content_factory(paths[0])[0];
532 auto subs2 = content_factory(paths[1])[0];
533 auto film = new_test_film2("interleaved_subtitle_are_emitted_correctly", { subs1, subs2 });
534 film->set_sequence(false);
535 subs1->set_position(film, DCPTime());
536 subs2->set_position(film, DCPTime());
538 Player player(film, Image::Alignment::COMPACT);
540 player.Text.connect([&last](PlayerText text, TextType, optional<DCPTextTrack>, dcpomatic::DCPTimePeriod) {
541 for (auto sub: text.string) {
542 BOOST_CHECK(sub.in() >= last);
546 while (!player.pass()) {}
550 BOOST_AUTO_TEST_CASE(multiple_sound_files_bug)
554 Config::instance()->set_log_types(Config::instance()->log_types() | LogEntry::TYPE_DEBUG_PLAYER);
556 auto A = content_factory(TestPaths::private_data() / "kook" / "1.wav").front();
557 auto B = content_factory(TestPaths::private_data() / "kook" / "2.wav").front();
558 auto C = content_factory(TestPaths::private_data() / "kook" / "3.wav").front();
560 auto film = new_test_film2("multiple_sound_files_bug", { A, B, C }, &cl);
561 film->set_audio_channels(16);
562 C->set_position(film, DCPTime(3840000));
564 make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
566 check_mxf_audio_file(TestPaths::private_data() / "kook" / "reference.mxf", dcp_file(film, "pcm_"));
572 BOOST_AUTO_TEST_CASE(trimmed_sound_mix_bug_13)
574 auto A = content_factory("test/data/sine_16_48_440_10.wav").front();
575 auto B = content_factory("test/data/sine_16_44.1_440_10.wav").front();
576 auto film = new_test_film2("trimmed_sound_mix_bug_13", { A, B });
577 film->set_audio_channels(16);
579 A->set_position(film, DCPTime());
580 A->audio->set_gain(-12);
581 B->set_position(film, DCPTime());
582 B->audio->set_gain(-12);
583 B->set_trim_start(film, ContentTime(13));
585 make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
586 check_mxf_audio_file("test/data/trimmed_sound_mix_bug_13.mxf", dcp_file(film, "pcm_"));
590 BOOST_AUTO_TEST_CASE(trimmed_sound_mix_bug_13_frame_rate_change)
592 auto A = content_factory("test/data/sine_16_48_440_10.wav").front();
593 auto B = content_factory("test/data/sine_16_44.1_440_10.wav").front();
594 auto film = new_test_film2("trimmed_sound_mix_bug_13_frame_rate_change", { A, B });
596 A->set_position(film, DCPTime());
597 A->audio->set_gain(-12);
598 B->set_position(film, DCPTime());
599 B->audio->set_gain(-12);
600 B->set_trim_start(film, ContentTime(13));
602 A->set_video_frame_rate(film, 24);
603 B->set_video_frame_rate(film, 24);
604 film->set_video_frame_rate(25);
605 film->set_audio_channels(16);
607 make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
608 check_mxf_audio_file("test/data/trimmed_sound_mix_bug_13_frame_rate_change.mxf", dcp_file(film, "pcm_"));
612 BOOST_AUTO_TEST_CASE(two_d_in_three_d_duplicates)
614 auto A = content_factory("test/data/flat_red.png").front();
615 auto B = content_factory("test/data/flat_green.png").front();
616 auto film = new_test_film2("two_d_in_three_d_duplicates", { A, B });
618 film->set_three_d(true);
619 B->video->set_frame_type(VideoFrameType::THREE_D_LEFT_RIGHT);
620 B->set_position(film, DCPTime::from_seconds(10));
621 B->video->set_custom_size(dcp::Size(1998, 1080));
623 auto player = std::make_shared<Player>(film, film->playlist());
625 std::vector<uint8_t> red_line(1998 * 3);
626 for (int i = 0; i < 1998; ++i) {
627 red_line[i * 3] = 255;
630 std::vector<uint8_t> green_line(1998 * 3);
631 for (int i = 0; i < 1998; ++i) {
632 green_line[i * 3 + 1] = 255;
635 Eyes last_eyes = Eyes::RIGHT;
636 optional<DCPTime> last_time;
637 player->Video.connect([&last_eyes, &last_time, &red_line, &green_line](shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time) {
638 BOOST_CHECK(last_eyes != video->eyes());
639 last_eyes = video->eyes();
640 if (video->eyes() == Eyes::LEFT) {
641 BOOST_CHECK(!last_time || time == *last_time + DCPTime::from_frames(1, 24));
643 BOOST_CHECK(time == *last_time);
647 auto image = video->image([](AVPixelFormat) { return AV_PIX_FMT_RGB24; }, VideoRange::FULL, false);
648 auto const size = image->size();
649 for (int y = 0; y < size.height; ++y) {
650 uint8_t* line = image->data()[0] + y * image->stride()[0];
651 if (time < DCPTime::from_seconds(10)) {
652 BOOST_REQUIRE_EQUAL(memcmp(line, red_line.data(), 1998 * 3), 0);
654 BOOST_REQUIRE_EQUAL(memcmp(line, green_line.data(), 1998 * 3), 0);
659 BOOST_CHECK(film->length() == DCPTime::from_seconds(20));
660 while (!player->pass()) {}
664 BOOST_AUTO_TEST_CASE(three_d_in_two_d_chooses_left)
666 auto left = content_factory("test/data/flat_red.png").front();
667 auto right = content_factory("test/data/flat_green.png").front();
668 auto mono = content_factory("test/data/flat_blue.png").front();
670 auto film = new_test_film2("three_d_in_two_d_chooses_left", { left, right, mono });
672 left->video->set_frame_type(VideoFrameType::THREE_D_LEFT);
673 left->set_position(film, dcpomatic::DCPTime());
674 right->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
675 right->set_position(film, dcpomatic::DCPTime());
677 mono->set_position(film, dcpomatic::DCPTime::from_seconds(10));
679 auto player = std::make_shared<Player>(film, film->playlist());
681 std::vector<uint8_t> red_line(1998 * 3);
682 for (int i = 0; i < 1998; ++i) {
683 red_line[i * 3] = 255;
686 std::vector<uint8_t> blue_line(1998 * 3);
687 for (int i = 0; i < 1998; ++i) {
688 blue_line[i * 3 + 2] = 255;
691 optional<DCPTime> last_time;
692 player->Video.connect([&last_time, &red_line, &blue_line](shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time) {
693 BOOST_CHECK(video->eyes() == Eyes::BOTH);
694 BOOST_CHECK(!last_time || time == *last_time + DCPTime::from_frames(1, 24));
697 auto image = video->image([](AVPixelFormat) { return AV_PIX_FMT_RGB24; }, VideoRange::FULL, false);
698 auto const size = image->size();
699 for (int y = 0; y < size.height; ++y) {
700 uint8_t* line = image->data()[0] + y * image->stride()[0];
701 if (time < DCPTime::from_seconds(10)) {
702 BOOST_REQUIRE_EQUAL(memcmp(line, red_line.data(), 1998 * 3), 0);
704 BOOST_REQUIRE_EQUAL(memcmp(line, blue_line.data(), 1998 * 3), 0);
709 BOOST_CHECK(film->length() == DCPTime::from_seconds(20));
710 while (!player->pass()) {}