Write the correct MCA subdescriptors depending on active channels.
[dcpomatic.git] / test / mca_subdescriptors_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/audio_content.h"
23 #include "lib/constants.h"
24 #include "lib/content.h"
25 #include "lib/content_factory.h"
26 #include "lib/film.h"
27 #include "test.h"
28 #include <libcxml/cxml.h>
29 #include <boost/test/unit_test.hpp>
30
31
32 using std::shared_ptr;
33 using std::string;
34 using std::vector;
35
36
37 static
38 void
39 test_descriptors(vector<dcp::Channel> channels, vector<string> mca_tag_symbols, string group_name)
40 {
41         auto content = content_factory("test/data/flat_red.png");
42         for (auto i = 0U; i < channels.size(); ++i) {
43                 content.push_back(content_factory("test/data/C.wav").front());
44         }
45         auto film = new_test_film2("mca_subdescriptors_written_correctly", content);
46         film->set_interop(false);
47
48         int N = 1;
49         for (auto channel: channels) {
50                 auto mapping = AudioMapping(1, MAX_DCP_AUDIO_CHANNELS);
51                 mapping.set(0, channel, 1);
52                 content[N]->audio->set_mapping(mapping);
53                 ++N;
54         }
55
56         make_and_verify_dcp(film);
57
58         cxml::Document check("CompositionPlaylist", find_file(film->dir(film->dcp_name()), "cpl_"));
59         vector<string> cpl_mca_tag_symbols;
60
61         auto mca_sub_descriptors = check.node_child("ReelList")->node_child("Reel")->node_child("AssetList")->node_child("CompositionMetadataAsset")->node_child("MCASubDescriptors");
62
63         for (auto node: mca_sub_descriptors->node_children("AudioChannelLabelSubDescriptor")) {
64                 cpl_mca_tag_symbols.push_back(node->string_child("MCATagSymbol"));
65         }
66
67         auto const cpl_group_name = mca_sub_descriptors->node_child("SoundfieldGroupLabelSubDescriptor")->string_child("MCATagSymbol");
68
69         BOOST_CHECK(cpl_mca_tag_symbols == mca_tag_symbols);
70         BOOST_CHECK(cpl_group_name == group_name);
71 }
72
73
74 BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_mono)
75 {
76         test_descriptors({ dcp::Channel::CENTRE }, { "chL", "chR", "chC", "chLFE", "chLs", "chRs" }, "sg51");
77 }
78
79
80 BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_stereo)
81 {
82         test_descriptors({ dcp::Channel::LEFT, dcp::Channel::RIGHT }, { "chL", "chR", "chC", "chLFE", "chLs", "chRs" }, "sg51");
83 }
84
85
86 BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_51)
87 {
88         test_descriptors(
89                 {
90                         dcp::Channel::LEFT,
91                         dcp::Channel::RIGHT,
92                         dcp::Channel::CENTRE,
93                         dcp::Channel::LFE,
94                         dcp::Channel::LS,
95                         dcp::Channel::RS,
96                 },
97                 { "chL", "chR", "chC", "chLFE", "chLs", "chRs" },
98                 "sg51"
99                 );
100 }
101
102
103 BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_51_with_hi_vi)
104 {
105         test_descriptors(
106                 {
107                         dcp::Channel::LEFT,
108                         dcp::Channel::RIGHT,
109                         dcp::Channel::CENTRE,
110                         dcp::Channel::LFE,
111                         dcp::Channel::LS,
112                         dcp::Channel::RS,
113                         dcp::Channel::HI,
114                         dcp::Channel::VI,
115                 },
116                 { "chL", "chR", "chC", "chLFE", "chLs", "chRs", "chHI", "chVIN" },
117                 "sg51"
118                 );
119 }
120
121
122 BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_71)
123 {
124         test_descriptors(
125                 {
126                         dcp::Channel::LEFT,
127                         dcp::Channel::RIGHT,
128                         dcp::Channel::CENTRE,
129                         dcp::Channel::LFE,
130                         dcp::Channel::LS,
131                         dcp::Channel::RS,
132                         dcp::Channel::BSL,
133                         dcp::Channel::BSR,
134                 },
135                 { "chL", "chR", "chC", "chLFE", "chLss", "chRss", "chLrs", "chRrs" },
136                 "sg71"
137                 );
138 }
139
140
141 BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_71_with_hi_vi)
142 {
143         test_descriptors(
144                 {
145                         dcp::Channel::LEFT,
146                         dcp::Channel::RIGHT,
147                         dcp::Channel::CENTRE,
148                         dcp::Channel::LFE,
149                         dcp::Channel::LS,
150                         dcp::Channel::RS,
151                         dcp::Channel::HI,
152                         dcp::Channel::VI,
153                         dcp::Channel::BSL,
154                         dcp::Channel::BSR,
155                 },
156                 { "chL", "chR", "chC", "chLFE", "chLss", "chRss", "chHI", "chVIN", "chLrs", "chRrs" },
157                 "sg71"
158                 );
159 }