summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-22 17:26:11 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-22 17:26:11 +0100
commit64fa6bfcdff322541a6afe7f079890a109cd4f71 (patch)
tree4363b51ff9a0688c38a32bb43c5da4112ecb326b
parentbfbd64d680a0cbe9867b23088023ae5f9ecc219b (diff)
Various more 3D fixes.
-rwxr-xr-xasdcplib/src/AS_DCP.h11
-rwxr-xr-xasdcplib/src/AS_DCP_JP2K.cpp33
-rw-r--r--src/picture_asset_writer.cc61
-rw-r--r--src/picture_asset_writer.h12
4 files changed, 76 insertions, 41 deletions
diff --git a/asdcplib/src/AS_DCP.h b/asdcplib/src/AS_DCP.h
index 2681bf14..3edd1f74 100755
--- a/asdcplib/src/AS_DCP.h
+++ b/asdcplib/src/AS_DCP.h
@@ -1268,11 +1268,11 @@ namespace ASDCP {
virtual MXF::OPAtomHeader& OPAtomHeader();
virtual MXF::OPAtomIndexFooter& OPAtomIndexFooter();
- // Open the file for writing. The file must not exist. Returns error if
+ // Open the file for writing. The file must not exist unless overwrite is true. Returns error if
// the operation cannot be completed or if nonsensical data is discovered
// in the essence descriptor.
Result_t OpenWrite(const char* filename, const WriterInfo&,
- const PictureDescriptor&, ui32_t HeaderSize = 16384);
+ const PictureDescriptor&, ui32_t HeaderSize, bool overwrite);
// Writes a pair of frames of essence to the MXF file. If the optional AESEncContext
// argument is present, the essence is encrypted prior to writing.
@@ -1287,11 +1287,16 @@ namespace ASDCP {
// RESULT_SPHASE will be returned if phase is reversed. The first frame
// written must be left eye.
Result_t WriteFrame(const FrameBuffer&, StereoscopicPhase_t phase,
- AESEncContext* = 0, HMACContext* = 0);
+ AESEncContext* = 0, HMACContext* = 0, std::string* hash = 0);
+ Result_t FakeWriteFrame(int size);
+
// Closes the MXF file, writing the index and revised header. Returns
// RESULT_SPHASE if WriteFrame was called an odd number of times.
Result_t Finalize();
+
+ // Return the current file offset in the MXF file that we are writing
+ ui64_t Tell() const;
};
//
diff --git a/asdcplib/src/AS_DCP_JP2K.cpp b/asdcplib/src/AS_DCP_JP2K.cpp
index e67bd8df..903b2e85 100755
--- a/asdcplib/src/AS_DCP_JP2K.cpp
+++ b/asdcplib/src/AS_DCP_JP2K.cpp
@@ -1182,7 +1182,7 @@ public:
//
Result_t WriteFrame(const FrameBuffer& FrameBuf, StereoscopicPhase_t phase,
- AESEncContext* Ctx, HMACContext* HMAC)
+ AESEncContext* Ctx, HMACContext* HMAC, std::string* hash)
{
if ( m_NextPhase != phase )
return RESULT_SPHASE;
@@ -1190,11 +1190,11 @@ public:
if ( phase == SP_LEFT )
{
m_NextPhase = SP_RIGHT;
- return lh__Writer::WriteFrame(FrameBuf, true, Ctx, HMAC);
+ return lh__Writer::WriteFrame(FrameBuf, true, Ctx, HMAC, hash);
}
m_NextPhase = SP_LEFT;
- return lh__Writer::WriteFrame(FrameBuf, false, Ctx, HMAC);
+ return lh__Writer::WriteFrame(FrameBuf, false, Ctx, HMAC, hash);
}
//
@@ -1253,7 +1253,7 @@ ASDCP::JP2K::MXFSWriter::OPAtomIndexFooter()
// the operation cannot be completed.
ASDCP::Result_t
ASDCP::JP2K::MXFSWriter::OpenWrite(const char* filename, const WriterInfo& Info,
- const PictureDescriptor& PDesc, ui32_t HeaderSize)
+ const PictureDescriptor& PDesc, ui32_t HeaderSize, bool overwrite)
{
if ( Info.LabelSetType == LS_MXF_SMPTE )
m_Writer = new h__SWriter(DefaultSMPTEDict());
@@ -1276,7 +1276,7 @@ ASDCP::JP2K::MXFSWriter::OpenWrite(const char* filename, const WriterInfo& Info,
m_Writer->m_Info = Info;
- Result_t result = m_Writer->OpenWrite(filename, ASDCP::ESS_JPEG_2000_S, HeaderSize, false);
+ Result_t result = m_Writer->OpenWrite(filename, ASDCP::ESS_JPEG_2000_S, HeaderSize, overwrite);
if ( ASDCP_SUCCESS(result) )
{
@@ -1315,10 +1315,10 @@ ASDCP::JP2K::MXFSWriter::WriteFrame(const SFrameBuffer& FrameBuf, AESEncContext*
if ( m_Writer.empty() )
return RESULT_INIT;
- Result_t result = m_Writer->WriteFrame(FrameBuf.Left, SP_LEFT, Ctx, HMAC);
+ Result_t result = m_Writer->WriteFrame(FrameBuf.Left, SP_LEFT, Ctx, HMAC, 0);
if ( ASDCP_SUCCESS(result) )
- result = m_Writer->WriteFrame(FrameBuf.Right, SP_RIGHT, Ctx, HMAC);
+ result = m_Writer->WriteFrame(FrameBuf.Right, SP_RIGHT, Ctx, HMAC, 0);
return result;
}
@@ -1329,12 +1329,21 @@ ASDCP::JP2K::MXFSWriter::WriteFrame(const SFrameBuffer& FrameBuf, AESEncContext*
// error occurs.
ASDCP::Result_t
ASDCP::JP2K::MXFSWriter::WriteFrame(const FrameBuffer& FrameBuf, StereoscopicPhase_t phase,
- AESEncContext* Ctx, HMACContext* HMAC)
+ AESEncContext* Ctx, HMACContext* HMAC, std::string* hash)
{
if ( m_Writer.empty() )
return RESULT_INIT;
- return m_Writer->WriteFrame(FrameBuf, phase, Ctx, HMAC);
+ return m_Writer->WriteFrame(FrameBuf, phase, Ctx, HMAC, hash);
+}
+
+ASDCP::Result_t
+ASDCP::JP2K::MXFSWriter::FakeWriteFrame(int size)
+{
+ if ( m_Writer.empty() )
+ return RESULT_INIT;
+
+ return m_Writer->FakeWriteFrame(size, true);
}
// Closes the MXF file, writing the index and other closing information.
@@ -1347,6 +1356,12 @@ ASDCP::JP2K::MXFSWriter::Finalize()
return m_Writer->Finalize();
}
+ui64_t
+ASDCP::JP2K::MXFSWriter::Tell() const
+{
+ return m_Writer->m_File.Tell();
+}
+
//
// end AS_DCP_JP2K.cpp
//
diff --git a/src/picture_asset_writer.cc b/src/picture_asset_writer.cc
index 748de2db..18e509d6 100644
--- a/src/picture_asset_writer.cc
+++ b/src/picture_asset_writer.cc
@@ -71,7 +71,7 @@ struct StereoPictureAssetWriter::ASDCPState
{}
ASDCP::JP2K::CodestreamParser j2k_parser;
- ASDCP::JP2K::SFrameBuffer frame_buffer;
+ ASDCP::JP2K::FrameBuffer frame_buffer;
ASDCP::JP2K::MXFSWriter mxf_writer;
ASDCP::WriterInfo writer_info;
ASDCP::JP2K::PictureDescriptor picture_descriptor;
@@ -97,7 +97,7 @@ StereoPictureAssetWriter::StereoPictureAssetWriter (StereoPictureAsset* asset, b
}
template <class P, class Q>
-void start (PictureAssetWriter* writer, shared_ptr<P> state, Q* asset, uint8_t* data, int size)
+void libdcp::start (PictureAssetWriter* writer, shared_ptr<P> state, Q* asset, uint8_t* data, int size)
{
if (ASDCP_FAILURE (state->j2k_parser.OpenReadFrame (data, size, state->frame_buffer))) {
boost::throw_exception (MiscError ("could not parse J2K frame"));
@@ -125,49 +125,66 @@ void start (PictureAssetWriter* writer, shared_ptr<P> state, Q* asset, uint8_t*
void
MonoPictureAssetWriter::start (uint8_t* data, int size)
{
- ::start (this, _state, _asset, data, size);
+ libdcp::start (this, _state, _asset, data, size);
}
void
StereoPictureAssetWriter::start (uint8_t* data, int size)
{
- ::start (this, _state, _asset, data, size);
+ libdcp::start (this, _state, _asset, data, size);
}
-template <class P, class Q>
-FrameInfo write (PictureAssetWriter* writer, shared_ptr<P> state, Q* asset, uint8_t* data, int size)
+FrameInfo
+MonoPictureAssetWriter::write (uint8_t* data, int size)
{
- assert (!writer->_finalized);
+ assert (!_finalized);
- if (!writer->_started) {
- writer->start (data, size);
+ if (!_started) {
+ start (data, size);
}
- if (ASDCP_FAILURE (state->j2k_parser.OpenReadFrame (data, size, state->frame_buffer))) {
+ if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
boost::throw_exception (MiscError ("could not parse J2K frame"));
}
- uint64_t const before_offset = state->mxf_writer.Tell ();
+ uint64_t const before_offset = _state->mxf_writer.Tell ();
string hash;
- if (ASDCP_FAILURE (state->mxf_writer.WriteFrame (state->frame_buffer, 0, 0, &hash))) {
- boost::throw_exception (MXFFileError ("error in writing video MXF", asset->path().string()));
+ if (ASDCP_FAILURE (_state->mxf_writer.WriteFrame (_state->frame_buffer, 0, 0, &hash))) {
+ boost::throw_exception (MXFFileError ("error in writing video MXF", _asset->path().string()));
}
- ++asset->_frames_written;
- return FrameInfo (before_offset, state->mxf_writer.Tell() - before_offset, hash);
+ ++_frames_written;
+ return FrameInfo (before_offset, _state->mxf_writer.Tell() - before_offset, hash);
}
FrameInfo
-MonoPictureAssetWriter::write (uint8_t* data, int size)
+StereoPictureAssetWriter::write (uint8_t* data, int size, Eye eye)
{
- return ::write (this, _state, _asset, data, size);
-}
+ assert (!_finalized);
-FrameInfo
-StereoPictureAssetWriter::write (uint8_t* data, int size)
-{
- return ::write (this, _state, _asset, data, size);
+ if (!_started) {
+ start (data, size);
+ }
+
+ if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
+ boost::throw_exception (MiscError ("could not parse J2K frame"));
+ }
+
+ uint64_t const before_offset = _state->mxf_writer.Tell ();
+
+ string hash;
+ if (ASDCP_FAILURE (_state->mxf_writer.WriteFrame (
+ _state->frame_buffer,
+ (eye == EYE_LEFT) ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT,
+ 0, 0, &hash)
+ )) {
+
+ boost::throw_exception (MXFFileError ("error in writing video MXF", _asset->path().string()));
+ }
+
+ ++_frames_written;
+ return FrameInfo (before_offset, _state->mxf_writer.Tell() - before_offset, hash);
}
void
diff --git a/src/picture_asset_writer.h b/src/picture_asset_writer.h
index 5c2b0fef..951633bf 100644
--- a/src/picture_asset_writer.h
+++ b/src/picture_asset_writer.h
@@ -23,6 +23,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include "metadata.h"
+#include "types.h"
namespace libdcp {
@@ -49,14 +50,11 @@ struct FrameInfo
class PictureAssetWriter : public boost::noncopyable
{
public:
- virtual FrameInfo write (uint8_t *, int) = 0;
- virtual void fake_write (int) = 0;
- virtual void finalize () = 0;
-
protected:
+ template <class P, class Q>
+ friend void start (PictureAssetWriter *, boost::shared_ptr<P>, Q *, uint8_t *, int);
PictureAssetWriter (bool, MXFMetadata const &);
- virtual void start (uint8_t *, int) = 0;
/** Number of picture frames written to the asset so far */
int _frames_written;
@@ -80,7 +78,7 @@ protected:
class MonoPictureAssetWriter : public PictureAssetWriter
{
public:
- FrameInfo write (uint8_t* data, int size);
+ FrameInfo write (uint8_t *, int);
void fake_write (int size);
void finalize ();
@@ -103,7 +101,7 @@ private:
class StereoPictureAssetWriter : public PictureAssetWriter
{
public:
- FrameInfo write (uint8_t* data, int size);
+ FrameInfo write (uint8_t *, int, Eye);
void fake_write (int size);
void finalize ();