// 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;
{
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 )
{
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;
}
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;
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)
{
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);
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()
//
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)
{
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();
return result;
}
+
// Rewinds the stream to the beginning.
ASDCP::Result_t
ASDCP::JP2K::SequenceParser::Reset() const
return m_Parser->ReadFrame(FB);
}
+//
ASDCP::Result_t
ASDCP::JP2K::SequenceParser::FillPictureDescriptor(PictureDescriptor& PDesc) const
{