2 Copyright (C) 2015-2019 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/>.
21 /** @file test/reels_test.cc
22 * @brief Check manipulation of reels in various ways.
27 #include "lib/ratio.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/image_content.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/dcp_content.h"
32 #include "lib/video_content.h"
33 #include "lib/string_text_file_content.h"
34 #include "lib/content_factory.h"
36 #include <boost/test/unit_test.hpp>
37 #include <boost/foreach.hpp>
42 using boost::shared_ptr;
43 using namespace dcpomatic;
45 /** Test Film::reels() */
46 BOOST_AUTO_TEST_CASE (reels_test1)
48 shared_ptr<Film> film = new_test_film ("reels_test1");
49 film->set_container (Ratio::from_id ("185"));
50 shared_ptr<FFmpegContent> A (new FFmpegContent("test/data/test.mp4"));
51 film->examine_and_add_content (A);
52 shared_ptr<FFmpegContent> B (new FFmpegContent("test/data/test.mp4"));
53 film->examine_and_add_content (B);
54 BOOST_REQUIRE (!wait_for_jobs());
55 BOOST_CHECK_EQUAL (A->full_length(film).get(), 288000);
57 film->set_reel_type (REELTYPE_SINGLE);
58 list<DCPTimePeriod> r = film->reels ();
59 BOOST_CHECK_EQUAL (r.size(), 1);
60 BOOST_CHECK_EQUAL (r.front().from.get(), 0);
61 BOOST_CHECK_EQUAL (r.front().to.get(), 288000 * 2);
63 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
65 BOOST_CHECK_EQUAL (r.size(), 2);
66 BOOST_CHECK_EQUAL (r.front().from.get(), 0);
67 BOOST_CHECK_EQUAL (r.front().to.get(), 288000);
68 BOOST_CHECK_EQUAL (r.back().from.get(), 288000);
69 BOOST_CHECK_EQUAL (r.back().to.get(), 288000 * 2);
71 film->set_j2k_bandwidth (100000000);
72 film->set_reel_type (REELTYPE_BY_LENGTH);
73 /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
74 film->set_reel_length (31253154);
76 BOOST_CHECK_EQUAL (r.size(), 3);
77 list<DCPTimePeriod>::const_iterator i = r.begin ();
78 BOOST_CHECK_EQUAL (i->from.get(), 0);
79 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_frames(60, 24).get());
81 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_frames(60, 24).get());
82 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_frames(120, 24).get());
84 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_frames(120, 24).get());
85 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_frames(144, 24).get());
88 /** Make a short DCP with multi reels split by video content, then import
89 * this into a new project and make a new DCP referencing it.
91 BOOST_AUTO_TEST_CASE (reels_test2)
93 shared_ptr<Film> film = new_test_film ("reels_test2");
94 film->set_name ("reels_test2");
95 film->set_container (Ratio::from_id ("185"));
96 film->set_interop (false);
97 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
100 shared_ptr<ImageContent> c (new ImageContent("test/data/flat_red.png"));
101 film->examine_and_add_content (c);
102 BOOST_REQUIRE (!wait_for_jobs());
103 c->video->set_length (24);
107 shared_ptr<ImageContent> c (new ImageContent("test/data/flat_green.png"));
108 film->examine_and_add_content (c);
109 BOOST_REQUIRE (!wait_for_jobs());
110 c->video->set_length (24);
114 shared_ptr<ImageContent> c (new ImageContent("test/data/flat_blue.png"));
115 film->examine_and_add_content (c);
116 BOOST_REQUIRE (!wait_for_jobs());
117 c->video->set_length (24);
120 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
121 BOOST_REQUIRE (!wait_for_jobs());
124 BOOST_REQUIRE (!wait_for_jobs());
126 check_dcp ("test/data/reels_test2", film->dir (film->dcp_name()));
128 shared_ptr<Film> film2 = new_test_film ("reels_test2b");
129 film2->set_name ("reels_test2b");
130 film2->set_container (Ratio::from_id ("185"));
131 film2->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
132 film2->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
134 shared_ptr<DCPContent> c (new DCPContent(film->dir(film->dcp_name())));
135 film2->examine_and_add_content (c);
136 BOOST_REQUIRE (!wait_for_jobs ());
138 list<DCPTimePeriod> r = film2->reels ();
139 BOOST_CHECK_EQUAL (r.size(), 3);
140 list<DCPTimePeriod>::const_iterator i = r.begin ();
141 BOOST_CHECK_EQUAL (i->from.get(), 0);
142 BOOST_CHECK_EQUAL (i->to.get(), 96000);
144 BOOST_CHECK_EQUAL (i->from.get(), 96000);
145 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 2);
147 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 2);
148 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 3);
150 c->set_reference_video (true);
151 c->set_reference_audio (true);
154 BOOST_REQUIRE (!wait_for_jobs());
157 /** Check that REELTYPE_BY_VIDEO_CONTENT adds an extra reel, if necessary, at the end
158 * of all the video content to mop up anything afterward.
160 BOOST_AUTO_TEST_CASE (reels_test3)
162 shared_ptr<Film> film = new_test_film ("reels_test3");
163 film->set_name ("reels_test3");
164 film->set_container (Ratio::from_id ("185"));
165 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
166 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
168 shared_ptr<Content> dcp (new DCPContent("test/data/reels_test2"));
169 film->examine_and_add_content (dcp);
170 shared_ptr<Content> sub (new StringTextFileContent("test/data/subrip.srt"));
171 film->examine_and_add_content (sub);
172 BOOST_REQUIRE (!wait_for_jobs());
174 list<DCPTimePeriod> reels = film->reels();
175 BOOST_REQUIRE_EQUAL (reels.size(), 4);
176 list<DCPTimePeriod>::const_iterator i = reels.begin ();
177 BOOST_CHECK_EQUAL (i->from.get(), 0);
178 BOOST_CHECK_EQUAL (i->to.get(), 96000);
180 BOOST_CHECK_EQUAL (i->from.get(), 96000);
181 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 2);
183 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 2);
184 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 3);
186 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 3);
187 BOOST_CHECK_EQUAL (i->to.get(), sub->full_length(film).ceil(film->video_frame_rate()).get());
190 /** Check creation of a multi-reel DCP with a single .srt subtitle file;
191 * make sure that the reel subtitle timing is done right.
193 BOOST_AUTO_TEST_CASE (reels_test4)
195 shared_ptr<Film> film = new_test_film ("reels_test4");
196 film->set_name ("reels_test4");
197 film->set_container (Ratio::from_id ("185"));
198 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
199 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
200 film->set_interop (false);
202 /* 4 piece of 1s-long content */
203 shared_ptr<ImageContent> content[4];
204 for (int i = 0; i < 4; ++i) {
205 content[i].reset (new ImageContent("test/data/flat_green.png"));
206 film->examine_and_add_content (content[i]);
207 BOOST_REQUIRE (!wait_for_jobs());
208 content[i]->video->set_length (24);
211 shared_ptr<StringTextFileContent> subs (new StringTextFileContent("test/data/subrip3.srt"));
212 film->examine_and_add_content (subs);
213 BOOST_REQUIRE (!wait_for_jobs());
215 list<DCPTimePeriod> reels = film->reels();
216 BOOST_REQUIRE_EQUAL (reels.size(), 4);
217 list<DCPTimePeriod>::const_iterator i = reels.begin ();
218 BOOST_CHECK_EQUAL (i->from.get(), 0);
219 BOOST_CHECK_EQUAL (i->to.get(), 96000);
221 BOOST_CHECK_EQUAL (i->from.get(), 96000);
222 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 2);
224 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 2);
225 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 3);
227 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 3);
228 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 4);
231 BOOST_REQUIRE (!wait_for_jobs());
233 check_dcp ("test/data/reels_test4", film->dir (film->dcp_name()));
236 BOOST_AUTO_TEST_CASE (reels_test5)
238 shared_ptr<Film> film = new_test_film ("reels_test5");
239 film->set_sequence (false);
240 shared_ptr<DCPContent> dcp (new DCPContent("test/data/reels_test4"));
241 film->examine_and_add_content (dcp);
242 BOOST_REQUIRE (!wait_for_jobs ());
244 /* Set to 2123 but it will be rounded up to the next frame (4000) */
245 dcp->set_position(film, DCPTime(2123));
248 list<DCPTimePeriod> p = dcp->reels (film);
249 BOOST_REQUIRE_EQUAL (p.size(), 4);
250 list<DCPTimePeriod>::const_iterator i = p.begin();
251 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 0), DCPTime(4000 + 96000)));
252 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 96000), DCPTime(4000 + 192000)));
253 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 192000), DCPTime(4000 + 288000)));
254 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 288000), DCPTime(4000 + 384000)));
258 dcp->set_trim_start (ContentTime::from_seconds (0.5));
259 list<DCPTimePeriod> p = dcp->reels (film);
260 BOOST_REQUIRE_EQUAL (p.size(), 4);
261 list<DCPTimePeriod>::const_iterator i = p.begin();
262 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 0), DCPTime(4000 + 48000)));
263 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 48000), DCPTime(4000 + 144000)));
264 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 144000), DCPTime(4000 + 240000)));
265 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 240000), DCPTime(4000 + 336000)));
269 dcp->set_trim_end (ContentTime::from_seconds (0.5));
270 list<DCPTimePeriod> p = dcp->reels (film);
271 BOOST_REQUIRE_EQUAL (p.size(), 4);
272 list<DCPTimePeriod>::const_iterator i = p.begin();
273 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 0), DCPTime(4000 + 48000)));
274 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 48000), DCPTime(4000 + 144000)));
275 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 144000), DCPTime(4000 + 240000)));
276 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 240000), DCPTime(4000 + 288000)));
280 dcp->set_trim_start (ContentTime::from_seconds (1.5));
281 list<DCPTimePeriod> p = dcp->reels (film);
282 BOOST_REQUIRE_EQUAL (p.size(), 3);
283 list<DCPTimePeriod>::const_iterator i = p.begin();
284 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 0), DCPTime(4000 + 48000)));
285 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 48000), DCPTime(4000 + 144000)));
286 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(4000 + 144000), DCPTime(4000 + 192000)));
290 /** Check reel split with a muxed video/audio source */
291 BOOST_AUTO_TEST_CASE (reels_test6)
293 shared_ptr<Film> film = new_test_film ("reels_test6");
294 film->set_name ("reels_test6");
295 film->set_container (Ratio::from_id ("185"));
296 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
297 shared_ptr<FFmpegContent> A (new FFmpegContent("test/data/test2.mp4"));
298 film->examine_and_add_content (A);
299 BOOST_REQUIRE (!wait_for_jobs ());
301 film->set_j2k_bandwidth (100000000);
302 film->set_reel_type (REELTYPE_BY_LENGTH);
303 /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
304 film->set_reel_length (31253154);
306 BOOST_REQUIRE (!wait_for_jobs ());
309 /** Check the case where the last bit of audio hangs over the end of the video
310 * and we are using REELTYPE_BY_VIDEO_CONTENT.
312 BOOST_AUTO_TEST_CASE (reels_test7)
314 shared_ptr<Film> film = new_test_film ("reels_test7");
315 film->set_name ("reels_test7");
316 film->set_container (Ratio::from_id ("185"));
317 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
318 shared_ptr<Content> A = content_factory("test/data/flat_red.png").front();
319 film->examine_and_add_content (A);
320 BOOST_REQUIRE (!wait_for_jobs ());
321 shared_ptr<Content> B = content_factory("test/data/awkward_length.wav").front();
322 film->examine_and_add_content (B);
323 BOOST_REQUIRE (!wait_for_jobs ());
324 film->set_video_frame_rate (24);
325 A->video->set_length (3 * 24);
327 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
328 BOOST_REQUIRE_EQUAL (film->reels().size(), 2);
329 BOOST_CHECK (film->reels().front() == DCPTimePeriod(DCPTime(0), DCPTime::from_frames(3 * 24, 24)));
330 BOOST_CHECK (film->reels().back() == DCPTimePeriod(DCPTime::from_frames(3 * 24, 24), DCPTime::from_frames(3 * 24 + 1, 24)));
333 BOOST_REQUIRE (!wait_for_jobs ());
336 /** Check a reels-related error; make_dcp() would raise a ProgrammingError */
337 BOOST_AUTO_TEST_CASE (reels_test8)
339 shared_ptr<Film> film = new_test_film ("reels_test8");
340 film->set_name ("reels_test8");
341 film->set_container (Ratio::from_id ("185"));
342 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
343 shared_ptr<FFmpegContent> A (new FFmpegContent("test/data/test2.mp4"));
344 film->examine_and_add_content (A);
345 BOOST_REQUIRE (!wait_for_jobs ());
347 A->set_trim_end (ContentTime::from_seconds (1));
349 BOOST_REQUIRE (!wait_for_jobs ());
352 /** Check another reels-related error; make_dcp() would raise a ProgrammingError */
353 BOOST_AUTO_TEST_CASE (reels_test9)
355 shared_ptr<Film> film = new_test_film2("reels_test9a");
356 shared_ptr<FFmpegContent> A(new FFmpegContent("test/data/flat_red.png"));
357 film->examine_and_add_content(A);
358 BOOST_REQUIRE(!wait_for_jobs());
359 A->video->set_length(5 * 24);
360 film->set_video_frame_rate(24);
362 BOOST_REQUIRE(!wait_for_jobs());
364 shared_ptr<Film> film2 = new_test_film2("reels_test9b");
365 shared_ptr<DCPContent> B(new DCPContent(film->dir(film->dcp_name())));
366 film2->examine_and_add_content(B);
367 film2->examine_and_add_content(content_factory("test/data/dcp_sub4.xml").front());
368 B->set_reference_video(true);
369 B->set_reference_audio(true);
370 BOOST_REQUIRE(!wait_for_jobs());
371 film2->set_reel_type(REELTYPE_BY_VIDEO_CONTENT);
372 film2->write_metadata();
374 BOOST_REQUIRE(!wait_for_jobs());
377 /** Another reels-related error; make_dcp() would raise a ProgrammingError
378 * in AudioBuffers::allocate due to an attempt to allocate a negatively-sized buffer.
379 * This was triggered by a VF where there are referenced audio reels followed by
380 * VF audio. When the VF audio arrives the Writer did not correctly skip over the
383 BOOST_AUTO_TEST_CASE (reels_test10)
386 shared_ptr<Film> ov = new_test_film2("reels_test10_ov");
387 shared_ptr<FFmpegContent> A(new FFmpegContent("test/data/flat_red.png"));
388 ov->examine_and_add_content (A);
389 BOOST_REQUIRE (!wait_for_jobs());
390 A->video->set_length (5 * 24);
392 shared_ptr<FFmpegContent> B(new FFmpegContent("test/data/flat_red.png"));
393 ov->examine_and_add_content (B);
394 BOOST_REQUIRE (!wait_for_jobs());
395 B->video->set_length (5 * 24);
397 ov->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
399 BOOST_REQUIRE (!wait_for_jobs());
400 ov->write_metadata ();
402 /* Now try to make the VF; this used to fail */
403 shared_ptr<Film> vf = new_test_film2("reels_test10_vf");
404 shared_ptr<DCPContent> ov_dcp(new DCPContent(ov->dir(ov->dcp_name())));
405 vf->examine_and_add_content (ov_dcp);
406 BOOST_REQUIRE (!wait_for_jobs());
407 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
408 ov_dcp->set_reference_video (true);
409 ov_dcp->set_reference_audio (true);
410 vf->examine_and_add_content (content_factory("test/data/15s.srt").front());
411 BOOST_REQUIRE (!wait_for_jobs());
414 BOOST_REQUIRE (!wait_for_jobs());
415 vf->write_metadata ();
418 /** Another reels error; REELTYPE_BY_VIDEO_CONTENT when the first content is not
421 BOOST_AUTO_TEST_CASE (reels_test11)
423 shared_ptr<Film> film = new_test_film2 ("reels_test11");
424 film->set_video_frame_rate (24);
425 shared_ptr<FFmpegContent> A(new FFmpegContent("test/data/flat_red.png"));
426 film->examine_and_add_content (A);
427 BOOST_REQUIRE (!wait_for_jobs());
428 A->video->set_length (240);
429 A->set_video_frame_rate (24);
430 A->set_position (film, DCPTime::from_seconds(1));
431 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
433 BOOST_REQUIRE (!wait_for_jobs());
434 BOOST_CHECK_EQUAL (A->position().get(), DCPTime::from_seconds(1).get());
435 BOOST_CHECK_EQUAL (A->end(film).get(), DCPTime::from_seconds(1 + 10).get());
437 list<DCPTimePeriod> r = film->reels ();
438 BOOST_CHECK_EQUAL (r.size(), 2);
439 BOOST_CHECK_EQUAL (r.front().from.get(), 0);
440 BOOST_CHECK_EQUAL (r.front().to.get(), DCPTime::from_seconds(1).get());
441 BOOST_CHECK_EQUAL (r.back().from.get(), DCPTime::from_seconds(1).get());
442 BOOST_CHECK_EQUAL (r.back().to.get(), DCPTime::from_seconds(1 + 10).get());
445 /** For VFs to work right we have to make separate reels for empty bits between
448 BOOST_AUTO_TEST_CASE (reels_test12)
450 shared_ptr<Film> film = new_test_film2 ("reels_test12");
451 film->set_video_frame_rate (24);
452 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
453 film->set_sequence (false);
455 shared_ptr<FFmpegContent> A(new FFmpegContent("test/data/flat_red.png"));
456 film->examine_and_add_content (A);
457 BOOST_REQUIRE (!wait_for_jobs());
458 A->video->set_length (240);
459 A->set_video_frame_rate (24);
460 A->set_position (film, DCPTime::from_seconds(1));
462 shared_ptr<FFmpegContent> B(new FFmpegContent("test/data/flat_red.png"));
463 film->examine_and_add_content (B);
464 BOOST_REQUIRE (!wait_for_jobs());
465 B->video->set_length (120);
466 B->set_video_frame_rate (24);
467 B->set_position (film, DCPTime::from_seconds(14));
469 list<DCPTimePeriod> r = film->reels ();
470 BOOST_REQUIRE_EQUAL (r.size(), 4);
471 list<DCPTimePeriod>::const_iterator i = r.begin ();
473 BOOST_CHECK_EQUAL (i->from.get(), 0);
474 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_seconds(1).get());
476 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_seconds(1).get());
477 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_seconds(11).get());
479 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_seconds(11).get());
480 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_seconds(14).get());
482 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_seconds(14).get());
483 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_seconds(19).get());