diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-02-02 12:47:49 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-02-02 12:47:49 +0000 |
| commit | fad33631d56d1cf92aff6463cd3ceea8eb494149 (patch) | |
| tree | e68d16d3a7e07c120799cfd80081f3885b24f081 /src | |
| parent | bb41c81485834a31c178cf2b2f4b5345aa00e5b4 (diff) | |
Tweak API a little.
Diffstat (limited to 'src')
| -rw-r--r-- | src/picture_asset.cc | 24 | ||||
| -rw-r--r-- | src/picture_asset.h | 7 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/picture_asset.cc b/src/picture_asset.cc index b6120171..d63cdee0 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -397,10 +397,10 @@ StereoPictureAsset::get_frame (int n) const } shared_ptr<MonoPictureAssetWriter> -MonoPictureAsset::start_write (uint8_t* data, int size, bool overwrite) +MonoPictureAsset::start_write (bool overwrite) { /* XXX: can't we use a shared_ptr here? */ - return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, data, size, overwrite)); + return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, overwrite)); } FrameInfo::FrameInfo (istream& s) @@ -431,11 +431,20 @@ struct MonoPictureAssetWriter::ASDCPState /** @param a Asset to write to. `a' must not be deleted while * this writer class still exists, or bad things will happen. */ -MonoPictureAssetWriter::MonoPictureAssetWriter (MonoPictureAsset* a, uint8_t* data, int size, bool overwrite) +MonoPictureAssetWriter::MonoPictureAssetWriter (MonoPictureAsset* a, bool overwrite) : _state (new MonoPictureAssetWriter::ASDCPState) , _asset (a) , _frames_written (0) + , _started (false) , _finalized (false) + , _overwrite (overwrite) +{ + +} + + +void +MonoPictureAssetWriter::start (uint8_t* data, int size) { if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) { throw MiscError ("could not parse J2K frame"); @@ -451,11 +460,13 @@ MonoPictureAssetWriter::MonoPictureAssetWriter (MonoPictureAsset* a, uint8_t* da _state->writer_info, _state->picture_descriptor, 16384, - overwrite) + _overwrite) )) { throw MXFFileError ("could not open MXF file for writing", _asset->path().string()); } + + _started = true; } FrameInfo @@ -463,6 +474,10 @@ MonoPictureAssetWriter::write (uint8_t* data, int size) { assert (!_finalized); + if (!_started) { + start (data, size); + } + if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) { throw MiscError ("could not parse J2K frame"); } @@ -481,6 +496,7 @@ MonoPictureAssetWriter::write (uint8_t* data, int size) void MonoPictureAssetWriter::fake_write (int size) { + assert (_started); assert (!_finalized); if (ASDCP_FAILURE (_state->mxf_writer.FakeWriteFrame (size))) { diff --git a/src/picture_asset.h b/src/picture_asset.h index 2ec17235..d3fabbbd 100644 --- a/src/picture_asset.h +++ b/src/picture_asset.h @@ -121,7 +121,8 @@ public: private: friend class MonoPictureAsset; - MonoPictureAssetWriter (MonoPictureAsset *, uint8_t *, int, bool); + MonoPictureAssetWriter (MonoPictureAsset *, bool); + void start (uint8_t *, int); /* no copy construction */ MonoPictureAssetWriter (MonoPictureAssetWriter const &); @@ -137,8 +138,10 @@ private: MonoPictureAsset* _asset; /** Number of picture frames written to the asset so far */ int _frames_written; + bool _started; /** true if finalize() has been called */ bool _finalized; + bool _overwrite; }; /** A 2D (monoscopic) picture asset */ @@ -204,7 +207,7 @@ public: MonoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size); /** Start a progressive write to a MonoPictureAsset */ - boost::shared_ptr<MonoPictureAssetWriter> start_write (uint8_t *, int, bool); + boost::shared_ptr<MonoPictureAssetWriter> start_write (bool); 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; |
