added identifier list type
authorjhurst <jhurst@cinecert.com>
Mon, 26 Mar 2007 23:08:16 +0000 (23:08 +0000)
committerjhurst <>
Mon, 26 Mar 2007 23:08:16 +0000 (23:08 +0000)
src/AS_DCP.h
src/AS_DCP_MPEG2.cpp
src/KM_fileio.cpp
src/KM_util.cpp
src/KM_util.h
src/MXF.cpp

index 4e10d09a361ba1f31f128eb3d6f5d42e0230ece8..05b1e651294b79905558b744f15ebe1962a44c88 100755 (executable)
@@ -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
index a0a4ad7ff8190f806ba33673f16e34c85b563306..b3044f63f3d2551f641331543af037e4a8892138 100755 (executable)
@@ -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++;
index ec68f3804b78f206d23f917bf42a40cbdb4a7b1a..e01b01ffee0973e47618b03c379d3b792ab78ce3 100644 (file)
@@ -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;
 }
 
 
index 82287390f609f3e0db40d6900928a3690ce087fb..99bb4a92f3abc501930093bc259984d797251274 100755 (executable)
@@ -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)
index dbbdedf40a70f46e83f8de877f9fa80c0b989dce..5ca3baa5d5218db8d48fab31140f7adb88257320 100755 (executable)
@@ -36,6 +36,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <KM_error.h>
 #include <string.h>
 #include <string>
+#include <list>
 
 namespace Kumu
 {
@@ -265,7 +266,43 @@ 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;
index 8bc2d0e4d231946abf66ebacc309302ff8bc4e3b..168ee527d713997fe54307711d020177f7db6a87 100755 (executable)
@@ -629,17 +629,12 @@ ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader)
       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;
+           }
        }
     }
 
@@ -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;
        }
     }