BOOST_FOREACH.
[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 using std::cout;
40 using std::shared_ptr;
41
42 /** Basic sanity check of 3D_LEFT_RIGHT */
43 BOOST_AUTO_TEST_CASE (threed_test1)
44 {
45         shared_ptr<Film> film = new_test_film ("threed_test1");
46         film->set_name ("test_film1");
47         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
48         film->examine_and_add_content (c);
49         BOOST_REQUIRE (!wait_for_jobs());
50
51         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT_RIGHT);
52
53         film->set_container (Ratio::from_id ("185"));
54         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
55         film->set_three_d (true);
56         film->make_dcp ();
57         film->write_metadata ();
58
59         BOOST_REQUIRE (!wait_for_jobs ());
60 }
61
62 /** Basic sanity check of 3D_ALTERNATE; at the moment this is just to make sure
63  *  that such a transcode completes without error.
64  */
65 BOOST_AUTO_TEST_CASE (threed_test2)
66 {
67         shared_ptr<Film> film = new_test_film ("threed_test2");
68         film->set_name ("test_film2");
69         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
70         film->examine_and_add_content (c);
71         BOOST_REQUIRE (!wait_for_jobs());
72
73         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D_ALTERNATE);
74
75         film->set_container (Ratio::from_id ("185"));
76         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
77         film->set_three_d (true);
78         film->make_dcp ();
79         film->write_metadata ();
80
81         BOOST_REQUIRE (!wait_for_jobs ());
82 }
83
84 /** Basic sanity check of 3D_LEFT and 3D_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         shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/test.mp4"));
91         film->examine_and_add_content (L);
92         shared_ptr<FFmpegContent> R (new 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 (VIDEO_FRAME_TYPE_3D_LEFT);
97         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
98
99         film->set_three_d (true);
100         film->make_dcp ();
101         film->write_metadata ();
102
103         BOOST_REQUIRE (!wait_for_jobs ());
104 }
105
106 BOOST_AUTO_TEST_CASE (threed_test4)
107 {
108         shared_ptr<Film> film = new_test_film2 ("threed_test4");
109         shared_ptr<FFmpegContent> L (new FFmpegContent(TestPaths::private_data() / "LEFT_TEST_DCP3D4K.mov"));
110         film->examine_and_add_content (L);
111         shared_ptr<FFmpegContent> R (new FFmpegContent(TestPaths::private_data() / "RIGHT_TEST_DCP3D4K.mov"));
112         film->examine_and_add_content (R);
113         BOOST_REQUIRE (!wait_for_jobs());
114
115         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
116         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
117         /* There doesn't seem much point in encoding the whole input, especially as we're only
118          * checking for errors during the encode and not the result.  Also decoding these files
119          * (4K HQ Prores) is very slow.
120          */
121         L->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
122         R->set_trim_end (dcpomatic::ContentTime::from_seconds(22));
123
124         film->set_three_d (true);
125         film->make_dcp ();
126         film->write_metadata ();
127
128         BOOST_REQUIRE (!wait_for_jobs ());
129 }
130
131 BOOST_AUTO_TEST_CASE (threed_test5)
132 {
133         shared_ptr<Film> film = new_test_film2 ("threed_test5");
134         shared_ptr<FFmpegContent> L (new FFmpegContent(TestPaths::private_data() / "boon_telly.mkv"));
135         film->examine_and_add_content (L);
136         shared_ptr<FFmpegContent> R (new FFmpegContent(TestPaths::private_data() / "boon_telly.mkv"));
137         film->examine_and_add_content (R);
138         BOOST_REQUIRE (!wait_for_jobs());
139
140         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
141         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
142         /* There doesn't seem much point in encoding the whole input, especially as we're only
143          * checking for errors during the encode and not the result.
144          */
145         L->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
146         R->set_trim_end (dcpomatic::ContentTime::from_seconds(3 * 60 + 20));
147
148         film->set_three_d (true);
149         film->make_dcp ();
150         film->write_metadata ();
151
152         BOOST_REQUIRE (!wait_for_jobs ());
153 }
154
155 BOOST_AUTO_TEST_CASE (threed_test6)
156 {
157         shared_ptr<Film> film = new_test_film2 ("threed_test6");
158         shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/3dL.mp4"));
159         film->examine_and_add_content (L);
160         shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/3dR.mp4"));
161         film->examine_and_add_content (R);
162         BOOST_REQUIRE (!wait_for_jobs());
163
164         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
165         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
166
167         film->set_three_d (true);
168         film->make_dcp ();
169         film->write_metadata ();
170
171         BOOST_REQUIRE (!wait_for_jobs());
172         check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
173 }
174
175 /** Check 2D content set as being 3D; this should give an informative error */
176 BOOST_AUTO_TEST_CASE (threed_test7)
177 {
178         using boost::filesystem::path;
179
180         shared_ptr<Film> film = new_test_film2 ("threed_test7");
181         path const content_path = "test/data/red_24.mp4";
182         shared_ptr<FFmpegContent> c (new FFmpegContent(content_path));
183         film->examine_and_add_content (c);
184         BOOST_REQUIRE (!wait_for_jobs());
185
186         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D);
187
188         film->set_three_d (true);
189         film->make_dcp ();
190         film->write_metadata ();
191
192         JobManager* jm = JobManager::instance ();
193         while (jm->work_to_do ()) {
194                 while (signal_manager->ui_idle()) {}
195                 dcpomatic_sleep_seconds (1);
196         }
197
198         while (signal_manager->ui_idle ()) {}
199
200         std::cout << "Here's the jobs:\n";
201         for (auto i: jm->_jobs) {
202                 std::cout << i->name() << " " << i->status() << " " << i->is_new() << " " << i->running() << " " << i->finished() << " " << i->finished_ok() << " " << i->finished_in_error() << "\n";
203         }
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 }