Fix input stream buffer behaviour in order to detect end of sequence and

add support to lock multiple sequence display
This commit is contained in:
jfmcarreira committed 2014-04-02 03:28:07 +01:00
1 parent ac6a3aaab9
commit 9c327eb0a3
5 files changed
+123 -101

No files matched your search

+22 -14
View File
@@ -157,7 +157,7 @@ Bool InputStream::open( QString filename, UInt width, UInt height, Int input_for
} }
} }
m_uiFrameBufferIndex = 0; m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex]; m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
@@ -188,11 +188,7 @@ Bool InputStream::open( QString filename, UInt width, UInt height, Int input_for
m_cStreamInformationString.append( "] " ); m_cStreamInformationString.append( "] " );
m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() ); m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() );
m_iCurrFrameNum = -1; seekInput( 0 );
readNextFrame();
setNextFrame();
if( m_uiTotalFrameNum > 1 )
readNextFrame();
m_cTimer.start(); m_cTimer.start();
m_uiAveragePlayInterval = 0; m_uiAveragePlayInterval = 0;
@@ -298,9 +294,9 @@ Void InputStream::readNextFrame()
if( m_iCurrFrameNum + 1 >= ( Int )m_uiTotalFrameNum ) if( m_iCurrFrameNum + 1 >= ( Int )m_uiTotalFrameNum )
{ {
m_iErrorStatus = END_OF_SEQ; m_iErrorStatus = LAST_FRAME;
m_iCurrFrameNum = 0; m_pcNextFrame = NULL;
seekInput( m_iCurrFrameNum ); return;
} }
#ifdef USE_FFMPEG #ifdef USE_FFMPEG
@@ -337,10 +333,19 @@ Bool InputStream::writeFrame( const QString& filename )
Void InputStream::setNextFrame() Void InputStream::setNextFrame()
{ {
m_pcCurrFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex]; if( m_pcNextFrame )
m_pcNextFrame = m_ppcFrameBuffer[!m_uiFrameBufferIndex]; {
m_uiFrameBufferIndex = !m_uiFrameBufferIndex; m_pcCurrFrame = m_pcNextFrame;
m_iCurrFrameNum++; m_iCurrFrameNum++;
m_pcNextFrame = m_ppcFrameBuffer[!m_uiFrameBufferIndex];
m_uiFrameBufferIndex = !m_uiFrameBufferIndex;
}
else
{
m_iErrorStatus = END_OF_SEQ;
m_iCurrFrameNum = 0;
seekInput( m_iCurrFrameNum );
}
} }
PlaYUVerFrame* InputStream::getCurrFrame( PlaYUVerFrame *pyuv_image ) PlaYUVerFrame* InputStream::getCurrFrame( PlaYUVerFrame *pyuv_image )
@@ -382,10 +387,13 @@ Void InputStream::seekInput( UInt64 new_frame_num )
UInt64 nbytes_seek = frame_bytes_input * new_frame_num; UInt64 nbytes_seek = frame_bytes_input * new_frame_num;
fseek( m_pFile, nbytes_seek, SEEK_SET ); fseek( m_pFile, nbytes_seek, SEEK_SET );
} }
m_uiFrameBufferIndex = 0;
m_pcCurrFrame = m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex];
m_iCurrFrameNum = new_frame_num - 1; m_iCurrFrameNum = new_frame_num - 1;
readNextFrame(); readNextFrame();
setNextFrame(); setNextFrame();
readNextFrame(); if( m_uiTotalFrameNum > 1 )
readNextFrame();
} }
Bool InputStream::checkErrors( Int error_type ) Bool InputStream::checkErrors( Int error_type )
+8 -7
View File
@@ -48,13 +48,6 @@
namespace plaYUVer namespace plaYUVer
{ {
enum InputStream_Errors
{
NO_STREAM_ERROR = 0,
READING = 1,
END_OF_SEQ = 2,
};
class InputStream class InputStream
{ {
private: private:
@@ -107,6 +100,14 @@ public:
YUVFormat = 0, // Use color space. YUVFormat = 0, // Use color space.
}; };
enum InputStreamErrors
{
NO_STREAM_ERROR = 0,
READING,
LAST_FRAME,
END_OF_SEQ,
};
Bool open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate ); Bool open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate );
Void close(); Void close();
+9 -10
View File
@@ -175,26 +175,25 @@ Bool SubWindowHandle::save()
return true; return true;
} }
bool SubWindowHandle::playEvent() Int SubWindowHandle::playEvent()
{ {
bool iRet = true;
if( m_bIsPlaying ) if( m_bIsPlaying )
{ {
m_pCurrStream->setNextFrame(); m_pCurrStream->setNextFrame();
refreshFrame(); refreshFrame();
if( m_pCurrStream->checkErrors( InputStream::END_OF_SEQ ) )
{
return -2;
}
m_pCurrStream->readNextFrame(); m_pCurrStream->readNextFrame();
if( m_pCurrStream->checkErrors( READING ) ) if( m_pCurrStream->checkErrors( InputStream::READING ) )
{ {
QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) ); QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) );
return false; return -3;
} }
else if( m_pCurrStream->checkErrors( END_OF_SEQ ) ) return 0;
{
iRet = false;
}
return iRet;
} }
return false; return -1;
} }
Void SubWindowHandle::seekAbsoluteEvent( UInt new_frame_num ) Void SubWindowHandle::seekAbsoluteEvent( UInt new_frame_num )
+2 -1
View File
@@ -67,7 +67,9 @@ public:
Bool loadFile( const QString &fileName ); Bool loadFile( const QString &fileName );
Bool save(); Bool save();
Int playEvent();
Void stopEvent(); Void stopEvent();
Void seekAbsoluteEvent( UInt new_frame_num ); Void seekAbsoluteEvent( UInt new_frame_num );
Void seekRelativeEvent( Bool bIsFoward ); Void seekRelativeEvent( Bool bIsFoward );
@@ -143,7 +145,6 @@ protected:
void closeEvent( QCloseEvent *event ); void closeEvent( QCloseEvent *event );
public Q_SLOTS: public Q_SLOTS:
bool playEvent();
void adjustScrollBar( double factor ); void adjustScrollBar( double factor );
}; };
+82 -69
View File
@@ -218,12 +218,11 @@ void plaYUVerApp::updateProperties()
void plaYUVerApp::play() void plaYUVerApp::play()
{ {
Bool bFind = false; if( m_pcCurrentSubWindow )
if( actionVideoLock->isChecked() )
{ {
if( m_pcCurrentSubWindow ) if( actionVideoLock->isChecked() && m_acPlayingSubWindows.size() )
{ {
Bool bFind = false;
for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{ {
if( m_acPlayingSubWindows.at( i ) == m_pcCurrentSubWindow ) if( m_acPlayingSubWindows.at( i ) == m_pcCurrentSubWindow )
@@ -235,26 +234,28 @@ void plaYUVerApp::play()
if( !bFind ) if( !bFind )
{ {
m_acPlayingSubWindows.append( m_pcCurrentSubWindow ); m_acPlayingSubWindows.append( m_pcCurrentSubWindow );
m_pcCurrentSubWindow->seekAbsoluteEvent( m_pcFrameSlider->value() ); m_pcCurrentSubWindow->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() );
m_pcFrameSlider->setMaximum( qMin( m_pcFrameSlider->value(), ( Int )m_pcCurrentSubWindow->getInputStream()->getFrameNum() - 1 ) ); m_pcFrameSlider->setMaximum( qMin( m_pcFrameSlider->maximum(), ( Int )m_pcCurrentSubWindow->getInputStream()->getFrameNum() - 1 ) );
} }
} }
} else
else {
{ playingTimer->stop();
playingTimer->stop(); m_acPlayingSubWindows.clear();
m_uiAveragePlayInterval = 0; m_acPlayingSubWindows.append( m_pcCurrentSubWindow );
m_bIsPlaying = false; m_uiAveragePlayInterval = 0;
} m_bIsPlaying = false;
if( !m_bIsPlaying ) }
{ if( !m_bIsPlaying )
UInt frameRate = m_pcCurrentSubWindow->getInputStream()->getFrameRate(); {
UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); UInt frameRate = m_acPlayingSubWindows.at( 0 )->getInputStream()->getFrameRate();
qDebug( ) << "Desired frame rate: " UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 );
<< QString::number( 1000 / timeInterval ) qDebug( ) << "Desired frame rate: "
<< " fps"; << QString::number( 1000 / timeInterval )
playingTimer->start( timeInterval ); << " fps";
m_cTimer.start(); playingTimer->start( timeInterval );
m_cTimer.start();
}
} }
} }
@@ -265,77 +266,90 @@ void plaYUVerApp::pause()
void plaYUVerApp::stop() void plaYUVerApp::stop()
{ {
if( actionVideoLock->isChecked() ) if( m_acPlayingSubWindows.size() )
{ {
for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->stopEvent();
}
m_acPlayingSubWindows.clear(); m_acPlayingSubWindows.clear();
playingTimer->stop();
m_pcFrameSlider->setValue( m_pcCurrentSubWindow->getInputStream()->getCurrFrameNum() );
if( m_uiAveragePlayInterval )
qDebug( ) << "Real display time: "
<< QString::number( 1000 / m_uiAveragePlayInterval )
<< " fps";
m_uiAveragePlayInterval = 0;
} }
else else
{ {
if( m_pcCurrentSubWindow ) m_pcCurrentSubWindow->stopEvent();
{ playingTimer->stop();
m_pcCurrentSubWindow->stopEvent(); m_pcFrameSlider->setValue( m_pcCurrentSubWindow->getInputStream()->getCurrFrameNum() );
m_pcFrameSlider->setValue( m_pcCurrentSubWindow->getInputStream()->getCurrFrameNum() );
playingTimer->stop();
if( m_uiAveragePlayInterval )
qDebug( ) << "Real display time: "
<< QString::number( 1000 / m_uiAveragePlayInterval )
<< " fps";
m_uiAveragePlayInterval = 0;
}
} }
} }
void plaYUVerApp::playEvent() void plaYUVerApp::playEvent()
{ {
//m_cTimer.restart(); UInt time = m_cTimer.elapsed();
if( actionVideoLock->isChecked() ) m_cTimer.restart();
for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{ {
for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) switch( m_acPlayingSubWindows.at( i )->playEvent() )
{ {
if( !m_acPlayingSubWindows.at( i )->playEvent() ) case -1:
stop();
m_pcFrameSlider->setValue( m_pcCurrentSubWindow ? m_pcCurrentSubWindow->getInputStream()->getCurrFrameNum() : 0 );
break;
case -2:
if( !actionVideoLoop->isChecked() )
{ {
if( !actionVideoLoop->isChecked() ) stop();
{ m_pcFrameSlider->setValue( m_pcCurrentSubWindow ? m_pcCurrentSubWindow->getInputStream()->getCurrFrameNum() : 0 );
stop(); return;
}
} }
} break;
m_pcFrameSlider->setValue( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); case -3:
} m_acPlayingSubWindows.at( i )->close();
else break;
{ default:
if( m_pcCurrentSubWindow ) break;
{
UInt time = m_cTimer.elapsed();
m_cTimer.restart();
m_uiAveragePlayInterval = ( m_uiAveragePlayInterval + time ) / 2;
if( !m_pcCurrentSubWindow->playEvent() )
{
if( !actionVideoLoop->isChecked() )
{
stop();
}
}
m_pcFrameSlider->setValue( m_pcCurrentSubWindow->getInputStream()->getCurrFrameNum() );
} }
} }
m_pcFrameSlider->setValue( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() );
m_uiAveragePlayInterval = ( m_uiAveragePlayInterval + time ) / 2;
} }
void plaYUVerApp::seekEvent( int direction ) void plaYUVerApp::seekEvent( int direction )
{ {
if( activeSubWindow() ) if( m_acPlayingSubWindows.size() )
{ {
activeSubWindow()->seekRelativeEvent( direction > 0 ? true : false ); for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->seekRelativeEvent( direction > 0 ? true : false );
}
}
else
{
if( m_pcCurrentSubWindow )
m_pcCurrentSubWindow->seekRelativeEvent( direction > 0 ? true : false );
} }
} }
void plaYUVerApp::seekSliderEvent( int new_frame_num ) void plaYUVerApp::seekSliderEvent( int new_frame_num )
{ {
if( activeSubWindow() ) if( m_acPlayingSubWindows.size() )
{ {
activeSubWindow()->seekAbsoluteEvent( ( UInt )new_frame_num ); for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->seekAbsoluteEvent( ( UInt )new_frame_num );
}
}
else
{
if( m_pcCurrentSubWindow )
m_pcCurrentSubWindow->seekAbsoluteEvent( ( UInt )new_frame_num );
} }
} }
@@ -348,7 +362,6 @@ void plaYUVerApp::lockButtonEvent()
} }
} }
// ----------------------- Zoom Functions ----------------------- // ----------------------- Zoom Functions -----------------------
void plaYUVerApp::normalSize() void plaYUVerApp::normalSize()
@@ -385,11 +398,11 @@ void plaYUVerApp::chageSubWindowSelection()
{ {
if( activeSubWindow() ) if( activeSubWindow() )
{ {
playingTimer->stop();
if( m_pcCurrentSubWindow ) if( m_pcCurrentSubWindow )
m_pcCurrentSubWindow->disableModule(); m_pcCurrentSubWindow->disableModule();
if( !actionVideoLock->isChecked() ) if( m_acPlayingSubWindows.size() < 2 )
{ {
playingTimer->stop();
m_pcFrameSlider->setMaximum( activeSubWindow()->getInputStream()->getFrameNum() - 1 ); m_pcFrameSlider->setMaximum( activeSubWindow()->getInputStream()->getFrameNum() - 1 );
m_pcFrameSlider->setValue( activeSubWindow()->getInputStream()->getCurrFrameNum() ); m_pcFrameSlider->setValue( activeSubWindow()->getInputStream()->getCurrFrameNum() );
} }