diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-06-18 15:07:41 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-06-18 15:07:41 +0100 |
| commit | c2bac22380bea453665a24c6f39200a977771daf (patch) | |
| tree | a464d94724318b81484eb3011fa0a946205550c3 /asdcplib/src/AS_DCP_JP2K.cpp | |
| parent | 564f68cb2c258e61c1e70950c9d036859ea8619a (diff) | |
| parent | 59617eb2230e47b59882c4f9ca6092ce05f53cf1 (diff) | |
Merge master.
Diffstat (limited to 'asdcplib/src/AS_DCP_JP2K.cpp')
| -rwxr-xr-x | asdcplib/src/AS_DCP_JP2K.cpp | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/asdcplib/src/AS_DCP_JP2K.cpp b/asdcplib/src/AS_DCP_JP2K.cpp index ca6d5270..e67bd8df 100755 --- a/asdcplib/src/AS_DCP_JP2K.cpp +++ b/asdcplib/src/AS_DCP_JP2K.cpp @@ -1,3 +1,5 @@ +/* -*- c-basic-offset: 2; -*- */ + /* Copyright (c) 2004-2012, John Hurst All rights reserved. @@ -33,6 +35,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <iostream> #include <iomanip> +using std::cout; using namespace ASDCP::JP2K; using Kumu::GenRandomValue; @@ -812,10 +815,11 @@ public: ~lh__Writer(){} - Result_t OpenWrite(const char*, EssenceType_t type, ui32_t HeaderSize); + Result_t OpenWrite(const char*, EssenceType_t type, ui32_t HeaderSize, bool); Result_t SetSourceStream(const PictureDescriptor&, const std::string& label, ASDCP::Rational LocalEditRate = ASDCP::Rational(0,0)); - Result_t WriteFrame(const JP2K::FrameBuffer&, bool add_index, AESEncContext*, HMACContext*); + Result_t WriteFrame(const JP2K::FrameBuffer&, bool add_index, AESEncContext*, HMACContext*, std::string* hash = 0); + Result_t FakeWriteFrame(int size, bool add_index); Result_t Finalize(); Result_t JP2K_PDesc_to_MD(JP2K::PictureDescriptor& PDesc); }; @@ -900,15 +904,21 @@ lh__Writer::JP2K_PDesc_to_MD(JP2K::PictureDescriptor& PDesc) } -// 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. ASDCP::Result_t -lh__Writer::OpenWrite(const char* filename, EssenceType_t type, ui32_t HeaderSize) +lh__Writer::OpenWrite(const char* filename, EssenceType_t type, ui32_t HeaderSize, bool overwrite) { if ( ! m_State.Test_BEGIN() ) return RESULT_STATE; - Result_t result = m_File.OpenWrite(filename); + Result_t result = RESULT_OK; + if (overwrite) { + result = m_File.OpenModify(filename); + m_File.Seek(0); + } else { + result = m_File.OpenWrite(filename); + } if ( ASDCP_SUCCESS(result) ) { @@ -978,7 +988,7 @@ lh__Writer::SetSourceStream(const PictureDescriptor& PDesc, const std::string& l // ASDCP::Result_t lh__Writer::WriteFrame(const JP2K::FrameBuffer& FrameBuf, bool add_index, - AESEncContext* Ctx, HMACContext* HMAC) + AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) { Result_t result = RESULT_OK; @@ -988,7 +998,31 @@ lh__Writer::WriteFrame(const JP2K::FrameBuffer& FrameBuf, bool add_index, ui64_t StreamOffset = m_StreamOffset; if ( ASDCP_SUCCESS(result) ) - result = WriteEKLVPacket(FrameBuf, m_EssenceUL, Ctx, HMAC); + result = WriteEKLVPacket(FrameBuf, m_EssenceUL, Ctx, HMAC, hash); + + if ( ASDCP_SUCCESS(result) && add_index ) + { + IndexTableSegment::IndexEntry Entry; + Entry.StreamOffset = StreamOffset; + m_FooterPart.PushIndexEntry(Entry); + } + + m_FramesWritten++; + return result; +} + +Result_t +lh__Writer::FakeWriteFrame(int size, bool add_index) +{ + Result_t result = RESULT_OK; + + if ( m_State.Test_READY() ) + result = m_State.Goto_RUNNING(); + + ui64_t StreamOffset = m_StreamOffset; + + if ( ASDCP_SUCCESS(result) ) + result = FakeWriteEKLVPacket(size); if ( ASDCP_SUCCESS(result) && add_index ) { @@ -1069,11 +1103,11 @@ ASDCP::JP2K::MXFWriter::OPAtomIndexFooter() return m_Writer->m_FooterPart; } -// 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. ASDCP::Result_t ASDCP::JP2K::MXFWriter::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__Writer(DefaultSMPTEDict()); @@ -1082,7 +1116,7 @@ ASDCP::JP2K::MXFWriter::OpenWrite(const char* filename, const WriterInfo& Info, m_Writer->m_Info = Info; - Result_t result = m_Writer->OpenWrite(filename, ASDCP::ESS_JPEG_2000, HeaderSize); + Result_t result = m_Writer->OpenWrite(filename, ASDCP::ESS_JPEG_2000, HeaderSize, overwrite); if ( ASDCP_SUCCESS(result) ) result = m_Writer->SetSourceStream(PDesc, JP2K_PACKAGE_LABEL); @@ -1099,12 +1133,21 @@ ASDCP::JP2K::MXFWriter::OpenWrite(const char* filename, const WriterInfo& Info, // Fails if the file is not open, is finalized, or an operating system // error occurs. ASDCP::Result_t -ASDCP::JP2K::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC) +ASDCP::JP2K::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) { if ( m_Writer.empty() ) return RESULT_INIT; - return m_Writer->WriteFrame(FrameBuf, true, Ctx, HMAC); + return m_Writer->WriteFrame(FrameBuf, true, Ctx, HMAC, hash); +} + +ASDCP::Result_t +ASDCP::JP2K::MXFWriter::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. @@ -1117,6 +1160,12 @@ ASDCP::JP2K::MXFWriter::Finalize() return m_Writer->Finalize(); } +ui64_t +ASDCP::JP2K::MXFWriter::Tell() const +{ + return m_Writer->m_File.Tell(); +} + //------------------------------------------------------------------------------------------ // @@ -1227,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); + Result_t result = m_Writer->OpenWrite(filename, ASDCP::ESS_JPEG_2000_S, HeaderSize, false); if ( ASDCP_SUCCESS(result) ) { |
