Add comment.
[libdcp.git] / src / dcp.cc
index 67c56f99b8deaf7c3b7a93a2996b073812e65f4c..b6014941b823c03b3f37eb257e452a6473791342 100644 (file)
@@ -262,21 +262,50 @@ DCP::DCP (string directory)
                }
        }
 
+       if (cpl_file.empty ()) {
+               throw FileError ("no CPL file found", "");
+       }
+
+       if (pkl_file.empty ()) {
+               throw FileError ("no PKL file found", "");
+       }
+
+       if (asset_map_file.empty ()) {
+               throw FileError ("no AssetMap file found", "");
+       }
+
        /* Read the XML */
-       CPL cpl (cpl_file);
-       PKL pkl (pkl_file);
-       AssetMap asset_map (asset_map_file);
+       shared_ptr<CPL> cpl;
+       try {
+               cpl.reset (new CPL (cpl_file));
+       } catch (FileError& e) {
+               throw FileError ("could not load CPL file", cpl_file);
+       }
+
+       shared_ptr<PKL> pkl;
+       try {
+               pkl.reset (new PKL (pkl_file));
+       } catch (FileError& e) {
+               throw FileError ("could not load PKL file", pkl_file);
+       }
+
+       shared_ptr<AssetMap> asset_map;
+       try {
+               asset_map.reset (new AssetMap (asset_map_file));
+       } catch (FileError& e) {
+               throw FileError ("could not load AssetMap file", asset_map_file);
+       }
 
        /* Cross-check */
        /* XXX */
 
        /* Now cherry-pick the required bits into our own data structure */
        
-       _name = cpl.annotation_text;
-       _content_kind = cpl.content_kind;
+       _name = cpl->annotation_text;
+       _content_kind = cpl->content_kind;
+
+       shared_ptr<CPLAssetList> cpl_assets = cpl->reels.front()->asset_list;
 
-       shared_ptr<CPLAssetList> cpl_assets = cpl.reels.front()->asset_list;
-       
        /* XXX */
        _fps = cpl_assets->main_picture->frame_rate.numerator;
        _length = cpl_assets->main_picture->duration;
@@ -296,7 +325,7 @@ DCP::DCP (string directory)
                _assets.push_back (shared_ptr<SoundAsset> (
                                           new SoundAsset (
                                                   _directory,
-                                                  cpl_assets->main_picture->annotation_text,
+                                                  cpl_assets->main_sound->annotation_text,
                                                   _fps,
                                                   _length
                                                   )
@@ -305,11 +334,11 @@ DCP::DCP (string directory)
 }
 
 list<string>
-DCP::equals (DCP const & other, EqualityFlags flags) const
+DCP::equals (DCP const & other, EqualityOptions opt) const
 {
        list<string> notes;
        
-       if (flags & LIBDCP_METADATA) {
+       if (opt.flags & LIBDCP_METADATA) {
                if (_name != other._name) {
                        notes.push_back ("names differ");
                }
@@ -332,7 +361,7 @@ DCP::equals (DCP const & other, EqualityFlags flags) const
        list<shared_ptr<Asset> >::const_iterator b = other._assets.begin ();
        
        while (a != _assets.end ()) {
-               list<string> n = (*a)->equals (*b->get(), flags);
+               list<string> n = (*a)->equals (*b, opt);
                notes.merge (n);
                ++a;
                ++b;
@@ -340,3 +369,16 @@ DCP::equals (DCP const & other, EqualityFlags flags) const
 
        return notes;
 }
+
+shared_ptr<const PictureAsset>
+DCP::picture_asset () const
+{
+       for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
+               shared_ptr<PictureAsset> p = dynamic_pointer_cast<PictureAsset> (*i);
+               if (p) {
+                       return p;
+               }
+       }
+
+       return shared_ptr<const PictureAsset> ();
+}