Add another OpenReadFrame method for JP2K::CodestreamParser.
authorCarl Hetherington <cth@carlh.net>
Mon, 23 Nov 2020 22:25:18 +0000 (23:25 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 23 Nov 2020 22:25:18 +0000 (23:25 +0100)
src/AS_DCP.h
src/JP2K_Codestream_Parser.cpp

index cb78dbc44cdf8d0ddf0529252bfe78a62cb7df19..d27766c44dcbe1b7706027ad6c8fee4fd850bd95 100755 (executable)
@@ -1142,6 +1142,8 @@ namespace ASDCP {
          // encrypted headers.
          Result_t OpenReadFrame(const std::string& filename, FrameBuffer&) const;
 
+         Result_t OpenReadFrame(const unsigned char * data, unsigned int size, FrameBuffer&) const;
+
          // Fill a PictureDescriptor struct with the values from the file's codestream.
          // Returns RESULT_INIT if the file is not open.
          Result_t FillPictureDescriptor(PictureDescriptor&) const;
index 5401db2e2d5f807f1a1f8cf9ecd2ec044fa47429..602cf75f2aa1cc7f1ca1706e20242b0b84372611 100755 (executable)
@@ -90,6 +90,26 @@ public:
 
     return result;
   }
+
+  Result_t OpenReadFrame(const unsigned char * data, unsigned int size, FrameBuffer& FB)
+  {
+    if ( FB.Capacity() < size )
+      {
+        DefaultLogSink().Error("FrameBuf.Capacity: %u frame length: %u\n", FB.Capacity(), (ui32_t) size);
+        return RESULT_SMALLBUF;
+      }
+
+    memcpy (FB.Data(), data, size);
+    FB.Size(size);
+
+    byte_t start_of_data = 0; // out param
+    const Result_t result = ParseMetadataIntoDesc(FB, m_PDesc, &start_of_data);
+
+    if ( ASDCP_SUCCESS(result) )
+      FB.PlaintextOffset(start_of_data);
+
+    return result;
+  }
 };
 
 ASDCP::Result_t
@@ -206,6 +226,15 @@ ASDCP::JP2K::CodestreamParser::OpenReadFrame(const std::string& filename, FrameB
   return m_Parser->OpenReadFrame(filename, FB);
 }
 
+// Opens the stream for reading, parses enough data to provide a complete
+// set of stream metadata for the MXFWriter below.
+ASDCP::Result_t
+ASDCP::JP2K::CodestreamParser::OpenReadFrame(const unsigned char* data, unsigned int size, FrameBuffer& FB) const
+{
+  const_cast<ASDCP::JP2K::CodestreamParser*>(this)->m_Parser = new h__CodestreamParser;
+  return m_Parser->OpenReadFrame(data, size, FB);
+}
+
 //
 ASDCP::Result_t
 ASDCP::JP2K::CodestreamParser::FillPictureDescriptor(PictureDescriptor& PDesc) const