Put xmlns:dsig on Signer and Signature rather than on the whole
[libdcp.git] / src / dcp.cc
index 8aff6c407f512f94faa56ffaee33a69dfc3bb651..e56547e3dc2e7d265161bbf03abb2fbe1883acce 100644 (file)
@@ -38,6 +38,7 @@
 #include "raw_convert.h"
 #include "dcp.h"
 #include "sound_asset.h"
+#include "atmos_asset.h"
 #include "picture_asset.h"
 #include "interop_subtitle_asset.h"
 #include "smpte_subtitle_asset.h"
 
 using std::string;
 using std::list;
+using std::vector;
 using std::cout;
 using std::make_pair;
 using std::map;
-using std::cout;
 using std::cerr;
 using std::exception;
 using boost::shared_ptr;
@@ -80,7 +81,7 @@ static string const assetmap_interop_ns = "http://www.digicine.com/PROTO-ASDCP-A
 static string const assetmap_smpte_ns   = "http://www.smpte-ra.org/schemas/429-9/2007/AM";
 static string const pkl_interop_ns      = "http://www.digicine.com/PROTO-ASDCP-PKL-20040311#";
 static string const pkl_smpte_ns        = "http://www.smpte-ra.org/schemas/429-8/2007/PKL";
-static string const volindex_interop_ns = "http://www.digicine.com/PROTO-ASDCP-AM-20040311#";
+static string const volindex_interop_ns = "http://www.digicine.com/PROTO-ASDCP-VL-20040311#";
 static string const volindex_smpte_ns   = "http://www.smpte-ra.org/schemas/429-9/2007/AM";
 
 DCP::DCP (boost::filesystem::path directory)
@@ -168,7 +169,7 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                                p->parse_file (path.string());
                        } catch (std::exception& e) {
                                delete p;
-                               continue;
+                               throw DCPReadError(String::compose("XML error in %1", path.string()), e.what());
                        }
 
                        string const root = p->get_document()->get_root_node()->get_name ();
@@ -222,8 +223,11 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                                case ASDCP::ESS_TIMED_TEXT:
                                        other_assets.push_back (shared_ptr<SMPTESubtitleAsset> (new SMPTESubtitleAsset (path)));
                                        break;
+                               case ASDCP::ESS_DCDATA_DOLBY_ATMOS:
+                                       other_assets.push_back (shared_ptr<AtmosAsset> (new AtmosAsset (path)));
+                                       break;
                                default:
-                                       throw DCPReadError ("Unknown MXF essence type");
+                                       throw DCPReadError (String::compose ("Unknown MXF essence type %1 in %2", int(type), path.string()));
                        }
                } else if (boost::filesystem::extension (path) == ".ttf") {
                        other_assets.push_back (shared_ptr<FontAsset> (new FontAsset (i->first, path)));
@@ -317,16 +321,8 @@ DCP::write_pkl (string file, Standard standard, string pkl_uuid, XMLMetadata met
                pkl = doc.create_root_node("PackingList", pkl_smpte_ns);
        }
 
-       if (signer) {
-               pkl->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "dsig");
-       }
-
        pkl->add_child("Id")->add_child_text ("urn:uuid:" + pkl_uuid);
-
-       /* XXX: this is a bit of a hack */
-       DCP_ASSERT (cpls().size() > 0);
-       pkl->add_child("AnnotationText")->add_child_text (cpls().front()->annotation_text ());
-
+       pkl->add_child("AnnotationText")->add_child_text (metadata.annotation_text);
        pkl->add_child("IssueDate")->add_child_text (metadata.issue_date);
        pkl->add_child("Issuer")->add_child_text (metadata.issuer);
        pkl->add_child("Creator")->add_child_text (metadata.creator);
@@ -411,7 +407,7 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, boost::filesystem::path
        }
 
        root->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid());
-       root->add_child("AnnotationText")->add_child_text ("Created by " + metadata.creator);
+       root->add_child("AnnotationText")->add_child_text (metadata.annotation_text);
 
        switch (standard) {
        case INTEROP:
@@ -466,15 +462,13 @@ DCP::write_xml (
        BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
                NameFormat::Map values;
                values['t'] = "cpl";
-               values['i'] = i->id();
-               i->write_xml (_directory / (name_format.get(values) + ".xml"), standard, signer);
+               i->write_xml (_directory / (name_format.get(values, "_" + i->id() + ".xml")), standard, signer);
        }
 
        string const pkl_uuid = make_uuid ();
        NameFormat::Map values;
        values['t'] = "pkl";
-       values['i'] = pkl_uuid;
-       boost::filesystem::path const pkl_path = write_pkl (name_format.get(values) + ".xml", standard, pkl_uuid, metadata, signer);
+       boost::filesystem::path const pkl_path = write_pkl (name_format.get(values, "_" + pkl_uuid + ".xml"), standard, pkl_uuid, metadata, signer);
 
        write_volindex (standard);
        write_assetmap (standard, pkl_uuid, pkl_path, metadata);
@@ -486,14 +480,20 @@ DCP::cpls () const
        return _cpls;
 }
 
-/** @return All assets (including CPLs) */
+/** @param ignore_unresolved true to silently ignore unresolved assets, otherwise
+ *  an exception is thrown if they are found.
+ *  @return All assets (including CPLs).
+ */
 list<shared_ptr<Asset> >
-DCP::assets () const
+DCP::assets (bool ignore_unresolved) const
 {
        list<shared_ptr<Asset> > assets;
        BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
                assets.push_back (i);
                BOOST_FOREACH (shared_ptr<const ReelAsset> j, i->reel_assets ()) {
+                       if (ignore_unresolved && !j->asset_ref().resolved()) {
+                               continue;
+                       }
                        shared_ptr<Asset> o = j->asset_ref().asset ();
                        assets.push_back (o);
                        /* More Interop special-casing */
@@ -506,3 +506,16 @@ DCP::assets () const
 
        return assets;
 }
+
+/** Given a list of files that make up 1 or more DCPs, return the DCP directories */
+vector<boost::filesystem::path>
+DCP::directories_from_files (vector<boost::filesystem::path> files)
+{
+       vector<boost::filesystem::path> d;
+       BOOST_FOREACH (boost::filesystem::path i, files) {
+               if (i.filename() == "ASSETMAP" || i.filename() == "ASSETMAP.xml") {
+                       d.push_back (i.parent_path ());
+               }
+       }
+       return d;
+}