summaryrefslogtreecommitdiff
path: root/asdcplib/src/AS_DCP_JP2K.cpp
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 /asdcplib/src/AS_DCP_JP2K.cpp
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 'asdcplib/src/AS_DCP_JP2K.cpp')
-rwxr-xr-xasdcplib/src/AS_DCP_JP2K.cpp63
1 files changed, 55 insertions, 8 deletions
diff --git a/asdcplib/src/AS_DCP_JP2K.cpp b/asdcplib/src/AS_DCP_JP2K.cpp
index 359cd910..05f5e005 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*, 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) )
{
@@ -986,6 +996,8 @@ lh__Writer::WriteFrame(const JP2K::FrameBuffer& FrameBuf, bool add_index,
result = m_State.Goto_RUNNING(); // first time through
ui64_t StreamOffset = m_StreamOffset;
+ cout << "Real write @ " << StreamOffset << " (header is " << m_HeaderSize << ")\n";
+ cout << "\tfile @ " << m_File.Tell() << "\n";
if ( ASDCP_SUCCESS(result) )
result = WriteEKLVPacket(FrameBuf, m_EssenceUL, Ctx, HMAC, hash);
@@ -1001,6 +1013,32 @@ lh__Writer::WriteFrame(const JP2K::FrameBuffer& FrameBuf, bool add_index,
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;
+ cout << "Fake write @ " << StreamOffset << " (header is " << m_HeaderSize << ")\n";
+ cout << "\tfile @ " << m_File.Tell() << "\n";
+
+ if ( ASDCP_SUCCESS(result) )
+ result = FakeWriteEKLVPacket(size);
+
+ if ( ASDCP_SUCCESS(result) && add_index )
+ {
+ IndexTableSegment::IndexEntry Entry;
+ Entry.StreamOffset = StreamOffset;
+ m_FooterPart.PushIndexEntry(Entry);
+ }
+
+ m_FramesWritten++;
+ return result;
+}
+
// Closes the MXF file, writing the index and other closing information.
//
@@ -1069,11 +1107,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 +1120,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);
@@ -1107,6 +1145,15 @@ ASDCP::JP2K::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* C
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.
ASDCP::Result_t
ASDCP::JP2K::MXFWriter::Finalize()
@@ -1233,7 +1280,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) )
{