2 Copyright (C) 2015-2016 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 #include "lib/ratio.h"
23 #include "lib/ffmpeg_content.h"
24 #include "lib/image_content.h"
25 #include "lib/dcp_content_type.h"
26 #include "lib/dcp_content.h"
27 #include "lib/video_content.h"
28 #include "lib/text_subtitle_content.h"
30 #include <boost/test/unit_test.hpp>
31 #include <boost/foreach.hpp>
34 using boost::shared_ptr;
36 /** Test Film::reels() */
37 BOOST_AUTO_TEST_CASE (reels_test1)
39 shared_ptr<Film> film = new_test_film ("reels_test1");
40 film->set_container (Ratio::from_id ("185"));
41 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
42 film->examine_and_add_content (A);
43 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
44 film->examine_and_add_content (B);
46 BOOST_CHECK_EQUAL (A->full_length().get(), 288000);
48 film->set_reel_type (REELTYPE_SINGLE);
49 list<DCPTimePeriod> r = film->reels ();
50 BOOST_CHECK_EQUAL (r.size(), 1);
51 BOOST_CHECK_EQUAL (r.front().from.get(), 0);
52 BOOST_CHECK_EQUAL (r.front().to.get(), 288000 * 2);
54 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
56 BOOST_CHECK_EQUAL (r.size(), 2);
57 BOOST_CHECK_EQUAL (r.front().from.get(), 0);
58 BOOST_CHECK_EQUAL (r.front().to.get(), 288000);
59 BOOST_CHECK_EQUAL (r.back().from.get(), 288000);
60 BOOST_CHECK_EQUAL (r.back().to.get(), 288000 * 2);
62 film->set_j2k_bandwidth (100000000);
63 film->set_reel_type (REELTYPE_BY_LENGTH);
64 /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
65 film->set_reel_length (31253154);
67 BOOST_CHECK_EQUAL (r.size(), 3);
68 list<DCPTimePeriod>::const_iterator i = r.begin ();
69 BOOST_CHECK_EQUAL (i->from.get(), 0);
70 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_frames(60, 24).get());
72 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_frames(60, 24).get());
73 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_frames(120, 24).get());
75 BOOST_CHECK_EQUAL (i->from.get(), DCPTime::from_frames(120, 24).get());
76 BOOST_CHECK_EQUAL (i->to.get(), DCPTime::from_frames(144, 24).get());
79 /** Make a short DCP with multi reels split by video content, then import
80 * this into a new project and make a new DCP referencing it.
82 BOOST_AUTO_TEST_CASE (reels_test2)
84 shared_ptr<Film> film = new_test_film ("reels_test2");
85 film->set_name ("reels_test2");
86 film->set_container (Ratio::from_id ("185"));
87 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
90 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_red.png"));
91 film->examine_and_add_content (c);
93 c->video->set_length (24);
97 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_green.png"));
98 film->examine_and_add_content (c);
100 c->video->set_length (24);
104 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_blue.png"));
105 film->examine_and_add_content (c);
107 c->video->set_length (24);
110 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
116 check_dcp ("test/data/reels_test2", film->dir (film->dcp_name()));
118 shared_ptr<Film> film2 = new_test_film ("reels_test2b");
119 film2->set_name ("reels_test2b");
120 film2->set_container (Ratio::from_id ("185"));
121 film2->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
122 film2->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
124 shared_ptr<DCPContent> c (new DCPContent (film2, film->dir (film->dcp_name ())));
125 film2->examine_and_add_content (c);
128 list<DCPTimePeriod> r = film2->reels ();
129 BOOST_CHECK_EQUAL (r.size(), 3);
130 list<DCPTimePeriod>::const_iterator i = r.begin ();
131 BOOST_CHECK_EQUAL (i->from.get(), 0);
132 BOOST_CHECK_EQUAL (i->to.get(), 96000);
134 BOOST_CHECK_EQUAL (i->from.get(), 96000);
135 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 2);
137 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 2);
138 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 3);
140 c->set_reference_video (true);
141 c->set_reference_audio (true);
147 /** Check that REELTYPE_BY_VIDEO_CONTENT adds an extra reel, if necessary, at the end
148 * of all the video content to mop up anything afterward.
150 BOOST_AUTO_TEST_CASE (reels_test3)
152 shared_ptr<Film> film = new_test_film ("reels_test3");
153 film->set_name ("reels_test3");
154 film->set_container (Ratio::from_id ("185"));
155 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
156 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
158 shared_ptr<Content> dcp (new DCPContent (film, "test/data/reels_test2"));
159 film->examine_and_add_content (dcp);
160 shared_ptr<Content> sub (new TextSubtitleContent (film, "test/data/subrip.srt"));
161 film->examine_and_add_content (sub);
164 list<DCPTimePeriod> reels = film->reels();
165 BOOST_REQUIRE_EQUAL (reels.size(), 4);
166 list<DCPTimePeriod>::const_iterator i = reels.begin ();
167 BOOST_CHECK_EQUAL (i->from.get(), 0);
168 BOOST_CHECK_EQUAL (i->to.get(), 96000);
170 BOOST_CHECK_EQUAL (i->from.get(), 96000);
171 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 2);
173 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 2);
174 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 3);
176 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 3);
177 BOOST_CHECK_EQUAL (i->to.get(), sub->full_length().round_up(film->video_frame_rate()).get());
180 /** Check creation of a multi-reel DCP with a single .srt subtitle file;
181 * make sure that the reel subtitle timing is done right.
183 BOOST_AUTO_TEST_CASE (reels_test4)
185 shared_ptr<Film> film = new_test_film ("reels_test4");
186 film->set_name ("reels_test4");
187 film->set_container (Ratio::from_id ("185"));
188 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
189 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
191 /* 4 piece of 1s-long content */
192 shared_ptr<ImageContent> content[4];
193 for (int i = 0; i < 4; ++i) {
194 content[i].reset (new ImageContent (film, "test/data/flat_green.png"));
195 film->examine_and_add_content (content[i]);
197 content[i]->video->set_length (24);
200 shared_ptr<TextSubtitleContent> subs (new TextSubtitleContent (film, "test/data/subrip3.srt"));
201 film->examine_and_add_content (subs);
204 list<DCPTimePeriod> reels = film->reels();
205 BOOST_REQUIRE_EQUAL (reels.size(), 4);
206 list<DCPTimePeriod>::const_iterator i = reels.begin ();
207 BOOST_CHECK_EQUAL (i->from.get(), 0);
208 BOOST_CHECK_EQUAL (i->to.get(), 96000);
210 BOOST_CHECK_EQUAL (i->from.get(), 96000);
211 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 2);
213 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 2);
214 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 3);
216 BOOST_CHECK_EQUAL (i->from.get(), 96000 * 3);
217 BOOST_CHECK_EQUAL (i->to.get(), 96000 * 4);
222 check_dcp ("test/data/reels_test4", film->dir (film->dcp_name()));
225 BOOST_AUTO_TEST_CASE (reels_test5)
227 shared_ptr<Film> film = new_test_film ("reels_test4");
228 shared_ptr<DCPContent> dcp (new DCPContent (film, "test/data/reels_test4"));
229 film->examine_and_add_content (dcp);
232 dcp->set_position(DCPTime(123));
235 list<DCPTimePeriod> p = dcp->reels ();
236 BOOST_REQUIRE_EQUAL (p.size(), 4);
237 list<DCPTimePeriod>::const_iterator i = p.begin();
238 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 0), DCPTime(123 + 96000)));
239 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 96000), DCPTime(123 + 192000)));
240 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 192000), DCPTime(123 + 288000)));
241 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 288000), DCPTime(123 + 384000)));
245 dcp->set_trim_start (ContentTime::from_seconds (0.5));
246 list<DCPTimePeriod> p = dcp->reels ();
247 BOOST_REQUIRE_EQUAL (p.size(), 4);
248 list<DCPTimePeriod>::const_iterator i = p.begin();
249 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 0), DCPTime(123 + 48000)));
250 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 48000), DCPTime(123 + 144000)));
251 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 144000), DCPTime(123 + 240000)));
252 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 240000), DCPTime(123 + 336000)));
256 dcp->set_trim_end (ContentTime::from_seconds (0.5));
257 list<DCPTimePeriod> p = dcp->reels ();
258 BOOST_REQUIRE_EQUAL (p.size(), 4);
259 list<DCPTimePeriod>::const_iterator i = p.begin();
260 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 0), DCPTime(123 + 48000)));
261 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 48000), DCPTime(123 + 144000)));
262 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 144000), DCPTime(123 + 240000)));
263 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 240000), DCPTime(123 + 288000)));
267 dcp->set_trim_start (ContentTime::from_seconds (1.5));
268 list<DCPTimePeriod> p = dcp->reels ();
269 BOOST_REQUIRE_EQUAL (p.size(), 3);
270 list<DCPTimePeriod>::const_iterator i = p.begin();
271 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 0), DCPTime(123 + 48000)));
272 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 48000), DCPTime(123 + 144000)));
273 BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 144000), DCPTime(123 + 192000)));