Take thumbprint rather than a full dcp::Certificate for trusted devices.
[libdcp.git] / src / dcp.cc
index cb5677f9b1b06cd1d25b35c8d79e2443c2ee2445..08febadcbad8a7a6b68fe7c2233a75961c8453d5 100644 (file)
@@ -81,9 +81,6 @@ using namespace dcp;
 
 static string const assetmap_interop_ns = "http://www.digicine.com/PROTO-ASDCP-AM-20040311#";
 static string const assetmap_smpte_ns   = "http://www.smpte-ra.org/schemas/429-9/2007/AM";
-/* XXX: these can be removed when PKL is all in pkl.cc */
-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-VL-20040311#";
 static string const volindex_smpte_ns   = "http://www.smpte-ra.org/schemas/429-9/2007/AM";
 
@@ -113,7 +110,7 @@ survivable_error (bool keep_going, dcp::DCP::ReadErrors* errors, T const & e)
 void
 DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mxf_type)
 {
-       /* Read the ASSETMAP */
+       /* Read the ASSETMAP and PKL */
 
        boost::filesystem::path asset_map_file;
        if (boost::filesystem::exists (_directory / "ASSETMAP")) {
@@ -137,7 +134,7 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
 
        list<shared_ptr<cxml::Node> > asset_nodes = asset_map.node_child("AssetList")->node_children ("Asset");
        map<string, boost::filesystem::path> paths;
-       optional<boost::filesystem::path> pkl_path;
+       list<boost::filesystem::path> pkl_paths;
        BOOST_FOREACH (shared_ptr<cxml::Node> i, asset_nodes) {
                if (i->node_child("ChunkList")->node_children("Chunk").size() != 1) {
                        boost::throw_exception (XMLError ("unsupported asset chunk count"));
@@ -146,25 +143,38 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                if (starts_with (p, "file://")) {
                        p = p.substr (7);
                }
-               paths.insert (make_pair (remove_urn_uuid (i->string_child ("Id")), p));
-               optional<string> pkl_bool = i->optional_string_child("PackingList");
-               if (pkl_bool && *pkl_bool == "true") {
-                       pkl_path = p;
+               switch (*_standard) {
+               case INTEROP:
+                       if (i->optional_node_child("PackingList")) {
+                               pkl_paths.push_back (p);
+                       } else {
+                               paths.insert (make_pair (remove_urn_uuid (i->string_child ("Id")), p));
+                       }
+                       break;
+               case SMPTE:
+               {
+                       optional<string> pkl_bool = i->optional_string_child("PackingList");
+                       if (pkl_bool && *pkl_bool == "true") {
+                               pkl_paths.push_back (p);
+                       } else {
+                               paths.insert (make_pair (remove_urn_uuid (i->string_child ("Id")), p));
+                       }
+                       break;
+               }
                }
        }
 
-       if (!pkl_path) {
-               boost::throw_exception (XMLError ("No packing list found in asset map"));
+       if (pkl_paths.empty()) {
+               boost::throw_exception (XMLError ("No packing lists found in asset map"));
        }
 
-       _pkl.reset (new PKL (_directory / *pkl_path));
+       BOOST_FOREACH (boost::filesystem::path i, pkl_paths) {
+               _pkls.push_back (shared_ptr<PKL>(new PKL(_directory / i)));
+       }
 
        /* Read all the assets from the asset map */
-       /* XXX: I think we should be looking at the PKL here to decide type, not
-          the extension of the file.
-       */
 
-       /* Make a list of non-CPL assets so that we can resolve the references
+       /* Make a list of non-CPL/PKL assets so that we can resolve the references
           from the CPLs.
        */
        list<shared_ptr<Asset> > other_assets;
@@ -177,7 +187,17 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                        continue;
                }
 
-               if (boost::filesystem::extension (path) == ".xml") {
+               optional<string> pkl_type;
+               BOOST_FOREACH (shared_ptr<PKL> j, _pkls) {
+                       pkl_type = j->type(i->first);
+                       if (pkl_type) {
+                               break;
+                       }
+               }
+
+               DCP_ASSERT (pkl_type);
+
+               if (*pkl_type == CPL::static_pkl_type(*_standard) || *pkl_type == InteropSubtitleAsset::static_pkl_type(*_standard)) {
                        xmlpp::DomParser* p = new xmlpp::DomParser;
                        try {
                                p->parse_file (path.string());
@@ -201,7 +221,12 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                                }
                                other_assets.push_back (shared_ptr<InteropSubtitleAsset> (new InteropSubtitleAsset (path)));
                        }
-               } else if (boost::filesystem::extension (path) == ".mxf") {
+               } else if (
+                       *pkl_type == PictureAsset::static_pkl_type(*_standard) ||
+                       *pkl_type == SoundAsset::static_pkl_type(*_standard) ||
+                       *pkl_type == AtmosAsset::static_pkl_type(*_standard) ||
+                       *pkl_type == SMPTESubtitleAsset::static_pkl_type(*_standard)
+                       ) {
 
                        /* XXX: asdcplib does not appear to support discovery of read MXFs standard
                           (Interop / SMPTE)
@@ -243,8 +268,12 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                                default:
                                        throw DCPReadError (String::compose ("Unknown MXF essence type %1 in %2", int(type), path.string()));
                        }
-               } else if (boost::filesystem::extension (path) == ".ttf") {
+               } else if (*pkl_type == FontAsset::static_pkl_type(*_standard)) {
                        other_assets.push_back (shared_ptr<FontAsset> (new FontAsset (i->first, path)));
+               } else if (*pkl_type == "image/png") {
+                       /* It's an Interop PNG subtitle; let it go */
+               } else {
+                       throw DCPReadError (String::compose("Unknown asset type %1 in PKL", *pkl_type));
                }
        }
 
@@ -449,20 +478,25 @@ DCP::write_xml (
                i->write_xml (_directory / (name_format.get(values, "_" + i->id() + ".xml")), standard, signer);
        }
 
-       if (!_pkl) {
-               _pkl.reset (new PKL (standard, metadata.annotation_text, metadata.issue_date, metadata.issuer, metadata.creator));
+       shared_ptr<PKL> pkl;
+
+       if (_pkls.empty()) {
+               pkl.reset (new PKL (standard, metadata.annotation_text, metadata.issue_date, metadata.issuer, metadata.creator));
+               _pkls.push_back (pkl);
                BOOST_FOREACH (shared_ptr<Asset> i, assets ()) {
-                       i->add_to_pkl (_pkl, _directory);
+                       i->add_to_pkl (pkl, _directory);
                }
+        } else {
+               pkl = _pkls.front ();
        }
 
        NameFormat::Map values;
        values['t'] = "pkl";
-       boost::filesystem::path pkl_path = _directory / name_format.get(values, "_" + _pkl->id() + ".xml");
-       _pkl->write (pkl_path, signer);
+       boost::filesystem::path pkl_path = _directory / name_format.get(values, "_" + pkl->id() + ".xml");
+       pkl->write (pkl_path, signer);
 
        write_volindex (standard);
-       write_assetmap (standard, _pkl->id(), pkl_path, metadata);
+       write_assetmap (standard, pkl->id(), pkl_path, metadata);
 }
 
 list<shared_ptr<CPL> >