Bump libdcp for new asdcplib version.
[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         Kumu::FileReaderFactory factory;
53         ASDCP::PCM::MXFReader reader(factory);
54         auto r = reader.OpenRead(find_file(film->dir(film->dcp_name()), "pcm_").string());
55         BOOST_REQUIRE(!ASDCP_FAILURE(r));
56
57         ASDCP::MXF::WaveAudioDescriptor* essence_descriptor = nullptr;
58         auto const rr = reader.OP1aHeader().GetMDObjectByType(
59                 dcp::asdcp_smpte_dict->ul(ASDCP::MDD_WaveAudioDescriptor),
60                 reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&essence_descriptor)
61                 );
62
63         if (!KM_SUCCESS(rr)) {
64                 return false;
65         }
66
67         return essence_descriptor->SubDescriptors.size() > 0;
68 }
69
70
71 BOOST_AUTO_TEST_CASE(bv21_extensions_used_when_not_limited)
72 {
73         auto picture = content_factory("test/data/flat_red.png");
74         auto sound = content_factory("test/data/sine_440.wav");
75         auto film = new_test_film2("bv21_extensions_used_when_not_limited", { picture.front(), sound.front() });
76
77         make_and_verify_dcp(film);
78
79         BOOST_CHECK(has_cpl_mca_subdescriptors(film));
80         BOOST_CHECK(has_mxf_mca_subdescriptors(film));
81 }
82
83
84 BOOST_AUTO_TEST_CASE(bv21_extensions_not_used_when_limited)
85 {
86         auto picture = content_factory("test/data/flat_red.png");
87         auto sound = content_factory("test/data/sine_440.wav");
88         auto film = new_test_film2("bv21_extensions_not_used_when_limited", { picture.front(), sound.front () });
89         film->set_limit_to_smpte_bv20(true);
90
91         make_and_verify_dcp(film);
92
93         BOOST_CHECK(!has_cpl_mca_subdescriptors(film));
94         BOOST_CHECK(!has_mxf_mca_subdescriptors(film));
95 }
96