From a65b47f8a31e61b4e416b78f5bae6d82a0a68c1a Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sun, 2 Feb 2014 18:01:05 +0000 Subject: [PATCH] Stop playing when reaches the end of file --- source/InputStream.cpp | 21 +++++++++++++++++++-- source/InputStream.h | 2 +- source/SubWindowHandle.cpp | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/source/InputStream.cpp b/source/InputStream.cpp index 90a54ef..860147b 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -145,7 +145,7 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for m_cCurrFrame = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat ); - UInt64 frame_bytes_input = m_uiWidth * m_uiHeight * 1.5; + UInt64 frame_bytes_input = m_cCurrFrame->getBytesPerFrame(); if( m_iFileFormat == YUVFormat ) { @@ -157,8 +157,8 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for return; } fseek( m_pFile, 0, SEEK_END ); - fseek( m_pFile, 0, SEEK_SET ); m_uiTotalFrameNum = ftell( m_pFile ) / ( frame_bytes_input ); + fseek( m_pFile, 0, SEEK_SET ); } if( !get_mem1Dpel( &m_pInputBuffer, m_cCurrFrame->getBytesPerFrame() ) ) @@ -167,6 +167,8 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for return; } + m_uiCurrFrameNum = 0; + m_iStatus = 1; return; @@ -191,6 +193,16 @@ Void InputStream::readFrame() } #endif + if( m_uiCurrFrameNum < m_uiTotalFrameNum ) + { + m_uiCurrFrameNum++; + } + else + { + m_iErrorStatus = END_OF_SEQ; + m_uiCurrFrameNum = 0; + seekInput( m_uiCurrFrameNum ); + } bytes_read = fread( m_pInputBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); if( bytes_read != frame_bytes_input ) { @@ -251,6 +263,11 @@ Void InputStream::seekInput( Int new_frame_num ) Bool InputStream::checkErrors( Int error_type ) { + if( m_iErrorStatus == error_type ) + { + m_iErrorStatus = NO_ERROR; + return true; + } if( m_iErrorStatus == error_type ) { m_iErrorStatus = NO_ERROR; diff --git a/source/InputStream.h b/source/InputStream.h index cd7762c..70f471f 100755 --- a/source/InputStream.h +++ b/source/InputStream.h @@ -45,7 +45,7 @@ namespace plaYUVer enum InputStream_Errors { - NO_ERROR = 0, READING = 1, + NO_ERROR = 0, READING = 1, END_OF_SEQ = 2, }; class InputStream diff --git a/source/SubWindowHandle.cpp b/source/SubWindowHandle.cpp index 6f8ce9e..73a1882 100644 --- a/source/SubWindowHandle.cpp +++ b/source/SubWindowHandle.cpp @@ -137,6 +137,11 @@ bool SubWindowHandle::playEvent() QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) ); return false; } + else if( m_currStream.checkErrors( END_OF_SEQ ) ) + { + m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + return false; + } m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); return true; }