2 Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "lib/ratio.h"
22 #include "lib/ffmpeg_content.h"
23 #include "lib/image_content.h"
24 #include "lib/dcp_content_type.h"
25 #include "lib/dcp_content.h"
26 #include "lib/video_content.h"
27 #include "lib/text_subtitle_content.h"
29 #include <boost/test/unit_test.hpp>
30 #include <boost/foreach.hpp>
33 using boost::shared_ptr;
35 /** Test Film::reels() */
36 BOOST_AUTO_TEST_CASE (reels_test1)
38 shared_ptr<Film> film = new_test_film ("reels_test1");
39 film->set_container (Ratio::from_id ("185"));
40 shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
41 film->examine_and_add_content (A);
42 shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
43 film->examine_and_add_content (B);
45 BOOST_CHECK_EQUAL (A->full_length(), DCPTime (288000));
47 film->set_reel_type (REELTYPE_SINGLE);
48 list<DCPTimePeriod> r = film->reels ();
49 BOOST_CHECK_EQUAL (r.size(), 1);
50 BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
51 BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000 * 2));
53 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
55 BOOST_CHECK_EQUAL (r.size(), 2);
56 BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
57 BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000));
58 BOOST_CHECK_EQUAL (r.back().from, DCPTime (288000));
59 BOOST_CHECK_EQUAL (r.back().to, DCPTime (288000 * 2));
61 film->set_j2k_bandwidth (100000000);
62 film->set_reel_type (REELTYPE_BY_LENGTH);
63 /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
64 film->set_reel_length (31253154);
66 BOOST_CHECK_EQUAL (r.size(), 3);
67 list<DCPTimePeriod>::const_iterator i = r.begin ();
68 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
69 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (60, 24));
71 BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (60, 24));
72 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (120, 24));
74 BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (120, 24));
75 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (144, 24));
78 /** Make a short DCP with multi reels split by video content, then import
79 * this into a new project and make a new DCP referencing it.
81 BOOST_AUTO_TEST_CASE (reels_test2)
83 shared_ptr<Film> film = new_test_film ("reels_test2");
84 film->set_name ("reels_test2");
85 film->set_container (Ratio::from_id ("185"));
86 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
89 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_red.png"));
90 film->examine_and_add_content (c);
92 c->video->set_length (24);
96 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_green.png"));
97 film->examine_and_add_content (c);
99 c->video->set_length (24);
103 shared_ptr<ImageContent> c (new ImageContent (film, "test/data/flat_blue.png"));
104 film->examine_and_add_content (c);
106 c->video->set_length (24);
109 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
115 check_dcp ("test/data/reels_test2", film->dir (film->dcp_name()));
117 shared_ptr<Film> film2 = new_test_film ("reels_test2b");
118 film2->set_name ("reels_test2b");
119 film2->set_container (Ratio::from_id ("185"));
120 film2->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
121 film2->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
123 shared_ptr<DCPContent> c (new DCPContent (film2, film->dir (film->dcp_name ())));
124 film2->examine_and_add_content (c);
127 list<DCPTimePeriod> r = film2->reels ();
128 BOOST_CHECK_EQUAL (r.size(), 3);
129 list<DCPTimePeriod>::const_iterator i = r.begin ();
130 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
131 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
133 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
134 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
136 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
137 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
139 c->set_reference_video (true);
140 c->set_reference_audio (true);
146 /** Check that REELTYPE_BY_VIDEO_CONTENT adds an extra reel, if necessary, at the end
147 * of all the video content to mop up anything afterward.
149 BOOST_AUTO_TEST_CASE (reels_test3)
151 shared_ptr<Film> film = new_test_film ("reels_test3");
152 film->set_name ("reels_test3");
153 film->set_container (Ratio::from_id ("185"));
154 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
155 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
157 shared_ptr<Content> dcp (new DCPContent (film, "test/data/reels_test2"));
158 film->examine_and_add_content (dcp);
159 shared_ptr<Content> sub (new TextSubtitleContent (film, "test/data/subrip.srt"));
160 film->examine_and_add_content (sub);
163 list<DCPTimePeriod> reels = film->reels();
164 BOOST_REQUIRE_EQUAL (reels.size(), 4);
165 list<DCPTimePeriod>::const_iterator i = reels.begin ();
166 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
167 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
169 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
170 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
172 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
173 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
175 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 3));
176 BOOST_CHECK_EQUAL (i->to, sub->full_length().round_up (film->video_frame_rate()));
179 /** Check creation of a multi-reel DCP with a single .srt subtitle file;
180 * make sure that the reel subtitle timing is done right.
182 BOOST_AUTO_TEST_CASE (reels_test4)
184 shared_ptr<Film> film = new_test_film ("reels_test4");
185 film->set_name ("reels_test4");
186 film->set_container (Ratio::from_id ("185"));
187 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
188 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
190 /* 4 piece of 1s-long content */
191 shared_ptr<ImageContent> content[4];
192 for (int i = 0; i < 4; ++i) {
193 content[i].reset (new ImageContent (film, "test/data/flat_green.png"));
194 film->examine_and_add_content (content[i]);
196 content[i]->video->set_length (24);
199 shared_ptr<TextSubtitleContent> subs (new TextSubtitleContent (film, "test/data/subrip3.srt"));
200 film->examine_and_add_content (subs);
203 list<DCPTimePeriod> reels = film->reels();
204 BOOST_REQUIRE_EQUAL (reels.size(), 4);
205 list<DCPTimePeriod>::const_iterator i = reels.begin ();
206 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
207 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
209 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
210 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
212 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
213 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
215 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 3));
216 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 4));
221 check_dcp ("test/data/reels_test4", film->dir (film->dcp_name()));