X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fdcp.cc;h=fa94c44d3d823aa05dd5777d706669f0fbd038fb;hb=bc09fbc79580f56c93e35de25230af18b30e0e1e;hp=27f3243eccb0c09022507f0990a65ace49e455f3;hpb=9a9d4e014c16be88d72914a9480343445bc785a5;p=libdcp.git diff --git a/src/dcp.cc b/src/dcp.cc index 27f3243e..fa94c44d 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -25,7 +25,9 @@ #include #include #include +#include #include +#include #include "dcp.h" #include "asset.h" #include "sound_asset.h" @@ -35,6 +37,7 @@ #include "exceptions.h" #include "cpl.h" #include "pkl.h" +#include "asset_map.h" using namespace std; using namespace boost; @@ -53,37 +56,25 @@ DCP::DCP (string directory, string name, ContentKind content_kind, int fps, int void DCP::add_sound_asset (vector const & files) { - filesystem::path p; - p /= _directory; - p /= "audio.mxf"; - _assets.push_back (shared_ptr (new SoundAsset (files, p.string(), &Progress, _fps, _length))); + _assets.push_back (shared_ptr (new SoundAsset (files, _directory, "audio.mxf", &Progress, _fps, _length))); } void DCP::add_sound_asset (sigc::slot get_path, int channels) { - filesystem::path p; - p /= _directory; - p /= "audio.mxf"; - _assets.push_back (shared_ptr (new SoundAsset (get_path, p.string(), &Progress, _fps, _length, channels))); + _assets.push_back (shared_ptr (new SoundAsset (get_path, _directory, "audio.mxf", &Progress, _fps, _length, channels))); } void DCP::add_picture_asset (vector const & files, int width, int height) { - filesystem::path p; - p /= _directory; - p /= "video.mxf"; - _assets.push_back (shared_ptr (new PictureAsset (files, p.string(), &Progress, _fps, _length, width, height))); + _assets.push_back (shared_ptr (new PictureAsset (files, _directory, "video.mxf", &Progress, _fps, _length, width, height))); } void DCP::add_picture_asset (sigc::slot get_path, int width, int height) { - filesystem::path p; - p /= _directory; - p /= "video.mxf"; - _assets.push_back (shared_ptr (new PictureAsset (get_path, p.string(), &Progress, _fps, _length, width, height))); + _assets.push_back (shared_ptr (new PictureAsset (get_path, _directory, "video.mxf", &Progress, _fps, _length, width, height))); } void @@ -251,29 +242,192 @@ DCP::DCP (string directory) string asset_map_file; for (filesystem::directory_iterator i = filesystem::directory_iterator(directory); i != filesystem::directory_iterator(); ++i) { + string const t = i->path().string (); - if (ends_with (t, "_cpl.xml")) { + + if (ends_with (t, ".mxf")) { + continue; + } + + xmlpp::DomParser* p = new xmlpp::DomParser; + + try { + p->parse_file (t); + } catch (std::exception& e) { + delete p; + continue; + } + + if (!p) { + delete p; + continue; + } + + string const root = p->get_document()->get_root_node()->get_name (); + delete p; + + if (root == "CompositionPlaylist") { if (cpl_file.empty ()) { cpl_file = t; } else { throw DCPReadError ("duplicate CPLs found"); } - } else if (ends_with (t, "_pkl.xml")) { + } else if (root == "PackingList") { if (pkl_file.empty ()) { pkl_file = t; } else { throw DCPReadError ("duplicate PKLs found"); } - } else if (ends_with (t, "ASSETMAP.xml")) { + } else if (root == "AssetMap") { if (asset_map_file.empty ()) { asset_map_file = t; } else { throw DCPReadError ("duplicate AssetMaps found"); } + asset_map_file = t; } } - CPL cpl (cpl_file); - PKL pkl (pkl_file); + 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 */ + shared_ptr cpl; + try { + cpl.reset (new CPL (cpl_file)); + } catch (FileError& e) { + throw FileError ("could not load CPL file", cpl_file); + } + + shared_ptr pkl; + try { + pkl.reset (new PKL (pkl_file)); + } catch (FileError& e) { + throw FileError ("could not load PKL file", pkl_file); + } + + shared_ptr 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; + + shared_ptr cpl_assets = cpl->reels.front()->asset_list; + + /* XXX */ + _fps = cpl_assets->main_picture->frame_rate.numerator; + _length = cpl_assets->main_picture->duration; + + string n = cpl_assets->main_picture->annotation_text; + if (n.empty ()) { + n = pkl->asset_from_id(cpl_assets->main_picture->id)->original_file_name; + } + + _assets.push_back (shared_ptr ( + new PictureAsset ( + _directory, + n, + _fps, + _length, + cpl_assets->main_picture->screen_aspect_ratio.numerator, + cpl_assets->main_picture->screen_aspect_ratio.denominator + ) + )); + + n = cpl_assets->main_sound->annotation_text; + if (n.empty ()) { + n = pkl->asset_from_id(cpl_assets->main_sound->id)->original_file_name; + } + + if (cpl_assets->main_sound) { + _assets.push_back (shared_ptr ( + new SoundAsset ( + _directory, + n, + _fps, + _length + ) + )); + } +} + +list +DCP::equals (DCP const & other, EqualityOptions opt) const +{ + list notes; + + if (opt.flags & LIBDCP_METADATA) { + if (_name != other._name) { + notes.push_back ("names differ"); + } + if (_content_kind != other._content_kind) { + notes.push_back ("content kinds differ"); + } + if (_fps != other._fps) { + notes.push_back ("frames per second differ"); + } + if (_length != other._length) { + notes.push_back ("lengths differ"); + } + } + + if (_assets.size() != other._assets.size()) { + notes.push_back ("asset counts differ"); + } + + list >::const_iterator a = _assets.begin (); + list >::const_iterator b = other._assets.begin (); + + while (a != _assets.end ()) { + list n = (*a)->equals (*b, opt); + notes.merge (n); + ++a; + ++b; + } + + return notes; +} + +shared_ptr +DCP::picture_asset () const +{ + for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { + shared_ptr p = dynamic_pointer_cast (*i); + if (p) { + return p; + } + } + + return shared_ptr (); } +shared_ptr +DCP::sound_asset () const +{ + for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { + shared_ptr s = dynamic_pointer_cast (*i); + if (s) { + return s; + } + } + + return shared_ptr (); +}