Use PKL types rather than file extensions.
authorCarl Hetherington <cth@carlh.net>
Fri, 17 Aug 2018 00:39:45 +0000 (01:39 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 17 Aug 2018 00:39:45 +0000 (01:39 +0100)
15 files changed:
src/atmos_asset.cc
src/atmos_asset.h
src/cpl.cc
src/cpl.h
src/dcp.cc
src/font_asset.cc
src/font_asset.h
src/interop_subtitle_asset.h
src/picture_asset.cc
src/picture_asset.h
src/pkl.cc
src/pkl.h
src/smpte_subtitle_asset.h
src/sound_asset.cc
src/sound_asset.h

index 1e4d9c18f7067f71c3cf1010114924cc385da796..171c8e8bcd701de9df7f21700c76d0619006106b 100644 (file)
@@ -83,7 +83,7 @@ AtmosAsset::AtmosAsset (boost::filesystem::path file)
 }
 
 string
-AtmosAsset::pkl_type (Standard) const
+AtmosAsset::static_pkl_type (Standard)
 {
        return "application/mxf";
 }
index 8e9190c88cef37572c21c659de9d286b74faa043..61f940557127d8ccbd57dc3c0f62ac4e6b4f2bf0 100644 (file)
@@ -51,7 +51,10 @@ public:
        boost::shared_ptr<AtmosAssetWriter> start_write (boost::filesystem::path file);
        boost::shared_ptr<AtmosAssetReader> start_read () const;
 
-       std::string pkl_type (Standard) const;
+       static std::string static_pkl_type (Standard);
+       std::string pkl_type (Standard s) const {
+               return static_pkl_type (s);
+       }
 
        Fraction edit_rate () const {
                return _edit_rate;
index aa61ec7afcc55052722369537b32262de61869cb..d23cd4aad156da45e78c7637b1b17ede93ee9881 100644 (file)
@@ -269,6 +269,12 @@ CPL::resolve_refs (list<shared_ptr<Asset> > assets)
 
 string
 CPL::pkl_type (Standard standard) const
+{
+       return static_pkl_type (standard);
+}
+
+string
+CPL::static_pkl_type (Standard standard)
 {
        switch (standard) {
        case INTEROP:
index 7e6dac6f9f9fda666dcba9fce9409293af8cd0a5..bcc1f06bd9ebb81bc4acc420ca7b2bac9c6c345f 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -140,6 +140,8 @@ public:
                return _standard;
        }
 
+       static std::string static_pkl_type (Standard standard);
+
 protected:
        /** @return type string for PKLs for this asset */
        std::string pkl_type (Standard standard) const;
index 523ec05387d6a11a6ce6d650fec3b78a6b06faa3..232c144304d831bd7ee7241ba210723893ce952f 100644 (file)
@@ -110,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")) {
@@ -143,10 +143,11 @@ 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;
+               } else {
+                       paths.insert (make_pair (remove_urn_uuid (i->string_child ("Id")), p));
                }
        }
 
@@ -157,11 +158,8 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
        _pkl.reset (new PKL (_directory / *pkl_path));
 
        /* 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;
@@ -174,7 +172,9 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
                        continue;
                }
 
-               if (boost::filesystem::extension (path) == ".xml") {
+               string const pkl_type = _pkl->type(i->first);
+
+               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());
@@ -198,7 +198,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)
@@ -240,7 +245,7 @@ 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)));
                }
        }
index f20ebfb4c23135e8f9c9fe8c484b892b66b518c0..f201d64973f8d0cc8a4bd687c6f67fd61a36cc4e 100644 (file)
@@ -48,7 +48,7 @@ FontAsset::FontAsset (string id, boost::filesystem::path file)
 }
 
 string
-FontAsset::pkl_type (Standard) const
+FontAsset::static_pkl_type (Standard)
 {
        return "application/ttf";
 }
index 5b431650b3172747d729e58a883cc668c0b0572f..1d41261957ef8fb12556f4d0d212eea4668a5b52 100644 (file)
@@ -47,8 +47,12 @@ class FontAsset : public Asset
 public:
        FontAsset (std::string id, boost::filesystem::path file);
 
+       static std::string static_pkl_type (Standard standard);
+
 private:
-       std::string pkl_type (Standard standard) const;
+       std::string pkl_type (Standard standard) const {
+               return static_pkl_type (standard);
+       }
 };
 
 }
index 72cd0022445e69b9fffa443df9ce6c30525b5233..703229a77cb788e243cfb73b9a58c2db348b151f 100644 (file)
@@ -105,10 +105,14 @@ public:
                return _movie_title;
        }
 
+       static std::string static_pkl_type (Standard) {
+               return "text/xml;asdcpKind=Subtitle";
+       }
+
 protected:
 
-       std::string pkl_type (Standard) const {
-               return "text/xml;asdcpKind=Subtitle";
+       std::string pkl_type (Standard s) const {
+               return static_pkl_type (s);
        }
 
 private:
index 7c4eb7b5802991ab1f1266c9048a6c03a41de18f..68af0896b245a77101fa10a6eb80fcf1e049eb0b 100644 (file)
@@ -200,7 +200,7 @@ PictureAsset::frame_buffer_equals (
 }
 
 string
-PictureAsset::pkl_type (Standard standard) const
+PictureAsset::static_pkl_type (Standard standard)
 {
        switch (standard) {
        case INTEROP:
@@ -211,3 +211,9 @@ PictureAsset::pkl_type (Standard standard) const
                DCP_ASSERT (false);
        }
 }
+
+string
+PictureAsset::pkl_type (Standard standard) const
+{
+       return static_pkl_type (standard);
+}
index 696776dad6a46b4d6ccf1182db33ee03a20c07d6..cc1be9f0360cfb234d9e980339ff042b3ecdf8d8 100644 (file)
@@ -101,6 +101,8 @@ public:
                return _intrinsic_duration;
        }
 
+       static std::string static_pkl_type (Standard standard);
+
 protected:
        friend class MonoPictureAssetWriter;
        friend class StereoPictureAssetWriter;
index a46ab3134c8ecb805959cbaef0298b31ede366ce..621cf465f3a3fe5004b7acc58a249711eae89dce 100644 (file)
@@ -38,6 +38,7 @@
 #include "dcp_assert.h"
 #include <libxml++/libxml++.h>
 #include <boost/foreach.hpp>
+#include <iostream>
 
 using std::string;
 using boost::shared_ptr;
@@ -125,3 +126,15 @@ PKL::hash (string id) const
 
        DCP_ASSERT (false);
 }
+
+string
+PKL::type (string id) const
+{
+       BOOST_FOREACH (shared_ptr<Asset> i, _asset_list) {
+               if (i->id() == id) {
+                       return i->type;
+               }
+       }
+
+       DCP_ASSERT (false);
+}
index d17b8fe15533a606266dde5ed7a8670113ccda11..aa78ae21b64ce0ca27a1c5b6db9ed7384f382925 100644 (file)
--- a/src/pkl.h
+++ b/src/pkl.h
@@ -61,6 +61,7 @@ public:
        }
 
        std::string hash (std::string id) const;
+       std::string type (std::string id) const;
 
        void add_asset (std::string id, boost::optional<std::string> annotation_text, std::string hash, int64_t size, std::string type);
        void write (boost::filesystem::path file, boost::shared_ptr<const CertificateChain> signer) const;
index 6631b31ef7e15ddcb2cffbcdf9946f28fc77434e..79a0024bc74b115d102db1dbab42966cd0d56d1c 100644 (file)
@@ -156,11 +156,14 @@ public:
        }
 
        static bool valid_mxf (boost::filesystem::path);
+       static std::string static_pkl_type (Standard) {
+               return "application/mxf";
+       }
 
 protected:
 
-       std::string pkl_type (Standard) const {
-               return "application/mxf";
+       std::string pkl_type (Standard s) const {
+               return static_pkl_type (s);
        }
 
 private:
index 641dc09a8a3b3679a9411909fb75ad5a2f420e33..1f1c2f4314b7589fdd551c812805dfb4961ddaec 100644 (file)
@@ -206,7 +206,7 @@ SoundAsset::start_read () const
 }
 
 string
-SoundAsset::pkl_type (Standard standard) const
+SoundAsset::static_pkl_type (Standard standard)
 {
        switch (standard) {
        case INTEROP:
index 774951523a38618fb5b1a638e13b6181ed95a38c..509ae559316bd800a9cde9da2e3f878bf54957e8 100644 (file)
@@ -86,11 +86,14 @@ public:
        }
 
        static bool valid_mxf (boost::filesystem::path);
+       static std::string static_pkl_type (Standard standard);
 
 private:
        friend class SoundAssetWriter;
 
-       std::string pkl_type (Standard standard) const;
+       std::string pkl_type (Standard standard) const {
+               return static_pkl_type (standard);
+       }
 
        Fraction _edit_rate;
        /** The total length of this content in video frames.  The amount of