ISXDDataEssenceDescriptor_NamespaceURI UL fixed
[asdcplib.git] / src / h__02_Writer.cpp
index ff8d000e71f668d3c77566c22bebb77f70f76086..9b1c6c6d27625db4d94b3e77825ae455b62d6038 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2011-2013, Robert Scheler, Heiko Sparenberg Fraunhofer IIS,
+Copyright (c) 2011-2018, Robert Scheler, Heiko Sparenberg Fraunhofer IIS,
 John Hurst
 
 All rights reserved.
@@ -47,6 +47,7 @@ AS_02::MXF::AS02IndexWriterVBR::AS02IndexWriterVBR(const ASDCP::Dictionary*& d)
 {
   BodySID = 0;
   IndexSID = 129;
+  MinorVersion = 3;
 }
 
 AS_02::MXF::AS02IndexWriterVBR::~AS02IndexWriterVBR() {}
@@ -57,7 +58,7 @@ AS_02::MXF::AS02IndexWriterVBR::WriteToFile(Kumu::FileWriter& Writer)
 {
   assert(m_Dict);
   ASDCP::FrameBuffer index_body_buffer;
-  ui32_t   index_body_size = m_PacketList->m_List.size() * MaxIndexSegmentSize; // segment-count * max-segment-size
+  ui32_t index_body_size = (ui32_t)m_PacketList->m_List.size() * MaxIndexSegmentSize; // segment-count * max-segment-size
   Result_t result = index_body_buffer.Capacity(index_body_size); 
   ui64_t start_position = 0;
 
@@ -140,7 +141,7 @@ AS_02::MXF::AS02IndexWriterVBR::GetDuration() const
       IndexTableSegment* segment = dynamic_cast<IndexTableSegment*>(*i);
       if ( segment != 0 )
        {
-         duration += segment->IndexEntryArray.size();
+         duration += (ui32_t)segment->IndexEntryArray.size();
        }
     }
 
@@ -165,6 +166,11 @@ AS_02::MXF::AS02IndexWriterVBR::PushIndexEntry(const IndexTableSegment::IndexEnt
   m_CurrentSegment->IndexEntryArray.push_back(Entry);
 }
 
+void
+AS_02::MXF::AS02IndexWriterVBR::SetEditRate(const ASDCP::Rational& edit_rate)
+{
+  m_EditRate = edit_rate;
+}
 
 //------------------------------------------------------------------------------------------
 //
@@ -177,12 +183,14 @@ AS_02::h__AS02WriterFrame::~h__AS02WriterFrame() {}
 
 //
 Result_t
-AS_02::h__AS02WriterFrame::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL, AESEncContext* Ctx, HMACContext* HMAC)
+AS_02::h__AS02WriterFrame::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL,
+                                          const ui32_t& MinEssenceElementBerLength,
+                                          AESEncContext* Ctx, HMACContext* HMAC)
 {
   ui64_t this_stream_offset = m_StreamOffset; // m_StreamOffset will be changed by the call to Write_EKLV_Packet
 
   Result_t result = Write_EKLV_Packet(m_File, *m_Dict, m_HeaderPart, m_Info, m_CtFrameBuf, m_FramesWritten,
-                                     m_StreamOffset, FrameBuf, EssenceUL, Ctx, HMAC);
+                                     m_StreamOffset, FrameBuf, EssenceUL, MinEssenceElementBerLength, Ctx, HMAC);
 
   if ( KM_SUCCESS(result) )
     {  
@@ -191,14 +199,15 @@ AS_02::h__AS02WriterFrame::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,co
       m_IndexWriter.PushIndexEntry(Entry);
     }
 
-  if ( m_FramesWritten > 0 && ( m_FramesWritten % m_PartitionSpace ) == 0 )
+  if ( m_FramesWritten > 1 && ( ( m_FramesWritten + 1 ) % m_PartitionSpace ) == 0 )
     {
-      m_IndexWriter.ThisPartition = m_File.Tell();
-      m_IndexWriter.WriteToFile(m_File);
-      m_RIP.PairArray.push_back(RIP::Pair(0, m_IndexWriter.ThisPartition));
+      assert(m_IndexWriter.GetDuration() > 0);
+      FlushIndexPartition();
 
       UL body_ul(m_Dict->ul(MDD_ClosedCompleteBodyPartition));
       Partition body_part(m_Dict);
+      body_part.MajorVersion = m_HeaderPart.MajorVersion;
+      body_part.MinorVersion = m_HeaderPart.MinorVersion;
       body_part.BodySID = 1;
       body_part.OperationalPattern = m_HeaderPart.OperationalPattern;
       body_part.EssenceContainers = m_HeaderPart.EssenceContainers;
@@ -206,7 +215,7 @@ AS_02::h__AS02WriterFrame::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,co
 
       body_part.BodyOffset = m_StreamOffset;
       result = body_part.WriteToFile(m_File, body_ul);
-      m_RIP.PairArray.push_back(RIP::Pair(1, body_part.ThisPartition));
+      m_RIP.PairArray.push_back(RIP::PartitionPair(1, body_part.ThisPartition));
     }
 
   return result;
@@ -222,6 +231,7 @@ AS_02::MXF::AS02IndexWriterCBR::AS02IndexWriterCBR(const ASDCP::Dictionary*& d)
 {
   BodySID = 0;
   IndexSID = 129;
+  MinorVersion = 3;
 }
 
 AS_02::MXF::AS02IndexWriterCBR::~AS02IndexWriterCBR() {}
@@ -372,8 +382,6 @@ AS_02::h__AS02WriterClip::FinalizeClip(ui32_t bytes_per_frame)
   return result;
 }
 
-
-
 //
 // end h__02_Writer.cpp
 //