Emit no audio from DCPs if none is mapped
[dcpomatic.git] / test / atmos_test.cc
index ec7e9e85d89c6cbe06e6fb512118c8a1d66649b9..9fdddc979306c79bb451437abe0bcf5490547ad0 100644 (file)
 #include "lib/dcp_content.h"
 #include "lib/film.h"
 #include "test.h"
+#include <dcp/atmos_asset.h>
+#include <dcp/cpl.h>
+#include <dcp/dcp.h>
+#include <dcp/reel.h>
+#include <dcp/reel_atmos_asset.h>
 #include <boost/test/unit_test.hpp>
 
 
+using std::make_shared;
+using std::shared_ptr;
+using std::shared_ptr;
 using std::string;
 using std::vector;
-using std::make_shared;
 using boost::optional;
-using std::shared_ptr;
 
 
 BOOST_AUTO_TEST_CASE (atmos_passthrough_test)
@@ -68,16 +74,11 @@ BOOST_AUTO_TEST_CASE (atmos_encrypted_passthrough_test)
 
        BOOST_REQUIRE (!mxf_atmos_files_same(ref, dcp_file(film, "atmos")));
 
-       auto kdm = film->make_kdm (
-               Config::instance()->decryption_chain()->leaf(),
-               vector<string>(),
-               dcp_file(film, "cpl"),
-               dcp::LocalTime(),
-               dcp::LocalTime(),
-               dcp::Formulation::MODIFIED_TRANSITIONAL_1,
-               false,
-               optional<int>()
-               );
+       auto signer = Config::instance()->signer_chain();
+       BOOST_REQUIRE(signer->valid());
+
+       auto const decrypted_kdm = film->make_kdm(dcp_file(film, "cpl"), dcp::LocalTime(), dcp::LocalTime());
+       auto const kdm = decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, false, {});
 
        auto content2 = make_shared<DCPContent>(film->dir(film->dcp_name()));
        content2->add_kdm (kdm);
@@ -104,3 +105,42 @@ BOOST_AUTO_TEST_CASE (atmos_trim_test)
        make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
 }
 
+
+BOOST_AUTO_TEST_CASE(atmos_replace_test)
+{
+       auto const frames = 240;
+
+       auto check = [](shared_ptr<const Film> film, int data) {
+               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());
+               auto asset = dcp.cpls()[0]->reels()[0]->atmos()->asset();
+               BOOST_REQUIRE(asset);
+               auto reader = asset->start_read();
+               for (int i = 0; i < frames; ++i) {
+                       auto frame = reader->get_frame(i);
+                       BOOST_REQUIRE(frame);
+                       for (int j = 0; j < frame->size(); ++j) {
+                               BOOST_REQUIRE_EQUAL(frame->data()[j], data);
+                       }
+               }
+       };
+
+       auto atmos_0 = content_factory("test/data/atmos_0.mxf");
+       auto ov = new_test_film2("atmos_merge_test_ov", atmos_0);
+       make_and_verify_dcp(ov, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
+       // atmos_0.mxf should contain all zeros for its data
+       check(ov, 0);
+
+       auto atmos_1 = content_factory("test/data/atmos_1.mxf");
+       auto ov_content = std::make_shared<DCPContent>(boost::filesystem::path("build/test/atmos_merge_test_ov") / ov->dcp_name());
+       auto vf = new_test_film2("atmos_merge_test_vf", { ov_content, atmos_1.front() });
+       ov_content->set_reference_video(true);
+       atmos_1.front()->set_position(vf, dcpomatic::DCPTime());
+       make_and_verify_dcp(vf, { dcp::VerificationNote::Code::MISSING_CPL_METADATA, dcp::VerificationNote::Code::EXTERNAL_ASSET }, false);
+       // atmos_1.mxf should contain all ones for its data, and it should have replaced atmos_0 in this DCP
+       check(vf, 1);
+}
+