diff options
Diffstat (limited to 'src/cpl.cc')
| -rw-r--r-- | src/cpl.cc | 206 |
1 files changed, 30 insertions, 176 deletions
@@ -31,6 +31,7 @@ #include "encryption.h" #include "exceptions.h" #include "compose.hpp" +#include "xml.h" using std::string; using std::stringstream; @@ -54,147 +55,29 @@ CPL::CPL (string annotation_text_, string content_title_text_, ContentKind conte /** Construct a CPL object from a XML file. * @param file The CPL XML filename. - * @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 (boost::filesystem::path file, list<PathAssetMap> asset_maps, bool require_mxfs) +CPL::CPL (boost::filesystem::path file) : content_kind (FEATURE) { - /* Read the XML */ - shared_ptr<parse::CPL> cpl; - try { - cpl.reset (new parse::CPL (file.string ())); - } catch (FileError& e) { - boost::throw_exception (FileError ("could not load CPL file", file.string ())); - } - - /* Now cherry-pick the required bits into our own data structure */ + cxml::Document xml ("CompositionPlaylist"); + xml.read_file (file); - annotation_text = cpl->annotation_text; - content_title_text = cpl->content_title_text; - content_kind = cpl->content_kind; - /* Trim urn:uuid: off the front */ - _id = cpl->id.substr (9); - - for (list<shared_ptr<parse::Reel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) { - - shared_ptr<parse::Picture> p; - - if ((*i)->asset_list->main_picture) { - p = (*i)->asset_list->main_picture; - } else { - p = (*i)->asset_list->main_stereoscopic_picture; - } - - shared_ptr<PictureAsset> picture; - shared_ptr<SoundAsset> sound; - shared_ptr<SubtitleAsset> subtitle; - - /* Some rather twisted logic to decide if we are 3D or not; - some DCPs give a MainStereoscopicPicture to indicate 3D, others - just have a FrameRate twice the EditRate and apparently - expect you to divine the fact that they are hence 3D. - */ - - 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 ( - asset.first, - asset.second->chunks.front()->path - ) - ); - - picture->set_entry_point (p->entry_point); - picture->set_duration (p->duration); - if (p->key_id.length() > 9) { - /* Trim urn:uuid: */ - picture->set_key_id (p->key_id.substr (9)); - } - } catch (MXFFileError) { - if (require_mxfs) { - throw; - } - } - - } else { - try { - pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id); - - picture.reset (new StereoPictureAsset ( - asset.first, - asset.second->chunks.front()->path, - p->edit_rate.numerator, - p->duration - ) - ); - - picture->set_entry_point (p->entry_point); - picture->set_duration (p->duration); - if (p->key_id.length() > 9) { - /* Trim urn:uuid: */ - picture->set_key_id (p->key_id.substr (9)); - } - - } catch (MXFFileError) { - if (require_mxfs) { - throw; - } - } - - } - - 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 ( - asset.first, - asset.second->chunks.front()->path - ) - ); - - shared_ptr<parse::MainSound> s = (*i)->asset_list->main_sound; - - sound->set_entry_point (s->entry_point); - sound->set_duration (s->duration); - if (s->key_id.length() > 9) { - /* Trim urn:uuid: */ - sound->set_key_id (s->key_id.substr (9)); - } - } catch (MXFFileError) { - if (require_mxfs) { - throw; - } - } - } - - 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 ( - asset.first, - asset.second->chunks.front()->path - ) - ); - - subtitle->set_entry_point ((*i)->asset_list->main_subtitle->entry_point); - subtitle->set_duration ((*i)->asset_list->main_subtitle->duration); - } - - _reels.push_back (shared_ptr<Reel> (new Reel (picture, sound, subtitle))); - } -} - -void -CPL::add_reel (shared_ptr<Reel> reel) -{ - _reels.push_back (reel); + _id = xml.string_child("Id").substr (9); + annotation_text = xml.optional_string_child ("AnnotationText").get_value_or (""); + issue_date = xml.string_child ("IssueDate"); + creator = xml.optional_string_child ("Creator").get_value_or (""); + content_title_text = xml.string_child ("ContentTitleText"); + content_kind = content_kind_from_string (xml.string_child ("ContentKind")); + xml.ignore_child ("RatingList"); + reels = type_grand_children<Reel> (xml, "ReelList", "Reel"); + + xml.ignore_child ("ContentVersion"); + xml.ignore_child ("Issuer"); + xml.ignore_child ("Signer"); + xml.ignore_child ("Signature"); + + xml.done (); } void @@ -234,7 +117,7 @@ CPL::write_xml (boost::filesystem::path directory, bool interop, XMLMetadata con xmlpp::Element* reel_list = root->add_child ("ReelList"); - for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + for (list<shared_ptr<Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) { (*i)->write_to_cpl (reel_list, interop); } @@ -258,25 +141,6 @@ CPL::write_to_pkl (xmlpp::Node* node) const asset->add_child("Type")->add_child_text ("text/xml"); } -list<shared_ptr<const Asset> > -CPL::assets () const -{ - list<shared_ptr<const Asset> > a; - for (list<shared_ptr<Reel> >::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 (xmlpp::Node* node) const { @@ -314,15 +178,15 @@ CPL::equals (CPL const & other, EqualityOptions opt, boost::function<void (NoteT return false; } - if (_reels.size() != other._reels.size()) { - note (ERROR, String::compose ("reel counts differ (%1 vs %2)", _reels.size(), other._reels.size())); + if (reels.size() != other.reels.size()) { + note (ERROR, String::compose ("reel counts differ (%1 vs %2)", reels.size(), other.reels.size())); return false; } - list<shared_ptr<Reel> >::const_iterator a = _reels.begin (); - list<shared_ptr<Reel> >::const_iterator b = other._reels.begin (); + list<shared_ptr<Reel> >::const_iterator a = reels.begin (); + list<shared_ptr<Reel> >::const_iterator b = other.reels.begin (); - while (a != _reels.end ()) { + while (a != reels.end ()) { if (!(*a)->equals (*b, opt, note)) { return false; } @@ -402,6 +266,8 @@ CPL::make_kdm ( } } + #if 0 + XXX { xmlpp::Element* key_id_list = kdm_required_extensions->add_child("KeyIdList"); list<shared_ptr<const Asset> > a = assets(); @@ -413,6 +279,7 @@ CPL::make_kdm ( } } } + #endif { xmlpp::Element* forensic_mark_flag_list = kdm_required_extensions->add_child("ForensicMarkFlagList"); @@ -492,7 +359,7 @@ CPL::make_kdm ( bool CPL::encrypted () const { - for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + for (list<shared_ptr<Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) { if ((*i)->encrypted ()) { return true; } @@ -504,20 +371,7 @@ CPL::encrypted () const void CPL::add_kdm (KDM const & kdm) { - for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { + for (list<shared_ptr<Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) { (*i)->add_kdm (kdm); } } - -pair<string, shared_ptr<const parse::AssetMapAsset> > -CPL::asset_from_id (list<PathAssetMap> asset_maps, string id) const -{ - 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 make_pair (i->first, a); - } - } - - return make_pair ("", shared_ptr<const parse::AssetMapAsset> ()); -} |
