Fix HMAC sequence count on MXF read.
[asdcplib.git] / src / AS_DCP_internal.h
index 1049a98b69bc777c6b8f225c54673c0e01880fcf..57ed006a04dffcee8351ae8362d489e2603a6ba3 100755 (executable)
@@ -47,6 +47,10 @@ using namespace ASDCP::MXF;
 #endif
 
 
+// uncomment to remove MXFGCGenericEssenceMultipleMappings from your AS-02 files
+// #define ASDCP_GCMULTI_PATCH
+
+
 #ifdef DEFAULT_MD_DECL
 ASDCP::MXF::OP1aHeader *g_OP1aHeader;
 ASDCP::MXF::OPAtomIndexFooter *g_OPAtomIndexFooter;
@@ -178,6 +182,7 @@ namespace ASDCP
   Result_t Write_EKLV_Packet(Kumu::FileWriter& File, const ASDCP::Dictionary& Dict, const MXF::OP1aHeader& HeaderPart,
                             const ASDCP::WriterInfo& Info, ASDCP::FrameBuffer& CtFrameBuf, ui32_t& FramesWritten,
                             ui64_t & StreamOffset, const ASDCP::FrameBuffer& FrameBuf, const byte_t* EssenceUL,
+                            const ui32_t& MinEssenceElementBerLength,
                             AESEncContext* Ctx, HMACContext* HMAC);
 
   //
@@ -409,17 +414,23 @@ namespace ASDCP
          // Count the sequence length in because this is the sequence
          // value needed to  complete the HMAC.
          ASDCP::MXF::RIP::const_pair_iterator i;
-         for ( i = m_RIP.PairArray.begin(); i != m_RIP.PairArray.end(); ++i, ++sequence )
+         for ( i = m_RIP.PairArray.begin(); i != m_RIP.PairArray.end(); ++i)
            {
-             if ( sid == i->BodySID )
-               {
-                 start_offset = i->ByteOffset;
-               }
-             else if ( start_offset != 0 )
-               {
-                 end_offset = i->ByteOffset;
-                 break;
-               }
+              if ( sid == i->BodySID )
+                {
+                  assert( start_offset == 0);
+                  start_offset = i->ByteOffset;
+                }
+              else if ( start_offset != 0 )
+                {
+                  end_offset = i->ByteOffset;
+                  break;
+                }
+
+              if ( i->BodySID > 0 )
+                {
+                  ++sequence;
+                }
            }
 
          if ( start_offset == 0 || end_offset == 0 )
@@ -781,8 +792,10 @@ namespace ASDCP
          // Essence Descriptors
          //
          assert(m_Dict);
+#ifndef ASDCP_GCMULTI_PATCH
          UL GenericContainerUL(m_Dict->ul(MDD_GCMulti));
          m_HeaderPart.EssenceContainers.push_back(GenericContainerUL);
+#endif
 
          if ( m_Info.EncryptedEssence )
            {
@@ -841,7 +854,8 @@ namespace ASDCP
              if ( KM_SUCCESS(result) )
                {
                  result = Write_EKLV_Packet(m_File, *m_Dict, m_HeaderPart, m_Info, m_CtFrameBuf, m_FramesWritten,
-                                            m_StreamOffset, frame_buffer, GenericStream_DataElement.Value(), enc, hmac);
+                                            m_StreamOffset, frame_buffer, GenericStream_DataElement.Value(),
+                                            MXF_BER_LENGTH, enc, hmac);
                }
            }
 
@@ -901,6 +915,7 @@ namespace ASDCP
 
       Result_t CreateBodyPart(const MXF::Rational& EditRate, ui32_t BytesPerEditUnit = 0);
       Result_t WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL,
+                              const ui32_t& MinEssenceElementBerLength,
                               AESEncContext* Ctx, HMACContext* HMAC);
       Result_t WriteASDCPFooter();
     };