Add option to load the entire file into memory

This commit is contained in:
jfmcarreira committed 2014-06-12 13:18:44 +01:00
1 parent f37bee7162
commit e829fa03bf
4 files changed
+87 -6

No files matched your search

+62 -5
View File
@@ -41,6 +41,7 @@ namespace plaYUVer
InputStream::InputStream()
{
m_bInit = false;
m_bLoadAll = false;
m_iErrorStatus = 0;
m_pFile = NULL;
@@ -58,6 +59,7 @@ InputStream::InputStream()
m_pcNextFrame = NULL;
m_ppcFrameBuffer = NULL;
m_uiFrameBufferSize = 2;
m_uiFrameBufferIndex = 0;
m_uiAveragePlayInterval = 0;
}
@@ -145,6 +147,7 @@ Bool InputStream::open( QString filename, UInt width, UInt height, Int input_for
return m_bInit;
}
m_uiFrameBufferSize = 2;
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
@@ -192,6 +195,7 @@ Bool InputStream::open( QString filename, UInt width, UInt height, Int input_for
m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() );
seekInput( 0 );
//loadAll();
m_cTimer.start();
m_uiAveragePlayInterval = 0;
@@ -228,6 +232,7 @@ Void InputStream::close()
<< QString::number( 1000 / ( m_uiAveragePlayInterval + 1 ) )
<< " fps";
m_bLoadAll = false;
m_bInit = false;
}
@@ -292,6 +297,41 @@ Bool InputStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, In
return bRet;
}
Void InputStream::loadAll()
{
if( m_ppcFrameBuffer )
{
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
{
if( m_ppcFrameBuffer[i] )
delete m_ppcFrameBuffer[i];
m_ppcFrameBuffer[i] = NULL;
}
freeMem1D<PlaYUVerFrame*>( m_ppcFrameBuffer );
m_ppcFrameBuffer = NULL;
}
m_uiFrameBufferSize = m_uiTotalFrameNum;
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 );
if( !m_ppcFrameBuffer[i] )
{
close();
}
}
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
seekInput( 0 );
for( UInt i = m_uiFrameBufferIndex+1; i < m_uiFrameBufferSize; i++ )
{
readNextFrame();
setNextFrame();
}
m_bLoadAll = true;
seekInput( 0 );
}
Void InputStream::getDuration( Int* duration_array )
{
Int hours, mins, secs;
@@ -326,6 +366,11 @@ Void InputStream::readNextFrame()
return;
}
if( m_bLoadAll )
{
return;
}
#ifdef USE_FFMPEG
if( m_cLibAvContext.getStatus() )
{
@@ -364,8 +409,12 @@ Void InputStream::setNextFrame()
{
m_pcCurrFrame = m_pcNextFrame;
m_iCurrFrameNum++;
m_pcNextFrame = m_ppcFrameBuffer[!m_uiFrameBufferIndex];
m_uiFrameBufferIndex = !m_uiFrameBufferIndex;
m_uiFrameBufferIndex++;
if( m_uiFrameBufferIndex == m_uiFrameBufferSize )
{
m_uiFrameBufferIndex = 0;
}
m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
}
else
{
@@ -391,10 +440,18 @@ PlaYUVerFrame* InputStream::getCurrFrame()
Void InputStream::seekInput( UInt64 new_frame_num )
{
if( !m_pFile )
if( !m_pFile || new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum)
return;
if( new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum )
m_iCurrFrameNum = new_frame_num - 1;
if( m_bLoadAll )
{
m_uiFrameBufferIndex = new_frame_num;
m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
setNextFrame();
return;
}
#ifdef USE_FFMPEG
if( m_cLibAvContext.getStatus() )
{
@@ -409,7 +466,7 @@ Void InputStream::seekInput( UInt64 new_frame_num )
}
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
m_iCurrFrameNum = new_frame_num - 1;
readNextFrame();
setNextFrame();
if( m_uiTotalFrameNum > 1 )
+3
View File
@@ -48,6 +48,7 @@ class InputStream
private:
Bool m_bInit;
Bool m_bLoadAll;
Int m_iErrorStatus;
#ifdef USE_FFMPEG
@@ -109,6 +110,8 @@ public:
Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Void loadAll();
Void readNextFrame();
Bool writeFrame( const QString& filename );
+20 -1
View File
@@ -164,8 +164,8 @@ Void plaYUVerApp::loadFile( QString fileName )
SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow();
if( interfaceChild->loadFile( fileName ) )
{
statusBar()->showMessage( tr( "Loading file..." ) );
mdiArea->addSubWindow( interfaceChild );
statusBar()->showMessage( tr( "File loaded" ), 2000 );
interfaceChild->show();
connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, PlaYUVerFrame *) ), this,
SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) );
@@ -173,6 +173,7 @@ Void plaYUVerApp::loadFile( QString fileName )
interfaceChild->zoomToFit();
interfaceChild->getViewArea()->setTool( m_appTool );
statusBar()->showMessage( tr( "File loaded" ), 2000 );
}
else
{
@@ -216,6 +217,17 @@ Void plaYUVerApp::format()
m_pcCurrentSubWindow->loadFile( m_pcCurrentSubWindow->currentFile(), true );
}
Void plaYUVerApp::loadAll()
{
if( m_pcCurrentSubWindow )
{
statusBar()->showMessage( tr( "Loading file into memory ..." ) );
m_pcCurrentSubWindow->getInputStream()->loadAll();
statusBar()->showMessage( tr( "File loaded" ), 2000 );
}
}
Void plaYUVerApp::closeActiveWindow()
{
SubWindowHandle *currSubWindow = activeSubWindow();
@@ -840,6 +852,11 @@ Void plaYUVerApp::createActions()
m_arrayActions[SAVE_ACT]->setStatusTip( tr( "Save current frame" ) );
connect( m_arrayActions[SAVE_ACT], SIGNAL( triggered() ), this, SLOT( save() ) );
m_arrayActions[LOAD_ALL_ACT] = new QAction( tr( "&Load All" ), this );
//m_arrayActions[LOAD_ALL_ACT]->setIcon( QIcon( ":/images/configuredialog.png" ) );
m_arrayActions[LOAD_ALL_ACT]->setStatusTip( tr( "Load sequence into memory (caution)" ) );
connect( m_arrayActions[LOAD_ALL_ACT], SIGNAL( triggered() ), this, SLOT( loadAll() ) );
m_arrayActions[FORMAT_ACT] = new QAction( tr( "&Format" ), this );
m_arrayActions[FORMAT_ACT]->setIcon( QIcon( ":/images/configuredialog.png" ) );
m_arrayActions[FORMAT_ACT]->setStatusTip( tr( "Open format dialog" ) );
@@ -1003,7 +1020,9 @@ Void plaYUVerApp::createMenus()
m_arrayMenu[FILE_MENU] = menuBar()->addMenu( tr( "&File" ) );
m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[OPEN_ACT] );
m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[SAVE_ACT] );
m_arrayMenu[FILE_MENU]->addSeparator();
m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[FORMAT_ACT] );
m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[LOAD_ALL_ACT] );
m_arrayMenu[FILE_MENU]->addSeparator();
m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[CLOSE_ACT] );
m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[EXIT_ACT] );
+2
View File
@@ -59,6 +59,7 @@ private Q_SLOTS:
void open();
void save();
void format();
void loadAll();
void closeActiveWindow();
void closeAll();
@@ -192,6 +193,7 @@ private:
OPEN_ACT = 0,
SAVE_ACT,
FORMAT_ACT,
LOAD_ALL_ACT,
CLOSE_ACT,
CLOSEALL_ACT,
EXIT_ACT,