From df0e4e0278e66a27f8f3980e53d262332695f679 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 21 Mar 2023 01:11:01 +0100 Subject: [PATCH] Write the correct MCA subdescriptors depending on active channels. --- src/lib/reel_writer.cc | 15 ++- test/mca_subdescriptors_test.cc | 159 ++++++++++++++++++++++++++++++++ test/wscript | 1 + 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 test/mca_subdescriptors_test.cc diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 9ffe1cdc5..8bd15a575 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -192,12 +192,25 @@ ReelWriter::ReelWriter ( DCPOMATIC_ASSERT (film()->directory()); + auto mapped = film()->mapped_audio_channels(); + std::vector extra_active_channels; + auto add_if_mapped = [mapped, &extra_active_channels](dcp::Channel channel) { + if (std::find(mapped.begin(), mapped.end(), static_cast(channel)) != mapped.end()) { + extra_active_channels.push_back(channel); + } + }; + + add_if_mapped(dcp::Channel::HI); + add_if_mapped(dcp::Channel::VI); + add_if_mapped(dcp::Channel::BSL); + add_if_mapped(dcp::Channel::BSR); + /* Write the sound asset into the film directory so that we leave the creation of the DCP directory until the last minute. */ _sound_asset_writer = _sound_asset->start_write ( film()->directory().get() / audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary), - film()->audio_channels(), + extra_active_channels, film()->contains_atmos_content() ? dcp::SoundAsset::AtmosSync::ENABLED : dcp::SoundAsset::AtmosSync::DISABLED, film()->limit_to_smpte_bv20() ? dcp::SoundAsset::MCASubDescriptors::DISABLED : dcp::SoundAsset::MCASubDescriptors::ENABLED ); diff --git a/test/mca_subdescriptors_test.cc b/test/mca_subdescriptors_test.cc new file mode 100644 index 000000000..7585aa1ab --- /dev/null +++ b/test/mca_subdescriptors_test.cc @@ -0,0 +1,159 @@ +/* + Copyright (C) 2023 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + + +#include "lib/audio_content.h" +#include "lib/constants.h" +#include "lib/content.h" +#include "lib/content_factory.h" +#include "lib/film.h" +#include "test.h" +#include +#include + + +using std::shared_ptr; +using std::string; +using std::vector; + + +static +void +test_descriptors(vector channels, vector mca_tag_symbols, string group_name) +{ + auto content = content_factory("test/data/flat_red.png"); + for (auto i = 0U; i < channels.size(); ++i) { + content.push_back(content_factory("test/data/C.wav").front()); + } + auto film = new_test_film2("mca_subdescriptors_written_correctly", content); + film->set_interop(false); + + int N = 1; + for (auto channel: channels) { + auto mapping = AudioMapping(1, MAX_DCP_AUDIO_CHANNELS); + mapping.set(0, channel, 1); + content[N]->audio->set_mapping(mapping); + ++N; + } + + make_and_verify_dcp(film); + + cxml::Document check("CompositionPlaylist", find_file(film->dir(film->dcp_name()), "cpl_")); + vector cpl_mca_tag_symbols; + + auto mca_sub_descriptors = check.node_child("ReelList")->node_child("Reel")->node_child("AssetList")->node_child("CompositionMetadataAsset")->node_child("MCASubDescriptors"); + + for (auto node: mca_sub_descriptors->node_children("AudioChannelLabelSubDescriptor")) { + cpl_mca_tag_symbols.push_back(node->string_child("MCATagSymbol")); + } + + auto const cpl_group_name = mca_sub_descriptors->node_child("SoundfieldGroupLabelSubDescriptor")->string_child("MCATagSymbol"); + + BOOST_CHECK(cpl_mca_tag_symbols == mca_tag_symbols); + BOOST_CHECK(cpl_group_name == group_name); +} + + +BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_mono) +{ + test_descriptors({ dcp::Channel::CENTRE }, { "chL", "chR", "chC", "chLFE", "chLs", "chRs" }, "sg51"); +} + + +BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_stereo) +{ + test_descriptors({ dcp::Channel::LEFT, dcp::Channel::RIGHT }, { "chL", "chR", "chC", "chLFE", "chLs", "chRs" }, "sg51"); +} + + +BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_51) +{ + test_descriptors( + { + dcp::Channel::LEFT, + dcp::Channel::RIGHT, + dcp::Channel::CENTRE, + dcp::Channel::LFE, + dcp::Channel::LS, + dcp::Channel::RS, + }, + { "chL", "chR", "chC", "chLFE", "chLs", "chRs" }, + "sg51" + ); +} + + +BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_51_with_hi_vi) +{ + test_descriptors( + { + dcp::Channel::LEFT, + dcp::Channel::RIGHT, + dcp::Channel::CENTRE, + dcp::Channel::LFE, + dcp::Channel::LS, + dcp::Channel::RS, + dcp::Channel::HI, + dcp::Channel::VI, + }, + { "chL", "chR", "chC", "chLFE", "chLs", "chRs", "chHI", "chVIN" }, + "sg51" + ); +} + + +BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_71) +{ + test_descriptors( + { + dcp::Channel::LEFT, + dcp::Channel::RIGHT, + dcp::Channel::CENTRE, + dcp::Channel::LFE, + dcp::Channel::LS, + dcp::Channel::RS, + dcp::Channel::BSL, + dcp::Channel::BSR, + }, + { "chL", "chR", "chC", "chLFE", "chLss", "chRss", "chLrs", "chRrs" }, + "sg71" + ); +} + + +BOOST_AUTO_TEST_CASE(mca_subdescriptors_written_correctly_71_with_hi_vi) +{ + test_descriptors( + { + dcp::Channel::LEFT, + dcp::Channel::RIGHT, + dcp::Channel::CENTRE, + dcp::Channel::LFE, + dcp::Channel::LS, + dcp::Channel::RS, + dcp::Channel::HI, + dcp::Channel::VI, + dcp::Channel::BSL, + dcp::Channel::BSR, + }, + { "chL", "chR", "chC", "chLFE", "chLss", "chRss", "chHI", "chVIN", "chLrs", "chRrs" }, + "sg71" + ); +} diff --git a/test/wscript b/test/wscript index dc108acb6..9917e7802 100644 --- a/test/wscript +++ b/test/wscript @@ -112,6 +112,7 @@ def build(bld): kdm_util_test.cc low_bitrate_test.cc markers_test.cc + mca_subdescriptors_test.cc no_use_video_test.cc optimise_stills_test.cc overlap_video_test.cc -- 2.30.2