Use configured issuer/creator for DCPs made by map (#2585).
[dcpomatic.git] / test / vf_test.cc
1 /*
2     Copyright (C) 2015-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/vf_Test.cc
23  *  @brief Various VF-related tests.
24  *  @ingroup feature
25  */
26
27
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"
32 #include "lib/film.h"
33 #include "lib/player.h"
34 #include "lib/text_content.h"
35 #include "lib/referenced_reel_asset.h"
36 #include "lib/video_content.h"
37 #include "test.h"
38 #include <dcp/cpl.h>
39 #include <dcp/reel.h>
40 #include <dcp/reel_picture_asset.h>
41 #include <dcp/reel_sound_asset.h>
42 #include <boost/test/unit_test.hpp>
43 #include <iostream>
44
45
46 using std::cout;
47 using std::dynamic_pointer_cast;
48 using std::list;
49 using std::make_shared;
50 using std::shared_ptr;
51 using std::string;
52 using namespace dcpomatic;
53
54
55 /** Test the logic which decides whether a DCP can be referenced or not */
56 BOOST_AUTO_TEST_CASE (vf_test1)
57 {
58         auto film = new_test_film ("vf_test1");
59         film->set_interop (false);
60         auto dcp = make_shared<DCPContent>("test/data/reels_test2");
61         film->examine_and_add_content (dcp);
62         BOOST_REQUIRE (!wait_for_jobs());
63
64         /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
65         film->set_reel_type (ReelType::SINGLE);
66         string why_not;
67         BOOST_CHECK (!dcp->can_reference_video(film, why_not));
68         BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
69         BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
70         BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
71
72         /* Multi-reel DCP can be referenced if we are using by-video-content */
73         film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
74         BOOST_CHECK (dcp->can_reference_video(film, why_not));
75         BOOST_CHECK (dcp->can_reference_audio(film, why_not));
76         /* (but reels_test2 has no texts to reference) */
77         BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
78         BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
79
80         auto other = make_shared<FFmpegContent>("test/data/test.mp4");
81         film->examine_and_add_content (other);
82         BOOST_REQUIRE (!wait_for_jobs());
83         BOOST_CHECK (!other->audio);
84
85         /* Not possible if there is overlap; we only check video here as that's all test.mp4 has */
86         other->set_position (film, DCPTime());
87         BOOST_CHECK (!dcp->can_reference_video(film, why_not));
88
89         /* This should not be considered an overlap */
90         other->set_position (film, dcp->end(film));
91         BOOST_CHECK (dcp->can_reference_video(film, why_not));
92         BOOST_CHECK (dcp->can_reference_audio(film, why_not));
93         /* (reels_test2 has no texts to reference) */
94         BOOST_CHECK (!dcp->can_reference_text(film, TextType::OPEN_SUBTITLE, why_not));
95         BOOST_CHECK (!dcp->can_reference_text(film, TextType::CLOSED_CAPTION, why_not));
96 }
97
98
99 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
100 BOOST_AUTO_TEST_CASE (vf_test2)
101 {
102         /* Make the OV */
103         auto ov = new_test_film ("vf_test2_ov");
104         ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
105         ov->set_name ("vf_test2_ov");
106         auto video = content_factory("test/data/flat_red.png")[0];
107         ov->examine_and_add_content (video);
108         BOOST_REQUIRE (!wait_for_jobs());
109         video->video->set_length (24 * 5);
110         auto audio = content_factory("test/data/white.wav")[0];
111         ov->examine_and_add_content (audio);
112         BOOST_REQUIRE (!wait_for_jobs());
113         make_and_verify_dcp (ov);
114
115         /* Make the VF */
116         auto vf = new_test_film ("vf_test2_vf");
117         vf->set_name ("vf_test2_vf");
118         vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
119         vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
120         auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
121         vf->examine_and_add_content (dcp);
122         BOOST_REQUIRE (!wait_for_jobs());
123         dcp->set_reference_video (true);
124         dcp->set_reference_audio (true);
125         auto sub = content_factory("test/data/subrip4.srt")[0];
126         vf->examine_and_add_content (sub);
127         BOOST_REQUIRE (!wait_for_jobs());
128         make_and_verify_dcp (
129                 vf,
130                 {
131                         dcp::VerificationNote::Code::EXTERNAL_ASSET,
132                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
133                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
134                         dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION
135                 });
136
137         dcp::DCP ov_c (ov->dir(ov->dcp_name()));
138         ov_c.read ();
139         BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1U);
140         BOOST_REQUIRE_EQUAL (ov_c.cpls()[0]->reels().size(), 1U);
141         BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_picture());
142         string const pic_id = ov_c.cpls()[0]->reels()[0]->main_picture()->id();
143         BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_sound());
144         string const sound_id = ov_c.cpls()[0]->reels()[0]->main_sound()->id();
145         BOOST_REQUIRE (!ov_c.cpls()[0]->reels()[0]->main_subtitle());
146
147         dcp::DCP vf_c (vf->dir(vf->dcp_name()));
148         vf_c.read ();
149         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
150         BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 1U);
151         BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_picture());
152         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->id(), pic_id);
153         BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_sound());
154         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->id(), sound_id);
155         BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_subtitle());
156 }
157
158
159 /** Test creation of a VF using a trimmed OV; the output should have entry point /
160  *  duration altered to effect the trimming.
161  */
162 BOOST_AUTO_TEST_CASE (vf_test3)
163 {
164         /* Make the OV */
165         auto ov = new_test_film ("vf_test3_ov");
166         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
167         ov->set_name ("vf_test3_ov");
168         auto video = content_factory("test/data/flat_red.png")[0];
169         ov->examine_and_add_content (video);
170         BOOST_REQUIRE (!wait_for_jobs());
171         video->video->set_length (24 * 5);
172         auto audio = content_factory("test/data/white.wav")[0];
173         ov->examine_and_add_content (audio);
174         BOOST_REQUIRE (!wait_for_jobs());
175         make_and_verify_dcp (ov);
176
177         /* Make the VF */
178         auto vf = new_test_film ("vf_test3_vf");
179         vf->set_name ("vf_test3_vf");
180         vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
181         vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
182         auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
183         BOOST_REQUIRE (dcp);
184         dcp->set_trim_start(vf, ContentTime::from_seconds (1));
185         dcp->set_trim_end (ContentTime::from_seconds (1));
186         vf->examine_and_add_content (dcp);
187         BOOST_REQUIRE (!wait_for_jobs());
188         dcp->set_reference_video (true);
189         dcp->set_reference_audio (true);
190         make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
191
192         dcp::DCP vf_c (vf->dir(vf->dcp_name()));
193         vf_c.read ();
194         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
195         BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 1U);
196         BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_picture());
197         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->entry_point().get_value_or(0), 24);
198         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_picture()->actual_duration(), 72);
199         BOOST_REQUIRE (vf_c.cpls()[0]->reels()[0]->main_sound());
200         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->entry_point().get_value_or(0), 24);
201         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels()[0]->main_sound()->actual_duration(), 72);
202 }
203
204
205 /** Make a OV with video and audio and a VF referencing the OV and adding some more video */
206 BOOST_AUTO_TEST_CASE (vf_test4)
207 {
208         /* Make the OV */
209         auto ov = new_test_film ("vf_test4_ov");
210         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
211         ov->set_name ("vf_test4_ov");
212         auto video = content_factory("test/data/flat_red.png")[0];
213         ov->examine_and_add_content (video);
214         BOOST_REQUIRE (!wait_for_jobs());
215         video->video->set_length (24 * 5);
216         auto audio = content_factory("test/data/white.wav")[0];
217         ov->examine_and_add_content (audio);
218         BOOST_REQUIRE (!wait_for_jobs());
219         make_and_verify_dcp (ov);
220
221         /* Make the VF */
222         auto vf = new_test_film ("vf_test4_vf");
223         vf->set_name ("vf_test4_vf");
224         vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
225         vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
226         vf->set_sequence (false);
227         auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
228         BOOST_REQUIRE (dcp);
229         vf->examine_and_add_content (dcp);
230         BOOST_REQUIRE (!wait_for_jobs());
231         dcp->set_position(vf, DCPTime::from_seconds(10));
232         dcp->set_reference_video (true);
233         dcp->set_reference_audio (true);
234         auto more_video = content_factory("test/data/flat_red.png")[0];
235         vf->examine_and_add_content (more_video);
236         BOOST_REQUIRE (!wait_for_jobs());
237         more_video->set_position (vf, DCPTime());
238         vf->write_metadata ();
239         make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
240
241         dcp::DCP ov_c (ov->dir(ov->dcp_name()));
242         ov_c.read ();
243         BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1U);
244         BOOST_REQUIRE_EQUAL (ov_c.cpls()[0]->reels().size(), 1U);
245         BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_picture());
246         string const pic_id = ov_c.cpls()[0]->reels()[0]->main_picture()->id();
247         BOOST_REQUIRE (ov_c.cpls()[0]->reels()[0]->main_sound());
248         string const sound_id = ov_c.cpls()[0]->reels()[0]->main_sound()->id();
249         BOOST_REQUIRE (!ov_c.cpls()[0]->reels()[0]->main_subtitle());
250
251         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
252         vf_c.read ();
253         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1U);
254         BOOST_REQUIRE_EQUAL (vf_c.cpls()[0]->reels().size(), 2U);
255         BOOST_REQUIRE (vf_c.cpls()[0]->reels().back()->main_picture());
256         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels().back()->main_picture()->id(), pic_id);
257         BOOST_REQUIRE (vf_c.cpls()[0]->reels().back()->main_sound());
258         BOOST_CHECK_EQUAL (vf_c.cpls()[0]->reels().back()->main_sound()->id(), sound_id);
259 }
260
261
262 /** Test bug #1495 */
263 BOOST_AUTO_TEST_CASE (vf_test5)
264 {
265         /* Make the OV */
266         auto ov = new_test_film ("vf_test5_ov");
267         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
268         ov->set_reel_type (ReelType::BY_VIDEO_CONTENT);
269         for (int i = 0; i < 3; ++i) {
270                 auto video = content_factory("test/data/flat_red.png")[0];
271                 ov->examine_and_add_content (video);
272                 BOOST_REQUIRE (!wait_for_jobs());
273                 video->video->set_length (24 * 10);
274         }
275
276         BOOST_REQUIRE (!wait_for_jobs());
277         make_and_verify_dcp (ov);
278
279         /* Make the VF */
280         auto vf = new_test_film ("vf_test5_vf");
281         vf->set_name ("vf_test5_vf");
282         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
283         vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
284         vf->set_sequence (false);
285         auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
286         BOOST_REQUIRE (dcp);
287         vf->examine_and_add_content (dcp);
288         BOOST_REQUIRE (!wait_for_jobs());
289         dcp->set_reference_video (true);
290         dcp->set_reference_audio (true);
291         dcp->set_trim_end (ContentTime::from_seconds(15));
292         make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
293
294         /* Check that the selected reel assets are right */
295         auto a = get_referenced_reel_assets(vf, vf->playlist());
296         BOOST_REQUIRE_EQUAL (a.size(), 4U);
297         auto i = a.begin();
298         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
299         ++i;
300         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
301         ++i;
302         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
303         ++i;
304         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
305         ++i;
306 }
307
308
309 /** Test bug #1528 */
310 BOOST_AUTO_TEST_CASE (vf_test6)
311 {
312         /* Make the OV */
313         auto ov = new_test_film ("vf_test6_ov");
314         ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
315         ov->set_reel_type (ReelType::BY_VIDEO_CONTENT);
316         auto video = content_factory("test/data/flat_red.png")[0];
317         ov->examine_and_add_content (video);
318         BOOST_REQUIRE (!wait_for_jobs());
319         video->video->set_length (24 * 10);
320         make_and_verify_dcp (ov);
321
322         /* Make the VF */
323         auto vf = new_test_film ("vf_test6_vf");
324         vf->set_name ("vf_test6_vf");
325         vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
326         vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
327         vf->set_sequence (false);
328         auto dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
329         vf->examine_and_add_content (dcp);
330         BOOST_REQUIRE (!wait_for_jobs());
331         dcp->set_reference_video (true);
332         dcp->set_reference_audio (true);
333
334         auto sub = content_factory("test/data/15s.srt")[0];
335         vf->examine_and_add_content (sub);
336         BOOST_REQUIRE (!wait_for_jobs());
337
338         make_and_verify_dcp (
339                 vf,
340                 {
341                         dcp::VerificationNote::Code::EXTERNAL_ASSET,
342                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
343                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
344                 });
345 }
346
347
348 /** Test bug #1643 (the second part; referring fails if there are gaps) */
349 BOOST_AUTO_TEST_CASE (vf_test7)
350 {
351         /* First OV */
352         auto ov1 = new_test_film2 ("vf_test7_ov1", {content_factory("test/data/flat_red.png")[0]});
353         ov1->set_video_frame_rate (24);
354         make_and_verify_dcp (ov1);
355
356         /* Second OV */
357         auto ov2 = new_test_film2 ("vf_test7_ov2", {content_factory("test/data/flat_red.png")[0]});
358         ov2->set_video_frame_rate (24);
359         make_and_verify_dcp (ov2);
360
361         /* VF */
362         auto ov1_dcp = make_shared<DCPContent>(ov1->dir(ov1->dcp_name()));
363         auto ov2_dcp = make_shared<DCPContent>(ov2->dir(ov2->dcp_name()));
364         auto vf = new_test_film2 ("vf_test7_vf", {ov1_dcp, ov2_dcp});
365         vf->set_reel_type (ReelType::BY_VIDEO_CONTENT);
366         ov1_dcp->set_reference_video (true);
367         ov2_dcp->set_reference_video (true);
368         ov1_dcp->set_position (vf, DCPTime::from_seconds(1));
369         ov2_dcp->set_position (vf, DCPTime::from_seconds(20));
370         vf->write_metadata ();
371         make_and_verify_dcp (vf);
372 }
373
374
375 /** Test bug #2116 */
376 BOOST_AUTO_TEST_CASE (test_vf_with_trimmed_multi_reel_dcp)
377 {
378         /* Make an OV with 3 reels */
379         std::vector<std::shared_ptr<Content>> ov_content;
380         for (int i = 0; i < 3; ++i) {
381                 auto c = content_factory("test/data/flat_red.png")[0];
382                 c->video->set_length(240);
383                 ov_content.push_back(c);
384         }
385         auto ov = new_test_film2 ("test_vf_with_trimmed_multi_reel_dcp_ov", ov_content);
386         ov->set_reel_type(ReelType::BY_VIDEO_CONTENT);
387         make_and_verify_dcp (ov);
388
389         /* Make a VF with a specific arrangement */
390         auto vf_image = content_factory("test/data/flat_red.png")[0];
391         auto vf_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name()));
392         auto vf = new_test_film2 ("test_vf_with_trimmed_multi_reel_dcp_vf", { vf_image, vf_dcp });
393         vf->set_reel_type(ReelType::BY_VIDEO_CONTENT);
394         vf_dcp->set_reference_video(true);
395         vf_dcp->set_reference_audio(true);
396         vf_dcp->set_trim_start(vf, ContentTime::from_seconds(10));
397         vf_dcp->set_position(vf, DCPTime::from_seconds(10));
398         make_and_verify_dcp (vf, { dcp::VerificationNote::Code::EXTERNAL_ASSET });
399 }
400
401
402 /** Test bug #2599: unable to reference open subtitles in an OV when creating a VF that adds closed captions */
403 BOOST_AUTO_TEST_CASE(test_referencing_ov_with_subs_when_adding_ccaps)
404 {
405         string const name("test_referencing_ov_with_subs_when_adding_ccaps");
406         auto subs = content_factory("test/data/15s.srt");
407         auto ov = new_test_film2(name + "_ov", subs);
408         make_and_verify_dcp(
409                 ov,
410                 {
411                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
412                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
413                         dcp::VerificationNote::Code::MISSING_CPL_METADATA
414                 });
415
416         auto ccaps = content_factory("test/data/15s.srt")[0];
417         auto ov_dcp = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
418         auto vf = new_test_film2(name + "_vf", { ov_dcp, ccaps });
419         ccaps->text[0]->set_type(TextType::CLOSED_CAPTION);
420
421         string why_not;
422         BOOST_CHECK(ov_dcp->can_reference_text(vf, TextType::OPEN_SUBTITLE, why_not));
423         std::cout << why_not << "\n";
424 }
425