std::shared_ptr
[dcpomatic.git] / test / no_use_video_test.cc
1 /*
2     Copyright (C) 2020 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
22 /** @file  test/test_no_use_video.cc
23  *  @brief Test some cases where the video parts of inputs are ignored, to
24  *  check that the right DCPs are made.
25  *  @ingroup completedcp
26  */
27
28
29 #include "lib/audio_content.h"
30 #include "lib/content.h"
31 #include "lib/content_factory.h"
32 #include "lib/film.h"
33 #include "lib/dcp_content.h"
34 #include "lib/video_content.h"
35 #include "test.h"
36 #include <dcp/cpl.h>
37 #include <dcp/dcp.h>
38 #include <dcp/reel.h>
39 #include <dcp/reel_sound_asset.h>
40 #include <dcp/reel_picture_asset.h>
41 #include <boost/test/unit_test.hpp>
42
43
44 using std::dynamic_pointer_cast;
45 using std::shared_ptr;
46
47
48 /** Overlay two video-only bits of content, don't use the video on one and
49  *  make sure the other one is in the DCP.
50  */
51 BOOST_AUTO_TEST_CASE (no_use_video_test1)
52 {
53         shared_ptr<Film> film = new_test_film2 ("no_use_video_test1");
54         shared_ptr<Content> A = content_factory ("test/data/flat_red.png").front();
55         shared_ptr<Content> B = content_factory ("test/data/flat_green.png").front();
56         film->examine_and_add_content (A);
57         film->examine_and_add_content (B);
58         BOOST_REQUIRE (!wait_for_jobs());
59
60         A->set_position (film, dcpomatic::DCPTime());
61         B->set_position (film, dcpomatic::DCPTime());
62         A->video->set_use (false);
63
64         film->make_dcp ();
65         BOOST_REQUIRE (!wait_for_jobs());
66
67         check_dcp ("test/data/no_use_video_test1", film);
68 }
69
70
71 /** Overlay two muxed sources and disable the video on one */
72 BOOST_AUTO_TEST_CASE (no_use_video_test2)
73 {
74         shared_ptr<Film> film = new_test_film2 ("no_use_video_test2");
75         shared_ptr<Content> A = content_factory (TestPaths::private_data() / "dolby_aurora.vob").front();
76         shared_ptr<Content> B = content_factory (TestPaths::private_data() / "big_buck_bunny_trailer_480p.mov").front();
77         film->examine_and_add_content (A);
78         film->examine_and_add_content (B);
79         BOOST_REQUIRE (!wait_for_jobs());
80
81         A->set_position (film, dcpomatic::DCPTime());
82         B->set_position (film, dcpomatic::DCPTime());
83         A->video->set_use (false);
84
85         film->make_dcp ();
86         BOOST_REQUIRE (!wait_for_jobs());
87
88         check_dcp (TestPaths::private_data() / "no_use_video_test2", film);
89 }
90
91
92 /** Make two DCPs and make a VF with the audio from one and the video from another */
93 BOOST_AUTO_TEST_CASE (no_use_video_test3)
94 {
95         shared_ptr<Film> ov_a = new_test_film2 ("no_use_video_test3_ov_a");
96         shared_ptr<Content> ov_a_pic = content_factory ("test/data/flat_red.png").front();
97         BOOST_REQUIRE (ov_a_pic);
98         shared_ptr<Content> ov_a_snd = content_factory ("test/data/sine_16_48_220_10.wav").front();
99         BOOST_REQUIRE (ov_a_snd);
100         ov_a->examine_and_add_content (ov_a_pic);
101         ov_a->examine_and_add_content (ov_a_snd);
102         BOOST_REQUIRE (!wait_for_jobs());
103         ov_a->make_dcp ();
104         BOOST_REQUIRE (!wait_for_jobs());
105
106         shared_ptr<Film> ov_b = new_test_film2 ("no_use_video_test3_ov_b");
107         shared_ptr<Content> ov_b_pic = content_factory ("test/data/flat_green.png").front();
108         BOOST_REQUIRE (ov_b_pic);
109         shared_ptr<Content> ov_b_snd = content_factory ("test/data/sine_16_48_880_10.wav").front();
110         BOOST_REQUIRE (ov_b_snd);
111         ov_b->examine_and_add_content (ov_b_pic);
112         ov_b->examine_and_add_content (ov_b_snd);
113         BOOST_REQUIRE (!wait_for_jobs());
114         ov_b->make_dcp ();
115         BOOST_REQUIRE (!wait_for_jobs());
116
117         shared_ptr<Film> vf = new_test_film2 ("no_use_video_test3_vf");
118         shared_ptr<DCPContent> A (new DCPContent(ov_a->dir(ov_a->dcp_name())));
119         shared_ptr<DCPContent> B (new DCPContent(ov_b->dir(ov_b->dcp_name())));
120         vf->examine_and_add_content (A);
121         vf->examine_and_add_content (B);
122         BOOST_REQUIRE (!wait_for_jobs());
123
124         A->set_position (vf, dcpomatic::DCPTime());
125         A->video->set_use (false);
126         B->set_position (vf, dcpomatic::DCPTime());
127         AudioMapping mapping (16, 16);
128         mapping.make_zero ();
129         B->audio->set_mapping(mapping);
130
131         A->set_reference_audio (true);
132         B->set_reference_video (true);
133
134         vf->make_dcp ();
135         BOOST_REQUIRE (!wait_for_jobs());
136
137         dcp::DCP ov_a_check (ov_a->dir(ov_a->dcp_name()));
138         ov_a_check.read ();
139         BOOST_REQUIRE_EQUAL (ov_a_check.cpls().size(), 1U);
140         BOOST_REQUIRE_EQUAL (ov_a_check.cpls().front()->reels().size(), 1U);
141         shared_ptr<dcp::Reel> ov_a_reel (ov_a_check.cpls().front()->reels().front());
142
143         dcp::DCP ov_b_check (ov_b->dir(ov_b->dcp_name()));
144         ov_b_check.read ();
145         BOOST_REQUIRE_EQUAL (ov_b_check.cpls().size(), 1U);
146         BOOST_REQUIRE_EQUAL (ov_b_check.cpls().front()->reels().size(), 1U);
147         shared_ptr<dcp::Reel> ov_b_reel (ov_b_check.cpls().front()->reels().front());
148
149         dcp::DCP vf_check (vf->dir(vf->dcp_name()));
150         vf_check.read ();
151         BOOST_REQUIRE_EQUAL (vf_check.cpls().size(), 1U);
152         BOOST_REQUIRE_EQUAL (vf_check.cpls().front()->reels().size(), 1U);
153         shared_ptr<dcp::Reel> vf_reel (vf_check.cpls().front()->reels().front());
154
155         BOOST_CHECK_EQUAL (vf_reel->main_picture()->asset_ref().id(), ov_b_reel->main_picture()->asset_ref().id());
156         BOOST_CHECK_EQUAL (vf_reel->main_sound()->asset_ref().id(), ov_a_reel->main_sound()->asset_ref().id());
157 }
158
159