diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-10-08 12:08:10 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-10-08 12:48:43 +0200 |
| commit | aab6630b945371038cc49e456a766ae45cab1f47 (patch) | |
| tree | a82f7ceaff2d091bff154e604b9c3e861b2994af /test/kdm_test.cc | |
| parent | 99d2243b7674c0673fee5f6f6cd4a65da16db37c (diff) | |
Fix problems when adding KDMs to a VF, before adding the OV.v1.8.2
If we have a KDM which contains keys for all the assets referred
to by a VF (even the ones in the OV) we would previously throw
an exception because we tried to give the KDM to the resolved
assets when it was given to the Reel.
Here we change things so that the addition of KDMs to assets can
be deferred if the asset is not yet resolved.
Diffstat (limited to 'test/kdm_test.cc')
| -rw-r--r-- | test/kdm_test.cc | 91 |
1 files changed, 88 insertions, 3 deletions
diff --git a/test/kdm_test.cc b/test/kdm_test.cc index 5b0ae622..d5cd456f 100644 --- a/test/kdm_test.cc +++ b/test/kdm_test.cc @@ -40,6 +40,9 @@ #include "picture_asset_writer.h" #include "reel.h" #include "reel_mono_picture_asset.h" +#include "reel_sound_asset.h" +#include "reel_smpte_subtitle_asset.h" +#include "smpte_subtitle_asset.h" #include "test.h" #include "types.h" #include "util.h" @@ -51,11 +54,11 @@ LIBDCP_ENABLE_WARNINGS #include <boost/test/unit_test.hpp> -using std::list; -using std::string; -using std::vector; +using std::dynamic_pointer_cast; using std::make_shared; using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; @@ -296,3 +299,85 @@ BOOST_AUTO_TEST_CASE (validity_period_test1) dcp::BadKDMDateError ); } + + +/** Test the case where we have: + * - a OV + VF + * - a single KDM which has keys for both OV and VF assets + * and we load VF, then KDM, then the OV. The OV's assets should have their + * KDMs properly assigned. + */ +BOOST_AUTO_TEST_CASE (vf_kdm_test) +{ + /* Make OV */ + + boost::filesystem::path const ov_path = "build/test/vf_kdm_test_ov"; + boost::filesystem::path const vf_path = "build/test/vf_kdm_test_vf"; + dcp::Key key; + + auto ov = make_simple(ov_path, 1, 48, dcp::Standard::SMPTE, key); + ov->write_xml (); + + auto ov_reel = ov->cpls()[0]->reels()[0]; + auto ov_reel_picture = make_shared<dcp::ReelMonoPictureAsset>(dynamic_pointer_cast<dcp::ReelMonoPictureAsset>(ov_reel->main_picture())->mono_asset(), 0); + auto ov_reel_sound = make_shared<dcp::ReelSoundAsset>(ov_reel->main_sound()->asset(), 0); + + /* Make VF */ + + auto subs = make_shared<dcp::SMPTESubtitleAsset>(); + subs->add(simple_subtitle()); + subs->set_key(key); + + boost::filesystem::remove_all (vf_path); + boost::filesystem::create_directory (vf_path); + dcp::ArrayData data(4096); + subs->add_font ("afont", data); + subs->write (vf_path / "subs.xml"); + + auto reel_subs = make_shared<dcp::ReelSMPTESubtitleAsset>(subs, dcp::Fraction(24, 1), 192, 0); + + auto reel = make_shared<dcp::Reel>(ov_reel_picture, ov_reel_sound, reel_subs); + + auto cpl = make_shared<dcp::CPL>("A Test DCP", dcp::ContentKind::TRAILER, dcp::Standard::SMPTE); + cpl->add (reel); + + auto vf = make_shared<dcp::DCP>("build/test/vf_kdm_test_vf"); + vf->add (cpl); + vf->write_xml (); + + /* Make KDM for VF */ + + auto kdm = dcp::DecryptedKDM( + cpl, + key, + dcp::LocalTime ("2016-01-01T00:00:00+00:00"), + dcp::LocalTime ("2017-01-08T00:00:00+00:00"), + "libdcp", + "test", + "2012-07-17T04:45:18+00:00" + ); + + /* Decrypt VF with the KDM */ + + dcp::DCP reload_vf(vf_path); + reload_vf.read(); + reload_vf.add (kdm); + + /* Add the OV */ + + dcp::DCP reload_ov(ov_path); + reload_ov.read(); + reload_vf.resolve_refs(reload_ov.assets()); + + /* Check that we can decrypt the VF */ + + BOOST_REQUIRE_EQUAL(reload_vf.cpls().size(), 1U); + BOOST_REQUIRE_EQUAL(reload_vf.cpls()[0]->reels().size(), 1U); + BOOST_REQUIRE(reload_vf.cpls()[0]->reels()[0]->main_picture()); + BOOST_REQUIRE(reload_vf.cpls()[0]->reels()[0]->main_picture()->asset()); + auto mono_asset = dynamic_pointer_cast<dcp::MonoPictureAsset>(reload_vf.cpls()[0]->reels()[0]->main_picture()->asset()); + BOOST_REQUIRE(mono_asset); + auto reader = mono_asset->start_read(); + reader->set_check_hmac(false); + reader->get_frame(0)->xyz_image(); +} |
