From 5c29a3586ea262abcc8829bf267d38d8a5a84d9b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 9 Sep 2012 12:48:47 +0100 Subject: Somewhat hacky rearrangement to support multiple CPLs per DCP. --- src/asset.h | 4 + src/dcp.cc | 303 ++++++++++++++++++++++++++++++++++++++++-------------------- src/dcp.h | 151 ++++++++++++++++-------------- src/reel.cc | 32 ------- src/reel.h | 2 - src/util.cc | 2 +- 6 files changed, 292 insertions(+), 202 deletions(-) (limited to 'src') diff --git a/src/asset.h b/src/asset.h index 0c8df0c8..eab24d28 100644 --- a/src/asset.h +++ b/src/asset.h @@ -64,6 +64,10 @@ public: */ void write_to_assetmap (std::ostream& s) const; + std::string uuid () const { + return _uuid; + } + virtual std::list equals (boost::shared_ptr other, EqualityOptions opt) const = 0; protected: diff --git a/src/dcp.cc b/src/dcp.cc index 907f7dd5..8de1ddd9 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -45,77 +45,31 @@ using namespace std; using namespace boost; using namespace libdcp; -DCP::DCP (string directory, string name, ContentKind content_kind, int fps, int length) +DCP::DCP (string directory) : _directory (directory) - , _name (name) - , _content_kind (content_kind) - , _fps (fps) - , _length (length) { filesystem::create_directories (directory); } -void -DCP::add_reel (shared_ptr reel) -{ - _reels.push_back (reel); -} - void DCP::write_xml () const { - string cpl_uuid = make_uuid (); - string cpl_path = write_cpl (cpl_uuid); - int cpl_length = filesystem::file_size (cpl_path); - string cpl_digest = make_digest (cpl_path, 0); + for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { + (*i)->write_xml (); + } string pkl_uuid = make_uuid (); - string pkl_path = write_pkl (pkl_uuid, cpl_uuid, cpl_digest, cpl_length); + string pkl_path = write_pkl (pkl_uuid); write_volindex (); - write_assetmap (cpl_uuid, cpl_length, pkl_uuid, filesystem::file_size (pkl_path)); -} - -string -DCP::write_cpl (string cpl_uuid) const -{ - filesystem::path p; - p /= _directory; - stringstream s; - s << cpl_uuid << "_cpl.xml"; - p /= s.str(); - ofstream cpl (p.string().c_str()); - - cpl << "\n" - << "\n" - << " urn:uuid:" << cpl_uuid << "\n" - << " " << _name << "\n" - << " " << Metadata::instance()->issue_date << "\n" - << " " << Metadata::instance()->creator << "\n" - << " " << _name << "\n" - << " " << content_kind_to_string (_content_kind) << "\n" - << " \n" - << " urn:uri:" << cpl_uuid << "_" << Metadata::instance()->issue_date << "\n" - << " " << cpl_uuid << "_" << Metadata::instance()->issue_date << "\n" - << " \n" - << " \n" - << " \n"; - - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - (*i)->write_to_cpl (cpl); - } - - cpl << " \n" - << " \n" - << " \n" - << "\n"; - - return p.string (); + write_assetmap (pkl_uuid, filesystem::file_size (pkl_path)); } std::string -DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_length) const +DCP::write_pkl (string pkl_uuid) const { + assert (!_cpls.empty ()); + filesystem::path p; p /= _directory; stringstream s; @@ -126,22 +80,21 @@ DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_len pkl << "\n" << "\n" << " urn:uuid:" << pkl_uuid << "\n" - << " " << _name << "\n" + /* XXX: this is a bit of a hack */ + << " " << _cpls.front()->name() << "\n" << " " << Metadata::instance()->issue_date << "\n" << " " << Metadata::instance()->issuer << "\n" << " " << Metadata::instance()->creator << "\n" << " \n"; - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + list > a = assets (); + for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { (*i)->write_to_pkl (pkl); } - pkl << " \n" - << " urn:uuid:" << cpl_uuid << "\n" - << " " << cpl_digest << "\n" - << " " << cpl_length << "\n" - << " text/xml\n" - << " \n"; + for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { + (*i)->write_to_pkl (pkl); + } pkl << " \n" << "\n"; @@ -164,7 +117,7 @@ DCP::write_volindex () const } void -DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_length) const +DCP::write_assetmap (string pkl_uuid, int pkl_length) const { filesystem::path p; p /= _directory; @@ -192,20 +145,13 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l << " \n" << " \n" << " \n"; - - am << " \n" - << " urn:uuid:" << cpl_uuid << "\n" - << " \n" - << " \n" - << " " << cpl_uuid << "_cpl.xml\n" - << " 1\n" - << " 0\n" - << " " << cpl_length << "\n" - << " \n" - << " \n" - << " \n"; - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { + (*i)->write_to_assetmap (am); + } + + list > a = assets (); + for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { (*i)->write_to_assetmap (am); } @@ -214,8 +160,8 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l } -DCP::DCP (string directory, bool require_mxfs) - : _directory (directory) +void +DCP::read (bool require_mxfs) { Files files; @@ -263,11 +209,7 @@ DCP::DCP (string directory, bool require_mxfs) delete p; if (root == "CompositionPlaylist") { - if (files.cpl.empty ()) { - files.cpl = t.string(); - } else { - throw DCPReadError ("duplicate CPLs found"); - } + files.cpls.push_back (t.string()); } else if (root == "PackingList") { if (files.pkl.empty ()) { files.pkl = t.string(); @@ -279,22 +221,14 @@ DCP::DCP (string directory, bool require_mxfs) } } - if (files.cpl.empty ()) { - throw FileError ("no CPL file found", ""); + if (files.cpls.empty ()) { + throw FileError ("no CPL files found", ""); } if (files.pkl.empty ()) { throw FileError ("no PKL file found", ""); } - /* Read the XML */ - shared_ptr cpl; - try { - cpl.reset (new CPLFile (files.cpl)); - } catch (FileError& e) { - throw FileError ("could not load CPL file", files.cpl); - } - shared_ptr pkl; try { pkl.reset (new PKLFile (files.pkl)); @@ -305,12 +239,91 @@ DCP::DCP (string directory, bool require_mxfs) /* Cross-check */ /* XXX */ + for (list::iterator i = files.cpls.begin(); i != files.cpls.end(); ++i) { + _cpls.push_back (shared_ptr (new CPL (_directory, *i, asset_map, require_mxfs))); + } + +} + +list +DCP::equals (DCP const & other, EqualityOptions opt) const +{ + list notes; + + if (_cpls.size() != other._cpls.size()) { + notes.push_back ("CPL counts differ"); + } + + list >::const_iterator a = _cpls.begin (); + list >::const_iterator b = other._cpls.begin (); + + while (a != _cpls.end ()) { + list n = (*a)->equals (*b->get(), opt); + notes.merge (n); + ++a; + ++b; + } + + return notes; +} + + +void +DCP::add_cpl (shared_ptr cpl) +{ + _cpls.push_back (cpl); +} + +class AssetComparator +{ +public: + bool operator() (shared_ptr a, shared_ptr b) { + return a->uuid() < b->uuid(); + } +}; + +list > +DCP::assets () const +{ + list > a; + for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { + list > t = (*i)->assets (); + a.merge (t); + } + + a.sort (); + a.unique (); + return a; +} + +CPL::CPL (string directory, string name, ContentKind content_kind, int length, int frames_per_second) + : _directory (directory) + , _name (name) + , _content_kind (content_kind) + , _length (length) + , _fps (frames_per_second) +{ + _uuid = make_uuid (); +} + +CPL::CPL (string directory, string file, shared_ptr asset_map, bool require_mxfs) + : _directory (directory) + , _content_kind (FEATURE) + , _length (0) + , _fps (0) +{ + /* Read the XML */ + shared_ptr cpl; + try { + cpl.reset (new CPLFile (file)); + } catch (FileError& e) { + throw FileError ("could not load CPL file", file); + } + /* Now cherry-pick the required bits into our own data structure */ _name = cpl->annotation_text; _content_kind = cpl->content_kind; - _length = 0; - _fps = 0; for (list >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) { @@ -322,7 +335,6 @@ DCP::DCP (string directory, bool require_mxfs) p = (*i)->asset_list->main_stereoscopic_picture; } - assert (_fps == 0 || _fps == p->edit_rate.numerator); _fps = p->edit_rate.numerator; _length += p->duration; @@ -397,8 +409,102 @@ DCP::DCP (string directory, bool require_mxfs) } } +void +CPL::add_reel (shared_ptr reel) +{ + _reels.push_back (reel); +} + +void +CPL::write_xml () const +{ + filesystem::path p; + p /= _directory; + stringstream s; + s << _uuid << "_cpl.xml"; + p /= s.str(); + ofstream os (p.string().c_str()); + + os << "\n" + << "\n" + << " urn:uuid:" << _uuid << "\n" + << " " << _name << "\n" + << " " << Metadata::instance()->issue_date << "\n" + << " " << Metadata::instance()->creator << "\n" + << " " << _name << "\n" + << " " << content_kind_to_string (_content_kind) << "\n" + << " \n" + << " urn:uri:" << _uuid << "_" << Metadata::instance()->issue_date << "\n" + << " " << _uuid << "_" << Metadata::instance()->issue_date << "\n" + << " \n" + << " \n" + << " \n"; + + for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + (*i)->write_to_cpl (os); + } + + os << " \n" + << " \n" + << " \n" + << "\n"; + + os.close (); + + _digest = make_digest (p.string (), 0); + _length = filesystem::file_size (p.string ()); +} + +void +CPL::write_to_pkl (ostream& s) const +{ + s << " \n" + << " urn:uuid:" << _uuid << "\n" + << " " << _digest << "\n" + << " " << _length << "\n" + << " text/xml\n" + << " \n"; +} + +list > +CPL::assets () const +{ + list > a; + for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + if ((*i)->main_picture ()) { + a.push_back ((*i)->main_picture ()); + } + if ((*i)->main_sound ()) { + a.push_back ((*i)->main_sound ()); + } + if ((*i)->main_subtitle ()) { + a.push_back ((*i)->main_subtitle ()); + } + } + + return a; +} + +void +CPL::write_to_assetmap (ostream& s) const +{ + s << " \n" + << " urn:uuid:" << _uuid << "\n" + << " \n" + << " \n" + << " " << _uuid << "_cpl.xml\n" + << " 1\n" + << " 0\n" + << " " << _length << "\n" + << " \n" + << " \n" + << " \n"; +} + + + list -DCP::equals (DCP const & other, EqualityOptions opt) const +CPL::equals (CPL const & other, EqualityOptions opt) const { list notes; @@ -433,4 +539,3 @@ DCP::equals (DCP const & other, EqualityOptions opt) const return notes; } - diff --git a/src/dcp.h b/src/dcp.h index 8dd7a412..79be5ca5 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -43,6 +43,68 @@ class PictureAsset; class SoundAsset; class SubtitleAsset; class Reel; +class AssetMap; + +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 asset_map, bool require_mxfs = true); + + void add_reel (boost::shared_ptr reel); + + /** @return the length in frames */ + int length () const { + return _length; + } + + /** @return the type of the content, used by media servers + * to categorise things (e.g. feature, trailer, etc.) + */ + ContentKind content_kind () const { + return _content_kind; + } + + std::list > reels () const { + return _reels; + } + + /** @return the CPL's name, as will be presented on projector + * media servers and theatre management systems. + */ + std::string name () const { + return _name; + } + + /** @return the number of frames per second */ + int frames_per_second () const { + return _fps; + } + + std::list > assets () const; + + std::list equals (CPL const & other, EqualityOptions options) const; + + void write_xml () const; + void write_to_assetmap (std::ostream& s) const; + void write_to_pkl (std::ostream& s) const; + +private: + std::string _directory; + /** the name of the DCP */ + std::string _name; + /** the content kind of the CPL */ + ContentKind _content_kind; + /** length in frames */ + mutable int _length; + /** frames per second */ + int _fps; + /** reels */ + std::list > _reels; + + std::string _uuid; + mutable std::string _digest; +}; /** @class DCP dcp.h libdcp/dcp.h * @brief A class to create or read a DCP. @@ -51,64 +113,29 @@ class Reel; class DCP { public: - /** Construct a DCP. - * - * This is for making a new DCP that you are going to add assets to. + /** Construct a DCP. You can pass an existing DCP's directory + * as the parameter, or a non-existant folder to create a new + * DCP in. * - * @param directory Directory to write files to. - * @param name Name. - * @param content_kind Content kind. - * @param fps Frames per second. - * @param length Length in frames. + * @param directory Directory containing the DCP's files. */ - DCP (std::string directory, std::string name, ContentKind content_kind, int fps, int length); + DCP (std::string directory); - /** Construct a DCP object for an existing DCP. + /** Read an existing DCP's data. * * The DCP's XML metadata will be examined, and you can then look at the contents * of the DCP. * - * @param directory Existing DCP's directory. - * @param read_mxfs true to read MXF files; setting to false can be useful for testing, but - * normally it should be set to true. + * @param require_mxfs true to throw an exception if MXF files are missing; setting to false + * can be useful for testing, but normally it should be set to true. */ - DCP (std::string directory, bool read_mxfs = true); - - void add_reel (boost::shared_ptr reel); + void read (bool require_mxfs = true); /** Write the required XML files to the directory that was * passed into the constructor. */ void write_xml () const; - /** @return the DCP's name, as will be presented on projector - * media servers and theatre management systems. - */ - std::string name () const { - return _name; - } - - /** @return the type of the content, used by media servers - * to categorise things (e.g. feature, trailer, etc.) - */ - ContentKind content_kind () const { - return _content_kind; - } - - /** @return the number of frames per second */ - int frames_per_second () const { - return _fps; - } - - /** @return the length in frames */ - int length () const { - return _length; - } - - std::list > reels () const { - return _reels; - } - /** Compare this DCP with another, according to various options. * @param other DCP to compare this one to. * @param options Options to define just what "equality" means. @@ -117,6 +144,12 @@ public: */ std::list equals (DCP const & other, EqualityOptions options) const; + void add_cpl (boost::shared_ptr cpl); + + std::list > cpls () const { + return _cpls; + } + /** Emitted with a parameter between 0 and 1 to indicate progress * for long jobs. */ @@ -124,33 +157,24 @@ public: private: - /** Write the CPL file. - * @param cpl_uuid UUID to use. - * @return CPL pathname. - */ - std::string write_cpl (std::string cpl_uuid) const; - /** Write the PKL file. * @param pkl_uuid UUID to use. - * @param cpl_uuid UUID of the CPL file. - * @param cpl_digest SHA digest of the CPL file. - * @param cpl_length Length of the CPL file in bytes. */ - std::string write_pkl (std::string pkl_uuid, std::string cpl_uuid, std::string cpl_digest, int cpl_length) const; + std::string write_pkl (std::string pkl_uuid) const; /** Write the VOLINDEX file */ void write_volindex () const; /** Write the ASSETMAP file. - * @param cpl_uuid UUID of our CPL. - * @param cpl_length Length of our CPL in bytes. * @param pkl_uuid UUID of our PKL. * @param pkl_length Length of our PKL in bytes. */ - void write_assetmap (std::string cpl_uuid, int cpl_length, std::string pkl_uuid, int pkl_length) const; + void write_assetmap (std::string pkl_uuid, int pkl_length) const; + + std::list > assets () const; struct Files { - std::string cpl; + std::list cpls; std::string pkl; std::string asset_map; std::list subtitles; @@ -158,16 +182,7 @@ private: /** the directory that we are writing to */ std::string _directory; - /** the name of the DCP */ - std::string _name; - /** the content kind of the DCP */ - ContentKind _content_kind; - /** frames per second */ - int _fps; - /** length in frames */ - int _length; - /** reels */ - std::list > _reels; + std::list > _cpls; }; } diff --git a/src/reel.cc b/src/reel.cc index 431af69a..50426cc1 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -46,38 +46,6 @@ Reel::write_to_cpl (ostream& s) const } } -void -Reel::write_to_pkl (ostream& s) const -{ - if (_main_picture) { - _main_picture->write_to_pkl (s); - } - - if (_main_sound) { - _main_sound->write_to_pkl (s); - } - - if (_main_subtitle) { - _main_subtitle->write_to_pkl (s); - } -} - -void -Reel::write_to_assetmap (ostream& s) const -{ - if (_main_picture) { - _main_picture->write_to_assetmap (s); - } - - if (_main_sound) { - _main_sound->write_to_assetmap (s); - } - - if (_main_subtitle) { - _main_subtitle->write_to_assetmap (s); - } -} - list Reel::equals (boost::shared_ptr other, EqualityOptions opt) const { diff --git a/src/reel.h b/src/reel.h index 2148e122..58caed31 100644 --- a/src/reel.h +++ b/src/reel.h @@ -53,8 +53,6 @@ public: } void write_to_cpl (std::ostream & s) const; - void write_to_pkl (std::ostream & s) const; - void write_to_assetmap (std::ostream & s) const; std::list equals (boost::shared_ptr other, EqualityOptions opt) const; diff --git a/src/util.cc b/src/util.cc index c171b2c7..4434b98c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -127,7 +127,7 @@ libdcp::content_kind_from_string (string type) return FEATURE; } else if (type == "short") { return SHORT; - } else if (type == "trailer") { + } else if (type == "trailer" || type == "Trailer") { return TRAILER; } else if (type == "test") { return TEST; -- cgit v1.2.3