diff options
| author | jhurst <jhurst@cinecert.com> | 2015-10-07 16:41:23 +0000 |
|---|---|---|
| committer | jhurst <> | 2015-10-07 16:41:23 +0000 |
| commit | af6a1e4ef13dcf5811ccd9eb6b63d21bdc88dc70 (patch) | |
| tree | 021ae744f611d9bfd2f8832c665351132205ab0b /src/MXFTypes.h | |
| parent | 77200515d9acee07988f26dadfa37ffbd169cdfb (diff) | |
o Moved personal dev environment from older gcc to newer clang. Many small changes were made to satisfy the new compiler:
- Altered many printf format codes to use the correct type for the given integer type
- Parenthesized some expressions to clarify previously ambiguous expectations of precedence
- Created macro KM_MACOSX for use in OS-specific code selection
- Removed last uses of the old C-language abs(), now using Kumu::xabs()
- Removed last uses of the old C-language atoi()
o Added platform-independent call Kumu::GetExecutablePath() (test with win32)
o Fixed a bug that was causing Array properties to be written without the (count, length) header (from PAL)
o Fixed Win32 build (from Crowe)
o Added imlementation of SMPTE ST 2092-1 pink noise generator
o Added pinkwave CLI utility
o Added font support to the IMF timed-text wrapper
Diffstat (limited to 'src/MXFTypes.h')
| -rwxr-xr-x | src/MXFTypes.h | 141 |
1 files changed, 118 insertions, 23 deletions
diff --git a/src/MXFTypes.h b/src/MXFTypes.h index 77c0f5f..f49ef8b 100755 --- a/src/MXFTypes.h +++ b/src/MXFTypes.h @@ -103,39 +103,105 @@ namespace ASDCP Batch() {} virtual ~Batch() {} + inline virtual bool HasValue() const { return ! this->empty(); } + + virtual ui32_t ArchiveLength() const { + ui32_t arch_size = sizeof(ui32_t) * 2; + typename std::vector<T>::const_iterator i; + + for ( i = this->begin(); i != this->end(); ++i ) + { + arch_size += i->ArchiveLength(); + } + + return arch_size; + } + + // + virtual bool Archive(Kumu::MemIOWriter* Writer) const { + if ( ! Writer->WriteUi32BE(this->size()) ) return false; + byte_t* p = Writer->CurrentData(); + + if ( ! Writer->WriteUi32BE(0) ) return false; + if ( this->empty() ) return true; + + typename std::vector<T>::const_iterator i = this->begin(); + assert(i != this->end()); + + ui32_t ItemSize = Writer->Remainder(); + if ( ! i->Archive(Writer) ) return false; + ItemSize -= Writer->Remainder(); + Kumu::i2p<ui32_t>(KM_i32_BE(ItemSize), p); + ++i; + + bool result = true; + for ( ; i != this->end() && result; ++i ) + { + result = i->Archive(Writer); + } + + return result; + } + // virtual bool Unarchive(Kumu::MemIOReader* Reader) { - ui32_t ItemCount, ItemSize; - if ( ! Reader->ReadUi32BE(&ItemCount) ) return false; - if ( ! Reader->ReadUi32BE(&ItemSize) ) return false; + ui32_t item_count, item_size; + if ( ! Reader->ReadUi32BE(&item_count) ) return false; + if ( ! Reader->ReadUi32BE(&item_size) ) return false; - if ( ( ItemCount > 65536 ) || ( ItemSize > 1024 ) ) - return false; + if ( ( item_count > 65536 ) || ( item_size > 1024 ) ) + { + return false; + } bool result = true; - for ( ui32_t i = 0; i < ItemCount && result; i++ ) + for ( ui32_t i = 0; i < item_count && result; ++i ) { T Tmp; result = Tmp.Unarchive(Reader); if ( result ) - this->push_back(Tmp); + { + this->push_back(Tmp); + } } return result; } + // + void Dump(FILE* stream = 0, ui32_t depth = 0) + { + char identbuf[IdentBufferLen]; + + if ( stream == 0 ) + stream = stderr; + + typename std::vector<T>::iterator i = this->begin(); + for ( ; i != this->end(); i++ ) + fprintf(stream, " %s\n", (*i).EncodeString(identbuf, IdentBufferLen)); + } + }; + + // + template <class T> + class Array : public std::list<T>, public Kumu::IArchive + { + public: + Array() {} + virtual ~Array() {} + inline virtual bool HasValue() const { return ! this->empty(); } virtual ui32_t ArchiveLength() const { - ui32_t arch_size = sizeof(ui32_t)*2; + ui32_t arch_size = sizeof(ui32_t) * 2; + typename std::list<T>::const_iterator i; - typename std::vector<T>::const_iterator l_i = this->begin(); - assert(l_i != this->end()); + for ( i = this->begin(); i != this->end(); ++i ) + { + arch_size += i->ArchiveLength(); + } - for ( ; l_i != this->end(); l_i++ ) - arch_size += l_i->ArchiveLength(); - return arch_size; } @@ -147,21 +213,50 @@ namespace ASDCP if ( ! Writer->WriteUi32BE(0) ) return false; if ( this->empty() ) return true; - typename std::vector<T>::const_iterator l_i = this->begin(); - assert(l_i != this->end()); + typename std::list<T>::const_iterator i = this->begin(); + assert(i != this->end()); ui32_t ItemSize = Writer->Remainder(); - if ( ! (*l_i).Archive(Writer) ) return false; + if ( ! i->Archive(Writer) ) return false; ItemSize -= Writer->Remainder(); Kumu::i2p<ui32_t>(KM_i32_BE(ItemSize), p); - l_i++; + ++i; bool result = true; - for ( ; l_i != this->end() && result; l_i++ ) - result = (*l_i).Archive(Writer); + for ( ; i != this->end() && result; ++i ) + { + result = i->Archive(Writer); + } + + return result; + } + + // + virtual bool Unarchive(Kumu::MemIOReader* Reader) { + ui32_t item_count, item_size; + if ( ! Reader->ReadUi32BE(&item_count) ) return false; + if ( ! Reader->ReadUi32BE(&item_size) ) return false; + + if ( ( item_count > 65536 ) || ( item_size > 1024 ) ) + { + return false; + } + + bool result = true; + for ( ui32_t i = 0; i < item_count && result; ++i ) + { + T Tmp; + result = Tmp.Unarchive(Reader); + + if ( result ) + { + this->push_back(Tmp); + } + } return result; } + // void Dump(FILE* stream = 0, ui32_t depth = 0) @@ -171,7 +266,7 @@ namespace ASDCP if ( stream == 0 ) stream = stderr; - typename std::vector<T>::iterator i = this->begin(); + typename std::list<T>::iterator i = this->begin(); for ( ; i != this->end(); i++ ) fprintf(stream, " %s\n", (*i).EncodeString(identbuf, IdentBufferLen)); } @@ -179,11 +274,11 @@ namespace ASDCP // template <class T> - class Array : public std::list<T>, public Kumu::IArchive + class HeadlessArray : public std::list<T>, public Kumu::IArchive { public: - Array() {} - virtual ~Array() {} + HeadlessArray() {} + virtual ~HeadlessArray() {} // virtual bool Unarchive(Kumu::MemIOReader* Reader) |
