Bump version
[libdcp.git] / src / mxf_asset.cc
index d52ab2cc45f318a36aba60e3bc1dbf3c763eb76a..f8fe8ac5eebb31be47d43a1bd36f2a8d1b80201b 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"
 #include "util.h"
 #include "metadata.h"
 #include "exceptions.h"
+#include "kdm.h"
 
 using std::string;
 using std::list;
+using std::pair;
 using boost::shared_ptr;
+using boost::lexical_cast;
 using boost::dynamic_pointer_cast;
 using namespace libdcp;
 
@@ -44,6 +48,7 @@ MXFAsset::MXFAsset (string directory, string file_name)
        , _progress (0)
        , _encrypted (false)
        , _encryption_context (0)
+       , _decryption_context (0)
 {
 
 }
@@ -53,6 +58,7 @@ MXFAsset::MXFAsset (string directory, string file_name, boost::signals2::signal<
        , _progress (progress)
        , _encrypted (encrypted)
        , _encryption_context (0)
+       , _decryption_context (0)
 {
        if (_encrypted) {
                _key_id = make_uuid ();
@@ -82,13 +88,17 @@ MXFAsset::~MXFAsset ()
 }
 
 void
-MXFAsset::fill_writer_info (ASDCP::WriterInfo* writer_info, string uuid, MXFMetadata const & metadata)
+MXFAsset::fill_writer_info (ASDCP::WriterInfo* writer_info, string uuid, bool interop, MXFMetadata const & metadata)
 {
        writer_info->ProductVersion = metadata.product_version;
        writer_info->CompanyName = metadata.company_name;
        writer_info->ProductName = metadata.product_name.c_str();
 
-       writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
+       if (interop) {
+               writer_info->LabelSetType = ASDCP::LS_MXF_INTEROP;
+       } else {
+               writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
+       }
        unsigned int c;
        Kumu::hex2bin (uuid.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
        assert (c == Kumu::UUID_Length);
@@ -133,3 +143,31 @@ 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::Element* node, bool interop) const
+{
+       pair<string, string> const attr = cpl_node_attribute (interop);
+       xmlpp::Element* a = node->add_child (cpl_node_name ());
+       if (!attr.first.empty ()) {
+               a->set_attribute (attr.first, attr.second);
+       }
+       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);
+       }
+}
+
+void
+MXFAsset::set_kdm_cipher (KDMCipher cipher)
+{
+       _decryption_context = new ASDCP::AESDecContext;
+       if (ASDCP_FAILURE (_decryption_context->InitKey (cipher.key_raw ()))) {
+               throw MiscError ("could not set up decryption context");
+       }
+}