// 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
// 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++;
{
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*
(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;
}
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
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;
}
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;
}
if ( fsize == 0 )
{
DefaultLogSink().Error("%s: zero file size\n", filename);
- return RESULT_ALLOC;
+ return RESULT_READFAIL;
}
result = ReadBuf.Capacity((ui32_t)fsize);
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;
}
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)
#include <KM_error.h>
#include <string.h>
#include <string>
+#include <list>
namespace Kumu
{
}
};
-
+ //
+ template <class T>
+ class IdentifierList : public std::list<T>, 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<T>::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;
else
{
m_HasRIP = true;
- }
- }
-
- if ( ASDCP_SUCCESS(result) )
- {
- Array<RIP::Pair>::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;
+ }
}
}
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));
}
// 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;
}
}