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/ffmpeg_content.h"
33 #include "lib/player.h"
34 #include "lib/referenced_reel_asset.h"
35 #include "lib/video_content.h"
39 #include <dcp/reel_picture_asset.h>
40 #include <dcp/reel_sound_asset.h>
41 #include <boost/test/unit_test.hpp>
46 using std::dynamic_pointer_cast;
48 using std::make_shared;
49 using std::shared_ptr;
51 using namespace dcpomatic;
54 /** Test the logic which decides whether a DCP can be referenced or not */
55 BOOST_AUTO_TEST_CASE (vf_test1)
57 auto film = new_test_film ("vf_test1");
58 film->set_interop (false);
59 auto dcp = make_shared<DCPContent>("test/data/reels_test2");
60 film->examine_and_add_content (dcp);
61 BOOST_REQUIRE (!wait_for_jobs());
63 /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
64 film->set_reel_type (ReelType::SINGLE);
66 BOOST_CHECK (!dcp->can_reference_video(film, why_not));
67 BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
68 BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
69 BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
71 /* Multi-reel DCP can be referenced if we are using by-video-content */
72 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
73 BOOST_CHECK (dcp->can_reference_video(film, why_not));
74 BOOST_CHECK (dcp->can_reference_audio(film, why_not));
75 /* (but reels_test2 has no texts to reference) */
76 BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
77 BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
79 auto other = make_shared<FFmpegContent>("test/data/test.mp4");
80 film->examine_and_add_content (other);
81 BOOST_REQUIRE (!wait_for_jobs());
82 BOOST_CHECK (!other->audio);
84 /* Not possible if there is overlap; we only check video here as that's all test.mp4 has */
85 other->set_position (film, DCPTime());
86 BOOST_CHECK (!dcp->can_reference_video(film, why_not));
88 /* This should not be considered an overlap */
89 other->set_position (film, dcp->end(film));
90 BOOST_CHECK (dcp->can_reference_video(film, why_not));
91 BOOST_CHECK (dcp->can_reference_audio(film, why_not));
92 /* (reels_test2 has no texts to reference) */
93 BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
94 BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
98 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
99 BOOST_AUTO_TEST_CASE (vf_test2)
102 auto ov = new_test_film ("vf_test2_ov");
103 ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
104 ov->set_name ("vf_test2_ov");
105 auto video = content_factory("test/data/flat_red.png")[0];
106 ov->examine_and_add_content (video);
107 BOOST_REQUIRE (!wait_for_jobs());
108 video->video->set_length (24 * 5);
109 auto audio = content_factory("test/data/white.wav")[0];
110 ov->examine_and_add_content (audio);
111 BOOST_REQUIRE (!wait_for_jobs());
112 make_and_verify_dcp (ov);
115 auto vf = new_test_film ("vf_test2_vf");
116 vf->set_name ("vf_test2_vf");
117 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
118 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
119 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
120 vf->examine_and_add_content (dcp);
121 BOOST_REQUIRE (!wait_for_jobs());
122 dcp->set_reference_video (true);
123 dcp->set_reference_audio (true);
124 auto sub = content_factory("test/data/subrip4.srt")[0];
125 vf->examine_and_add_content (sub);
126 BOOST_REQUIRE (!wait_for_jobs());
127 make_and_verify_dcp (
130 dcp::VerificationNote::Code::EXTERNAL_ASSET,
131 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
132 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
133 dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION
136 dcp::DCP ov_c (ov->dir(ov->dcp_name()));
138 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1U);
139 BOOST_REQUIRE_EQUAL (ov_c.cpls()[0]->reels().size(), 1U);
140 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_picture());
141 string const pic_id = ov_c.cpls()[0]->reels()[0]->main_picture()->id();
142 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_sound());
143 string const sound_id = ov_c.cpls()[0]->reels()[0]->main_sound()->id();
144 BOOST_REQUIRE (!ov_c.cpls()[0]->reels()[0]->main_subtitle());
146 dcp::DCP vf_c (vf->dir(vf->dcp_name()));
148 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
149 BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 1U);
150 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_picture());
151 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->id(), pic_id);
152 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_sound());
153 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->id(), sound_id);
154 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_subtitle());
158 /** Test creation of a VF using a trimmed OV; the output should have entry point /
159 * duration altered to effect the trimming.
161 BOOST_AUTO_TEST_CASE (vf_test3)
164 auto ov = new_test_film ("vf_test3_ov");
165 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
166 ov->set_name ("vf_test3_ov");
167 auto video = content_factory("test/data/flat_red.png")[0];
168 ov->examine_and_add_content (video);
169 BOOST_REQUIRE (!wait_for_jobs());
170 video->video->set_length (24 * 5);
171 auto audio = content_factory("test/data/white.wav")[0];
172 ov->examine_and_add_content (audio);
173 BOOST_REQUIRE (!wait_for_jobs());
174 make_and_verify_dcp (ov);
177 auto vf = new_test_film ("vf_test3_vf");
178 vf->set_name ("vf_test3_vf");
179 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
180 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
181 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
183 dcp->set_trim_start(vf, ContentTime::from_seconds (1));
184 dcp->set_trim_end (ContentTime::from_seconds (1));
185 vf->examine_and_add_content (dcp);
186 BOOST_REQUIRE (!wait_for_jobs());
187 dcp->set_reference_video (true);
188 dcp->set_reference_audio (true);
189 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
191 dcp::DCP vf_c (vf->dir(vf->dcp_name()));
193 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
194 BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 1U);
195 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_picture());
196 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->entry_point().get_value_or(0), 24);
197 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->actual_duration(), 72);
198 BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_sound());
199 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->entry_point().get_value_or(0), 24);
200 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->actual_duration(), 72);
204 /** Make a OV with video and audio and a VF referencing the OV and adding some more video */
205 BOOST_AUTO_TEST_CASE (vf_test4)
208 auto ov = new_test_film ("vf_test4_ov");
209 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
210 ov->set_name ("vf_test4_ov");
211 auto video = content_factory("test/data/flat_red.png")[0];
212 ov->examine_and_add_content (video);
213 BOOST_REQUIRE (!wait_for_jobs());
214 video->video->set_length (24 * 5);
215 auto audio = content_factory("test/data/white.wav")[0];
216 ov->examine_and_add_content (audio);
217 BOOST_REQUIRE (!wait_for_jobs());
218 make_and_verify_dcp (ov);
221 auto vf = new_test_film ("vf_test4_vf");
222 vf->set_name ("vf_test4_vf");
223 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
224 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
225 vf->set_sequence (false);
226 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
228 vf->examine_and_add_content (dcp);
229 BOOST_REQUIRE (!wait_for_jobs());
230 dcp->set_position(vf, DCPTime::from_seconds(10));
231 dcp->set_reference_video (true);
232 dcp->set_reference_audio (true);
233 auto more_video = content_factory("test/data/flat_red.png")[0];
234 vf->examine_and_add_content (more_video);
235 BOOST_REQUIRE (!wait_for_jobs());
236 more_video->set_position (vf, DCPTime());
237 vf->write_metadata ();
238 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
240 dcp::DCP ov_c (ov->dir(ov->dcp_name()));
242 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1U);
243 BOOST_REQUIRE_EQUAL (ov_c.cpls()[0]->reels().size(), 1U);
244 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_picture());
245 string const pic_id = ov_c.cpls()[0]->reels()[0]->main_picture()->id();
246 BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_sound());
247 string const sound_id = ov_c.cpls()[0]->reels()[0]->main_sound()->id();
248 BOOST_REQUIRE (!ov_c.cpls()[0]->reels()[0]->main_subtitle());
250 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
252 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
253 BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 2U);
254 BOOST_REQUIRE (vf_c.cpls()[0]->reels().back()->main_picture());
255 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels().back()->main_picture()->id(), pic_id);
256 BOOST_REQUIRE (vf_c.cpls()[0]->reels().back()->main_sound());
257 BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels().back()->main_sound()->id(), sound_id);
261 /** Test bug #1495 */
262 BOOST_AUTO_TEST_CASE (vf_test5)
265 auto ov = new_test_film ("vf_test5_ov");
266 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
267 ov->set_reel_type (ReelType::BY_VIDEO_CONTENT);
268 for (int i = 0; i < 3; ++i) {
269 auto video = content_factory("test/data/flat_red.png")[0];
270 ov->examine_and_add_content (video);
271 BOOST_REQUIRE (!wait_for_jobs());
272 video->video->set_length (24 * 10);
275 BOOST_REQUIRE (!wait_for_jobs());
276 make_and_verify_dcp (ov);
279 auto vf = new_test_film ("vf_test5_vf");
280 vf->set_name ("vf_test5_vf");
281 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
282 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
283 vf->set_sequence (false);
284 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
286 vf->examine_and_add_content (dcp);
287 BOOST_REQUIRE (!wait_for_jobs());
288 dcp->set_reference_video (true);
289 dcp->set_reference_audio (true);
290 dcp->set_trim_end (ContentTime::from_seconds(15));
291 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
293 /* Check that the selected reel assets are right */
294 auto a = get_referenced_reel_assets(vf, vf->playlist());
295 BOOST_REQUIRE_EQUAL (a.size(), 4U);
297 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
299 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
301 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
303 BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
308 /** Test bug #1528 */
309 BOOST_AUTO_TEST_CASE (vf_test6)
312 auto ov = new_test_film ("vf_test6_ov");
313 ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
314 ov->set_reel_type (ReelType::BY_VIDEO_CONTENT);
315 auto video = content_factory("test/data/flat_red.png")[0];
316 ov->examine_and_add_content (video);
317 BOOST_REQUIRE (!wait_for_jobs());
318 video->video->set_length (24 * 10);
319 make_and_verify_dcp (ov);
322 auto vf = new_test_film ("vf_test6_vf");
323 vf->set_name ("vf_test6_vf");
324 vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
325 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
326 vf->set_sequence (false);
327 auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
328 vf->examine_and_add_content (dcp);
329 BOOST_REQUIRE (!wait_for_jobs());
330 dcp->set_reference_video (true);
331 dcp->set_reference_audio (true);
333 auto sub = content_factory("test/data/15s.srt")[0];
334 vf->examine_and_add_content (sub);
335 BOOST_REQUIRE (!wait_for_jobs());
337 make_and_verify_dcp (
340 dcp::VerificationNote::Code::EXTERNAL_ASSET,
341 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
342 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
347 /** Test bug #1643 (the second part; referring fails if there are gaps) */
348 BOOST_AUTO_TEST_CASE (vf_test7)
351 auto ov1 = new_test_film2 ("vf_test7_ov1", {content_factory("test/data/flat_red.png")[0]});
352 ov1->set_video_frame_rate (24);
353 make_and_verify_dcp (ov1);
356 auto ov2 = new_test_film2 ("vf_test7_ov2", {content_factory("test/data/flat_red.png")[0]});
357 ov2->set_video_frame_rate (24);
358 make_and_verify_dcp (ov2);
361 auto ov1_dcp = make_shared<DCPContent>(ov1->dir(ov1->dcp_name()));
362 auto ov2_dcp = make_shared<DCPContent>(ov2->dir(ov2->dcp_name()));
363 auto vf = new_test_film2 ("vf_test7_vf", {ov1_dcp, ov2_dcp});
364 vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
365 ov1_dcp->set_reference_video (true);
366 ov2_dcp->set_reference_video (true);
367 ov1_dcp->set_position (vf, DCPTime::from_seconds(1));
368 ov2_dcp->set_position (vf, DCPTime::from_seconds(20));
369 vf->write_metadata ();
370 make_and_verify_dcp (vf);
374 /** Test bug #2116 */
375 BOOST_AUTO_TEST_CASE (test_vf_with_trimmed_multi_reel_dcp)
377 /* Make an OV with 3 reels */
378 std::vector<std::shared_ptr<Content>> ov_content;
379 for (int i = 0; i < 3; ++i) {
380 auto c = content_factory("test/data/flat_red.png")[0];
381 c->video->set_length(240);
382 ov_content.push_back(c);
384 auto ov = new_test_film2 ("test_vf_with_trimmed_multi_reel_dcp_ov", ov_content);
385 ov->set_reel_type(ReelType::BY_VIDEO_CONTENT);
386 make_and_verify_dcp (ov);
388 /* Make a VF with a specific arrangement */
389 auto vf_image = content_factory("test/data/flat_red.png")[0];
390 auto vf_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
391 auto vf = new_test_film2 ("test_vf_with_trimmed_multi_reel_dcp_vf", { vf_image, vf_dcp });
392 vf->set_reel_type(ReelType::BY_VIDEO_CONTENT);
393 vf_dcp->set_reference_video(true);
394 vf_dcp->set_reference_audio(true);
395 vf_dcp->set_trim_start(vf, ContentTime::from_seconds(10));
396 vf_dcp->set_position(vf, DCPTime::from_seconds(10));
397 make_and_verify_dcp (vf, { dcp::VerificationNote::Code::EXTERNAL_ASSET });