Add function to find the stream handler and fix problems with modules and stream info description

This commit is contained in:
jfmcarreira committed 2015-04-09 01:11:11 +01:00
1 parent 4c8b6376d7
commit e51a5c8288
5 files changed
+102 -102

No files matched your search

+19 -14
View File
@@ -111,6 +111,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget
VideoSubWindow::~VideoSubWindow()
{
m_pcCurrFrame = NULL;
disableModule();
delete m_cViewArea;
if( m_pCurrStream )
@@ -227,23 +228,23 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo )
Void VideoSubWindow::updateVideoWindowInfo()
{
if( m_pCurrStream )
m_cStreamInformation = "";
if( m_bIsModule )
{
m_cStreamInformation = "Module";
}
else if( m_pCurrStream )
{
QString m_cFormatName = QString::fromStdString( m_pCurrStream->getFormatName() );
QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() );
QString m_cPelFmtName = QString::fromStdString( m_pCurrStream->getPelFmtName() );
m_cStreamInformation = m_cFormatName + " | " + m_cCodedName + " | " + m_cPelFmtName;
m_cStreamInformation = m_cFormatName + " | " + m_cCodedName;
}
else if( m_pcCurrFrame )
if( m_pcCurrFrame )
{
if( m_bIsModule || m_pcCurrentDisplayModule )
{
m_cStreamInformation = "Module | ";
}
QString m_cPelFmtName = QString::fromStdString( PlaYUVerFrame::supportedPixelFormatListNames()[m_pcCurrFrame->getPelFormat()].c_str() );
m_cStreamInformation += m_cPelFmtName;
QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrame->getPelFmtName() );
m_cStreamInformation += " | " + m_cPelFmtName;
}
else
if( m_cStreamInformation.isEmpty() )
{
m_cStreamInformation = " ";
}
@@ -404,8 +405,8 @@ Void VideoSubWindow::disableModule( PlaYUVerAppModuleIf* pcModule )
}
if( bRefresh )
{
updateVideoWindowInfo();
refreshFrame();
updateVideoWindowInfo();
}
}
@@ -416,8 +417,12 @@ Void VideoSubWindow::associateModule( PlaYUVerAppModuleIf* pcModule )
Void VideoSubWindow::setCurrFrame( PlaYUVerFrame* pcCurrFrame )
{
m_pcCurrFrame = pcCurrFrame;
m_cViewArea->setImage( m_pcCurrFrame );
// if( m_pcCurrFrame )
{
m_pcCurrFrame = pcCurrFrame;
m_cViewArea->setImage( m_pcCurrFrame );
updateVideoWindowInfo();
}
}
Void VideoSubWindow::refreshFrameOperation()
+1 -1
View File
@@ -208,7 +208,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
getMem1D( &m_pcARGB32, m_uiHeight * m_uiWidth * 4 );
xSetupStatistics( this );
openPixfc();
m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str();
}
Int PlaYUVerFrame::getColorSpace() const
+5
View File
@@ -228,6 +228,10 @@ public:
PlaYUVerFrame::Pixel getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace = COLOR_INVALID );
std::string getPelFmtName()
{
return m_cPelFmtName;
}
UInt getWidth() const
{
return m_uiWidth;
@@ -333,6 +337,7 @@ private:
//! Strcut with the pixel format description.
PlaYUVerPixFmtDescriptor* m_pcPelFormat;
std::string m_cPelFmtName;
UInt m_uiWidth; //!< Width of the frame
UInt m_uiHeight; //!< Height of the frame
+74 -80
View File
@@ -135,7 +135,7 @@ PlaYUVerStream::PlaYUVerStream()
m_bIsInput = true;
m_bIsOpened = false;
m_bLoadAll = false;
m_uiStreamHandler = 0;
m_iStreamHandler = INVALID_HANDLER;
m_pFile = NULL;
m_pchFilename = NULL;
m_uiWidth = 0;
@@ -145,7 +145,6 @@ PlaYUVerStream::PlaYUVerStream()
m_iPixelFormat = -1;
m_uiBitsPerPixel = 8;
m_dFrameRate = 30;
m_iFileFormat = -1;
m_pStreamBuffer = NULL;
m_cFilename = "";
m_pcCurrFrame = NULL;
@@ -164,6 +163,53 @@ PlaYUVerStream::~PlaYUVerStream()
close();
}
Void PlaYUVerStream::findHandler()
{
m_iStreamHandler = INVALID_HANDLER;
if( m_uiBitsPerPixel != 8 )
{
m_iStreamHandler = YUV_IO;
return;
}
std::string currExt = m_cFilename.substr( m_cFilename.find_last_of( "." ) + 1 );
if( m_bIsInput )
{
#ifdef USE_FFMPEG
for( UInt i = 0; i < LibAvContextHandle::supportedReadFormatsExt().size(); i++ )
{
if( LibAvContextHandle::supportedReadFormatsExt()[i] == currExt )
{
m_cFormatName = LibAvContextHandle::supportedReadFormatsExt()[i];
m_iStreamHandler = FFMPEG;
return;
}
}
#endif
if( m_iStreamHandler == INVALID_HANDLER )
m_iStreamHandler = YUV_IO;
}
else
{
#ifdef USE_FFMPEG
for( UInt i = 0; i < LibAvContextHandle::supportedWriteFormatsExt().size(); i++ )
{
if( LibAvContextHandle::supportedWriteFormatsExt()[i] == currExt )
{
m_cFormatName = LibAvContextHandle::supportedWriteFormatsExt()[i];
m_iStreamHandler = FFMPEG;
return;
}
}
#endif
if( currExt == "yuv" )
{
m_iStreamHandler = YUV_IO;
}
}
}
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt frame_rate, Bool bInput )
{
UInt width;
@@ -208,69 +254,18 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
std::copy( m_cFilename.begin(), m_cFilename.end(), m_pchFilename );
m_pchFilename[m_cFilename.size()] = '\0'; // don't forget the terminating 0
if( m_bIsInput )
findHandler();
if( m_iStreamHandler == INVALID_HANDLER )
{
m_iFileFormat = INVALID_HANDLER;
std::string currExt = filename.substr( filename.find_last_of( "." ) + 1 );
for( UInt i = 0; i < PlaYUVerStream::supportedReadFormatsExt().size(); i++ )
{
if( PlaYUVerStream::supportedReadFormatsExt()[i] == currExt )
{
m_iFileFormat = i;
m_cFormatName = PlaYUVerStream::supportedReadFormatsExt()[i];
break;
}
}
if( m_iFileFormat == INVALID_HANDLER )
{
close();
throw "Invalid file format";
return m_bInit;
}
if( m_cFormatName == "yuv" )
{
m_uiStreamHandler = YUV_IO;
}
//#ifdef USE_OPENCV
// else if( m_cFormatName == "png" || m_cFormatName == "jpg" )
// {
// m_uiStreamHandler = OPENCV_HANDLER;
// }
//#endif
#ifdef USE_FFMPEG
else
{
m_uiStreamHandler = FFMPEG;
}
#endif
#if 0
if( !avStatus )
{
switch( m_iFileFormat )
{
case PGMINPUT:
break;
}
}
#endif
if( m_uiBitsPerPixel != 8 )
{
m_uiStreamHandler = YUV_IO;
}
m_uiFrameBufferSize = 2;
}
else
{
m_iFileFormat = 0;
m_uiStreamHandler = YUV_IO;
m_uiFrameBufferSize = 1;
close();
throw "Invalid file format";
return m_bInit;
}
m_uiFrameBufferSize = m_bIsInput ? 2 : 1;
#ifdef USE_FFMPEG
if( m_uiStreamHandler == FFMPEG )
if( m_iStreamHandler == FFMPEG )
{
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_dFrameRate, m_uiTotalFrameNum ) )
{
@@ -281,7 +276,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
#endif
#ifdef USE_OPENCV
if( m_uiStreamHandler == OPENCV_HANDLER )
if( m_iStreamHandler == OPENCV_HANDLER )
{
m_pcCurrFrame = LibOpenCVHandler::loadFrame( m_cFilename );
if( m_pcCurrFrame )
@@ -300,9 +295,9 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
return m_bInit;
}
if( m_uiStreamHandler != OPENCV_HANDLER )
if( m_iStreamHandler != OPENCV_HANDLER )
{
if( m_uiStreamHandler == YUV_IO )
if( m_iStreamHandler == YUV_IO )
{
if( !openFile() )
{
@@ -333,7 +328,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
if( m_uiStreamHandler == YUV_IO && m_bIsInput )
if( m_iStreamHandler == YUV_IO && m_bIsInput )
{
fseek( m_pFile, 0, SEEK_END );
UInt64 fileSize = ftell( m_pFile );
@@ -380,10 +375,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
m_uiBitsPerPixel = m_pcCurrFrame->getBitsPel();
}
m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str();
m_iCurrFrameNum = -1;
m_bInit = true;
seekInput( 0 );
@@ -394,7 +386,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
Bool PlaYUVerStream::openFile()
{
//m_fsIOStream.open( m_cFilename, std::ios::in | std::ios::binary )
//m_fsIOStream.open( m_cFilename, std::ios::in | std::ios::binary )
m_pFile = NULL;
m_pFile = fopen( m_pchFilename, m_bIsInput ? "rb" : "wb" );
if( m_pFile == NULL )
@@ -419,11 +411,11 @@ Void PlaYUVerStream::close()
if( !m_bInit )
return;
if( m_uiStreamHandler == YUV_IO )
if( m_iStreamHandler == YUV_IO )
closeFile();
#ifdef USE_FFMPEG
if( m_uiStreamHandler == FFMPEG )
if( m_iStreamHandler == FFMPEG )
m_cLibAvContext->closeAvFormat();
delete m_cLibAvContext;
#endif
@@ -516,12 +508,14 @@ Void PlaYUVerStream::getDuration( Int* duration_array )
{
Int hours, mins, secs;
#ifdef USE_FFMPEG
if( m_cLibAvContext->getStatus() )
if( m_iStreamHandler == FFMPEG )
{
secs = m_cLibAvContext->getStreamDuration();
}
else
#endif
if( m_iStreamHandler == YUV_IO )
{
secs = m_uiTotalFrameNum / m_dFrameRate;
}
@@ -553,13 +547,13 @@ Void PlaYUVerStream::readFrame()
return;
}
if( m_uiStreamHandler == OPENCV_HANDLER )
if( m_iStreamHandler == OPENCV_HANDLER )
{
return;
}
#ifdef USE_FFMPEG
if( m_uiStreamHandler == FFMPEG )
if( m_iStreamHandler == FFMPEG )
{
if( !m_cLibAvContext->decodeAvFormat() )
{
@@ -569,7 +563,7 @@ Void PlaYUVerStream::readFrame()
m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize );
}
#endif
if( m_uiStreamHandler == YUV_IO )
if( m_iStreamHandler == YUV_IO )
{
UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame();
UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Byte), frame_bytes_input, m_pFile );
@@ -591,7 +585,7 @@ Void PlaYUVerStream::writeFrame()
Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
{
if( m_uiStreamHandler == YUV_IO )
if( m_iStreamHandler == YUV_IO )
{
UInt64 frame_bytes_input = pcFrame->getBytesPerFrame();
pcFrame->frameToBuffer( m_pStreamBuffer );
@@ -614,7 +608,7 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *save
Int iFileFormat = INVALID_HANDLER;
std::string fmtExt;
//std::string currExt = QFileInfo( qtString ).suffix().toStdString();
//std::string currExt = QFileInfo( qtString ).suffix().toStdString();
std::string currExt = filename.substr( filename.find_last_of( "." ) + 1 );
for( UInt i = 0; i < PlaYUVerStream::supportedSaveFormatsExt().size(); i++ )
@@ -738,17 +732,17 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num )
setNextFrame();
return true;
}
if( m_uiStreamHandler == OPENCV_HANDLER )
if( m_iStreamHandler == OPENCV_HANDLER )
{
return true;
}
#ifdef USE_FFMPEG
if( m_uiStreamHandler == FFMPEG )
if( m_iStreamHandler == FFMPEG )
{
m_cLibAvContext->seekAvFormat( new_frame_num );
}
#endif
if( m_uiStreamHandler == YUV_IO )
if( m_iStreamHandler == YUV_IO )
{
UInt64 frame_bytes_input = m_ppcFrameBuffer[0]->getBytesPerFrame();
UInt64 nbytes_seek = frame_bytes_input * new_frame_num;
+3 -7
View File
@@ -67,7 +67,7 @@ private:
FFMPEG,
TOTAL_HANDLERR
};
UInt m_uiStreamHandler;
Int m_iStreamHandler;
LibAvContextHandle* m_cLibAvContext;
std::string m_cFilename;
@@ -75,9 +75,7 @@ private:
std::string m_cFormatName;
std::string m_cCodedName;
std::string m_cPelFmtName;
Int m_iFileFormat;
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPixelFormat;
@@ -97,6 +95,8 @@ private:
UInt m_uiFrameBufferIndex;
UInt64 m_uiCurrFrameFileIdx;
Void findHandler();
public:
static std::vector<std::string> supportedReadFormatsExt();
@@ -164,10 +164,6 @@ public:
{
return m_cCodedName;
}
std::string getPelFmtName()
{
return m_cPelFmtName;
}
UInt getFrameNum()
{