diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-01-22 19:42:39 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-01-22 19:42:39 +0000 |
| commit | 1c724e363a644abaee7efb39d6091e7b30de0fb6 (patch) | |
| tree | 413e28533849835f8496c8c972bd26e1d27aefbe /src | |
| parent | 1e9f115b7cda68ccba99f58d194a2c0eb83e7e23 (diff) | |
Various work.
Diffstat (limited to 'src')
31 files changed, 344 insertions, 435 deletions
diff --git a/src/asset.h b/src/asset.h index 86d4734e..f3546cd8 100644 --- a/src/asset.h +++ b/src/asset.h @@ -17,6 +17,9 @@ */ +#ifndef LIBDCP_ASSET_H +#define LIBDCP_ASSET_H + #include "object.h" namespace dcp { @@ -34,3 +37,5 @@ public: }; } + +#endif diff --git a/src/content_asset.cc b/src/content.cc index 56891007..9a035c80 100644 --- a/src/content_asset.cc +++ b/src/content.cc @@ -24,7 +24,7 @@ #include <libxml++/nodes/element.h> #include "AS_DCP.h" #include "KM_util.h" -#include "content_asset.h" +#include "content.h" #include "util.h" #include "metadata.h" @@ -32,88 +32,60 @@ using namespace std; using namespace boost; using namespace dcp; -ContentAsset::ContentAsset (boost::filesystem::path directory, boost::filesystem::path file_name) - : _directory (directory) - , _file_name (file_name) - , _uuid (make_uuid ()) +Content::Content (boost::filesystem::path file) + : _file (file) , _edit_rate (0) - , _entry_point (0) , _intrinsic_duration (0) - , _duration (0) { - if (_file_name.empty ()) { - _file_name = _uuid + ".xml"; - } + +} + +Content::Content (int edit_rate) + : _edit_rate (edit_rate) + , _intrinsic_duration (0) +{ + } void -ContentAsset::write_to_pkl (xmlpp::Node* node) const +Content::write_to_pkl (xmlpp::Node* node) const { xmlpp::Node* asset = node->add_child ("Asset"); - asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); - asset->add_child("AnnotationText")->add_child_text (_file_name.string ()); - asset->add_child("Hash")->add_child_text (digest ()); - asset->add_child("Size")->add_child_text (lexical_cast<string> (filesystem::file_size(path()))); + asset->add_child("Id")->add_child_text ("urn:uuid:" + _id); + asset->add_child("AnnotationText")->add_child_text (_id); +//XXX asset->add_child("Hash")->add_child_text (digest ()); + asset->add_child("Size")->add_child_text (lexical_cast<string> (filesystem::file_size (_file))); asset->add_child("Type")->add_child_text ("application/mxf"); } void -ContentAsset::write_to_assetmap (xmlpp::Node* node) const +Content::write_to_assetmap (xmlpp::Node* node) const { xmlpp::Node* asset = node->add_child ("Asset"); - asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid); + asset->add_child("Id")->add_child_text ("urn:uuid:" + _id); xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); - chunk->add_child("Path")->add_child_text (_file_name.string ()); + chunk->add_child("Path")->add_child_text (_file.string ()); chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text ("0"); - chunk->add_child("Length")->add_child_text (lexical_cast<string> (filesystem::file_size(path()))); -} - -filesystem::path -ContentAsset::path () const -{ - filesystem::path p; - p /= _directory; - p /= _file_name; - return p; -} - -string -ContentAsset::digest () const -{ - if (_digest.empty ()) { - _digest = make_digest (path().string(), 0); - } - - return _digest; -} - -void -ContentAsset::compute_digest (boost::function<void (float)> progress) -{ - if (!_digest.empty ()) { - return; - } - - _digest = make_digest (path().string(), &progress); + chunk->add_child("Length")->add_child_text (lexical_cast<string> (filesystem::file_size (_file))); } bool -ContentAsset::equals (shared_ptr<const ContentAsset> other, EqualityOptions, boost::function<void (NoteType, string)> note) const +Content::equals (shared_ptr<const Content> other, EqualityOptions, boost::function<void (NoteType, string)> note) const { - if (_edit_rate != other->_edit_rate) { - note (ERROR, "asset edit rates differ"); - return false; - } + // if (_edit_rate != other->_edit_rate) { + // note (ERROR, "asset edit rates differ"); + // return false; + // } - if (_intrinsic_duration != other->_intrinsic_duration) { - note (ERROR, "asset intrinsic durations differ"); - } + // if (_intrinsic_duration != other->_intrinsic_duration) { + // note (ERROR, "asset intrinsic durations differ"); + // } - if (_duration != other->_duration) { - note (ERROR, "asset durations differ"); - } + // if (_duration != other->_duration) { + // note (ERROR, "asset durations differ"); + // } - return true; + // return true; } diff --git a/src/content.h b/src/content.h new file mode 100644 index 00000000..75e39a01 --- /dev/null +++ b/src/content.h @@ -0,0 +1,114 @@ +/* + Copyright (C) 2012 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef LIBDCP_CONTENT_H +#define LIBDCP_CONTENT_H + +#include <string> +#include <list> +#include <boost/filesystem.hpp> +#include <boost/function.hpp> +#include <libxml++/libxml++.h> +#include "types.h" +#include "asset.h" + +namespace ASDCP { + class WriterInfo; +} + +namespace xmlpp { + class Element; +} + +namespace dcp +{ + +/** @class Content + * @brief An asset that represents a piece of content, i.e. picture, sound or subtitle. + * + * Such a piece of content will be contained in a file (either MXF or XML) within a DCP. + */ +class Content : public Asset +{ +public: + Content (boost::filesystem::path file); + Content (int edit_rate); + + virtual ~Content () {} + + /** Write details of the asset to a PKL AssetList node. + * @param p Parent node. + */ + void write_to_pkl (xmlpp::Node *) const; + + /** Write details of the asset to a ASSETMAP stream. + * @param s Stream. + */ + void write_to_assetmap (xmlpp::Node *) const; + + boost::filesystem::path file () const { + return _file; + } + + void set_file (boost::filesystem::path file) { + _file = file; + } + + int edit_rate () const { + return _edit_rate; + } + + void set_edit_rate (int r) { + _edit_rate = r; + } + + void set_entry_point (int64_t p) { + _entry_point = p; + } + + int64_t intrinsic_duration () const { + return _intrinsic_duration; + } + + void set_intrinsic_duration (int64_t d) { + _intrinsic_duration = d; + } + + int64_t duration () const { + return _duration; + } + + void set_duration (int64_t d) { + _duration = d; + } + + virtual bool equals (boost::shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, std::string)>) const; + +protected: + boost::filesystem::path _file; + /** The edit rate; this is normally equal to the number of video frames per second */ + int _edit_rate; + int64_t _entry_point; + int64_t _intrinsic_duration; + int64_t _duration; +}; + +} + +#endif diff --git a/src/content_asset.h b/src/content_asset.h deleted file mode 100644 index 4e7ed031..00000000 --- a/src/content_asset.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - Copyright (C) 2012 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef LIBDCP_ASSET_H -#define LIBDCP_ASSET_H - -#include <string> -#include <list> -#include <boost/filesystem.hpp> -#include <boost/function.hpp> -#include <libxml++/libxml++.h> -#include "types.h" - -namespace ASDCP { - class WriterInfo; -} - -namespace xmlpp { - class Element; -} - -namespace dcp -{ - -/** XXX */ -class ContentAsset -{ -public: - /** Construct a ContentAsset. - * @param directory Directory where our XML or MXF file is. - * @param file_name Name of our file within directory, or empty to make one up based on UUID. - */ - ContentAsset (boost::filesystem::path directory, boost::filesystem::path file_name = ""); - - virtual ~ContentAsset() {} - - /** Write details of the asset to a CPL AssetList node. - * @param p Parent element. - */ - virtual void write_to_cpl (xmlpp::Element* p) const = 0; - - /** Write details of the asset to a PKL AssetList node. - * @param p Parent node. - */ - void write_to_pkl (xmlpp::Node *) const; - - /** Write details of the asset to a ASSETMAP stream. - * @param s Stream. - */ - void write_to_assetmap (xmlpp::Node *) const; - - /** Compute the digest for this asset. Calling this is optional: if - * it is not called, the digest will be computed when required. However, - * calling this method allows the caller to see the progress of the - * computation, which can be long for large assets. - * @param Called with progress between 0 and 1. - */ - void compute_digest (boost::function<void (float)> progress); - - std::string uuid () const { - return _uuid; - } - - boost::filesystem::path path () const; - - void set_directory (boost::filesystem::path d) { - _directory = d; - } - - void set_file_name (boost::filesystem::path f) { - _file_name = f; - } - - int entry_point () const { - return _entry_point; - } - - int duration () const { - return _duration; - } - - int intrinsic_duration () const { - return _intrinsic_duration; - } - - int edit_rate () const { - return _edit_rate; - } - - void set_entry_point (int e) { - _entry_point = e; - } - - void set_duration (int d) { - _duration = d; - } - - void set_intrinsic_duration (int d) { - _intrinsic_duration = d; - } - - void set_edit_rate (int r) { - _edit_rate = r; - } - - virtual bool equals (boost::shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)>) const; - -protected: - - std::string digest () const; - - /** Directory that our MXF or XML file is in */ - boost::filesystem::path _directory; - /** Name of our MXF or XML file */ - boost::filesystem::path _file_name; - /** Our UUID */ - std::string _uuid; - /** The edit rate; this is normally equal to the number of video frames per second */ - int _edit_rate; - /** Start point to present in frames */ - int _entry_point; - /** Total length in frames */ - int _intrinsic_duration; - /** Length to present in frames */ - int _duration; - -private: - /** Digest of our MXF or XML file */ - mutable std::string _digest; -}; - -} - -#endif @@ -109,15 +109,15 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass try { pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id); - picture.reset (new MonoPictureMXF (asset.first, asset.second->chunks.front()->path)); +// picture.reset (new MonoPictureMXF (asset.first, asset.second->chunks.front()->path)); - picture->read (); - picture->set_edit_rate (_fps); - picture->set_entry_point (p->entry_point); - picture->set_duration (p->duration); +// picture->read (); +// picture->set_edit_rate (_fps); +// 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)); +// picture->set_key_id (p->key_id.substr (9)); } } catch (MXFFileError) { if (require_mxfs) { @@ -129,15 +129,15 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass try { pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id); - picture.reset (new StereoPictureMXF (asset.first, asset.second->chunks.front()->path)); +// picture.reset (new StereoPictureMXF (asset.first, asset.second->chunks.front()->path)); - picture->read (); - picture->set_edit_rate (_fps); - picture->set_entry_point (p->entry_point); - picture->set_duration (p->duration); +// picture->read (); +// picture->set_edit_rate (_fps); +// 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)); +// picture->set_key_id (p->key_id.substr (9)); } } catch (MXFFileError) { @@ -153,16 +153,16 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass try { pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_sound->id); - sound.reset (new SoundMXF (asset.first, asset.second->chunks.front()->path)); - shared_ptr<parse::MainSound> s = (*i)->asset_list->main_sound; +// sound.reset (new SoundMXF (asset.first, asset.second->chunks.front()->path)); +// shared_ptr<parse::MainSound> s = (*i)->asset_list->main_sound; - sound->read (); - sound->set_entry_point (s->entry_point); - sound->set_duration (s->duration); - if (s->key_id.length() > 9) { +// sound->read (); +// 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)); - } +// sound->set_key_id (s->key_id.substr (9)); +// } } catch (MXFFileError) { if (require_mxfs) { throw; @@ -172,15 +172,15 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass 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); +// 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.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); +// 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))); +// _reels.push_back (shared_ptr<Reel> (new Reel (picture, sound, subtitle))); } } @@ -252,10 +252,10 @@ CPL::write_to_pkl (xmlpp::Node* node) const asset->add_child("Type")->add_child_text ("text/xml"); } -list<shared_ptr<const ContentAsset> > +list<shared_ptr<const Content> > CPL::assets () const { - list<shared_ptr<const ContentAsset> > a; + list<shared_ptr<const Content> > 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 ()); @@ -39,7 +39,7 @@ namespace parse { class AssetMapAsset; } -class ContentAsset; +class Content; class Reel; class XMLMetadata; class MXFMetadata; @@ -85,7 +85,7 @@ public: return _fps; } - std::list<boost::shared_ptr<const ContentAsset> > assets () const; + std::list<boost::shared_ptr<const Content> > assets () const; bool encrypted () const; @@ -108,8 +108,8 @@ DCP::write_pkl (string pkl_uuid, bool interop, XMLMetadata const & metadata, sha pkl->add_child("Creator")->add_child_text (metadata.creator); xmlpp::Element* asset_list = pkl->add_child("AssetList"); - list<shared_ptr<const ContentAsset> > a = assets (); - for (list<shared_ptr<const ContentAsset> >::const_iterator i = a.begin(); i != a.end(); ++i) { + list<shared_ptr<const Content> > a = assets (); + for (list<shared_ptr<const Content> >::const_iterator i = a.begin(); i != a.end(); ++i) { (*i)->write_to_pkl (asset_list); } @@ -191,8 +191,8 @@ DCP::write_assetmap (string pkl_uuid, int pkl_length, bool interop, XMLMetadata (*i)->write_to_assetmap (asset_list); } - list<shared_ptr<const ContentAsset> > a = assets (); - for (list<shared_ptr<const ContentAsset> >::const_iterator i = a.begin(); i != a.end(); ++i) { + list<shared_ptr<const Content> > a = assets (); + for (list<shared_ptr<const Content> >::const_iterator i = a.begin(); i != a.end(); ++i) { (*i)->write_to_assetmap (asset_list); } @@ -321,17 +321,17 @@ DCP::add_cpl (shared_ptr<CPL> cpl) class AssetComparator { public: - bool operator() (shared_ptr<const ContentAsset> a, shared_ptr<const ContentAsset> b) { - return a->uuid() < b->uuid(); + bool operator() (shared_ptr<const Content> a, shared_ptr<const Content> b) { + return a->id() < b->id(); } }; -list<shared_ptr<const ContentAsset> > +list<shared_ptr<const Content> > DCP::assets () const { - list<shared_ptr<const ContentAsset> > a; + list<shared_ptr<const Content> > a; for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { - list<shared_ptr<const ContentAsset> > t = (*i)->assets (); + list<shared_ptr<const Content> > t = (*i)->assets (); a.merge (t); } @@ -40,7 +40,7 @@ namespace xmlpp { namespace dcp { -class ContentAsset; +class Content; class PictureAsset; class SoundAsset; class SubtitleAsset; @@ -138,7 +138,7 @@ private: void write_assetmap (std::string pkl_uuid, int pkl_length, bool, XMLMetadata const &) const; /** @return Assets in all the CPLs in this DCP */ - std::list<boost::shared_ptr<const ContentAsset> > assets () const; + std::list<boost::shared_ptr<const Content> > assets () const; struct Files { std::list<std::string> cpls; @@ -124,8 +124,8 @@ KDM::KDM ( */ apu.authorized_device_info.device_list.push_back ("2jmj7l5rSw0yVb/vlWAYkK/YBwk="); - list<shared_ptr<const ContentAsset> > assets = cpl->assets (); - for (list<shared_ptr<const ContentAsset> >::iterator i = assets.begin(); i != assets.end(); ++i) { + list<shared_ptr<const Content> > assets = cpl->assets (); + for (list<shared_ptr<const Content> >::iterator i = assets.begin(); i != assets.end(); ++i) { /* XXX: non-MXF assets? */ shared_ptr<const MXF> mxf = boost::dynamic_pointer_cast<const MXF> (*i); if (mxf) { @@ -138,7 +138,7 @@ KDM::KDM ( /* AuthenticatedPrivate */ - for (list<shared_ptr<const ContentAsset> >::iterator i = assets.begin(); i != assets.end(); ++i) { + for (list<shared_ptr<const Content> >::iterator i = assets.begin(); i != assets.end(); ++i) { /* XXX: non-MXF assets? */ shared_ptr<const MXF> mxf = boost::dynamic_pointer_cast<const MXF> (*i); if (mxf) { diff --git a/src/mono_picture_mxf.cc b/src/mono_picture_mxf.cc index 30973e5a..cea21c15 100644 --- a/src/mono_picture_mxf.cc +++ b/src/mono_picture_mxf.cc @@ -31,19 +31,13 @@ using boost::dynamic_pointer_cast; using boost::lexical_cast; using namespace dcp; -MonoPictureMXF::MonoPictureMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name) - : PictureMXF (directory, mxf_name) -{ - -} - -void -MonoPictureMXF::read () +MonoPictureMXF::MonoPictureMXF (boost::filesystem::path file) + : PictureMXF (file) { ASDCP::JP2K::MXFReader reader; - Kumu::Result_t r = reader.OpenRead (path().string().c_str()); + Kumu::Result_t r = reader.OpenRead (file.string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file.string(), r)); } ASDCP::JP2K::PictureDescriptor desc; @@ -58,35 +52,35 @@ MonoPictureMXF::read () _intrinsic_duration = desc.ContainerDuration; } -boost::filesystem::path -MonoPictureMXF::path_from_list (int f, vector<boost::filesystem::path> const & files) const +MonoPictureMXF::MonoPictureMXF (int edit_rate) + : PictureMXF (edit_rate) { - return files[f]; + } shared_ptr<const MonoPictureFrame> MonoPictureMXF::get_frame (int n) const { - return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (path(), n, _decryption_context)); + return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (_file, n, _decryption_context)); } bool -MonoPictureMXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const +MonoPictureMXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const { if (!MXF::equals (other, opt, note)) { return false; } ASDCP::JP2K::MXFReader reader_A; - Kumu::Result_t r = reader_A.OpenRead (path().string().c_str()); + Kumu::Result_t r = reader_A.OpenRead (_file.string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", _file.string(), r)); } ASDCP::JP2K::MXFReader reader_B; - r = reader_B.OpenRead (other->path().string().c_str()); + r = reader_B.OpenRead (other->file().string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", other->file().string(), r)); } ASDCP::JP2K::PictureDescriptor desc_A; @@ -127,10 +121,10 @@ MonoPictureMXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions op } shared_ptr<PictureMXFWriter> -MonoPictureMXF::start_write (bool overwrite) +MonoPictureMXF::start_write (boost::filesystem::path file, bool overwrite) { /* XXX: can't we use shared_ptr here? */ - return shared_ptr<MonoPictureMXFWriter> (new MonoPictureMXFWriter (this, overwrite)); + return shared_ptr<MonoPictureMXFWriter> (new MonoPictureMXFWriter (this, file, overwrite)); } string diff --git a/src/mono_picture_mxf.h b/src/mono_picture_mxf.h index 029ccce5..8c8ee531 100644 --- a/src/mono_picture_mxf.h +++ b/src/mono_picture_mxf.h @@ -24,23 +24,29 @@ namespace dcp { -/** A 2D (monoscopic) picture asset */ +/** @class MonoPictureMXF + * @brief A 2D (monoscopic) picture MXF. + */ class MonoPictureMXF : public PictureMXF { public: - MonoPictureMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name); + /** Create a MonoPictureMXF by reading a file. + * @param file MXF file to read. + */ + MonoPictureMXF (boost::filesystem::path file); - void read (); + /** Create a MonoPictureMXF with a given edit rate. + * @param edit_rate Edit rate (i.e. frame rate) in frames per second. + */ + MonoPictureMXF (int edit_rate); /** Start a progressive write to a MonoPictureMXF */ - boost::shared_ptr<PictureMXFWriter> start_write (bool); + boost::shared_ptr<PictureMXFWriter> start_write (boost::filesystem::path, bool); boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const; - bool equals (boost::shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; + bool equals (boost::shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; private: - boost::filesystem::path path_from_list (int f, std::vector<boost::filesystem::path> const & files) const; - void construct (boost::function<boost::filesystem::path (int)>, bool, MXFMetadata const &); std::string cpl_node_name () const; int edit_rate_factor () const; }; diff --git a/src/mono_picture_mxf_writer.cc b/src/mono_picture_mxf_writer.cc index 24ca2079..590a3f7d 100644 --- a/src/mono_picture_mxf_writer.cc +++ b/src/mono_picture_mxf_writer.cc @@ -40,8 +40,8 @@ struct MonoPictureMXFWriter::ASDCPState : public ASDCPStateBase /** @param a Asset to write to. `a' must not be deleted while * this writer class still exists, or bad things will happen. */ -MonoPictureMXFWriter::MonoPictureMXFWriter (PictureMXF* asset, bool overwrite) - : PictureMXFWriter (asset, overwrite) +MonoPictureMXFWriter::MonoPictureMXFWriter (PictureMXF* asset, boost::filesystem::path file, bool overwrite) + : PictureMXFWriter (asset, file, overwrite) , _state (new MonoPictureMXFWriter::ASDCPState) { _state->encryption_context = asset->encryption_context (); @@ -50,7 +50,7 @@ MonoPictureMXFWriter::MonoPictureMXFWriter (PictureMXF* asset, bool overwrite) void MonoPictureMXFWriter::start (uint8_t* data, int size) { - dcp::start (this, _state, _asset, data, size); + dcp::start (this, _state, _mxf, data, size); } FrameInfo @@ -71,7 +71,7 @@ MonoPictureMXFWriter::write (uint8_t* data, int size) string hash; ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _state->encryption_context, 0, &hash); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in writing video MXF", _asset->path().string(), r)); + boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r)); } ++_frames_written; @@ -86,7 +86,7 @@ MonoPictureMXFWriter::fake_write (int size) Kumu::Result_t r = _state->mxf_writer.FakeWriteFrame (size); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in writing video MXF", _asset->path().string(), r)); + boost::throw_exception (MXFFileError ("error in writing video MXF", _mxf->file().string(), r)); } ++_frames_written; @@ -99,11 +99,11 @@ MonoPictureMXFWriter::finalize () Kumu::Result_t r = _state->mxf_writer.Finalize(); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in finalizing video MXF", _asset->path().string(), r)); + boost::throw_exception (MXFFileError ("error in finalizing video MXF", _mxf->file().string(), r)); } _finalized = true; - _asset->set_intrinsic_duration (_frames_written); - _asset->set_duration (_frames_written); + _mxf->set_intrinsic_duration (_frames_written); + _mxf->set_duration (_frames_written); } diff --git a/src/mono_picture_mxf_writer.h b/src/mono_picture_mxf_writer.h index 4faa6b60..c4d9b6ed 100644 --- a/src/mono_picture_mxf_writer.h +++ b/src/mono_picture_mxf_writer.h @@ -26,10 +26,9 @@ namespace dcp { -/** A helper class for writing to MonoPictureAssets progressively (i.e. writing frame-by-frame, - * rather than giving libdcp all the frames in one go). +/** A helper class for writing to MonoPictureMXFs. * - * Objects of this class can only be created with MonoPictureAsset::start_write(). + * Objects of this class can only be created with MonoPictureMXF::start_write(). * * Frames can be written to the MonoPictureAsset by calling write() with a JPEG2000 image * (a verbatim .j2c file). finalize() must be called after the last frame has been written. @@ -46,7 +45,7 @@ public: private: friend class MonoPictureMXF; - MonoPictureMXFWriter (PictureMXF *, bool); + MonoPictureMXFWriter (PictureMXF *, boost::filesystem::path file, bool); void start (uint8_t *, int); /* do this with an opaque pointer so we don't have to include @@ -42,8 +42,8 @@ using boost::lexical_cast; using boost::dynamic_pointer_cast; using namespace dcp; -MXF::MXF (boost::filesystem::path directory, boost::filesystem::path file_name) - : ContentAsset (directory, file_name) +MXF::MXF (boost::filesystem::path file) + : Content (file) , _progress (0) , _encryption_context (0) , _decryption_context (0) @@ -71,7 +71,7 @@ MXF::fill_writer_info (ASDCP::WriterInfo* writer_info) writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE; } unsigned int c; - Kumu::hex2bin (_uuid.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c); + Kumu::hex2bin (_id.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c); assert (c == Kumu::UUID_Length); if (_key) { @@ -85,9 +85,9 @@ MXF::fill_writer_info (ASDCP::WriterInfo* writer_info) } bool -MXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const +MXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const { - if (!ContentAsset::equals (other, opt, note)) { + if (!Content::equals (other, opt, note)) { return false; } @@ -97,7 +97,7 @@ MXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::f return false; } - if (_file_name != other_mxf->_file_name) { + if (_file != other_mxf->file ()) { note (ERROR, "MXF names differ"); if (!opt.mxf_names_can_differ) { return false; @@ -115,8 +115,8 @@ MXF::write_to_cpl (xmlpp::Element* node) const if (!attr.first.empty ()) { a->set_attribute (attr.first, attr.second); } - a->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid); - a->add_child ("AnnotationText")->add_child_text (_file_name.string ()); + a->add_child ("Id")->add_child_text ("urn:uuid:" + _id); + a->add_child ("AnnotationText")->add_child_text (_file.string ()); a->add_child ("EditRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1"); a->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration)); a->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point)); @@ -21,7 +21,7 @@ #define LIBDCP_MXF_ASSET_H #include <boost/signals2.hpp> -#include "content_asset.h" +#include "content.h" #include "key.h" #include "metadata.h" @@ -38,20 +38,15 @@ class MXFMetadata; /** @class MXF * @brief Parent class for classes which represent MXF files. */ -class MXF : public ContentAsset +class MXF : public Content { public: - /** Construct an MXF. - * This class will not write anything to disk in this constructor, but subclasses may. - * - * @param directory Directory where MXF file is. - * @param file_name Name of MXF file. - */ - MXF (boost::filesystem::path directory, boost::filesystem::path file_name); + MXF (boost::filesystem::path file); + MXF (int edit_rate); ~MXF (); - virtual bool equals (boost::shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; + virtual bool equals (boost::shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; virtual void write_to_cpl (xmlpp::Element *) const; virtual std::string key_type () const = 0; diff --git a/src/object.h b/src/object.h index f2ef4c13..636c76a0 100644 --- a/src/object.h +++ b/src/object.h @@ -17,6 +17,9 @@ */ +#ifndef LIBDCP_OBJECT_H +#define LIBDCP_OBJECT_H + #include <string> namespace dcp { @@ -27,6 +30,7 @@ class Object public: Object (); Object (std::string id); + virtual ~Object () {} std::string id () const { return _id; @@ -37,3 +41,5 @@ protected: }; } + +#endif diff --git a/src/picture_mxf.cc b/src/picture_mxf.cc index 3221a88f..8f0f85b9 100644 --- a/src/picture_mxf.cc +++ b/src/picture_mxf.cc @@ -52,8 +52,14 @@ using boost::dynamic_pointer_cast; using boost::lexical_cast; using namespace dcp; -PictureMXF::PictureMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name) - : MXF (directory, mxf_name) +PictureMXF::PictureMXF (boost::filesystem::path file) + : MXF (file) +{ + +} + +PictureMXF::PictureMXF (int edit_rate) + : MXF (edit_rate) { } diff --git a/src/picture_mxf.h b/src/picture_mxf.h index 1966ee8e..3a587280 100644 --- a/src/picture_mxf.h +++ b/src/picture_mxf.h @@ -46,28 +46,11 @@ class PictureMXFWriter; class PictureMXF : public MXF { public: - /** Construct a PictureAsset. - * - * @param directory Directory where MXF file is. - * @param mxf_name Name of MXF file. - */ - PictureMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name); - - /** Start a progressive write to this asset. - * The following parameters must be set up (if required) before calling this: - * Interop mode (set_interop) - * Edit rate (set_edit_rate) - * MXF Metadata (set_metadata) - * - * @param overwrite true to overwrite an existing MXF file; in this mode, writing can be resumed to a partially-written MXF; false if the - * MXF file does not exist. - */ - virtual boost::shared_ptr<PictureMXFWriter> start_write (bool overwrite) = 0; - - virtual void read () = 0; - virtual void create (std::vector<boost::filesystem::path> const &) {} - virtual void create (boost::function<boost::filesystem::path (int)>) {} - + PictureMXF (boost::filesystem::path file); + PictureMXF (int edit_rate); + + virtual boost::shared_ptr<PictureMXFWriter> start_write (boost::filesystem::path file, bool overwrite) = 0; + Size size () const { return _size; } diff --git a/src/picture_mxf_writer.cc b/src/picture_mxf_writer.cc index 61dd854b..1a128b33 100644 --- a/src/picture_mxf_writer.cc +++ b/src/picture_mxf_writer.cc @@ -83,8 +83,9 @@ FrameInfo::write (FILE* f) const } -PictureMXFWriter::PictureMXFWriter (PictureMXF* asset, bool overwrite) - : _asset (asset) +PictureMXFWriter::PictureMXFWriter (PictureMXF* mxf, boost::filesystem::path file, bool overwrite) + : _mxf (mxf) + , _file (file) , _frames_written (0) , _started (false) , _finalized (false) diff --git a/src/picture_mxf_writer.h b/src/picture_mxf_writer.h index 3d10288f..9f50f973 100644 --- a/src/picture_mxf_writer.h +++ b/src/picture_mxf_writer.h @@ -55,15 +55,16 @@ public: virtual FrameInfo write (uint8_t *, int) = 0; virtual void finalize () = 0; virtual void fake_write (int) = 0; - + protected: template <class P, class Q> friend void start (PictureMXFWriter *, boost::shared_ptr<P>, Q *, uint8_t *, int); - PictureMXFWriter (PictureMXF *, bool); + PictureMXFWriter (PictureMXF *, boost::filesystem::path, bool); - PictureMXF* _asset; - + PictureMXF* _mxf; + + boost::filesystem::path _file; /** Number of picture frames written to the asset so far. For stereo assets * this will be incremented for each eye (i.e. there will be twice the number * of frames as in a mono asset). diff --git a/src/picture_mxf_writer_common.cc b/src/picture_mxf_writer_common.cc index 07a0964a..6ac8ae35 100644 --- a/src/picture_mxf_writer_common.cc +++ b/src/picture_mxf_writer_common.cc @@ -33,19 +33,21 @@ struct ASDCPStateBase }; template <class P, class Q> -void dcp::start (PictureMXFWriter* writer, shared_ptr<P> state, Q* asset, uint8_t* data, int size) +void dcp::start (PictureMXFWriter* writer, shared_ptr<P> state, Q* mxf, uint8_t* data, int size) { + mxf->set_file (writer->_file); + if (ASDCP_FAILURE (state->j2k_parser.OpenReadFrame (data, size, state->frame_buffer))) { boost::throw_exception (MiscError ("could not parse J2K frame")); } state->j2k_parser.FillPictureDescriptor (state->picture_descriptor); - state->picture_descriptor.EditRate = ASDCP::Rational (asset->edit_rate(), 1); + state->picture_descriptor.EditRate = ASDCP::Rational (mxf->edit_rate(), 1); - asset->fill_writer_info (&state->writer_info); + mxf->fill_writer_info (&state->writer_info); Kumu::Result_t r = state->mxf_writer.OpenWrite ( - asset->path().string().c_str(), + mxf->file().string().c_str(), state->writer_info, state->picture_descriptor, 16384, @@ -53,7 +55,7 @@ void dcp::start (PictureMXFWriter* writer, shared_ptr<P> state, Q* asset, uint8_ ); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for writing", asset->path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for writing", mxf->file().string(), r)); } writer->_started = true; diff --git a/src/sound_mxf.cc b/src/sound_mxf.cc index b569c57a..63f9ba05 100644 --- a/src/sound_mxf.cc +++ b/src/sound_mxf.cc @@ -42,21 +42,15 @@ using boost::shared_ptr; using boost::lexical_cast; using namespace dcp; -SoundMXF::SoundMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name) - : MXF (directory, mxf_name) +SoundMXF::SoundMXF (boost::filesystem::path file) + : MXF (file) , _channels (0) , _sampling_rate (0) { - -} - -void -SoundMXF::read () -{ ASDCP::PCM::MXFReader reader; - Kumu::Result_t r = reader.OpenRead (path().string().c_str()); + Kumu::Result_t r = reader.OpenRead (file.string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file.string(), r)); } ASDCP::PCM::AudioDescriptor desc; @@ -78,22 +72,22 @@ SoundMXF::cpl_node_name () const } bool -SoundMXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const +SoundMXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const { if (!MXF::equals (other, opt, note)) { return false; } ASDCP::PCM::MXFReader reader_A; - Kumu::Result_t r = reader_A.OpenRead (path().string().c_str()); + Kumu::Result_t r = reader_A.OpenRead (file().string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r)); } ASDCP::PCM::MXFReader reader_B; - r = reader_B.OpenRead (other->path().string().c_str()); + r = reader_B.OpenRead (other->file().string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r)); } ASDCP::PCM::AudioDescriptor desc_A; @@ -157,7 +151,7 @@ shared_ptr<const SoundFrame> SoundMXF::get_frame (int n) const { /* XXX: should add on entry point here? */ - return shared_ptr<const SoundFrame> (new SoundFrame (path().string(), n, _decryption_context)); + return shared_ptr<const SoundFrame> (new SoundFrame (file().string(), n, _decryption_context)); } shared_ptr<SoundMXFWriter> @@ -202,9 +196,9 @@ SoundMXFWriter::SoundMXFWriter (SoundMXF* a) _asset->fill_writer_info (&_state->writer_info); - Kumu::Result_t r = _state->mxf_writer.OpenWrite (_asset->path().string().c_str(), _state->writer_info, _state->audio_desc); + Kumu::Result_t r = _state->mxf_writer.OpenWrite (_asset->file().string().c_str(), _state->writer_info, _state->audio_desc); if (ASDCP_FAILURE (r)) { - boost::throw_exception (FileError ("could not open audio MXF for writing", _asset->path().string(), r)); + boost::throw_exception (FileError ("could not open audio MXF for writing", _asset->file().string(), r)); } } diff --git a/src/sound_mxf.h b/src/sound_mxf.h index eec3fab6..4216accb 100644 --- a/src/sound_mxf.h +++ b/src/sound_mxf.h @@ -68,13 +68,11 @@ private: class SoundMXF : public MXF { public: - SoundMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name); - - void read (); + SoundMXF (boost::filesystem::path file); boost::shared_ptr<SoundMXFWriter> start_write (); - bool equals (boost::shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; + bool equals (boost::shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; boost::shared_ptr<const SoundFrame> get_frame (int n) const; @@ -96,7 +94,6 @@ public: private: std::string key_type () const; - void construct (boost::function<boost::filesystem::path (Channel)> get_path); std::string cpl_node_name () const; /** Number of channels in the asset */ diff --git a/src/stereo_picture_frame.cc b/src/stereo_picture_frame.cc index 8f318371..893a9f72 100644 --- a/src/stereo_picture_frame.cc +++ b/src/stereo_picture_frame.cc @@ -59,12 +59,11 @@ StereoPictureFrame::~StereoPictureFrame () delete _buffer; } -/** @param reduce a factor by which to reduce the resolution +/** @param eye Eye to return (EYE_LEFT or EYE_RIGHT). + * @param reduce a factor by which to reduce the resolution * of the image, expressed as a power of two (pass 0 for no * reduction). * - * @param eye Eye to return (EYE_LEFT or EYE_RIGHT). - * * @return An ARGB representation of one of the eyes (left or right) * of this frame. This is ARGB in the Cairo sense, so that each * pixel takes up 4 bytes; the first byte is blue, second green, diff --git a/src/stereo_picture_mxf.cc b/src/stereo_picture_mxf.cc index 29283746..7e112687 100644 --- a/src/stereo_picture_mxf.cc +++ b/src/stereo_picture_mxf.cc @@ -31,22 +31,22 @@ using boost::dynamic_pointer_cast; using namespace dcp; bool -StereoPictureMXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const +StereoPictureMXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const { if (!MXF::equals (other, opt, note)) { return false; } ASDCP::JP2K::MXFSReader reader_A; - Kumu::Result_t r = reader_A.OpenRead (path().string().c_str()); + Kumu::Result_t r = reader_A.OpenRead (file().string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r)); } ASDCP::JP2K::MXFSReader reader_B; - r = reader_B.OpenRead (other->path().string().c_str()); + r = reader_B.OpenRead (other->file().string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r)); } ASDCP::JP2K::PictureDescriptor desc_A; @@ -89,19 +89,13 @@ StereoPictureMXF::equals (shared_ptr<const ContentAsset> other, EqualityOptions return true; } -StereoPictureMXF::StereoPictureMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name) - : PictureMXF (directory, mxf_name) -{ - -} - -void -StereoPictureMXF::read () +StereoPictureMXF::StereoPictureMXF (boost::filesystem::path file) + : PictureMXF (file) { ASDCP::JP2K::MXFSReader reader; - Kumu::Result_t r = reader.OpenRead (path().string().c_str()); + Kumu::Result_t r = reader.OpenRead (file.string().c_str()); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string(), r)); + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file.string(), r)); } ASDCP::JP2K::PictureDescriptor desc; @@ -116,13 +110,13 @@ StereoPictureMXF::read () shared_ptr<const StereoPictureFrame> StereoPictureMXF::get_frame (int n) const { - return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (path().string(), n)); + return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (file().string(), n)); } shared_ptr<PictureMXFWriter> -StereoPictureMXF::start_write (bool overwrite) +StereoPictureMXF::start_write (boost::filesystem::path file, bool overwrite) { - return shared_ptr<StereoPictureMXFWriter> (new StereoPictureMXFWriter (this, overwrite)); + return shared_ptr<StereoPictureMXFWriter> (new StereoPictureMXFWriter (this, file, overwrite)); } string diff --git a/src/stereo_picture_mxf.h b/src/stereo_picture_mxf.h index 2e16b22c..4af8a327 100644 --- a/src/stereo_picture_mxf.h +++ b/src/stereo_picture_mxf.h @@ -28,15 +28,13 @@ namespace dcp { class StereoPictureMXF : public PictureMXF { public: - StereoPictureMXF (boost::filesystem::path directory, boost::filesystem::path mxf_name); + StereoPictureMXF (boost::filesystem::path file); - void read (); - /** Start a progressive write to a StereoPictureMXF */ - boost::shared_ptr<PictureMXFWriter> start_write (bool); + boost::shared_ptr<PictureMXFWriter> start_write (boost::filesystem::path file, bool); boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const; - bool equals (boost::shared_ptr<const ContentAsset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; + bool equals (boost::shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; private: std::string cpl_node_name () const; diff --git a/src/stereo_picture_mxf_writer.cc b/src/stereo_picture_mxf_writer.cc index b988d75a..10c5ea06 100644 --- a/src/stereo_picture_mxf_writer.cc +++ b/src/stereo_picture_mxf_writer.cc @@ -36,18 +36,18 @@ struct StereoPictureMXFWriter::ASDCPState : public ASDCPStateBase ASDCP::JP2K::MXFSWriter mxf_writer; }; -StereoPictureMXFWriter::StereoPictureMXFWriter (PictureMXF* asset, bool overwrite) - : PictureMXFWriter (asset, overwrite) +StereoPictureMXFWriter::StereoPictureMXFWriter (PictureMXF* mxf, boost::filesystem::path file, bool overwrite) + : PictureMXFWriter (mxf, file, overwrite) , _state (new StereoPictureMXFWriter::ASDCPState) , _next_eye (EYE_LEFT) { - _state->encryption_context = asset->encryption_context (); + _state->encryption_context = mxf->encryption_context (); } void StereoPictureMXFWriter::start (uint8_t* data, int size) { - dcp::start (this, _state, _asset, data, size); + dcp::start (this, _state, _mxf, data, size); } /** Write a frame for one eye. Frames must be written left, then right, then left etc. @@ -79,7 +79,7 @@ StereoPictureMXFWriter::write (uint8_t* data, int size) ); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in writing video MXF", _asset->path().string(), r)); + boost::throw_exception (MXFFileError ("error in writing video MXF", _mxf->file().string(), r)); } _next_eye = _next_eye == EYE_LEFT ? EYE_RIGHT : EYE_LEFT; @@ -96,7 +96,7 @@ StereoPictureMXFWriter::fake_write (int size) Kumu::Result_t r = _state->mxf_writer.FakeWriteFrame (size); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in writing video MXF", _asset->path().string(), r)); + boost::throw_exception (MXFFileError ("error in writing video MXF", _mxf->file().string(), r)); } _next_eye = _next_eye == EYE_LEFT ? EYE_RIGHT : EYE_LEFT; @@ -110,10 +110,10 @@ StereoPictureMXFWriter::finalize () Kumu::Result_t r = _state->mxf_writer.Finalize(); if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("error in finalizing video MXF", _asset->path().string(), r)); + boost::throw_exception (MXFFileError ("error in finalizing video MXF", _mxf->file().string(), r)); } _finalized = true; - _asset->set_intrinsic_duration (_frames_written / 2); - _asset->set_duration (_frames_written / 2); + _mxf->set_intrinsic_duration (_frames_written / 2); + _mxf->set_duration (_frames_written / 2); } diff --git a/src/stereo_picture_mxf_writer.h b/src/stereo_picture_mxf_writer.h index 384250db..a34af069 100644 --- a/src/stereo_picture_mxf_writer.h +++ b/src/stereo_picture_mxf_writer.h @@ -46,7 +46,7 @@ public: private: friend class StereoPictureMXF; - StereoPictureMXFWriter (PictureMXF *, bool); + StereoPictureMXFWriter (PictureMXF *, boost::filesystem::path file, bool); void start (uint8_t *, int); /* do this with an opaque pointer so we don't have to include diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index fcc8bac0..1c36fdfc 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -36,30 +36,14 @@ using boost::lexical_cast; using boost::optional; using namespace dcp; -SubtitleAsset::SubtitleAsset (string directory, string xml_file) - : ContentAsset (directory, xml_file) +SubtitleAsset::SubtitleAsset (boost::filesystem::path file) + : Content (file) , _need_sort (false) { - read_xml (path().string()); -} - -SubtitleAsset::SubtitleAsset (string directory, string movie_title, string language) - : ContentAsset (directory) - , _movie_title (movie_title) - , _reel_number ("1") - , _language (language) - , _need_sort (false) -{ - -} - -void -SubtitleAsset::read_xml (string xml_file) -{ shared_ptr<cxml::Document> xml (new cxml::Document ("DCSubtitle")); - xml->read_file (xml_file); + xml->read_file (file); - _uuid = xml->string_child ("SubtitleID"); + _id = xml->string_child ("SubtitleID"); _movie_title = xml->string_child ("MovieTitle"); _reel_number = xml->string_child ("ReelNumber"); _language = xml->string_child ("Language"); @@ -77,6 +61,16 @@ SubtitleAsset::read_xml (string xml_file) examine_font_nodes (xml, font_nodes, parse_state); } +SubtitleAsset::SubtitleAsset (string directory, string movie_title, string language) + : Content (directory) + , _movie_title (movie_title) + , _reel_number ("1") + , _language (language) + , _need_sort (false) +{ + +} + void SubtitleAsset::examine_font_nodes ( shared_ptr<const cxml::Node> xml, @@ -284,8 +278,8 @@ SubtitleAsset::write_to_cpl (xmlpp::Element* node) const /* XXX: should EditRate, Duration and IntrinsicDuration be in here? */ xmlpp::Node* ms = node->add_child ("MainSubtitle"); - ms->add_child("Id")->add_child_text("urn:uuid:" + _uuid); - ms->add_child("AnnotationText")->add_child_text (_file_name.string ()); + ms->add_child("Id")->add_child_text("urn:uuid:" + _id); + ms->add_child("AnnotationText")->add_child_text (_file.string ()); /* XXX */ ms->add_child("EntryPoint")->add_child_text ("0"); } @@ -302,7 +296,7 @@ struct SubtitleSorter { void SubtitleAsset::write_xml () const { - FILE* f = fopen_boost (path (), "r"); + FILE* f = fopen_boost (file (), "r"); Glib::ustring const s = xml_as_string (); fwrite (s.c_str(), 1, s.length(), f); fclose (f); @@ -315,7 +309,7 @@ SubtitleAsset::xml_as_string () const xmlpp::Element* root = doc.create_root_node ("DCSubtitle"); root->set_attribute ("Version", "1.0"); - root->add_child("SubtitleID")->add_child_text (_uuid); + root->add_child("SubtitleID")->add_child_text (_id); root->add_child("MovieTitle")->add_child_text (_movie_title); root->add_child("ReelNumber")->add_child_text (lexical_cast<string> (_reel_number)); root->add_child("Language")->add_child_text (_language); diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index cff65b2b..cbd3ad58 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -21,7 +21,7 @@ #define LIBDCP_SUBTITLE_ASSET_H #include <libcxml/cxml.h> -#include "content_asset.h" +#include "content.h" #include "dcp_time.h" namespace dcp @@ -133,14 +133,14 @@ private: bool operator== (Subtitle const & a, Subtitle const & b); std::ostream& operator<< (std::ostream& s, Subtitle const & sub); -class SubtitleAsset : public ContentAsset +class SubtitleAsset : public Content { public: - SubtitleAsset (std::string directory, std::string xml_file); + SubtitleAsset (boost::filesystem::path file); SubtitleAsset (std::string directory, std::string movie_title, std::string language); void write_to_cpl (xmlpp::Element *) const; - virtual bool equals (boost::shared_ptr<const ContentAsset>, EqualityOptions, boost::function<void (NoteType, std::string)> note) const { + virtual bool equals (boost::shared_ptr<const Content>, EqualityOptions, boost::function<void (NoteType, std::string)> note) const { /* XXX */ note (ERROR, "subtitle assets not compared yet"); return true; @@ -157,7 +157,6 @@ public: void add (boost::shared_ptr<Subtitle>); - void read_xml (std::string); void write_xml () const; Glib::ustring xml_as_string () const; diff --git a/src/wscript b/src/wscript index bcdc149c..3e92900a 100644 --- a/src/wscript +++ b/src/wscript @@ -16,7 +16,7 @@ def build(bld): asset.cc certificates.cc colour_matrix.cc - content_asset.cc + content.cc cpl.cc dcp.cc dcp_time.cc |
