diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-07-06 20:30:19 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-07-06 20:30:19 +0100 |
| commit | dcccb2dd1d180b8be67e539395dccbe82b0fb5a8 (patch) | |
| tree | 53b76a2df1343e5896bc9462ec8661179ede2ee3 /src | |
| parent | 5f71c3f0a7a041b3621f7325915d1105424f7e53 (diff) | |
Move some CPL writing from picture/sound assets to the MXF. Pick up key_id from CPL assets and hence provide and test for encrypted() method on DCP.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cpl.cc | 16 | ||||
| -rw-r--r-- | src/cpl.h | 2 | ||||
| -rw-r--r-- | src/dcp.cc | 12 | ||||
| -rw-r--r-- | src/dcp.h | 2 | ||||
| -rw-r--r-- | src/mxf_asset.cc | 17 | ||||
| -rw-r--r-- | src/mxf_asset.h | 11 | ||||
| -rw-r--r-- | src/parse/cpl.cc | 5 | ||||
| -rw-r--r-- | src/parse/cpl.h | 2 | ||||
| -rw-r--r-- | src/picture_asset.cc | 30 | ||||
| -rw-r--r-- | src/picture_asset.h | 13 | ||||
| -rw-r--r-- | src/reel.cc | 6 | ||||
| -rw-r--r-- | src/reel.h | 2 | ||||
| -rw-r--r-- | src/sound_asset.cc | 15 | ||||
| -rw-r--r-- | src/sound_asset.h | 5 |
14 files changed, 102 insertions, 36 deletions
@@ -110,6 +110,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa picture->set_entry_point (p->entry_point); picture->set_duration (p->duration); + picture->set_key_id (p->key_id); } catch (MXFFileError) { if (require_mxfs) { throw; @@ -128,6 +129,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa picture->set_entry_point (p->entry_point); picture->set_duration (p->duration); + picture->set_key_id (p->key_id); } catch (MXFFileError) { if (require_mxfs) { @@ -148,6 +150,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa sound->set_entry_point ((*i)->asset_list->main_sound->entry_point); sound->set_duration ((*i)->asset_list->main_sound->duration); + sound->set_key_id ((*i)->asset_list->main_sound->key_id); } catch (MXFFileError) { if (require_mxfs) { throw; @@ -465,3 +468,16 @@ CPL::make_kdm ( return doc; } + +/** @return true if we have any encrypted content */ +bool +CPL::encrypted () const +{ + for (list<shared_ptr<const Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + if ((*i)->encrypted ()) { + return true; + } + } + + return false; +} @@ -75,6 +75,8 @@ public: } std::list<boost::shared_ptr<const Asset> > assets () const; + + bool encrypted () const; bool equals (CPL const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const; @@ -302,3 +302,15 @@ DCP::assets () const a.unique (); return a; } + +bool +DCP::encrypted () const +{ + for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { + if ((*i)->encrypted ()) { + return true; + } + } + + return false; +} @@ -96,6 +96,8 @@ public: return _cpls; } + bool encrypted () const; + /** Emitted with a parameter between 0 and 1 to indicate progress * for long jobs. */ diff --git a/src/mxf_asset.cc b/src/mxf_asset.cc index d52ab2cc..3cb13250 100644 --- a/src/mxf_asset.cc +++ b/src/mxf_asset.cc @@ -24,6 +24,7 @@ #include <iostream> #include <fstream> #include <boost/filesystem.hpp> +#include <boost/lexical_cast.hpp> #include <libxml++/nodes/element.h> #include "AS_DCP.h" #include "KM_prng.h" @@ -36,6 +37,7 @@ using std::string; using std::list; using boost::shared_ptr; +using boost::lexical_cast; using boost::dynamic_pointer_cast; using namespace libdcp; @@ -133,3 +135,18 @@ MXFAsset::add_typed_key_id (xmlpp::Element* parent) const typed_key_id->add_child("KeyType")->add_child_text(key_type ()); typed_key_id->add_child("KeyId")->add_child_text("urn:uuid:" + _key_id); } + +void +MXFAsset::write_to_cpl (xmlpp::Node* node) const +{ + xmlpp::Node* a = node->add_child (cpl_node_name ()); + a->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); + a->add_child ("AnnotationText")->add_child_text (_file_name); + a->add_child ("EditRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1"); + a->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration)); + a->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point)); + a->add_child ("Duration")->add_child_text (lexical_cast<string> (_duration)); + if (_encrypted) { + a->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id); + } +} diff --git a/src/mxf_asset.h b/src/mxf_asset.h index a23a052d..1e4d362c 100644 --- a/src/mxf_asset.h +++ b/src/mxf_asset.h @@ -59,6 +59,8 @@ public: virtual bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; + virtual void write_to_cpl (xmlpp::Node *) const; + /** Fill in a ADSCP::WriteInfo struct. * @param w struct to fill in. * @param uuid uuid to use. @@ -66,9 +68,18 @@ public: void fill_writer_info (ASDCP::WriterInfo* w, std::string uuid, MXFMetadata const & metadata); void add_typed_key_id (xmlpp::Element *) const; + + void set_key_id (std::string k) { + _key_id = k; + } + + bool encrypted () const { + return !_key_id.empty (); + } protected: virtual std::string key_type () const = 0; + virtual std::string cpl_node_name () const = 0; /** Signal to emit to report progress, or 0 */ boost::signals2::signal<void (float)>* _progress; diff --git a/src/parse/cpl.cc b/src/parse/cpl.cc index c4cf4374..e7ed4497 100644 --- a/src/parse/cpl.cc +++ b/src/parse/cpl.cc @@ -111,6 +111,8 @@ Picture::Picture (shared_ptr<const cxml::Node> node) } + key_id = node->optional_string_child ("KeyId").get_value_or (""); + node->ignore_child ("Hash"); node->done (); @@ -124,7 +126,8 @@ MainSound::MainSound (shared_ptr<const cxml::Node> node) intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration"); entry_point = node->number_child<int64_t> ("EntryPoint"); duration = node->number_child<int64_t> ("Duration"); - + key_id = node->optional_string_child ("KeyId").get_value_or (""); + node->ignore_child ("Hash"); node->ignore_child ("Language"); diff --git a/src/parse/cpl.h b/src/parse/cpl.h index 434a244b..04bf9351 100644 --- a/src/parse/cpl.h +++ b/src/parse/cpl.h @@ -48,6 +48,7 @@ public: int64_t duration; Fraction frame_rate; Fraction screen_aspect_ratio; + std::string key_id; }; @@ -80,6 +81,7 @@ public: int64_t intrinsic_duration; int64_t entry_point; int64_t duration; + std::string key_id; }; /** @brief A simple parser for and representation of a CPL \<MainSubtitle\> node */ diff --git a/src/picture_asset.cc b/src/picture_asset.cc index c6a95c74..c9e1da45 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -65,21 +65,27 @@ PictureAsset::PictureAsset (string directory, string mxf_name) } +string +PictureAsset::cpl_node_name () const +{ + return "MainPicture"; +} + void PictureAsset::write_to_cpl (xmlpp::Node* node) const { - xmlpp::Node* mp = node->add_child ("MainPicture"); - mp->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); - mp->add_child ("AnnotationText")->add_child_text (_file_name); - mp->add_child ("EditRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1"); - mp->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration)); - mp->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point)); - mp->add_child ("Duration")->add_child_text (lexical_cast<string> (_duration)); - if (_encrypted) { - mp->add_child("KeyId")->add_child_text("urn:uuid:" + _key_id); - } - mp->add_child ("FrameRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1"); - mp->add_child ("ScreenAspectRatio")->add_child_text (lexical_cast<string> (_size.width) + " " + lexical_cast<string> (_size.height)); + MXFAsset::write_to_cpl (node); + + xmlpp::Node::NodeList c = node->get_children (); + xmlpp::Node::NodeList::iterator i = c.begin(); + while (i != c.end() && (*i)->get_name() != cpl_node_name ()) { + ++i; + } + + assert (i != c.end ()); + + (*i)->add_child ("FrameRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1"); + (*i)->add_child ("ScreenAspectRatio")->add_child_text (lexical_cast<string> (_size.width) + " " + lexical_cast<string> (_size.height)); } bool diff --git a/src/picture_asset.h b/src/picture_asset.h index 08f892ed..cc99ddbc 100644 --- a/src/picture_asset.h +++ b/src/picture_asset.h @@ -59,21 +59,16 @@ public: */ PictureAsset (std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration, bool encrypted, Size); - /** Write details of this asset to a CPL XML node. - * @param node Node. - */ - void write_to_cpl (xmlpp::Node* node) const; - bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; Size size () const { return _size; } + void write_to_cpl (xmlpp::Node *) const; + protected: - std::string key_type () const; - bool frame_buffer_equals ( int frame, EqualityOptions opt, boost::function<void (NoteType, std::string)> note, uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B @@ -81,6 +76,10 @@ protected: /** picture size in pixels */ Size _size; + +private: + std::string key_type () const; + std::string cpl_node_name () const; }; class MonoPictureAsset; diff --git a/src/reel.cc b/src/reel.cc index 3f077269..4a266fda 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -80,3 +80,9 @@ Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt, boost::f return true; } +bool +Reel::encrypted () const +{ + return ((_main_picture && _main_picture->encrypted ()) || (_main_sound && _main_sound->encrypted ())); +} + @@ -61,6 +61,8 @@ public: void write_to_cpl (xmlpp::Node *) const; + bool encrypted () const; + bool equals (boost::shared_ptr<const Reel> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> notes) const; private: diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 45a65646..0901e915 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -216,19 +216,10 @@ SoundAsset::construct (boost::function<string (Channel)> get_path, MXFMetadata c } } -void -SoundAsset::write_to_cpl (xmlpp::Node* node) const +string +SoundAsset::cpl_node_name () const { - xmlpp::Node* ms = node->add_child ("MainSound"); - ms->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); - ms->add_child ("AnnotationText")->add_child_text (_file_name); - ms->add_child ("EditRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1"); - ms->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration)); - ms->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point)); - ms->add_child ("Duration")->add_child_text (lexical_cast<string> (_duration)); - if (_encrypted) { - ms->add_child("KeyId")->add_child_text("urn:uuid:" + _key_id); - } + return "MainSound"; } bool diff --git a/src/sound_asset.h b/src/sound_asset.h index a587b551..06ad79b4 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -131,10 +131,6 @@ public: boost::shared_ptr<SoundAssetWriter> start_write (MXFMetadata const & metadata = MXFMetadata ()); - /** Write details of this asset to a CPL XML node. - * @param node Node. - */ - void write_to_cpl (xmlpp::Node* node) const; bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; @@ -152,6 +148,7 @@ private: std::string key_type () const; void construct (boost::function<std::string (Channel)> get_path, MXFMetadata const &); std::string path_from_channel (Channel channel, std::vector<std::string> const & files); + std::string cpl_node_name () const; /** Number of channels in the asset */ int _channels; |
