new interface for in-memory metadata packets
authorjhurst <jhurst@cinecert.com>
Mon, 6 Oct 2008 04:40:02 +0000 (04:40 +0000)
committerjhurst <>
Mon, 6 Oct 2008 04:40:02 +0000 (04:40 +0000)
src/AS_DCP_MXF.cpp
src/KM_tai.cpp
src/MXF.cpp
src/MXF.h

index 6b30da94d45f35100b1f8453c7eb808288ea8fec..8bb084e268a100e783bde60c73f42a3b8b0b8144 100755 (executable)
@@ -431,7 +431,7 @@ ASDCP::IntegrityPack::CalcValues(const ASDCP::FrameBuffer& FB, byte_t* AssetID,
   byte_t* p = Data;
   HMAC->Reset();
 
-  static byte_t ber_4[MXF_BER_LENGTH] = {0x83, 0};
+  static byte_t ber_4[MXF_BER_LENGTH] = {0x83, 0, 0, 0};
 
   // update HMAC with essence data
   HMAC->Update(FB.RoData(), FB.Size());
index 7aa7ada1e0e788e27f365a6dce3d07fa61a68b61..dca8471449e13d33d7acdbae95519eb7cc2610d7 100644 (file)
@@ -55,6 +55,7 @@ The libtai source code is in the public domain.
 void
 caldate_frommjd(Kumu::TAI::caldate* cd, i32_t day)
 {
+  assert(cd);
   i32_t year, month, yday;
 
   year = day / 146097L;
@@ -101,6 +102,7 @@ static ui32_t montab[12] =
 i32_t
 caldate_mjd(const Kumu::TAI::caldate* cd)
 {
+  assert(cd);
   i32_t y, m, d;
 
   d = cd->day - 678882L;
@@ -138,6 +140,7 @@ caldate_mjd(const Kumu::TAI::caldate* cd)
 void
 caltime_utc(Kumu::TAI::caltime* ct, const Kumu::TAI::tai* t)
 {
+  assert(ct&&t);
   Kumu::TAI::tai t2 = *t;
   ui64_t u;
   i32_t s;
@@ -163,6 +166,7 @@ caltime_utc(Kumu::TAI::caltime* ct, const Kumu::TAI::tai* t)
 void
 caltime_tai(const Kumu::TAI::caltime* ct, Kumu::TAI::tai* t)
 {
+  assert(ct&&t);
   i32_t day, s;
 
   /* XXX: check for overflow? */
index d01393c9f26eab1e39c4d5c5c130f2a888de97ed..cc09b1575cb604d7741007668b86839b0fc22c89 100755 (executable)
@@ -283,27 +283,33 @@ ASDCP::MXF::Partition::InitFromFile(const Kumu::FileReader& Reader)
   Result_t result = KLVFilePacket::InitFromFile(Reader);
   // test the UL
   // could be one of several values
-
   if ( ASDCP_SUCCESS(result) )
-    {
-      Kumu::MemIOReader MemRDR(m_ValueStart, m_ValueLength);
-      result = RESULT_KLV_CODING;
+    result = ASDCP::MXF::Partition::InitFromBuffer(m_ValueStart, m_ValueLength);
+  
+  return result;
+}
 
-      if ( MemRDR.ReadUi16BE(&MajorVersion) )
-       if ( MemRDR.ReadUi16BE(&MinorVersion) )
-         if ( MemRDR.ReadUi32BE(&KAGSize) )
-           if ( MemRDR.ReadUi64BE(&ThisPartition) )
-             if ( MemRDR.ReadUi64BE(&PreviousPartition) )
-               if ( MemRDR.ReadUi64BE(&FooterPartition) )
-                 if ( MemRDR.ReadUi64BE(&HeaderByteCount) )
-                   if ( MemRDR.ReadUi64BE(&IndexByteCount) )
-                     if ( MemRDR.ReadUi32BE(&IndexSID) )
-                       if ( MemRDR.ReadUi64BE(&BodyOffset) )
-                         if ( MemRDR.ReadUi32BE(&BodySID) )
-                           if ( OperationalPattern.Unarchive(&MemRDR) )
-                             if ( EssenceContainers.Unarchive(&MemRDR) )
-                               result = RESULT_OK;
-    }
+//
+ASDCP::Result_t
+ASDCP::MXF::Partition::InitFromBuffer(const byte_t* p, ui32_t l)
+{
+  Kumu::MemIOReader MemRDR(p, l);
+  Result_t result = RESULT_KLV_CODING;
+
+  if ( MemRDR.ReadUi16BE(&MajorVersion) )
+    if ( MemRDR.ReadUi16BE(&MinorVersion) )
+      if ( MemRDR.ReadUi32BE(&KAGSize) )
+       if ( MemRDR.ReadUi64BE(&ThisPartition) )
+         if ( MemRDR.ReadUi64BE(&PreviousPartition) )
+           if ( MemRDR.ReadUi64BE(&FooterPartition) )
+             if ( MemRDR.ReadUi64BE(&HeaderByteCount) )
+               if ( MemRDR.ReadUi64BE(&IndexByteCount) )
+                 if ( MemRDR.ReadUi32BE(&IndexSID) )
+                   if ( MemRDR.ReadUi64BE(&BodyOffset) )
+                     if ( MemRDR.ReadUi32BE(&BodySID) )
+                       if ( OperationalPattern.Unarchive(&MemRDR) )
+                         if ( EssenceContainers.Unarchive(&MemRDR) )
+                           result = RESULT_OK;
 
   if ( ASDCP_FAILURE(result) )
     DefaultLogSink().Error("Failed to initialize Partition\n");
@@ -731,8 +737,33 @@ ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader)
        }
     }
 
-  const byte_t* p = m_Buffer.RoData();
-  const byte_t* end_p = p + m_Buffer.Capacity();
+  result = InitFromBuffer(m_Buffer.RoData(), m_Buffer.Capacity());
+}
+
+//
+ASDCP::Result_t
+ASDCP::MXF::OPAtomHeader::InitFromPartitionBuffer(const byte_t* p, ui32_t l)
+{
+  Result_t result = KLVPacket::InitFromBuffer(p, l);
+
+  if ( ASDCP_SUCCESS(result) )
+    result = Partition::InitFromBuffer(m_ValueStart, m_ValueLength); // test UL and OP
+
+  if ( ASDCP_SUCCESS(result) )
+    {
+      ui32_t pp_len = KLVPacket::PacketLength();
+      result = InitFromBuffer(p + pp_len, l - pp_len);
+    }
+
+  return result;
+}
+
+//
+ASDCP::Result_t
+ASDCP::MXF::OPAtomHeader::InitFromBuffer(const byte_t* p, ui32_t l)
+{
+  Result_t result = RESULT_OK;
+  const byte_t* end_p = p + l;
 
   while ( ASDCP_SUCCESS(result) && p < end_p )
     {
@@ -761,11 +792,8 @@ ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader)
            {
              m_PacketList->AddPacket(object);
 
-             if ( object->IsA(Dict::ul(MDD_Preface)) )
-               {
-                 assert(m_Preface == 0);
-                 m_Preface = (Preface*)object;
-               }
+             if ( object->IsA(Dict::ul(MDD_Preface)) && m_Preface == 0 )
+               m_Preface = (Preface*)object;
            }
        }
       else
@@ -948,7 +976,7 @@ ASDCP::MXF::OPAtomIndexFooter::OPAtomIndexFooter() :
 
 ASDCP::MXF::OPAtomIndexFooter::~OPAtomIndexFooter() {}
 
-
+//
 ASDCP::Result_t
 ASDCP::MXF::OPAtomIndexFooter::InitFromFile(const Kumu::FileReader& Reader)
 {
@@ -973,8 +1001,36 @@ ASDCP::MXF::OPAtomIndexFooter::InitFromFile(const Kumu::FileReader& Reader)
       return RESULT_FAIL;
     }
 
-  const byte_t* p = m_Buffer.RoData();
-  const byte_t* end_p = p + m_Buffer.Capacity();
+  if ( ASDCP_SUCCESS(result) )
+    result = InitFromBuffer(m_Buffer.RoData(), m_Buffer.Capacity());
+
+  return result;
+}
+
+//
+ASDCP::Result_t
+ASDCP::MXF::OPAtomIndexFooter::InitFromPartitionBuffer(const byte_t* p, ui32_t l)
+{
+  Result_t result = KLVPacket::InitFromBuffer(p, l);
+
+  if ( ASDCP_SUCCESS(result) )
+    result = Partition::InitFromBuffer(m_ValueStart, m_ValueLength); // test UL and OP
+
+  if ( ASDCP_SUCCESS(result) )
+    {
+      ui32_t pp_len = KLVPacket::PacketLength();
+      result = InitFromBuffer(p + pp_len, l - pp_len);
+    }
+
+  return result;
+}
+
+//
+ASDCP::Result_t
+ASDCP::MXF::OPAtomIndexFooter::InitFromBuffer(const byte_t* p, ui32_t l)
+{
+  Result_t result = RESULT_OK;
+  const byte_t* end_p = p + l;
   
   while ( ASDCP_SUCCESS(result) && p < end_p )
     {
index 6a9b14d47dca824db2cd5aa00242bcc614c30e15..95f904358595df7957f16e3e21354901f0da4650 100755 (executable)
--- a/src/MXF.h
+++ b/src/MXF.h
@@ -133,6 +133,7 @@ namespace ASDCP
          virtual ~Partition();
          virtual void     AddChildObject(InterchangeObject*);
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer, UL& PartitionLabel);
          virtual ui32_t   ArchiveSize(); // returns the size of the archived structure
          virtual void     Dump(FILE* = 0);
@@ -327,6 +328,8 @@ namespace ASDCP
          OPAtomHeader();
          virtual ~OPAtomHeader();
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t InitFromPartitionBuffer(const byte_t* p, ui32_t l);
+         virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderLength = 16384);
          virtual void     Dump(FILE* = 0);
          virtual Result_t GetMDObjectByID(const UUID&, InterchangeObject** = 0);
@@ -353,6 +356,8 @@ namespace ASDCP
          OPAtomIndexFooter();
          virtual ~OPAtomIndexFooter();
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t InitFromPartitionBuffer(const byte_t* p, ui32_t l);
+         virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui64_t duration);
          virtual void     Dump(FILE* = 0);