2 Copyright (C) 2013-2021 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 /** @file test/threed_test.cc
23 * @brief Create some 3D DCPs (without comparing the results to anything).
24 * @ingroup completedcp
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.h"
33 #include "lib/dcp_content_type.h"
34 #include "lib/ffmpeg_content.h"
36 #include "lib/image.h"
38 #include "lib/job_manager.h"
39 #include "lib/make_dcp.h"
40 #include "lib/player.h"
41 #include "lib/ratio.h"
43 #include "lib/video_content.h"
45 #include <dcp/mono_picture_asset.h>
46 #include <dcp/stereo_picture_asset.h>
47 #include <boost/test/unit_test.hpp>
52 using std::make_shared;
53 using std::shared_ptr;
56 /** Basic sanity check of THREE_D_LEFT_RIGHT */
57 BOOST_AUTO_TEST_CASE (threed_test1)
59 auto film = new_test_film ("threed_test1");
60 film->set_name ("test_film1");
61 auto c = make_shared<FFmpegContent>("test/data/test.mp4");
62 film->examine_and_add_content (c);
63 BOOST_REQUIRE (!wait_for_jobs());
65 c->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
67 film->set_container (Ratio::from_id ("185"));
68 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
69 film->set_three_d (true);
70 make_and_verify_dcp (film);
74 /** Basic sanity check of THREE_D_ALTERNATE; at the moment this is just to make sure
75 * that such a transcode completes without error.
77 BOOST_AUTO_TEST_CASE (threed_test2)
79 auto film = new_test_film ("threed_test2");
80 film->set_name ("test_film2");
81 auto c = make_shared<FFmpegContent>("test/data/test.mp4");
82 film->examine_and_add_content (c);
83 BOOST_REQUIRE (!wait_for_jobs());
85 c->video->set_frame_type (VideoFrameType::THREE_D_ALTERNATE);
87 film->set_container (Ratio::from_id ("185"));
88 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
89 film->set_three_d (true);
90 make_and_verify_dcp (film);
94 /** Basic sanity check of THREE_D_LEFT and THREE_D_RIGHT; at the moment this is just to make sure
95 * that such a transcode completes without error.
97 BOOST_AUTO_TEST_CASE (threed_test3)
99 auto film = new_test_film2 ("threed_test3");
100 auto L = make_shared<FFmpegContent>("test/data/test.mp4");
101 film->examine_and_add_content (L);
102 auto R = make_shared<FFmpegContent>("test/data/test.mp4");
103 film->examine_and_add_content (R);
104 BOOST_REQUIRE (!wait_for_jobs());
106 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
107 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
109 film->set_three_d (true);
110 make_and_verify_dcp (film);
114 BOOST_AUTO_TEST_CASE (threed_test4)
118 /* Try to stop out-of-memory crashes on my laptop */
119 Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency() / 4);
121 auto film = new_test_film2 ("threed_test4");
122 auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "LEFT_TEST_DCP3D4K.mov");
123 film->examine_and_add_content (L);
124 auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "RIGHT_TEST_DCP3D4K.mov");
125 film->examine_and_add_content (R);
126 BOOST_REQUIRE (!wait_for_jobs());
128 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
129 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
130 /* There doesn't seem much point in encoding the whole input, especially as we're only
131 * checking for errors during the encode and not the result. Also decoding these files
132 * (4K HQ Prores) is very slow.
134 L->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
135 R->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
137 film->set_three_d (true);
140 {dcp::VerificationNote::Code::INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D},
142 /* XXX: Clairmeta error about invalid edit rate 24 for 4K 3D */
148 BOOST_AUTO_TEST_CASE (threed_test5)
150 auto film = new_test_film2 ("threed_test5");
151 auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
152 film->examine_and_add_content (L);
153 auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
154 film->examine_and_add_content (R);
155 BOOST_REQUIRE (!wait_for_jobs());
157 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
158 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
159 /* There doesn't seem much point in encoding the whole input, especially as we're only
160 * checking for errors during the encode and not the result.
162 L->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
163 R->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
165 film->set_three_d (true);
166 make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K});
170 BOOST_AUTO_TEST_CASE (threed_test6)
172 auto film = new_test_film2 ("threed_test6");
173 auto L = make_shared<FFmpegContent>("test/data/3dL.mp4");
174 film->examine_and_add_content (L);
175 auto R = make_shared<FFmpegContent>("test/data/3dR.mp4");
176 film->examine_and_add_content (R);
177 film->set_audio_channels(16);
178 BOOST_REQUIRE (!wait_for_jobs());
180 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
181 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
183 film->set_three_d (true);
184 make_and_verify_dcp (film);
185 check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
189 /** Check 2D content set as being 3D; this should give an informative error */
190 BOOST_AUTO_TEST_CASE (threed_test7)
192 using boost::filesystem::path;
194 auto film = new_test_film2 ("threed_test7");
195 path const content_path = "test/data/flat_red.png";
196 auto c = content_factory(content_path)[0];
197 film->examine_and_add_content (c);
198 BOOST_REQUIRE (!wait_for_jobs());
200 c->video->set_frame_type (VideoFrameType::THREE_D);
201 c->video->set_length (24);
203 film->set_three_d (true);
204 make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
205 film->write_metadata ();
207 auto jm = JobManager::instance ();
208 while (jm->work_to_do ()) {
209 while (signal_manager->ui_idle()) {}
210 dcpomatic_sleep_seconds (1);
213 while (signal_manager->ui_idle ()) {}
215 BOOST_REQUIRE (jm->errors());
216 shared_ptr<Job> failed;
217 for (auto i: jm->_jobs) {
218 if (i->finished_in_error()) {
219 BOOST_REQUIRE (!failed);
223 BOOST_REQUIRE (failed);
224 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()));
226 while (signal_manager->ui_idle ()) {}
232 /** Trigger a -114 error by trying to make a 3D DCP out of two files with slightly
235 BOOST_AUTO_TEST_CASE (threed_test_separate_files_slightly_different_lengths)
237 auto film = new_test_film2("threed_test3");
238 auto L = make_shared<FFmpegContent>("test/data/test.mp4");
239 film->examine_and_add_content (L);
240 auto R = make_shared<FFmpegContent>("test/data/test.mp4");
241 film->examine_and_add_content (R);
242 BOOST_REQUIRE (!wait_for_jobs());
244 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
245 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
246 R->set_trim_end (dcpomatic::ContentTime::from_frames(1, 24));
248 film->set_three_d (true);
249 make_and_verify_dcp (film);
253 /** Trigger a -114 error by trying to make a 3D DCP out of two files with very
256 BOOST_AUTO_TEST_CASE (threed_test_separate_files_very_different_lengths)
258 auto film = new_test_film2("threed_test3");
259 auto L = make_shared<FFmpegContent>("test/data/test.mp4");
260 film->examine_and_add_content (L);
261 auto R = make_shared<FFmpegContent>("test/data/test.mp4");
262 film->examine_and_add_content (R);
263 BOOST_REQUIRE (!wait_for_jobs());
265 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
266 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
267 R->set_trim_end (dcpomatic::ContentTime::from_seconds(1.5));
269 film->set_three_d (true);
270 make_and_verify_dcp (film);
274 BOOST_AUTO_TEST_CASE (threed_test_butler_overfill)
276 auto film = new_test_film2("threed_test_butler_overfill");
277 auto A = make_shared<FFmpegContent>(TestPaths::private_data() / "arrietty_JP-EN.mkv");
278 film->examine_and_add_content(A);
279 auto B = make_shared<FFmpegContent>(TestPaths::private_data() / "arrietty_JP-EN.mkv");
280 film->examine_and_add_content(B);
281 BOOST_REQUIRE (!wait_for_jobs());
283 Player player(film, Image::Alignment::COMPACT);
284 int const audio_channels = 2;
285 auto butler = std::make_shared<Butler>(
286 film, player, AudioMapping(), audio_channels, boost::bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED
289 int const audio_frames = 1920;
290 std::vector<float> audio(audio_frames * audio_channels);
292 B->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
293 B->set_position(film, dcpomatic::DCPTime());
295 butler->seek(dcpomatic::DCPTime(), true);
297 for (auto i = 0; i < 960; ++i) {
298 butler->get_video(Butler::Behaviour::BLOCKING, &error);
299 butler->get_audio(Butler::Behaviour::BLOCKING, audio.data(), audio_frames);
301 BOOST_REQUIRE (error.code == Butler::Error::Code::NONE);
305 /** Check that creating a 2D DCP from a 3D DCP passes the J2K data unaltered */
306 BOOST_AUTO_TEST_CASE(threed_passthrough_test, * boost::unit_test::depends_on("threed_test6"))
308 using namespace boost::filesystem;
310 /* Find the DCP in threed_test6 */
311 boost::optional<path> input_dcp;
312 for (auto i: directory_iterator("build/test/threed_test6")) {
313 if (is_directory(i.path()) && boost::algorithm::starts_with(i.path().filename().string(), "Dcp")) {
314 input_dcp = i.path();
318 BOOST_REQUIRE(input_dcp);
320 auto content = make_shared<DCPContent>(*input_dcp);
321 auto film = new_test_film2("threed_passthrough_test", { content });
322 film->set_three_d(false);
324 make_and_verify_dcp(film);
326 std::vector<directory_entry> matches;
327 std::copy_if(recursive_directory_iterator(*input_dcp), recursive_directory_iterator(), std::back_inserter(matches), [](directory_entry const& entry) {
328 return boost::algorithm::starts_with(entry.path().filename().string(), "j2c");
331 BOOST_REQUIRE_EQUAL(matches.size(), 1U);
333 auto stereo = dcp::StereoPictureAsset(matches[0]);
334 auto stereo_reader = stereo.start_read();
336 auto mono = dcp::MonoPictureAsset(dcp_file(film, "j2c"));
337 auto mono_reader = mono.start_read();
339 BOOST_REQUIRE_EQUAL(stereo.intrinsic_duration(), mono.intrinsic_duration());
341 for (auto i = 0; i < stereo.intrinsic_duration(); ++i) {
342 auto stereo_frame = stereo_reader->get_frame(i);
343 auto mono_frame = mono_reader->get_frame(i);
344 BOOST_REQUIRE(stereo_frame->left()->size() == mono_frame->size());
345 BOOST_REQUIRE_EQUAL(memcmp(stereo_frame->left()->data(), mono_frame->data(), mono_frame->size()), 0);
349 /* #2476 was a writer error when 3D picture padding is needed */
350 BOOST_AUTO_TEST_CASE(threed_test_when_padding_needed)
352 auto left = content_factory("test/data/flat_red.png").front();
353 auto right = content_factory("test/data/flat_red.png").front();
354 auto sound = content_factory("test/data/sine_440.wav").front();
355 auto film = new_test_film2("threed_test_when_padding_needed", { left, right, sound });
357 left->video->set_frame_type(VideoFrameType::THREE_D_LEFT);
358 left->set_position(film, dcpomatic::DCPTime());
359 left->video->set_length(23);
360 right->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
361 right->set_position(film, dcpomatic::DCPTime());
362 right->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
363 right->video->set_length(23);
364 film->set_three_d(true);
366 make_and_verify_dcp(film);