Denis' bug fixes
[asdcplib.git] / src / h__Writer.cpp
index 7d874c029d9d13ab24d578d3846ab9834ace3505..1105e039de873964c7c937bb25b5efe035829f4d 100755 (executable)
@@ -55,7 +55,6 @@ ASDCP::h__Writer::~h__Writer()
 {
 }
 
-
 //
 // add DMS CryptographicFramework entry to source package
 void
@@ -110,7 +109,12 @@ ASDCP::h__Writer::WriteMXFHeader(const std::string& PackageLabel, const UL& Wrap
   // so we tell the world by using OP1a
   m_HeaderPart.m_Preface->OperationalPattern = UL(Dict::ul(MDD_OP1a));
   m_HeaderPart.OperationalPattern = m_HeaderPart.m_Preface->OperationalPattern;
-  m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(0, 0)); // First RIP Entry
+
+  // First RIP Entry
+  if ( m_Info.LabelSetType == LS_MXF_SMPTE )
+    m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(0, 0)); // 3-part, no essence in header
+  else
+    m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(1, 0)); // 2-part, essence in header
 
   //
   // Identification
@@ -129,7 +133,7 @@ ASDCP::h__Writer::WriteMXFHeader(const std::string& PackageLabel, const UL& Wrap
   Ident->ToolkitVersion.Minor = VERSION_APIMINOR;
   Ident->ToolkitVersion.Patch = VERSION_IMPMINOR;
   Ident->ToolkitVersion.Build = ASDCP_BUILD_NUMBER;
-  Ident->ToolkitVersion.Release = VersionType::RL_DEVELOPMENT;
+  Ident->ToolkitVersion.Release = VersionType::RL_RELEASE;
 
   //
   ContentStorage* Storage = new ContentStorage;
@@ -201,8 +205,9 @@ ASDCP::h__Writer::WriteMXFHeader(const std::string& PackageLabel, const UL& Wrap
   m_FilePackage->Name = PackageLabel.c_str();
   m_FilePackage->PackageUID = PackageUMID;
   ECD->LinkedPackageUID = PackageUMID;
+
   m_MPClip->SourcePackageID = PackageUMID;
-  m_MPClip->SourceTrackID = 1;
+  m_MPClip->SourceTrackID = 2;
 
   m_HeaderPart.AddChildObject(m_FilePackage);
   Storage->Packages.push_back(m_FilePackage->InstanceUID);
@@ -245,6 +250,10 @@ ASDCP::h__Writer::WriteMXFHeader(const std::string& PackageLabel, const UL& Wrap
   m_FPClSequence->StructuralComponents.push_back(m_FPClip->InstanceUID);
   m_FPClip->DataDefinition = DataDefinition;
 
+  // for now we do not allow setting this value, so all files will be 'original'
+  m_FPClip->SourceTrackID = 0;
+  m_FPClip->SourcePackageID = NilUMID;
+
   //
   // Essence Descriptor
   //
@@ -270,33 +279,40 @@ ASDCP::h__Writer::WriteMXFHeader(const std::string& PackageLabel, const UL& Wrap
 
   m_HeaderPart.m_Preface->EssenceContainers = m_HeaderPart.EssenceContainers;
   m_HeaderPart.AddChildObject(m_EssenceDescriptor);
+
+  std::list<FileDescriptor*>::iterator sdli = m_EssenceSubDescriptorList.begin();
+  for ( ; sdli != m_EssenceSubDescriptorList.end(); sdli++ )
+    m_HeaderPart.AddChildObject(*sdli);
+
   m_FilePackage->Descriptor = m_EssenceDescriptor->InstanceUID;
 
   // Write the header partition
   Result_t result = m_HeaderPart.WriteToFile(m_File, m_HeaderSize);
 
-  if ( ASDCP_SUCCESS(result) )
+  // create a body partition of we're writing proper 429-3/OP-Atom
+  if ( ASDCP_SUCCESS(result) && m_Info.LabelSetType == LS_MXF_SMPTE )
     {
       // Body Partition
       m_BodyPart.EssenceContainers = m_HeaderPart.EssenceContainers;
       m_BodyPart.ThisPartition = m_File.Tell();
       m_BodyPart.BodySID = 1;
       UL OPAtomUL(Dict::ul(MDD_OPAtom));
-
-      if ( m_Info.LabelSetType == LS_MXF_INTEROP )
-       OPAtomUL.Set(Dict::ul(MDD_MXFInterop_OPAtom));
-
       m_BodyPart.OperationalPattern = OPAtomUL;
       m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(1, m_BodyPart.ThisPartition)); // Second RIP Entry
       
       UL BodyUL(Dict::ul(MDD_ClosedCompleteBodyPartition));
       result = m_BodyPart.WriteToFile(m_File, BodyUL);
     }
+  else
+    {
+      m_HeaderPart.BodySID = 1;
+    }
 
   if ( ASDCP_SUCCESS(result) )
     {
       // Index setup
-      fpos_t ECoffset = m_File.Tell();
+      Kumu::fpos_t ECoffset = m_File.Tell();
+      m_FooterPart.IndexSID = 129;
 
       if ( BytesPerEditUnit == 0 )
        m_FooterPart.SetIndexParamsVBR(&m_HeaderPart.m_Primer, EditRate, ECoffset);
@@ -434,8 +450,8 @@ ASDCP::h__Writer::WriteMXFFooter()
     m_FPTCSequence->Duration = m_FPTimecode->Duration = m_FPClSequence->Duration = m_FPClip->Duration = 
     m_EssenceDescriptor->ContainerDuration = m_FramesWritten;
 
-  fpos_t here = m_File.Tell();
-  m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(0, here)); // Third RIP Entry
+  Kumu::fpos_t here = m_File.Tell();
+  m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(0, here)); // Last RIP Entry
   m_HeaderPart.FooterPartition = here;
 
   // re-label the partition
@@ -447,7 +463,11 @@ ASDCP::h__Writer::WriteMXFFooter()
   m_HeaderPart.OperationalPattern = OPAtomUL;
   m_HeaderPart.m_Preface->OperationalPattern = m_HeaderPart.OperationalPattern;
 
-  m_FooterPart.PreviousPartition = m_BodyPart.ThisPartition;
+  if ( m_Info.LabelSetType == LS_MXF_SMPTE )
+    m_FooterPart.PreviousPartition = m_BodyPart.ThisPartition;
+  else
+    m_FooterPart.PreviousPartition = m_HeaderPart.ThisPartition;
+
   m_FooterPart.OperationalPattern = m_HeaderPart.OperationalPattern;
   m_FooterPart.EssenceContainers = m_HeaderPart.EssenceContainers;
   m_FooterPart.FooterPartition = here;