build JP2K parsers with file lists
authorjhurst <jhurst@cinecert.com>
Tue, 4 Aug 2009 18:43:10 +0000 (18:43 +0000)
committerjhurst <>
Tue, 4 Aug 2009 18:43:10 +0000 (18:43 +0000)
src/AS_DCP.h
src/AS_DCP_MXF.cpp
src/JP2K_Sequence_Parser.cpp
src/KM_fileio.cpp
src/KM_util.h

index da18976ffe6e37da2b1bbcbd39b6c35db1cfafed..3cbc4810368daa56fb8a8d961936a5b6f6a73f22 100755 (executable)
@@ -1070,6 +1070,15 @@ namespace ASDCP {
          // mismatch is detected.
          Result_t OpenRead(const char* filename, bool pedantic = false) const;
 
+         // Opens a file sequence for reading.  The sequence is expected to contain one or
+         // more filenames, each naming a file containing the codestream for exactly one
+         // picture. The parser will automatically parse enough data
+         // from the first file to provide a complete set of stream metadata for the
+         // MXFWriter below.  If the "pedantic" parameter is given and is true, the
+         // parser will check the metadata for each codestream and fail if a 
+         // mismatch is detected.
+         Result_t OpenRead(const std::list<std::string>& file_list, bool pedantic = false) const;
+
          // Fill a PictureDescriptor struct with the values from the first file's codestream.
          // Returns RESULT_INIT if the directory is not open.
          Result_t FillPictureDescriptor(PictureDescriptor&) const;
index 7251b7dab47f500ff4e2c4c7f4776d5d52b5e7e1..95e219e1df331de0f392e3cd600f6ab8013ff45b 100755 (executable)
@@ -234,7 +234,11 @@ ASDCP::RawEssenceType(const char* filename, EssenceType_t& type)
            {
              type = ESS_MPEG2_VES;
            }
-         else if ( ASDCP_SUCCESS(WavHeader.ReadFromBuffer(p, read_count, &data_offset)) )
+         else if ( memcmp(FB.RoData(), ASDCP::JP2K::Magic, sizeof(ASDCP::JP2K::Magic)) == 0 )
+           {
+             type = ESS_JPEG_2000;
+           }
+         else if ( ASDCP_SUCCESS(WavHeader.ReadFromBuffer(FB.RoData(), read_count, &data_offset)) )
            {
              switch ( WavHeader.samplespersec )
                {
@@ -244,11 +248,11 @@ ASDCP::RawEssenceType(const char* filename, EssenceType_t& type)
                  return RESULT_FORMAT;
                }
            }
-         else if ( ASDCP_SUCCESS(AIFFHeader.ReadFromBuffer(p, read_count, &data_offset)) )
+         else if ( ASDCP_SUCCESS(AIFFHeader.ReadFromBuffer(FB.RoData(), read_count, &data_offset)) )
            {
              type = ESS_PCM_24b_48k;
            }
-         else if ( Kumu::StringIsXML((const char*)p, FB.Size()) )
+         else if ( Kumu::StringIsXML((const char*)FB.RoData(), FB.Size()) )
            {
              type = ESS_TIMED_TEXT;
            }
@@ -281,10 +285,19 @@ ASDCP::RawEssenceType(const char* filename, EssenceType_t& type)
              if ( ASDCP_SUCCESS(result) )
                {
                  if ( memcmp(FB.RoData(), ASDCP::JP2K::Magic, sizeof(ASDCP::JP2K::Magic)) == 0 )
-                   type = ESS_JPEG_2000;
-
+                   {
+                     type = ESS_JPEG_2000;
+                   }
                  else if ( ASDCP_SUCCESS(WavHeader.ReadFromBuffer(FB.RoData(), read_count, &data_offset)) )
-                   type = ESS_PCM_24b_48k;
+                   {
+                     switch ( WavHeader.samplespersec )
+                       {
+                       case 48000: type = ESS_PCM_24b_48k; break;
+                       case 96000: type = ESS_PCM_24b_96k; break;
+                       default:
+                         return RESULT_FORMAT;
+                       }
+                   }
                }
 
              break;
index 5cb4e91adbfbbc20262f523c4b687788ff4f6e56..77de5bed8ba2cc5f40def184ce92556b3f6d02fb 100755 (executable)
@@ -50,6 +50,12 @@ public:
   FileList() {}
   ~FileList() {}
 
+  const FileList& operator=(const std::list<std::string>& pathlist) {
+    std::list<std::string>::const_iterator i;
+    for ( i = pathlist.begin(); i != pathlist.end(); i++ )
+      push_back(*i);
+  }
+
   //
   Result_t InitFromDirectory(const char* path)
   {
@@ -89,13 +95,16 @@ class ASDCP::JP2K::SequenceParser::h__SequenceParser
   FileList           m_FileList;
   FileList::iterator m_CurrentFile;
   CodestreamParser   m_Parser;
+  bool               m_Pedantic;
+
+  Result_t OpenRead();
 
   ASDCP_NO_COPY_CONSTRUCT(h__SequenceParser);
 
 public:
   PictureDescriptor  m_PDesc;
 
-  h__SequenceParser() : m_FramesRead(0)
+  h__SequenceParser() : m_FramesRead(0), m_Pedantic(false)
   {
     memset(&m_PDesc, 0, sizeof(m_PDesc));
     m_PDesc.EditRate = Rational(24,1); 
@@ -106,7 +115,8 @@ public:
     Close();
   }
 
-  Result_t OpenRead(const char* filename);
+  Result_t OpenRead(const char* filename, bool pedantic);
+  Result_t OpenRead(const std::list<std::string>& file_list, bool pedantic);
   void     Close() {}
 
   Result_t Reset()
@@ -122,48 +132,61 @@ public:
 
 //
 ASDCP::Result_t
-ASDCP::JP2K::SequenceParser::h__SequenceParser::OpenRead(const char* filename)
+ASDCP::JP2K::SequenceParser::h__SequenceParser::OpenRead()
 {
-  ASDCP_TEST_NULL_STR(filename);
-
-  Result_t result = m_FileList.InitFromDirectory(filename);
-
   if ( m_FileList.empty() )
     return RESULT_ENDOFFILE;
 
-  if ( ASDCP_SUCCESS(result) )
-    {
-      m_CurrentFile = m_FileList.begin();
+  m_CurrentFile = m_FileList.begin();
+  CodestreamParser Parser;
+  FrameBuffer TmpBuffer;
 
-      CodestreamParser Parser;
-      FrameBuffer TmpBuffer;
+  Kumu::fsize_t file_size = Kumu::FileSize((*m_CurrentFile).c_str());
 
-      Kumu::fsize_t file_size = Kumu::FileSize((*m_CurrentFile).c_str());
+  if ( file_size == 0 )
+    return RESULT_NOT_FOUND;
 
-      if ( file_size == 0 )
-       result = RESULT_NOT_FOUND;
+  assert(file_size <= 0xFFFFFFFFL);
+  Result_t result = TmpBuffer.Capacity((ui32_t) file_size);
 
-      if ( ASDCP_SUCCESS(result) )
-       {
-         assert(file_size <= 0xFFFFFFFFL);
-         result = TmpBuffer.Capacity((ui32_t) file_size);
-       }
-
-      if ( ASDCP_SUCCESS(result) )
-       result = Parser.OpenReadFrame((*m_CurrentFile).c_str(), TmpBuffer);
+  if ( ASDCP_SUCCESS(result) )
+    result = Parser.OpenReadFrame((*m_CurrentFile).c_str(), TmpBuffer);
       
-      if ( ASDCP_SUCCESS(result) )
-       result = Parser.FillPictureDescriptor(m_PDesc);
+  if ( ASDCP_SUCCESS(result) )
+    result = Parser.FillPictureDescriptor(m_PDesc);
 
-      // how big is it?
-      if ( ASDCP_SUCCESS(result) )
-       m_PDesc.ContainerDuration = m_FileList.size();
-    }
+  // how big is it?
+  if ( ASDCP_SUCCESS(result) )
+    m_PDesc.ContainerDuration = m_FileList.size();
+
+  return result;
+}
+
+//
+ASDCP::Result_t
+ASDCP::JP2K::SequenceParser::h__SequenceParser::OpenRead(const char* filename, bool pedantic)
+{
+  ASDCP_TEST_NULL_STR(filename);
+  m_Pedantic = pedantic;
+
+  Result_t result = m_FileList.InitFromDirectory(filename);
+
+  if ( ASDCP_SUCCESS(result) )
+    result = OpenRead();
 
   return result;
 }
 
+
 //
+ASDCP::Result_t
+ASDCP::JP2K::SequenceParser::h__SequenceParser::OpenRead(const std::list<std::string>& file_list, bool pedantic)
+{
+  m_Pedantic = pedantic;
+  m_FileList = file_list;
+  return OpenRead();
+}
+
 //
 ASDCP::Result_t
 ASDCP::JP2K::SequenceParser::h__SequenceParser::ReadFrame(FrameBuffer& FB)
@@ -201,7 +224,21 @@ ASDCP::JP2K::SequenceParser::OpenRead(const char* filename, bool pedantic) const
 {
   const_cast<ASDCP::JP2K::SequenceParser*>(this)->m_Parser = new h__SequenceParser;
 
-  Result_t result = m_Parser->OpenRead(filename);
+  Result_t result = m_Parser->OpenRead(filename, pedantic);
+
+  if ( ASDCP_FAILURE(result) )
+    const_cast<ASDCP::JP2K::SequenceParser*>(this)->m_Parser.release();
+
+  return result;
+}
+
+//
+Result_t
+ASDCP::JP2K::SequenceParser::OpenRead(const std::list<std::string>& file_list, bool pedantic) const
+{
+  const_cast<ASDCP::JP2K::SequenceParser*>(this)->m_Parser = new h__SequenceParser;
+
+  Result_t result = m_Parser->OpenRead(file_list, pedantic);
 
   if ( ASDCP_FAILURE(result) )
     const_cast<ASDCP::JP2K::SequenceParser*>(this)->m_Parser.release();
@@ -209,6 +246,7 @@ ASDCP::JP2K::SequenceParser::OpenRead(const char* filename, bool pedantic) const
   return result;
 }
 
+
 // Rewinds the stream to the beginning.
 ASDCP::Result_t
 ASDCP::JP2K::SequenceParser::Reset() const
@@ -230,6 +268,7 @@ ASDCP::JP2K::SequenceParser::ReadFrame(FrameBuffer& FB) const
   return m_Parser->ReadFrame(FB);
 }
 
+//
 ASDCP::Result_t
 ASDCP::JP2K::SequenceParser::FillPictureDescriptor(PictureDescriptor& PDesc) const
 {
index fba85789f78b4a3c5d16e709067d79c6b3101294..b9257abda88d7d9c87bd929cbce7a9bd806c47c7 100644 (file)
@@ -1455,7 +1455,9 @@ Kumu::DeleteFile(const std::string& filename)
 Result_t
 h__DeletePath(const std::string& pathname)
 {
-  fprintf(stderr, "h__DeletePath %s\n", pathname.c_str());
+  if ( pathname.empty() )
+    return RESULT_NULL_STR;
+
   Result_t result = RESULT_OK;
 
   if ( ! PathIsDirectory(pathname) )
index 6bf2366cf991b3540a07b22493e51cfdb184e280..a9c96c66311434e3684e92e1db357d9f115ab80d 100755 (executable)
@@ -342,6 +342,8 @@ namespace Kumu
   void GenRandomUUID(byte_t* buf); // buf must be UUID_Length or longer
   void GenRandomValue(UUID&);
   
+  typedef ArchivableList<UUID> UUIDList;
+
   // a self-wiping key container
   //
   const ui32_t SymmetricKey_Length = 16;