Updating version info in Win32 portions
[asdcplib.git] / src / Index.cpp
index 0f243f865ebc6ef5191237ff7d377dc804492e91..307e8518a816fad30db4da75428bc7255cf940e2 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2006, John Hurst
+Copyright (c) 2005-2009, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -34,7 +34,8 @@ const ui32_t kl_length = ASDCP::SMPTE_UL_LENGTH + ASDCP::MXF_BER_LENGTH;
 
 
 //
-ASDCP::MXF::IndexTableSegment::IndexTableSegment() :
+ASDCP::MXF::IndexTableSegment::IndexTableSegment(const Dictionary*& d) :
+  InterchangeObject(d), m_Dict(d),
   IndexStartPosition(0), IndexDuration(0), EditUnitByteCount(0),
   IndexSID(129), BodySID(1), SliceCount(0), PosTableCount(0)
 {
@@ -55,27 +56,11 @@ ASDCP::MXF::IndexTableSegment::InitFromTLVSet(TLVReader& TLVSet)
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi64(OBJ_READ_ARGS(IndexTableSegmentBase, IndexDuration));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, EditUnitByteCount));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, IndexSID));
-  if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, BodySID));
+  if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(EssenceContainerData, BodySID));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi8(OBJ_READ_ARGS(IndexTableSegmentBase, SliceCount));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi8(OBJ_READ_ARGS(IndexTableSegmentBase, PosTableCount));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegment, DeltaEntryArray));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegment, IndexEntryArray));
-
-#if 0
-  if ( ASDCP_SUCCESS(result) )
-    {
-      Batch<IndexEntry>::iterator i;
-      ui32_t offset = 0;
-      for ( i = IndexEntryArray.begin(); i != IndexEntryArray.end(); i++ )
-       {
-         if ( (*i).Flags == 0x40 )
-           offset = 0;
-
-         (*i).KeyFrameOffset = offset++;
-       }
-    }
-#endif
-
   return result;
 }
 
@@ -89,7 +74,7 @@ ASDCP::MXF::IndexTableSegment::WriteToTLVSet(TLVWriter& TLVSet)
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi64(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexDuration));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, EditUnitByteCount));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexSID));
-  if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, BodySID));
+  if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(EssenceContainerData, BodySID));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi8(OBJ_WRITE_ARGS(IndexTableSegmentBase, SliceCount));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi8(OBJ_WRITE_ARGS(IndexTableSegmentBase, PosTableCount));
   if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegment, DeltaEntryArray));
@@ -101,7 +86,8 @@ ASDCP::MXF::IndexTableSegment::WriteToTLVSet(TLVWriter& TLVSet)
 ASDCP::Result_t
 ASDCP::MXF::IndexTableSegment::InitFromBuffer(const byte_t* p, ui32_t l)
 {
-  m_Typeinfo = &Dict::Type(MDD_IndexTableSegment);
+  assert(m_Dict);
+  m_Typeinfo = &(m_Dict->Type(MDD_IndexTableSegment));
   return InterchangeObject::InitFromBuffer(p, l);
 }
 
@@ -109,7 +95,8 @@ ASDCP::MXF::IndexTableSegment::InitFromBuffer(const byte_t* p, ui32_t l)
 ASDCP::Result_t
 ASDCP::MXF::IndexTableSegment::WriteToBuffer(ASDCP::FrameBuffer& Buffer)
 {
-  m_Typeinfo = &Dict::Type(MDD_IndexTableSegment);
+  assert(m_Dict);
+  m_Typeinfo = &(m_Dict->Type(MDD_IndexTableSegment));
   return InterchangeObject::WriteToBuffer(Buffer);
 }
 
@@ -123,12 +110,12 @@ ASDCP::MXF::IndexTableSegment::Dump(FILE* stream)
     stream = stderr;
 
   InterchangeObject::Dump(stream);
-  fprintf(stream, "  IndexEditRate      = %s\n",  IndexEditRate.ToString(identbuf));
+  fprintf(stream, "  IndexEditRate      = %s\n",  IndexEditRate.EncodeString(identbuf, IdentBufferLen));
   fprintf(stream, "  IndexStartPosition = %s\n",  i64sz(IndexStartPosition, identbuf));
   fprintf(stream, "  IndexDuration      = %s\n",  i64sz(IndexDuration, identbuf));
-  fprintf(stream, "  EditUnitByteCount  = %lu\n", EditUnitByteCount);
-  fprintf(stream, "  IndexSID           = %lu\n", IndexSID);
-  fprintf(stream, "  BodySID            = %lu\n", BodySID);
+  fprintf(stream, "  EditUnitByteCount  = %u\n",  EditUnitByteCount);
+  fprintf(stream, "  IndexSID           = %u\n",  IndexSID);
+  fprintf(stream, "  BodySID            = %u\n",  BodySID);
   fprintf(stream, "  SliceCount         = %hu\n", SliceCount);
   fprintf(stream, "  PosTableCount      = %hu\n", PosTableCount);
 
@@ -141,7 +128,7 @@ ASDCP::MXF::IndexTableSegment::Dump(FILE* stream)
     }
   else
     {
-      fprintf(stream, "  IndexEntryArray: %lu entries\n", IndexEntryArray.size());
+      fprintf(stream, "  IndexEntryArray: %du entries\n", IndexEntryArray.size());
     }
 }
 
@@ -150,30 +137,30 @@ ASDCP::MXF::IndexTableSegment::Dump(FILE* stream)
 
 //
 const char*
-ASDCP::MXF::IndexTableSegment::DeltaEntry::ToString(char* str_buf) const
+ASDCP::MXF::IndexTableSegment::DeltaEntry::EncodeString(char* str_buf, ui32_t buf_len) const
 {
-  snprintf(str_buf, IdentBufferLen, "%3i %-3hu %-3lu", PosTableIndex, Slice, ElementData);
+  snprintf(str_buf, buf_len, "%3d %-3hu %-3u", PosTableIndex, Slice, ElementData);
   return str_buf;
 }
 
 //
-ASDCP::Result_t
-ASDCP::MXF::IndexTableSegment::DeltaEntry::Unarchive(ASDCP::MemIOReader& Reader)
+bool
+ASDCP::MXF::IndexTableSegment::DeltaEntry::Unarchive(Kumu::MemIOReader* Reader)
 {
-  Result_t result = Reader.ReadUi8((ui8_t*)&PosTableIndex);
-  if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Slice);
-  if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi32BE(&ElementData);
-  return result;
+  if ( ! Reader->ReadUi8((ui8_t*)&PosTableIndex) ) return false;
+  if ( ! Reader->ReadUi8(&Slice) ) return false;
+  if ( ! Reader->ReadUi32BE(&ElementData) ) return false;
+  return true;
 }
 
 //
-ASDCP::Result_t
-ASDCP::MXF::IndexTableSegment::DeltaEntry::Archive(ASDCP::MemIOWriter& Writer) const
+bool
+ASDCP::MXF::IndexTableSegment::DeltaEntry::Archive(Kumu::MemIOWriter* Writer) const
 {
-  Result_t result = Writer.WriteUi8((ui8_t)PosTableIndex);
-  if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Slice);
-  if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi32BE(ElementData);
-  return result;
+  if ( ! Writer->WriteUi8((ui8_t)PosTableIndex) ) return false;
+  if ( ! Writer->WriteUi8(Slice) ) return false;
+  if ( ! Writer->WriteUi32BE(ElementData) ) return false;
+  return true;
 }
 
 //------------------------------------------------------------------------------------------
@@ -193,7 +180,7 @@ ASDCP::MXF::IndexTableSegment::DeltaEntry::Archive(ASDCP::MemIOWriter& Writer) c
 
 //
 const char*
-ASDCP::MXF::IndexTableSegment::IndexEntry::ToString(char* str_buf) const
+ASDCP::MXF::IndexTableSegment::IndexEntry::EncodeString(char* str_buf, ui32_t buf_len) const
 {
   char intbuf[IntBufferLen];
   char txt_flags[6];
@@ -205,33 +192,33 @@ ASDCP::MXF::IndexTableSegment::IndexEntry::ToString(char* str_buf) const
   txt_flags[4] = ( (Flags & 0x0f) == 3 ) ? 'B' : ( (Flags & 0x0f) == 2 ) ? 'P' : 'I';
   txt_flags[5] = 0;
 
-  snprintf(str_buf, IdentBufferLen, "%3i %-3hu %s %s",
-         TemporalOffset, KeyFrameOffset, txt_flags,
-         i64sz(StreamOffset, intbuf));
+  snprintf(str_buf, buf_len, "%3i %-3hu %s %s",
+          TemporalOffset, KeyFrameOffset, txt_flags,
+          i64sz(StreamOffset, intbuf));
 
   return str_buf;
 }
 
 //
-ASDCP::Result_t
-ASDCP::MXF::IndexTableSegment::IndexEntry::Unarchive(ASDCP::MemIOReader& Reader)
+bool
+ASDCP::MXF::IndexTableSegment::IndexEntry::Unarchive(Kumu::MemIOReader* Reader)
 {
-  Result_t result = Reader.ReadUi8((ui8_t*)&TemporalOffset);
-  if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8((ui8_t*)&KeyFrameOffset);
-  if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Flags);
-  if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi64BE(&StreamOffset);
-  return result;
+  if ( ! Reader->ReadUi8((ui8_t*)&TemporalOffset) ) return false;
+  if ( ! Reader->ReadUi8((ui8_t*)&KeyFrameOffset) ) return false;
+  if ( ! Reader->ReadUi8(&Flags) ) return false;
+  if ( ! Reader->ReadUi64BE(&StreamOffset) ) return false;
+  return true;
 }
 
 //
-ASDCP::Result_t
-ASDCP::MXF::IndexTableSegment::IndexEntry::Archive(ASDCP::MemIOWriter& Writer) const
+bool
+ASDCP::MXF::IndexTableSegment::IndexEntry::Archive(Kumu::MemIOWriter* Writer) const
 {
-  Result_t result = Writer.WriteUi8((ui8_t)TemporalOffset);
-  if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8((ui8_t)KeyFrameOffset);
-  if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Flags);
-  if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi64BE(StreamOffset);
-  return result;
+  if ( ! Writer->WriteUi8((ui8_t)TemporalOffset) ) return false;
+  if ( ! Writer->WriteUi8((ui8_t)KeyFrameOffset) ) return false;
+  if ( ! Writer->WriteUi8(Flags) ) return false;
+  if ( ! Writer->WriteUi64BE(StreamOffset) ) return false;
+  return true;
 }