X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FMXFTypes.cpp;h=72338bbfda5f3290f8de2b9990345e4c52e92ba9;hb=refs%2Fheads%2Fissues%2F0015-replace-ATMOS-w-IAB;hp=a76957fe5f3d5e0b7d23044e70e2eda2358d9d46;hpb=50fab55d36abf7f01c733d2f80833408dbe0f761;p=asdcplib.git diff --git a/src/MXFTypes.cpp b/src/MXFTypes.cpp index a76957f..72338bb 100755 --- a/src/MXFTypes.cpp +++ b/src/MXFTypes.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2009, John Hurst +Copyright (c) 2005-2019, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -30,6 +30,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include "MXFTypes.h" #include @@ -38,6 +39,7 @@ using Kumu::DefaultLogSink; //------------------------------------------------------------------------------------------ // +// bool ASDCP::UL::operator==(const UL& rhs) const { @@ -48,7 +50,7 @@ ASDCP::UL::operator==(const UL& rhs) const m_Value[4] == rhs.m_Value[4] && m_Value[5] == rhs.m_Value[5] && m_Value[6] == rhs.m_Value[6] && - // m_Value[7] == rhs.m_Value[7] && version is ignored when performing lookups + // m_Value[7] == rhs.m_Value[7] && // version is ignored when performing lookups m_Value[8] == rhs.m_Value[8] && m_Value[9] == rhs.m_Value[9] && m_Value[10] == rhs.m_Value[10] && @@ -63,6 +65,57 @@ ASDCP::UL::operator==(const UL& rhs) const return false; } +// +bool +ASDCP::UL::MatchIgnoreStream(const UL& rhs) const +{ + if ( m_Value[0] == rhs.m_Value[0] && + m_Value[1] == rhs.m_Value[1] && + m_Value[2] == rhs.m_Value[2] && + m_Value[3] == rhs.m_Value[3] && + m_Value[4] == rhs.m_Value[4] && + m_Value[5] == rhs.m_Value[5] && + m_Value[6] == rhs.m_Value[6] && + // m_Value[7] == rhs.m_Value[7] && // version is ignored when performing lookups + m_Value[8] == rhs.m_Value[8] && + m_Value[9] == rhs.m_Value[9] && + m_Value[10] == rhs.m_Value[10] && + m_Value[11] == rhs.m_Value[11] && + m_Value[12] == rhs.m_Value[12] && + m_Value[13] == rhs.m_Value[13] && + m_Value[14] == rhs.m_Value[14] + // m_Value[15] == rhs.m_Value[15] // ignore stream number + ) + return true; + + return false; +} + +// +bool +ASDCP::UL::MatchExact(const UL& rhs) const +{ + if ( m_Value[0] == rhs.m_Value[0] && + m_Value[1] == rhs.m_Value[1] && + m_Value[2] == rhs.m_Value[2] && + m_Value[3] == rhs.m_Value[3] && + m_Value[4] == rhs.m_Value[4] && + m_Value[5] == rhs.m_Value[5] && + m_Value[6] == rhs.m_Value[6] && + m_Value[7] == rhs.m_Value[7] && + m_Value[8] == rhs.m_Value[8] && + m_Value[9] == rhs.m_Value[9] && + m_Value[10] == rhs.m_Value[10] && + m_Value[11] == rhs.m_Value[11] && + m_Value[12] == rhs.m_Value[12] && + m_Value[13] == rhs.m_Value[13] && + m_Value[14] == rhs.m_Value[14] && + m_Value[15] == rhs.m_Value[15] + ) + return true; + + return false; +} const char* ASDCP::UL::EncodeString(char* str_buf, ui32_t buf_len) const @@ -70,7 +123,7 @@ ASDCP::UL::EncodeString(char* str_buf, ui32_t buf_len) const if ( buf_len > 38 ) // room for dotted notation? { snprintf(str_buf, buf_len, - "%02x%02x%02x%02x.%02x%02x.%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x", + "%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x", m_Value[0], m_Value[1], m_Value[2], m_Value[3], m_Value[4], m_Value[5], m_Value[6], m_Value[7], m_Value[8], m_Value[9], m_Value[10], m_Value[11], @@ -126,14 +179,17 @@ ASDCP::UMID::MakeUMID(int Type, const UUID& AssetID) } -// Write the timestamp value to the given buffer in the form 2004-05-01 13:20:00.000 +// Write the UMID value to the given buffer in the form +// [00000000.0000.0000.00000000],00,00,00,00,00000000.0000.0000.00000000.00000000] +// or +// [00000000.0000.0000.00000000],00,00,00,00,00000000-0000-0000-0000-000000000000] // returns 0 if the buffer is smaller than DateTimeLen const char* ASDCP::UMID::EncodeString(char* str_buf, ui32_t buf_len) const { assert(str_buf); - snprintf(str_buf, buf_len, "[%02x%02x%02x%02x.%02x%02x.%02x%02x.%02x%02x%02x%02x],%02x,%02x,%02x,%02x,", + snprintf(str_buf, buf_len, "[%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x],%02x,%02x,%02x,%02x,", m_Value[0], m_Value[1], m_Value[2], m_Value[3], m_Value[4], m_Value[5], m_Value[6], m_Value[7], m_Value[8], m_Value[9], m_Value[10], m_Value[11], @@ -146,7 +202,7 @@ ASDCP::UMID::EncodeString(char* str_buf, ui32_t buf_len) const { // half-swapped UL, use [bbaa9988.ddcc.ffee.00010203.04050607] snprintf(str_buf + offset, buf_len - offset, - "[%02x%02x%02x%02x.%02x%02x.%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x]", + "[%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x]", m_Value[24], m_Value[25], m_Value[26], m_Value[27], m_Value[28], m_Value[29], m_Value[30], m_Value[31], m_Value[16], m_Value[17], m_Value[18], m_Value[19], @@ -171,6 +227,20 @@ ASDCP::UMID::EncodeString(char* str_buf, ui32_t buf_len) const //------------------------------------------------------------------------------------------ // +// +ASDCP::MXF::UTF16String::UTF16String(const char* sz) +{ + if ( sz != 0 && *sz != 0 ) + { + this->assign(sz); + } +} + +ASDCP::MXF::UTF16String::UTF16String(const std::string& str) +{ + this->assign(str); +} + // const ASDCP::MXF::UTF16String& ASDCP::MXF::UTF16String::operator=(const char* sz) @@ -209,11 +279,14 @@ ASDCP::MXF::UTF16String::Unarchive(Kumu::MemIOReader* Reader) erase(); const ui16_t* p = (ui16_t*)Reader->CurrentData(); ui32_t length = Reader->Remainder() / 2; - char mb_buf[MB_LEN_MAX+1]; + char mb_buf[MB_LEN_MAX]; + + mbstate_t ps; + memset(&ps, 0, sizeof(mbstate_t)); for ( ui32_t i = 0; i < length; i++ ) { - int count = wctomb(mb_buf, KM_i16_BE(p[i])); + int count = wcrtomb(mb_buf, KM_i16_BE(p[i]), &ps); if ( count == -1 ) { @@ -246,9 +319,12 @@ ASDCP::MXF::UTF16String::Archive(Kumu::MemIOWriter* Writer) const ui32_t length = size(); ui32_t i = 0; + mbstate_t ps; + memset(&ps, 0, sizeof(mbstate_t)); + while ( i < length ) { - int count = mbtowc(&wcp, mbp+i, remainder); + int count = mbrtowc(&wcp, mbp+i, remainder, &ps); if ( count == -1 ) { @@ -256,7 +332,9 @@ ASDCP::MXF::UTF16String::Archive(Kumu::MemIOWriter* Writer) const return false; } else if ( count == 0 ) - break; + { + break; + } bool result = Writer->WriteUi16BE((ui16_t)wcp); @@ -273,241 +351,74 @@ ASDCP::MXF::UTF16String::Archive(Kumu::MemIOWriter* Writer) const return true; } - //------------------------------------------------------------------------------------------ // -#ifdef WIN32 - -#define TIMESTAMP_TO_SYSTIME(ts, t) \ - (t)->wYear = (ts).Year; /* year */ \ - (t)->wMonth = (ts).Month; /* month of year (1 - 12) */ \ - (t)->wDay = (ts).Day; /* day of month (1 - 31) */ \ - (t)->wHour = (ts).Hour; /* hours (0 - 23) */ \ - (t)->wMinute = (ts).Minute; /* minutes (0 - 59) */ \ - (t)->wSecond = (ts).Second; /* seconds (0 - 60) */ \ - (t)->wDayOfWeek = 0; \ - (t)->wMilliseconds = ((ts).Tick * 4); - -#define SYSTIME_TO_TIMESTAMP(t, ts) \ - (ts).Year = (t)->wYear; /* year */ \ - (ts).Month = (t)->wMonth; /* month of year (1 - 12) */ \ - (ts).Day = (t)->wDay; /* day of month (1 - 31) */ \ - (ts).Hour = (t)->wHour; /* hours (0 - 23) */ \ - (ts).Minute = (t)->wMinute; /* minutes (0 - 59) */ \ - (ts).Second = (t)->wSecond; /* seconds (0 - 60) */ \ - (ts).Tick = (t)->wMilliseconds / 4; - // -ASDCP::MXF::Timestamp::Timestamp() : - Year(0), Month(0), Day(0), Hour(0), Minute(0), Second(0), Tick(0) +ASDCP::MXF::ISO8String::ISO8String(const char* sz) { - SYSTEMTIME sys_time; - GetSystemTime(&sys_time); - SYSTIME_TO_TIMESTAMP(&sys_time, *this); + if ( sz != 0 && *sz != 0 ) + { + this->assign(sz); + } } -// -bool -ASDCP::MXF::Timestamp::operator<(const Timestamp& rhs) const +ASDCP::MXF::ISO8String::ISO8String(const std::string& str) { - SYSTEMTIME lhst, rhst; - FILETIME lft, rft; - - TIMESTAMP_TO_SYSTIME(*this, &lhst); - TIMESTAMP_TO_SYSTIME(rhs, &rhst); - SystemTimeToFileTime(&lhst, &lft); - SystemTimeToFileTime(&rhst, &rft); - return ( CompareFileTime(&lft, &rft) == -1 ); + this->assign(str); } -inline ui64_t -seconds_to_ns100(ui32_t seconds) -{ - return ((ui64_t)seconds * 10000000); -} // -void -ASDCP::MXF::Timestamp::AddDays(i32_t days) +const ASDCP::MXF::ISO8String& +ASDCP::MXF::ISO8String::operator=(const char* sz) { - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; + if ( sz == 0 || *sz == 0 ) + erase(); - if ( days != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(86400) * (ui64_t)days ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } + else + this->assign(sz); + + return *this; } // -void -ASDCP::MXF::Timestamp::AddHours(i32_t hours) +const ASDCP::MXF::ISO8String& +ASDCP::MXF::ISO8String::operator=(const std::string& str) { - SYSTEMTIME current_st; - FILETIME current_ft; - ULARGE_INTEGER current_ul; - - if ( hours != 0 ) - { - TIMESTAMP_TO_SYSTIME(*this, ¤t_st); - SystemTimeToFileTime(¤t_st, ¤t_ft); - memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); - current_ul.QuadPart += ( seconds_to_ns100(3600) * (ui64_t)hours ); - memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); - FileTimeToSystemTime(¤t_ft, ¤t_st); - SYSTIME_TO_TIMESTAMP(¤t_st, *this); - } + this->assign(str); + return *this; } -#else // KM_WIN32 - -#include - -#define TIMESTAMP_TO_TM(ts, t) \ - (t)->tm_year = (ts).Year - 1900; /* year - 1900 */ \ - (t)->tm_mon = (ts).Month - 1; /* month of year (0 - 11) */ \ - (t)->tm_mday = (ts).Day; /* day of month (1 - 31) */ \ - (t)->tm_hour = (ts).Hour; /* hours (0 - 23) */ \ - (t)->tm_min = (ts).Minute; /* minutes (0 - 59) */ \ - (t)->tm_sec = (ts).Second; /* seconds (0 - 60) */ - -#define TM_TO_TIMESTAMP(t, ts) \ - (ts).Year = (t)->tm_year + 1900; /* year - 1900 */ \ - (ts).Month = (t)->tm_mon + 1; /* month of year (0 - 11) */ \ - (ts).Day = (t)->tm_mday; /* day of month (1 - 31) */ \ - (ts).Hour = (t)->tm_hour; /* hours (0 - 23) */ \ - (ts).Minute = (t)->tm_min; /* minutes (0 - 59) */ \ - (ts).Second = (t)->tm_sec; /* seconds (0 - 60) */ - // -ASDCP::MXF::Timestamp::Timestamp() : - Year(0), Month(0), Day(0), Hour(0), Minute(0), Second(0) +const char* +ASDCP::MXF::ISO8String::EncodeString(char* str_buf, ui32_t buf_len) const { - time_t t_now = time(0); - struct tm* now = gmtime(&t_now); - TM_TO_TIMESTAMP(now, *this); + ui32_t write_len = Kumu::xmin(buf_len - 1, (ui32_t)size()); + strncpy(str_buf, c_str(), write_len); + str_buf[write_len] = 0; + return str_buf; } // bool -ASDCP::MXF::Timestamp::operator<(const Timestamp& rhs) const +ASDCP::MXF::ISO8String::Unarchive(Kumu::MemIOReader* Reader) { - struct tm lhtm, rhtm; - TIMESTAMP_TO_TM(*this, &lhtm); - TIMESTAMP_TO_TM(rhs, &rhtm); - return ( timegm(&lhtm) < timegm(&rhtm) ); + assign((char*)Reader->CurrentData(), Reader->Remainder()); + return true; } // -void -ASDCP::MXF::Timestamp::AddDays(i32_t days) +bool +ASDCP::MXF::ISO8String::Archive(Kumu::MemIOWriter* Writer) const { - struct tm current; - - if ( days != 0 ) + if ( size() > IdentBufferLen ) { - TIMESTAMP_TO_TM(*this, ¤t); - time_t adj_time = timegm(¤t); - adj_time += 86400 * days; - struct tm* now = gmtime(&adj_time); - TM_TO_TIMESTAMP(now, *this); + DefaultLogSink().Error("String length exceeds maximum %u bytes\n", IdentBufferLen); + return false; } -} -// -void -ASDCP::MXF::Timestamp::AddHours(i32_t hours) -{ - struct tm current; - - if ( hours != 0 ) - { - TIMESTAMP_TO_TM(*this, ¤t); - time_t adj_time = timegm(¤t); - adj_time += 3600 * hours; - struct tm* now = gmtime(&adj_time); - TM_TO_TIMESTAMP(now, *this); - } -} - -#endif // KM_WIN32 - - -ASDCP::MXF::Timestamp::Timestamp(const Timestamp& rhs) : IArchive() -{ - Year = rhs.Year; - Month = rhs.Month; - Day = rhs.Day; - Hour = rhs.Hour; - Minute = rhs.Minute; - Second = rhs.Second; -} - -ASDCP::MXF::Timestamp::~Timestamp() -{ -} - -// -const ASDCP::MXF::Timestamp& -ASDCP::MXF::Timestamp::operator=(const Timestamp& rhs) -{ - Year = rhs.Year; - Month = rhs.Month; - Day = rhs.Day; - Hour = rhs.Hour; - Minute = rhs.Minute; - Second = rhs.Second; - return *this; -} - -// -bool -ASDCP::MXF::Timestamp::operator==(const Timestamp& rhs) const -{ - if ( Year == rhs.Year - && Month == rhs.Month - && Day == rhs.Day - && Hour == rhs.Hour - && Minute == rhs.Minute - && Second == rhs.Second ) - return true; - - return false; -} - -// -bool -ASDCP::MXF::Timestamp::operator!=(const Timestamp& rhs) const -{ - if ( Year != rhs.Year - || Month != rhs.Month - || Day != rhs.Day - || Hour != rhs.Hour - || Minute != rhs.Minute - || Second != rhs.Second ) - return true; - - return false; -} - -// -const char* -ASDCP::MXF::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const -{ - // 2004-05-01 13:20:00.000 - snprintf(str_buf, buf_len, - "%04hu-%02hu-%02hu %02hu:%02hu:%02hu.000", - Year, Month, Day, Hour, Minute, Second); - - return str_buf; + return Writer->WriteRaw((const byte_t*)c_str(), size()); } //------------------------------------------------------------------------------------------ @@ -534,7 +445,7 @@ ASDCP::MXF::TLVReader::TLVReader(const byte_t* p, ui32_t c, IPrimerLookup* Prime DefaultLogSink().Error("Malformed Set\n"); m_ElementMap.clear(); - result = RESULT_KLV_CODING; + result = RESULT_KLV_CODING(__LINE__, __FILE__); } } @@ -584,7 +495,10 @@ ASDCP::MXF::TLVReader::ReadObject(const MDDEntry& Entry, Kumu::IArchive* Object) if ( FindTL(Entry) ) { if ( m_size < m_capacity ) // don't try to unarchive an empty item - return Object->Unarchive(this) ? RESULT_OK : RESULT_KLV_CODING; + { + // TODO: carry on if uachive fails + return Object->Unarchive(this) ? RESULT_OK : RESULT_FALSE(__LINE__, __FILE__); + } } return RESULT_FALSE; @@ -597,7 +511,7 @@ ASDCP::MXF::TLVReader::ReadUi8(const MDDEntry& Entry, ui8_t* value) ASDCP_TEST_NULL(value); if ( FindTL(Entry) ) - return MemIOReader::ReadUi8(value) ? RESULT_OK : RESULT_KLV_CODING; + return MemIOReader::ReadUi8(value) ? RESULT_OK : RESULT_FALSE(__LINE__, __FILE__); return RESULT_FALSE; } @@ -609,7 +523,7 @@ ASDCP::MXF::TLVReader::ReadUi16(const MDDEntry& Entry, ui16_t* value) ASDCP_TEST_NULL(value); if ( FindTL(Entry) ) - return MemIOReader::ReadUi16BE(value) ? RESULT_OK : RESULT_KLV_CODING; + return MemIOReader::ReadUi16BE(value) ? RESULT_OK : RESULT_FALSE(__LINE__, __FILE__); return RESULT_FALSE; } @@ -621,7 +535,7 @@ ASDCP::MXF::TLVReader::ReadUi32(const MDDEntry& Entry, ui32_t* value) ASDCP_TEST_NULL(value); if ( FindTL(Entry) ) - return MemIOReader::ReadUi32BE(value) ? RESULT_OK : RESULT_KLV_CODING; + return MemIOReader::ReadUi32BE(value) ? RESULT_OK : RESULT_FALSE(__LINE__, __FILE__); return RESULT_FALSE; } @@ -633,7 +547,7 @@ ASDCP::MXF::TLVReader::ReadUi64(const MDDEntry& Entry, ui64_t* value) ASDCP_TEST_NULL(value); if ( FindTL(Entry) ) - return MemIOReader::ReadUi64BE(value) ? RESULT_OK : RESULT_KLV_CODING; + return MemIOReader::ReadUi64BE(value) ? RESULT_OK : RESULT_FALSE(__LINE__, __FILE__); return RESULT_FALSE; } @@ -653,7 +567,7 @@ ASDCP::MXF::TLVWriter::WriteTag(const MDDEntry& Entry) { if ( m_Lookup == 0 ) { - DefaultLogSink().Error("No Primer object available\n"); + DefaultLogSink().Error("No Primer object available.\n"); return RESULT_FAIL; } @@ -665,8 +579,8 @@ ASDCP::MXF::TLVWriter::WriteTag(const MDDEntry& Entry) return RESULT_FAIL; } - if ( ! MemIOWriter::WriteUi8(TmpTag.a) ) return RESULT_KLV_CODING; - if ( ! MemIOWriter::WriteUi8(TmpTag.b) ) return RESULT_KLV_CODING; + if ( ! MemIOWriter::WriteUi8(TmpTag.a) ) return RESULT_KLV_CODING(__LINE__, __FILE__); + if ( ! MemIOWriter::WriteUi8(TmpTag.b) ) return RESULT_KLV_CODING(__LINE__, __FILE__); return RESULT_OK; } @@ -686,11 +600,11 @@ ASDCP::MXF::TLVWriter::WriteObject(const MDDEntry& Entry, Kumu::IArchive* Object // write a temp length byte_t* l_p = CurrentData(); - if ( ! MemIOWriter::WriteUi16BE(0) ) return RESULT_KLV_CODING; + if ( ! MemIOWriter::WriteUi16BE(0) ) return RESULT_KLV_CODING(__LINE__, __FILE__); ui32_t before = Length(); - if ( ! Object->Archive(this) ) return RESULT_KLV_CODING; - if ( (Length() - before) > 0xffffL ) return RESULT_KLV_CODING; + if ( ! Object->Archive(this) ) return RESULT_KLV_CODING(__LINE__, __FILE__); + if ( (Length() - before) > 0xffffL ) return RESULT_KLV_CODING(__LINE__, __FILE__); Kumu::i2p(KM_i16_BE(Length() - before), l_p); } @@ -706,8 +620,8 @@ ASDCP::MXF::TLVWriter::WriteUi8(const MDDEntry& Entry, ui8_t* value) if ( ASDCP_SUCCESS(result) ) { - if ( ! MemIOWriter::WriteUi16BE(sizeof(ui8_t)) ) return RESULT_KLV_CODING; - if ( ! MemIOWriter::WriteUi8(*value) ) return RESULT_KLV_CODING; + if ( ! MemIOWriter::WriteUi16BE(sizeof(ui8_t)) ) return RESULT_KLV_CODING(__LINE__, __FILE__); + if ( ! MemIOWriter::WriteUi8(*value) ) return RESULT_KLV_CODING(__LINE__, __FILE__); } return result; @@ -722,8 +636,8 @@ ASDCP::MXF::TLVWriter::WriteUi16(const MDDEntry& Entry, ui16_t* value) if ( KM_SUCCESS(result) ) { - if ( ! MemIOWriter::WriteUi16BE(sizeof(ui16_t)) ) return RESULT_KLV_CODING; - if ( ! MemIOWriter::WriteUi16BE(*value) ) return RESULT_KLV_CODING; + if ( ! MemIOWriter::WriteUi16BE(sizeof(ui16_t)) ) return RESULT_KLV_CODING(__LINE__, __FILE__); + if ( ! MemIOWriter::WriteUi16BE(*value) ) return RESULT_KLV_CODING(__LINE__, __FILE__); } return result; @@ -738,8 +652,8 @@ ASDCP::MXF::TLVWriter::WriteUi32(const MDDEntry& Entry, ui32_t* value) if ( KM_SUCCESS(result) ) { - if ( ! MemIOWriter::WriteUi16BE(sizeof(ui32_t)) ) return RESULT_KLV_CODING; - if ( ! MemIOWriter::WriteUi32BE(*value) ) return RESULT_KLV_CODING; + if ( ! MemIOWriter::WriteUi16BE(sizeof(ui32_t)) ) return RESULT_KLV_CODING(__LINE__, __FILE__); + if ( ! MemIOWriter::WriteUi32BE(*value) ) return RESULT_KLV_CODING(__LINE__, __FILE__); } return result; @@ -754,14 +668,71 @@ ASDCP::MXF::TLVWriter::WriteUi64(const MDDEntry& Entry, ui64_t* value) if ( KM_SUCCESS(result) ) { - if ( ! MemIOWriter::WriteUi16BE(sizeof(ui64_t)) ) return RESULT_KLV_CODING; - if ( ! MemIOWriter::WriteUi64BE(*value) ) return RESULT_KLV_CODING; + if ( ! MemIOWriter::WriteUi16BE(sizeof(ui64_t)) ) return RESULT_KLV_CODING(__LINE__, __FILE__); + if ( ! MemIOWriter::WriteUi64BE(*value) ) return RESULT_KLV_CODING(__LINE__, __FILE__); } return result; } +//---------------------------------------------------------------------------------------------------- +// + + +ASDCP::MXF::RGBALayout::RGBALayout() +{ + memset(m_value, 0, RGBAValueLength); +} + +ASDCP::MXF::RGBALayout::RGBALayout(const byte_t* value) +{ + memcpy(m_value, value, RGBAValueLength); +} + +ASDCP::MXF::RGBALayout::~RGBALayout() +{ +} + +static char +get_char_for_code(byte_t c) +{ + for ( int i = 0; ASDCP::MXF::RGBALayoutTable[i].code != 0; ++i ) + { + if ( ASDCP::MXF::RGBALayoutTable[i].code == c ) + { + return ASDCP::MXF::RGBALayoutTable[i].symbol; + } + } + + return '_'; +} + +// +const char* +ASDCP::MXF::RGBALayout::EncodeString(char* buf, ui32_t buf_len) const +{ + std::string tmp_str; + char tmp_buf[64]; + + for ( int i = 0; i < RGBAValueLength && m_value[i] != 0; i += 2 ) + { + snprintf(tmp_buf, 64, "%c(%d)", get_char_for_code(m_value[i]), m_value[i+1]); + + if ( ! tmp_str.empty() ) + { + tmp_str += " "; + } + + tmp_str += tmp_buf; + } + + assert(tmp_str.size() < buf_len); + strncpy(buf, tmp_str.c_str(), tmp_str.size()); + return buf; +} + + //---------------------------------------------------------------------------------------------------- // @@ -803,6 +774,63 @@ ASDCP::MXF::Raw::EncodeString(char* str_buf, ui32_t buf_len) const return str_buf; } + +// +bool +ASDCP::MXF::J2KExtendedCapabilitiesType::Archive(Kumu::MemIOWriter* Writer) const { + if ( ! Writer->WriteUi32BE(Pcap) ) + { + return false; + } + + if ( ! Ccap.Archive(Writer) ) + { + return false; + } + + return true; +} + +// +bool +ASDCP::MXF::J2KExtendedCapabilitiesType::Unarchive(Kumu::MemIOReader* Reader) { + if ( ! Reader->ReadUi32BE(&Pcap) ) + { + return false; + } + + if ( ! Ccap.Unarchive(Reader) ) + { + return false; + } + + return true; +} + +// +const char* +ASDCP::MXF::J2KExtendedCapabilitiesType::EncodeString(char* str_buf, ui32_t buf_len) const +{ + const int str_len = ( sizeof(ui16_t) + 1 ) * JP2K::MaxCapabilities; + + if ( Pcap != 0 && buf_len > str_len ) + { + for ( int i = 0; i < Ccap.size(); ++i ) + { + snprintf(str_buf+(i*3), 4, "%02hx.", Ccap[i].value); + } + + str_buf[str_len-1] = 0; + } + else + { + str_buf[0] = 0; + } + + return str_buf; +} + + // // end MXFTypes.cpp //