2 Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "lib/config.h"
23 #include "lib/content.h"
24 #include "lib/content_factory.h"
25 #include "lib/dcp_content.h"
28 #include <dcp/atmos_asset.h>
32 #include <dcp/reel_atmos_asset.h>
33 #include <boost/test/unit_test.hpp>
36 using std::make_shared;
37 using std::shared_ptr;
38 using std::shared_ptr;
41 using boost::optional;
44 BOOST_AUTO_TEST_CASE (atmos_passthrough_test)
48 auto film = new_test_film2 (
49 "atmos_passthrough_test",
50 content_factory(TestPaths::private_data() / "atmos_asset.mxf"),
54 make_and_verify_dcp (film, {dcp::VerificationNote::Code::MISSING_CPL_METADATA});
56 auto ref = TestPaths::private_data() / "atmos_asset.mxf";
57 BOOST_REQUIRE (mxf_atmos_files_same(ref, dcp_file(film, "atmos"), true));
63 BOOST_AUTO_TEST_CASE (atmos_encrypted_passthrough_test)
67 auto ref = TestPaths::private_data() / "atmos_asset.mxf";
68 auto content = content_factory(TestPaths::private_data() / "atmos_asset.mxf");
69 auto film = new_test_film2 ("atmos_encrypted_passthrough_test", content, &cl);
71 film->set_encrypted (true);
72 film->_key = dcp::Key ("4fac12927eb122af1c2781aa91f3a4cc");
73 make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
75 BOOST_REQUIRE (!mxf_atmos_files_same(ref, dcp_file(film, "atmos")));
77 auto signer = Config::instance()->signer_chain();
78 BOOST_REQUIRE(signer->valid());
80 auto const decrypted_kdm = film->make_kdm(dcp_file(film, "cpl"), dcp::LocalTime(), dcp::LocalTime());
81 auto const kdm = decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, false, {});
83 auto content2 = make_shared<DCPContent>(film->dir(film->dcp_name()));
84 content2->add_kdm (kdm);
85 auto film2 = new_test_film2 ("atmos_encrypted_passthrough_test2", {content2}, &cl);
86 make_and_verify_dcp (film2, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
88 BOOST_CHECK (mxf_atmos_files_same(ref, dcp_file(film2, "atmos"), true));
94 BOOST_AUTO_TEST_CASE (atmos_trim_test)
98 auto ref = TestPaths::private_data() / "atmos_asset.mxf";
99 auto content = content_factory(TestPaths::private_data() / "atmos_asset.mxf");
100 auto film = new_test_film2 ("atmos_trim_test", content, &cl);
102 content[0]->set_trim_start(film, dcpomatic::ContentTime::from_seconds(1));
104 /* Just check that the encode runs; I'm not sure how to test the MXF */
105 make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
109 BOOST_AUTO_TEST_CASE(atmos_replace_test)
111 auto const frames = 240;
113 auto check = [](shared_ptr<const Film> film, int data) {
114 dcp::DCP dcp(film->dir(film->dcp_name()));
116 BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
117 BOOST_REQUIRE_EQUAL(dcp.cpls()[0]->reels().size(), 1U);
118 BOOST_REQUIRE(dcp.cpls()[0]->reels()[0]->atmos());
119 auto asset = dcp.cpls()[0]->reels()[0]->atmos()->asset();
120 BOOST_REQUIRE(asset);
121 auto reader = asset->start_read();
122 for (int i = 0; i < frames; ++i) {
123 auto frame = reader->get_frame(i);
124 BOOST_REQUIRE(frame);
125 for (int j = 0; j < frame->size(); ++j) {
126 BOOST_REQUIRE_EQUAL(frame->data()[j], data);
131 auto atmos_0 = content_factory("test/data/atmos_0.mxf");
132 auto ov = new_test_film2("atmos_merge_test_ov", atmos_0);
133 make_and_verify_dcp(ov, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
134 // atmos_0.mxf should contain all zeros for its data
137 auto atmos_1 = content_factory("test/data/atmos_1.mxf");
138 auto ov_content = std::make_shared<DCPContent>(boost::filesystem::path("build/test/atmos_merge_test_ov") / ov->dcp_name());
139 auto vf = new_test_film2("atmos_merge_test_vf", { ov_content, atmos_1.front() });
140 ov_content->set_reference_video(true);
141 atmos_1.front()->set_position(vf, dcpomatic::DCPTime());
142 make_and_verify_dcp(vf, { dcp::VerificationNote::Code::MISSING_CPL_METADATA, dcp::VerificationNote::Code::EXTERNAL_ASSET });
143 // atmos_1.mxf should contain all ones for its data, and it should have replaced atmos_0 in this DCP