a4889645f100064e2ae1bbc8008e6f97fd887870
[dcpomatic.git] / test / threed_test.cc
1 /*
2     Copyright (C) 2013-2019 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 /** @file  test/threed_test.cc
22  *  @brief Create some 3D DCPs (without comparing the results to anything).
23  *  @ingroup completedcp
24  */
25
26 #include "lib/config.h"
27 #include "lib/content_factory.h"
28 #include "lib/cross.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/ffmpeg_content.h"
31 #include "lib/film.h"
32 #include "lib/job.h"
33 #include "lib/job_manager.h"
34 #include "lib/ratio.h"
35 #include "lib/video_content.h"
36 #include "test.h"
37 #include <boost/test/unit_test.hpp>
38 #include <iostream>
39
40
41 using std::cout;
42 using std::make_shared;
43 using std::shared_ptr;
44
45
46 /** Basic sanity check of THREE_D_LEFT_RIGHT */
47 BOOST_AUTO_TEST_CASE (threed_test1)
48 {
49         auto film = new_test_film ("threed_test1");
50         film->set_name ("test_film1");
51         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
52         film->examine_and_add_content (c);
53         BOOST_REQUIRE (!wait_for_jobs());
54
55         c->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
56
57         film->set_container (Ratio::from_id ("185"));
58         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
59         film->set_three_d (true);
60         make_and_verify_dcp (film);
61 }
62
63
64 /** Basic sanity check of THREE_D_ALTERNATE; at the moment this is just to make sure
65  *  that such a transcode completes without error.
66  */
67 BOOST_AUTO_TEST_CASE (threed_test2)
68 {
69         auto film = new_test_film ("threed_test2");
70         film->set_name ("test_film2");
71         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
72         film->examine_and_add_content (c);
73         BOOST_REQUIRE (!wait_for_jobs());
74
75         c->video->set_frame_type (VideoFrameType::THREE_D_ALTERNATE);
76
77         film->set_container (Ratio::from_id ("185"));
78         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
79         film->set_three_d (true);
80         make_and_verify_dcp (film);
81 }
82
83
84 /** Basic sanity check of THREE_D_LEFT and THREE_D_RIGHT; at the moment this is just to make sure
85  *  that such a transcode completes without error.
86  */
87 BOOST_AUTO_TEST_CASE (threed_test3)
88 {
89         shared_ptr<Film> film = new_test_film2 ("threed_test3");
90         auto L = make_shared<FFmpegContent>("test/data/test.mp4");
91         film->examine_and_add_content (L);
92         auto R = make_shared<FFmpegContent>("test/data/test.mp4");
93         film->examine_and_add_content (R);
94         BOOST_REQUIRE (!wait_for_jobs());
95
96         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
97         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
98
99         film->set_three_d (true);
100         make_and_verify_dcp (film);
101 }
102
103
104 BOOST_AUTO_TEST_CASE (threed_test4)
105 {
106         auto film = new_test_film2 ("threed_test4");
107         auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "LEFT_TEST_DCP3D4K.mov");
108         film->examine_and_add_content (L);
109         auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "RIGHT_TEST_DCP3D4K.mov");
110         film->examine_and_add_content (R);
111         BOOST_REQUIRE (!wait_for_jobs());
112
113         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
114         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
115         /* There doesn't seem much point in encoding the whole input, especially as we're only
116          * checking for errors during the encode and not the result.  Also decoding these files
117          * (4K HQ Prores) is very slow.
118          */
119         L->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
120         R->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
121
122         film->set_three_d (true);
123         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D});
124 }
125
126
127 BOOST_AUTO_TEST_CASE (threed_test5)
128 {
129         auto film = new_test_film2 ("threed_test5");
130         auto L = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
131         film->examine_and_add_content (L);
132         auto R = make_shared<FFmpegContent>(TestPaths::private_data() / "boon_telly.mkv");
133         film->examine_and_add_content (R);
134         BOOST_REQUIRE (!wait_for_jobs());
135
136         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
137         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
138         /* There doesn't seem much point in encoding the whole input, especially as we're only
139          * checking for errors during the encode and not the result.
140          */
141         L->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
142         R->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
143
144         film->set_three_d (true);
145         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K});
146 }
147
148
149 BOOST_AUTO_TEST_CASE (threed_test6)
150 {
151         auto film = new_test_film2 ("threed_test6");
152         auto L = make_shared<FFmpegContent>("test/data/3dL.mp4");
153         film->examine_and_add_content (L);
154         auto R = make_shared<FFmpegContent>("test/data/3dR.mp4");
155         film->examine_and_add_content (R);
156         BOOST_REQUIRE (!wait_for_jobs());
157
158         L->video->set_frame_type (VideoFrameType::THREE_D_LEFT);
159         R->video->set_frame_type (VideoFrameType::THREE_D_RIGHT);
160
161         film->set_three_d (true);
162         make_and_verify_dcp (film);
163         check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
164 }
165
166
167 /** Check 2D content set as being 3D; this should give an informative error */
168 BOOST_AUTO_TEST_CASE (threed_test7)
169 {
170         using boost::filesystem::path;
171
172         auto film = new_test_film2 ("threed_test7");
173         path const content_path = "test/data/flat_red.png";
174         auto c = content_factory(content_path).front();
175         film->examine_and_add_content (c);
176         BOOST_REQUIRE (!wait_for_jobs());
177
178         c->video->set_frame_type (VideoFrameType::THREE_D);
179         c->video->set_length (24);
180
181         film->set_three_d (true);
182         film->make_dcp ();
183         film->write_metadata ();
184
185         auto jm = JobManager::instance ();
186         while (jm->work_to_do ()) {
187                 while (signal_manager->ui_idle()) {}
188                 dcpomatic_sleep_seconds (1);
189         }
190
191         while (signal_manager->ui_idle ()) {}
192
193         BOOST_REQUIRE (jm->errors());
194         shared_ptr<Job> failed;
195         for (auto i: jm->_jobs) {
196                 if (i->finished_in_error()) {
197                         BOOST_REQUIRE (!failed);
198                         failed = i;
199                 }
200         }
201         BOOST_REQUIRE (failed);
202         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()));
203
204         while (signal_manager->ui_idle ()) {}
205
206         JobManager::drop ();
207 }