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 check_dcp (ref.string(), check.string());
149 /** Check behaviour with an awkward playlist whose data does not end on a video frame start */
150 BOOST_AUTO_TEST_CASE (player_subframe_test)
152 auto film = new_test_film ("reels_test7");
153 film->set_name ("reels_test7");
154 film->set_container (Ratio::from_id("185"));
155 film->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
156 auto A = content_factory("test/data/flat_red.png")[0];
157 film->examine_and_add_content (A);
158 BOOST_REQUIRE (!wait_for_jobs());
159 auto B = content_factory("test/data/awkward_length.wav")[0];
160 film->examine_and_add_content (B);
161 BOOST_REQUIRE (!wait_for_jobs());
162 film->set_video_frame_rate (24);
163 A->video->set_length (3 * 24);
165 BOOST_CHECK (A->full_length(film) == DCPTime::from_frames(3 * 24, 24));
166 BOOST_CHECK (B->full_length(film) == DCPTime(289920));
167 /* Length should be rounded up from B's length to the next video frame */
168 BOOST_CHECK (film->length() == DCPTime::from_frames(3 * 24 + 1, 24));
170 Player player(film, Image::Alignment::COMPACT);
171 player.setup_pieces();
172 BOOST_REQUIRE_EQUAL(player._black._periods.size(), 1U);
173 BOOST_CHECK(player._black._periods.front() == DCPTimePeriod(DCPTime::from_frames(3 * 24, 24), DCPTime::from_frames(3 * 24 + 1, 24)));
174 BOOST_REQUIRE_EQUAL(player._silent._periods.size(), 1U);
175 BOOST_CHECK(player._silent._periods.front() == DCPTimePeriod(DCPTime(289920), DCPTime::from_frames(3 * 24 + 1, 24)));
179 static Frame video_frames;
180 static Frame audio_frames;
184 video (shared_ptr<PlayerVideo>, DCPTime)
190 audio (shared_ptr<AudioBuffers> audio, DCPTime)
192 audio_frames += audio->frames();
196 /** Check with a video-only file that the video and audio emissions happen more-or-less together */
197 BOOST_AUTO_TEST_CASE (player_interleave_test)
199 auto film = new_test_film ("ffmpeg_transcoder_basic_test_subs");
200 film->set_name ("ffmpeg_transcoder_basic_test");
201 film->set_container (Ratio::from_id ("185"));
202 film->set_audio_channels (6);
204 auto c = std::make_shared<FFmpegContent>("test/data/test.mp4");
205 film->examine_and_add_content (c);
206 BOOST_REQUIRE (!wait_for_jobs ());
208 auto s = std::make_shared<StringTextFileContent>("test/data/subrip.srt");
209 film->examine_and_add_content (s);
210 BOOST_REQUIRE (!wait_for_jobs ());
212 Player player(film, Image::Alignment::COMPACT);
213 player.Video.connect(bind(&video, _1, _2));
214 player.Audio.connect(bind(&audio, _1, _2));
215 video_frames = audio_frames = 0;
216 while (!player.pass()) {
217 BOOST_CHECK (abs(video_frames - (audio_frames / 2000)) <= 8);
222 /** Test some seeks towards the start of a DCP with awkward subtitles; see mantis #1085
223 * and a number of others. I thought this was a player seek bug but in fact it was
224 * caused by the subtitle starting just after the start of the video frame and hence
227 BOOST_AUTO_TEST_CASE (player_seek_test)
229 auto film = std::make_shared<Film>(optional<boost::filesystem::path>());
230 auto dcp = std::make_shared<DCPContent>(TestPaths::private_data() / "awkward_subs");
231 film->examine_and_add_content (dcp, true);
232 BOOST_REQUIRE (!wait_for_jobs ());
233 dcp->only_text()->set_use (true);
235 Player player(film, Image::Alignment::COMPACT);
237 player.set_always_burn_open_subtitles();
238 player.set_play_referenced();
240 auto butler = std::make_shared<Butler>(
241 film, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::DISABLED
244 for (int i = 0; i < 10; ++i) {
245 auto t = DCPTime::from_frames (i, 24);
246 butler->seek (t, true);
247 auto video = butler->get_video(Butler::Behaviour::BLOCKING, 0);
248 BOOST_CHECK_EQUAL(video.second.get(), t.get());
249 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));
250 /* This 14.08 is empirically chosen (hopefully) to accept changes in rendering between the reference and a test machine
251 (17.10 and 16.04 seem to anti-alias a little differently) but to reject gross errors e.g. missing fonts or missing
254 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);
259 /** Test some more seeks towards the start of a DCP with awkward subtitles */
260 BOOST_AUTO_TEST_CASE (player_seek_test2)
262 auto film = std::make_shared<Film>(optional<boost::filesystem::path>());
263 auto dcp = std::make_shared<DCPContent>(TestPaths::private_data() / "awkward_subs2");
264 film->examine_and_add_content (dcp, true);
265 BOOST_REQUIRE (!wait_for_jobs ());
266 dcp->only_text()->set_use (true);
268 Player player(film, Image::Alignment::COMPACT);
270 player.set_always_burn_open_subtitles();
271 player.set_play_referenced();
273 auto butler = std::make_shared<Butler>
274 (film, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::DISABLED
277 butler->seek(DCPTime::from_seconds(5), true);
279 for (int i = 0; i < 10; ++i) {
280 auto t = DCPTime::from_seconds(5) + DCPTime::from_frames (i, 24);
281 butler->seek (t, true);
282 auto video = butler->get_video(Butler::Behaviour::BLOCKING, 0);
283 BOOST_CHECK_EQUAL(video.second.get(), t.get());
285 video.first->image(bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true), String::compose("build/test/player_seek_test2_%1.png", i)
287 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);
292 /** Test a bug when trimmed content follows other content */
293 BOOST_AUTO_TEST_CASE (player_trim_test)
295 auto film = new_test_film2 ("player_trim_test");
296 auto A = content_factory("test/data/flat_red.png")[0];
297 film->examine_and_add_content (A);
298 BOOST_REQUIRE (!wait_for_jobs ());
299 A->video->set_length (10 * 24);
300 auto B = content_factory("test/data/flat_red.png")[0];
301 film->examine_and_add_content (B);
302 BOOST_REQUIRE (!wait_for_jobs ());
303 B->video->set_length (10 * 24);
304 B->set_position (film, DCPTime::from_seconds(10));
305 B->set_trim_start(film, ContentTime::from_seconds(2));
307 make_and_verify_dcp (film);
314 optional<DCPTextTrack> track;
315 DCPTimePeriod period;
320 store (list<Sub>* out, PlayerText text, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
331 /** Test ignoring both video and audio */
332 BOOST_AUTO_TEST_CASE (player_ignore_video_and_audio_test)
334 auto film = new_test_film2 ("player_ignore_video_and_audio_test");
335 auto ff = content_factory(TestPaths::private_data() / "boon_telly.mkv")[0];
336 film->examine_and_add_content (ff);
337 auto text = content_factory("test/data/subrip.srt")[0];
338 film->examine_and_add_content (text);
339 BOOST_REQUIRE (!wait_for_jobs());
340 text->only_text()->set_type (TextType::CLOSED_CAPTION);
341 text->only_text()->set_use (true);
343 Player player(film, Image::Alignment::COMPACT);
344 player.set_ignore_video();
345 player.set_ignore_audio();
348 player.Text.connect(bind (&store, &out, _1, _2, _3, _4));
349 while (!player.pass()) {}
351 BOOST_CHECK_EQUAL (out.size(), 6U);
355 /** Trigger a crash due to the assertion failure in Player::emit_audio */
356 BOOST_AUTO_TEST_CASE (player_trim_crash)
358 auto film = new_test_film2 ("player_trim_crash");
359 auto boon = content_factory(TestPaths::private_data() / "boon_telly.mkv")[0];
360 film->examine_and_add_content (boon);
361 BOOST_REQUIRE (!wait_for_jobs());
363 Player player(film, Image::Alignment::COMPACT);
365 auto butler = std::make_shared<Butler>(
366 film, player, AudioMapping(), 6, bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::COMPACT, true, false, Butler::Audio::ENABLED
369 /* Wait for the butler to fill */
370 dcpomatic_sleep_seconds (5);
372 boon->set_trim_start(film, ContentTime::from_seconds(5));
374 butler->seek (DCPTime(), true);
376 /* Wait for the butler to refill */
377 dcpomatic_sleep_seconds (5);
383 /** Test a crash when the gap between the last audio and the start of a silent period is more than 1 sample */
384 BOOST_AUTO_TEST_CASE (player_silence_crash)
386 auto film = new_test_film2 ("player_silence_crash");
387 auto sine = content_factory("test/data/impulse_train.wav")[0];
388 film->examine_and_add_content (sine);
389 BOOST_REQUIRE (!wait_for_jobs());
391 sine->set_video_frame_rate(film, 23.976);
392 film->write_metadata ();
393 make_and_verify_dcp (film, {dcp::VerificationNote::Code::MISSING_CPL_METADATA});
397 /** Test a crash when processing a 3D DCP */
398 BOOST_AUTO_TEST_CASE (player_3d_test_1)
400 auto film = new_test_film2 ("player_3d_test_1a");
401 auto left = content_factory("test/data/flat_red.png")[0];
402 film->examine_and_add_content (left);
403 auto right = content_factory("test/data/flat_blue.png")[0];
404 film->examine_and_add_content (right);
405 BOOST_REQUIRE (!wait_for_jobs());
407 left->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
408 left->set_position (film, DCPTime());
409 right->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
410 right->set_position (film, DCPTime());
411 film->set_three_d (true);
413 make_and_verify_dcp (film);
415 auto dcp = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
416 auto film2 = new_test_film2 ("player_3d_test_1b", {dcp});
418 film2->set_three_d (true);
419 make_and_verify_dcp (film2);
423 /** Test a crash when processing a 3D DCP as content in a 2D project */
424 BOOST_AUTO_TEST_CASE (player_3d_test_2)
426 auto left = content_factory("test/data/flat_red.png")[0];
427 auto right = content_factory("test/data/flat_blue.png")[0];
428 auto film = new_test_film2 ("player_3d_test_2a", {left, right});
430 left->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
431 left->set_position (film, DCPTime());
432 right->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
433 right->set_position (film, DCPTime());
434 film->set_three_d (true);
436 make_and_verify_dcp (film);
438 auto dcp = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
439 auto film2 = new_test_film2 ("player_3d_test_2b", {dcp});
441 make_and_verify_dcp (film2);
445 /** Test a crash when there is video-only content at the end of the DCP and a frame-rate conversion is happening;
448 BOOST_AUTO_TEST_CASE (player_silence_at_end_crash)
450 /* 25fps DCP with some audio */
451 auto content1 = content_factory("test/data/flat_red.png")[0];
452 auto film1 = new_test_film2 ("player_silence_at_end_crash_1", {content1});
453 content1->video->set_length (25);
454 film1->set_video_frame_rate (25);
455 make_and_verify_dcp (film1);
457 /* Make another project importing this DCP */
458 auto content2 = std::make_shared<DCPContent>(film1->dir(film1->dcp_name()));
459 auto film2 = new_test_film2 ("player_silence_at_end_crash_2", {content2});
461 /* and importing just the video MXF on its own at the end */
462 optional<boost::filesystem::path> video;
463 for (auto i: boost::filesystem::directory_iterator(film1->dir(film1->dcp_name()))) {
464 if (boost::starts_with(i.path().filename().string(), "j2c_")) {
469 BOOST_REQUIRE (video);
470 auto content3 = content_factory(*video)[0];
471 film2->examine_and_add_content (content3);
472 BOOST_REQUIRE (!wait_for_jobs());
473 content3->set_position (film2, DCPTime::from_seconds(1.5));
474 film2->set_video_frame_rate (24);
475 make_and_verify_dcp (film2);
480 BOOST_AUTO_TEST_CASE (encrypted_dcp_with_no_kdm_gives_no_butler_error)
482 auto content = content_factory("test/data/flat_red.png")[0];
483 auto film = new_test_film2 ("encrypted_dcp_with_no_kdm_gives_no_butler_error", { content });
484 int constexpr length = 24 * 25;
485 content->video->set_length(length);
486 film->set_encrypted (true);
487 make_and_verify_dcp (
490 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
493 auto content2 = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
494 auto film2 = new_test_film2 ("encrypted_dcp_with_no_kdm_gives_no_butler_error2", { content2 });
496 Player player(film, Image::Alignment::COMPACT);
497 Butler butler(film2, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED);
499 float buffer[2000 * 6];
500 for (int i = 0; i < length; ++i) {
501 butler.get_video(Butler::Behaviour::BLOCKING, 0);
502 butler.get_audio(Butler::Behaviour::BLOCKING, buffer, 2000);
505 BOOST_CHECK_NO_THROW(butler.rethrow());
509 BOOST_AUTO_TEST_CASE (interleaved_subtitle_are_emitted_correctly)
511 boost::filesystem::path paths[2] = {
512 "build/test/interleaved_subtitle_are_emitted_correctly1.srt",
513 "build/test/interleaved_subtitle_are_emitted_correctly2.srt"
516 dcp::File subs_file[2] = { dcp::File(paths[0], "w"), dcp::File(paths[1], "w") };
518 fprintf(subs_file[0].get(), "1\n00:00:01,000 -> 00:00:02,000\nSub 1/1\n\n");
519 fprintf(subs_file[0].get(), "2\n00:00:05,000 -> 00:00:06,000\nSub 1/2\n\n");
521 fprintf(subs_file[1].get(), "1\n00:00:00,500 -> 00:00:01,500\nSub 2/1\n\n");
522 fprintf(subs_file[1].get(), "2\n00:00:02,000 -> 00:00:03,000\nSub 2/2\n\n");
524 subs_file[0].close();
525 subs_file[1].close();
527 auto subs1 = content_factory(paths[0])[0];
528 auto subs2 = content_factory(paths[1])[0];
529 auto film = new_test_film2("interleaved_subtitle_are_emitted_correctly", { subs1, subs2 });
530 film->set_sequence(false);
531 subs1->set_position(film, DCPTime());
532 subs2->set_position(film, DCPTime());
534 Player player(film, Image::Alignment::COMPACT);
536 player.Text.connect([&last](PlayerText text, TextType, optional<DCPTextTrack>, dcpomatic::DCPTimePeriod) {
537 for (auto sub: text.string) {
538 BOOST_CHECK(sub.in() >= last);
542 while (!player.pass()) {}
546 BOOST_AUTO_TEST_CASE(multiple_sound_files_bug)
548 Config::instance()->set_log_types(Config::instance()->log_types() | LogEntry::TYPE_DEBUG_PLAYER);
550 auto A = content_factory(TestPaths::private_data() / "kook" / "1.wav").front();
551 auto B = content_factory(TestPaths::private_data() / "kook" / "2.wav").front();
552 auto C = content_factory(TestPaths::private_data() / "kook" / "3.wav").front();
554 auto film = new_test_film2("multiple_sound_files_bug", { A, B, C });
555 C->set_position(film, DCPTime(3840000));
557 make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
559 check_mxf_audio_file(TestPaths::private_data() / "kook" / "reference.mxf", dcp_file(film, "pcm_"));
563 BOOST_AUTO_TEST_CASE(trimmed_sound_mix_bug_13)
565 auto A = content_factory("test/data/sine_16_48_440_10.wav").front();
566 auto B = content_factory("test/data/sine_16_44.1_440_10.wav").front();
567 auto film = new_test_film2("trimmed_sound_mix_bug_13", { A, B });
569 A->set_position(film, DCPTime());
570 A->audio->set_gain(-12);
571 B->set_position(film, DCPTime());
572 B->audio->set_gain(-12);
573 B->set_trim_start(film, ContentTime(13));
575 make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
576 check_mxf_audio_file("test/data/trimmed_sound_mix_bug_13.mxf", dcp_file(film, "pcm_"));
580 BOOST_AUTO_TEST_CASE(trimmed_sound_mix_bug_13_frame_rate_change)
582 auto A = content_factory("test/data/sine_16_48_440_10.wav").front();
583 auto B = content_factory("test/data/sine_16_44.1_440_10.wav").front();
584 auto film = new_test_film2("trimmed_sound_mix_bug_13_frame_rate_change", { A, B });
586 A->set_position(film, DCPTime());
587 A->audio->set_gain(-12);
588 B->set_position(film, DCPTime());
589 B->audio->set_gain(-12);
590 B->set_trim_start(film, ContentTime(13));
592 A->set_video_frame_rate(film, 24);
593 B->set_video_frame_rate(film, 24);
594 film->set_video_frame_rate(25);
596 make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
597 check_mxf_audio_file("test/data/trimmed_sound_mix_bug_13_frame_rate_change.mxf", dcp_file(film, "pcm_"));
601 BOOST_AUTO_TEST_CASE(two_d_in_three_d_duplicates)
603 auto A = content_factory("test/data/flat_red.png").front();
604 auto B = content_factory("test/data/flat_green.png").front();
605 auto film = new_test_film2("two_d_in_three_d_duplicates", { A, B });
607 film->set_three_d(true);
608 B->video->set_frame_type(VideoFrameType::THREE_D_LEFT_RIGHT);
609 B->set_position(film, DCPTime::from_seconds(10));
610 B->video->set_custom_size(dcp::Size(1998, 1080));
612 auto player = std::make_shared<Player>(film, film->playlist());
614 std::vector<uint8_t> red_line(1998 * 3);
615 for (int i = 0; i < 1998; ++i) {
616 red_line[i * 3] = 255;
619 std::vector<uint8_t> green_line(1998 * 3);
620 for (int i = 0; i < 1998; ++i) {
621 green_line[i * 3 + 1] = 255;
624 Eyes last_eyes = Eyes::RIGHT;
625 optional<DCPTime> last_time;
626 player->Video.connect([&last_eyes, &last_time, &red_line, &green_line](shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time) {
627 BOOST_CHECK(last_eyes != video->eyes());
628 last_eyes = video->eyes();
629 if (video->eyes() == Eyes::LEFT) {
630 BOOST_CHECK(!last_time || time == *last_time + DCPTime::from_frames(1, 24));
632 BOOST_CHECK(time == *last_time);
636 auto image = video->image([](AVPixelFormat) { return AV_PIX_FMT_RGB24; }, VideoRange::FULL, false);
637 auto const size = image->size();
638 for (int y = 0; y < size.height; ++y) {
639 uint8_t* line = image->data()[0] + y * image->stride()[0];
640 if (time < DCPTime::from_seconds(10)) {
641 BOOST_REQUIRE_EQUAL(memcmp(line, red_line.data(), 1998 * 3), 0);
643 BOOST_REQUIRE_EQUAL(memcmp(line, green_line.data(), 1998 * 3), 0);
648 BOOST_CHECK(film->length() == DCPTime::from_seconds(20));
649 while (!player->pass()) {}
653 BOOST_AUTO_TEST_CASE(three_d_in_two_d_chooses_left)
655 auto left = content_factory("test/data/flat_red.png").front();
656 auto right = content_factory("test/data/flat_green.png").front();
657 auto mono = content_factory("test/data/flat_blue.png").front();
659 auto film = new_test_film2("three_d_in_two_d_chooses_left", { left, right, mono });
661 left->video->set_frame_type(VideoFrameType::THREE_D_LEFT);
662 left->set_position(film, dcpomatic::DCPTime());
663 right->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
664 right->set_position(film, dcpomatic::DCPTime());
666 mono->set_position(film, dcpomatic::DCPTime::from_seconds(10));
668 auto player = std::make_shared<Player>(film, film->playlist());
670 std::vector<uint8_t> red_line(1998 * 3);
671 for (int i = 0; i < 1998; ++i) {
672 red_line[i * 3] = 255;
675 std::vector<uint8_t> blue_line(1998 * 3);
676 for (int i = 0; i < 1998; ++i) {
677 blue_line[i * 3 + 2] = 255;
680 optional<DCPTime> last_time;
681 player->Video.connect([&last_time, &red_line, &blue_line](shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time) {
682 BOOST_CHECK(video->eyes() == Eyes::BOTH);
683 BOOST_CHECK(!last_time || time == *last_time + DCPTime::from_frames(1, 24));
686 auto image = video->image([](AVPixelFormat) { return AV_PIX_FMT_RGB24; }, VideoRange::FULL, false);
687 auto const size = image->size();
688 for (int y = 0; y < size.height; ++y) {
689 uint8_t* line = image->data()[0] + y * image->stride()[0];
690 if (time < DCPTime::from_seconds(10)) {
691 BOOST_REQUIRE_EQUAL(memcmp(line, red_line.data(), 1998 * 3), 0);
693 BOOST_REQUIRE_EQUAL(memcmp(line, blue_line.data(), 1998 * 3), 0);
698 BOOST_CHECK(film->length() == DCPTime::from_seconds(20));
699 while (!player->pass()) {}