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>
32 #include <boost/make_shared.hpp>
35 using boost::shared_ptr;
36 using boost::make_shared;
38 /** Test Film::reels() */
39 BOOST_AUTO_TEST_CASE (reels_test1)
41 shared_ptr<Film> film = new_test_film ("reels_test1");
42 film->set_container (Ratio::from_id ("185"));
43 shared_ptr<FFmpegContent> A = make_shared<FFmpegContent> (film, "test/data/test.mp4");
44 film->examine_and_add_content (A);
45 shared_ptr<FFmpegContent> B = make_shared<FFmpegContent> (film, "test/data/test.mp4");
46 film->examine_and_add_content (B);
48 BOOST_CHECK_EQUAL (A->full_length(), DCPTime (288000));
50 film->set_reel_type (REELTYPE_SINGLE);
51 list<DCPTimePeriod> r = film->reels ();
52 BOOST_CHECK_EQUAL (r.size(), 1);
53 BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
54 BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000 * 2));
56 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
58 BOOST_CHECK_EQUAL (r.size(), 2);
59 BOOST_CHECK_EQUAL (r.front().from, DCPTime (0));
60 BOOST_CHECK_EQUAL (r.front().to, DCPTime (288000));
61 BOOST_CHECK_EQUAL (r.back().from, DCPTime (288000));
62 BOOST_CHECK_EQUAL (r.back().to, DCPTime (288000 * 2));
64 film->set_j2k_bandwidth (100000000);
65 film->set_reel_type (REELTYPE_BY_LENGTH);
66 /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
67 film->set_reel_length (31253154);
69 BOOST_CHECK_EQUAL (r.size(), 3);
70 list<DCPTimePeriod>::const_iterator i = r.begin ();
71 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
72 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (60, 24));
74 BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (60, 24));
75 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (120, 24));
77 BOOST_CHECK_EQUAL (i->from, DCPTime::from_frames (120, 24));
78 BOOST_CHECK_EQUAL (i->to, DCPTime::from_frames (144, 24));
81 /** Make a short DCP with multi reels split by video content, then import
82 * this into a new project and make a new DCP referencing it.
84 BOOST_AUTO_TEST_CASE (reels_test2)
86 shared_ptr<Film> film = new_test_film ("reels_test2");
87 film->set_name ("reels_test2");
88 film->set_container (Ratio::from_id ("185"));
89 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
92 shared_ptr<ImageContent> c = make_shared<ImageContent> (film, "test/data/flat_red.png");
93 film->examine_and_add_content (c);
95 c->video->set_length (24);
99 shared_ptr<ImageContent> c = make_shared<ImageContent> (film, "test/data/flat_green.png");
100 film->examine_and_add_content (c);
102 c->video->set_length (24);
106 shared_ptr<ImageContent> c = make_shared<ImageContent> (film, "test/data/flat_blue.png");
107 film->examine_and_add_content (c);
109 c->video->set_length (24);
112 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
118 check_dcp ("test/data/reels_test2", film->dir (film->dcp_name()));
120 shared_ptr<Film> film2 = new_test_film ("reels_test2b");
121 film2->set_name ("reels_test2b");
122 film2->set_container (Ratio::from_id ("185"));
123 film2->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
124 film2->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
126 shared_ptr<DCPContent> c = make_shared<DCPContent> (film2, film->dir (film->dcp_name ()));
127 film2->examine_and_add_content (c);
130 list<DCPTimePeriod> r = film2->reels ();
131 BOOST_CHECK_EQUAL (r.size(), 3);
132 list<DCPTimePeriod>::const_iterator i = r.begin ();
133 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
134 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
136 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
137 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
139 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
140 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
142 c->set_reference_video (true);
143 c->set_reference_audio (true);
149 /** Check that REELTYPE_BY_VIDEO_CONTENT adds an extra reel, if necessary, at the end
150 * of all the video content to mop up anything afterward.
152 BOOST_AUTO_TEST_CASE (reels_test3)
154 shared_ptr<Film> film = new_test_film ("reels_test3");
155 film->set_name ("reels_test3");
156 film->set_container (Ratio::from_id ("185"));
157 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
158 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
160 shared_ptr<Content> dcp = make_shared<DCPContent> (film, "test/data/reels_test2");
161 film->examine_and_add_content (dcp);
162 shared_ptr<Content> sub = make_shared<TextSubtitleContent> (film, "test/data/subrip.srt");
163 film->examine_and_add_content (sub);
166 list<DCPTimePeriod> reels = film->reels();
167 BOOST_REQUIRE_EQUAL (reels.size(), 4);
168 list<DCPTimePeriod>::const_iterator i = reels.begin ();
169 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
170 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
172 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
173 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
175 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
176 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
178 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 3));
179 BOOST_CHECK_EQUAL (i->to, sub->full_length().round_up (film->video_frame_rate()));
182 /** Check creation of a multi-reel DCP with a single .srt subtitle file;
183 * make sure that the reel subtitle timing is done right.
185 BOOST_AUTO_TEST_CASE (reels_test4)
187 shared_ptr<Film> film = new_test_film ("reels_test4");
188 film->set_name ("reels_test4");
189 film->set_container (Ratio::from_id ("185"));
190 film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
191 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
193 /* 4 piece of 1s-long content */
194 shared_ptr<ImageContent> content[4];
195 for (int i = 0; i < 4; ++i) {
196 content[i].reset (new ImageContent (film, "test/data/flat_green.png"));
197 film->examine_and_add_content (content[i]);
199 content[i]->video->set_length (24);
202 shared_ptr<TextSubtitleContent> subs = make_shared<TextSubtitleContent> (film, "test/data/subrip3.srt");
203 film->examine_and_add_content (subs);
206 list<DCPTimePeriod> reels = film->reels();
207 BOOST_REQUIRE_EQUAL (reels.size(), 4);
208 list<DCPTimePeriod>::const_iterator i = reels.begin ();
209 BOOST_CHECK_EQUAL (i->from, DCPTime (0));
210 BOOST_CHECK_EQUAL (i->to, DCPTime (96000));
212 BOOST_CHECK_EQUAL (i->from, DCPTime (96000));
213 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 2));
215 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 2));
216 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 3));
218 BOOST_CHECK_EQUAL (i->from, DCPTime (96000 * 3));
219 BOOST_CHECK_EQUAL (i->to, DCPTime (96000 * 4));
224 check_dcp ("test/data/reels_test4", film->dir (film->dcp_name()));