Handle 2D/3D mismatches in the player (#2409).
[dcpomatic.git] / test / player_test.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 /** @file  test/player_test.cc
23  *  @brief Test Player class.
24  *  @ingroup selfcontained
25  */
26
27
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"
39 #include "lib/film.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"
47 #include "test.h"
48 #include <boost/test/unit_test.hpp>
49 #include <boost/algorithm/string.hpp>
50 #include <iostream>
51
52
53 using std::cout;
54 using std::list;
55 using std::shared_ptr;
56 using std::make_shared;
57 using boost::bind;
58 using boost::optional;
59 #if BOOST_VERSION >= 106100
60 using namespace boost::placeholders;
61 #endif
62 using namespace dcpomatic;
63
64
65 static shared_ptr<AudioBuffers> accumulated;
66
67
68 static void
69 accumulate (shared_ptr<AudioBuffers> audio, DCPTime)
70 {
71         BOOST_REQUIRE (accumulated);
72         accumulated->append (audio);
73 }
74
75
76 /** Check that the Player correctly generates silence when used with a silent FFmpegContent */
77 BOOST_AUTO_TEST_CASE (player_silence_padding_test)
78 {
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);
84
85         film->examine_and_add_content (c);
86         BOOST_REQUIRE (!wait_for_jobs());
87
88         accumulated = std::make_shared<AudioBuffers>(film->audio_channels(), 0);
89
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 ());
95
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);
99                 }
100         }
101 }
102
103
104 /* Test insertion of black frames between separate bits of video content */
105 BOOST_AUTO_TEST_CASE (player_black_fill_test)
106 {
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");
115
116         film->examine_and_add_content (contentA);
117         film->examine_and_add_content (contentB);
118         BOOST_REQUIRE (!wait_for_jobs());
119
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);
126
127         make_and_verify_dcp (
128                 film,
129                 {
130                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
131                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
132                 });
133
134         boost::filesystem::path ref;
135         ref = "test";
136         ref /= "data";
137         ref /= "black_fill_test";
138
139         boost::filesystem::path check;
140         check = "build";
141         check /= "test";
142         check /= "black_fill_test";
143         check /= film->dcp_name();
144
145         check_dcp (ref.string(), check.string());
146 }
147
148
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)
151 {
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);
164
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));
169
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)));
176 }
177
178
179 static Frame video_frames;
180 static Frame audio_frames;
181
182
183 static void
184 video (shared_ptr<PlayerVideo>, DCPTime)
185 {
186         ++video_frames;
187 }
188
189 static void
190 audio (shared_ptr<AudioBuffers> audio, DCPTime)
191 {
192         audio_frames += audio->frames();
193 }
194
195
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)
198 {
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);
203
204         auto c = std::make_shared<FFmpegContent>("test/data/test.mp4");
205         film->examine_and_add_content (c);
206         BOOST_REQUIRE (!wait_for_jobs ());
207
208         auto s = std::make_shared<StringTextFileContent>("test/data/subrip.srt");
209         film->examine_and_add_content (s);
210         BOOST_REQUIRE (!wait_for_jobs ());
211
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);
218         }
219 }
220
221
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
225  *  being faded out.
226  */
227 BOOST_AUTO_TEST_CASE (player_seek_test)
228 {
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);
234
235         Player player(film, Image::Alignment::COMPACT);
236         player.set_fast();
237         player.set_always_burn_open_subtitles();
238         player.set_play_referenced();
239
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
242                 );
243
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
252                    text altogether.
253                 */
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);
255         }
256 }
257
258
259 /** Test some more seeks towards the start of a DCP with awkward subtitles */
260 BOOST_AUTO_TEST_CASE (player_seek_test2)
261 {
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);
267
268         Player player(film, Image::Alignment::COMPACT);
269         player.set_fast();
270         player.set_always_burn_open_subtitles();
271         player.set_play_referenced();
272
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
275                  );
276
277         butler->seek(DCPTime::from_seconds(5), true);
278
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());
284                 write_image(
285                         video.first->image(bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true), String::compose("build/test/player_seek_test2_%1.png", i)
286                         );
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);
288         }
289 }
290
291
292 /** Test a bug when trimmed content follows other content */
293 BOOST_AUTO_TEST_CASE (player_trim_test)
294 {
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));
306
307        make_and_verify_dcp (film);
308 }
309
310
311 struct Sub {
312         PlayerText text;
313         TextType type;
314         optional<DCPTextTrack> track;
315         DCPTimePeriod period;
316 };
317
318
319 static void
320 store (list<Sub>* out, PlayerText text, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
321 {
322         Sub s;
323         s.text = text;
324         s.type = type;
325         s.track = track;
326         s.period = period;
327         out->push_back (s);
328 }
329
330
331 /** Test ignoring both video and audio */
332 BOOST_AUTO_TEST_CASE (player_ignore_video_and_audio_test)
333 {
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);
342
343         Player player(film, Image::Alignment::COMPACT);
344         player.set_ignore_video();
345         player.set_ignore_audio();
346
347         list<Sub> out;
348         player.Text.connect(bind (&store, &out, _1, _2, _3, _4));
349         while (!player.pass()) {}
350
351         BOOST_CHECK_EQUAL (out.size(), 6U);
352 }
353
354
355 /** Trigger a crash due to the assertion failure in Player::emit_audio */
356 BOOST_AUTO_TEST_CASE (player_trim_crash)
357 {
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());
362
363         Player player(film, Image::Alignment::COMPACT);
364         player.set_fast();
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
367                 );
368
369         /* Wait for the butler to fill */
370         dcpomatic_sleep_seconds (5);
371
372         boon->set_trim_start(film, ContentTime::from_seconds(5));
373
374         butler->seek (DCPTime(), true);
375
376         /* Wait for the butler to refill */
377         dcpomatic_sleep_seconds (5);
378
379         butler->rethrow ();
380 }
381
382
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)
385 {
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());
390
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});
394 }
395
396
397 /** Test a crash when processing a 3D DCP */
398 BOOST_AUTO_TEST_CASE (player_3d_test_1)
399 {
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());
406
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);
412
413         make_and_verify_dcp (film);
414
415         auto dcp = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
416         auto film2 = new_test_film2 ("player_3d_test_1b", {dcp});
417
418         film2->set_three_d (true);
419         make_and_verify_dcp (film2);
420 }
421
422
423 /** Test a crash when processing a 3D DCP as content in a 2D project */
424 BOOST_AUTO_TEST_CASE (player_3d_test_2)
425 {
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});
429
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);
435
436         make_and_verify_dcp (film);
437
438         auto dcp = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
439         auto film2 = new_test_film2 ("player_3d_test_2b", {dcp});
440
441         make_and_verify_dcp (film2);
442 }
443
444
445 /** Test a crash when there is video-only content at the end of the DCP and a frame-rate conversion is happening;
446  *  #1691.
447  */
448 BOOST_AUTO_TEST_CASE (player_silence_at_end_crash)
449 {
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);
456
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});
460
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_")) {
465                         video = i.path();
466                 }
467         }
468
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);
476 }
477
478
479 /** #2257 */
480 BOOST_AUTO_TEST_CASE (encrypted_dcp_with_no_kdm_gives_no_butler_error)
481 {
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 (
488                 film,
489                 {
490                         dcp::VerificationNote::Code::MISSING_CPL_METADATA,
491                 });
492
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 });
495
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);
498
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);
503         }
504
505         BOOST_CHECK_NO_THROW(butler.rethrow());
506 }
507
508
509 BOOST_AUTO_TEST_CASE (interleaved_subtitle_are_emitted_correctly)
510 {
511         boost::filesystem::path paths[2] = {
512                 "build/test/interleaved_subtitle_are_emitted_correctly1.srt",
513                 "build/test/interleaved_subtitle_are_emitted_correctly2.srt"
514         };
515
516         dcp::File subs_file[2] = { dcp::File(paths[0], "w"), dcp::File(paths[1], "w") };
517
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");
520
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");
523
524         subs_file[0].close();
525         subs_file[1].close();
526
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());
533
534         Player player(film, Image::Alignment::COMPACT);
535         dcp::Time last;
536         player.Text.connect([&last](PlayerText text, TextType, optional<DCPTextTrack>, dcpomatic::DCPTimePeriod) {
537                 for (auto sub: text.string) {
538                         BOOST_CHECK(sub.in() >= last);
539                         last = sub.in();
540                 }
541         });
542         while (!player.pass()) {}
543 }
544
545
546 BOOST_AUTO_TEST_CASE(multiple_sound_files_bug)
547 {
548         Config::instance()->set_log_types(Config::instance()->log_types() | LogEntry::TYPE_DEBUG_PLAYER);
549
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();
553
554         auto film = new_test_film2("multiple_sound_files_bug", { A, B, C });
555         C->set_position(film, DCPTime(3840000));
556
557         make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
558
559         check_mxf_audio_file(TestPaths::private_data() / "kook" / "reference.mxf", dcp_file(film, "pcm_"));
560 }
561
562
563 BOOST_AUTO_TEST_CASE(trimmed_sound_mix_bug_13)
564 {
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 });
568
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));
574
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_"));
577 }
578
579
580 BOOST_AUTO_TEST_CASE(trimmed_sound_mix_bug_13_frame_rate_change)
581 {
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 });
585
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));
591
592         A->set_video_frame_rate(film, 24);
593         B->set_video_frame_rate(film, 24);
594         film->set_video_frame_rate(25);
595
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_"));
598 }
599
600
601 BOOST_AUTO_TEST_CASE(two_d_in_three_d_duplicates)
602 {
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 });
606
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));
611
612         auto player = std::make_shared<Player>(film, film->playlist());
613
614         std::vector<uint8_t> red_line(1998 * 3);
615         for (int i = 0; i < 1998; ++i) {
616                 red_line[i * 3] = 255;
617         };
618
619         std::vector<uint8_t> green_line(1998 * 3);
620         for (int i = 0; i < 1998; ++i) {
621                 green_line[i * 3 + 1] = 255;
622         };
623
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));
631                 } else {
632                         BOOST_CHECK(time == *last_time);
633                 }
634                 last_time = time;
635
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);
642                         } else {
643                                 BOOST_REQUIRE_EQUAL(memcmp(line, green_line.data(), 1998 * 3), 0);
644                         }
645                 }
646         });
647
648         BOOST_CHECK(film->length() == DCPTime::from_seconds(20));
649         while (!player->pass()) {}
650 }
651
652
653 BOOST_AUTO_TEST_CASE(three_d_in_two_d_chooses_left)
654 {
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();
658
659         auto film = new_test_film2("three_d_in_two_d_chooses_left", { left, right, mono });
660
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());
665
666         mono->set_position(film, dcpomatic::DCPTime::from_seconds(10));
667
668         auto player = std::make_shared<Player>(film, film->playlist());
669
670         std::vector<uint8_t> red_line(1998 * 3);
671         for (int i = 0; i < 1998; ++i) {
672                 red_line[i * 3] = 255;
673         };
674
675         std::vector<uint8_t> blue_line(1998 * 3);
676         for (int i = 0; i < 1998; ++i) {
677                 blue_line[i * 3 + 2] = 255;
678         };
679
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));
684                 last_time = time;
685
686                 std::cout << to_string(time) << "\n";
687                 auto image = video->image([](AVPixelFormat) { return AV_PIX_FMT_RGB24; }, VideoRange::FULL, false);
688                 auto const size = image->size();
689                 for (int y = 0; y < size.height; ++y) {
690                         uint8_t* line = image->data()[0] + y * image->stride()[0];
691                         if (time < DCPTime::from_seconds(10)) {
692                                 BOOST_REQUIRE_EQUAL(memcmp(line, red_line.data(), 1998 * 3), 0);
693                         } else {
694                                 BOOST_REQUIRE_EQUAL(memcmp(line, blue_line.data(), 1998 * 3), 0);
695                         }
696                 }
697         });
698
699         BOOST_CHECK(film->length() == DCPTime::from_seconds(20));
700         while (!player->pass()) {}
701 }
702