Fix paths in OV DCP searches.
authorCarl Hetherington <cth@carlh.net>
Tue, 27 Aug 2013 21:27:02 +0000 (22:27 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 27 Aug 2013 21:27:02 +0000 (22:27 +0100)
src/cpl.cc
src/cpl.h
src/dcp.cc
src/dcp.h
src/types.h

index e22ddc71e1f1f8528c0fbe82540da8ef4ad0a08d..b45e5892e3cd9af34ee9530acbdc9f9da059488b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -37,8 +37,11 @@ using std::stringstream;
 using std::ofstream;
 using std::ostream;
 using std::list;
+using std::pair;
+using std::make_pair;
 using boost::shared_ptr;
 using boost::lexical_cast;
+using boost::optional;
 using namespace libdcp;
 
 CPL::CPL (string directory, string name, ContentKind content_kind, int length, int frames_per_second)
@@ -57,7 +60,7 @@ CPL::CPL (string directory, string name, ContentKind content_kind, int length, i
  *  @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, list<shared_ptr<const parse::AssetMap> > asset_maps, bool require_mxfs)
+CPL::CPL (string directory, string file, list<PathAssetMap> asset_maps, bool require_mxfs)
        : _directory (directory)
        , _content_kind (FEATURE)
        , _length (0)
@@ -104,10 +107,12 @@ CPL::CPL (string directory, string file, list<shared_ptr<const parse::AssetMap>
 
                if (!(*i)->asset_list->main_stereoscopic_picture && p->edit_rate == p->frame_rate) {
 
+                       pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
                        try {
                                picture.reset (new MonoPictureAsset (
-                                                      _directory,
-                                                      asset_from_id (asset_maps, p->id)->chunks.front()->path
+                                                      asset.first,
+                                                      asset.second->chunks.front()->path
                                                       )
                                        );
 
@@ -125,9 +130,11 @@ CPL::CPL (string directory, string file, list<shared_ptr<const parse::AssetMap>
                        
                } else {
                        try {
+                               pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
                                picture.reset (new StereoPictureAsset (
-                                                      _directory,
-                                                      asset_from_id (asset_maps, p->id)->chunks.front()->path,
+                                                      asset.first,
+                                                      asset.second->chunks.front()->path,
                                                       _fps,
                                                       p->duration
                                                       )
@@ -151,9 +158,11 @@ CPL::CPL (string directory, string file, list<shared_ptr<const parse::AssetMap>
                if ((*i)->asset_list->main_sound) {
                        
                        try {
+                               pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_sound->id);
+                       
                                sound.reset (new SoundAsset (
-                                                    _directory,
-                                                    asset_from_id (asset_maps, (*i)->asset_list->main_sound->id)->chunks.front()->path
+                                                    asset.first,
+                                                    asset.second->chunks.front()->path
                                                     )
                                        );
 
@@ -174,9 +183,11 @@ CPL::CPL (string directory, string file, list<shared_ptr<const parse::AssetMap>
 
                if ((*i)->asset_list->main_subtitle) {
                        
+                       pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id);
+
                        subtitle.reset (new SubtitleAsset (
-                                               _directory,
-                                               asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id)->chunks.front()->path
+                                               asset.first,
+                                               asset.second->chunks.front()->path
                                                )
                                );
 
@@ -509,15 +520,15 @@ CPL::add_kdm (KDM const & kdm)
        }
 }
 
-shared_ptr<parse::AssetMapAsset>
-CPL::asset_from_id (list<shared_ptr<const parse::AssetMap> > asset_maps, string id) const
+pair<string, shared_ptr<const parse::AssetMapAsset> >
+CPL::asset_from_id (list<PathAssetMap> 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);
+       for (list<PathAssetMap>::const_iterator i = asset_maps.begin(); i != asset_maps.end(); ++i) {
+               shared_ptr<parse::AssetMapAsset> a = i->second->asset_from_id (id);
                if (a) {
-                       return a;
+                       return make_pair (i->first, a);
                }
        }
 
-       return shared_ptr<parse::AssetMapAsset> ();
+       return make_pair ("", shared_ptr<const parse::AssetMapAsset> ());
 }
index 57d4373fdef6925ff99f3f8b1c14b29023f29f48..95bcd03fb8d9ee217ee0b32f8da97806bf851b4f 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -24,6 +24,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/function.hpp>
 #include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/optional.hpp>
 #include <libxml++/libxml++.h>
 #include "types.h"
 #include "certificates.h"
@@ -47,7 +48,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, std::list<boost::shared_ptr<const parse::AssetMap> > asset_maps, bool require_mxfs = true);
+       CPL (std::string directory, std::string file, std::list<PathAssetMap> asset_maps, bool require_mxfs = true);
 
        void add_reel (boost::shared_ptr<Reel> reel);
        
@@ -107,7 +108,7 @@ 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::pair<std::string, boost::shared_ptr<const parse::AssetMapAsset> > asset_from_id (std::list<PathAssetMap>, std::string id) const;
        
        std::string _directory;
        /** the name of the DCP */
index b9f434724ec4549e37b21c00050f83cd373fdf79..9bed7e938185eb0658d19b4d59912aa771d1e775 100644 (file)
@@ -55,6 +55,7 @@ using std::ofstream;
 using std::ostream;
 using std::copy;
 using std::back_inserter;
+using std::make_pair;
 using boost::shared_ptr;
 using boost::lexical_cast;
 using namespace libdcp;
@@ -271,7 +272,7 @@ DCP::read (bool require_mxfs)
        /* Cross-check */
        /* XXX */
 
-       _asset_maps.push_back (asset_map);
+       _asset_maps.push_back (make_pair (boost::filesystem::absolute (_directory).string(), 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_maps, require_mxfs)));
index 55d3d705c80a38b1b7dc3ccf093ea2aed8e20e35..8086f4de21177eeed67bd578e94a1449c8327ce6 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -150,7 +150,7 @@ private:
        /** our CPLs */
        std::list<boost::shared_ptr<CPL> > _cpls;
 
-       std::list<boost::shared_ptr<const parse::AssetMap> > _asset_maps;
+       std::list<PathAssetMap> _asset_maps;
 };
 
 }
index edabb9e233b9c9595e704fb5a7831bd003193bc9..1a74039fcf7d3e35dc3a0598fd0dd9d8bc429f0e 100644 (file)
 namespace libdcp
 {
 
+namespace parse {
+       class AssetMap;
+}
+
 /** Identifier for a sound channel */
 enum Channel {
        LEFT = 0,      ///< left
@@ -141,6 +145,8 @@ extern bool operator== (Color const & a, Color const & b);
 extern bool operator!= (Color const & a, Color const & b);
 extern std::ostream & operator<< (std::ostream & s, Color const & c);
 
+typedef std::pair<std::string, boost::shared_ptr<const parse::AssetMap> > PathAssetMap;
+
 }
 
 #endif