changes to make Wailua integration easier
authorjhurst <jhurst@cinecert.com>
Mon, 21 Jan 2008 03:57:52 +0000 (03:57 +0000)
committerjhurst <>
Mon, 21 Jan 2008 03:57:52 +0000 (03:57 +0000)
src/AS_DCP.h
src/AS_DCP_JP2K.cpp
src/JP2K_Codestream_Parser.cpp

index 1cefa98de534e893579e85a7baddb5ac09d16a37..65442e146da701f5ec2fcb0fb131920ecb3c9c86 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2003-2007, John Hurst
+Copyright (c) 2003-2008, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -154,8 +154,8 @@ namespace ASDCP {
   // in file format, and if no changes were made to AS_DCP.h, the new version would be
   // 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1.
   const ui32_t VERSION_MAJOR = 1;
-  const ui32_t VERSION_APIMINOR = 2;
-  const ui32_t VERSION_IMPMINOR = 17;
+  const ui32_t VERSION_APIMINOR = 3;
+  const ui32_t VERSION_IMPMINOR = 18;
   const char* Version();
 
   // UUIDs are passed around as strings of UUIDlen bytes
@@ -1011,6 +1011,10 @@ namespace ASDCP {
          Result_t FillPictureDescriptor(PictureDescriptor&) const;
        };
 
+      // Parses the data in the frame buffer to fill in the picture descriptor. Copies
+      // the offset of the image data into start_of_data. Returns error if the parser fails.
+      Result_t ParseMetadataIntoDesc(const FrameBuffer&, PictureDescriptor&, byte_t* start_of_data = 0);
+
       // An object which reads a sequence of files containing JPEG 2000 pictures.
       class SequenceParser
        {
@@ -1125,10 +1129,20 @@ namespace ASDCP {
        SP_LEFT,
        SP_RIGHT
       };
+      
+      struct SFrameBuffer
+      {
+       JP2K::FrameBuffer Left;
+       JP2K::FrameBuffer Right;
 
+       SFrameBuffer(ui32_t size) {
+         Left.Capacity(size);
+         Right.Capacity(size);
+       }
+      };
 
       class MXFSWriter
-       {
+      {
          class h__SWriter;
          mem_ptr<h__SWriter> m_Writer;
          ASDCP_NO_COPY_CONSTRUCT(MXFSWriter);
@@ -1143,6 +1157,12 @@ namespace ASDCP {
          Result_t OpenWrite(const char* filename, const WriterInfo&,
                             const PictureDescriptor&, ui32_t HeaderSize = 16384);
 
+         // Writes a pair of frames of essence to the MXF file. If the optional AESEncContext
+         // argument is present, the essence is encrypted prior to writing.
+         // Fails if the file is not open, is finalized, or an operating system
+         // error occurs.
+         Result_t WriteFrame(const SFrameBuffer&, AESEncContext* = 0, HMACContext* = 0);
+
          // Writes a frame of essence to the MXF file. If the optional AESEncContext
          // argument is present, the essence is encrypted prior to writing.
          // Fails if the file is not open, is finalized, or an operating system
@@ -1183,6 +1203,15 @@ namespace ASDCP {
          // Returns RESULT_INIT if the file is not open.
          Result_t FillWriterInfo(WriterInfo&) const;
 
+         // Reads a pair of frames of essence from the MXF file. If the optional AESEncContext
+         // argument is present, the essence is decrypted after reading. If the MXF
+         // file is encrypted and the AESDecContext argument is NULL, the frame buffer
+         // will contain the ciphertext frame data. If the HMACContext argument is
+         // not NULL, the HMAC will be calculated (if the file supports it).
+         // Returns RESULT_INIT if the file is not open, failure if the frame number is
+         // out of range, or if optional decrypt or HAMC operations fail.
+         Result_t ReadFrame(ui32_t frame_number, SFrameBuffer&, AESDecContext* = 0, HMACContext* = 0) const;
+
          // Reads a frame of essence from the MXF file. If the optional AESEncContext
          // argument is present, the essence is decrypted after reading. If the MXF
          // file is encrypted and the AESDecContext argument is NULL, the frame buffer
index 8f771739ffb8b6865aca548c3a84871b49692ea8..e0852b1154b906357ec9812c59722f8f1572d714 100755 (executable)
@@ -484,6 +484,23 @@ ASDCP::JP2K::MXFSReader::OpenRead(const char* filename) const
   return m_Reader->OpenRead(filename, ASDCP::ESS_JPEG_2000_S);
 }
 
+//
+ASDCP::Result_t
+ASDCP::JP2K::MXFSReader::ReadFrame(ui32_t FrameNum, SFrameBuffer& FrameBuf, AESDecContext* Ctx, HMACContext* HMAC) const
+{
+  Result_t result = RESULT_INIT;
+
+  if ( m_Reader && m_Reader->m_File.IsOpen() )
+    {
+      result = m_Reader->ReadFrame(FrameNum, SP_LEFT, FrameBuf.Left, Ctx, HMAC);
+
+      if ( ASDCP_SUCCESS(result) )
+       result = m_Reader->ReadFrame(FrameNum, SP_RIGHT, FrameBuf.Right, Ctx, HMAC);
+    }
+
+  return result;
+}
+
 //
 ASDCP::Result_t
 ASDCP::JP2K::MXFSReader::ReadFrame(ui32_t FrameNum, StereoscopicPhase_t phase, FrameBuffer& FrameBuf,
@@ -495,7 +512,6 @@ ASDCP::JP2K::MXFSReader::ReadFrame(ui32_t FrameNum, StereoscopicPhase_t phase, F
   return RESULT_INIT;
 }
 
-
 // Fill the struct with the values from the file's header.
 // Returns RESULT_INIT if the file is not open.
 ASDCP::Result_t
@@ -906,6 +922,19 @@ ASDCP::JP2K::MXFSWriter::OpenWrite(const char* filename, const WriterInfo& Info,
   return result;
 }
 
+ASDCP::Result_t
+ASDCP::JP2K::MXFSWriter::WriteFrame(const SFrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC)
+{
+  if ( m_Writer.empty() )
+    return RESULT_INIT;
+
+  Result_t result = m_Writer->WriteFrame(FrameBuf.Left, SP_LEFT, Ctx, HMAC);
+
+  if ( ASDCP_SUCCESS(result) )
+    result = m_Writer->WriteFrame(FrameBuf.Right, SP_RIGHT, Ctx, HMAC);
+
+  return result;
+}
 
 // Writes a frame of essence to the MXF file. If the optional AESEncContext
 // argument is present, the essence is encrypted prior to writing.
index f4596a87e5ceb889faa2ebf6746aca5390ee448d..7230fecd37dfdfcf21ab573fc21e1bfd6d6e5bf8 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2006, John Hurst
+Copyright (c) 2004-2008, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -82,94 +82,109 @@ public:
 
     if ( ASDCP_SUCCESS(result) )
       {
-       Marker NextMarker;
-       ui32_t i;
-       const byte_t* p = FB.RoData();
-       const byte_t* end_p = p + FB.Size();
+       byte_t start_of_data = 0; // out param
+       result = ParseMetadataIntoDesc(FB, m_PDesc, &start_of_data);
 
-       while ( p < end_p && ASDCP_SUCCESS(result) )
-         {
-           result = GetNextMarker(&p, NextMarker);
-
-           if ( ASDCP_FAILURE(result) )
-             {
-               result = RESULT_RAW_ESS;
-               break;
-             }
-
-           switch ( NextMarker.m_Type )
-             {
-             case MRK_SOD:
-               FB.PlaintextOffset(p - FB.RoData());
-               p = end_p;
-               break;
-
-             case MRK_SIZ:
-               {
-                 Accessor::SIZ SIZ_(NextMarker);
-                 m_PDesc.StoredWidth = SIZ_.Xsize();
-                 m_PDesc.StoredHeight = SIZ_.Ysize();
-                 m_PDesc.AspectRatio = Rational(SIZ_.Xsize(), SIZ_.Ysize());
-                 m_PDesc.Rsize = SIZ_.Rsize();
-                 m_PDesc.Xsize = SIZ_.Xsize();
-                 m_PDesc.Ysize = SIZ_.Ysize();
-                 m_PDesc.XOsize = SIZ_.XOsize();
-                 m_PDesc.YOsize = SIZ_.YOsize();
-                 m_PDesc.XTsize = SIZ_.XTsize();
-                 m_PDesc.YTsize = SIZ_.YTsize();
-                 m_PDesc.XTOsize = SIZ_.XTOsize();
-                 m_PDesc.YTOsize = SIZ_.YTOsize();
-                 m_PDesc.Csize = SIZ_.Csize();
-
-                 if ( m_PDesc.Csize != 3 )
-                   {
-                     DefaultLogSink().Error("Unexpected number of components: %u\n", m_PDesc.Csize);
-                     return RESULT_RAW_FORMAT;
-                   }
-
-                 for ( i = 0; i < m_PDesc.Csize; i++ )
-                   SIZ_.ReadComponent(i, m_PDesc.ImageComponents[i]);
-               }
-               break;
-
-             case MRK_COD:
-               memset(&m_PDesc.CodingStyleDefault, 0, sizeof(CodingStyleDefault_t));
-
-               if ( NextMarker.m_DataSize > sizeof(CodingStyleDefault_t) )
-                 {
-                   DefaultLogSink().Error("Unexpectedly large CodingStyle data: %u\n", NextMarker.m_DataSize);
-                   return RESULT_RAW_FORMAT;
-                 }
-
-               memcpy(&m_PDesc.CodingStyleDefault, NextMarker.m_Data, NextMarker.m_DataSize);
-               break;
-
-             case MRK_QCD:
-               memset(&m_PDesc.QuantizationDefault, 0, sizeof(QuantizationDefault_t));
-
-               if ( NextMarker.m_DataSize < 16 )
-                 {
-                   DefaultLogSink().Error("No quantization signaled\n");
-                   return RESULT_RAW_FORMAT;
-                 }
-
-               if ( NextMarker.m_DataSize > MaxDefaults )
-                 {
-                   DefaultLogSink().Error("Quantization Default length exceeds maximum %d\n", NextMarker.m_DataSize);
-                   return RESULT_RAW_FORMAT;
-                 }
-
-               memcpy(&m_PDesc.QuantizationDefault, NextMarker.m_Data, NextMarker.m_DataSize);
-               m_PDesc.QuantizationDefault.SPqcdLength = NextMarker.m_DataSize - 1;
-               break;
-             }
-         }
+       if ( ASDCP_SUCCESS(result) )
+         FB.PlaintextOffset(start_of_data);
       }
 
     return result;
   }
 };
 
+ASDCP::Result_t
+ASDCP::JP2K::ParseMetadataIntoDesc(const FrameBuffer& FB, PictureDescriptor& PDesc, byte_t* start_of_data)
+{
+  Result_t result = RESULT_OK;
+  Marker NextMarker;
+  ui32_t i;
+  const byte_t* p = FB.RoData();
+  const byte_t* end_p = p + FB.Size();
+
+  while ( p < end_p && ASDCP_SUCCESS(result) )
+    {
+      result = GetNextMarker(&p, NextMarker);
+
+      if ( ASDCP_FAILURE(result) )
+       {
+         result = RESULT_RAW_ESS;
+         break;
+       }
+
+      switch ( NextMarker.m_Type )
+       {
+       case MRK_SOD:
+         if ( start_of_data != 0 )
+           *start_of_data = p - FB.RoData();
+
+         p = end_p;
+         break;
+
+       case MRK_SIZ:
+         {
+           Accessor::SIZ SIZ_(NextMarker);
+           PDesc.StoredWidth = SIZ_.Xsize();
+           PDesc.StoredHeight = SIZ_.Ysize();
+           PDesc.AspectRatio = Rational(SIZ_.Xsize(), SIZ_.Ysize());
+           PDesc.Rsize = SIZ_.Rsize();
+           PDesc.Xsize = SIZ_.Xsize();
+           PDesc.Ysize = SIZ_.Ysize();
+           PDesc.XOsize = SIZ_.XOsize();
+           PDesc.YOsize = SIZ_.YOsize();
+           PDesc.XTsize = SIZ_.XTsize();
+           PDesc.YTsize = SIZ_.YTsize();
+           PDesc.XTOsize = SIZ_.XTOsize();
+           PDesc.YTOsize = SIZ_.YTOsize();
+           PDesc.Csize = SIZ_.Csize();
+
+           if ( PDesc.Csize != 3 )
+             {
+               DefaultLogSink().Error("Unexpected number of components: %u\n", PDesc.Csize);
+               return RESULT_RAW_FORMAT;
+             }
+           
+           for ( i = 0; i < PDesc.Csize; i++ )
+             SIZ_.ReadComponent(i, PDesc.ImageComponents[i]);
+         }
+         break;
+
+       case MRK_COD:
+         memset(&PDesc.CodingStyleDefault, 0, sizeof(CodingStyleDefault_t));
+
+         if ( NextMarker.m_DataSize > sizeof(CodingStyleDefault_t) )
+           {
+             DefaultLogSink().Error("Unexpectedly large CodingStyle data: %u\n", NextMarker.m_DataSize);
+             return RESULT_RAW_FORMAT;
+           }
+         
+         memcpy(&PDesc.CodingStyleDefault, NextMarker.m_Data, NextMarker.m_DataSize);
+         break;
+
+       case MRK_QCD:
+         memset(&PDesc.QuantizationDefault, 0, sizeof(QuantizationDefault_t));
+
+         if ( NextMarker.m_DataSize < 16 )
+           {
+             DefaultLogSink().Error("No quantization signaled\n");
+             return RESULT_RAW_FORMAT;
+           }
+         
+         if ( NextMarker.m_DataSize > MaxDefaults )
+           {
+             DefaultLogSink().Error("Quantization Default length exceeds maximum %d\n", NextMarker.m_DataSize);
+             return RESULT_RAW_FORMAT;
+           }
+
+         memcpy(&PDesc.QuantizationDefault, NextMarker.m_Data, NextMarker.m_DataSize);
+         PDesc.QuantizationDefault.SPqcdLength = NextMarker.m_DataSize - 1;
+         break;
+       }
+    }
+
+  return result;
+}
+
 //------------------------------------------------------------------------------------------
 
 ASDCP::JP2K::CodestreamParser::CodestreamParser()