Fix memory leak which also causes strange flickering in the audio
[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 "lib/dcpomatic_log.h"
37 #include <boost/test/unit_test.hpp>
38 #include <iostream>
39
40 using std::cout;
41 using boost::shared_ptr;
42
43 /** Basic sanity check of 3D_LEFT_RIGHT */
44 BOOST_AUTO_TEST_CASE (threed_test1)
45 {
46         shared_ptr<Film> film = new_test_film ("threed_test1");
47         film->set_name ("test_film1");
48         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
49         film->examine_and_add_content (c);
50         BOOST_REQUIRE (!wait_for_jobs());
51
52         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT_RIGHT);
53         c->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
54
55         film->set_container (Ratio::from_id ("185"));
56         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
57         film->set_three_d (true);
58         film->make_dcp ();
59         film->write_metadata ();
60
61         BOOST_REQUIRE (!wait_for_jobs ());
62 }
63
64 /** Basic sanity check of 3D_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         shared_ptr<Film> film = new_test_film ("threed_test2");
70         film->set_name ("test_film2");
71         shared_ptr<FFmpegContent> c (new 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 (VIDEO_FRAME_TYPE_3D_ALTERNATE);
76         c->video->set_scale (VideoContentScale (Ratio::from_id ("185")));
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 3D_LEFT and 3D_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         shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/test.mp4"));
94         film->examine_and_add_content (L);
95         shared_ptr<FFmpegContent> R (new 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 (VIDEO_FRAME_TYPE_3D_LEFT);
100         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_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         Config::instance()->set_master_encoding_threads (8);
112
113         shared_ptr<Film> film = new_test_film2 ("threed_test4");
114         shared_ptr<FFmpegContent> L (new FFmpegContent(private_data / "LEFT_TEST_DCP3D4K.mov"));
115         film->examine_and_add_content (L);
116         shared_ptr<FFmpegContent> R (new FFmpegContent(private_data / "RIGHT_TEST_DCP3D4K.mov"));
117         film->examine_and_add_content (R);
118         BOOST_REQUIRE (!wait_for_jobs());
119
120         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
121         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
122
123         film->set_three_d (true);
124         film->make_dcp ();
125         film->write_metadata ();
126
127         BOOST_REQUIRE (!wait_for_jobs ());
128
129         Config::instance()->set_master_encoding_threads (8);
130 }
131
132 BOOST_AUTO_TEST_CASE (threed_test5)
133 {
134         Config::instance()->set_master_encoding_threads (8);
135
136         shared_ptr<Film> film = new_test_film2 ("threed_test5");
137         dcpomatic_log = film->log();
138         shared_ptr<FFmpegContent> L (new FFmpegContent(private_data / "boon_telly.mkv"));
139         film->examine_and_add_content (L);
140         shared_ptr<FFmpegContent> R (new FFmpegContent(private_data / "boon_telly.mkv"));
141         film->examine_and_add_content (R);
142         BOOST_REQUIRE (!wait_for_jobs());
143
144         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
145         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
146
147         film->set_three_d (true);
148         film->make_dcp ();
149         film->write_metadata ();
150
151         BOOST_REQUIRE (!wait_for_jobs ());
152
153         Config::instance()->set_master_encoding_threads (1);
154 }
155
156 BOOST_AUTO_TEST_CASE (threed_test6)
157 {
158         shared_ptr<Film> film = new_test_film2 ("threed_test6");
159         shared_ptr<FFmpegContent> L (new FFmpegContent("test/data/3dL.mp4"));
160         film->examine_and_add_content (L);
161         shared_ptr<FFmpegContent> R (new FFmpegContent("test/data/3dR.mp4"));
162         film->examine_and_add_content (R);
163         BOOST_REQUIRE (!wait_for_jobs());
164
165         L->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT);
166         R->video->set_frame_type (VIDEO_FRAME_TYPE_3D_RIGHT);
167
168         film->set_three_d (true);
169         film->make_dcp ();
170         film->write_metadata ();
171
172         BOOST_REQUIRE (!wait_for_jobs());
173         check_dcp ("test/data/threed_test6", film->dir(film->dcp_name()));
174 }
175
176 /** Check 2D content set as being 3D; this should give an informative error */
177 BOOST_AUTO_TEST_CASE (threed_test7)
178 {
179         shared_ptr<Film> film = new_test_film2 ("threed_test7");
180         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/red_24.mp4"));
181         film->examine_and_add_content (c);
182         BOOST_REQUIRE (!wait_for_jobs());
183
184         c->video->set_frame_type (VIDEO_FRAME_TYPE_3D);
185
186         film->set_three_d (true);
187         film->make_dcp ();
188         film->write_metadata ();
189
190         JobManager* jm = JobManager::instance ();
191         while (jm->work_to_do ()) {
192                 while (signal_manager->ui_idle()) {}
193                 dcpomatic_sleep (1);
194         }
195
196         BOOST_REQUIRE (jm->errors());
197         shared_ptr<Job> failed;
198         BOOST_FOREACH (shared_ptr<Job> i, jm->_jobs) {
199                 if (i->finished_in_error()) {
200                         BOOST_REQUIRE (!failed);
201                         failed = i;
202                 }
203         }
204         BOOST_REQUIRE (failed);
205         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.");
206
207         while (signal_manager->ui_idle ()) {}
208
209         JobManager::drop ();
210 }