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");
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");
92 ov->examine_and_add_content (audio);
98 shared_ptr<Film> vf = new_test_film ("vf_test2_vf");
99 vf->set_name ("vf_test2_vf");
100 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
101 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
102 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content_factory (vf, ov->dir (ov->dcp_name ())));
104 vf->examine_and_add_content (dcp);
106 dcp->set_reference_video (true);
107 dcp->set_reference_audio (true);
108 shared_ptr<Content> sub = content_factory (vf, "test/data/subrip4.srt");
109 vf->examine_and_add_content (sub);
112 vf->write_metadata ();
114 dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
116 BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
117 BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
118 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
119 string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
120 BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
121 string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
122 BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
124 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
126 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
127 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
128 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
129 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->id(), pic_id);
130 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
131 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->id(), sound_id);
132 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_subtitle());
135 /** Test creation of a VF using a trimmed OV; the output should have entry point /
136 * duration altered to effect the trimming.
138 BOOST_AUTO_TEST_CASE (vf_test3)
141 shared_ptr<Film> ov = new_test_film ("vf_test3_ov");
142 ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
143 ov->set_name ("vf_test3_ov");
144 shared_ptr<Content> video = content_factory (ov, "test/data/flat_red.png");
145 ov->examine_and_add_content (video);
147 video->video->set_length (24 * 5);
148 shared_ptr<Content> audio = content_factory (ov, "test/data/white.wav");
149 ov->examine_and_add_content (audio);
155 shared_ptr<Film> vf = new_test_film ("vf_test3_vf");
156 vf->set_name ("vf_test3_vf");
157 vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
158 vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
159 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content_factory (vf, ov->dir (ov->dcp_name ())));
161 dcp->set_trim_start (ContentTime::from_seconds (1));
162 dcp->set_trim_end (ContentTime::from_seconds (1));
163 vf->examine_and_add_content (dcp);
165 dcp->set_reference_video (true);
166 dcp->set_reference_audio (true);
169 vf->write_metadata ();
171 dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
173 BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
174 BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
175 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
176 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->entry_point(), 24);
177 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->duration(), 72);
178 BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
179 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->entry_point(), 24);
180 BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->duration(), 72);