2 Copyright (C) 2015-2017 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/vf_Test.cc
22 * @brief Various VF-related tests.
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"
35 #include <dcp/reel_picture_asset.h>
36 #include <dcp/reel_sound_asset.h>
37 #include <boost/test/unit_test.hpp>
38 #include <boost/foreach.hpp>
43 using boost::shared_ptr;
44 using boost::dynamic_pointer_cast;
46 /** Test the logic which decides whether a DCP can be referenced or not */
47 BOOST_AUTO_TEST_CASE (vf_test1)
49 shared_ptr<Film> film = new_test_film ("vf_test1");
50 film->set_interop (false);
51 shared_ptr<DCPContent> dcp (new DCPContent ("test/data/reels_test2"));
52 film->examine_and_add_content (dcp);
55 /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
56 film->set_reel_type (REELTYPE_SINGLE);
58 BOOST_CHECK (!dcp->can_reference_video(film, why_not));
59 BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
60 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
61 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
63 /* Multi-reel DCP can be referenced if we are using by-video-content */
64 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
65 BOOST_CHECK (dcp->can_reference_video(film, why_not));
66 BOOST_CHECK (dcp->can_reference_audio(film, why_not));
67 /* (but reels_test2 has no texts to reference) */
68 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
69 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
71 shared_ptr<FFmpegContent> other (new FFmpegContent("test/data/test.mp4"));
72 film->examine_and_add_content (other);
75 /* Not possible if there is overlap */
76 other->set_position (film, DCPTime());
77 BOOST_CHECK (!dcp->can_reference_video(film, why_not));
78 BOOST_CHECK (!dcp->can_reference_audio(film, why_not));
79 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
80 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
82 /* This should not be considered an overlap */
83 other->set_position (film, dcp->end(film));
84 BOOST_CHECK (dcp->can_reference_video(film, why_not));
85 BOOST_CHECK (dcp->can_reference_audio(film, why_not));
86 /* (reels_test2 has no texts to reference) */
87 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_OPEN_SUBTITLE, why_not));
88 BOOST_CHECK (!dcp->can_reference_text(film, TEXT_CLOSED_CAPTION, why_not));
91 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
92 BOOST_AUTO_TEST_CASE (vf_test2)
95 shared_ptr<Film> ov = new_test_film ("vf_test2_ov");
96 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
97 ov->set_name ("vf_test2_ov");
98 shared_ptr<Content> video = content_factory ("test/data/flat_red.png").front();
99 ov->examine_and_add_content (video);
101 video->video->set_length (24 * 5);
102 shared_ptr<Content> audio = content_factory ("test/data/white.wav").front();
103 ov->examine_and_add_content (audio);
109 shared_ptr<Film> vf = new_test_film ("vf_test2_vf");
110 vf->set_name ("vf_test2_vf");
111 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
112 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
113 shared_ptr<DCPContent> dcp (new DCPContent(ov->dir (ov->dcp_name ())));
115 vf->examine_and_add_content (dcp);
117 dcp->set_reference_video (true);
118 dcp->set_reference_audio (true);
119 shared_ptr<Content> sub = content_factory("test/data/subrip4.srt").front();
120 vf->examine_and_add_content (sub);
121 DCPOMATIC_ASSERT (!wait_for_jobs ());
123 DCPOMATIC_ASSERT (!wait_for_jobs ());
124 vf->write_metadata ();
126 dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
128 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
129 BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
130 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
131 string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
132 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
133 string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
134 BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
136 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
138 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
139 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
140 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
141 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->id(), pic_id);
142 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
143 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->id(), sound_id);
144 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_subtitle());
147 /** Test creation of a VF using a trimmed OV; the output should have entry point /
148 * duration altered to effect the trimming.
150 BOOST_AUTO_TEST_CASE (vf_test3)
153 shared_ptr<Film> ov = new_test_film ("vf_test3_ov");
154 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
155 ov->set_name ("vf_test3_ov");
156 shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
157 ov->examine_and_add_content (video);
159 video->video->set_length (24 * 5);
160 shared_ptr<Content> audio = content_factory("test/data/white.wav").front();
161 ov->examine_and_add_content (audio);
167 shared_ptr<Film> vf = new_test_film ("vf_test3_vf");
168 vf->set_name ("vf_test3_vf");
169 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
170 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
171 shared_ptr<DCPContent> dcp (new DCPContent(ov->dir(ov->dcp_name())));
173 dcp->set_trim_start (ContentTime::from_seconds (1));
174 dcp->set_trim_end (ContentTime::from_seconds (1));
175 vf->examine_and_add_content (dcp);
177 dcp->set_reference_video (true);
178 dcp->set_reference_audio (true);
181 vf->write_metadata ();
183 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
185 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
186 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
187 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
188 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->entry_point(), 24);
189 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->duration(), 72);
190 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
191 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->entry_point(), 24);
192 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->duration(), 72);
195 /** Make a OV with video and audio and a VF referencing the OV and adding some more video */
196 BOOST_AUTO_TEST_CASE (vf_test4)
199 shared_ptr<Film> ov = new_test_film ("vf_test4_ov");
200 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
201 ov->set_name ("vf_test4_ov");
202 shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
203 ov->examine_and_add_content (video);
205 video->video->set_length (24 * 5);
206 shared_ptr<Content> audio = content_factory("test/data/white.wav").front();
207 ov->examine_and_add_content (audio);
213 shared_ptr<Film> vf = new_test_film ("vf_test4_vf");
214 vf->set_name ("vf_test4_vf");
215 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
216 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
217 vf->set_sequence (false);
218 shared_ptr<DCPContent> dcp (new DCPContent(ov->dir(ov->dcp_name())));
220 vf->examine_and_add_content (dcp);
222 dcp->set_position(vf, DCPTime::from_seconds(10));
223 dcp->set_reference_video (true);
224 dcp->set_reference_audio (true);
225 shared_ptr<Content> more_video = content_factory("test/data/flat_red.png").front();
226 vf->examine_and_add_content (more_video);
227 DCPOMATIC_ASSERT (!wait_for_jobs ());
228 more_video->set_position (vf, DCPTime());
229 vf->write_metadata ();
231 DCPOMATIC_ASSERT (!wait_for_jobs ());
233 dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
235 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
236 BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
237 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
238 string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
239 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
240 string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
241 BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
243 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
245 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
246 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 2);
247 BOOST_REQUIRE (vf_c.cpls().front()->reels().back()->main_picture());
248 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().back()->main_picture()->id(), pic_id);
249 BOOST_REQUIRE (vf_c.cpls().front()->reels().back()->main_sound());
250 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().back()->main_sound()->id(), sound_id);