From bcc9e32cd3c886fbe02f1b2573bd19ca9ec340dc Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 29 Oct 2025 22:19:24 +0100 Subject: Don't report channels as mapped when they are not included in the film's channel count. So e.g. if you map the 7.1 surrounds but have a 6-channel film it should consider those channels un-mapped. --- src/lib/film.cc | 16 ++++++++++++---- src/lib/film.h | 5 +++++ test/cpl_metadata_test.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/lib/film.cc b/src/lib/film.cc index c6a6f3cce..8dc55c590 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -797,11 +797,18 @@ list Film::mapped_audio_channels() const { list mapped; + auto const highest_channel = audio_channels() - 1; + + auto maybe_add = [&mapped, highest_channel](int channel) { + if (channel <= highest_channel) { + mapped.push_back(channel); + } + }; if (audio_processor()) { /* Assume all a processor's declared output channels are mapped */ for (int i = 0; i < audio_processor()->out_channels(); ++i) { - mapped.push_back(i); + maybe_add(i); } /* Check to see if channels that the processor passes through are mapped */ @@ -810,7 +817,7 @@ Film::mapped_audio_channels() const if (i->audio) { for (auto c: i->audio->mapping().mapped_output_channels()) { if (std::find(pass.begin(), pass.end(), dcp::Channel(c)) != pass.end()) { - mapped.push_back(c); + maybe_add(c); } } } @@ -819,8 +826,9 @@ Film::mapped_audio_channels() const } else { for (auto i: content()) { if (i->audio) { - auto c = i->audio->mapping().mapped_output_channels(); - copy(c.begin(), c.end(), back_inserter(mapped)); + for (auto c: i->audio->mapping().mapped_output_channels()) { + maybe_add(c); + } } } diff --git a/src/lib/film.h b/src/lib/film.h index 8574c700f..6d04da9bf 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -173,6 +173,11 @@ public: } std::vector reels() const; + + /** @return List of channel indicies that are mapped to the DCP. This takes the + * value of audio_channels() into account, so even if a channel above audio_channels() + * is mapped it will not be returned here. + */ std::list mapped_audio_channels() const; boost::optional audio_language() const { diff --git a/test/cpl_metadata_test.cc b/test/cpl_metadata_test.cc index b3c269919..b8857968d 100644 --- a/test/cpl_metadata_test.cc +++ b/test/cpl_metadata_test.cc @@ -119,3 +119,49 @@ BOOST_AUTO_TEST_CASE(main_sound_configuration_test_71) BOOST_CHECK_EQUAL(msc->as_string(), "71/L,R,C,LFE,Lss,Rss,-,VIN,-,-,Lrs,Rrs"); } + + +BOOST_AUTO_TEST_CASE(main_sound_configuration_test_71_mapped_but_51_dcp) +{ + auto picture = content_factory("test/data/flat_red.png")[0]; + auto L = content_factory("test/data/L.wav")[0]; + auto R = content_factory("test/data/R.wav")[0]; + auto C = content_factory("test/data/C.wav")[0]; + auto Lfe = content_factory("test/data/Lfe.wav")[0]; + auto Ls = content_factory("test/data/Ls.wav")[0]; + auto Rs = content_factory("test/data/Rs.wav")[0]; + auto BsL = content_factory("test/data/Ls.wav")[0]; + auto BsR = content_factory("test/data/Rs.wav")[0]; + auto VI = content_factory("test/data/sine_440.wav")[0]; + + auto film = new_test_film("main_sound_configuration_test_71_mapped_51_set_vi", { picture, L, R, C, Lfe, Ls, Rs, BsL, BsR, VI }); + film->set_audio_channels(6); + + auto set_map = [](shared_ptr content, dcp::Channel channel) { + auto map = content->audio->mapping(); + map.set(0, channel, 1.0f); + content->audio->set_mapping(map); + }; + + set_map(L, dcp::Channel::LEFT); + set_map(R, dcp::Channel::RIGHT); + set_map(C, dcp::Channel::CENTRE); + set_map(Lfe, dcp::Channel::LFE); + set_map(Ls, dcp::Channel::LS); + set_map(Rs, dcp::Channel::RS); + set_map(BsL, dcp::Channel::BSL); + set_map(BsR, dcp::Channel::BSR); + set_map(VI, dcp::Channel::VI); + + make_and_verify_dcp(film); + + dcp::DCP dcp(film->dir(film->dcp_name())); + dcp.read(); + BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U); + auto cpl = dcp.cpls()[0]; + + auto msc = cpl->main_sound_configuration(); + BOOST_REQUIRE(msc); + + BOOST_CHECK_EQUAL(msc->as_string(), "51/L,R,C,LFE,Ls,Rs"); +} -- cgit v1.2.3