summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-02-02 12:04:23 +0000
committerCarl Hetherington <cth@carlh.net>2013-02-02 12:04:23 +0000
commitbb41c81485834a31c178cf2b2f4b5345aa00e5b4 (patch)
tree597621103a09e5639a73804c8b60204b7d85b588 /src
parentfe4c98bdc865290d10e70ebab7e48247d390f4c4 (diff)
Basics of fake write seem to work.
Diffstat (limited to 'src')
-rw-r--r--src/picture_asset.cc70
-rw-r--r--src/picture_asset.h12
2 files changed, 34 insertions, 48 deletions
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index 11815761..b6120171 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -44,6 +44,7 @@ using std::max;
using std::pair;
using std::make_pair;
using std::istream;
+using std::cout;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using boost::lexical_cast;
@@ -396,28 +397,21 @@ StereoPictureAsset::get_frame (int n) const
}
shared_ptr<MonoPictureAssetWriter>
-MonoPictureAsset::start_write ()
+MonoPictureAsset::start_write (uint8_t* data, int size, bool overwrite)
{
/* XXX: can't we use a shared_ptr here? */
- 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));
+ return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this, data, size, overwrite));
}
FrameInfo::FrameInfo (istream& s)
{
- s >> offset >> length >> hash;
+ s >> offset >> size >> hash;
}
void
FrameInfo::write (ostream& s)
{
- s << offset << " " << length << " " << hash;
+ s << offset << " " << size << " " << hash;
}
struct MonoPictureAssetWriter::ASDCPState
@@ -437,36 +431,41 @@ 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)
+MonoPictureAssetWriter::MonoPictureAssetWriter (MonoPictureAsset* a, uint8_t* data, int size, bool overwrite)
: _state (new MonoPictureAssetWriter::ASDCPState)
, _asset (a)
, _frames_written (0)
, _finalized (false)
{
+ if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
+ throw MiscError ("could not parse J2K frame");
+ }
+ _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,
+ overwrite)
+ )) {
+
+ throw MXFFileError ("could not open MXF file for writing", _asset->path().string());
+ }
}
FrameInfo
MonoPictureAssetWriter::write (uint8_t* data, int size)
{
assert (!_finalized);
-
- if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
- throw MiscError ("could not parse J2K frame");
- }
- 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, false))) {
- throw MXFFileError ("could not open MXF file for writing", _asset->path().string());
- }
- }
+ if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
+ throw MiscError ("could not parse J2K frame");
+ }
uint64_t const before_offset = _state->mxf_writer.Tell ();
@@ -484,19 +483,6 @@ 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");
}
@@ -507,6 +493,8 @@ MonoPictureAssetWriter::fake_write (int size)
void
MonoPictureAssetWriter::finalize ()
{
+ assert (!_finalized);
+
if (ASDCP_FAILURE (_state->mxf_writer.Finalize())) {
throw MiscError ("error in finalizing video MXF");
}
diff --git a/src/picture_asset.h b/src/picture_asset.h
index 9df85bad..2ec17235 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -84,9 +84,9 @@ class MonoPictureAsset;
struct FrameInfo
{
- FrameInfo (uint64_t o, uint64_t l, std::string h)
+ FrameInfo (uint64_t o, uint64_t s, std::string h)
: offset (o)
- , length (l)
+ , size (s)
, hash (h)
{}
@@ -95,7 +95,7 @@ struct FrameInfo
void write (std::ostream& s);
uint64_t offset;
- uint64_t length;
+ uint64_t size;
std::string hash;
};
@@ -121,7 +121,7 @@ public:
private:
friend class MonoPictureAsset;
- MonoPictureAssetWriter (MonoPictureAsset *, bool);
+ MonoPictureAssetWriter (MonoPictureAsset *, uint8_t *, int, bool);
/* no copy construction */
MonoPictureAssetWriter (MonoPictureAssetWriter const &);
@@ -204,9 +204,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 ();
-
- boost::shared_ptr<MonoPictureAssetWriter> start_overwrite ();
+ boost::shared_ptr<MonoPictureAssetWriter> start_write (uint8_t *, int, 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;