diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 8a89f027d..6de04fa2a 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -69,6 +69,7 @@ DCPContent::DCPContent(boost::filesystem::path p) , _kdm_valid(false) , _reference_video(false) , _reference_audio(false) + , _reference_atmos(false) , _three_d(false) { LOG_GENERAL("Creating DCP content from {}", p.string()); @@ -112,6 +113,7 @@ DCPContent::DCPContent(cxml::ConstNodePtr node, boost::optionalbool_child("KDMValid"); _reference_video = node->optional_bool_child("ReferenceVideo").get_value_or(false); _reference_audio = node->optional_bool_child("ReferenceAudio").get_value_or(false); + _reference_atmos = node->optional_bool_child("ReferenceAtmos").get_value_or(false); if (version >= 37) { _reference_text[TextType::OPEN_SUBTITLE] = node->optional_bool_child("ReferenceOpenSubtitle").get_value_or(false); _reference_text[TextType::CLOSED_CAPTION] = node->optional_bool_child("ReferenceClosedCaption").get_value_or(false); @@ -450,6 +452,7 @@ DCPContent::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_ cxml::add_text_child(element, "KDMValid", _kdm_valid ? "1" : "0"); cxml::add_text_child(element, "ReferenceVideo", _reference_video ? "1" : "0"); cxml::add_text_child(element, "ReferenceAudio", _reference_audio ? "1" : "0"); + cxml::add_text_child(element, "ReferenceAtmos", _reference_atmos ? "1" : "0"); cxml::add_text_child(element, "ReferenceOpenSubtitle", _reference_text[TextType::OPEN_SUBTITLE] ? "1" : "0"); cxml::add_text_child(element, "ReferenceClosedCaption", _reference_text[TextType::CLOSED_CAPTION] ? "1" : "0"); if (_standard) { @@ -652,6 +655,17 @@ DCPContent::set_reference_audio(bool r) } } +void +DCPContent::set_reference_atmos(bool r) +{ + ContentChangeSignaller cc(this, DCPContentProperty::REFERENCE_ATMOS); + + { + boost::mutex::scoped_lock lm(_mutex); + _reference_atmos = r; + } +} + void DCPContent::set_reference_text(TextType type, bool r) { @@ -833,6 +847,29 @@ DCPContent::can_reference_audio(shared_ptr film, string& why_not) co } +bool +DCPContent::can_reference_atmos(shared_ptr film, string& why_not) const +{ + if (!atmos) { + /// TRANSLATORS: this string will follow "Cannot reference this DCP: " + why_not = _("it has no Atmos track."); + return false; + } + + auto part = [](shared_ptr c) { + return static_cast(c->atmos); + }; + + if (overlaps(film, part)) { + /// TRANSLATORS: this string will follow "Cannot reference this DCP: " + why_not = _("it overlaps other Atmos content."); + return false; + } + + return can_reference_anything(film, why_not); +} + + bool DCPContent::can_reference_text(shared_ptr film, TextType type, string& why_not) const { @@ -884,6 +921,7 @@ DCPContent::take_settings_from(shared_ptr c) _reference_video = dc->_reference_video; _reference_audio = dc->_reference_audio; + _reference_atmos = dc->_reference_atmos; _reference_text = dc->_reference_text; } @@ -951,7 +989,7 @@ DCPContent::active_audio_channels() const bool DCPContent::reference_anything() const { - if (reference_video() || reference_audio()) { + if (reference_video() || reference_audio() || reference_atmos()) { return true; } diff --git a/src/lib/dcp_content.h b/src/lib/dcp_content.h index 8ef8cc66d..31a36fb80 100644 --- a/src/lib/dcp_content.h +++ b/src/lib/dcp_content.h @@ -51,6 +51,7 @@ class DCPContentProperty static int constexpr NAME = 605; static int constexpr TEXTS = 606; static int constexpr CPL = 607; + static int constexpr REFERENCE_ATMOS = 608; }; @@ -161,6 +162,15 @@ class DCPContent : public Content bool can_reference_text(std::shared_ptr film, TextType type, std::string &) const; + void set_reference_atmos(bool r); + + bool reference_atmos() const { + boost::mutex::scoped_lock lm(_mutex); + return _reference_atmos; + } + + bool can_reference_atmos(std::shared_ptr film, std::string &) const; + bool reference_anything() const; void set_cpl(std::string id); @@ -291,6 +301,10 @@ class DCPContent : public Content * not what they are being used for. */ EnumIndexedVector _reference_text; + /** true if the Atmos track in this DCP should be included in the output by reference + * rather than by rewrapping. + */ + bool _reference_atmos; boost::optional _standard; boost::optional _main_sound_configuration; diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 42119a041..345c1ca52 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -443,7 +443,7 @@ DCPDecoder::get_readers() _sound_reader->set_check_hmac(false); } - if ((*_reel)->atmos()) { + if ((*_reel)->atmos() && (_decode_referenced || !_dcp_content->reference_atmos())) { auto asset = (*_reel)->atmos()->asset(); _atmos_reader = asset->start_read(); _atmos_reader->set_check_hmac(false); diff --git a/src/lib/film.cc b/src/lib/film.cc index c70257ef0..0f213bf42 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1832,6 +1832,10 @@ Film::check_settings_consistency() d->set_reference_audio(false); change_made = true; } + if (d->reference_atmos() && !d->can_reference_atmos(shared_from_this(), why_not)) { + d->set_reference_atmos(false); + change_made = true; + } if (d->reference_text(TextType::OPEN_SUBTITLE) && !d->can_reference_text(shared_from_this(), TextType::OPEN_SUBTITLE, why_not)) { d->set_reference_text(TextType::OPEN_SUBTITLE, false); change_made = true; diff --git a/src/lib/film_util.cc b/src/lib/film_util.cc index 13068e91d..9592a0196 100644 --- a/src/lib/film_util.cc +++ b/src/lib/film_util.cc @@ -65,7 +65,7 @@ dcpomatic::film::is_vf(shared_ptr film) any_text = true; } } - if (dcp->reference_video() || dcp->reference_audio() || any_text) { + if (dcp->reference_video() || dcp->reference_audio() || dcp->reference_atmos() || any_text) { return true; } } diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index e9e8fc6d2..5887cdda4 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -602,6 +602,36 @@ ReelWriter::create_reel_sound(shared_ptr reel, list reel, list const & refs) const +{ + if (_atmos_asset) { + /* We have made an Atmos asset of our own. Put it into the reel */ + reel->add(make_shared(_atmos_asset, 0)); + return; + } + + /* We don't have an Atmos asset of our own; use one that we reference, if there is one */ + for (auto ref: refs) { + if (auto atmos = dynamic_pointer_cast(ref.asset)) { + if (ref.period.contains(_period)) { + auto const vfr = film()->video_frame_rate(); + auto reel_asset = make_shared(*atmos); + reel_asset->set_entry_point( + reel_asset->entry_point().get_value_or(0) + dcpomatic::DCPTime(_period.from - ref.period.from).frames_round(vfr) + ); + reel_asset->set_duration(_period.duration().frames_round(vfr)); + /* If we have a hash for this asset in the CPL, assume that it is correct */ + if (atmos->hash()) { + atmos->asset_ref()->set_hash(atmos->hash().get()); + } + reel->add(reel_asset); + } + } + } +} + + /** @param ensure_closed_captions List of DCPTextTracks that we need to make sure exist in this reel */ void ReelWriter::create_reel_text( @@ -748,9 +778,7 @@ ReelWriter::create_reel( create_reel_text(reel, refs, duration, output_dcp, ensure_subtitles, ensure_closed_captions); - if (_atmos_asset) { - reel->add(make_shared(_atmos_asset, 0)); - } + create_reel_atmos(reel, refs); return reel; } diff --git a/src/lib/reel_writer.h b/src/lib/reel_writer.h index 367b62349..3b41c7e77 100644 --- a/src/lib/reel_writer.h +++ b/src/lib/reel_writer.h @@ -111,6 +111,7 @@ class ReelWriter : public WeakConstFilm std::shared_ptr create_reel_picture(std::shared_ptr reel, std::list const & refs) const; void create_reel_sound(std::shared_ptr reel, std::list const & refs) const; + void create_reel_atmos(std::shared_ptr reel, std::list const & refs) const; void create_reel_text( std::shared_ptr reel, std::list const & refs, diff --git a/src/lib/referenced_reel_asset.cc b/src/lib/referenced_reel_asset.cc index afc6f4c06..b5669169c 100644 --- a/src/lib/referenced_reel_asset.cc +++ b/src/lib/referenced_reel_asset.cc @@ -27,6 +27,7 @@ #include "referenced_reel_asset.h" #include #include +#include #include #include #include @@ -69,7 +70,7 @@ get_referenced_reel_assets(shared_ptr film, shared_ptrreference_video() && !dcp->reference_audio() && !dcp->reference_text(TextType::OPEN_SUBTITLE) && !dcp->reference_text(TextType::CLOSED_CAPTION)) { + if (!dcp->reference_video() && !dcp->reference_audio() && !dcp->reference_atmos() && !dcp->reference_text(TextType::OPEN_SUBTITLE) && !dcp->reference_text(TextType::CLOSED_CAPTION)) { continue; } @@ -115,6 +116,10 @@ get_referenced_reel_assets(shared_ptr film, shared_ptrmain_sound(), reel_trim_start, reel_trim_end, from, frame_rate); } + if (dcp->reference_atmos() && reel->atmos()) { + maybe_add_asset(reel_assets, reel->atmos(), reel_trim_start, reel_trim_end, from, frame_rate); + } + if (dcp->reference_text(TextType::OPEN_SUBTITLE) && reel->main_subtitle()) { maybe_add_asset(reel_assets, reel->main_subtitle(), reel_trim_start, reel_trim_end, from, frame_rate); } diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index 4cf374b00..8e85008a1 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -575,6 +575,7 @@ DCPPanel::film_content_changed(int property) case VideoContentProperty::CROP: case DCPContentProperty::REFERENCE_VIDEO: case DCPContentProperty::REFERENCE_AUDIO: + case DCPContentProperty::REFERENCE_ATMOS: case DCPContentProperty::REFERENCE_TEXT: setup_dcp_name(); update_standards(); diff --git a/src/wx/dcp_referencing_dialog.cc b/src/wx/dcp_referencing_dialog.cc index 9f4a71658..f96365e3b 100644 --- a/src/wx/dcp_referencing_dialog.cc +++ b/src/wx/dcp_referencing_dialog.cc @@ -91,6 +91,7 @@ DCPReferencingDialog::film_content_changed(ChangeType type, int property) if ( property != DCPContentProperty::REFERENCE_VIDEO && property != DCPContentProperty::REFERENCE_AUDIO && + property != DCPContentProperty::REFERENCE_ATMOS && property != DCPContentProperty::REFERENCE_TEXT) { setup(); } @@ -108,11 +109,11 @@ DCPReferencingDialog::setup() wxFont font(*wxNORMAL_FONT); font.SetWeight(wxFONTWEIGHT_BOLD); text->SetFont(font); - _dcp_grid->Add(text, wxGBPosition(row, 1), wxGBSpan(1, 4), wxALIGN_CENTER); + _dcp_grid->Add(text, wxGBPosition(row, 1), wxGBSpan(1, 5), wxALIGN_CENTER); ++row; int column = 0; - for (auto const& sub_heading: { _("OV DCP"), _("Picture"), _("Sound"), _("Subtitles"), _("Closed captions") }) { + for (auto const& sub_heading: { _("OV DCP"), _("Picture"), _("Sound"), _("Atmos"), _("Subtitles"), _("Closed captions") }) { auto text = new StaticText(this, sub_heading); wxFont font(*wxNORMAL_FONT); font.SetWeight(wxFONTWEIGHT_BOLD); @@ -122,7 +123,7 @@ DCPReferencingDialog::setup() } ++row; - auto const all_parts = { Part::VIDEO, Part::AUDIO, Part::SUBTITLES, Part::CLOSED_CAPTIONS }; + auto const all_parts = { Part::VIDEO, Part::AUDIO, Part::ATMOS, Part::SUBTITLES, Part::CLOSED_CAPTIONS }; for (auto& content: _film->content()) { auto dcp_content = dynamic_pointer_cast(content); @@ -143,6 +144,9 @@ DCPReferencingDialog::setup() case Part::AUDIO: record.check_box[part]->set(dcp_content->reference_audio()); break; + case Part::ATMOS: + record.check_box[part]->set(dcp_content->reference_atmos()); + break; case Part::SUBTITLES: record.check_box[part]->set(dcp_content->reference_text(TextType::OPEN_SUBTITLE)); break; @@ -162,7 +166,7 @@ DCPReferencingDialog::setup() wxFont font(*wxNORMAL_FONT); font.SetStyle(wxFONTSTYLE_ITALIC); reason->SetFont(font); - _dcp_grid->Add(reason, wxGBPosition(row, 0), wxGBSpan(1, 5), wxLEFT, DCPOMATIC_SIZER_X_GAP * 4); + _dcp_grid->Add(reason, wxGBPosition(row, 0), wxGBSpan(1, 6), wxLEFT, DCPOMATIC_SIZER_X_GAP * 4); ++row; }; @@ -188,6 +192,13 @@ DCPReferencingDialog::setup() } } + if (!dcp_content->can_reference_atmos(_film, why_not)) { + record.check_box[Part::ATMOS]->Enable(false); + if (dcp_content->atmos) { + add_problem(_("Cannot reference this DCP's Atmos"), why_not); + } + } + if (!dcp_content->can_reference_text(_film, TextType::OPEN_SUBTITLE, why_not)) { record.check_box[Part::SUBTITLES]->Enable(false); if (dcp_content->text_of_original_type(TextType::OPEN_SUBTITLE)) { @@ -227,6 +238,9 @@ DCPReferencingDialog::checkbox_changed(weak_ptr weak_content, CheckB case Part::AUDIO: content->set_reference_audio(check_box->get()); break; + case Part::ATMOS: + content->set_reference_atmos(check_box->get()); + break; case Part::SUBTITLES: content->set_reference_text(TextType::OPEN_SUBTITLE, check_box->get()); break; diff --git a/src/wx/dcp_referencing_dialog.h b/src/wx/dcp_referencing_dialog.h index e49292c22..44c137ef9 100644 --- a/src/wx/dcp_referencing_dialog.h +++ b/src/wx/dcp_referencing_dialog.h @@ -42,6 +42,7 @@ class DCPReferencingDialog : public wxDialog enum class Part { VIDEO, AUDIO, + ATMOS, SUBTITLES, CLOSED_CAPTIONS, COUNT diff --git a/src/wx/dcp_timeline.cc b/src/wx/dcp_timeline.cc index 46c77f296..b0a5d0b6f 100644 --- a/src/wx/dcp_timeline.cc +++ b/src/wx/dcp_timeline.cc @@ -255,6 +255,7 @@ DCPTimeline::film_content_changed(ChangeType type, int property) property == DCPContentProperty::NEEDS_ASSETS || property == DCPContentProperty::REFERENCE_VIDEO || property == DCPContentProperty::REFERENCE_AUDIO || + property == DCPContentProperty::REFERENCE_ATMOS || property == DCPContentProperty::REFERENCE_TEXT) { setup_reel_types(); setup_sensitivity(); diff --git a/src/wx/video_panel.cc b/src/wx/video_panel.cc index 055f8eaba..bb6a5f974 100644 --- a/src/wx/video_panel.cc +++ b/src/wx/video_panel.cc @@ -465,6 +465,7 @@ VideoPanel::film_content_changed(int property) } case DCPContentProperty::REFERENCE_VIDEO: case DCPContentProperty::REFERENCE_AUDIO: + case DCPContentProperty::REFERENCE_ATMOS: case DCPContentProperty::REFERENCE_TEXT: setup_sensitivity(); break; diff --git a/test/README.tex b/test/README.tex index 89a598832..016cdf408 100644 --- a/test/README.tex +++ b/test/README.tex @@ -54,6 +54,8 @@ \subsection{Tests of fairly specific areas} \hline \textbf{File} & \textbf{Test summary} \\ \hline + \co{atmos\_reference\_asset\_test} & Referencing the Atmos track of an existing DCP from a VF. \\ + \hline \co{audio\_delay\_test} & Some FFmpeg content with audio delays. \\ \hline \co{client\_server\_test} & An encode server running on \co{localhost}. \\ diff --git a/test/atmos_reference_asset_test.cc b/test/atmos_reference_asset_test.cc new file mode 100644 index 000000000..a78bf426a --- /dev/null +++ b/test/atmos_reference_asset_test.cc @@ -0,0 +1,302 @@ +/* + Copyright (C) 2026 Jaume Puig + + 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 . + +*/ + + +/** @file test/atmos_reference_asset_test.cc + * @brief Tests of referencing the Atmos track of an existing DCP from a VF. + * + * These use test/data/atmos_0.mxf and atmos_1.mxf, which are in the public test data, + * so unlike atmos_test.cc they do not need the private data. + * @ingroup feature + */ + + +#include "lib/content_factory.h" +#include "lib/dcp_content.h" +#include "lib/film.h" +#include "lib/film_util.h" +#include "lib/player.h" +#include "test.h" +#include +#include +#include +#include +#include +#include + + +using std::dynamic_pointer_cast; +using std::make_shared; +using std::shared_ptr; +using std::string; + + +/** Make and verify an OV containing the Atmos track test/data/atmos_0.mxf */ +static +shared_ptr +make_atmos_ov(string name) +{ + auto ov = new_test_film(name, content_factory("test/data/atmos_0.mxf")); + make_and_verify_dcp(ov, { dcp::VerificationNote::Code::MISSING_CPL_METADATA }); + return ov; +} + + +static +shared_ptr +dcp_content_of(shared_ptr film) +{ + return make_shared(film->dir(film->dcp_name())); +} + + +BOOST_AUTO_TEST_CASE(atmos_reference_test) +{ + auto ov = make_atmos_ov("atmos_reference_test_ov"); + + /* @return the Atmos reel asset of the first reel of the film's DCP */ + auto atmos_asset = [](shared_ptr film) { + dcp::DCP dcp(film->dir(film->dcp_name())); + dcp.read(); + BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U); + BOOST_REQUIRE_EQUAL(dcp.cpls()[0]->reels().size(), 1U); + BOOST_REQUIRE(dcp.cpls()[0]->reels()[0]->atmos()); + return dcp.cpls()[0]->reels()[0]->atmos(); + }; + + auto const ov_asset = atmos_asset(ov); + auto const ov_id = ov_asset->asset_ref().id(); + + auto make_vf = [ov](string name, bool reference_atmos, dcpomatic::ContentTime trim_start, dcpomatic::ContentTime trim_end) { + auto ov_content = dcp_content_of(ov); + auto vf = new_test_film(name, { ov_content }); + ov_content->set_reference_video(true); + string why_not; + BOOST_CHECK(ov_content->can_reference_atmos(vf, why_not)); + ov_content->set_reference_atmos(reference_atmos); + ov_content->set_trim_start(vf, trim_start); + ov_content->set_trim_end(trim_end); + make_and_verify_dcp(vf, { dcp::VerificationNote::Code::MISSING_CPL_METADATA, dcp::VerificationNote::Code::EXTERNAL_ASSET }, false); + return vf; + }; + + /* Without referencing, the Atmos is written again with a new ID */ + BOOST_CHECK(atmos_asset(make_vf("atmos_reference_test_vf_rewrite", false, {}, {}))->asset_ref().id() != ov_id); + + /* With referencing, the VF's CPL points at the OV's Atmos asset */ + auto const whole = atmos_asset(make_vf("atmos_reference_test_vf_reference", true, {}, {})); + BOOST_CHECK_EQUAL(whole->asset_ref().id(), ov_id); + BOOST_CHECK_EQUAL(whole->entry_point().get_value_or(0), 0); + BOOST_CHECK_EQUAL(whole->actual_duration(), ov_asset->actual_duration()); + + /* With trims, the VF still points at the same asset (same ID), and only the entry point and duration in the CPL change */ + auto const vf = make_vf("atmos_reference_test_vf_trim", true, dcpomatic::ContentTime::from_seconds(1), dcpomatic::ContentTime::from_seconds(2)); + auto const trimmed = atmos_asset(vf); + auto const rate = vf->video_frame_rate(); + BOOST_CHECK_EQUAL(trimmed->asset_ref().id(), ov_id); + BOOST_CHECK_EQUAL(trimmed->entry_point().get_value_or(0), rate); + BOOST_CHECK_EQUAL(trimmed->actual_duration(), ov_asset->actual_duration() - 3 * rate); +} + + +/** The flag is saved in the project's metadata and comes back when it is read, and a project saved + * without it (from before it existed) reads as not referencing the Atmos track. + */ +BOOST_AUTO_TEST_CASE(atmos_reference_metadata_test) +{ + auto ov = make_atmos_ov("atmos_reference_metadata_test_ov"); + + auto content = dcp_content_of(ov); + auto film = new_test_film("atmos_reference_metadata_test", { content }); + content->set_reference_video(true); + content->set_reference_atmos(true); + BOOST_REQUIRE(content->reference_atmos()); + film->write_metadata(); + + auto reread = make_shared(film->directory().get()); + reread->read_metadata(); + BOOST_REQUIRE_EQUAL(reread->content().size(), 1U); + auto reread_content = dynamic_pointer_cast(reread->content().front()); + BOOST_REQUIRE(reread_content); + BOOST_CHECK(reread_content->reference_atmos()); + + content->set_reference_atmos(false); + film->write_metadata(); + + auto reread_again = make_shared(film->directory().get()); + reread_again->read_metadata(); + BOOST_REQUIRE_EQUAL(reread_again->content().size(), 1U); + BOOST_CHECK(!dynamic_pointer_cast(reread_again->content().front())->reference_atmos()); +} + + +/** The identifier is part of the path of the encoded video, so referencing the Atmos track must not + * change it: that would make the video be encoded again for no reason. + */ +BOOST_AUTO_TEST_CASE(atmos_reference_identifier_test) +{ + auto ov = make_atmos_ov("atmos_reference_identifier_test_ov"); + + auto content = dcp_content_of(ov); + auto film = new_test_film("atmos_reference_identifier_test", { content }); + auto const not_referenced = content->identifier(); + + content->set_reference_atmos(true); + BOOST_REQUIRE(content->reference_atmos()); + BOOST_CHECK_EQUAL(content->identifier(), not_referenced); +} + + +/** A DCP without an Atmos track cannot have it referenced, and neither can one whose Atmos track + * overlaps other Atmos content in the film. + */ +BOOST_AUTO_TEST_CASE(atmos_reference_unavailable_test) +{ + /* No Atmos track */ + auto picture_only = new_test_film("atmos_reference_unavailable_test_picture", content_factory("test/data/flat_red.png")); + make_and_verify_dcp(picture_only); + + auto picture_only_content = dcp_content_of(picture_only); + auto vf_picture = new_test_film("atmos_reference_unavailable_test_vf_picture", { picture_only_content }); + string why_not; + BOOST_CHECK(!picture_only_content->can_reference_atmos(vf_picture, why_not)); + BOOST_CHECK_EQUAL(why_not, "it has no Atmos track."); + + /* Overlapping Atmos content */ + auto ov = make_atmos_ov("atmos_reference_unavailable_test_ov"); + auto ov_content = dcp_content_of(ov); + auto atmos_1 = content_factory("test/data/atmos_1.mxf"); + auto vf = new_test_film("atmos_reference_unavailable_test_vf", { ov_content, atmos_1.front() }); + ov_content->set_reference_video(true); + atmos_1.front()->set_position(vf, dcpomatic::DCPTime()); + why_not.clear(); + BOOST_CHECK(!ov_content->can_reference_atmos(vf, why_not)); + BOOST_CHECK_EQUAL(why_not, "it overlaps other Atmos content."); +} + + +/** If the Atmos track can no longer be referenced, the film switches the flag off. */ +BOOST_AUTO_TEST_CASE(atmos_reference_reset_test) +{ + auto ov = make_atmos_ov("atmos_reference_reset_test_ov"); + + auto ov_content = dcp_content_of(ov); + auto atmos_1 = content_factory("test/data/atmos_1.mxf"); + auto vf = new_test_film("atmos_reference_reset_test_vf", { ov_content, atmos_1.front() }); + atmos_1.front()->set_position(vf, dcpomatic::DCPTime()); + + /* The other Atmos content overlaps, so this must not stay on */ + ov_content->set_reference_video(true); + ov_content->set_reference_atmos(true); + BOOST_CHECK(!ov_content->reference_atmos()); +} + + +/** Referencing the Atmos track makes a film a VF, even if nothing else is referenced. */ +BOOST_AUTO_TEST_CASE(atmos_reference_is_vf_test) +{ + auto ov = make_atmos_ov("atmos_reference_is_vf_test_ov"); + + auto content = dcp_content_of(ov); + auto film = new_test_film("atmos_reference_is_vf_test", { content }); + BOOST_CHECK(!dcpomatic::film::is_vf(film)); + + content->set_reference_atmos(true); + BOOST_REQUIRE(content->reference_atmos()); + BOOST_CHECK(!content->reference_video()); + BOOST_CHECK(!content->reference_audio()); + BOOST_CHECK(dcpomatic::film::is_vf(film)); +} + + +/** A referenced Atmos track is not decoded, because the output points at the original asset. */ +BOOST_AUTO_TEST_CASE(atmos_reference_not_decoded_test) +{ + auto ov = make_atmos_ov("atmos_reference_not_decoded_test_ov"); + + auto atmos_frames = [ov](bool reference_atmos) { + auto content = dcp_content_of(ov); + auto film = new_test_film(reference_atmos ? "atmos_reference_not_decoded_test_referenced" : "atmos_reference_not_decoded_test_rewritten", { content }); + content->set_reference_video(true); + content->set_reference_atmos(reference_atmos); + + auto player = make_shared(film, Image::Alignment::COMPACT, false); + int frames = 0; + player->Atmos.connect([&frames](shared_ptr, dcpomatic::DCPTime, AtmosMetadata) { + ++frames; + }); + while (!player->pass()) {} + return frames; + }; + + BOOST_CHECK(atmos_frames(false) > 0); + BOOST_CHECK_EQUAL(atmos_frames(true), 0); +} + + +/** Which of the OV's sound and Atmos assets does the VF point at, for each combination of referencing them? + * The two are independent: each is the OV's if and only if it is referenced. + */ +BOOST_AUTO_TEST_CASE(atmos_reference_audio_test) +{ + auto ov = make_atmos_ov("atmos_reference_audio_test_ov"); + + auto first_reel = [](shared_ptr film) { + dcp::DCP dcp(film->dir(film->dcp_name())); + dcp.read(); + BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U); + BOOST_REQUIRE_EQUAL(dcp.cpls()[0]->reels().size(), 1U); + return dcp.cpls()[0]->reels()[0]; + }; + + auto const ov_reel = first_reel(ov); + BOOST_REQUIRE(ov_reel->main_sound()); + BOOST_REQUIRE(ov_reel->atmos()); + + /* Setting the two in either order, so that neither can undo the other */ + for (auto atmos_first: { false, true }) { + for (auto reference_audio: { false, true }) { + for (auto reference_atmos: { false, true }) { + auto content = dcp_content_of(ov); + auto vf = new_test_film( + string("atmos_reference_audio_test_vf_") + (atmos_first ? "atmos_first" : "audio_first") + (reference_audio ? "_audio" : "_noaudio") + (reference_atmos ? "_atmos" : "_noatmos"), + { content } + ); + content->set_reference_video(true); + if (atmos_first) { + content->set_reference_atmos(reference_atmos); + content->set_reference_audio(reference_audio); + } else { + content->set_reference_audio(reference_audio); + content->set_reference_atmos(reference_atmos); + } + make_and_verify_dcp(vf, { dcp::VerificationNote::Code::MISSING_CPL_METADATA, dcp::VerificationNote::Code::EXTERNAL_ASSET }, false); + + auto const reel = first_reel(vf); + BOOST_REQUIRE(reel->main_sound()); + BOOST_REQUIRE(reel->atmos()); + BOOST_CHECK_EQUAL(content->reference_audio(), reference_audio); + BOOST_CHECK_EQUAL(content->reference_atmos(), reference_atmos); + BOOST_CHECK_EQUAL(reel->main_sound()->asset_ref().id() == ov_reel->main_sound()->asset_ref().id(), reference_audio); + BOOST_CHECK_EQUAL(reel->atmos()->asset_ref().id() == ov_reel->atmos()->asset_ref().id(), reference_atmos); + } + } + } +} diff --git a/test/wscript b/test/wscript index ddedb1ad6..3ab2fd371 100644 --- a/test/wscript +++ b/test/wscript @@ -49,6 +49,7 @@ def build(bld): 3042_regression_test.cc 4k_test.cc analytics_test.cc + atmos_reference_asset_test.cc atmos_test.cc audio_analysis_test.cc audio_buffers_test.cc