Supporters update.
[dcpomatic.git] / test / atmos_test.cc
1 /*
2     Copyright (C) 2020-2021 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
22 #include "lib/config.h"
23 #include "lib/content.h"
24 #include "lib/content_factory.h"
25 #include "lib/dcp_content.h"
26 #include "lib/film.h"
27 #include "test.h"
28 #include <dcp/atmos_asset.h>
29 #include <dcp/cpl.h>
30 #include <dcp/dcp.h>
31 #include <dcp/reel.h>
32 #include <dcp/reel_atmos_asset.h>
33 #include <boost/test/unit_test.hpp>
34
35
36 using std::make_shared;
37 using std::shared_ptr;
38 using std::shared_ptr;
39 using std::string;
40 using std::vector;
41 using boost::optional;
42
43
44 BOOST_AUTO_TEST_CASE (atmos_passthrough_test)
45 {
46         Cleanup cl;
47
48         auto film = new_test_film2 (
49                 "atmos_passthrough_test",
50                 content_factory(TestPaths::private_data() / "atmos_asset.mxf"),
51                 &cl
52                 );
53
54         make_and_verify_dcp (film, {dcp::VerificationNote::Code::MISSING_CPL_METADATA});
55
56         auto ref = TestPaths::private_data() / "atmos_asset.mxf";
57         BOOST_REQUIRE (mxf_atmos_files_same(ref, dcp_file(film, "atmos"), true));
58
59         cl.run ();
60 }
61
62
63 BOOST_AUTO_TEST_CASE (atmos_encrypted_passthrough_test)
64 {
65         Cleanup cl;
66
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);
70
71         film->set_encrypted (true);
72         film->_key = dcp::Key ("4fac12927eb122af1c2781aa91f3a4cc");
73         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
74
75         BOOST_REQUIRE (!mxf_atmos_files_same(ref, dcp_file(film, "atmos")));
76
77         auto signer = Config::instance()->signer_chain();
78         BOOST_REQUIRE(signer->valid());
79
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, {});
82
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 });
87
88         BOOST_CHECK (mxf_atmos_files_same(ref, dcp_file(film2, "atmos"), true));
89
90         cl.run ();
91 }
92
93
94 BOOST_AUTO_TEST_CASE (atmos_trim_test)
95 {
96         Cleanup cl;
97
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);
101
102         content[0]->set_trim_start(film, dcpomatic::ContentTime::from_seconds(1));
103
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 });
106 }
107
108
109 BOOST_AUTO_TEST_CASE(atmos_replace_test)
110 {
111         auto const frames = 240;
112
113         auto check = [](shared_ptr<const Film> film, int data) {
114                 dcp::DCP dcp(film->dir(film->dcp_name()));
115                 dcp.read();
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);
127                         }
128                 }
129         };
130
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
135         check(ov, 0);
136
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 }, false);
143         // atmos_1.mxf should contain all ones for its data, and it should have replaced atmos_0 in this DCP
144         check(vf, 1);
145 }
146