From: jhurst Date: Mon, 26 Mar 2007 23:08:16 +0000 (+0000) Subject: added identifier list type X-Git-Tag: rel_2_10_32~569 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=253b0b7af5aacd4e112190689fbdeb10968ca074;p=asdcplib.git added identifier list type --- diff --git a/src/AS_DCP.h b/src/AS_DCP.h index 4e10d09..05b1e65 100755 --- a/src/AS_DCP.h +++ b/src/AS_DCP.h @@ -144,7 +144,7 @@ namespace ASDCP { // 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1. const ui32_t VERSION_MAJOR = 1; const ui32_t VERSION_APIMINOR = 1; - const ui32_t VERSION_IMPMINOR = 13; + const ui32_t VERSION_IMPMINOR = 14; const char* Version(); // UUIDs are passed around as strings of UUIDlen bytes diff --git a/src/AS_DCP_MPEG2.cpp b/src/AS_DCP_MPEG2.cpp index a0a4ad7..b3044f6 100755 --- a/src/AS_DCP_MPEG2.cpp +++ b/src/AS_DCP_MPEG2.cpp @@ -492,8 +492,15 @@ ASDCP::MPEG2::MXFWriter::h__Writer::WriteFrame(const FrameBuffer& FrameBuf, AESE // update the index manager Entry.TemporalOffset = - FrameBuf.TemporalOffset(); - Entry.KeyFrameOffset = m_GOPOffset; + Entry.KeyFrameOffset = - m_GOPOffset; Entry.Flags = Flags; + /* + fprintf(stderr, "to: %4hd ko: %4hd c1: %4hd c2: %4hd fl: 0x%02x\n", + Entry.TemporalOffset, Entry.KeyFrameOffset, + m_GOPOffset + Entry.TemporalOffset, + Entry.KeyFrameOffset - Entry.TemporalOffset, + Entry.Flags); + */ m_FooterPart.PushIndexEntry(Entry); m_FramesWritten++; m_GOPOffset++; diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp index ec68f38..e01b01f 100644 --- a/src/KM_fileio.cpp +++ b/src/KM_fileio.cpp @@ -210,7 +210,7 @@ Kumu::FileWriter::Writev(const byte_t* buf, ui32_t buf_len) { DefaultLogSink().Error("The iovec is full! Only %u entries allowed before a flush.\n", IOVecMaxEntries); - return RESULT_FAIL; + return RESULT_WRITEFAIL; } iov->m_iovec[iov->m_Count].iov_base = (char*)buf; // stupid iovec uses char* @@ -405,13 +405,12 @@ Kumu::FileWriter::Writev(ui32_t* bytes_written) (DWORD*)&tmp_count, NULL); - if ( wr_result == 0 ) + if ( wr_result == 0 || tmp_count != iov->m_iovec[i].iov_len) { result = Kumu::RESULT_WRITEFAIL; break; } - assert(iov->m_iovec[i].iov_len == tmp_count); *bytes_written += tmp_count; } @@ -439,7 +438,10 @@ Kumu::FileWriter::Write(const byte_t* buf, ui32_t buf_len, ui32_t* bytes_written BOOL result = ::WriteFile(m_Handle, buf, buf_len, (DWORD*)bytes_written, NULL); ::SetErrorMode(prev); - return ( result == 0 ) ? Kumu::RESULT_WRITEFAIL : Kumu::RESULT_OK; + if ( result == 0 || bytes_written != buf_len ) + return Kumu::RESULT_WRITEFAIL; + + return Kumu::RESULT_OK; } #else // KM_WIN32 @@ -576,13 +578,17 @@ Kumu::FileWriter::Writev(ui32_t* bytes_written) if ( m_Handle == -1L ) return RESULT_STATE; - int read_size = writev(m_Handle, iov->m_iovec, iov->m_Count); + int total_size = 0; + for ( int i = 0; i < iov->m_Count; i++ ) + total_size += iov->m_iovec[i].iov_len; + + int write_size = writev(m_Handle, iov->m_iovec, iov->m_Count); - if ( read_size == -1L ) + if ( write_size == -1L || write_size != total_size ) return RESULT_WRITEFAIL; iov->m_Count = 0; - *bytes_written = read_size; + *bytes_written = write_size; return RESULT_OK; } @@ -596,18 +602,15 @@ Kumu::FileWriter::Write(const byte_t* buf, ui32_t buf_len, ui32_t* bytes_written if ( bytes_written == 0 ) bytes_written = &tmp_int; - // TODO: flush iovec - - if ( m_Handle == -1L ) return RESULT_STATE; - int read_size = write(m_Handle, buf, buf_len); - - if ( read_size == -1L ) + int write_size = write(m_Handle, buf, buf_len); + + if ( write_size == -1L || (ui32_t)write_size != buf_len ) return RESULT_WRITEFAIL; - *bytes_written = read_size; + *bytes_written = write_size; return RESULT_OK; } @@ -643,7 +646,7 @@ Kumu::ReadFileIntoString(const char* filename, std::string& outString, ui32_t ma if ( fsize == 0 ) { DefaultLogSink().Error("%s: zero file size\n", filename); - return RESULT_ALLOC; + return RESULT_READFAIL; } result = ReadBuf.Capacity((ui32_t)fsize); @@ -672,10 +675,7 @@ Kumu::WriteStringIntoFile(const char* filename, const std::string& inString) if ( KM_SUCCESS(result) ) result = File.Write((byte_t*)inString.c_str(), inString.length(), &write_count); - if ( KM_SUCCESS(result) && write_count != inString.length() ) - return RESULT_WRITEFAIL; - - return RESULT_OK; + return result; } diff --git a/src/KM_util.cpp b/src/KM_util.cpp index 8228739..99bb4a9 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -921,31 +921,6 @@ Kumu::Timestamp::Archive(MemIOWriter* Writer) const return true; } -#if 0 -// -bool -Kumu::UnarchiveString(MemIOReader* Reader, std::string&) -{ - assert(Reader); - ui32_t str_length; - if ( ! Reader->ReadUi32BE(&str_length) ) return false; - assign((const char*)Reader->CurrentData(), str_length); - if ( ! Reader->SkipOffset(str_length) ) return false; - return true; -} - -// -bool -Kumu::String::Archive(MemIOWriter* Writer) const -{ - assert(Writer); - if ( ! Writer->WriteUi32BE(length()) ) return false; - if ( ! Writer->WriteRaw((const byte_t*)c_str(), length()) ) return false; - - return true; -} -#endif - //------------------------------------------------------------------------------------------ Kumu::MemIOWriter::MemIOWriter(ByteString* Buf) diff --git a/src/KM_util.h b/src/KM_util.h index dbbdedf..5ca3baa 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -36,6 +36,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace Kumu { @@ -265,7 +266,43 @@ namespace Kumu } }; - + // + template + class IdentifierList : public std::list, public IArchive + { + public: + IdentifierList() {} + virtual ~IdentifierList() {} + + bool HasValue() const { return ! this->empty(); } + + bool Unarchive(Kumu::MemIOReader* Reader) + { + if ( Reader == 0 )return false; + ui32_t read_size = 0; + if ( ! Reader->ReadUi32BE(&read_size) ) return false; + for ( ui32_t i = 0; i < read_size; i++ ) + { + T TmpTP; + if ( ! TmpTP.Unarchive(Reader) ) return false; + this->push_back(TmpTP); + } + + return true; + } + + bool Archive(Kumu::MemIOWriter* Writer) const + { + if ( Writer == 0 )return false; + if ( ! Writer->WriteUi32BE(this->size()) ) return false; + typename IdentifierList::const_iterator i = this->begin(); + for ( ; i != this->end(); i++ ) + if ( ! (*i).Archive(Writer) ) return false; + + return true; + } + }; + // UUID // const ui32_t UUID_Length = 16; diff --git a/src/MXF.cpp b/src/MXF.cpp index 8bc2d0e..168ee52 100755 --- a/src/MXF.cpp +++ b/src/MXF.cpp @@ -629,17 +629,12 @@ ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader) else { m_HasRIP = true; - } - } - - if ( ASDCP_SUCCESS(result) ) - { - Array::iterator r_i = m_RIP.PairArray.begin(); - if ( (*r_i).ByteOffset != 0 ) - { - DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n"); - result = RESULT_FORMAT; + if ( m_RIP.PairArray.front().ByteOffset != 0 ) + { + DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n"); + result = RESULT_FORMAT; + } } } @@ -649,6 +644,9 @@ ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader) if ( ASDCP_SUCCESS(result) ) result = Partition::InitFromFile(Reader); // test UL and OP + if ( ASDCP_FAILURE(result) ) + return result; + // is it really OP-Atom? UL OPAtomUL(Dict::ul(MDD_OPAtom)); UL InteropOPAtomUL(Dict::ul(MDD_MXFInterop_OPAtom)); @@ -664,24 +662,24 @@ ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader) } // slurp up the remainder of the header - if ( ASDCP_SUCCESS(result) ) - { - if ( HeaderByteCount < 1024 ) - DefaultLogSink().Warn("Improbably small HeaderByteCount value: %u\n", HeaderByteCount); + if ( HeaderByteCount < 1024 ) + DefaultLogSink().Warn("Improbably small HeaderByteCount value: %u\n", HeaderByteCount); - result = m_Buffer.Capacity(HeaderByteCount); - } + result = m_Buffer.Capacity(HeaderByteCount); if ( ASDCP_SUCCESS(result) ) { ui32_t read_count; result = Reader.Read(m_Buffer.Data(), m_Buffer.Capacity(), &read_count); - if ( ASDCP_SUCCESS(result) && read_count != m_Buffer.Capacity() ) + if ( ASDCP_FAILURE(result) ) + return result; + + if ( read_count != m_Buffer.Capacity() ) { DefaultLogSink().Error("Short read of OP-Atom header metadata; wanted %u, got %u\n", m_Buffer.Capacity(), read_count); - return RESULT_FAIL; + return RESULT_KLV_CODING; } }