summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-02-01 21:12:06 +0000
committerCarl Hetherington <cth@carlh.net>2013-02-01 21:12:06 +0000
commitfe4c98bdc865290d10e70ebab7e48247d390f4c4 (patch)
treefe7ea4bc09543298a0897f87a78b2edbc85ed206 /src
parent5724ce48e44192ae0f303ea93cbecf7936700193 (diff)
Unfinished attempt to overwrite existing; tricky because you need to delay writes of the MXF header until you know lots of stuff about the JP2K file (to fill in the picture descriptor).
Diffstat (limited to 'src')
-rw-r--r--src/picture_asset.cc42
-rw-r--r--src/picture_asset.h5
2 files changed, 41 insertions, 6 deletions
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index d242777c..11815761 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -207,7 +207,7 @@ MonoPictureAsset::construct (boost::function<string (int)> get_path)
fill_writer_info (&writer_info, _uuid);
ASDCP::JP2K::MXFWriter mxf_writer;
- if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc))) {
+ if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc, 16384, false))) {
throw MXFFileError ("could not open MXF file for writing", path().string());
}
@@ -399,7 +399,14 @@ shared_ptr<MonoPictureAssetWriter>
MonoPictureAsset::start_write ()
{
/* XXX: can't we use a shared_ptr here? */
- return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this));
+ return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, false));
+}
+
+shared_ptr<MonoPictureAssetWriter>
+MonoPictureAsset::start_overwrite ()
+{
+ /* XXX: can't we use a shared_ptr here? */
+ return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, true));
}
FrameInfo::FrameInfo (istream& s)
@@ -455,8 +462,8 @@ MonoPictureAssetWriter::write (uint8_t* data, int size)
_state->picture_descriptor.EditRate = ASDCP::Rational (_asset->edit_rate(), 1);
MXFAsset::fill_writer_info (&_state->writer_info, _asset->uuid());
-
- if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().string().c_str(), _state->writer_info, _state->picture_descriptor))) {
+
+ if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().string().c_str(), _state->writer_info, _state->picture_descriptor, 16384, false))) {
throw MXFFileError ("could not open MXF file for writing", _asset->path().string());
}
}
@@ -468,11 +475,36 @@ MonoPictureAssetWriter::write (uint8_t* data, int size)
throw MiscError ("error in writing video MXF");
}
- _frames_written++;
+ ++_frames_written;
return FrameInfo (before_offset, _state->mxf_writer.Tell() - before_offset, hash);
}
void
+MonoPictureAssetWriter::fake_write (int size)
+{
+ assert (!_finalized);
+
+ if (_frames_written == 0) {
+ /* This is our first frame; set up the writer */
+
+ _state->j2k_parser.FillPictureDescriptor (_state->picture_descriptor);
+ _state->picture_descriptor.EditRate = ASDCP::Rational (_asset->edit_rate(), 1);
+
+ MXFAsset::fill_writer_info (&_state->writer_info, _asset->uuid());
+
+ if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().string().c_str(), _state->writer_info, _state->picture_descriptor, 16384, true))) {
+ throw MXFFileError ("could not open MXF file for writing", _asset->path().string());
+ }
+ }
+
+ if (ASDCP_FAILURE (_state->mxf_writer.FakeWriteFrame (size))) {
+ throw MiscError ("error in writing video MXF");
+ }
+
+ ++_frames_written;
+}
+
+void
MonoPictureAssetWriter::finalize ()
{
if (ASDCP_FAILURE (_state->mxf_writer.Finalize())) {
diff --git a/src/picture_asset.h b/src/picture_asset.h
index 4e9e1dd7..9df85bad 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -115,12 +115,13 @@ public:
~MonoPictureAssetWriter ();
FrameInfo write (uint8_t* data, int size);
+ void fake_write (int size);
void finalize ();
private:
friend class MonoPictureAsset;
- MonoPictureAssetWriter (MonoPictureAsset *);
+ MonoPictureAssetWriter (MonoPictureAsset *, bool);
/* no copy construction */
MonoPictureAssetWriter (MonoPictureAssetWriter const &);
@@ -205,6 +206,8 @@ public:
/** Start a progressive write to a MonoPictureAsset */
boost::shared_ptr<MonoPictureAssetWriter> start_write ();
+ boost::shared_ptr<MonoPictureAssetWriter> start_overwrite ();
+
boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;