X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FPCMParserList.cpp;h=c073e3f54955a9e366b41053247ce8f4251cae22;hb=7f8e4c2f945e5c33ea707b232cc4eb5859b1d8f9;hp=26791624ea91dda5351d8448c4a04c5ccc4f5870;hpb=8095eaa320551b6795d0368c0ad0c227a3167caa;p=asdcplib.git diff --git a/src/PCMParserList.cpp b/src/PCMParserList.cpp index 2679162..c073e3f 100755 --- a/src/PCMParserList.cpp +++ b/src/PCMParserList.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004, John Hurst +Copyright (c) 2004-2016, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -30,9 +30,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include +#include #include using namespace ASDCP; +using namespace Kumu; ASDCP::ParserInstance::ParserInstance() : m_p(0), m_SampleSize(0) @@ -45,10 +48,8 @@ ASDCP::ParserInstance::~ParserInstance() // PCM::CalcSampleSize(ADesc); Result_t -ASDCP::ParserInstance::OpenRead(const char* filename, Rational& PictureRate) +ASDCP::ParserInstance::OpenRead(const std::string& filename, const Rational& PictureRate) { - ASDCP_TEST_NULL_STR(filename); - Result_t result = Parser.OpenRead(filename, PictureRate); if ( ASDCP_SUCCESS(result) ) @@ -56,7 +57,7 @@ ASDCP::ParserInstance::OpenRead(const char* filename, Rational& PictureRate) if ( ASDCP_SUCCESS(result) ) { - ADesc.SampleRate = PictureRate; + ADesc.EditRate = PictureRate; m_SampleSize = PCM::CalcSampleSize(ADesc); result = FB.Capacity(PCM::CalcFrameBufferSize(ADesc)); } @@ -71,11 +72,18 @@ ASDCP::ParserInstance::PutSample(byte_t* p) { ASDCP_TEST_NULL(p); - memcpy(p, m_p, m_SampleSize); - m_p += m_SampleSize; - return RESULT_OK; -} + if ( m_p != 0 ) + { + if ( m_p < ( FB.RoData() + FB.Size() ) ) + { + memcpy(p, m_p, m_SampleSize); + m_p += m_SampleSize; + return RESULT_OK; + } + } + return RESULT_ENDOFFILE; +} // Result_t @@ -105,27 +113,91 @@ ASDCP::PCMParserList::~PCMParserList() } } +// +Result_t +ASDCP::PCMParserList::OpenRead(ui32_t argc, const char** argv, const Rational& PictureRate) +{ + ASDCP_TEST_NULL(argv); + PathList_t TmpFileList; + + for ( ui32_t i = 0; i < argc; ++i ) + { + ASDCP_TEST_NULL(argv[i]); + TmpFileList.push_back(argv[i]); + } + + return OpenRead(TmpFileList, PictureRate); +} // Result_t -ASDCP::PCMParserList::OpenRead(ui32_t argc, const char** argv, Rational& PictureRate) +ASDCP::PCMParserList::OpenRead(const Kumu::PathList_t& argv, const Rational& PictureRate) { - ASDCP_TEST_NULL_STR(argv); Result_t result = RESULT_OK; + PathList_t::iterator fi; + Kumu::PathList_t file_list; - for ( ui32_t i = 0; i < argc && ASDCP_SUCCESS(result); i++ ) + if ( argv.size() == 1 && PathIsDirectory(argv.front()) ) { - ParserInstance* I = new ParserInstance; - result = I->OpenRead(argv[i], PictureRate); + DirScanner Dir; + char name_buf[MaxFilePath]; + result = Dir.Open(argv.front().c_str()); - if ( ASDCP_SUCCESS(result) ) + if ( KM_SUCCESS(result) ) + result = Dir.GetNext(name_buf); + + while ( KM_SUCCESS(result) ) + { + if ( name_buf[0] != '.' ) // no hidden files + { + std::string tmp_path = argv.front() + "/" + name_buf; + file_list.push_back(tmp_path); + } + + result = Dir.GetNext(name_buf); + } + + if ( result == RESULT_ENDOFFILE ) { - if ( i == 0 ) - m_ADesc = I->ADesc; + result = RESULT_OK; + file_list.sort(); + } + } + else + { + file_list = argv; + } + + for ( fi = file_list.begin(); KM_SUCCESS(result) && fi != file_list.end(); ++fi ) + { + mem_ptr I = new ParserInstance; + result = I->OpenRead(fi->c_str(), PictureRate); + if ( ASDCP_SUCCESS(result) ) + { + if ( fi == file_list.begin() ) + { + m_ADesc = I->ADesc; + } else - m_ADesc.BlockAlign += I->ADesc.BlockAlign; - // result = I->CmpADesc(m_ADesc); + { + if ( I->ADesc.AudioSamplingRate != m_ADesc.AudioSamplingRate ) + { + DefaultLogSink().Error("AudioSamplingRate mismatch in PCM parser list."); + return RESULT_FORMAT; + } + + if ( I->ADesc.QuantizationBits != m_ADesc.QuantizationBits ) + { + DefaultLogSink().Error("QuantizationBits mismatch in PCM parser list."); + return RESULT_FORMAT; + } + + if ( I->ADesc.ContainerDuration < m_ADesc.ContainerDuration ) + m_ADesc.ContainerDuration = I->ADesc.ContainerDuration; + + m_ADesc.BlockAlign += I->ADesc.BlockAlign; + } m_ChannelCount += I->ADesc.ChannelCount; } @@ -134,14 +206,22 @@ ASDCP::PCMParserList::OpenRead(ui32_t argc, const char** argv, Rational& Picture result = I->FB.Capacity(PCM::CalcFrameBufferSize(m_ADesc)); if ( ASDCP_SUCCESS(result) ) - push_back(I); + { + push_back(I); + I.release(); + } + } + + if ( ASDCP_SUCCESS(result) ) + { + m_ADesc.ChannelCount = m_ChannelCount; + m_ADesc.AvgBps = (ui32_t)(ceil(m_ADesc.AudioSamplingRate.Quotient()) * m_ADesc.BlockAlign); + } + else + { + clear(); } - m_ADesc.ChannelCount = m_ChannelCount; - - if ( ASDCP_FAILURE(result) ) - clear(); - return result; } @@ -174,21 +254,23 @@ ASDCP::PCMParserList::ReadFrame(PCM::FrameBuffer& OutFB) Result_t result = RESULT_OK; if ( size() == 1 ) - return front()->Parser.ReadFrame(OutFB); + { + return front()->Parser.ReadFrame(OutFB); + } PCMParserList::iterator self_i; assert(PCM::CalcFrameBufferSize(m_ADesc) <= OutFB.Capacity()); for ( self_i = begin(); self_i != end() && ASDCP_SUCCESS(result) ; self_i++ ) - result = (*self_i)->ReadFrame(); + { + result = (*self_i)->ReadFrame(); + } if ( ASDCP_SUCCESS(result) ) { - OutFB.Size(PCM::CalcFrameBufferSize(m_ADesc)); - - // ui32_t sample_size = (PCM::CalcSampleSize(m_ADesc)); byte_t* Out_p = OutFB.Data(); - byte_t* End_p = Out_p + OutFB.Size(); + byte_t* End_p = Out_p + OutFB.Capacity(); + ui64_t total_sample_bytes = 0; while ( Out_p < End_p && ASDCP_SUCCESS(result) ) { @@ -197,17 +279,41 @@ ASDCP::PCMParserList::ReadFrame(PCM::FrameBuffer& OutFB) while ( self_i != end() && ASDCP_SUCCESS(result) ) { result = (*self_i)->PutSample(Out_p); - Out_p += (*self_i)->SampleSize(); - self_i++; + + if ( ASDCP_SUCCESS(result) ) + { + Out_p += (*self_i)->SampleSize(); + total_sample_bytes += (*self_i)->SampleSize(); + self_i++; + } } } - assert(Out_p == End_p); + OutFB.Size(total_sample_bytes); + + if ( result == RESULT_ENDOFFILE ) + { + result = RESULT_OK; + } } return result; } +// +ASDCP::Result_t ASDCP::PCMParserList::Seek(ui32_t frame_number) +{ + Result_t result = RESULT_OK; + PCMParserList::iterator self_i; + + for( self_i = begin(); self_i != end() && ASDCP_SUCCESS(result); self_i++ ) + { + result = (*self_i)->Parser.Seek(frame_number); + } + + return result; +} + // // end PCMParserList.cpp //