change the behaviour of read and display new frames: now the frame is
show and the new frame is saved in a buffer
This commit is contained in:
1 parent
c538f35046
commit
495f0728c3
4 files changed
+66
-48
No files matched your search
+48
-20
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "InputStream.h"
|
||||
#include "LibMemAlloc.h"
|
||||
#include "LibMemory.h"
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
@@ -47,11 +48,14 @@ InputStream::InputStream()
|
||||
|
||||
m_iFileFormat = INVALID;
|
||||
|
||||
m_cCurrFrame = NULL;
|
||||
m_pInputBuffer = NULL;
|
||||
|
||||
m_cFilename = QString( "" );
|
||||
m_cStreamInformationString = QString( "" );
|
||||
|
||||
m_pcCurrFrame = NULL;
|
||||
m_ppcFrameBuffer = NULL;
|
||||
m_uiFrameBufferSize = 2;
|
||||
}
|
||||
|
||||
InputStream::~InputStream()
|
||||
@@ -154,9 +158,15 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for
|
||||
return;
|
||||
}
|
||||
|
||||
m_cCurrFrame = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
|
||||
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
|
||||
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
|
||||
{
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
|
||||
}
|
||||
m_pcCurrFrame = m_ppcFrameBuffer[0];
|
||||
m_uiFrameBufferIndex = 1;
|
||||
|
||||
UInt64 frame_bytes_input = m_cCurrFrame->getBytesPerFrame();
|
||||
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
|
||||
|
||||
if( !avStatus )
|
||||
{
|
||||
@@ -173,7 +183,7 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for
|
||||
m_cStreamInformationString.append( QString::fromUtf8("rawvideo ") );
|
||||
}
|
||||
|
||||
if( !get_mem1Dpel( &m_pInputBuffer, m_cCurrFrame->getBytesPerFrame() ) )
|
||||
if( !getMem1D<Pel>( &m_pInputBuffer, m_pcCurrFrame->getBytesPerFrame() ) )
|
||||
{
|
||||
//Error
|
||||
return;
|
||||
@@ -190,6 +200,9 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for
|
||||
m_iCurrFrameNum = -1;
|
||||
m_iStatus = 1;
|
||||
|
||||
readNextFrame();
|
||||
setNextFrame();
|
||||
readNextFrame();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,16 +215,22 @@ Void InputStream::close()
|
||||
m_cLibAvContext.closeAvFormat();
|
||||
#endif
|
||||
|
||||
if( m_cCurrFrame )
|
||||
delete m_cCurrFrame;
|
||||
if( m_ppcFrameBuffer )
|
||||
{
|
||||
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
|
||||
{
|
||||
delete m_ppcFrameBuffer[i];
|
||||
}
|
||||
freeMem1D<PlaYUVerFrame*>( m_ppcFrameBuffer );
|
||||
}
|
||||
|
||||
if( m_pInputBuffer )
|
||||
free_mem1Dpel( m_pInputBuffer );
|
||||
freeMem1D<Pel>( m_pInputBuffer );
|
||||
|
||||
m_iStatus = 0;
|
||||
}
|
||||
|
||||
Void InputStream::readFrame()
|
||||
Void InputStream::readNextFrame()
|
||||
{
|
||||
UInt64 bytes_read = 0;
|
||||
|
||||
@@ -220,8 +239,7 @@ Void InputStream::readFrame()
|
||||
return;
|
||||
}
|
||||
|
||||
m_iCurrFrameNum++;
|
||||
if( m_iCurrFrameNum >= (Int)m_uiTotalFrameNum )
|
||||
if( m_iCurrFrameNum + 1 >= (Int)m_uiTotalFrameNum )
|
||||
{
|
||||
m_iErrorStatus = END_OF_SEQ;
|
||||
m_iCurrFrameNum = 0;
|
||||
@@ -232,12 +250,12 @@ Void InputStream::readFrame()
|
||||
if( m_cLibAvContext.getStatus() )
|
||||
{
|
||||
m_cLibAvContext.decodeAvFormat();
|
||||
m_cCurrFrame->FrameFromBuffer( m_cLibAvContext.video_dst_data[0], m_iPixelFormat );
|
||||
m_ppcFrameBuffer[!m_uiFrameBufferIndex]->FrameFromBuffer( m_cLibAvContext.video_dst_data[0], m_iPixelFormat );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
UInt64 frame_bytes_input = m_cCurrFrame->getBytesPerFrame();
|
||||
UInt64 frame_bytes_input = m_ppcFrameBuffer[0]->getBytesPerFrame();
|
||||
bytes_read = fread( m_pInputBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
|
||||
if( bytes_read != frame_bytes_input )
|
||||
{
|
||||
@@ -245,28 +263,35 @@ Void InputStream::readFrame()
|
||||
qDebug( ) << " Reading error !!!" << endl;
|
||||
return;
|
||||
}
|
||||
m_cCurrFrame->FrameFromBuffer( m_pInputBuffer, m_iPixelFormat );
|
||||
m_ppcFrameBuffer[!m_uiFrameBufferIndex]->FrameFromBuffer( m_pInputBuffer, m_iPixelFormat );
|
||||
m_uiFrameBufferIndex = !m_uiFrameBufferIndex;
|
||||
return;
|
||||
}
|
||||
|
||||
Bool InputStream::writeFrame( const QString& filename )
|
||||
{
|
||||
m_cCurrFrame->getQimage().save( filename );
|
||||
m_pcCurrFrame->getQimage().save( filename );
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaYUVerFrame* InputStream::getFrame( PlaYUVerFrame *pyuv_image )
|
||||
Void InputStream::setNextFrame()
|
||||
{
|
||||
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
|
||||
m_iCurrFrameNum++;
|
||||
}
|
||||
|
||||
PlaYUVerFrame* InputStream::getCurrFrame( PlaYUVerFrame *pyuv_image )
|
||||
{
|
||||
if( pyuv_image == NULL )
|
||||
pyuv_image = new PlaYUVerFrame( m_cCurrFrame->getWidth(), m_cCurrFrame->getHeight(), m_cCurrFrame->getPelFormat() );
|
||||
pyuv_image = new PlaYUVerFrame( m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), m_pcCurrFrame->getPelFormat() );
|
||||
|
||||
pyuv_image->CopyFrom(m_cCurrFrame);
|
||||
pyuv_image->CopyFrom(m_pcCurrFrame);
|
||||
return pyuv_image;
|
||||
}
|
||||
|
||||
PlaYUVerFrame* InputStream::getFrame()
|
||||
PlaYUVerFrame* InputStream::getCurrFrame()
|
||||
{
|
||||
return m_cCurrFrame;
|
||||
return m_pcCurrFrame;
|
||||
}
|
||||
|
||||
#ifdef USE_OPENCV
|
||||
@@ -288,11 +313,14 @@ Void InputStream::seekInput( Int new_frame_num )
|
||||
else
|
||||
#endif
|
||||
{
|
||||
UInt64 frame_bytes_input = m_cCurrFrame->getBytesPerFrame();
|
||||
UInt64 frame_bytes_input = m_ppcFrameBuffer[0]->getBytesPerFrame();
|
||||
UInt64 nbytes_seek = frame_bytes_input * new_frame_num;
|
||||
fseek( m_pFile, nbytes_seek, SEEK_SET );
|
||||
m_iCurrFrameNum = new_frame_num - 1;
|
||||
}
|
||||
readNextFrame();
|
||||
setNextFrame();
|
||||
readNextFrame();
|
||||
}
|
||||
|
||||
Bool InputStream::checkErrors( Int error_type )
|
||||
|
||||
+8
-10
@@ -72,7 +72,10 @@ private:
|
||||
|
||||
Pel* m_pInputBuffer;
|
||||
|
||||
PlaYUVerFrame *m_cCurrFrame;
|
||||
UInt m_uiFrameBufferSize;
|
||||
PlaYUVerFrame **m_ppcFrameBuffer;
|
||||
PlaYUVerFrame *m_pcCurrFrame;
|
||||
UInt m_uiFrameBufferIndex;
|
||||
|
||||
UInt m_uiWidth;
|
||||
UInt m_uiHeight;
|
||||
@@ -99,12 +102,13 @@ public:
|
||||
Void init( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate );
|
||||
Void close();
|
||||
|
||||
Void readFrame();
|
||||
Void readNextFrame();
|
||||
|
||||
Bool writeFrame( const QString& filename );
|
||||
|
||||
PlaYUVerFrame* getFrame();
|
||||
PlaYUVerFrame* getFrame( PlaYUVerFrame * );
|
||||
Void setNextFrame();
|
||||
PlaYUVerFrame* getCurrFrame();
|
||||
PlaYUVerFrame* getCurrFrame( PlaYUVerFrame * );
|
||||
#ifdef USE_OPENCV
|
||||
cv::Mat getFrameCvMat();
|
||||
#endif
|
||||
@@ -160,12 +164,6 @@ public:
|
||||
m_uiHeight = new_height;
|
||||
}
|
||||
}
|
||||
|
||||
PlaYUVerFrame *getCurrentFrame()
|
||||
{
|
||||
return m_cCurrFrame;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
@@ -96,14 +96,8 @@ bool SubWindowHandle::loadFile( const QString &fileName )
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pCurrFrameQImage = new QImage( m_pCurrStream->getFrame()->getQImageBuffer(), m_pCurrStream->getWidth(), m_pCurrStream->getHeight(), QImage::Format_RGB888 );
|
||||
m_pCurrFrameQImage = new QImage( m_pCurrStream->getCurrFrame()->getQImageBuffer(), m_pCurrStream->getWidth(), m_pCurrStream->getHeight(), QImage::Format_RGB888 );
|
||||
|
||||
m_pCurrStream->readFrame();
|
||||
if( m_pCurrStream->checkErrors( READING ) )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( fileName ) );
|
||||
return false;
|
||||
}
|
||||
m_cViewArea->setInputStream(m_pCurrStream);
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
@@ -133,7 +127,7 @@ Void SubWindowHandle::enableModule( PlaYUVerModuleIf* select_module )
|
||||
return;
|
||||
}
|
||||
m_pcCurrentModule = select_module;
|
||||
m_pcCurrentModule->create( m_pCurrStream->getFrame() );
|
||||
m_pcCurrentModule->create( m_pCurrStream->getCurrFrame() );
|
||||
refreshFrame();
|
||||
}
|
||||
|
||||
@@ -165,11 +159,11 @@ Void SubWindowHandle::refreshFrame()
|
||||
{
|
||||
if( m_pcCurrentModule )
|
||||
{
|
||||
FrameToQImage( m_pcCurrentModule->process( m_pCurrStream->getFrame() ) );
|
||||
FrameToQImage( m_pcCurrentModule->process( m_pCurrStream->getCurrFrame() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
FrameToQImage( m_pCurrStream->getFrame() );
|
||||
FrameToQImage( m_pCurrStream->getCurrFrame() );
|
||||
}
|
||||
m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) );
|
||||
}
|
||||
@@ -209,7 +203,9 @@ bool SubWindowHandle::playEvent()
|
||||
bool iRet = true;
|
||||
if( m_bIsPlaying )
|
||||
{
|
||||
m_pCurrStream->readFrame();
|
||||
m_pCurrStream->setNextFrame();
|
||||
refreshFrame();
|
||||
m_pCurrStream->readNextFrame();
|
||||
if( m_pCurrStream->checkErrors( READING ) )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) );
|
||||
@@ -219,7 +215,6 @@ bool SubWindowHandle::playEvent()
|
||||
{
|
||||
iRet = false;
|
||||
}
|
||||
refreshFrame();
|
||||
return iRet;
|
||||
}
|
||||
return false;
|
||||
@@ -228,15 +223,12 @@ bool SubWindowHandle::playEvent()
|
||||
Void SubWindowHandle::seekEvent( UInt new_frame_num )
|
||||
{
|
||||
m_pCurrStream->seekInput( new_frame_num );
|
||||
m_pCurrStream->readFrame();
|
||||
refreshFrame();
|
||||
}
|
||||
|
||||
Void SubWindowHandle::stopEvent()
|
||||
{
|
||||
m_pCurrStream->seekInput( 0 );
|
||||
m_pCurrStream->readFrame();
|
||||
refreshFrame();
|
||||
seekEvent( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ void plaYUVerApp::playEvent()
|
||||
{
|
||||
if( !activeSubWindow()->playEvent() )
|
||||
{
|
||||
stop();
|
||||
//stop();
|
||||
}
|
||||
m_pcFrameSlider->setValue( activeSubWindow()->getInputStream()->getCurrFrameNum() );
|
||||
}
|
||||
@@ -637,7 +637,7 @@ void plaYUVerApp::updatePixelValueStatusBar(const QPoint & pos, InputStream* str
|
||||
Int posX = pos.x(), posY = pos.y();
|
||||
QString strPixel;
|
||||
QString strStatus = QString("(%1,%2) ").arg(posX).arg(posY);
|
||||
PlaYUVerFrame *curFrame = stream->getFrame();
|
||||
PlaYUVerFrame *curFrame = stream->getCurrFrame();
|
||||
|
||||
iWidth = stream->getWidth();
|
||||
iHeight = stream->getHeight();
|
||||
|
||||
Reference in new issue
Block a user