summaryrefslogtreecommitdiff
path: root/src/AS_02_internal.h
diff options
context:
space:
mode:
authormilla <marc.illa@dolby.com>2021-06-03 14:23:52 +0200
committermilla <marc.illa@dolby.com>2021-06-03 14:23:52 +0200
commitbc8f5448441a85605f052294d40cf947473e83f5 (patch)
tree72b6588d5ed35b9cbb6ebc9e6646dd7583c76eab /src/AS_02_internal.h
parentf9d7fbc33aa571c547d916b145712469efd9f4b8 (diff)
Templatize h__AS02WriteClip, move functions to header. Note that this depends on filereader pluggable at runtime commit as the reader is called as a pointer here.
Diffstat (limited to 'src/AS_02_internal.h')
-rw-r--r--src/AS_02_internal.h119
1 files changed, 104 insertions, 15 deletions
diff --git a/src/AS_02_internal.h b/src/AS_02_internal.h
index ba7c33d..778ac7b 100644
--- a/src/AS_02_internal.h
+++ b/src/AS_02_internal.h
@@ -296,7 +296,7 @@ namespace AS_02
}
};
- //
+ //
class h__AS02WriterFrame : public h__AS02Writer<AS_02::MXF::AS02IndexWriterVBR>
{
ASDCP_NO_COPY_CONSTRUCT(h__AS02WriterFrame);
@@ -314,23 +314,112 @@ namespace AS_02
};
//
- class h__AS02WriterClip : public h__AS02Writer<AS_02::MXF::AS02IndexWriterCBR>
+ template <typename IndexWriterType>
+ class h__AS02WriterClip : public h__AS02Writer<IndexWriterType>
{
ASDCP_NO_COPY_CONSTRUCT(h__AS02WriterClip);
- h__AS02WriterClip();
+ h__AS02WriterClip() {}
public:
- ui64_t m_ECStart; // offset of the first essence element
- ui64_t m_ClipStart; // state variable for clip-wrap-in-progress
- IndexStrategy_t m_IndexStrategy; // per SMPTE ST 2067-5
-
- h__AS02WriterClip(const Dictionary*);
- virtual ~h__AS02WriterClip();
-
- bool HasOpenClip() const;
- Result_t StartClip(const byte_t* EssenceUL, AESEncContext* Ctx, HMACContext* HMAC);
- Result_t WriteClipBlock(const ASDCP::FrameBuffer& FrameBuf);
- Result_t FinalizeClip(ui32_t bytes_per_frame);
+ ui64_t m_ECStart; // offset of the first essence element
+ ui64_t m_ClipStart; // state variable for clip-wrap-in-progress
+ IndexStrategy_t m_IndexStrategy; // per SMPTE ST 2067-5
+
+ h__AS02WriterClip(const Dictionary* d) :
+ h__AS02Writer<IndexWriterType>(d),
+ m_ECStart(0), m_ClipStart(0), m_IndexStrategy(AS_02::IS_FOLLOW)
+ {}
+ virtual ~h__AS02WriterClip()
+ {}
+
+ bool HasOpenClip() const { return m_ClipStart != 0; }
+ Result_t StartClip(const byte_t* EssenceUL, AESEncContext* Ctx, HMACContext* HMAC)
+ {
+ if (Ctx != 0)
+ {
+ DefaultLogSink().Error("Encryption not yet supported for PCM clip-wrap.\n");
+ return RESULT_STATE;
+ }
+
+ if (m_ClipStart != 0)
+ {
+ DefaultLogSink().Error("Cannot open clip, clip already open.\n");
+ return RESULT_STATE;
+ }
+
+ m_ClipStart = h__AS02Writer<IndexWriterType>::m_File.TellPosition();
+ byte_t clip_buffer[24] = { 0 };
+ memcpy(clip_buffer, EssenceUL, 16);
+ bool check = Kumu::write_BER(clip_buffer + 16, 0, 8);
+ assert(check);
+ return h__AS02Writer<IndexWriterType>::m_File.Write(clip_buffer, 24);
+ }
+ Result_t WriteClipBlock(const ASDCP::FrameBuffer& FrameBuf)
+ {
+ if (m_ClipStart == 0)
+ {
+ DefaultLogSink().Error("Cannot write clip block, no clip open.\n");
+ return RESULT_STATE;
+ }
+
+ return h__AS02Writer<IndexWriterType>::m_File.Write(FrameBuf.RoData(), FrameBuf.Size());
+ }
+ Result_t FinalizeClip(ui32_t bytes_per_frame)
+ {
+ if (m_ClipStart == 0)
+ {
+ DefaultLogSink().Error("Cannot close clip, clip not open.\n");
+ return RESULT_STATE;
+ }
+
+ ui64_t current_position = h__AS02Writer<IndexWriterType>::m_File.TellPosition();
+ Result_t result = h__AS02Writer<IndexWriterType>::m_File.Seek(m_ClipStart + 16);
+
+ if (KM_SUCCESS(result))
+ {
+ byte_t clip_buffer[8] = { 0 };
+ ui64_t size = static_cast<ui64_t>(h__AS02Writer<IndexWriterType>::m_FramesWritten) * bytes_per_frame;
+ bool check = Kumu::write_BER(clip_buffer, size, 8);
+ assert(check);
+ result = h__AS02Writer<IndexWriterType>::m_File.Write(clip_buffer, 8);
+ }
+
+ if (KM_SUCCESS(result))
+ {
+ result = h__AS02Writer<IndexWriterType>::m_File.Seek(current_position);
+ m_ClipStart = 0;
+ }
+
+ return result;
+ }
+ Result_t FinalizeClip(ui64_t total_bytes_written)
+ {
+ if (m_ClipStart == 0)
+ {
+ DefaultLogSink().Error("Cannot close clip, clip not open.\n");
+ return RESULT_STATE;
+ }
+
+ ui64_t current_position = h__AS02Writer<IndexWriterType>::m_File.TellPosition();
+ Result_t result = h__AS02Writer<IndexWriterType>::m_File.Seek(m_ClipStart + 16);
+
+ if (KM_SUCCESS(result))
+ {
+ byte_t clip_buffer[8] = { 0 };
+ bool check = Kumu::write_BER(clip_buffer, total_bytes_written, 8);
+ assert(check);
+ result = h__AS02Writer<IndexWriterType>::m_File.Write(clip_buffer, 8);
+ }
+
+ if (KM_SUCCESS(result))
+ {
+ result = h__AS02Writer<IndexWriterType>::m_File.Seek(current_position);
+ m_ClipStart = 0;
+ }
+
+ return result;
+
+ }
};
} // namespace AS_02
@@ -339,4 +428,4 @@ namespace AS_02
//
// end AS_02_internal.h
-//
+// \ No newline at end of file