From 367371ceb2efbd43596959f0db2c31d882e80ca4 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Wed, 8 Jul 2020 19:46:21 -0700 Subject: Improve use of constants --- src/AS_02_IAB.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/AS_02_IAB.cpp') diff --git a/src/AS_02_IAB.cpp b/src/AS_02_IAB.cpp index 467d0cd..b058515 100644 --- a/src/AS_02_IAB.cpp +++ b/src/AS_02_IAB.cpp @@ -47,6 +47,12 @@ namespace Kumu { //------------------------------------------------------------------------------------------ +/* Size of the BER Length of the clip */ +static const int CLIP_BER_LENGTH_SIZE = 8; + +/* Combined size of the Key and Length of the clip */ +static const int RESERVED_KL_SIZE = ASDCP::SMPTE_UL_LENGTH + CLIP_BER_LENGTH_SIZE; + AS_02::IAB::MXFWriter::MXFWriter() : m_ClipStart(0), m_State(ST_BEGIN) { } @@ -169,22 +175,24 @@ AS_02::IAB::MXFWriter::OpenWrite( this->m_ClipStart = this->m_Writer->m_File.Tell(); - byte_t clip_buffer[24] = { 0 }; + /* reserve space for the KL of the KLV, which will be written later during finalization */ + + byte_t clip_buffer[RESERVED_KL_SIZE] = { 0 }; - memcpy(clip_buffer, this->m_Writer->m_Dict->ul(MDD_IMF_IABEssenceClipWrappedElement), 16); + memcpy(clip_buffer, this->m_Writer->m_Dict->ul(MDD_IMF_IABEssenceClipWrappedElement), ASDCP::SMPTE_UL_LENGTH); - if (!Kumu::write_BER(clip_buffer + 16, 0, 8)) { + if (!Kumu::write_BER(clip_buffer + ASDCP::SMPTE_UL_LENGTH, 0, CLIP_BER_LENGTH_SIZE)) { throw Kumu::RuntimeError(Kumu::RESULT_FAIL); } - this->m_Writer->m_StreamOffset = 24; - - result = this->m_Writer->m_File.Write(clip_buffer, 24); + result = this->m_Writer->m_File.Write(clip_buffer, RESERVED_KL_SIZE); if (result.Failure()) { throw Kumu::RuntimeError(result); } + this->m_Writer->m_StreamOffset = RESERVED_KL_SIZE; + this->m_State = ST_READY; } catch (Kumu::RuntimeError e) { @@ -268,19 +276,19 @@ AS_02::IAB::MXFWriter::Finalize() { ui64_t current_position = this->m_Writer->m_File.Tell(); - result = this->m_Writer->m_File.Seek(m_ClipStart + 16); + result = this->m_Writer->m_File.Seek(m_ClipStart + ASDCP::SMPTE_UL_LENGTH); - byte_t clip_buffer[8] = { 0 }; + byte_t clip_buffer[CLIP_BER_LENGTH_SIZE] = { 0 }; - ui64_t size = static_cast(this->m_Writer->m_StreamOffset) /* total size of the KLV */ - 24 /* K and L length */; + ui64_t size = static_cast(this->m_Writer->m_StreamOffset) /* total size of the KLV */ - RESERVED_KL_SIZE; - bool check = Kumu::write_BER(clip_buffer, size, 8); + bool check = Kumu::write_BER(clip_buffer, size, CLIP_BER_LENGTH_SIZE); if (!check) { throw Kumu::RuntimeError(Kumu::RESULT_FAIL); } - result = this->m_Writer->m_File.Write(clip_buffer, 8); + result = this->m_Writer->m_File.Write(clip_buffer, CLIP_BER_LENGTH_SIZE); if (result.Failure()) { throw Kumu::RuntimeError(result); -- cgit v1.2.3