summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-09-25 20:41:45 +0100
committerCarl Hetherington <cth@carlh.net>2013-09-25 20:41:45 +0100
commitf76647abae551840a43bb8f07189051ec20bab6d (patch)
tree12d67e33c71516480cb71381bc426dfe18513821 /src
parente8530ea06f0b0883e5e19dd18beed70732ac5d3c (diff)
Switch away from the many-constructor-arguments approach to a hopefully simpler API.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc8
-rw-r--r--src/asset.h6
-rw-r--r--src/cpl.cc36
-rw-r--r--src/mxf_asset.cc10
-rw-r--r--src/mxf_asset.h46
-rw-r--r--src/picture_asset.cc181
-rw-r--r--src/picture_asset.h110
-rw-r--r--src/picture_asset_writer.cc14
-rw-r--r--src/picture_asset_writer.h8
-rw-r--r--src/sound_asset.cc66
-rw-r--r--src/sound_asset.h75
11 files changed, 173 insertions, 387 deletions
diff --git a/src/asset.cc b/src/asset.cc
index 6e4901b5..4e17f855 100644
--- a/src/asset.cc
+++ b/src/asset.cc
@@ -37,14 +37,14 @@ using namespace std;
using namespace boost;
using namespace libdcp;
-Asset::Asset (boost::filesystem::path directory, string file_name, int edit_rate, int intrinsic_duration)
+Asset::Asset (boost::filesystem::path directory, string file_name)
: _directory (directory)
, _file_name (file_name)
, _uuid (make_uuid ())
- , _edit_rate (edit_rate)
+ , _edit_rate (0)
, _entry_point (0)
- , _intrinsic_duration (intrinsic_duration)
- , _duration (intrinsic_duration)
+ , _intrinsic_duration (0)
+ , _duration (0)
{
if (_file_name.empty ()) {
_file_name = _uuid + ".xml";
diff --git a/src/asset.h b/src/asset.h
index 940ed548..ec1385e6 100644
--- a/src/asset.h
+++ b/src/asset.h
@@ -53,7 +53,7 @@ public:
* @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.
*/
- Asset (boost::filesystem::path directory, std::string file_name = "", int edit_rate = 0, int intrinsic_duration = 0);
+ Asset (boost::filesystem::path directory, std::string file_name = "");
virtual ~Asset() {}
@@ -123,6 +123,10 @@ public:
_intrinsic_duration = d;
}
+ void set_edit_rate (int r) {
+ _edit_rate = r;
+ }
+
virtual bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)>) const;
protected:
diff --git a/src/cpl.cc b/src/cpl.cc
index 5d57c7c7..48d08035 100644
--- a/src/cpl.cc
+++ b/src/cpl.cc
@@ -107,15 +107,13 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
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
- )
- );
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+ picture.reset (new MonoPictureAsset (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);
if (p->key_id.length() > 9) {
@@ -132,14 +130,10 @@ 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 StereoPictureAsset (
- asset.first,
- asset.second->chunks.front()->path,
- _fps,
- p->duration
- )
- );
+ picture.reset (new StereoPictureAsset (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);
if (p->key_id.length() > 9) {
@@ -160,14 +154,10 @@ 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 SoundAsset (
- asset.first,
- asset.second->chunks.front()->path
- )
- );
-
+ sound.reset (new SoundAsset (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) {
@@ -185,11 +175,7 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
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);
diff --git a/src/mxf_asset.cc b/src/mxf_asset.cc
index 956d38f9..7bffc9f2 100644
--- a/src/mxf_asset.cc
+++ b/src/mxf_asset.cc
@@ -48,19 +48,11 @@ MXFAsset::MXFAsset (boost::filesystem::path directory, string file_name)
, _progress (0)
, _encryption_context (0)
, _decryption_context (0)
+ , _interop (false)
{
}
-MXFAsset::MXFAsset (boost::filesystem::path directory, string file_name, boost::signals2::signal<void (float)>* progress, int edit_rate, int intrinsic_duration)
- : Asset (directory, file_name, edit_rate, intrinsic_duration)
- , _progress (progress)
- , _encryption_context (0)
- , _decryption_context (0)
-{
-
-}
-
MXFAsset::~MXFAsset ()
{
delete _encryption_context;
diff --git a/src/mxf_asset.h b/src/mxf_asset.h
index e566c32c..b7144281 100644
--- a/src/mxf_asset.h
+++ b/src/mxf_asset.h
@@ -23,6 +23,7 @@
#include <boost/signals2.hpp>
#include "asset.h"
#include "key.h"
+#include "metadata.h"
namespace ASDCP {
class AESEncContext;
@@ -46,29 +47,12 @@ public:
*/
MXFAsset (boost::filesystem::path directory, std::string file_name);
- /** Construct an MXFAsset.
- * 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.
- * @param progress Signal to use to inform of progress, or 0.
- * @param edit_rate Edit rate in frames per second (usually equal to the video frame rate).
- * @param intrinsic_duration Duration of the whole asset in frames.
- */
- MXFAsset (
- boost::filesystem::path directory,
- std::string file_name,
- boost::signals2::signal<void (float)>* progress,
- int edit_rate,
- int intrinsic_duration
- );
-
~MXFAsset ();
virtual bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
-
virtual void write_to_cpl (xmlpp::Element *, bool interop) const;
-
+ virtual std::string key_type () const = 0;
+
/** Fill in a ADSCP::WriteInfo struct.
* @param w struct to fill in.
* @param uuid uuid to use.
@@ -76,6 +60,10 @@ public:
*/
void fill_writer_info (ASDCP::WriterInfo* w, std::string uuid, bool interop, MXFMetadata const & metadata);
+ void set_progress (boost::signals2::signal<void (float)>* progress) {
+ _progress = progress;
+ }
+
bool encrypted () const {
return !_key_id.empty ();
}
@@ -98,8 +86,22 @@ public:
return _encryption_context;
}
- virtual std::string key_type () const = 0;
-
+ void set_metadata (MXFMetadata m) {
+ _metadata = m;
+ }
+
+ MXFMetadata metadata () const {
+ return _metadata;
+ }
+
+ void set_interop (bool i) {
+ _interop = i;
+ }
+
+ bool interop () const {
+ return _interop;
+ }
+
protected:
virtual std::string cpl_node_name () const = 0;
virtual std::pair<std::string, std::string> cpl_node_attribute (bool) const {
@@ -112,6 +114,8 @@ protected:
ASDCP::AESDecContext* _decryption_context;
std::string _key_id;
boost::optional<Key> _key;
+ MXFMetadata _metadata;
+ bool _interop;
};
}
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index 78d7576d..97fce2ab 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -54,57 +54,12 @@ using boost::dynamic_pointer_cast;
using boost::lexical_cast;
using namespace libdcp;
-PictureAsset::PictureAsset (
- boost::filesystem::path directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration, Size size
- )
- : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
- , _size (size)
-{
-
-}
-
PictureAsset::PictureAsset (boost::filesystem::path directory, string mxf_name)
: MXFAsset (directory, mxf_name)
{
}
-string
-MonoPictureAsset::cpl_node_name () const
-{
- return "MainPicture";
-}
-
-int
-MonoPictureAsset::edit_rate_factor () const
-{
- return 1;
-}
-
-string
-StereoPictureAsset::cpl_node_name () const
-{
- return "msp-cpl:MainStereoscopicPicture";
-}
-
-pair<string, string>
-StereoPictureAsset::cpl_node_attribute (bool interop) const
-{
- if (interop) {
- return make_pair ("xmlns:msp-cpl", "http://www.digicine.com/schemas/437-Y/2007/Main-Stereo-Picture-CPL");
- } else {
- return make_pair ("xmlns:msp-cpl", "http://www.smpte-ra.org/schemas/429-10/2008/Main-Stereo-Picture-CPL");
- }
-
- return make_pair ("", "");
-}
-
-int
-StereoPictureAsset::edit_rate_factor () const
-{
- return 2;
-}
-
void
PictureAsset::write_to_cpl (xmlpp::Element* node, bool interop) const
{
@@ -189,67 +144,20 @@ PictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, boost:
return true;
}
-
-MonoPictureAsset::MonoPictureAsset (
- boost::function<boost::filesystem::path (int)> get_path,
- boost::filesystem::path directory,
- string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- Size size,
- bool interop,
- MXFMetadata const & metadata
- )
- : PictureAsset (directory, mxf_name, progress, fps, intrinsic_duration, size)
+MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, string mxf_name)
+ : PictureAsset (directory, mxf_name)
{
- construct (get_path, interop, metadata);
-}
-MonoPictureAsset::MonoPictureAsset (
- vector<boost::filesystem::path> const & files,
- boost::filesystem::path directory,
- string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- Size size,
- bool interop,
- MXFMetadata const & metadata
- )
- : PictureAsset (directory, mxf_name, progress, fps, intrinsic_duration, size)
-{
- construct (boost::bind (&MonoPictureAsset::path_from_list, this, _1, files), interop, metadata);
}
-MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, string mxf_name, int fps, Size size)
- : PictureAsset (directory, mxf_name, 0, fps, 0, size)
+void
+MonoPictureAsset::create (vector<boost::filesystem::path> const & files)
{
-
-}
-
-MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, string mxf_name)
- : PictureAsset (directory, mxf_name)
-{
- ASDCP::JP2K::MXFReader reader;
- if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string()));
- }
-
- ASDCP::JP2K::PictureDescriptor desc;
- if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
- boost::throw_exception (DCPReadError ("could not read video MXF information"));
- }
-
- _size.width = desc.StoredWidth;
- _size.height = desc.StoredHeight;
- _edit_rate = desc.EditRate.Numerator;
- assert (desc.EditRate.Denominator == 1);
- _intrinsic_duration = desc.ContainerDuration;
+ create (boost::bind (&MonoPictureAsset::path_from_list, this, _1, files));
}
void
-MonoPictureAsset::construct (boost::function<boost::filesystem::path (int)> get_path, bool interop, MXFMetadata const & metadata)
+MonoPictureAsset::create (boost::function<boost::filesystem::path (int)> get_path)
{
ASDCP::JP2K::CodestreamParser j2k_parser;
ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
@@ -262,7 +170,7 @@ MonoPictureAsset::construct (boost::function<boost::filesystem::path (int)> get_
picture_desc.EditRate = ASDCP::Rational (_edit_rate, 1);
ASDCP::WriterInfo writer_info;
- fill_writer_info (&writer_info, _uuid, interop, metadata);
+ fill_writer_info (&writer_info, _uuid, _interop, _metadata);
ASDCP::JP2K::MXFWriter mxf_writer;
if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc, 16384, false))) {
@@ -291,6 +199,26 @@ MonoPictureAsset::construct (boost::function<boost::filesystem::path (int)> get_
}
}
+void
+MonoPictureAsset::read ()
+{
+ ASDCP::JP2K::MXFReader reader;
+ if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", path().string()));
+ }
+
+ ASDCP::JP2K::PictureDescriptor desc;
+ if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
+ boost::throw_exception (DCPReadError ("could not read video MXF information"));
+ }
+
+ _size.width = desc.StoredWidth;
+ _size.height = desc.StoredHeight;
+ _edit_rate = desc.EditRate.Numerator;
+ assert (desc.EditRate.Denominator == 1);
+ _intrinsic_duration = desc.ContainerDuration;
+}
+
boost::filesystem::path
MonoPictureAsset::path_from_list (int f, vector<boost::filesystem::path> const & files) const
{
@@ -303,7 +231,6 @@ MonoPictureAsset::get_frame (int n) const
return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (path().string(), n, _decryption_context));
}
-
bool
MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
{
@@ -436,8 +363,14 @@ PictureAsset::frame_buffer_equals (
}
-StereoPictureAsset::StereoPictureAsset (boost::filesystem::path directory, string mxf_name, int fps, int intrinsic_duration)
- : PictureAsset (directory, mxf_name, 0, fps, intrinsic_duration, Size (0, 0))
+StereoPictureAsset::StereoPictureAsset (boost::filesystem::path directory, string mxf_name)
+ : PictureAsset (directory, mxf_name)
+{
+
+}
+
+void
+StereoPictureAsset::read ()
{
ASDCP::JP2K::MXFSReader reader;
if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
@@ -460,10 +393,10 @@ StereoPictureAsset::get_frame (int n) const
}
shared_ptr<PictureAssetWriter>
-MonoPictureAsset::start_write (bool overwrite, bool interop, MXFMetadata const & metadata)
+MonoPictureAsset::start_write (bool overwrite)
{
/* XXX: can't we use shared_ptr here? */
- return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, overwrite, interop, metadata));
+ return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, overwrite));
}
string
@@ -472,15 +405,45 @@ PictureAsset::key_type () const
return "MDIK";
}
-StereoPictureAsset::StereoPictureAsset (boost::filesystem::path directory, string mxf_name, int fps, Size size)
- : PictureAsset (directory, mxf_name, 0, fps, 0, size)
+shared_ptr<PictureAssetWriter>
+StereoPictureAsset::start_write (bool overwrite)
{
+ return shared_ptr<StereoPictureAssetWriter> (new StereoPictureAssetWriter (this, overwrite));
+}
+string
+MonoPictureAsset::cpl_node_name () const
+{
+ return "MainPicture";
}
-shared_ptr<PictureAssetWriter>
-StereoPictureAsset::start_write (bool overwrite, bool interop, MXFMetadata const & metadata)
+int
+MonoPictureAsset::edit_rate_factor () const
+{
+ return 1;
+}
+
+string
+StereoPictureAsset::cpl_node_name () const
{
- return shared_ptr<StereoPictureAssetWriter> (new StereoPictureAssetWriter (this, overwrite, interop, metadata));
+ return "msp-cpl:MainStereoscopicPicture";
+}
+
+pair<string, string>
+StereoPictureAsset::cpl_node_attribute (bool interop) const
+{
+ if (interop) {
+ return make_pair ("xmlns:msp-cpl", "http://www.digicine.com/schemas/437-Y/2007/Main-Stereo-Picture-CPL");
+ } else {
+ return make_pair ("xmlns:msp-cpl", "http://www.smpte-ra.org/schemas/429-10/2008/Main-Stereo-Picture-CPL");
+ }
+
+ return make_pair ("", "");
+}
+
+int
+StereoPictureAsset::edit_rate_factor () const
+{
+ return 2;
}
diff --git a/src/picture_asset.h b/src/picture_asset.h
index 495c6647..d1b097fa 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -48,31 +48,15 @@ public:
*/
PictureAsset (boost::filesystem::path directory, std::string mxf_name);
- /** Construct a PictureAsset.
- * This class will not write anything to disk in this constructor, but subclasses may.
- *
- * @param directory Directory where MXF file is.
- * @param mxf_name Name of MXF file.
- * @param progress Signal to use to inform of progres, or 0.
- * @param fps Video frames per second.
- * @param intrinsic_duration Total number of frames in the asset.
- * @param size Size of video frame images in pixels.
- */
- PictureAsset (
- boost::filesystem::path directory,
- std::string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- Size
- );
-
/** Start a progressive write to this asset.
* @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.
- * @param metadata MXF metadata to use.
*/
- virtual boost::shared_ptr<PictureAssetWriter> start_write (bool overwrite, bool interop, MXFMetadata const & metadata = MXFMetadata ()) = 0;
+ virtual boost::shared_ptr<PictureAssetWriter> 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)>) {}
bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
@@ -80,6 +64,10 @@ public:
return _size;
}
+ void set_size (Size s) {
+ _size = s;
+ }
+
void write_to_cpl (xmlpp::Element *, bool) const;
protected:
@@ -101,70 +89,14 @@ private:
class MonoPictureAsset : public PictureAsset
{
public:
- /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
- * This may take some time; progress is indicated by emission of the Progress signal.
- *
- * @param files Pathnames of JPEG2000 files, in frame order.
- * @param directory Directory in which to create MXF file.
- * @param mxf_name Name of MXF file to create.
- * @param progress Signal to inform of progress.
- * @param fps Video frames per second.
- * @param intrinsic_duration Total number of frames in the asset.
- * @param size Size of images in pixels.
- */
- MonoPictureAsset (
- std::vector<boost::filesystem::path> const & files,
- boost::filesystem::path directory,
- std::string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- Size size,
- bool interop,
- MXFMetadata const & metadata = MXFMetadata ()
- );
-
- /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
- * This may take some time; progress is indicated by emission of the Progress signal.
- *
- * @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
- * @param directory Directory in which to create MXF file.
- * @param mxf_name Name of MXF file to create.
- * @param progress Signal to inform of progress.
- * @param fps Video frames per second.
- * @param intrinsic_duration Total number of frames in the asset.
- * @param size Size of images in pixels.
- */
- MonoPictureAsset (
- boost::function<boost::filesystem::path (int)> get_path,
- boost::filesystem::path directory,
- std::string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- Size size,
- bool interop,
- MXFMetadata const & metadata = MXFMetadata ()
- );
-
- /** Construct a MonoPictureAsset, reading the MXF from disk.
- * @param directory Directory that the MXF is in.
- * @param mxf_name The filename of the MXF within `directory'.
- */
MonoPictureAsset (boost::filesystem::path directory, std::string mxf_name);
- /** Construct a MonoPictureAsset for progressive writing using
- * start_write() and a MonoPictureAssetWriter.
- *
- * @param directory Directory to put the MXF in.
- * @param mxf_name Filename of the MXF within this directory.
- * @param fps Video frames per second.
- * @param size Size in pixels that the picture frames will be.
- */
- MonoPictureAsset (boost::filesystem::path directory, std::string mxf_name, int fps, Size size);
+ void read ();
+ void create (std::vector<boost::filesystem::path> const & files);
+ void create (boost::function<boost::filesystem::path (int)> get_path);
/** Start a progressive write to a MonoPictureAsset */
- boost::shared_ptr<PictureAssetWriter> start_write (bool, bool, MXFMetadata const & metadata = MXFMetadata ());
+ boost::shared_ptr<PictureAssetWriter> start_write (bool);
boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
@@ -180,20 +112,12 @@ private:
class StereoPictureAsset : public PictureAsset
{
public:
- StereoPictureAsset (boost::filesystem::path directory, std::string mxf_name, int fps, int intrinsic_duration);
-
- /** Construct a StereoPictureAsset for progressive writing using
- * start_write() and a StereoPictureAssetWriter.
- *
- * @param directory Directory to put the MXF in.
- * @param mxf_name Filename of the MXF within this directory.
- * @param fps Video frames per second.
- * @param size Size in pixels that the picture frames will be.
- */
- StereoPictureAsset (boost::filesystem::path directory, std::string mxf_name, int fps, Size size);
+ StereoPictureAsset (boost::filesystem::path directory, std::string mxf_name);
+ void read ();
+
/** Start a progressive write to a StereoPictureAsset */
- boost::shared_ptr<PictureAssetWriter> start_write (bool, bool, MXFMetadata const & metadata = MXFMetadata ());
+ boost::shared_ptr<PictureAssetWriter> start_write (bool);
boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
diff --git a/src/picture_asset_writer.cc b/src/picture_asset_writer.cc
index f5767e3d..ca5a3e96 100644
--- a/src/picture_asset_writer.cc
+++ b/src/picture_asset_writer.cc
@@ -52,14 +52,12 @@ FrameInfo::write (ostream& s)
}
-PictureAssetWriter::PictureAssetWriter (PictureAsset* asset, bool overwrite, bool interop, MXFMetadata const & metadata)
+PictureAssetWriter::PictureAssetWriter (PictureAsset* asset, bool overwrite)
: _asset (asset)
, _frames_written (0)
, _started (false)
, _finalized (false)
, _overwrite (overwrite)
- , _interop (interop)
- , _metadata (metadata)
{
}
@@ -90,15 +88,15 @@ struct StereoPictureAssetWriter::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.
*/
-MonoPictureAssetWriter::MonoPictureAssetWriter (PictureAsset* asset, bool overwrite, bool interop, MXFMetadata const & metadata)
- : PictureAssetWriter (asset, overwrite, interop, metadata)
+MonoPictureAssetWriter::MonoPictureAssetWriter (PictureAsset* asset, bool overwrite)
+ : PictureAssetWriter (asset, overwrite)
, _state (new MonoPictureAssetWriter::ASDCPState)
{
_state->encryption_context = asset->encryption_context ();
}
-StereoPictureAssetWriter::StereoPictureAssetWriter (PictureAsset* asset, bool overwrite, bool interop, MXFMetadata const & metadata)
- : PictureAssetWriter (asset, overwrite, interop, metadata)
+StereoPictureAssetWriter::StereoPictureAssetWriter (PictureAsset* asset, bool overwrite)
+ : PictureAssetWriter (asset, overwrite)
, _state (new StereoPictureAssetWriter::ASDCPState)
, _next_eye (EYE_LEFT)
{
@@ -115,7 +113,7 @@ void libdcp::start (PictureAssetWriter* writer, shared_ptr<P> state, Q* asset, u
state->j2k_parser.FillPictureDescriptor (state->picture_descriptor);
state->picture_descriptor.EditRate = ASDCP::Rational (asset->edit_rate(), 1);
- asset->fill_writer_info (&state->writer_info, asset->uuid(), writer->_interop, writer->_metadata);
+ asset->fill_writer_info (&state->writer_info, asset->uuid(), writer->_asset->interop(), writer->_asset->metadata());
if (ASDCP_FAILURE (state->mxf_writer.OpenWrite (
asset->path().string().c_str(),
diff --git a/src/picture_asset_writer.h b/src/picture_asset_writer.h
index b6d2e92c..fd4f81ee 100644
--- a/src/picture_asset_writer.h
+++ b/src/picture_asset_writer.h
@@ -58,7 +58,7 @@ protected:
template <class P, class Q>
friend void start (PictureAssetWriter *, boost::shared_ptr<P>, Q *, uint8_t *, int);
- PictureAssetWriter (PictureAsset *, bool, bool, MXFMetadata const &);
+ PictureAssetWriter (PictureAsset *, bool);
PictureAsset* _asset;
@@ -71,8 +71,6 @@ protected:
/** true if finalize() has been called */
bool _finalized;
bool _overwrite;
- bool _interop;
- MXFMetadata _metadata;
};
/** A helper class for writing to MonoPictureAssets progressively (i.e. writing frame-by-frame,
@@ -95,7 +93,7 @@ public:
private:
friend class MonoPictureAsset;
- MonoPictureAssetWriter (PictureAsset *, bool, bool, MXFMetadata const &);
+ MonoPictureAssetWriter (PictureAsset *, bool);
void start (uint8_t *, int);
/* do this with an opaque pointer so we don't have to include
@@ -126,7 +124,7 @@ public:
private:
friend class StereoPictureAsset;
- StereoPictureAssetWriter (PictureAsset *, bool, bool, MXFMetadata const &);
+ StereoPictureAssetWriter (PictureAsset *, bool);
void start (uint8_t *, int);
/* do this with an opaque pointer so we don't have to include
diff --git a/src/sound_asset.cc b/src/sound_asset.cc
index 984d8f0f..ec82752c 100644
--- a/src/sound_asset.cc
+++ b/src/sound_asset.cc
@@ -42,48 +42,22 @@ using boost::shared_ptr;
using boost::lexical_cast;
using namespace libdcp;
-SoundAsset::SoundAsset (
- vector<boost::filesystem::path> const & files,
- boost::filesystem::path directory,
- string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- bool interop,
- MXFMetadata const & metadata
- )
- : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
- , _channels (files.size ())
+SoundAsset::SoundAsset (boost::filesystem::path directory, string mxf_name)
+ : MXFAsset (directory, mxf_name)
+ , _channels (0)
, _sampling_rate (0)
{
- assert (_channels);
-
- construct (boost::bind (&SoundAsset::path_from_channel, this, _1, files), interop, metadata);
+
}
-SoundAsset::SoundAsset (
- boost::function<boost::filesystem::path (Channel)> get_path,
- boost::filesystem::path directory,
- string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- int channels,
- bool interop,
- MXFMetadata const & metadata
- )
- : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
- , _channels (channels)
- , _sampling_rate (0)
+void
+SoundAsset::create (vector<boost::filesystem::path> const & files)
{
- assert (_channels);
-
- construct (get_path, interop, metadata);
+ create (boost::bind (&SoundAsset::path_from_channel, this, _1, files));
}
-SoundAsset::SoundAsset (boost::filesystem::path directory, string mxf_name)
- : MXFAsset (directory, mxf_name)
- , _channels (0)
+void
+SoundAsset::read ()
{
ASDCP::PCM::MXFReader reader;
if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
@@ -102,14 +76,6 @@ SoundAsset::SoundAsset (boost::filesystem::path directory, string mxf_name)
_intrinsic_duration = desc.ContainerDuration;
}
-SoundAsset::SoundAsset (boost::filesystem::path directory, string mxf_name, int fps, int channels, int sampling_rate)
- : MXFAsset (directory, mxf_name, 0, fps, 0)
- , _channels (channels)
- , _sampling_rate (sampling_rate)
-{
-
-}
-
boost::filesystem::path
SoundAsset::path_from_channel (Channel channel, vector<boost::filesystem::path> const & files)
{
@@ -119,10 +85,11 @@ SoundAsset::path_from_channel (Channel channel, vector<boost::filesystem::path>
}
void
-SoundAsset::construct (boost::function<boost::filesystem::path (Channel)> get_path, bool interop, MXFMetadata const & metadata)
+SoundAsset::create (boost::function<boost::filesystem::path (Channel)> get_path)
{
ASDCP::Rational asdcp_edit_rate (_edit_rate, 1);
+ assert (_channels > 0);
ASDCP::PCM::WAVParser pcm_parser_channel[_channels];
if (pcm_parser_channel[0].OpenRead (get_path(LEFT).c_str(), asdcp_edit_rate)) {
boost::throw_exception (FileError ("could not open WAV file for reading", get_path(LEFT)));
@@ -172,7 +139,7 @@ SoundAsset::construct (boost::function<boost::filesystem::path (Channel)> get_pa
frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (audio_desc));
ASDCP::WriterInfo writer_info;
- MXFAsset::fill_writer_info (&writer_info, _uuid, interop, metadata);
+ MXFAsset::fill_writer_info (&writer_info, _uuid, _interop, _metadata);
ASDCP::PCM::MXFWriter mxf_writer;
if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, audio_desc))) {
@@ -304,10 +271,10 @@ SoundAsset::get_frame (int n) const
}
shared_ptr<SoundAssetWriter>
-SoundAsset::start_write (bool interop, MXFMetadata const & metadata)
+SoundAsset::start_write ()
{
/* XXX: can't we use a shared_ptr here? */
- return shared_ptr<SoundAssetWriter> (new SoundAssetWriter (this, interop, metadata));
+ return shared_ptr<SoundAssetWriter> (new SoundAssetWriter (this));
}
struct SoundAssetWriter::ASDCPState
@@ -319,13 +286,12 @@ struct SoundAssetWriter::ASDCPState
ASDCP::AESEncContext* encryption_context;
};
-SoundAssetWriter::SoundAssetWriter (SoundAsset* a, bool interop, MXFMetadata const & m)
+SoundAssetWriter::SoundAssetWriter (SoundAsset* a)
: _state (new SoundAssetWriter::ASDCPState)
, _asset (a)
, _finalized (false)
, _frames_written (0)
, _frame_buffer_offset (0)
- , _metadata (m)
{
_state->encryption_context = a->encryption_context ();
@@ -344,7 +310,7 @@ SoundAssetWriter::SoundAssetWriter (SoundAsset* a, bool interop, MXFMetadata con
_state->frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (_state->audio_desc));
memset (_state->frame_buffer.Data(), 0, _state->frame_buffer.Capacity());
- _asset->fill_writer_info (&_state->writer_info, _asset->uuid (), interop, _metadata);
+ _asset->fill_writer_info (&_state->writer_info, _asset->uuid (), _asset->interop(), _asset->metadata());
if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().string().c_str(), _state->writer_info, _state->audio_desc))) {
boost::throw_exception (FileError ("could not open audio MXF for writing", _asset->path().string()));
diff --git a/src/sound_asset.h b/src/sound_asset.h
index 1d2a4755..d41b72d5 100644
--- a/src/sound_asset.h
+++ b/src/sound_asset.h
@@ -43,7 +43,7 @@ public:
private:
friend class SoundAsset;
- SoundAssetWriter (SoundAsset *, bool interop, MXFMetadata const &);
+ SoundAssetWriter (SoundAsset *);
/* no copy construction */
SoundAssetWriter (SoundAssetWriter const &);
@@ -62,76 +62,27 @@ private:
bool _finalized;
int _frames_written;
int _frame_buffer_offset;
- MXFMetadata _metadata;
};
/** @brief An asset made up of WAV files */
class SoundAsset : public MXFAsset
{
public:
- /** Construct a SoundAsset, generating the MXF from some WAV files.
- * This may take some time; progress is indicated by emission of the Progress signal.
- * @param files Pathnames of sound files, in the order Left, Right, Centre, Lfe (sub), Left surround, Right surround.
- * @param directory Directory in which to create MXF file.
- * @param mxf_name Name of MXF file to create.
- * @param progress Signal to inform of progress.
- * @param fps Frames per second.
- * @param length Length in frames.
- * @param start_frame Frame in the source to start writing from.
- * @param intrinsic_duration Length of the whole asset in frames.
- * Note that this is different to entry_point in that the asset will contain no data before start_frame.
- */
- SoundAsset (
- std::vector<boost::filesystem::path> const & files,
- boost::filesystem::path directory,
- std::string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- bool interop,
- MXFMetadata const & metadata = MXFMetadata ()
- );
-
- /** Construct a SoundAsset, generating the MXF from some WAV files.
- * This may take some time; progress is indicated by emission of the Progress signal.
- * @param get_path Functor which returns a WAV file path for a given channel.
- * @param directory Directory in which to create MXF file.
- * @param mxf_name Name of MXF file to create.
- * @param progress Signal to inform of progress.
- * @param fps Frames per second.
- * @param intrinsic_duration Length of the whole asset in frames.
- * @param channels Number of audio channels.
- */
- SoundAsset (
- boost::function<boost::filesystem::path (Channel)> get_path,
- boost::filesystem::path directory,
- std::string mxf_name,
- boost::signals2::signal<void (float)>* progress,
- int fps,
- int intrinsic_duration,
- int channels,
- bool interop,
- MXFMetadata const & metadata = MXFMetadata ()
- );
-
- SoundAsset (
- boost::filesystem::path directory,
- std::string mxf_name
- );
-
- SoundAsset (
- boost::filesystem::path directory,
- std::string mxf_name,
- int fps,
- int channels,
- int sampling_rate
- );
-
- boost::shared_ptr<SoundAssetWriter> start_write (bool, MXFMetadata const & metadata = MXFMetadata ());
+ SoundAsset (boost::filesystem::path directory, std::string mxf_name);
+
+ void read ();
+ void create (std::vector<boost::filesystem::path> const & files);
+ void create (boost::function<boost::filesystem::path (Channel)> get_path);
+
+ boost::shared_ptr<SoundAssetWriter> start_write ();
bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
boost::shared_ptr<const SoundFrame> get_frame (int n) const;
+
+ void set_channels (int c) {
+ _channels = c;
+ }
int channels () const {
return _channels;
@@ -143,7 +94,7 @@ public:
private:
std::string key_type () const;
- void construct (boost::function<boost::filesystem::path (Channel)> get_path, bool interop, MXFMetadata const &);
+ void construct (boost::function<boost::filesystem::path (Channel)> get_path);
boost::filesystem::path path_from_channel (Channel channel, std::vector<boost::filesystem::path> const & files);
std::string cpl_node_name () const;