Respect _no_video and _no_audio when filling.
[dcpomatic.git] / test / vf_test.cc
1 /*
2     Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 /** @file  test/vf_Test.cc
22  *  @brief Various VF-related tests.
23  *  @ingroup specific
24  */
25
26 #include "lib/film.h"
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"
32 #include "test.h"
33 #include <dcp/cpl.h>
34 #include <dcp/reel.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>
39
40 using std::list;
41 using std::string;
42 using boost::shared_ptr;
43 using boost::dynamic_pointer_cast;
44
45 /** Test the logic which decides whether a DCP can be referenced or not */
46 BOOST_AUTO_TEST_CASE (vf_test1)
47 {
48         shared_ptr<Film> film = new_test_film ("vf_test1");
49         shared_ptr<DCPContent> dcp (new DCPContent (film, "test/data/reels_test2"));
50         film->examine_and_add_content (dcp);
51         wait_for_jobs ();
52
53         /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
54         film->set_reel_type (REELTYPE_SINGLE);
55         list<string> why_not;
56         BOOST_CHECK (!dcp->can_reference_video(why_not));
57         BOOST_CHECK (!dcp->can_reference_audio(why_not));
58         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
59
60         /* Multi-reel DCP can be referenced if we are using by-video-content */
61         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
62         BOOST_CHECK (dcp->can_reference_video(why_not));
63         BOOST_CHECK (dcp->can_reference_audio(why_not));
64         /* (but reels_test2 has no subtitles to reference) */
65         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
66
67         shared_ptr<FFmpegContent> other (new FFmpegContent (film, "test/data/test.mp4"));
68         film->examine_and_add_content (other);
69         wait_for_jobs ();
70
71         /* Not possible if there is overlap */
72         other->set_position (DCPTime (0));
73         BOOST_CHECK (!dcp->can_reference_video(why_not));
74         BOOST_CHECK (!dcp->can_reference_audio(why_not));
75         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
76
77         /* This should not be considered an overlap */
78         other->set_position (dcp->end ());
79         BOOST_CHECK (dcp->can_reference_video(why_not));
80         BOOST_CHECK (dcp->can_reference_audio(why_not));
81         /* (reels_test2 has no subtitles to reference) */
82         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
83 }
84
85 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
86 BOOST_AUTO_TEST_CASE (vf_test2)
87 {
88         /* Make the OV */
89         shared_ptr<Film> ov = new_test_film ("vf_test2_ov");
90         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
91         ov->set_name ("vf_test2_ov");
92         shared_ptr<Content> video = content_factory (ov, "test/data/flat_red.png").front();
93         ov->examine_and_add_content (video);
94         wait_for_jobs ();
95         video->video->set_length (24 * 5);
96         shared_ptr<Content> audio = content_factory(ov, "test/data/white.wav").front();
97         ov->examine_and_add_content (audio);
98         wait_for_jobs ();
99         ov->make_dcp ();
100         wait_for_jobs ();
101
102         /* Make the VF */
103         shared_ptr<Film> vf = new_test_film ("vf_test2_vf");
104         vf->set_name ("vf_test2_vf");
105         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
106         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
107         shared_ptr<DCPContent> dcp (new DCPContent (vf, ov->dir (ov->dcp_name ())));
108         BOOST_REQUIRE (dcp);
109         vf->examine_and_add_content (dcp);
110         wait_for_jobs ();
111         dcp->set_reference_video (true);
112         dcp->set_reference_audio (true);
113         shared_ptr<Content> sub = content_factory(vf, "test/data/subrip4.srt").front();
114         vf->examine_and_add_content (sub);
115         DCPOMATIC_ASSERT (!wait_for_jobs ());
116         vf->make_dcp ();
117         DCPOMATIC_ASSERT (!wait_for_jobs ());
118         vf->write_metadata ();
119
120         dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
121         ov_c.read ();
122         BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
123         BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
124         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
125         string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
126         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
127         string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
128         BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
129
130         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
131         vf_c.read ();
132         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
133         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
134         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
135         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->id(), pic_id);
136         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
137         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->id(), sound_id);
138         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_subtitle());
139 }
140
141 /** Test creation of a VF using a trimmed OV; the output should have entry point /
142  *  duration altered to effect the trimming.
143  */
144 BOOST_AUTO_TEST_CASE (vf_test3)
145 {
146         /* Make the OV */
147         shared_ptr<Film> ov = new_test_film ("vf_test3_ov");
148         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
149         ov->set_name ("vf_test3_ov");
150         shared_ptr<Content> video = content_factory(ov, "test/data/flat_red.png").front();
151         ov->examine_and_add_content (video);
152         wait_for_jobs ();
153         video->video->set_length (24 * 5);
154         shared_ptr<Content> audio = content_factory(ov, "test/data/white.wav").front();
155         ov->examine_and_add_content (audio);
156         wait_for_jobs ();
157         ov->make_dcp ();
158         wait_for_jobs ();
159
160         /* Make the VF */
161         shared_ptr<Film> vf = new_test_film ("vf_test3_vf");
162         vf->set_name ("vf_test3_vf");
163         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
164         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
165         shared_ptr<DCPContent> dcp (new DCPContent (vf, ov->dir (ov->dcp_name ())));
166         BOOST_REQUIRE (dcp);
167         dcp->set_trim_start (ContentTime::from_seconds (1));
168         dcp->set_trim_end (ContentTime::from_seconds (1));
169         vf->examine_and_add_content (dcp);
170         wait_for_jobs ();
171         dcp->set_reference_video (true);
172         dcp->set_reference_audio (true);
173         vf->make_dcp ();
174         wait_for_jobs ();
175         vf->write_metadata ();
176
177         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
178         vf_c.read ();
179         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
180         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
181         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
182         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->entry_point(), 24);
183         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->duration(), 72);
184         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
185         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->entry_point(), 24);
186         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->duration(), 72);
187 }