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/dcp_content.h"
23 #include "lib/ffmpeg_content.h"
24 #include "lib/content_factory.h"
25 #include "lib/dcp_content_type.h"
26 #include "lib/video_content.h"
30 #include <dcp/reel_picture_asset.h>
31 #include <dcp/reel_sound_asset.h>
32 #include <boost/test/unit_test.hpp>
33 #include <boost/foreach.hpp>
37 using boost::shared_ptr;
38 using boost::dynamic_pointer_cast;
40 /** Test the logic which decides whether a DCP can be referenced or not */
41 BOOST_AUTO_TEST_CASE (vf_test1)
43 shared_ptr<Film> film = new_test_film ("vf_test1");
44 shared_ptr<DCPContent> dcp (new DCPContent (film, "test/data/reels_test2"));
45 film->examine_and_add_content (dcp);
48 /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
49 film->set_reel_type (REELTYPE_SINGLE);
51 BOOST_CHECK (!dcp->can_reference_video(why_not));
52 BOOST_CHECK (!dcp->can_reference_audio(why_not));
53 BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
55 /* Multi-reel DCP can be referenced if we are using by-video-content */
56 film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
57 BOOST_CHECK (dcp->can_reference_video(why_not));
58 BOOST_CHECK (dcp->can_reference_audio(why_not));
59 /* (but reels_test2 has no subtitles to reference) */
60 BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
62 shared_ptr<FFmpegContent> other (new FFmpegContent (film, "test/data/test.mp4"));
63 film->examine_and_add_content (other);
66 /* Not possible if there is overlap */
67 other->set_position (DCPTime (0));
68 BOOST_CHECK (!dcp->can_reference_video(why_not));
69 BOOST_CHECK (!dcp->can_reference_audio(why_not));
70 BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
72 /* This should not be considered an overlap */
73 other->set_position (dcp->end ());
74 BOOST_CHECK (dcp->can_reference_video(why_not));
75 BOOST_CHECK (dcp->can_reference_audio(why_not));
76 /* (reels_test2 has no subtitles to reference) */
77 BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
80 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
81 BOOST_AUTO_TEST_CASE (vf_test2)
84 shared_ptr<Film> ov = new_test_film ("vf_test2_ov");
85 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
86 ov->set_name ("vf_test2_ov");
87 shared_ptr<Content> video = content_factory (ov, "test/data/flat_red.png").front();
88 ov->examine_and_add_content (video);
90 video->video->set_length (24 * 5);
91 shared_ptr<Content> audio = content_factory(ov, "test/data/white.wav").front();
92 ov->examine_and_add_content (audio);
97 std::cout << "incoming vf.\n";
100 shared_ptr<Film> vf = new_test_film ("vf_test2_vf");
101 vf->set_name ("vf_test2_vf");
102 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
103 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
104 shared_ptr<DCPContent> dcp (new DCPContent (vf, ov->dir (ov->dcp_name ())));
106 vf->examine_and_add_content (dcp);
108 dcp->set_reference_video (true);
109 dcp->set_reference_audio (true);
110 shared_ptr<Content> sub = content_factory(vf, "test/data/subrip4.srt").front();
111 vf->examine_and_add_content (sub);
114 vf->write_metadata ();
116 dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
118 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
119 BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
120 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
121 string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
122 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
123 string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
124 BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
126 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
128 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
129 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
130 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
131 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->id(), pic_id);
132 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
133 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->id(), sound_id);
134 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_subtitle());
137 /** Test creation of a VF using a trimmed OV; the output should have entry point /
138 * duration altered to effect the trimming.
140 BOOST_AUTO_TEST_CASE (vf_test3)
143 shared_ptr<Film> ov = new_test_film ("vf_test3_ov");
144 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
145 ov->set_name ("vf_test3_ov");
146 shared_ptr<Content> video = content_factory(ov, "test/data/flat_red.png").front();
147 ov->examine_and_add_content (video);
149 video->video->set_length (24 * 5);
150 shared_ptr<Content> audio = content_factory(ov, "test/data/white.wav").front();
151 ov->examine_and_add_content (audio);
157 shared_ptr<Film> vf = new_test_film ("vf_test3_vf");
158 vf->set_name ("vf_test3_vf");
159 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
160 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
161 shared_ptr<DCPContent> dcp (new DCPContent (vf, ov->dir (ov->dcp_name ())));
163 dcp->set_trim_start (ContentTime::from_seconds (1));
164 dcp->set_trim_end (ContentTime::from_seconds (1));
165 vf->examine_and_add_content (dcp);
167 dcp->set_reference_video (true);
168 dcp->set_reference_audio (true);
171 vf->write_metadata ();
173 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
175 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
176 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
177 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
178 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->entry_point(), 24);
179 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->duration(), 72);
180 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
181 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->entry_point(), 24);
182 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->duration(), 72);