2 Copyright (C) 2015-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/vf_Test.cc
23 * @brief Various VF-related tests.
28 #include "lib/content_factory.h"
29 #include "lib/dcp_content.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/examine_content_job.h"
32 #include "lib/ffmpeg_content.h"
34 #include "lib/job_manager.h"
35 #include "lib/make_dcp.h"
36 #include "lib/player.h"
37 #include "lib/text_content.h"
38 #include "lib/referenced_reel_asset.h"
39 #include "lib/video_content.h"
43 #include <dcp/reel_picture_asset.h>
44 #include <dcp/reel_sound_asset.h>
45 #include <boost/test/unit_test.hpp>
50 using std::dynamic_pointer_cast;
52 using std::make_shared;
53 using std::shared_ptr;
55 using namespace dcpomatic;
58 /** Test the logic which decides whether a DCP can be referenced or not */
59 BOOST_AUTO_TEST_CASE (vf_test1)
61 auto film = new_test_film ("vf_test1");
62 film->set_interop (false);
63 auto dcp = make_shared<DCPContent>("test/data/reels_test2");
64 film->examine_and_add_content (dcp);
65 BOOST_REQUIRE (!wait_for_jobs());
67 /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
68 film->set_reel_type (ReelType::SINGLE);
70 BOOST_CHECK (!dcp->can_reference_video(film, why_not));
71 BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
72 BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
73 BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
75 /* Multi-reel DCP can be referenced if we are using by-video-content */
76 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
77 BOOST_CHECK (dcp->can_reference_video(film, why_not));
78 BOOST_CHECK (dcp->can_reference_audio(film, why_not));
79 /* (but reels_test2 has no texts to reference) */
80 BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
81 BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
83 auto other = make_shared<FFmpegContent>("test/data/test.mp4");
84 film->examine_and_add_content (other);
85 BOOST_REQUIRE (!wait_for_jobs());
86 BOOST_CHECK (!other->audio);
88 /* Not possible if there is overlap; we only check video here as that's all test.mp4 has */
89 other->set_position (film, DCPTime());
90 BOOST_CHECK (!dcp->can_reference_video(film, why_not));
92 /* This should not be considered an overlap */
93 other->set_position (film, dcp->end(film));
94 BOOST_CHECK (dcp->can_reference_video(film, why_not));
95 BOOST_CHECK (dcp->can_reference_audio(film, why_not));
96 /* (reels_test2 has no texts to reference) */
97 BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
98 BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
102 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
103 BOOST_AUTO_TEST_CASE (vf_test2)
106 auto ov = new_test_film ("vf_test2_ov");
107 ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
108 ov->set_name ("vf_test2_ov");
109 auto video = content_factory("test/data/flat_red.png")[0];
110 ov->examine_and_add_content (video);
111 BOOST_REQUIRE (!wait_for_jobs());
112 video->video->set_length (24 * 5);
113 auto audio = content_factory("test/data/white.wav")[0];
114 ov->examine_and_add_content (audio);
115 BOOST_REQUIRE (!wait_for_jobs());
116 make_and_verify_dcp (ov);
119 auto vf = new_test_film ("vf_test2_vf");
120 vf->set_name ("vf_test2_vf");
121 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
122 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
123 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
124 vf->examine_and_add_content (dcp);
125 BOOST_REQUIRE (!wait_for_jobs());
126 dcp->set_reference_video (true);
127 dcp->set_reference_audio (true);
128 auto sub = content_factory("test/data/subrip4.srt")[0];
129 vf->examine_and_add_content (sub);
130 BOOST_REQUIRE (!wait_for_jobs());
131 make_and_verify_dcp (
134 dcp::VerificationNote::Code::EXTERNAL_ASSET,
135 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
136 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
137 dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION
140 dcp::DCP ov_c (ov->dir(ov->dcp_name()));
142 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1U);
143 BOOST_REQUIRE_EQUAL (ov_c.cpls()[0]->reels().size(), 1U);
144 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_picture());
145 string const pic_id = ov_c.cpls()[0]->reels()[0]->main_picture()->id();
146 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_sound());
147 string const sound_id = ov_c.cpls()[0]->reels()[0]->main_sound()->id();
148 BOOST_REQUIRE (!ov_c.cpls()[0]->reels()[0]->main_subtitle());
150 dcp::DCP vf_c (vf->dir(vf->dcp_name()));
152 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
153 BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 1U);
154 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_picture());
155 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->id(), pic_id);
156 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_sound());
157 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->id(), sound_id);
158 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_subtitle());
162 /** Test creation of a VF using a trimmed OV; the output should have entry point /
163 * duration altered to effect the trimming.
165 BOOST_AUTO_TEST_CASE (vf_test3)
168 auto ov = new_test_film ("vf_test3_ov");
169 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
170 ov->set_name ("vf_test3_ov");
171 auto video = content_factory("test/data/flat_red.png")[0];
172 ov->examine_and_add_content (video);
173 BOOST_REQUIRE (!wait_for_jobs());
174 video->video->set_length (24 * 5);
175 auto audio = content_factory("test/data/white.wav")[0];
176 ov->examine_and_add_content (audio);
177 BOOST_REQUIRE (!wait_for_jobs());
178 make_and_verify_dcp (ov);
181 auto vf = new_test_film ("vf_test3_vf");
182 vf->set_name ("vf_test3_vf");
183 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
184 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
185 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
187 dcp->set_trim_start(vf, ContentTime::from_seconds (1));
188 dcp->set_trim_end (ContentTime::from_seconds (1));
189 vf->examine_and_add_content (dcp);
190 BOOST_REQUIRE (!wait_for_jobs());
191 dcp->set_reference_video (true);
192 dcp->set_reference_audio (true);
193 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
195 dcp::DCP vf_c (vf->dir(vf->dcp_name()));
197 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
198 BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 1U);
199 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_picture());
200 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->entry_point().get_value_or(0), 24);
201 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->actual_duration(), 72);
202 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_sound());
203 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->entry_point().get_value_or(0), 24);
204 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->actual_duration(), 72);
208 /** Make a OV with video and audio and a VF referencing the OV and adding some more video */
209 BOOST_AUTO_TEST_CASE (vf_test4)
212 auto ov = new_test_film ("vf_test4_ov");
213 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
214 ov->set_name ("vf_test4_ov");
215 auto video = content_factory("test/data/flat_red.png")[0];
216 ov->examine_and_add_content (video);
217 BOOST_REQUIRE (!wait_for_jobs());
218 video->video->set_length (24 * 5);
219 auto audio = content_factory("test/data/white.wav")[0];
220 ov->examine_and_add_content (audio);
221 BOOST_REQUIRE (!wait_for_jobs());
222 make_and_verify_dcp (ov);
225 auto vf = new_test_film ("vf_test4_vf");
226 vf->set_name ("vf_test4_vf");
227 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
228 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
229 vf->set_sequence (false);
230 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
232 vf->examine_and_add_content (dcp);
233 BOOST_REQUIRE (!wait_for_jobs());
234 dcp->set_position(vf, DCPTime::from_seconds(10));
235 dcp->set_reference_video (true);
236 dcp->set_reference_audio (true);
237 auto more_video = content_factory("test/data/flat_red.png")[0];
238 vf->examine_and_add_content (more_video);
239 BOOST_REQUIRE (!wait_for_jobs());
240 more_video->set_position (vf, DCPTime());
241 vf->write_metadata ();
242 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
244 dcp::DCP ov_c (ov->dir(ov->dcp_name()));
246 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1U);
247 BOOST_REQUIRE_EQUAL (ov_c.cpls()[0]->reels().size(), 1U);
248 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_picture());
249 string const pic_id = ov_c.cpls()[0]->reels()[0]->main_picture()->id();
250 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_sound());
251 string const sound_id = ov_c.cpls()[0]->reels()[0]->main_sound()->id();
252 BOOST_REQUIRE (!ov_c.cpls()[0]->reels()[0]->main_subtitle());
254 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
256 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
257 BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 2U);
258 BOOST_REQUIRE (vf_c.cpls()[0]->reels().back()->main_picture());
259 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels().back()->main_picture()->id(), pic_id);
260 BOOST_REQUIRE (vf_c.cpls()[0]->reels().back()->main_sound());
261 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels().back()->main_sound()->id(), sound_id);
265 /** Test bug #1495 */
266 BOOST_AUTO_TEST_CASE (vf_test5)
269 auto ov = new_test_film ("vf_test5_ov");
270 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
271 ov->set_reel_type (ReelType::BY_VIDEO_CONTENT);
272 for (int i = 0; i < 3; ++i) {
273 auto video = content_factory("test/data/flat_red.png")[0];
274 ov->examine_and_add_content (video);
275 BOOST_REQUIRE (!wait_for_jobs());
276 video->video->set_length (24 * 10);
279 BOOST_REQUIRE (!wait_for_jobs());
280 make_and_verify_dcp (ov);
283 auto vf = new_test_film ("vf_test5_vf");
284 vf->set_name ("vf_test5_vf");
285 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
286 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
287 vf->set_sequence (false);
288 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
290 vf->examine_and_add_content (dcp);
291 BOOST_REQUIRE (!wait_for_jobs());
292 dcp->set_reference_video (true);
293 dcp->set_reference_audio (true);
294 dcp->set_trim_end (ContentTime::from_seconds(15));
295 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
297 /* Check that the selected reel assets are right */
298 auto a = get_referenced_reel_assets(vf, vf->playlist());
299 BOOST_REQUIRE_EQUAL (a.size(), 4U);
301 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
303 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
305 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
307 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
312 /** Test bug #1528 */
313 BOOST_AUTO_TEST_CASE (vf_test6)
316 auto ov = new_test_film ("vf_test6_ov");
317 ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
318 ov->set_reel_type (ReelType::BY_VIDEO_CONTENT);
319 auto video = content_factory("test/data/flat_red.png")[0];
320 ov->examine_and_add_content (video);
321 BOOST_REQUIRE (!wait_for_jobs());
322 video->video->set_length (24 * 10);
323 make_and_verify_dcp (ov);
326 auto vf = new_test_film ("vf_test6_vf");
327 vf->set_name ("vf_test6_vf");
328 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
329 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
330 vf->set_sequence (false);
331 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
332 vf->examine_and_add_content (dcp);
333 BOOST_REQUIRE (!wait_for_jobs());
334 dcp->set_reference_video (true);
335 dcp->set_reference_audio (true);
337 auto sub = content_factory("test/data/15s.srt")[0];
338 vf->examine_and_add_content (sub);
339 BOOST_REQUIRE (!wait_for_jobs());
341 make_and_verify_dcp (
344 dcp::VerificationNote::Code::EXTERNAL_ASSET,
345 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
346 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
351 /** Test bug #1643 (the second part; referring fails if there are gaps) */
352 BOOST_AUTO_TEST_CASE (vf_test7)
355 auto ov1 = new_test_film2 ("vf_test7_ov1", {content_factory("test/data/flat_red.png")[0]});
356 ov1->set_video_frame_rate (24);
357 make_and_verify_dcp (ov1);
360 auto ov2 = new_test_film2 ("vf_test7_ov2", {content_factory("test/data/flat_red.png")[0]});
361 ov2->set_video_frame_rate (24);
362 make_and_verify_dcp (ov2);
365 auto ov1_dcp = make_shared<DCPContent>(ov1->dir(ov1->dcp_name()));
366 auto ov2_dcp = make_shared<DCPContent>(ov2->dir(ov2->dcp_name()));
367 auto vf = new_test_film2 ("vf_test7_vf", {ov1_dcp, ov2_dcp});
368 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
369 ov1_dcp->set_reference_video (true);
370 ov2_dcp->set_reference_video (true);
371 ov1_dcp->set_position (vf, DCPTime::from_seconds(1));
372 ov2_dcp->set_position (vf, DCPTime::from_seconds(20));
373 vf->write_metadata ();
374 make_and_verify_dcp (vf);
378 /** Test bug #2116 */
379 BOOST_AUTO_TEST_CASE (test_vf_with_trimmed_multi_reel_dcp)
381 /* Make an OV with 3 reels */
382 std::vector<std::shared_ptr<Content>> ov_content;
383 for (int i = 0; i < 3; ++i) {
384 auto c = content_factory("test/data/flat_red.png")[0];
385 c->video->set_length(240);
386 ov_content.push_back(c);
388 auto ov = new_test_film2 ("test_vf_with_trimmed_multi_reel_dcp_ov", ov_content);
389 ov->set_reel_type(ReelType::BY_VIDEO_CONTENT);
390 make_and_verify_dcp (ov);
392 /* Make a VF with a specific arrangement */
393 auto vf_image = content_factory("test/data/flat_red.png")[0];
394 auto vf_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
395 auto vf = new_test_film2 ("test_vf_with_trimmed_multi_reel_dcp_vf", { vf_image, vf_dcp });
396 vf->set_reel_type(ReelType::BY_VIDEO_CONTENT);
397 vf_dcp->set_reference_video(true);
398 vf_dcp->set_reference_audio(true);
399 vf_dcp->set_trim_start(vf, ContentTime::from_seconds(10));
400 vf_dcp->set_position(vf, DCPTime::from_seconds(10));
401 make_and_verify_dcp (vf, { dcp::VerificationNote::Code::EXTERNAL_ASSET });
405 /** Test bug #2599: unable to reference open subtitles in an OV when creating a VF that adds closed captions */
406 BOOST_AUTO_TEST_CASE(test_referencing_ov_with_subs_when_adding_ccaps)
408 string const name("test_referencing_ov_with_subs_when_adding_ccaps");
409 auto subs = content_factory("test/data/15s.srt");
410 auto ov = new_test_film2(name + "_ov", subs);
414 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
415 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
416 dcp::VerificationNote::Code::MISSING_CPL_METADATA
419 auto ccaps = content_factory("test/data/15s.srt")[0];
420 auto ov_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
421 auto vf = new_test_film2(name + "_vf", { ov_dcp, ccaps });
422 ccaps->text[0]->set_type(TextType::CLOSED_CAPTION);
425 BOOST_CHECK(ov_dcp->can_reference_text(vf, TextType::OPEN_SUBTITLE, why_not));
426 std::cout << why_not << "\n";
430 BOOST_AUTO_TEST_CASE(test_duplicate_font_id_in_vf)
432 string const name("test_duplicate_font_id_in_vf");
433 auto subs = content_factory("test/data/15s.srt");
434 auto ov = new_test_film2(name + "_ov", subs);
438 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
439 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
440 dcp::VerificationNote::Code::MISSING_CPL_METADATA
443 auto ccaps = content_factory("test/data/15s.srt")[0];
444 auto ov_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
445 auto vf = new_test_film2(name + "_vf", { ov_dcp, ccaps });
446 ov_dcp->set_reference_audio(true);
447 ov_dcp->set_reference_video(true);
448 ov_dcp->text[0]->set_use(true);
449 ccaps->text[0]->set_type(TextType::CLOSED_CAPTION);
451 BOOST_CHECK_MESSAGE(ov_dcp->can_reference_text(vf, TextType::OPEN_SUBTITLE, why_not), why_not);
452 ov_dcp->set_reference_text(TextType::OPEN_SUBTITLE, true);
453 vf->write_metadata();
454 make_dcp(vf, TranscodeJob::ChangedBehaviour::IGNORE);
455 BOOST_REQUIRE(!wait_for_jobs());
457 auto vf_dcp = make_shared<DCPContent>(vf->dir(vf->dcp_name(false)));
459 auto test = new_test_film2(name + "_test", { vf_dcp });
460 vf_dcp->add_ov(ov->dir(ov->dcp_name(false)));
461 JobManager::instance()->add(make_shared<ExamineContentJob>(test, vf_dcp));
462 BOOST_CHECK(!wait_for_jobs());
467 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
468 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
469 dcp::VerificationNote::Code::MISSING_CPL_METADATA,