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_type.h"
33 #include "lib/ffmpeg_content.h"
35 #include "lib/image.h"
37 #include "lib/job_manager.h"
38 #include "lib/make_dcp.h"
39 #include "lib/player.h"
40 #include "lib/ratio.h"
42 #include "lib/video_content.h"
44 #include <boost/test/unit_test.hpp>
49 using std::make_shared;
50 using std::shared_ptr;
53 /** Basic sanity check of THREE_D_LEFT_RIGHT */
54 BOOST_AUTO_TEST_CASE (threed_test1)
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());
62 c->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
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);
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.
74 BOOST_AUTO_TEST_CASE (threed_test2)
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());
82 c->video->set_frame_type (VideoFrameType::THREE_D_ALTERNATE);
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);
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.
94 BOOST_AUTO_TEST_CASE (threed_test3)
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());
103 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
104 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
106 film->set_three_d (true);
107 make_and_verify_dcp (film);
111 BOOST_AUTO_TEST_CASE (threed_test4)
115 /* Try to stop out-of-memory crashes on my laptop */
116 Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency() / 4);
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());
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.
131 L->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
132 R->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
134 film->set_three_d (true);
135 make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D});
139 BOOST_AUTO_TEST_CASE (threed_test5)
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());
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.
153 L->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
154 R->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
156 film->set_three_d (true);
157 make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K});
161 BOOST_AUTO_TEST_CASE (threed_test6)
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());
170 L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
171 R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
173 film->set_three_d (true);
174 make_and_verify_dcp (film);
175 check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
179 /** Check 2D content set as being 3D; this should give an informative error */
180 BOOST_AUTO_TEST_CASE (threed_test7)
182 using boost::filesystem::path;
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());
190 c->video->set_frame_type (VideoFrameType::THREE_D);
191 c->video->set_length (24);
193 film->set_three_d (true);
194 make_dcp (film, TranscodeJob::ChangedBehaviour::IGNORE);
195 film->write_metadata ();
197 auto jm = JobManager::instance ();
198 while (jm->work_to_do ()) {
199 while (signal_manager->ui_idle()) {}
200 dcpomatic_sleep_seconds (1);
203 while (signal_manager->ui_idle ()) {}
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);
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()));
216 while (signal_manager->ui_idle ()) {}
222 /** Trigger a -114 error by trying to make a 3D DCP out of two files with slightly
225 BOOST_AUTO_TEST_CASE (threed_test_separate_files_slightly_different_lengths)
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());
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));
238 film->set_three_d (true);
239 make_and_verify_dcp (film);
243 /** Trigger a -114 error by trying to make a 3D DCP out of two files with very
246 BOOST_AUTO_TEST_CASE (threed_test_separate_files_very_different_lengths)
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());
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));
259 film->set_three_d (true);
260 make_and_verify_dcp (film);
264 BOOST_AUTO_TEST_CASE (threed_test_butler_overfill)
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());
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
279 int const audio_frames = 1920;
280 std::vector<float> audio(audio_frames * audio_channels);
282 B->video->set_frame_type(VideoFrameType::THREE_D_RIGHT);
283 B->set_position(film, dcpomatic::DCPTime());
285 butler->seek(dcpomatic::DCPTime(), true);
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);
291 BOOST_REQUIRE (error.code == Butler::Error::Code::NONE);