ReadFileIntoString() modified to return OK when the file is empty
[asdcplib.git] / src / AS_02_internal.h
index 4bdb64cf1342daf7a7bd692ad2c41ba2c69f4747..4be764d8935a30907a0248ca18d6dcbfb90ca579 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.
@@ -63,7 +63,7 @@ namespace AS_02
       h__AS02Reader(const ASDCP::Dictionary&);
       virtual ~h__AS02Reader();
 
-      Result_t OpenMXFRead(const char* filename);
+      Result_t OpenMXFRead(const std::string& filename);
 
       // USE FRAME WRAPPING...
       Result_t ReadEKLVFrame(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf,
@@ -107,6 +107,7 @@ namespace AS_02
 
        ui32_t GetDuration() const;
        void PushIndexEntry(const ASDCP::MXF::IndexTableSegment::IndexEntry&);
+       void SetEditRate(const ASDCP::Rational& edit_rate);
       };
 
 
@@ -172,13 +173,15 @@ namespace AS_02
            return RESULT_PARAM;
          }
 
-       InitHeader();
+       InitHeader(MXFVersion_2011);
 
        AddSourceClip(EditRate, EditRate/*TODO: for a moment*/, TCFrameRate, TrackName, EssenceUL, DataDefinition, PackageLabel);
        AddEssenceDescriptor(WrappingUL);
 
        this->m_IndexWriter.SetPrimerLookup(&this->m_HeaderPart.m_Primer);
-       this->m_RIP.PairArray.push_back(RIP::Pair(0, 0)); // Header partition RIP entry
+       this->m_RIP.PairArray.push_back(RIP::PartitionPair(0, 0)); // Header partition RIP entry
+       this->m_IndexWriter.MajorVersion = m_HeaderPart.MajorVersion;
+       this->m_IndexWriter.MinorVersion = m_HeaderPart.MinorVersion;
        this->m_IndexWriter.OperationalPattern = this->m_HeaderPart.OperationalPattern;
        this->m_IndexWriter.EssenceContainers = this->m_HeaderPart.EssenceContainers;
 
@@ -186,34 +189,41 @@ namespace AS_02
 
        if ( KM_SUCCESS(result) )
          {
-           this->m_PartitionSpace *= floor( EditRate.Quotient() + 0.5 );  // convert seconds to edit units
+           this->m_PartitionSpace *= (ui32_t)floor( EditRate.Quotient() + 0.5 );  // convert seconds to edit units
            this->m_ECStart = this->m_File.Tell();
            this->m_IndexWriter.IndexSID = 129;
 
            UL body_ul(this->m_Dict->ul(MDD_ClosedCompleteBodyPartition));
            Partition body_part(this->m_Dict);
            body_part.BodySID = 1;
+           body_part.MajorVersion = this->m_HeaderPart.MajorVersion;
+           body_part.MinorVersion = this->m_HeaderPart.MinorVersion;
            body_part.OperationalPattern = this->m_HeaderPart.OperationalPattern;
            body_part.EssenceContainers = this->m_HeaderPart.EssenceContainers;
            body_part.ThisPartition = this->m_ECStart;
            result = body_part.WriteToFile(this->m_File, body_ul);
-           this->m_RIP.PairArray.push_back(RIP::Pair(1, body_part.ThisPartition)); // Second RIP Entry
+           this->m_RIP.PairArray.push_back(RIP::PartitionPair(1, body_part.ThisPartition)); // Second RIP Entry
          }
 
        return result;
       }
 
-      // standard method of writing the header and footer of a completed AS-02 file
-      //
-      Result_t WriteAS02Footer()
+      void FlushIndexPartition()
       {
        if ( this->m_IndexWriter.GetDuration() > 0 )
          {
            this->m_IndexWriter.ThisPartition = this->m_File.Tell();
            this->m_IndexWriter.WriteToFile(this->m_File);
-           this->m_RIP.PairArray.push_back(RIP::Pair(0, this->m_IndexWriter.ThisPartition));
+           this->m_RIP.PairArray.push_back(RIP::PartitionPair(0, this->m_IndexWriter.ThisPartition));
          }
-
+      }
+      
+      // standard method of writing the header and footer of a completed AS-02 file
+      //
+      Result_t WriteAS02Footer()
+      {
+       this->FlushIndexPartition();
+         
        // update all Duration properties
        ASDCP::MXF::Partition footer_part(this->m_Dict);
        DurationElementList_t::iterator dli = this->m_DurationUpdateList.begin();
@@ -227,10 +237,12 @@ namespace AS_02
        footer_part.PreviousPartition = this->m_RIP.PairArray.back().ByteOffset;
 
        Kumu::fpos_t here = this->m_File.Tell();
-       this->m_RIP.PairArray.push_back(RIP::Pair(0, here)); // Last RIP Entry
+       this->m_RIP.PairArray.push_back(RIP::PartitionPair(0, here)); // Last RIP Entry
        this->m_HeaderPart.FooterPartition = here;
 
        assert(this->m_Dict);
+       footer_part.MajorVersion = this->m_HeaderPart.MajorVersion;
+       footer_part.MinorVersion = this->m_HeaderPart.MinorVersion;
        footer_part.OperationalPattern = this->m_HeaderPart.OperationalPattern;
        footer_part.EssenceContainers = this->m_HeaderPart.EssenceContainers;
        footer_part.FooterPartition = here;
@@ -250,7 +262,7 @@ namespace AS_02
   
        if ( KM_SUCCESS(result) )
          {
-           ASDCP::MXF::Array<ASDCP::MXF::RIP::Pair>::const_iterator i = this->m_RIP.PairArray.begin();
+           ASDCP::MXF::RIP::const_pair_iterator i = this->m_RIP.PairArray.begin();
            ui64_t header_byte_count = this->m_HeaderPart.HeaderByteCount;
            ui64_t previous_partition = 0;
 
@@ -297,6 +309,7 @@ namespace AS_02
       virtual ~h__AS02WriterFrame();
 
       Result_t WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL,
+                              const ui32_t& MinEssenceElementBerLength,
                               AESEncContext* Ctx, HMACContext* HMAC);
     };
 
@@ -309,7 +322,6 @@ namespace AS_02
     public:
       ui64_t  m_ECStart; // offset of the first essence element
       ui64_t  m_ClipStart;  // state variable for clip-wrap-in-progress
-      //      AS_02::MXF::AS02IndexWriterCBR m_IndexWriter;
       IndexStrategy_t m_IndexStrategy; // per SMPTE ST 2067-5
 
       h__AS02WriterClip(const Dictionary&);