Move some CPL writing from picture/sound assets to the MXF. Pick up key_id from...
authorCarl Hetherington <cth@carlh.net>
Sat, 6 Jul 2013 19:30:19 +0000 (20:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 6 Jul 2013 19:30:19 +0000 (20:30 +0100)
15 files changed:
src/cpl.cc
src/cpl.h
src/dcp.cc
src/dcp.h
src/mxf_asset.cc
src/mxf_asset.h
src/parse/cpl.cc
src/parse/cpl.h
src/picture_asset.cc
src/picture_asset.h
src/reel.cc
src/reel.h
src/sound_asset.cc
src/sound_asset.h
test/tests.cc

index fd7b734ea22f7e9c573f2d1c465655c299297043..7889b14c82bb55a2510b002a96640aeb82e717fb 100644 (file)
@@ -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;
+}
index 3f4835047205e6951c18cef4d66a2839da622dfe..0aa2fed3a6f1a995ebc43937ebaa529c989e9c8c 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -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;
        
index fdd7a1f5a756b565e8e9d50f6d8c6641a17148f2..c2118ed0bcd9a5736a2c3e3b4b63266b1e0178f1 100644 (file)
@@ -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;
+}
index 42c48387cee6591808c34cee14c33e429d4c1813..7a9cb12677af8db4cc42fdf1df97c2044c162fab 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -96,6 +96,8 @@ public:
                return _cpls;
        }
 
+       bool encrypted () const;
+
        /** Emitted with a parameter between 0 and 1 to indicate progress
         *  for long jobs.
         */
index d52ab2cc45f318a36aba60e3bc1dbf3c763eb76a..3cb1325069cb0ee77f08926b1dcbe88d3031a115 100644 (file)
@@ -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);
+       }
+}
index a23a052dafd91643b3c533eb22738a2b9efd06ea..1e4d362c3ec6a48e5d313e4e9c45449fc5c92ff5 100644 (file)
@@ -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;
index c4cf4374a4a4f3bb2164df5657a47bdd75de1029..e7ed44978186dbe0b0dd138b6aa2d17a98af88af 100644 (file)
@@ -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");
        
index 434a244b53d04452b60636eab7988c7318c9caee..04bf9351bcea69e06abe3cb1ca8bab73b85cd35c 100644 (file)
@@ -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 */
index c6a95c74509b7969bafcd1904e7bede9a64c3b27..c9e1da45d02acde5d089f59a1e0157a2ab43e93e 100644 (file)
@@ -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
index 08f892ed34e2f868b2a7937cf707aaa60fdc6d25..cc99ddbcbe0ea592d89000fee51a7958c44114c5 100644 (file)
@@ -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;
index 3f07726929158e62f2a1c23f1d84d239093cd2b1..4a266fdab28f3af24330cb729dab8b7271d016ca 100644 (file)
@@ -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 ()));
+}
+
index 00278a143e4c0d13f6a3a29995d6bc9a2801ff7d..d09227b59005add9bc29046b56c9a60937391e35 100644 (file)
@@ -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:
index 45a656462c8ab6e54f6374d8332f5b892199dcba..0901e915af6fb837e99d48f04a5d483d529b1c46 100644 (file)
@@ -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
index a587b55101fbd7ec030df5999cc5a56e8679941c..06ad79b4a6607ef3e751e8edd82ff59bd1c07a80 100644 (file)
@@ -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;
index 1a29857aa63c83446060e6e7d90eea9535812584..4fc81571acde3a5889cc0331105d5fc52d1c0597 100644 (file)
@@ -68,6 +68,9 @@ wav (libdcp::Channel)
        return "test/data/1s_24-bit_48k_silence.wav";
 }
 
+static string test_corpus = "../libdcp-test";
+
+#include "decryption_test.cc"
 #include "dcp_test.cc"
 #include "error_test.cc"
 #include "read_dcp_test.cc"
@@ -76,12 +79,12 @@ wav (libdcp::Channel)
 #include "color_test.cc"
 #include "recovery_test.cc"
 
-BOOST_AUTO_TEST_CASE (crypt_chain)
-{
-       boost::filesystem::remove_all ("build/test/crypt");
-       boost::filesystem::create_directory ("build/test/crypt");
-       libdcp::make_crypt_chain ("build/test/crypt");
-}
+//BOOST_AUTO_TEST_CASE (crypt_chain)
+//{
+//     boost::filesystem::remove_all ("build/test/crypt");
+//     boost::filesystem::create_directory ("build/test/crypt");
+//     libdcp::make_crypt_chain ("build/test/crypt");
+//}
 
-#include "encryption_test.cc"
-#include "certificates_test.cc"
+//#include "encryption_test.cc"
+//#include "certificates_test.cc"