Move private_data into TestPaths
[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 boost::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         c->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
53
54         film->set_container (Ratio::from_id ("185"));
55         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
56         film->set_three_d (true);
57         film->make_dcp ();
58         film->write_metadata ();
59
60         BOOST_REQUIRE (!wait_for_jobs ());
61 }
62
63 /** Basic sanity check of 3D_ALTERNATE; at the moment this is just to make sure
64  *  that such a transcode completes without error.
65  */
66 BOOST_AUTO_TEST_CASE (threed_test2)
67 {
68         shared_ptr<Film> film = new_test_film ("threed_test2");
69         film->set_name ("test_film2");
70         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
71         film->examine_and_add_content (c);
72         BOOST_REQUIRE (!wait_for_jobs());
73
74         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D_ALTERNATE);
75         c->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
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         film->make_dcp ();
81         film->write_metadata ();
82
83         BOOST_REQUIRE (!wait_for_jobs ());
84 }
85
86 /** Basic sanity check of 3D_LEFT and 3D_RIGHT; at the moment this is just to make sure
87  *  that such a transcode completes without error.
88  */
89 BOOST_AUTO_TEST_CASE (threed_test3)
90 {
91         shared_ptr<Film> film = new_test_film2 ("threed_test3");
92         shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/test.mp4"));
93         film->examine_and_add_content (L);
94         shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/test.mp4"));
95         film->examine_and_add_content (R);
96         BOOST_REQUIRE (!wait_for_jobs());
97
98         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
99         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
100
101         film->set_three_d (true);
102         film->make_dcp ();
103         film->write_metadata ();
104
105         BOOST_REQUIRE (!wait_for_jobs ());
106 }
107
108 BOOST_AUTO_TEST_CASE (threed_test4)
109 {
110         Config::instance()->set_master_encoding_threads (8);
111
112         shared_ptr<Film> film = new_test_film2 ("threed_test4");
113         shared_ptr<FFmpegContent> L (new FFmpegContent(TestPaths::private_data / "LEFT_TEST_DCP3D4K.mov"));
114         film->examine_and_add_content (L);
115         shared_ptr<FFmpegContent> R (new FFmpegContent(TestPaths::private_data / "RIGHT_TEST_DCP3D4K.mov"));
116         film->examine_and_add_content (R);
117         BOOST_REQUIRE (!wait_for_jobs());
118
119         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
120         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
121
122         film->set_three_d (true);
123         film->make_dcp ();
124         film->write_metadata ();
125
126         BOOST_REQUIRE (!wait_for_jobs ());
127
128         Config::instance()->set_master_encoding_threads (8);
129 }
130
131 BOOST_AUTO_TEST_CASE (threed_test5)
132 {
133         Config::instance()->set_master_encoding_threads (8);
134
135         shared_ptr<Film> film = new_test_film2 ("threed_test5");
136         shared_ptr<FFmpegContent> L (new FFmpegContent(TestPaths::private_data / "boon_telly.mkv"));
137         film->examine_and_add_content (L);
138         shared_ptr<FFmpegContent> R (new FFmpegContent(TestPaths::private_data / "boon_telly.mkv"));
139         film->examine_and_add_content (R);
140         BOOST_REQUIRE (!wait_for_jobs());
141
142         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
143         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
144
145         film->set_three_d (true);
146         film->make_dcp ();
147         film->write_metadata ();
148
149         BOOST_REQUIRE (!wait_for_jobs ());
150
151         Config::instance()->set_master_encoding_threads (1);
152 }
153
154 BOOST_AUTO_TEST_CASE (threed_test6)
155 {
156         shared_ptr<Film> film = new_test_film2 ("threed_test6");
157         shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/3dL.mp4"));
158         film->examine_and_add_content (L);
159         shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/3dR.mp4"));
160         film->examine_and_add_content (R);
161         BOOST_REQUIRE (!wait_for_jobs());
162
163         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
164         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
165
166         film->set_three_d (true);
167         film->make_dcp ();
168         film->write_metadata ();
169
170         BOOST_REQUIRE (!wait_for_jobs());
171         check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
172 }
173
174 /** Check 2D content set as being 3D; this should give an informative error */
175 BOOST_AUTO_TEST_CASE (threed_test7)
176 {
177         shared_ptr<Film> film = new_test_film2 ("threed_test7");
178         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/red_24.mp4"));
179         film->examine_and_add_content (c);
180         BOOST_REQUIRE (!wait_for_jobs());
181
182         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D);
183
184         film->set_three_d (true);
185         film->make_dcp ();
186         film->write_metadata ();
187
188         JobManager* jm = JobManager::instance ();
189         while (jm->work_to_do ()) {
190                 while (signal_manager->ui_idle()) {}
191                 dcpomatic_sleep_seconds (1);
192         }
193
194         while (signal_manager->ui_idle ()) {}
195
196         std::cout << "Here's the jobs:\n";
197         BOOST_FOREACH (shared_ptr<Job> i, jm->_jobs) {
198                 std::cout << i->name() << " " << i->status() << " " << i->is_new() << " " << i->running() << " " << i->finished() << " " << i->finished_ok() << " " << i->finished_in_error() << "\n";
199         }
200
201         BOOST_REQUIRE (jm->errors());
202         shared_ptr<Job> failed;
203         BOOST_FOREACH (shared_ptr<Job> i, jm->_jobs) {
204                 if (i->finished_in_error()) {
205                         BOOST_REQUIRE (!failed);
206                         failed = i;
207                 }
208         }
209         BOOST_REQUIRE (failed);
210         BOOST_CHECK_EQUAL (failed->error_summary(), "The content file test/data/red_24.mp4 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.");
211
212         while (signal_manager->ui_idle ()) {}
213
214         JobManager::drop ();
215 }