Supporters update.
[dcpomatic.git] / test / bv20_test.cc
1 /*
2     Copyright (C) 2023 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/content_factory.h"
23 #include "lib/film.h"
24 #include "test.h"
25 #include <dcp/warnings.h>
26 LIBDCP_DISABLE_WARNINGS
27 #include <asdcp/Metadata.h>
28 LIBDCP_ENABLE_WARNINGS
29 #include <dcp/sound_asset.h>
30 #include <dcp/util.h>
31 #include <boost/test/unit_test.hpp>
32
33
34 using std::shared_ptr;
35
36
37 bool
38 has_cpl_mca_subdescriptors(shared_ptr<const Film> film)
39 {
40         auto cpl = dcp::file_to_string(find_file(film->dir(film->dcp_name()), "cpl_"));
41         return cpl.find("MCASubDescriptors") != std::string::npos;
42 }
43
44
45 bool
46 has_mxf_mca_subdescriptors(shared_ptr<const Film> film)
47 {
48         /* One day hopefully libdcp will read these descriptors and we can find out from the SoundAsset
49          * whether they exist.
50          */
51
52         ASDCP::PCM::MXFReader reader;
53         auto r = reader.OpenRead(find_file(film->dir(film->dcp_name()), "pcm_").string());
54         BOOST_REQUIRE(!ASDCP_FAILURE(r));
55
56         ASDCP::MXF::WaveAudioDescriptor* essence_descriptor = nullptr;
57         auto const rr = reader.OP1aHeader().GetMDObjectByType(
58                 dcp::asdcp_smpte_dict->ul(ASDCP::MDD_WaveAudioDescriptor),
59                 reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&essence_descriptor)
60                 );
61
62         if (!KM_SUCCESS(rr)) {
63                 return false;
64         }
65
66         return essence_descriptor->SubDescriptors.size() > 0;
67 }
68
69
70 BOOST_AUTO_TEST_CASE(bv21_extensions_used_when_not_limited)
71 {
72         auto picture = content_factory("test/data/flat_red.png");
73         auto sound = content_factory("test/data/sine_440.wav");
74         auto film = new_test_film2("bv21_extensions_used_when_not_limited", { picture.front(), sound.front() });
75
76         make_and_verify_dcp(film);
77
78         BOOST_CHECK(has_cpl_mca_subdescriptors(film));
79         BOOST_CHECK(has_mxf_mca_subdescriptors(film));
80 }
81
82
83 BOOST_AUTO_TEST_CASE(bv21_extensions_not_used_when_limited)
84 {
85         auto picture = content_factory("test/data/flat_red.png");
86         auto sound = content_factory("test/data/sine_440.wav");
87         auto film = new_test_film2("bv21_extensions_not_used_when_limited", { picture.front(), sound.front () });
88         film->set_limit_to_smpte_bv20(true);
89
90         make_and_verify_dcp(film);
91
92         BOOST_CHECK(!has_cpl_mca_subdescriptors(film));
93         BOOST_CHECK(!has_mxf_mca_subdescriptors(film));
94 }
95