Support hashing while writing MXFs.
[asdcplib.git] / src / h__Writer.cpp
index c7aa8ab792d48149a5339ce61d41c8617e1f30de..4eaf72fd832499abea0f9a747266018b96e20c8a 100755 (executable)
@@ -319,12 +319,12 @@ ASDCP::h__ASDCPWriter::WriteASDCPHeader(const std::string& PackageLabel, const U
 //
 Result_t
 ASDCP::h__ASDCPWriter::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL,
-                                      const ui32_t& MinEssenceElementBerLength,               
-                                      AESEncContext* Ctx, HMACContext* HMAC)
+                                      const ui32_t& MinEssenceElementBerLength,
+                                      AESEncContext* Ctx, HMACContext* HMAC, std::string* hash)
 {
   return Write_EKLV_Packet(m_File, *m_Dict, m_HeaderPart, m_Info, m_CtFrameBuf, m_FramesWritten,
                           m_StreamOffset, FrameBuf, EssenceUL, MinEssenceElementBerLength,
-                          Ctx, HMAC);
+                          Ctx, HMAC, hash);
 }
 
 Result_t
@@ -393,11 +393,16 @@ ASDCP::Write_EKLV_Packet(Kumu::FileWriter& File, const ASDCP::Dictionary& Dict,
                         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)
+                        AESEncContext* Ctx, HMACContext* HMAC, std::string* hash)
 {
   Result_t result = RESULT_OK;
   IntegrityPack IntPack;
 
+  if (hash)
+    {
+      File.StartHashing();
+    }
+
   byte_t overhead[128];
   Kumu::MemIOWriter Overhead(overhead, 128);
   // We declare HMACOverhead and its buffer in the outer scope, even though it is not used on
@@ -538,6 +543,11 @@ ASDCP::Write_EKLV_Packet(Kumu::FileWriter& File, const ASDCP::Dictionary& Dict,
   if ( ASDCP_SUCCESS(result) )
     result = File.Writev();
 
+  if (hash)
+    {
+      *hash = File.StopHashing();
+    }
+
   return result;
 }