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