Head off some cert validity warnings.
[dcpomatic.git] / test / threed_test.cc
1 /*
2     Copyright (C) 2013-2021 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/threed_test.cc
23  *  @brief Create some 3D DCPs (without comparing the results to anything).
24  *  @ingroup completedcp
25  */
26
27
28 #include "lib/config.h"
29 #include "lib/content_factory.h"
30 #include "lib/cross.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/ffmpeg_content.h"
33 #include "lib/film.h"
34 #include "lib/job.h"
35 #include "lib/job_manager.h"
36 #include "lib/ratio.h"
37 #include "lib/video_content.h"
38 #include "test.h"
39 #include <boost/test/unit_test.hpp>
40 #include <iostream>
41
42
43 using std::cout;
44 using std::make_shared;
45 using std::shared_ptr;
46
47
48 /** Basic sanity check of THREE_D_LEFT_RIGHT */
49 BOOST_AUTO_TEST_CASE (threed_test1)
50 {
51         auto film = new_test_film ("threed_test1");
52         film->set_name ("test_film1");
53         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
54         film->examine_and_add_content (c);
55         BOOST_REQUIRE (!wait_for_jobs());
56
57         c->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
58
59         film->set_container (Ratio::from_id ("185"));
60         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
61         film->set_three_d (true);
62         make_and_verify_dcp (film);
63 }
64
65
66 /** Basic sanity check of THREE_D_ALTERNATE; at the moment this is just to make sure
67  *  that such a transcode completes without error.
68  */
69 BOOST_AUTO_TEST_CASE (threed_test2)
70 {
71         auto film = new_test_film ("threed_test2");
72         film->set_name ("test_film2");
73         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
74         film->examine_and_add_content (c);
75         BOOST_REQUIRE (!wait_for_jobs());
76
77         c->video->set_frame_type (VideoFrameType::THREE_D_ALTERNATE);
78
79         film->set_container (Ratio::from_id ("185"));
80         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
81         film->set_three_d (true);
82         make_and_verify_dcp (film);
83 }
84
85
86 /** Basic sanity check of THREE_D_LEFT and THREE_D_RIGHT; at the moment this is just to make sure
87  *  that such a transcode completes without error.
88  */
89 BOOST_AUTO_TEST_CASE (threed_test3)
90 {
91         shared_ptr<Film> film = new_test_film2 ("threed_test3");
92         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
93         film->examine_and_add_content (L);
94         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
95         film->examine_and_add_content (R);
96         BOOST_REQUIRE (!wait_for_jobs());
97
98         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
99         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
100
101         film->set_three_d (true);
102         make_and_verify_dcp (film);
103 }
104
105
106 BOOST_AUTO_TEST_CASE (threed_test4)
107 {
108         ConfigRestorer cr;
109
110         /* Try to stop out-of-memory crashes on my laptop */
111         Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency() / 4);
112
113         auto film = new_test_film2 ("threed_test4");
114         auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "LEFT_TEST_DCP3D4K.mov");
115         film->examine_and_add_content (L);
116         auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "RIGHT_TEST_DCP3D4K.mov");
117         film->examine_and_add_content (R);
118         BOOST_REQUIRE (!wait_for_jobs());
119
120         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
121         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
122         /* There doesn't seem much point in encoding the whole input, especially as we're only
123          * checking for errors during the encode and not the result.  Also decoding these files
124          * (4K HQ Prores) is very slow.
125          */
126         L->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
127         R->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
128
129         film->set_three_d (true);
130         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D});
131 }
132
133
134 BOOST_AUTO_TEST_CASE (threed_test5)
135 {
136         auto film = new_test_film2 ("threed_test5");
137         auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
138         film->examine_and_add_content (L);
139         auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
140         film->examine_and_add_content (R);
141         BOOST_REQUIRE (!wait_for_jobs());
142
143         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
144         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
145         /* There doesn't seem much point in encoding the whole input, especially as we're only
146          * checking for errors during the encode and not the result.
147          */
148         L->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
149         R->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
150
151         film->set_three_d (true);
152         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K});
153 }
154
155
156 BOOST_AUTO_TEST_CASE (threed_test6)
157 {
158         auto film = new_test_film2 ("threed_test6");
159         auto L = make_shared<FFmpegContent>("test/data/3dL.mp4");
160         film->examine_and_add_content (L);
161         auto R = make_shared<FFmpegContent>("test/data/3dR.mp4");
162         film->examine_and_add_content (R);
163         BOOST_REQUIRE (!wait_for_jobs());
164
165         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
166         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
167
168         film->set_three_d (true);
169         make_and_verify_dcp (film);
170         check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
171 }
172
173
174 /** Check 2D content set as being 3D; this should give an informative error */
175 BOOST_AUTO_TEST_CASE (threed_test7)
176 {
177         using boost::filesystem::path;
178
179         auto film = new_test_film2 ("threed_test7");
180         path const content_path = "test/data/flat_red.png";
181         auto c = content_factory(content_path).front();
182         film->examine_and_add_content (c);
183         BOOST_REQUIRE (!wait_for_jobs());
184
185         c->video->set_frame_type (VideoFrameType::THREE_D);
186         c->video->set_length (24);
187
188         film->set_three_d (true);
189         film->make_dcp (TranscodeJob::ChangedBehaviour::IGNORE);
190         film->write_metadata ();
191
192         auto jm = JobManager::instance ();
193         while (jm->work_to_do ()) {
194                 while (signal_manager->ui_idle()) {}
195                 dcpomatic_sleep_seconds (1);
196         }
197
198         while (signal_manager->ui_idle ()) {}
199
200         BOOST_REQUIRE (jm->errors());
201         shared_ptr<Job> failed;
202         for (auto i: jm->_jobs) {
203                 if (i->finished_in_error()) {
204                         BOOST_REQUIRE (!failed);
205                         failed = i;
206                 }
207         }
208         BOOST_REQUIRE (failed);
209         BOOST_CHECK_EQUAL (failed->error_summary(), String::compose("The content file %1 is set as 3D but does not appear to contain 3D images.  Please set it to 2D.  You can still make a 3D DCP from this content by ticking the 3D option in the DCP video tab.", content_path.string()));
210
211         while (signal_manager->ui_idle ()) {}
212
213         JobManager::drop ();
214 }
215
216
217 /** Trigger a -114 error by trying to make a 3D DCP out of two files with slightly
218  *  different lengths.
219  */
220 BOOST_AUTO_TEST_CASE (threed_test_separate_files_slightly_different_lengths)
221 {
222         shared_ptr<Film> film = new_test_film2 ("threed_test3");
223         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
224         film->examine_and_add_content (L);
225         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
226         film->examine_and_add_content (R);
227         BOOST_REQUIRE (!wait_for_jobs());
228
229         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
230         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
231         R->set_trim_end (dcpomatic::ContentTime::from_frames(1, 24));
232
233         film->set_three_d (true);
234         make_and_verify_dcp (film);
235 }
236
237
238 /** Trigger a -114 error by trying to make a 3D DCP out of two files with very
239  *  different lengths.
240  */
241 BOOST_AUTO_TEST_CASE (threed_test_separate_files_very_different_lengths)
242 {
243         shared_ptr<Film> film = new_test_film2 ("threed_test3");
244         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
245         film->examine_and_add_content (L);
246         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
247         film->examine_and_add_content (R);
248         BOOST_REQUIRE (!wait_for_jobs());
249
250         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
251         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
252         R->set_trim_end (dcpomatic::ContentTime::from_seconds(1.5));
253
254         film->set_three_d (true);
255         make_and_verify_dcp (film);
256 }