Fix ordering of KeyId tag in SMPTE CPLs.
authorCarl Hetherington <cth@carlh.net>
Fri, 5 Jun 2015 00:51:24 +0000 (01:51 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 5 Jun 2015 00:51:24 +0000 (01:51 +0100)
src/reel_mxf_asset.cc
src/reel_mxf_asset.h
src/reel_picture_asset.cc
src/reel_sound_asset.cc
src/reel_sound_asset.h
src/util.cc
src/util.h

index 9d7c1fada363d66737cbf9fe1de6677d96d057c1..55cb7e9c6816a8a7c5f8245473bdea6b91780221 100644 (file)
@@ -46,21 +46,3 @@ ReelMXFAsset::ReelMXFAsset (shared_ptr<const cxml::Node> node)
                _key_id = _key_id.substr (9);
        }
 }
-
-void
-ReelMXFAsset::write_to_cpl (xmlpp::Node* node, Standard s) const
-{
-       ReelAsset::write_to_cpl (node, s);
-
-       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;
-       }
-
-       DCP_ASSERT (i != c.end ());
-       
-        if (!_key_id.empty ()) {
-                (*i)->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id);
-        }
-}
index 765ba393fd42ec3452b72ea2bbc301aa753083d8..60234f4f47eba4d01d5845fa7d55201108af79d5 100644 (file)
@@ -43,8 +43,6 @@ public:
        /** @return the 4-character key type for this MXF (MDIK, MDAK, etc.) */
        virtual std::string key_type () const = 0;
        
-       void write_to_cpl (xmlpp::Node* node, Standard standard) const;
-       
        /** @return true if a KeyId is specified for this asset, implying
         *  that its content is encrypted.
         */
index 6bac3bce5f47d21fe3563f8cd72a2d460f28a608..d08f1781e5e9a0341683dffc1144ab4fcf05f0e1 100644 (file)
@@ -71,26 +71,27 @@ ReelPictureAsset::ReelPictureAsset (shared_ptr<const cxml::Node> node)
 void
 ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
 {
-       ReelMXFAsset::write_to_cpl (node, standard);
+       ReelAsset::write_to_cpl (node, standard);
 
-       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;
-       }
-
-       DCP_ASSERT (i != c.end ());
+       /* Find <MainPicture> */
+       xmlpp::Node* mp = find_child (node, cpl_node_name ());
        
-       (*i)->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator));
+       mp->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator));
        if (standard == INTEROP) {
                stringstream s;
                s << std::fixed << std::setprecision (2) << (float (_screen_aspect_ratio.numerator) / _screen_aspect_ratio.denominator);
-               (*i)->add_child ("ScreenAspectRatio")->add_child_text (s.str ());
+               mp->add_child ("ScreenAspectRatio")->add_child_text (s.str ());
        } else {
-               (*i)->add_child ("ScreenAspectRatio")->add_child_text (
+               mp->add_child ("ScreenAspectRatio")->add_child_text (
                        String::compose ("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator)
                        );
        }
+
+        if (!key_id ().empty ()) {
+               /* Find <Hash> */
+               xmlpp::Node* hash = find_child (mp, "Hash");
+               mp->add_child_before (hash, "KeyId")->add_child_text ("urn:uuid:" + key_id ());
+        }
 }
 
 string
index 55167d827b3e7c704e6062f882a31883b7699392..a5e32b024cf6295005d06bfd77238478525ecf0c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
  */
 
 #include "reel_sound_asset.h"
+#include "dcp_assert.h"
 #include <libcxml/cxml.h>
 
 using std::string;
@@ -52,3 +53,17 @@ ReelSoundAsset::key_type () const
 {
        return "MDAK";
 }
+
+void
+ReelSoundAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
+{
+       ReelAsset::write_to_cpl (node, standard);
+
+        if (!key_id ().empty ()) {
+               /* Find <MainSound> */
+               xmlpp::Node* ms = find_child (node, cpl_node_name ());
+               /* Find <Hash> */
+               xmlpp::Node* hash = find_child (ms, "Hash");
+               ms->add_child_before (hash, "KeyId")->add_child_text ("urn:uuid:" + key_id ());
+        }
+}
index b5dc819a07f843f7ce2868763063a8b1a1b6a66e..622a97cf6aaf80852ec9329ded151104089b255f 100644 (file)
@@ -37,6 +37,8 @@ public:
        ReelSoundAsset (boost::shared_ptr<dcp::SoundMXF> content, int64_t entry_point);
        ReelSoundAsset (boost::shared_ptr<const cxml::Node>);
 
+       void write_to_cpl (xmlpp::Node* node, Standard standard) const;
+
        /** @return the SoundMXF that this object refers to */
        boost::shared_ptr<SoundMXF> mxf () {
                return boost::dynamic_pointer_cast<SoundMXF> (_content.object ());
index 044801b79ba6376dd1a723f50c4b18b59eee81e4..86d1bc87d2810e0bfe7f3632e4509b586015447e 100644 (file)
@@ -414,3 +414,16 @@ dcp::private_key_fingerprint (string key)
        char digest_base64[64];
        return Kumu::base64encode (digest, 20, digest_base64, 64);
 }
+
+xmlpp::Node *
+dcp::find_child (xmlpp::Node const * node, string name)
+{
+       xmlpp::Node::NodeList c = node->get_children ();
+       xmlpp::Node::NodeList::iterator i = c.begin();
+       while (i != c.end() && (*i)->get_name() != name) {
+               ++i;
+       }
+
+       DCP_ASSERT (i != c.end ());
+       return *i;
+}
index dbcec78ccb4789713939b97bce76a5158e0fb3c9..2ae912668681aa74767b31e501beec856f17afe6 100644 (file)
@@ -35,6 +35,7 @@
 
 namespace xmlpp {
        class Element;
+       class Node;
 }
 
 namespace dcp {
@@ -67,6 +68,7 @@ extern boost::optional<boost::filesystem::path> relative_to_root (boost::filesys
 extern FILE * fopen_boost (boost::filesystem::path, std::string);
 extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length = 65536);
 extern std::string private_key_fingerprint (std::string key);
+extern xmlpp::Node* find_child (xmlpp::Node const * node, std::string name);
 
 template <class F, class T>
 std::list<boost::shared_ptr<T> >