diff options
| author | Pierre-Anthony Lemieux <pal@palemieux.com> | 2020-07-08 19:46:21 -0700 |
|---|---|---|
| committer | Pierre-Anthony Lemieux <pal@palemieux.com> | 2020-07-08 19:46:21 -0700 |
| commit | 367371ceb2efbd43596959f0db2c31d882e80ca4 (patch) | |
| tree | eafe1a217881896b8c296d387448705fc6621196 /src/AS_02_IAB.cpp | |
| parent | 7f5ecd3dae499fcd9bf5de66814ab06cbecbc347 (diff) | |
Improve use of constants
Diffstat (limited to 'src/AS_02_IAB.cpp')
| -rw-r--r-- | src/AS_02_IAB.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
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<ui64_t>(this->m_Writer->m_StreamOffset) /* total size of the KLV */ - 24 /* K and L length */; + ui64_t size = static_cast<ui64_t>(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); |
