Basics of OV/supplemental support when reading.
authorCarl Hetherington <cth@carlh.net>
Tue, 27 Aug 2013 19:13:53 +0000 (20:13 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 27 Aug 2013 19:13:53 +0000 (20:13 +0100)
src/cpl.cc
src/cpl.h
src/dcp.cc
src/dcp.h

index 8d8f6a00df7e11e74b6cd572af353a3df6d8186a..e22ddc71e1f1f8528c0fbe82540da8ef4ad0a08d 100644 (file)
@@ -54,10 +54,10 @@ CPL::CPL (string directory, string name, ContentKind content_kind, int length, i
 /** Construct a CPL object from a XML file.
  *  @param directory The directory containing this CPL's DCP.
  *  @param file The CPL XML filename.
- *  @param asset_map The corresponding asset map.
+ *  @param asset_maps AssetMaps to look for assets in.
  *  @param require_mxfs true to throw an exception if a required MXF file does not exist.
  */
-CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMap> asset_map, bool require_mxfs)
+CPL::CPL (string directory, string file, list<shared_ptr<const parse::AssetMap> > asset_maps, bool require_mxfs)
        : _directory (directory)
        , _content_kind (FEATURE)
        , _length (0)
@@ -79,7 +79,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa
        /* Trim urn:uuid: off the front */
        _id = cpl->id.substr (9);
 
-       for (list<shared_ptr<libdcp::parse::Reel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
+       for (list<shared_ptr<parse::Reel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
 
                shared_ptr<parse::Picture> p;
 
@@ -107,7 +107,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa
                        try {
                                picture.reset (new MonoPictureAsset (
                                                       _directory,
-                                                      asset_map->asset_from_id (p->id)->chunks.front()->path
+                                                      asset_from_id (asset_maps, p->id)->chunks.front()->path
                                                       )
                                        );
 
@@ -127,7 +127,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa
                        try {
                                picture.reset (new StereoPictureAsset (
                                                       _directory,
-                                                      asset_map->asset_from_id (p->id)->chunks.front()->path,
+                                                      asset_from_id (asset_maps, p->id)->chunks.front()->path,
                                                       _fps,
                                                       p->duration
                                                       )
@@ -153,7 +153,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa
                        try {
                                sound.reset (new SoundAsset (
                                                     _directory,
-                                                    asset_map->asset_from_id ((*i)->asset_list->main_sound->id)->chunks.front()->path
+                                                    asset_from_id (asset_maps, (*i)->asset_list->main_sound->id)->chunks.front()->path
                                                     )
                                        );
 
@@ -176,7 +176,7 @@ CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMa
                        
                        subtitle.reset (new SubtitleAsset (
                                                _directory,
-                                               asset_map->asset_from_id ((*i)->asset_list->main_subtitle->id)->chunks.front()->path
+                                               asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id)->chunks.front()->path
                                                )
                                );
 
@@ -508,3 +508,16 @@ CPL::add_kdm (KDM const & kdm)
                (*i)->add_kdm (kdm);
        }
 }
+
+shared_ptr<parse::AssetMapAsset>
+CPL::asset_from_id (list<shared_ptr<const parse::AssetMap> > asset_maps, string id) const
+{
+       for (list<shared_ptr<const parse::AssetMap> >::const_iterator i = asset_maps.begin(); i != asset_maps.end(); ++i) {
+               shared_ptr<parse::AssetMapAsset> a = (*i)->asset_from_id (id);
+               if (a) {
+                       return a;
+               }
+       }
+
+       return shared_ptr<parse::AssetMapAsset> ();
+}
index 94ab877af885f46ef57fc445167caaa583316f5b..57d4373fdef6925ff99f3f8b1c14b29023f29f48 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -32,6 +32,7 @@ namespace libdcp {
 
 namespace parse {
        class AssetMap;
+       class AssetMapAsset;
 }
        
 class Asset;
@@ -46,7 +47,7 @@ class CPL
 {
 public:
        CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
-       CPL (std::string directory, std::string file, boost::shared_ptr<const parse::AssetMap> asset_map, bool require_mxfs = true);
+       CPL (std::string directory, std::string file, std::list<boost::shared_ptr<const parse::AssetMap> > asset_maps, bool require_mxfs = true);
 
        void add_reel (boost::shared_ptr<Reel> reel);
        
@@ -106,6 +107,8 @@ public:
        void add_kdm (KDM const &);
        
 private:
+       boost::shared_ptr<parse::AssetMapAsset> asset_from_id (std::list<boost::shared_ptr<const parse::AssetMap> > asset_maps, std::string id) const;
+       
        std::string _directory;
        /** the name of the DCP */
        std::string _name;
index a69a5198efcecd24bbec8831e783d4daf1f274b3..b9f434724ec4549e37b21c00050f83cd373fdf79 100644 (file)
@@ -53,6 +53,8 @@ using std::list;
 using std::stringstream;
 using std::ofstream;
 using std::ostream;
+using std::copy;
+using std::back_inserter;
 using boost::shared_ptr;
 using boost::lexical_cast;
 using namespace libdcp;
@@ -269,8 +271,10 @@ DCP::read (bool require_mxfs)
        /* Cross-check */
        /* XXX */
 
+       _asset_maps.push_back (asset_map);
+
        for (list<string>::iterator i = files.cpls.begin(); i != files.cpls.end(); ++i) {
-               _cpls.push_back (shared_ptr<CPL> (new CPL (_directory, *i, asset_map, require_mxfs)));
+               _cpls.push_back (shared_ptr<CPL> (new CPL (_directory, *i, _asset_maps, require_mxfs)));
        }
 }
 
@@ -349,3 +353,9 @@ DCP::add_kdm (KDM const & kdm)
                }
        }
 }
+
+void
+DCP::add_assets_from (DCP const & ov)
+{
+       copy (ov._asset_maps.begin(), ov._asset_maps.end(), back_inserter (_asset_maps));
+}
index d6237e8af4ae14eff89d80306b4de8b621d0546d..55d3d705c80a38b1b7dc3ccf093ea2aed8e20e35 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -50,6 +50,10 @@ class XMLMetadata;
 class Encryption;
 class KDM;
 
+namespace parse {
+       class AssetMap;
+}
+
 /** @class DCP
  *  @brief A class to create or read a DCP.
  */
@@ -97,6 +101,16 @@ public:
                return _cpls;
        }
 
+       /** Add another DCP as a source of assets for this DCP.  This should be called before
+        *  ::read() on the DCP that needs the extra assets.  For example
+        *
+        *  DCP original_version ("my_dcp_OV");
+        *  DCP supplemental ("my_dcp_VF");
+        *  supplemental.add_assets_from (original_version);
+        *  supplemental.read ();
+        */
+       void add_assets_from (libdcp::DCP const &);
+
        bool encrypted () const;
 
        void add_kdm (KDM const &);
@@ -122,7 +136,7 @@ private:
         */
        void write_assetmap (std::string pkl_uuid, int pkl_length, bool, XMLMetadata const &) const;
 
-       /** @return Assets in all this CPLs in this DCP */
+       /** @return Assets in all the CPLs in this DCP */
        std::list<boost::shared_ptr<const Asset> > assets () const;
 
        struct Files {
@@ -135,6 +149,8 @@ private:
        std::string _directory;
        /** our CPLs */
        std::list<boost::shared_ptr<CPL> > _cpls;
+
+       std::list<boost::shared_ptr<const parse::AssetMap> > _asset_maps;
 };
 
 }