2 Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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.
11 libdcp 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.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
23 #include "mono_picture_asset.h"
24 #include "stereo_picture_asset.h"
25 #include "picture_asset_writer.h"
26 #include "sound_asset_writer.h"
27 #include "sound_asset.h"
28 #include "atmos_asset.h"
32 #include "reel_mono_picture_asset.h"
33 #include "reel_stereo_picture_asset.h"
34 #include "reel_sound_asset.h"
35 #include "reel_atmos_asset.h"
36 #include <asdcp/KM_util.h>
38 #include <boost/test/unit_test.hpp>
41 using boost::shared_ptr;
43 static shared_ptr<dcp::DCP>
44 make_simple (boost::filesystem::path path)
46 Kumu::cth_test = true;
48 /* Some known metadata */
49 dcp::XMLMetadata xml_meta;
50 xml_meta.annotation_text = "Created by libdcp";
51 xml_meta.issuer = "OpenDCP 0.0.25";
52 xml_meta.creator = "OpenDCP 0.0.25";
53 xml_meta.issue_date = "2012-07-17T04:45:18+00:00";
54 dcp::MXFMetadata mxf_meta;
55 mxf_meta.company_name = "OpenDCP";
56 mxf_meta.product_name = "OpenDCP";
57 mxf_meta.product_version = "0.0.25";
59 /* We're making build/test/DCP/dcp_test1 */
60 boost::filesystem::remove_all (path);
61 boost::filesystem::create_directories (path);
62 shared_ptr<dcp::DCP> d (new dcp::DCP (path));
63 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE));
64 cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
65 cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
66 cpl->set_metadata (xml_meta);
68 shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1)));
69 mp->set_metadata (mxf_meta);
70 shared_ptr<dcp::PictureAssetWriter> picture_writer = mp->start_write (path / "video.mxf", dcp::SMPTE, false);
71 dcp::File j2c ("test/data/32x32_red_square.j2c");
72 for (int i = 0; i < 24; ++i) {
73 picture_writer->write (j2c.data (), j2c.size ());
75 picture_writer->finalize ();
77 shared_ptr<dcp::SoundAsset> ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1));
78 ms->set_metadata (mxf_meta);
79 shared_ptr<dcp::SoundAssetWriter> sound_writer = ms->start_write (path / "audio.mxf", dcp::SMPTE);
83 SNDFILE* sndfile = sf_open ("test/data/1s_24-bit_48k_silence.wav", SFM_READ, &info);
84 BOOST_CHECK (sndfile);
89 sf_count_t N = sf_readf_float (sndfile, buffer, 4096);
90 sound_writer->write (channels, N);
96 sound_writer->finalize ();
98 cpl->add (shared_ptr<dcp::Reel> (
100 shared_ptr<dcp::ReelMonoPictureAsset> (new dcp::ReelMonoPictureAsset (mp, 0)),
101 shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (ms, 0))
109 /** Test creation of a 2D SMPTE DCP from very simple inputs */
110 BOOST_AUTO_TEST_CASE (dcp_test1)
112 dcp::XMLMetadata xml_meta;
113 xml_meta.annotation_text = "Created by libdcp";
114 xml_meta.issuer = "OpenDCP 0.0.25";
115 xml_meta.creator = "OpenDCP 0.0.25";
116 xml_meta.issue_date = "2012-07-17T04:45:18+00:00";
117 make_simple("build/test/DCP/dcp_test1")->write_xml (dcp::SMPTE, xml_meta);
118 /* build/test/DCP/dcp_test1 is checked against test/ref/DCP/dcp_test1 by run/tests */
121 /** Test creation of a 3D DCP from very simple inputs */
122 BOOST_AUTO_TEST_CASE (dcp_test2)
124 Kumu::cth_test = true;
126 /* Some known metadata */
127 dcp::XMLMetadata xml_meta;
128 xml_meta.annotation_text = "Created by libdcp";
129 xml_meta.issuer = "OpenDCP 0.0.25";
130 xml_meta.creator = "OpenDCP 0.0.25";
131 xml_meta.issue_date = "2012-07-17T04:45:18+00:00";
132 dcp::MXFMetadata mxf_meta;
133 mxf_meta.company_name = "OpenDCP";
134 mxf_meta.product_name = "OpenDCP";
135 mxf_meta.product_version = "0.0.25";
137 /* We're making build/test/DCP/dcp_test2 */
138 boost::filesystem::remove_all ("build/test/DCP/dcp_test2");
139 boost::filesystem::create_directories ("build/test/DCP/dcp_test2");
140 dcp::DCP d ("build/test/DCP/dcp_test2");
141 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE));
142 cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
143 cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
144 cpl->set_metadata (xml_meta);
146 shared_ptr<dcp::StereoPictureAsset> mp (new dcp::StereoPictureAsset (dcp::Fraction (24, 1)));
147 mp->set_metadata (mxf_meta);
148 shared_ptr<dcp::PictureAssetWriter> picture_writer = mp->start_write ("build/test/DCP/dcp_test2/video.mxf", dcp::SMPTE, false);
149 dcp::File j2c ("test/data/32x32_red_square.j2c");
150 for (int i = 0; i < 24; ++i) {
152 picture_writer->write (j2c.data (), j2c.size ());
154 picture_writer->write (j2c.data (), j2c.size ());
156 picture_writer->finalize ();
158 shared_ptr<dcp::SoundAsset> ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1));
159 ms->set_metadata (mxf_meta);
160 shared_ptr<dcp::SoundAssetWriter> sound_writer = ms->start_write ("build/test/DCP/dcp_test2/audio.mxf", dcp::SMPTE);
164 SNDFILE* sndfile = sf_open ("test/data/1s_24-bit_48k_silence.wav", SFM_READ, &info);
165 BOOST_CHECK (sndfile);
166 float buffer[4096*6];
168 channels[0] = buffer;
170 sf_count_t N = sf_readf_float (sndfile, buffer, 4096);
171 sound_writer->write (channels, N);
177 sound_writer->finalize ();
179 cpl->add (shared_ptr<dcp::Reel> (
181 shared_ptr<dcp::ReelStereoPictureAsset> (new dcp::ReelStereoPictureAsset (mp, 0)),
182 shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (ms, 0))
188 d.write_xml (dcp::SMPTE, xml_meta);
190 /* build/test/DCP/dcp_test2 is checked against test/ref/DCP/dcp_test2 by run/tests */
194 note (dcp::NoteType, string)
199 /** Test comparison of a DCP with itself */
200 BOOST_AUTO_TEST_CASE (dcp_test3)
202 dcp::DCP A ("test/ref/DCP/dcp_test1");
204 dcp::DCP B ("test/ref/DCP/dcp_test1");
207 BOOST_CHECK (A.equals (B, dcp::EqualityOptions(), boost::bind (¬e, _1, _2)));
210 /** Test comparison of a DCP with a different DCP */
211 BOOST_AUTO_TEST_CASE (dcp_test4)
213 dcp::DCP A ("test/ref/DCP/dcp_test1");
215 dcp::DCP B ("test/ref/DCP/dcp_test2");
218 BOOST_CHECK (!A.equals (B, dcp::EqualityOptions(), boost::bind (¬e, _1, _2)));
221 /** Test creation of a 2D DCP with an Atmos track */
222 BOOST_AUTO_TEST_CASE (dcp_test5)
224 Kumu::cth_test = true;
226 /* Some known metadata */
227 dcp::XMLMetadata xml_meta;
228 xml_meta.annotation_text = "Created by libdcp";
229 xml_meta.issuer = "OpenDCP 0.0.25";
230 xml_meta.creator = "OpenDCP 0.0.25";
231 xml_meta.issue_date = "2012-07-17T04:45:18+00:00";
232 dcp::MXFMetadata mxf_meta;
233 mxf_meta.company_name = "OpenDCP";
234 mxf_meta.product_name = "OpenDCP";
235 mxf_meta.product_version = "0.0.25";
237 /* We're making build/test/DCP/dcp_test5 */
238 boost::filesystem::remove_all ("build/test/DCP/dcp_test5");
239 boost::filesystem::create_directories ("build/test/DCP/dcp_test5");
240 dcp::DCP d ("build/test/DCP/dcp_test5");
241 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE));
242 cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
243 cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
244 cpl->set_metadata (xml_meta);
246 shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1)));
247 mp->set_metadata (mxf_meta);
248 shared_ptr<dcp::PictureAssetWriter> picture_writer = mp->start_write ("build/test/DCP/dcp_test5/video.mxf", dcp::SMPTE, false);
249 dcp::File j2c ("test/data/32x32_red_square.j2c");
250 for (int i = 0; i < 24; ++i) {
251 picture_writer->write (j2c.data (), j2c.size ());
253 picture_writer->finalize ();
255 shared_ptr<dcp::SoundAsset> ms (new dcp::SoundAsset (dcp::Fraction (24, 1), 48000, 1));
256 ms->set_metadata (mxf_meta);
257 shared_ptr<dcp::SoundAssetWriter> sound_writer = ms->start_write ("build/test/DCP/dcp_test5/audio.mxf", dcp::SMPTE);
261 SNDFILE* sndfile = sf_open ("test/data/1s_24-bit_48k_silence.wav", SFM_READ, &info);
262 BOOST_CHECK (sndfile);
263 float buffer[4096*6];
265 channels[0] = buffer;
267 sf_count_t N = sf_readf_float (sndfile, buffer, 4096);
268 sound_writer->write (channels, N);
274 sound_writer->finalize ();
276 shared_ptr<dcp::AtmosAsset> am (new dcp::AtmosAsset (private_test / "20160218_NameOfFilm_FTR_OV_EN_A_dcs_r01.mxf"));
278 cpl->add (shared_ptr<dcp::Reel> (
280 shared_ptr<dcp::ReelMonoPictureAsset> (new dcp::ReelMonoPictureAsset (mp, 0)),
281 shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (ms, 0)),
282 shared_ptr<dcp::ReelSubtitleAsset> (),
283 shared_ptr<dcp::ReelAtmosAsset> (new dcp::ReelAtmosAsset (am, 0))
289 d.write_xml (dcp::SMPTE, xml_meta);
291 /* build/test/DCP/dcp_test5 is checked against test/ref/DCP/dcp_test5 by run/tests */
294 /** Basic tests of reading a 2D DCP with an Atmos track */
295 BOOST_AUTO_TEST_CASE (dcp_test6)
297 dcp::DCP dcp ("test/ref/DCP/dcp_test5");
300 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
301 BOOST_REQUIRE_EQUAL (dcp.cpls().front()->reels().size(), 1);
302 BOOST_CHECK (dcp.cpls().front()->reels().front()->main_picture());
303 BOOST_CHECK (dcp.cpls().front()->reels().front()->main_sound());
304 BOOST_CHECK (!dcp.cpls().front()->reels().front()->main_subtitle());
305 BOOST_CHECK (dcp.cpls().front()->reels().front()->atmos());
308 /** Test creation of a 2D Interop DCP from very simple inputs */
309 BOOST_AUTO_TEST_CASE (dcp_test7)
311 dcp::XMLMetadata xml_meta;
312 xml_meta.annotation_text = "Created by libdcp";
313 xml_meta.issuer = "OpenDCP 0.0.25";
314 xml_meta.creator = "OpenDCP 0.0.25";
315 xml_meta.issue_date = "2012-07-17T04:45:18+00:00";
316 make_simple("build/test/DCP/dcp_test7")->write_xml (dcp::INTEROP, xml_meta);
317 /* build/test/DCP/dcp_test7 is checked against test/ref/DCP/dcp_test7 by run/tests */