const, baby
[asdcplib.git] / src / AS_DCP_JP2K.cpp
index ed8a9238b34fa51fce48f9904082fbba21d912f3..86327c283fc52cae465c84c7c4fba06fb5532662 100755 (executable)
@@ -312,8 +312,8 @@ lh__Reader::OpenRead(const char* filename, EssenceType_t type)
        {
          if ( m_EditRate != m_SampleRate )
            {
-             DefaultLogSink().Error("EditRate and SampleRate do not match (%.03f, %.03f).\n",
-                                    m_EditRate.Quotient(), m_SampleRate.Quotient());
+             DefaultLogSink().Warn("EditRate and SampleRate do not match (%.03f, %.03f).\n",
+                                   m_EditRate.Quotient(), m_SampleRate.Quotient());
              
              if ( m_EditRate == EditRate_24 && m_SampleRate == EditRate_48 )
                {
@@ -326,9 +326,34 @@ lh__Reader::OpenRead(const char* filename, EssenceType_t type)
        }
       else if ( type == ASDCP::ESS_JPEG_2000_S )
        {
-         if ( ! ( m_EditRate == EditRate_24 && m_SampleRate == EditRate_48 ) )
+         if ( m_EditRate == EditRate_24 )
            {
-             DefaultLogSink().Error("EditRate and SampleRate not correct for 24/48 stereoscopic essence.\n");
+             if ( m_SampleRate != EditRate_48 )
+               {
+                 DefaultLogSink().Error("EditRate and SampleRate not correct for 24/48 stereoscopic essence.\n");
+                 return RESULT_FORMAT;
+               }
+           }
+         else if ( m_EditRate == EditRate_25 )
+           {
+             if ( m_SampleRate != EditRate_50 )
+               {
+                 DefaultLogSink().Error("EditRate and SampleRate not correct for 25/50 stereoscopic essence.\n");
+                 return RESULT_FORMAT;
+               }
+           }
+         else if ( m_EditRate == EditRate_30 )
+           {
+             if ( m_SampleRate != EditRate_60 )
+               {
+                 DefaultLogSink().Error("EditRate and SampleRate not correct for 30/60 stereoscopic essence.\n");
+                 return RESULT_FORMAT;
+               }
+           }
+         else
+           {
+             DefaultLogSink().Error("EditRate not correct for stereoscopic essence: %d/%d.\n",
+                                    m_EditRate.Numerator, m_EditRate.Denominator);
              return RESULT_FORMAT;
            }
        }
@@ -359,6 +384,7 @@ lh__Reader::ReadFrame(ui32_t FrameNum, JP2K::FrameBuffer& FrameBuf,
   if ( ! m_File.IsOpen() )
     return RESULT_INIT;
 
+  assert(m_Dict);
   return ReadEKLVFrame(FrameNum, FrameBuf, m_Dict->ul(MDD_JPEG2000Essence), Ctx, HMAC);
 }
 
@@ -547,6 +573,7 @@ public:
       {
        ui32_t SequenceNum = FrameNum * 2;
        SequenceNum += ( phase == SP_RIGHT ) ? 2 : 1;
+       assert(m_Dict);
        result = ReadEKLVPacket(FrameNum, SequenceNum, FrameBuf, m_Dict->ul(MDD_JPEG2000Essence), Ctx, HMAC);
       }
 
@@ -706,6 +733,7 @@ lh__Writer::JP2K_PDesc_to_MD(JP2K::PictureDescriptor& PDesc)
   // PixelLayout          byte_t[PixelLayoutSize] = s_PixelLayoutXYZ
   //    }
 
+  assert(m_Dict);
   if ( PDesc.StoredWidth < 2049 )
     {
       PDescObj->PictureEssenceCoding.Set(m_Dict->ul(MDD_JP2KEssenceCompression_2K));
@@ -796,6 +824,7 @@ lh__Writer::OpenWrite(const char* filename, EssenceType_t type, ui32_t HeaderSiz
 ASDCP::Result_t
 lh__Writer::SetSourceStream(const PictureDescriptor& PDesc, const std::string& label, ASDCP::Rational LocalEditRate)
 {
+  assert(m_Dict);
   if ( ! m_State.Test_INIT() )
     return RESULT_STATE;
 
@@ -1002,9 +1031,11 @@ ASDCP::JP2K::MXFSWriter::OpenWrite(const char* filename, const WriterInfo& Info,
   else
     m_Writer = new h__SWriter(DefaultInteropDict());
 
-  if ( PDesc.EditRate != ASDCP::EditRate_24 )
+  if ( PDesc.EditRate != ASDCP::EditRate_24
+       && PDesc.EditRate != ASDCP::EditRate_25
+       && PDesc.EditRate != ASDCP::EditRate_30 )
     {
-      DefaultLogSink().Error("Stereoscopic wrapping requires 24 fps input streams.\n");
+      DefaultLogSink().Error("Stereoscopic wrapping requires 24, 25 or 30 fps input streams.\n");
       return RESULT_FORMAT;
     }
 
@@ -1018,9 +1049,17 @@ ASDCP::JP2K::MXFSWriter::OpenWrite(const char* filename, const WriterInfo& Info,
   if ( ASDCP_SUCCESS(result) )
     {
       PictureDescriptor TmpPDesc = PDesc;
-      TmpPDesc.EditRate = ASDCP::EditRate_48;
 
-      result = m_Writer->SetSourceStream(TmpPDesc, JP2K_S_PACKAGE_LABEL, ASDCP::EditRate_24);
+      if ( PDesc.EditRate == ASDCP::EditRate_24 )
+       TmpPDesc.EditRate = ASDCP::EditRate_48;
+
+      else if ( PDesc.EditRate == ASDCP::EditRate_25 )
+       TmpPDesc.EditRate = ASDCP::EditRate_50;
+
+      else if ( PDesc.EditRate == ASDCP::EditRate_30 )
+       TmpPDesc.EditRate = ASDCP::EditRate_60;
+
+      result = m_Writer->SetSourceStream(TmpPDesc, JP2K_S_PACKAGE_LABEL, PDesc.EditRate);
     }
 
   if ( ASDCP_FAILURE(result) )