Tidy up interop API.
[libdcp.git] / src / dcp.cc
index c2118ed0bcd9a5736a2c3e3b4b63266b1e0178f1..30a3c3a430150cbc32e3ac7ff7a28af0e2921ccf 100644 (file)
@@ -46,6 +46,7 @@
 #include "reel.h"
 #include "cpl.h"
 #include "encryption.h"
+#include "kdm.h"
 
 using std::string;
 using std::list;
@@ -63,21 +64,21 @@ DCP::DCP (string directory)
 }
 
 void
-DCP::write_xml (XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
+DCP::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
 {
-       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
-               (*i)->write_xml (metadata, crypt);
+       for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+               (*i)->write_xml (interop, metadata, crypt);
        }
 
        string pkl_uuid = make_uuid ();
-       string pkl_path = write_pkl (pkl_uuid, metadata, crypt);
+       string pkl_path = write_pkl (pkl_uuid, interop, metadata, crypt);
        
        write_volindex ();
-       write_assetmap (pkl_uuid, boost::filesystem::file_size (pkl_path), metadata);
+       write_assetmap (pkl_uuid, boost::filesystem::file_size (pkl_path), interop, metadata);
 }
 
 std::string
-DCP::write_pkl (string pkl_uuid, XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
+DCP::write_pkl (string pkl_uuid, bool interop, XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
 {
        assert (!_cpls.empty ());
        
@@ -88,7 +89,13 @@ DCP::write_pkl (string pkl_uuid, XMLMetadata const & metadata, shared_ptr<Encryp
        p /= s.str();
 
        xmlpp::Document doc;
-       xmlpp::Element* pkl = doc.create_root_node("PackingList", "http://www.smpte-ra.org/schemas/429-8/2007/PKL");
+       xmlpp::Element* pkl;
+       if (interop) {
+               pkl = doc.create_root_node("PackingList", "http://www.digicine.com/PROTO-ASDCP-PKL-20040311#");
+       } else {
+               pkl = doc.create_root_node("PackingList", "http://www.smpte-ra.org/schemas/429-8/2007/PKL");
+       }
+       
        if (crypt) {
                pkl->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "dsig");
        }
@@ -106,12 +113,12 @@ DCP::write_pkl (string pkl_uuid, XMLMetadata const & metadata, shared_ptr<Encryp
                (*i)->write_to_pkl (asset_list);
        }
        
-       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+       for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
                (*i)->write_to_pkl (asset_list);
        }
 
        if (crypt) {
-               sign (pkl, crypt->certificates, crypt->signer_key);
+               sign (pkl, crypt->certificates, crypt->signer_key, interop);
        }
                
        doc.write_to_file_formatted (p.string (), "UTF-8");
@@ -132,14 +139,19 @@ DCP::write_volindex () const
 }
 
 void
-DCP::write_assetmap (string pkl_uuid, int pkl_length, XMLMetadata const & metadata) const
+DCP::write_assetmap (string pkl_uuid, int pkl_length, bool interop, XMLMetadata const & metadata) const
 {
        boost::filesystem::path p;
        p /= _directory;
        p /= "ASSETMAP.xml";
 
        xmlpp::Document doc;
-       xmlpp::Element* root = doc.create_root_node ("AssetMap", "http://www.smpte-ra.org/schemas/429-9/2007/AM");
+       xmlpp::Element* root;
+       if (interop) {
+               root = doc.create_root_node ("AssetMap", "http://www.digicine.com/PROTO-ASDCP-AM-20040311#");
+       } else {
+               root = doc.create_root_node ("AssetMap", "http://www.smpte-ra.org/schemas/429-9/2007/AM");
+       }
 
        root->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid());
        root->add_child("Creator")->add_child_text (metadata.creator);
@@ -158,7 +170,7 @@ DCP::write_assetmap (string pkl_uuid, int pkl_length, XMLMetadata const & metada
        chunk->add_child("Offset")->add_child_text ("0");
        chunk->add_child("Length")->add_child_text (lexical_cast<string> (pkl_length));
        
-       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+       for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
                (*i)->write_to_assetmap (asset_list);
        }
 
@@ -261,8 +273,8 @@ DCP::equals (DCP const & other, EqualityOptions opt, boost::function<void (NoteT
                return false;
        }
 
-       list<shared_ptr<const CPL> >::const_iterator a = _cpls.begin ();
-       list<shared_ptr<const CPL> >::const_iterator b = other._cpls.begin ();
+       list<shared_ptr<CPL> >::const_iterator a = _cpls.begin ();
+       list<shared_ptr<CPL> >::const_iterator b = other._cpls.begin ();
 
        while (a != _cpls.end ()) {
                if (!(*a)->equals (*b->get(), opt, note)) {
@@ -293,7 +305,7 @@ list<shared_ptr<const Asset> >
 DCP::assets () const
 {
        list<shared_ptr<const Asset> > a;
-       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+       for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
                list<shared_ptr<const Asset> > t = (*i)->assets ();
                a.merge (t);
        }
@@ -306,7 +318,7 @@ DCP::assets () const
 bool
 DCP::encrypted () const
 {
-       for (list<shared_ptr<const CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+       for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
                if ((*i)->encrypted ()) {
                        return true;
                }
@@ -314,3 +326,17 @@ DCP::encrypted () const
 
        return false;
 }
+
+void
+DCP::add_kdm (KDM const & kdm)
+{
+       list<KDMCipher> ciphers = kdm.ciphers ();
+       
+       for (list<shared_ptr<CPL> >::iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
+               for (list<KDMCipher>::iterator j = ciphers.begin(); j != ciphers.end(); ++j) {
+                       if (j->cpl_id() == (*i)->id()) {
+                               (*i)->add_kdm (kdm);
+                       }                               
+               }
+       }
+}