From 488e3d1bd5e6b17d49f6db4df14c64f4b64db89b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 13 Apr 2021 23:36:22 +0200 Subject: [PATCH] Remove ReelEncryptableAsset and tidy up a bit. --- src/cpl.cc | 46 ----------- src/cpl.h | 5 -- src/decrypted_kdm.cc | 22 +++--- src/decrypted_kdm.h | 4 +- src/reel.cc | 31 ++------ src/reel_asset.cc | 5 +- src/reel_asset.h | 8 +- src/reel_atmos_asset.cc | 14 +--- src/reel_atmos_asset.h | 9 ++- src/reel_closed_caption_asset.cc | 11 ++- src/reel_encryptable_asset.cc | 77 ------------------- src/reel_encryptable_asset.h | 97 ------------------------ src/reel_file_asset.cc | 27 ++++++- src/reel_file_asset.h | 21 ++++- src/reel_interop_closed_caption_asset.cc | 22 +++--- src/reel_interop_closed_caption_asset.h | 4 +- src/reel_interop_subtitle_asset.cc | 12 --- src/reel_interop_subtitle_asset.h | 2 - src/reel_markers_asset.cc | 2 +- src/reel_picture_asset.cc | 20 ++--- src/reel_picture_asset.h | 9 ++- src/reel_smpte_closed_caption_asset.cc | 7 +- src/reel_smpte_closed_caption_asset.h | 7 +- src/reel_smpte_subtitle_asset.cc | 14 ---- src/reel_smpte_subtitle_asset.h | 9 +-- src/reel_sound_asset.cc | 18 +---- src/reel_sound_asset.h | 12 ++- src/reel_subtitle_asset.cc | 26 ++++++- src/reel_subtitle_asset.h | 2 + src/verify.cc | 13 +--- src/wscript | 3 +- 31 files changed, 154 insertions(+), 405 deletions(-) delete mode 100644 src/reel_encryptable_asset.cc delete mode 100644 src/reel_encryptable_asset.h diff --git a/src/cpl.cc b/src/cpl.cc index 1257484a..145ce1cd 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -538,52 +538,6 @@ CPL::reel_file_assets () const } -template -void -add_encryptable_assets (vector>& assets, vector> reels) -{ - for (auto i: reels) { - if (i->main_picture ()) { - assets.push_back (i->main_picture()); - } - if (i->main_sound ()) { - assets.push_back (i->main_sound()); - } - if (i->main_subtitle ()) { - if (auto enc = dynamic_pointer_cast(i->main_subtitle())) { - assets.push_back (enc); - } - } - for (auto j: i->closed_captions()) { - if (auto enc = dynamic_pointer_cast(j)) { - assets.push_back (enc); - } - } - if (i->atmos ()) { - assets.push_back (i->atmos()); - } - } -} - - -vector> -CPL::reel_encryptable_assets () -{ - vector> c; - add_encryptable_assets (c, _reels); - return c; -} - - -vector> -CPL::reel_encryptable_assets () const -{ - vector> c; - add_encryptable_assets (c, _reels); - return c; -} - - bool CPL::equals (shared_ptr other, EqualityOptions opt, NoteHandler note) const { diff --git a/src/cpl.h b/src/cpl.h index 03e35a4e..246233c1 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -59,7 +59,6 @@ struct verify_invalid_language3; namespace dcp { -class ReelEncryptableAsset; class ReelFileAsset; class Reel; class MXFMetadata; @@ -104,10 +103,6 @@ public: std::vector> reel_file_assets () const; std::vector> reel_file_assets (); - /** @return the ReelEncryptableAssets in this CPL in all reels */ - std::vector> reel_encryptable_assets () const; - std::vector> reel_encryptable_assets (); - /** @return true if we have any encrypted content */ bool any_encrypted () const; diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc index 447a0a12..03c5ea26 100644 --- a/src/decrypted_kdm.cc +++ b/src/decrypted_kdm.cc @@ -37,17 +37,17 @@ */ +#include "certificate_chain.h" +#include "compose.hpp" +#include "cpl.h" +#include "dcp_assert.h" #include "decrypted_kdm.h" #include "decrypted_kdm_key.h" #include "encrypted_kdm.h" -#include "reel_encryptable_asset.h" +#include "exceptions.h" #include "reel_asset.h" +#include "reel_file_asset.h" #include "util.h" -#include "exceptions.h" -#include "cpl.h" -#include "certificate_chain.h" -#include "dcp_assert.h" -#include "compose.hpp" #include #include #include @@ -251,7 +251,7 @@ DecryptedKDM::DecryptedKDM ( DecryptedKDM::DecryptedKDM ( string cpl_id, - map, Key> keys, + map, Key> keys, LocalTime not_valid_before, LocalTime not_valid_after, string annotation_text, @@ -264,7 +264,7 @@ DecryptedKDM::DecryptedKDM ( , _content_title_text (content_title_text) , _issue_date (issue_date) { - for (map, Key>::const_iterator i = keys.begin(); i != keys.end(); ++i) { + for (map, Key>::const_iterator i = keys.begin(); i != keys.end(); ++i) { add_key (i->first->key_type(), i->first->key_id().get(), i->second, cpl_id, Standard::SMPTE); } } @@ -287,9 +287,9 @@ DecryptedKDM::DecryptedKDM ( { /* Create DecryptedKDMKey objects for each encryptable asset */ bool did_one = false; - for (auto i: cpl->reel_encryptable_assets()) { - if (i->key_id()) { - add_key (i->key_type(), i->key_id().get(), key, cpl->id(), Standard::SMPTE); + for (auto i: cpl->reel_file_assets()) { + if (i->encryptable()) { + add_key (i->key_type().get(), i->key_id().get(), key, cpl->id(), Standard::SMPTE); did_one = true; } } diff --git a/src/decrypted_kdm.h b/src/decrypted_kdm.h index 16b0acba..6bdd9fcd 100644 --- a/src/decrypted_kdm.h +++ b/src/decrypted_kdm.h @@ -60,7 +60,7 @@ class DecryptedKDMKey; class EncryptedKDM; class CertificateChain; class CPL; -class ReelEncryptableAsset; +class ReelFileAsset; /** @class DecryptedKDM @@ -99,7 +99,7 @@ public: */ DecryptedKDM ( std::string cpl_id, - std::map, Key> keys, + std::map, Key> keys, LocalTime not_valid_before, LocalTime not_valid_after, std::string annotation_text, diff --git a/src/reel.cc b/src/reel.cc index 4baa2fc9..e99f7140 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -274,24 +274,15 @@ Reel::any_encrypted () const { auto ecc = false; for (auto i: _closed_captions) { - if (auto enc = dynamic_pointer_cast(i)) { - if (enc->encrypted()) { - ecc = true; - } - } - } - - bool esub = false; - if (_main_subtitle) { - if (auto enc = dynamic_pointer_cast(_main_picture)) { - esub = enc->encrypted(); + if (i->encrypted()) { + ecc = true; } } return ( (_main_picture && _main_picture->encrypted()) || (_main_sound && _main_sound->encrypted()) || - esub || + (_main_subtitle && _main_subtitle->encrypted()) || ecc || (_atmos && _atmos->encrypted()) ); @@ -303,25 +294,15 @@ Reel::all_encrypted () const { auto ecc = true; for (auto i: _closed_captions) { - if (auto enc = dynamic_pointer_cast(i)) { - if (!enc->encrypted()) { - ecc = false; - } - } - } - - /* It's ok if there's no subtitle, or it's not encryptable */ - bool esub = true; - if (_main_subtitle) { - if (auto enc = dynamic_pointer_cast(_main_picture)) { - esub = enc->encrypted(); + if (!i->encrypted()) { + ecc = false; } } return ( (!_main_picture || _main_picture->encrypted()) && (!_main_sound || _main_sound->encrypted()) && - esub && + (!_main_subtitle || _main_subtitle->encrypted()) && ecc && (!_atmos || _atmos->encrypted()) ); diff --git a/src/reel_asset.cc b/src/reel_asset.cc index cd54ccba..1a6a25be 100644 --- a/src/reel_asset.cc +++ b/src/reel_asset.cc @@ -78,7 +78,7 @@ ReelAsset::ReelAsset (shared_ptr node) xmlpp::Node* -ReelAsset::write_to_cpl_asset (xmlpp::Node* node, Standard standard, optional hash) const +ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const { auto a = node->add_child (cpl_node_name (standard)); auto const attr = cpl_node_attribute (standard); @@ -99,9 +99,6 @@ ReelAsset::write_to_cpl_asset (xmlpp::Node* node, Standard standard, optionaladd_child("Duration")->add_child_text(raw_convert(*_duration)); } - if (hash) { - a->add_child("Hash")->add_child_text (hash.get()); - } return a; } diff --git a/src/reel_asset.h b/src/reel_asset.h index 00355335..ab06434e 100644 --- a/src/reel_asset.h +++ b/src/reel_asset.h @@ -83,7 +83,11 @@ public: explicit ReelAsset (std::shared_ptr); - virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const = 0; + virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const; + + virtual bool encryptable () const { + return false; + } Fraction edit_rate () const { return _edit_rate; @@ -139,8 +143,6 @@ protected: /** @return Any namespace that should be used on the asset's node in the CPL */ virtual std::pair cpl_node_namespace () const; - xmlpp::Node* write_to_cpl_asset (xmlpp::Node* node, Standard standard, boost::optional hash) const; - int64_t _intrinsic_duration = 0; ///< The <IntrinsicDuration> from the reel's entry for this asset boost::optional _duration; ///< The <Duration> from the reel's entry for this asset, if present diff --git a/src/reel_atmos_asset.cc b/src/reel_atmos_asset.cc index b17dceca..1df26ce9 100644 --- a/src/reel_atmos_asset.cc +++ b/src/reel_atmos_asset.cc @@ -51,8 +51,7 @@ using namespace dcp; ReelAtmosAsset::ReelAtmosAsset (std::shared_ptr asset, int64_t entry_point) - : ReelFileAsset (asset, asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point) - , ReelEncryptableAsset (asset->key_id()) + : ReelFileAsset (asset, asset->key_id(), asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point) { } @@ -60,7 +59,6 @@ ReelAtmosAsset::ReelAtmosAsset (std::shared_ptr asset, int64_t entry ReelAtmosAsset::ReelAtmosAsset (std::shared_ptr node) : ReelFileAsset (node) - , ReelEncryptableAsset (node) { node->ignore_child ("DataType"); node->done (); @@ -81,18 +79,10 @@ ReelAtmosAsset::cpl_node_namespace () const } -string -ReelAtmosAsset::key_type () const -{ - return "MDEK"; -} - - xmlpp::Node * ReelAtmosAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const { - auto asset = write_to_cpl_asset (node, standard, hash()); - write_to_cpl_encryptable (asset); + auto asset = ReelFileAsset::write_to_cpl (node, standard); asset->add_child("axd:DataType")->add_child_text("urn:smpte:ul:060e2b34.04010105.0e090604.00000000"); return asset; } diff --git a/src/reel_atmos_asset.h b/src/reel_atmos_asset.h index 8aaf6a59..2e4a8d4e 100644 --- a/src/reel_atmos_asset.h +++ b/src/reel_atmos_asset.h @@ -41,9 +41,8 @@ #define LIBDCP_REEL_ATMOS_ASSET_H -#include "reel_asset.h" +#include "reel_file_asset.h" #include "atmos_asset.h" -#include "reel_encryptable_asset.h" namespace dcp { @@ -55,7 +54,7 @@ class AtmosAsset; /** @class ReelAtmosAsset * @brief Part of a Reel's description which refers to a Atmos MXF */ -class ReelAtmosAsset : public ReelFileAsset, public ReelEncryptableAsset +class ReelAtmosAsset : public ReelFileAsset { public: ReelAtmosAsset (std::shared_ptr asset, int64_t entry_point); @@ -69,7 +68,9 @@ public: bool equals (std::shared_ptr, EqualityOptions, NoteHandler) const; private: - std::string key_type () const override; + boost::optional key_type () const override { + return std::string("MDEK"); + } std::string cpl_node_name (Standard standard) const override; std::pair cpl_node_namespace () const override; }; diff --git a/src/reel_closed_caption_asset.cc b/src/reel_closed_caption_asset.cc index 4ba6fe0c..3e4627d3 100644 --- a/src/reel_closed_caption_asset.cc +++ b/src/reel_closed_caption_asset.cc @@ -54,7 +54,14 @@ using namespace dcp; ReelClosedCaptionAsset::ReelClosedCaptionAsset (std::shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) - : ReelFileAsset (asset, asset->id(), edit_rate, intrinsic_duration, entry_point) + : ReelFileAsset ( + asset, + dynamic_pointer_cast(asset) ? dynamic_pointer_cast(asset)->key_id() : boost::none, + asset->id(), + edit_rate, + intrinsic_duration, + entry_point + ) { } @@ -79,3 +86,5 @@ ReelClosedCaptionAsset::equals (shared_ptr other, return true; } + + diff --git a/src/reel_encryptable_asset.cc b/src/reel_encryptable_asset.cc deleted file mode 100644 index f8e8303f..00000000 --- a/src/reel_encryptable_asset.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (C) 2012-2021 Carl Hetherington - - This file is part of libdcp. - - libdcp 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. - - libdcp 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 libdcp. If not, see . - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the - OpenSSL library under certain conditions as described in each - individual source file, and distribute linked combinations - including the two. - - You must obey the GNU General Public License in all respects - for all of the code used other than OpenSSL. If you modify - file(s) with this exception, you may extend this exception to your - version of the file(s), but you are not obligated to do so. If you - do not wish to do so, delete this exception statement from your - version. If you delete this exception statement from all source - files in the program, then also delete it here. -*/ - - -/** @file src/reel_encryptable_asset.cc - * @brief ReelEncryptableAsset class - */ - - -#include "reel_encryptable_asset.h" -#include "util.h" -#include "mxf.h" -#include "dcp_assert.h" -#include -#include - - -using std::string; -using std::shared_ptr; -using boost::optional; -using namespace dcp; - - -ReelEncryptableAsset::ReelEncryptableAsset (optional key_id) - : _key_id (key_id) -{ - -} - - -ReelEncryptableAsset::ReelEncryptableAsset (shared_ptr node) - : _key_id (node->optional_string_child("KeyId")) -{ - if (_key_id) { - _key_id = remove_urn_uuid (*_key_id); - } -} - - -void -ReelEncryptableAsset::write_to_cpl_encryptable (xmlpp::Node* node) const -{ - if (key_id()) { - auto hash = find_child (node, "Hash"); - node->add_child_before(hash, "KeyId")->add_child_text("urn:uuid:" + key_id().get()); - } -} diff --git a/src/reel_encryptable_asset.h b/src/reel_encryptable_asset.h deleted file mode 100644 index 0eeb9640..00000000 --- a/src/reel_encryptable_asset.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright (C) 2012-2021 Carl Hetherington - - This file is part of libdcp. - - libdcp 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. - - libdcp 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 libdcp. If not, see . - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the - OpenSSL library under certain conditions as described in each - individual source file, and distribute linked combinations - including the two. - - You must obey the GNU General Public License in all respects - for all of the code used other than OpenSSL. If you modify - file(s) with this exception, you may extend this exception to your - version of the file(s), but you are not obligated to do so. If you - do not wish to do so, delete this exception statement from your - version. If you delete this exception statement from all source - files in the program, then also delete it here. -*/ - - -/** @file src/reel_encryptable_asset.h - * @brief ReelEncryptableAsset class - */ - - -#ifndef LIBDCP_REEL_ENCRYPTABLE_ASSET_H -#define LIBDCP_REEL_ENCRYPTABLE_ASSET_H - - -#include "reel_file_asset.h" -#include "ref.h" -#include -#include -#include - - -namespace cxml { - class Node; -} - - -namespace dcp { - - -/** @class ReelEncryptableAsset - * @brief Part of a Reel's description which refers to an asset which can be encrypted - */ -class ReelEncryptableAsset -{ -public: - explicit ReelEncryptableAsset (boost::optional key_id); - explicit ReelEncryptableAsset (std::shared_ptr); - virtual ~ReelEncryptableAsset () {} - - /** @return the 4-character key type for this MXF (MDIK, MDAK, etc.) */ - virtual std::string key_type () const = 0; - - /** @return true if a KeyId is specified for this asset, implying - * that its content is encrypted. - */ - bool encrypted () const { - return static_cast(_key_id); - } - - /** @return Key ID to describe the key that encrypts this asset's - * content, if there is one. - */ - boost::optional key_id () const { - return _key_id; - } - -protected: - void write_to_cpl_encryptable (xmlpp::Node* node) const; - -private: - boost::optional _key_id; ///< The <KeyId> from the reel's entry for this asset, if there is one -}; - - -} - - -#endif diff --git a/src/reel_file_asset.cc b/src/reel_file_asset.cc index 85bf9de7..1ca77b4d 100644 --- a/src/reel_file_asset.cc +++ b/src/reel_file_asset.cc @@ -39,16 +39,20 @@ #include "asset.h" #include "reel_file_asset.h" +#include using std::shared_ptr; +using std::string; +using boost::optional; using namespace dcp; -ReelFileAsset::ReelFileAsset (shared_ptr asset, std::string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) +ReelFileAsset::ReelFileAsset (shared_ptr asset, optional key_id, std::string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) : ReelAsset (id, edit_rate, intrinsic_duration, entry_point) , _asset_ref (asset) , _hash (asset->hash()) + , _key_id (key_id) { } @@ -57,9 +61,12 @@ ReelFileAsset::ReelFileAsset (shared_ptr asset, std::string id, Fraction ReelFileAsset::ReelFileAsset (shared_ptr node) : ReelAsset (node) , _asset_ref (remove_urn_uuid(node->string_child("Id"))) - , _hash (node->optional_string_child ("Hash")) + , _hash (node->optional_string_child("Hash")) + , _key_id (node->optional_string_child("KeyId")) { - + if (_key_id) { + _key_id = remove_urn_uuid (*_key_id); + } } @@ -82,3 +89,17 @@ ReelFileAsset::file_asset_equals (shared_ptr other, Equalit return true; } + +xmlpp::Node * +ReelFileAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +{ + auto asset = ReelAsset::write_to_cpl (node, standard); + if (_key_id) { + asset->add_child("KeyId")->add_child_text("urn:uuid:" + *_key_id); + } + if (_hash) { + asset->add_child("Hash")->add_child_text(*_hash); + } + return asset; +} + diff --git a/src/reel_file_asset.h b/src/reel_file_asset.h index 042f94b4..6ef917ab 100644 --- a/src/reel_file_asset.h +++ b/src/reel_file_asset.h @@ -53,9 +53,11 @@ namespace dcp { class ReelFileAsset : public ReelAsset { public: - ReelFileAsset (std::shared_ptr asset, std::string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point); + ReelFileAsset (std::shared_ptr asset, boost::optional key_id, std::string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point); explicit ReelFileAsset (std::shared_ptr node); + virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + /** @return a Ref to our actual asset */ Ref const & asset_ref () const { return _asset_ref; @@ -79,6 +81,22 @@ public: bool file_asset_equals (std::shared_ptr other, EqualityOptions opt, NoteHandler note) const; + virtual boost::optional key_type () const { + return boost::none; + } + + bool encryptable () const override { + return static_cast(key_type()); + } + + boost::optional key_id () const { + return _key_id; + } + + bool encrypted () const { + return static_cast(key_id()); + } + protected: template @@ -98,6 +116,7 @@ protected: /** Either our asset's computed hash or the hash read in from the CPL, if it's present */ boost::optional _hash; + boost::optional _key_id; ///< The <KeyId> from the reel's entry for this asset, if there is one }; diff --git a/src/reel_interop_closed_caption_asset.cc b/src/reel_interop_closed_caption_asset.cc index 0730f77e..3e85b135 100644 --- a/src/reel_interop_closed_caption_asset.cc +++ b/src/reel_interop_closed_caption_asset.cc @@ -58,18 +58,6 @@ ReelInteropClosedCaptionAsset::ReelInteropClosedCaptionAsset (shared_ptradd_child("Language")->add_child_text(*_language); - } - - return asset; -} - - string ReelInteropClosedCaptionAsset::cpl_node_name (Standard) const { @@ -83,3 +71,13 @@ ReelInteropClosedCaptionAsset::cpl_node_namespace () const return make_pair("http://www.digicine.com/PROTO-ASDCP-CC-CPL-20070926#", "cc-cpl"); } + +xmlpp::Node * +ReelInteropClosedCaptionAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +{ + auto asset = ReelClosedCaptionAsset::write_to_cpl (node, standard); + if (_language) { + asset->add_child("Language")->add_child_text(*_language); + } + return asset; +} diff --git a/src/reel_interop_closed_caption_asset.h b/src/reel_interop_closed_caption_asset.h index 8031142d..bb5b5cec 100644 --- a/src/reel_interop_closed_caption_asset.h +++ b/src/reel_interop_closed_caption_asset.h @@ -54,12 +54,12 @@ public: ReelInteropClosedCaptionAsset (std::shared_ptr asset, Fraction edit_rate, int64_t instrinsic_duration, int64_t entry_point); explicit ReelInteropClosedCaptionAsset (std::shared_ptr); + xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; + std::shared_ptr interop_asset () const { return std::dynamic_pointer_cast(asset()); } - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const; - private: std::string cpl_node_name (Standard) const; std::pair cpl_node_namespace () const override; diff --git a/src/reel_interop_subtitle_asset.cc b/src/reel_interop_subtitle_asset.cc index 5b8cfcdd..08ea4bb4 100644 --- a/src/reel_interop_subtitle_asset.cc +++ b/src/reel_interop_subtitle_asset.cc @@ -60,15 +60,3 @@ ReelInteropSubtitleAsset::ReelInteropSubtitleAsset (std::shared_ptrdone (); } - -xmlpp::Node * -ReelInteropSubtitleAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const -{ - auto asset = write_to_cpl_asset (node, standard, _hash); - if (_language) { - asset->add_child("Language")->add_child_text(*_language); - } - return asset; -} - - diff --git a/src/reel_interop_subtitle_asset.h b/src/reel_interop_subtitle_asset.h index 41c4fa67..83a7ab25 100644 --- a/src/reel_interop_subtitle_asset.h +++ b/src/reel_interop_subtitle_asset.h @@ -57,8 +57,6 @@ public: std::shared_ptr interop_asset () const { return std::dynamic_pointer_cast(asset()); } - - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const; }; diff --git a/src/reel_markers_asset.cc b/src/reel_markers_asset.cc index c6339df5..55a50a68 100644 --- a/src/reel_markers_asset.cc +++ b/src/reel_markers_asset.cc @@ -105,7 +105,7 @@ xmlpp::Node* ReelMarkersAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const { int const tcr = edit_rate().numerator / edit_rate().denominator; - auto asset = write_to_cpl_asset (node, standard, optional()); + auto asset = ReelAsset::write_to_cpl (node, standard); auto ml = asset->add_child("MarkerList"); for (auto const& i: _markers) { auto m = ml->add_child("Marker"); diff --git a/src/reel_picture_asset.cc b/src/reel_picture_asset.cc index ddc6a802..4f7f863f 100644 --- a/src/reel_picture_asset.cc +++ b/src/reel_picture_asset.cc @@ -57,8 +57,7 @@ using namespace dcp; ReelPictureAsset::ReelPictureAsset (shared_ptr asset, int64_t entry_point) - : ReelFileAsset (asset, asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point) - , ReelEncryptableAsset (asset->key_id()) + : ReelFileAsset (asset, asset->key_id(), asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point) , _frame_rate (asset->frame_rate ()) , _screen_aspect_ratio (asset->screen_aspect_ratio ()) { @@ -68,7 +67,6 @@ ReelPictureAsset::ReelPictureAsset (shared_ptr asset, int64_t entr ReelPictureAsset::ReelPictureAsset (shared_ptr node) : ReelFileAsset (node) - , ReelEncryptableAsset (node) { _frame_rate = Fraction (node->string_child ("FrameRate")); try { @@ -88,9 +86,10 @@ ReelPictureAsset::ReelPictureAsset (shared_ptr node) xmlpp::Node* ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const { - auto asset = write_to_cpl_asset (node, standard, hash()); + auto asset = ReelFileAsset::write_to_cpl (node, standard); asset->add_child("FrameRate")->add_child_text(String::compose("%1 %2", _frame_rate.numerator, _frame_rate.denominator)); + if (standard == Standard::INTEROP) { /* Allowed values for this tag from the standard */ @@ -111,26 +110,17 @@ ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const } } - asset->add_child ("ScreenAspectRatio")->add_child_text (raw_convert (closest.get(), 2, true)); + asset->add_child("ScreenAspectRatio")->add_child_text(raw_convert(closest.get(), 2, true)); } else { - asset->add_child ("ScreenAspectRatio")->add_child_text ( + asset->add_child("ScreenAspectRatio")->add_child_text( String::compose ("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator) ); } - write_to_cpl_encryptable (asset); - return asset; } -string -ReelPictureAsset::key_type () const -{ - return "MDIK"; -} - - bool ReelPictureAsset::equals (shared_ptr other, EqualityOptions opt, NoteHandler note) const { diff --git a/src/reel_picture_asset.h b/src/reel_picture_asset.h index 6eb01bc9..5a925e24 100644 --- a/src/reel_picture_asset.h +++ b/src/reel_picture_asset.h @@ -41,8 +41,7 @@ #define LIBDCP_REEL_PICTURE_ASSET_H -#include "reel_encryptable_asset.h" -#include "reel_asset.h" +#include "reel_file_asset.h" #include "picture_asset.h" @@ -52,7 +51,7 @@ namespace dcp { /** @class ReelPictureAsset * @brief Part of a Reel's description which refers to a picture asset */ -class ReelPictureAsset : public ReelFileAsset, public ReelEncryptableAsset +class ReelPictureAsset : public ReelFileAsset { public: ReelPictureAsset (std::shared_ptr asset, int64_t entry_point); @@ -88,7 +87,9 @@ public: } private: - std::string key_type () const; + boost::optional key_type () const override { + return std::string ("MDIK"); + } Fraction _frame_rate; Fraction _screen_aspect_ratio; diff --git a/src/reel_smpte_closed_caption_asset.cc b/src/reel_smpte_closed_caption_asset.cc index 44125037..34fba18b 100644 --- a/src/reel_smpte_closed_caption_asset.cc +++ b/src/reel_smpte_closed_caption_asset.cc @@ -50,7 +50,6 @@ using namespace dcp; ReelSMPTEClosedCaptionAsset::ReelSMPTEClosedCaptionAsset (shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) : ReelClosedCaptionAsset (asset, edit_rate, intrinsic_duration, entry_point) - , ReelEncryptableAsset (asset->key_id()) { } @@ -58,7 +57,6 @@ ReelSMPTEClosedCaptionAsset::ReelSMPTEClosedCaptionAsset (shared_ptr node) : ReelClosedCaptionAsset (node) - , ReelEncryptableAsset (node) { node->done (); } @@ -67,13 +65,10 @@ ReelSMPTEClosedCaptionAsset::ReelSMPTEClosedCaptionAsset (shared_ptradd_child("Language", "tt")->add_child_text(*_language); } - return asset; } diff --git a/src/reel_smpte_closed_caption_asset.h b/src/reel_smpte_closed_caption_asset.h index 32fe5117..889ce5f6 100644 --- a/src/reel_smpte_closed_caption_asset.h +++ b/src/reel_smpte_closed_caption_asset.h @@ -41,7 +41,6 @@ #define LIBDCP_REEL_SMPTE_CLOSED_CAPTION_ASSET_H -#include "reel_encryptable_asset.h" #include "reel_file_asset.h" #include "reel_closed_caption_asset.h" #include "smpte_subtitle_asset.h" @@ -50,7 +49,7 @@ namespace dcp { -class ReelSMPTEClosedCaptionAsset : public ReelClosedCaptionAsset, public ReelEncryptableAsset +class ReelSMPTEClosedCaptionAsset : public ReelClosedCaptionAsset { public: ReelSMPTEClosedCaptionAsset (std::shared_ptr asset, Fraction edit_rate, int64_t instrinsic_duration, int64_t entry_point); @@ -63,8 +62,8 @@ public: } private: - std::string key_type () const override { - return "MDSK"; + boost::optional key_type () const override { + return std::string("MDSK"); } std::string cpl_node_name (Standard) const override; diff --git a/src/reel_smpte_subtitle_asset.cc b/src/reel_smpte_subtitle_asset.cc index 0cd38c21..5a7c8c6c 100644 --- a/src/reel_smpte_subtitle_asset.cc +++ b/src/reel_smpte_subtitle_asset.cc @@ -50,7 +50,6 @@ using namespace dcp; ReelSMPTESubtitleAsset::ReelSMPTESubtitleAsset (shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) : ReelSubtitleAsset (asset, edit_rate, intrinsic_duration, entry_point) - , ReelEncryptableAsset (asset->key_id()) { } @@ -58,20 +57,7 @@ ReelSMPTESubtitleAsset::ReelSMPTESubtitleAsset (shared_ptr a ReelSMPTESubtitleAsset::ReelSMPTESubtitleAsset (shared_ptr node) : ReelSubtitleAsset (node) - , ReelEncryptableAsset (node) { node->done (); } - -xmlpp::Node * -ReelSMPTESubtitleAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const -{ - auto asset = write_to_cpl_asset (node, standard, _hash); - write_to_cpl_encryptable (asset); - if (_language) { - asset->add_child("Language")->add_child_text(*_language); - } - return asset; -} - diff --git a/src/reel_smpte_subtitle_asset.h b/src/reel_smpte_subtitle_asset.h index 8a7e0c24..aaff9a98 100644 --- a/src/reel_smpte_subtitle_asset.h +++ b/src/reel_smpte_subtitle_asset.h @@ -37,7 +37,6 @@ */ -#include "reel_encryptable_asset.h" #include "reel_subtitle_asset.h" #include "smpte_subtitle_asset.h" @@ -51,21 +50,19 @@ class SMPTESubtitleAsset; /** @class ReelSMPTESubtitleAsset * @brief Part of a Reel's description which refers to an SMPTE subtitle MXF file */ -class ReelSMPTESubtitleAsset : public ReelSubtitleAsset, public ReelEncryptableAsset +class ReelSMPTESubtitleAsset : public ReelSubtitleAsset { public: ReelSMPTESubtitleAsset (std::shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point); explicit ReelSMPTESubtitleAsset (std::shared_ptr); - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const override; - std::shared_ptr smpte_asset () const { return std::dynamic_pointer_cast(asset()); } private: - std::string key_type () const { - return "MDSK"; + boost::optional key_type () const override { + return std::string("MDSK"); } }; diff --git a/src/reel_sound_asset.cc b/src/reel_sound_asset.cc index 9cf672df..e944467f 100644 --- a/src/reel_sound_asset.cc +++ b/src/reel_sound_asset.cc @@ -45,12 +45,12 @@ using std::string; using std::shared_ptr; +using boost::optional; using namespace dcp; ReelSoundAsset::ReelSoundAsset (shared_ptr asset, int64_t entry_point) - : ReelFileAsset (asset, asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point) - , ReelEncryptableAsset (asset->key_id()) + : ReelFileAsset (asset, asset->key_id(), asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point) { } @@ -58,7 +58,6 @@ ReelSoundAsset::ReelSoundAsset (shared_ptr asset, int64_t entry_poin ReelSoundAsset::ReelSoundAsset (shared_ptr node) : ReelFileAsset (node) - , ReelEncryptableAsset (node) { node->ignore_child ("Language"); node->done (); @@ -72,19 +71,10 @@ ReelSoundAsset::cpl_node_name (Standard) const } -string +optional ReelSoundAsset::key_type () const { - return "MDAK"; -} - - -xmlpp::Node * -ReelSoundAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const -{ - auto asset = write_to_cpl_asset (node, standard, hash()); - write_to_cpl_encryptable (asset); - return asset; + return string("MDAK"); } diff --git a/src/reel_sound_asset.h b/src/reel_sound_asset.h index bf686ec9..0b4d0f9d 100644 --- a/src/reel_sound_asset.h +++ b/src/reel_sound_asset.h @@ -37,8 +37,7 @@ */ -#include "reel_encryptable_asset.h" -#include "reel_asset.h" +#include "reel_file_asset.h" #include "sound_asset.h" #include #include @@ -50,27 +49,26 @@ namespace dcp { /** @class ReelSoundAsset * @brief Part of a Reel's description which refers to a sound asset */ -class ReelSoundAsset : public ReelFileAsset, public ReelEncryptableAsset +class ReelSoundAsset : public ReelFileAsset { public: ReelSoundAsset (std::shared_ptr content, int64_t entry_point); explicit ReelSoundAsset (std::shared_ptr); - xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const; bool equals (std::shared_ptr, EqualityOptions, NoteHandler) const; /** @return the SoundAsset that this object refers to */ std::shared_ptr asset () { - return asset_of_type (); + return asset_of_type(); } /** @return the SoundAsset that this object refers to */ std::shared_ptr asset () const { - return asset_of_type (); + return asset_of_type(); } private: - std::string key_type () const; + boost::optional key_type () const; std::string cpl_node_name (Standard standard) const; }; diff --git a/src/reel_subtitle_asset.cc b/src/reel_subtitle_asset.cc index 9c683caa..e3ca2006 100644 --- a/src/reel_subtitle_asset.cc +++ b/src/reel_subtitle_asset.cc @@ -52,7 +52,14 @@ using namespace dcp; ReelSubtitleAsset::ReelSubtitleAsset (std::shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) - : ReelFileAsset (asset, asset->id(), edit_rate, intrinsic_duration, entry_point) + : ReelFileAsset ( + asset, + dynamic_pointer_cast(asset) ? dynamic_pointer_cast(asset)->key_id() : boost::none, + asset->id(), + edit_rate, + intrinsic_duration, + entry_point + ) { } @@ -85,11 +92,22 @@ ReelSubtitleAsset::equals (shared_ptr other, EqualityOp if (!asset_equals (other, opt, note)) { return false; } - - if (_asset_ref.resolved() && other->_asset_ref.resolved()) { - return _asset_ref->equals (other->_asset_ref.asset(), opt, note); + if (!file_asset_equals (other, opt, note)) { + return false; } return true; } + +xmlpp::Node * +ReelSubtitleAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const +{ + auto asset = ReelFileAsset::write_to_cpl (node, standard); + if (_language) { + asset->add_child("Language")->add_child_text(*_language); + } + return asset; +} + + diff --git a/src/reel_subtitle_asset.h b/src/reel_subtitle_asset.h index fd4c5cd1..a4e674ba 100644 --- a/src/reel_subtitle_asset.h +++ b/src/reel_subtitle_asset.h @@ -65,6 +65,8 @@ public: ReelSubtitleAsset (std::shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point); explicit ReelSubtitleAsset (std::shared_ptr); + xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const; + bool equals (std::shared_ptr, EqualityOptions, NoteHandler) const; std::shared_ptr asset () const { diff --git a/src/verify.cc b/src/verify.cc index e176362a..a2298f38 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -1088,14 +1088,9 @@ pkl_has_encrypted_assets (shared_ptr dcp, shared_ptr pkl) for (auto i: dcp->cpls()) { for (auto j: i->reel_file_assets()) { if (j->asset_ref().resolved()) { - /* It's a bit surprising / broken but Interop subtitle assets are represented - * in reels by ReelSubtitleAsset which inherits ReelEncryptableAsset, so it's possible for - * ReelEncryptableAssets to have assets which are not MXFs. - */ - if (auto asset = dynamic_pointer_cast(j->asset_ref().asset())) { - if (asset->encrypted()) { - encrypted.push_back(j->asset_ref().id()); - } + auto mxf = dynamic_pointer_cast(j->asset_ref().asset()); + if (mxf && mxf->encrypted()) { + encrypted.push_back(j->asset_ref().id()); } } } @@ -1242,7 +1237,7 @@ dcp::verify ( notes.push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::INVALID_INTRINSIC_DURATION, i->id()}); } auto file_asset = dynamic_pointer_cast(i); - if (dynamic_pointer_cast(i) && !file_asset->hash()) { + if (i->encryptable() && !file_asset->hash()) { notes.push_back ({VerificationNote::Type::BV21_ERROR, VerificationNote::Code::MISSING_HASH, i->id()}); } } diff --git a/src/wscript b/src/wscript index f6e0d15b..de7d8e67 100644 --- a/src/wscript +++ b/src/wscript @@ -82,7 +82,6 @@ def build(bld): reel_asset.cc reel_atmos_asset.cc reel_closed_caption_asset.cc - reel_encryptable_asset.cc reel_file_asset.cc reel_interop_closed_caption_asset.cc reel_interop_subtitle_asset.cc @@ -173,7 +172,7 @@ def build(bld): reel.h reel_asset.h reel_atmos_asset.h - reel_encryptable_asset.h + reel_closed_caption_asset.h reel_file_asset.h reel_interop_closed_caption_asset.h reel_interop_subtitle_asset.h -- 2.30.2