Debug for strange test failure in threed_test.
[dcpomatic.git] / test / vf_test.cc
1 /*
2     Copyright (C) 2015-2019 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 /** @file  test/vf_Test.cc
22  *  @brief Various VF-related tests.
23  *  @ingroup specific
24  */
25
26 #include "lib/film.h"
27 #include "lib/dcp_content.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/content_factory.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/video_content.h"
32 #include "lib/referenced_reel_asset.h"
33 #include "lib/player.h"
34 #include "test.h"
35 #include <dcp/cpl.h>
36 #include <dcp/reel.h>
37 #include <dcp/reel_picture_asset.h>
38 #include <dcp/reel_sound_asset.h>
39 #include <boost/test/unit_test.hpp>
40 #include <boost/foreach.hpp>
41 #include <iostream>
42
43 using std::list;
44 using std::string;
45 using std::cout;
46 using boost::shared_ptr;
47 using boost::dynamic_pointer_cast;
48 using namespace dcpomatic;
49
50 /** Test the logic which decides whether a DCP can be referenced or not */
51 BOOST_AUTO_TEST_CASE (vf_test1)
52 {
53         shared_ptr<Film> film = new_test_film ("vf_test1");
54         film->set_interop (false);
55         shared_ptr<DCPContent> dcp (new DCPContent ("test/data/reels_test2"));
56         film->examine_and_add_content (dcp);
57         BOOST_REQUIRE (!wait_for_jobs());
58
59         /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
60         film->set_reel_type (REELTYPE_SINGLE);
61         string why_not;
62         BOOST_CHECK (!dcp->can_reference_video(film, why_not));
63         BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
64         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
65         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
66
67         /* Multi-reel DCP can be referenced if we are using by-video-content */
68         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
69         BOOST_CHECK (dcp->can_reference_video(film, why_not));
70         BOOST_CHECK (dcp->can_reference_audio(film, why_not));
71         /* (but reels_test2 has no texts to reference) */
72         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
73         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
74
75         shared_ptr<FFmpegContent> other (new FFmpegContent("test/data/test.mp4"));
76         film->examine_and_add_content (other);
77         BOOST_REQUIRE (!wait_for_jobs());
78
79         /* Not possible if there is overlap */
80         other->set_position (film, DCPTime());
81         BOOST_CHECK (!dcp->can_reference_video(film, why_not));
82         BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
83         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
84         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
85
86         /* This should not be considered an overlap */
87         other->set_position (film, dcp->end(film));
88         BOOST_CHECK (dcp->can_reference_video(film, why_not));
89         BOOST_CHECK (dcp->can_reference_audio(film, why_not));
90         /* (reels_test2 has no texts to reference) */
91         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
92         BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
93 }
94
95 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
96 BOOST_AUTO_TEST_CASE (vf_test2)
97 {
98         /* Make the OV */
99         shared_ptr<Film> ov = new_test_film ("vf_test2_ov");
100         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
101         ov->set_name ("vf_test2_ov");
102         shared_ptr<Content> video = content_factory ("test/data/flat_red.png").front();
103         ov->examine_and_add_content (video);
104         BOOST_REQUIRE (!wait_for_jobs());
105         video->video->set_length (24 * 5);
106         shared_ptr<Content> audio = content_factory ("test/data/white.wav").front();
107         ov->examine_and_add_content (audio);
108         BOOST_REQUIRE (!wait_for_jobs());
109         ov->make_dcp ();
110         BOOST_REQUIRE (!wait_for_jobs());
111
112         /* Make the VF */
113         shared_ptr<Film> vf = new_test_film ("vf_test2_vf");
114         vf->set_name ("vf_test2_vf");
115         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
116         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
117         shared_ptr<DCPContent> dcp (new DCPContent(ov->dir (ov->dcp_name ())));
118         BOOST_REQUIRE (dcp);
119         vf->examine_and_add_content (dcp);
120         BOOST_REQUIRE (!wait_for_jobs());
121         dcp->set_reference_video (true);
122         dcp->set_reference_audio (true);
123         shared_ptr<Content> sub = content_factory("test/data/subrip4.srt").front();
124         vf->examine_and_add_content (sub);
125         BOOST_REQUIRE (!wait_for_jobs());
126         vf->make_dcp ();
127         BOOST_REQUIRE (!wait_for_jobs());
128         vf->write_metadata ();
129
130         dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
131         ov_c.read ();
132         BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
133         BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
134         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
135         string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
136         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
137         string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
138         BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
139
140         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
141         vf_c.read ();
142         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
143         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
144         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
145         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->id(), pic_id);
146         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
147         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->id(), sound_id);
148         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_subtitle());
149 }
150
151 /** Test creation of a VF using a trimmed OV; the output should have entry point /
152  *  duration altered to effect the trimming.
153  */
154 BOOST_AUTO_TEST_CASE (vf_test3)
155 {
156         /* Make the OV */
157         shared_ptr<Film> ov = new_test_film ("vf_test3_ov");
158         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
159         ov->set_name ("vf_test3_ov");
160         shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
161         ov->examine_and_add_content (video);
162         BOOST_REQUIRE (!wait_for_jobs());
163         video->video->set_length (24 * 5);
164         shared_ptr<Content> audio = content_factory("test/data/white.wav").front();
165         ov->examine_and_add_content (audio);
166         BOOST_REQUIRE (!wait_for_jobs());
167         ov->make_dcp ();
168         BOOST_REQUIRE (!wait_for_jobs());
169
170         /* Make the VF */
171         shared_ptr<Film> vf = new_test_film ("vf_test3_vf");
172         vf->set_name ("vf_test3_vf");
173         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
174         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
175         shared_ptr<DCPContent> dcp (new DCPContent(ov->dir(ov->dcp_name())));
176         BOOST_REQUIRE (dcp);
177         dcp->set_trim_start (ContentTime::from_seconds (1));
178         dcp->set_trim_end (ContentTime::from_seconds (1));
179         vf->examine_and_add_content (dcp);
180         BOOST_REQUIRE (!wait_for_jobs());
181         dcp->set_reference_video (true);
182         dcp->set_reference_audio (true);
183         vf->make_dcp ();
184         BOOST_REQUIRE (!wait_for_jobs());
185         vf->write_metadata ();
186
187         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
188         vf_c.read ();
189         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
190         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
191         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
192         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->entry_point().get_value_or(0), 24);
193         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->actual_duration(), 72);
194         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
195         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->entry_point().get_value_or(0), 24);
196         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->actual_duration(), 72);
197 }
198
199 /** Make a OV with video and audio and a VF referencing the OV and adding some more video */
200 BOOST_AUTO_TEST_CASE (vf_test4)
201 {
202         /* Make the OV */
203         shared_ptr<Film> ov = new_test_film ("vf_test4_ov");
204         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
205         ov->set_name ("vf_test4_ov");
206         shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
207         ov->examine_and_add_content (video);
208         BOOST_REQUIRE (!wait_for_jobs());
209         video->video->set_length (24 * 5);
210         shared_ptr<Content> audio = content_factory("test/data/white.wav").front();
211         ov->examine_and_add_content (audio);
212         BOOST_REQUIRE (!wait_for_jobs());
213         ov->make_dcp ();
214         BOOST_REQUIRE (!wait_for_jobs());
215
216         /* Make the VF */
217         shared_ptr<Film> vf = new_test_film ("vf_test4_vf");
218         vf->set_name ("vf_test4_vf");
219         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
220         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
221         vf->set_sequence (false);
222         shared_ptr<DCPContent> dcp (new DCPContent(ov->dir(ov->dcp_name())));
223         BOOST_REQUIRE (dcp);
224         vf->examine_and_add_content (dcp);
225         BOOST_REQUIRE (!wait_for_jobs());
226         dcp->set_position(vf, DCPTime::from_seconds(10));
227         dcp->set_reference_video (true);
228         dcp->set_reference_audio (true);
229         shared_ptr<Content> more_video = content_factory("test/data/flat_red.png").front();
230         vf->examine_and_add_content (more_video);
231         BOOST_REQUIRE (!wait_for_jobs());
232         more_video->set_position (vf, DCPTime());
233         vf->write_metadata ();
234         vf->make_dcp ();
235         BOOST_REQUIRE (!wait_for_jobs());
236
237         dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
238         ov_c.read ();
239         BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
240         BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
241         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
242         string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
243         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
244         string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
245         BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
246
247         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
248         vf_c.read ();
249         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
250         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 2);
251         BOOST_REQUIRE (vf_c.cpls().front()->reels().back()->main_picture());
252         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().back()->main_picture()->id(), pic_id);
253         BOOST_REQUIRE (vf_c.cpls().front()->reels().back()->main_sound());
254         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().back()->main_sound()->id(), sound_id);
255 }
256
257 /** Test bug #1495 */
258 BOOST_AUTO_TEST_CASE (vf_test5)
259 {
260         /* Make the OV */
261         shared_ptr<Film> ov = new_test_film ("vf_test5_ov");
262         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
263         ov->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
264         for (int i = 0; i < 3; ++i) {
265                 shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
266                 ov->examine_and_add_content (video);
267                 BOOST_REQUIRE (!wait_for_jobs());
268                 video->video->set_length (24 * 10);
269         }
270
271         BOOST_REQUIRE (!wait_for_jobs());
272         ov->make_dcp ();
273         BOOST_REQUIRE (!wait_for_jobs());
274
275         /* Make the VF */
276         shared_ptr<Film> vf = new_test_film ("vf_test5_vf");
277         vf->set_name ("vf_test5_vf");
278         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
279         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
280         vf->set_sequence (false);
281         shared_ptr<DCPContent> dcp (new DCPContent(ov->dir(ov->dcp_name())));
282         BOOST_REQUIRE (dcp);
283         vf->examine_and_add_content (dcp);
284         BOOST_REQUIRE (!wait_for_jobs());
285         dcp->set_reference_video (true);
286         dcp->set_reference_audio (true);
287         dcp->set_trim_end (ContentTime::from_seconds(15));
288         vf->make_dcp ();
289         BOOST_REQUIRE (!wait_for_jobs());
290
291         /* Check that the selected reel assets are right */
292         shared_ptr<Player> player (new Player(vf, vf->playlist()));
293         list<ReferencedReelAsset> a = player->get_reel_assets();
294         BOOST_REQUIRE_EQUAL (a.size(), 4);
295         list<ReferencedReelAsset>::const_iterator i = a.begin();
296         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
297         ++i;
298         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(0), DCPTime(960000)));
299         ++i;
300         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
301         ++i;
302         BOOST_CHECK (i->period == DCPTimePeriod(DCPTime(960000), DCPTime(1440000)));
303         ++i;
304 }
305
306 /** Test bug #1528 */
307 BOOST_AUTO_TEST_CASE (vf_test6)
308 {
309         /* Make the OV */
310         shared_ptr<Film> ov = new_test_film ("vf_test6_ov");
311         ov->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
312         ov->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
313         shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
314         ov->examine_and_add_content (video);
315         BOOST_REQUIRE (!wait_for_jobs());
316         video->video->set_length (24 * 10);
317         ov->make_dcp ();
318         BOOST_REQUIRE (!wait_for_jobs());
319
320         /* Make the VF */
321         shared_ptr<Film> vf = new_test_film ("vf_test6_vf");
322         vf->set_name ("vf_test6_vf");
323         vf->set_dcp_content_type (DCPContentType::from_isdcf_name("TST"));
324         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
325         vf->set_sequence (false);
326         shared_ptr<DCPContent> dcp (new DCPContent(ov->dir(ov->dcp_name())));
327         BOOST_REQUIRE (dcp);
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);
332
333         shared_ptr<Content> sub = content_factory("test/data/15s.srt").front();
334         vf->examine_and_add_content (sub);
335         BOOST_REQUIRE (!wait_for_jobs());
336
337         vf->make_dcp ();
338         BOOST_REQUIRE (!wait_for_jobs());
339 }