Fill test disk partitions with random noise to expose more bugs.
[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/butler.h"
29 #include "lib/config.h"
30 #include "lib/content_factory.h"
31 #include "lib/cross.h"
32 #include "lib/dcp_content_type.h"
33 #include "lib/ffmpeg_content.h"
34 #include "lib/film.h"
35 #include "lib/image.h"
36 #include "lib/job.h"
37 #include "lib/job_manager.h"
38 #include "lib/make_dcp.h"
39 #include "lib/player.h"
40 #include "lib/ratio.h"
41 #include "lib/util.h"
42 #include "lib/video_content.h"
43 #include "test.h"
44 #include <boost/test/unit_test.hpp>
45 #include <iostream>
46
47
48 using std::cout;
49 using std::make_shared;
50 using std::shared_ptr;
51
52
53 /** Basic sanity check of THREE_D_LEFT_RIGHT */
54 BOOST_AUTO_TEST_CASE (threed_test1)
55 {
56         auto film = new_test_film ("threed_test1");
57         film->set_name ("test_film1");
58         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
59         film->examine_and_add_content (c);
60         BOOST_REQUIRE (!wait_for_jobs());
61
62         c->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
63
64         film->set_container (Ratio::from_id ("185"));
65         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
66         film->set_three_d (true);
67         make_and_verify_dcp (film);
68 }
69
70
71 /** Basic sanity check of THREE_D_ALTERNATE; at the moment this is just to make sure
72  *  that such a transcode completes without error.
73  */
74 BOOST_AUTO_TEST_CASE (threed_test2)
75 {
76         auto film = new_test_film ("threed_test2");
77         film->set_name ("test_film2");
78         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
79         film->examine_and_add_content (c);
80         BOOST_REQUIRE (!wait_for_jobs());
81
82         c->video->set_frame_type (VideoFrameType::THREE_D_ALTERNATE);
83
84         film->set_container (Ratio::from_id ("185"));
85         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
86         film->set_three_d (true);
87         make_and_verify_dcp (film);
88 }
89
90
91 /** Basic sanity check of THREE_D_LEFT and THREE_D_RIGHT; at the moment this is just to make sure
92  *  that such a transcode completes without error.
93  */
94 BOOST_AUTO_TEST_CASE (threed_test3)
95 {
96         shared_ptr<Film> film = new_test_film2 ("threed_test3");
97         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
98         film->examine_and_add_content (L);
99         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
100         film->examine_and_add_content (R);
101         BOOST_REQUIRE (!wait_for_jobs());
102
103         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
104         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
105
106         film->set_three_d (true);
107         make_and_verify_dcp (film);
108 }
109
110
111 BOOST_AUTO_TEST_CASE (threed_test4)
112 {
113         ConfigRestorer cr;
114
115         /* Try to stop out-of-memory crashes on my laptop */
116         Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency() / 4);
117
118         auto film = new_test_film2 ("threed_test4");
119         auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "LEFT_TEST_DCP3D4K.mov");
120         film->examine_and_add_content (L);
121         auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "RIGHT_TEST_DCP3D4K.mov");
122         film->examine_and_add_content (R);
123         BOOST_REQUIRE (!wait_for_jobs());
124
125         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
126         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
127         /* There doesn't seem much point in encoding the whole input, especially as we're only
128          * checking for errors during the encode and not the result.  Also decoding these files
129          * (4K HQ Prores) is very slow.
130          */
131         L->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
132         R->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
133
134         film->set_three_d (true);
135         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D});
136 }
137
138
139 BOOST_AUTO_TEST_CASE (threed_test5)
140 {
141         auto film = new_test_film2 ("threed_test5");
142         auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
143         film->examine_and_add_content (L);
144         auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
145         film->examine_and_add_content (R);
146         BOOST_REQUIRE (!wait_for_jobs());
147
148         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
149         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
150         /* There doesn't seem much point in encoding the whole input, especially as we're only
151          * checking for errors during the encode and not the result.
152          */
153         L->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
154         R->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
155
156         film->set_three_d (true);
157         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K});
158 }
159
160
161 BOOST_AUTO_TEST_CASE (threed_test6)
162 {
163         auto film = new_test_film2 ("threed_test6");
164         auto L = make_shared<FFmpegContent>("test/data/3dL.mp4");
165         film->examine_and_add_content (L);
166         auto R = make_shared<FFmpegContent>("test/data/3dR.mp4");
167         film->examine_and_add_content (R);
168         BOOST_REQUIRE (!wait_for_jobs());
169
170         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
171         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
172
173         film->set_three_d (true);
174         make_and_verify_dcp (film);
175         check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
176 }
177
178
179 /** Check 2D content set as being 3D; this should give an informative error */
180 BOOST_AUTO_TEST_CASE (threed_test7)
181 {
182         using boost::filesystem::path;
183
184         auto film = new_test_film2 ("threed_test7");
185         path const content_path = "test/data/flat_red.png";
186         auto c = content_factory(content_path).front();
187         film->examine_and_add_content (c);
188         BOOST_REQUIRE (!wait_for_jobs());
189
190         c->video->set_frame_type (VideoFrameType::THREE_D);
191         c->video->set_length (24);
192
193         film->set_three_d (true);
194         make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
195         film->write_metadata ();
196
197         auto jm = JobManager::instance ();
198         while (jm->work_to_do ()) {
199                 while (signal_manager->ui_idle()) {}
200                 dcpomatic_sleep_seconds (1);
201         }
202
203         while (signal_manager->ui_idle ()) {}
204
205         BOOST_REQUIRE (jm->errors());
206         shared_ptr<Job> failed;
207         for (auto i: jm->_jobs) {
208                 if (i->finished_in_error()) {
209                         BOOST_REQUIRE (!failed);
210                         failed = i;
211                 }
212         }
213         BOOST_REQUIRE (failed);
214         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()));
215
216         while (signal_manager->ui_idle ()) {}
217
218         JobManager::drop ();
219 }
220
221
222 /** Trigger a -114 error by trying to make a 3D DCP out of two files with slightly
223  *  different lengths.
224  */
225 BOOST_AUTO_TEST_CASE (threed_test_separate_files_slightly_different_lengths)
226 {
227         shared_ptr<Film> film = new_test_film2 ("threed_test3");
228         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
229         film->examine_and_add_content (L);
230         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
231         film->examine_and_add_content (R);
232         BOOST_REQUIRE (!wait_for_jobs());
233
234         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
235         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
236         R->set_trim_end (dcpomatic::ContentTime::from_frames(1, 24));
237
238         film->set_three_d (true);
239         make_and_verify_dcp (film);
240 }
241
242
243 /** Trigger a -114 error by trying to make a 3D DCP out of two files with very
244  *  different lengths.
245  */
246 BOOST_AUTO_TEST_CASE (threed_test_separate_files_very_different_lengths)
247 {
248         shared_ptr<Film> film = new_test_film2 ("threed_test3");
249         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
250         film->examine_and_add_content (L);
251         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
252         film->examine_and_add_content (R);
253         BOOST_REQUIRE (!wait_for_jobs());
254
255         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
256         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
257         R->set_trim_end (dcpomatic::ContentTime::from_seconds(1.5));
258
259         film->set_three_d (true);
260         make_and_verify_dcp (film);
261 }
262
263
264 BOOST_AUTO_TEST_CASE (threed_test_butler_overfill)
265 {
266         auto film = new_test_film2("threed_test_butler_overfill");
267         auto A = make_shared<FFmpegContent>(TestPaths::private_data() / "arrietty_JP-EN.mkv");
268         film->examine_and_add_content(A);
269         auto B = make_shared<FFmpegContent>(TestPaths::private_data() / "arrietty_JP-EN.mkv");
270         film->examine_and_add_content(B);
271         BOOST_REQUIRE (!wait_for_jobs());
272
273         auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
274         int const audio_channels = 2;
275         auto butler = std::make_shared<Butler>(
276                 film, player, AudioMapping(), audio_channels, boost::bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED
277                 );
278
279         int const audio_frames = 1920;
280         std::vector<float> audio(audio_frames * audio_channels);
281
282         B->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
283         B->set_position(film, dcpomatic::DCPTime());
284
285         butler->seek(dcpomatic::DCPTime(), true);
286         Butler::Error error;
287         for (auto i = 0; i < 960; ++i) {
288                 butler->get_video(Butler::Behaviour::BLOCKING, &error);
289                 butler->get_audio(Butler::Behaviour::BLOCKING, audio.data(), audio_frames);
290         }
291         BOOST_REQUIRE (error.code == Butler::Error::Code::NONE);
292 }
293