From 25a4e9765f5d4e2efbc1bbde633ebe273b5c1b0f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 9 Dec 2017 02:32:11 +0000 Subject: [PATCH] Fix some problems Fix problems in the histogram calculation Change handle of frame count in the stream handlers --- app/CMakeLists.txt | 2 +- app/HistogramWidget.cpp | 13 +++-- app/HistogramWidget.h | 2 +- app/ModuleHandleDock.cpp | 1 - app/PlotSubWindow.cpp | 3 +- app/VideoSubWindow.cpp | 8 +-- app/external/qcustomplot/CMakeLists.txt | 2 +- lib/LibMemory.h | 69 +++---------------------- lib/PlaYUVerFrame.cpp | 29 ++++------- lib/PlaYUVerStream.cpp | 32 ++++++------ lib/PlaYUVerStream.h | 1 - lib/PlaYUVerStreamHandlerIf.h | 13 +++-- lib/StreamHandlerLibav.cpp | 21 ++++---- lib/StreamHandlerLibav.h | 2 +- lib/StreamHandlerOpenCV.cpp | 15 +++--- lib/StreamHandlerOpenCV.h | 1 - lib/StreamHandlerPortableMap.cpp | 6 +-- lib/StreamHandlerPortableMap.h | 1 - lib/StreamHandlerRaw.cpp | 18 ++++--- lib/StreamHandlerRaw.h | 2 +- 20 files changed, 92 insertions(+), 149 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a4241db..a2da427 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -130,7 +130,7 @@ ENDIF() ADD_EXECUTABLE( ${PROJECT_NAME} ${plaYUVer_App_SRCS} ${HEADERS_MOC_FILES} ${PlaYUVer_App_UI_Wrap} ${PlaYUVer_App_RCC} ${WINDOWS_RES_FILE} ) -TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PlaYUVerLib PlaYUVerModules QCustomPlotLib ${APP_LINKER_LIBS} ${QT_LINKER_LIBS} ) +TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PlaYUVerLib PlaYUVerModules ${APP_LINKER_LIBS} ${QT_LINKER_LIBS} QCustomPlotLib ) # QT5_USE_MODULES( ${PROJECT_NAME} ${QT_MODULES} ) diff --git a/app/HistogramWidget.cpp b/app/HistogramWidget.cpp index 725be1c..65da8e3 100644 --- a/app/HistogramWidget.cpp +++ b/app/HistogramWidget.cpp @@ -25,10 +25,16 @@ // TODO: // - Optimizar paintEvent. Parece haver codigo redundante !! -#include "HistogramWidget.h" + #include "config.h" +#include "HistogramWidget.h" #include -#include +#include +#include +#include +#include +#include +#include #include class HistogramWorker : public QThread @@ -47,7 +53,8 @@ public: Void setup( PlaYUVerFrame* frame ) { m_pcFrame = frame; - run(); + // run(); + start(); } Void run() { diff --git a/app/HistogramWidget.h b/app/HistogramWidget.h index 11d73d7..1c501b4 100644 --- a/app/HistogramWidget.h +++ b/app/HistogramWidget.h @@ -26,8 +26,8 @@ #ifndef __HISTOGRAMWIDGET_H__ #define __HISTOGRAMWIDGET_H__ -#include "PlaYUVerAppDefs.h" #include "config.h" +#include "PlaYUVerAppDefs.h" #include "lib/PlaYUVerFrame.h" #include #include diff --git a/app/ModuleHandleDock.cpp b/app/ModuleHandleDock.cpp index 639da66..4ddfb58 100644 --- a/app/ModuleHandleDock.cpp +++ b/app/ModuleHandleDock.cpp @@ -30,7 +30,6 @@ #include #include - ModuleHandleDock::ModuleHandleDock( QWidget* parent, PlaYUVerAppModuleIf* moduleIf ) : QWidget( parent ), m_pcCurrModuleIf( moduleIf ) { // ----------------- Dock definition ----------------- diff --git a/app/PlotSubWindow.cpp b/app/PlotSubWindow.cpp index 565fb23..dd5d766 100644 --- a/app/PlotSubWindow.cpp +++ b/app/PlotSubWindow.cpp @@ -23,7 +23,8 @@ */ #include "PlotSubWindow.h" -#include "external/qcustomplot/qcustomplot.h" +#include "qcustomplot.h" +//#include "external/qcustomplot/qcustomplot.h" Void PlotSubWindow::definePlotColors() { diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index ba44c1d..1c8f290 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -133,6 +133,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* , m_pcCurrentDisplayModule( NULL ) , m_pcReferenceSubWindow( NULL ) , m_bIsPlaying( false ) + , m_pcUpdateTimer( NULL ) { // Create a new scroll area inside the sub-window m_pcScrollArea = new QScrollArea; @@ -150,8 +151,8 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* connect( m_cViewArea, SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectedArea( QRect ) ) ); connect( m_cViewArea, SIGNAL( positionChanged( const QPoint& ) ), this, SLOT( updatePixelValueStatusBar( const QPoint& ) ) ); - m_pcScrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - m_pcScrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + // m_pcScrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + // m_pcScrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); // Define the cViewArea as the widget inside the scroll area m_pcScrollArea->setWidget( m_cViewArea ); @@ -176,6 +177,7 @@ VideoSubWindow::~VideoSubWindow() m_pcCurrFrame = NULL; disableModule(); delete m_cViewArea; + delete m_pcUpdateTimer; if( m_pCurrStream ) delete m_pCurrStream; } @@ -304,7 +306,7 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog ) Bool bConfig = guessFormat( cFilename, Width, Height, InputFormat, BitsPel, Endianness ) || bForceDialog; Bool bRet = false; for( Int iPass = 0; iPass < 2 && !bRet; iPass++ ) { - if( iPass && bConfig ) + if( iPass || bConfig ) { if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate ) == QDialog::Rejected ) diff --git a/app/external/qcustomplot/CMakeLists.txt b/app/external/qcustomplot/CMakeLists.txt index fdb0c22..a44396d 100644 --- a/app/external/qcustomplot/CMakeLists.txt +++ b/app/external/qcustomplot/CMakeLists.txt @@ -9,7 +9,7 @@ set(qcustomplot_SRCS qcustomplot.h ) -ADD_LIBRARY( QCustomPlotLib SHARED ${qcustomplot_SRCS} ) +ADD_LIBRARY( QCustomPlotLib STATIC ${qcustomplot_SRCS} ) TARGET_LINK_LIBRARIES( QCustomPlotLib Qt5::Core Qt5::Gui diff --git a/lib/LibMemory.h b/lib/LibMemory.h index 5cac4bc..5479751 100644 --- a/lib/LibMemory.h +++ b/lib/LibMemory.h @@ -116,48 +116,19 @@ Int getMem3D( T**** array3D, Int dim0, Int dim1, Int dim2 ) } template -Int getMem4D( T***** array4D, Int dim0, Int dim1, Int dim2, Int dim3 ) -{ - int i, mem_size = dim0 * sizeof( int*** ); - - if( ( ( *array4D ) = (T****)xMallocMem( dim0 * sizeof( T*** ) ) ) == NULL ) - printf( "get_mem4Dint: array4D" ); - - mem_size += getMem3D( *array4D, dim0 * dim1, dim2, dim3 ); - - for( i = 1; i < dim0; i++ ) ( *array4D )[i] = ( *array4D )[i - 1] + dim1; - - return mem_size; -} - -template -Int getMem5D( T****** array5D, Int dim0, Int dim1, Int dim2, Int dim3, Int dim4 ) -{ - int i, mem_size = dim0 * sizeof( T**** ); - - if( ( ( *array5D ) = (T*****)xMallocMem( dim0 * sizeof( T**** ) ) ) == NULL ) - printf( "get_mem5Dint: array5D" ); - - mem_size += getMem4D( *array5D, dim0 * dim1, dim2, dim3, dim4 ); - - for( i = 1; i < dim0; i++ ) ( *array5D )[i] = ( *array5D )[i - 1] + dim1; - - return mem_size; -} - -template -Void freeMem1D( T* array1D ) +Void freeMem1D( T*& array1D ) { if( array1D ) { xFreeMem( array1D ); + array1D = NULL; } } template -Void freeMem2D( T** array2D ) +Void freeMem2D( T**& array2D ) { - if( array2D ) + if( *array2D ) { if( *array2D ) xFreeMem( *array2D ); @@ -165,6 +136,7 @@ Void freeMem2D( T** array2D ) printf( "free_mem2Dint: trying to free unused memory" ); xFreeMem( array2D ); + array2D = NULL; } else { @@ -173,12 +145,13 @@ Void freeMem2D( T** array2D ) } template -Void freeMem3D( T*** array3D ) +Void freeMem3D( T***& array3D ) { if( array3D ) { freeMem2D( *array3D ); xFreeMem( array3D ); + array3D = NULL; } else { @@ -186,32 +159,4 @@ Void freeMem3D( T*** array3D ) } } -template -Void freeMem4D( T**** array4D ) -{ - if( array4D ) - { - freeMem3D( *array4D ); - xFreeMem( array4D ); - } - else - { - printf( "free_mem4Dint: trying to free unused memory" ); - } -} - -template -Void freeMem5D( T***** array5D ) -{ - if( array5D ) - { - freeMem4D( *array5D ); - xFreeMem( array5D ); - } - else - { - printf( "free_mem5Dint: trying to free unused memory" ); - } -} - #endif // __LIBMEMORY_H__ diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 3ec7486..7a93bf4 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -138,17 +138,16 @@ struct PlaYUVerFramePrivate Bool m_bHasRGBPel; //!< Flag indicating that the ARGB buffer was computed UChar* m_pcARGB32; //!< Buffer with the ARGB pixels used in Qt libs + /** Histogram control variables **/ + Bool m_bHasHistogram; + Bool m_bHistogramRunning; /** The histogram data.*/ UInt* m_puiHistogram; - /** If the image is RGB and calcLuma is true, we have 1 more channel */ UInt m_uiHistoChannels; - /** Numbers of histogram segments depending of image bytes depth*/ UInt m_uiHistoSegments; - Bool m_bHasHistogram; - /** * Common constructor function of a frame * @@ -189,6 +188,7 @@ struct PlaYUVerFramePrivate m_puiHistogram = NULL; m_bHasHistogram = false; + m_bHistogramRunning = false; m_uiHistoSegments = 1 << m_uiBitsPel; @@ -197,6 +197,8 @@ struct PlaYUVerFramePrivate else m_uiHistoChannels = m_pcPelFormat->numberChannels; + getMem1D( &( m_puiHistogram ), m_uiHistoSegments * m_uiHistoChannels ); + m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str(); m_bInit = true; @@ -204,20 +206,17 @@ struct PlaYUVerFramePrivate ~PlaYUVerFramePrivate() { + while( m_bHistogramRunning ) + ; if( m_puiHistogram ) - { freeMem1D( m_puiHistogram ); - } - m_puiHistogram = NULL; m_bHasHistogram = false; if( m_pppcInputPel ) freeImgMemory( m_pppcInputPel ); - m_pppcInputPel = NULL; if( m_pcARGB32 ) freeMem1D( m_pcARGB32 ); - m_pcARGB32 = NULL; } }; @@ -728,17 +727,10 @@ Void PlaYUVerFrame::fillRGBBuffer() Void PlaYUVerFrame::calcHistogram() { - if( d->m_bHasHistogram ) + if( d->m_bHasHistogram || !d->m_puiHistogram ) return; - if( !d->m_puiHistogram ) - { - getMem1D( &( d->m_puiHistogram ), d->m_uiHistoSegments * d->m_uiHistoChannels ); - if( !d->m_puiHistogram ) - { - return; - } - } + d->m_bHistogramRunning = true; xMemSet( UInt, d->m_uiHistoSegments * d->m_uiHistoChannels, d->m_puiHistogram ); @@ -784,6 +776,7 @@ Void PlaYUVerFrame::calcHistogram() } } d->m_bHasHistogram = true; + d->m_bHistogramRunning = false; } Int PlaYUVerFrame::getHistogramSegment() diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 802612c..08a21d8 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -188,7 +188,6 @@ PlaYUVerStream::PlaYUVerStream() m_pcHandler = NULL; m_bIsInput = true; m_bLoadAll = false; - m_uiTotalFrameNum = 0; m_iCurrFrameNum = -1; m_cFilename = ""; } @@ -289,14 +288,12 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f return m_bInit; } - m_pcHandler->setBytesPerFrame( m_frameBuffer->current()->getBytesPerFrame() ); + m_pcHandler->m_uiNBytesPerFrame = m_frameBuffer->current()->getBytesPerFrame(); - if( m_bIsInput ) - { - m_uiTotalFrameNum = m_pcHandler->calculateFrameNumber(); - } + // Some handlers need to know how long is a frame to get frame number + m_pcHandler->calculateFrameNumber(); - if( m_bIsInput && m_uiTotalFrameNum <= 0 ) + if( m_bIsInput && m_pcHandler->m_uiTotalNumberFrames == 0 ) { close(); throw PlaYUVerFailure( "PlaYUVerStream", "Incorrect configuration: less than one frame" ); @@ -327,15 +324,16 @@ Bool PlaYUVerStream::reload() throw PlaYUVerFailure( "PlaYUVerStream", "Cannot open stream " + m_cFilename + " with the " + String( m_pcHandler->m_pchHandlerName ) + " handler" ); } - m_pcHandler->setBytesPerFrame( m_frameBuffer->current()->getBytesPerFrame() ); - m_uiTotalFrameNum = m_pcHandler->calculateFrameNumber(); + m_pcHandler->m_uiNBytesPerFrame = m_frameBuffer->current()->getBytesPerFrame(); + m_pcHandler->calculateFrameNumber(); + m_pcHandler->configureBuffer( m_frameBuffer->current() ); if( m_pcHandler->m_uiWidth <= 0 || m_pcHandler->m_uiHeight <= 0 || m_pcHandler->m_iPixelFormat < 0 || m_pcHandler->m_uiBitsPerPixel == 0 || - m_uiTotalFrameNum < 1 ) + m_pcHandler->m_uiTotalNumberFrames == 0 ) { return false; } - if( UInt( m_iCurrFrameNum ) >= m_uiTotalFrameNum ) + if( UInt( m_iCurrFrameNum ) >= m_pcHandler->m_uiTotalNumberFrames ) { m_iCurrFrameNum = 0; } @@ -366,7 +364,7 @@ String PlaYUVerStream::getFileName() UInt PlaYUVerStream::getFrameNum() { - return m_uiTotalFrameNum; + return m_pcHandler->m_uiTotalNumberFrames; } UInt PlaYUVerStream::getWidth() const { @@ -419,7 +417,7 @@ Void PlaYUVerStream::loadAll() try { - m_frameBuffer->increase( m_uiTotalFrameNum ); + m_frameBuffer->increase( m_pcHandler->m_uiTotalNumberFrames ); } catch( PlaYUVerFailure& e ) { @@ -460,7 +458,7 @@ Void PlaYUVerStream::getDuration( Int* duration_array ) Bool PlaYUVerStream::readFrame( PlaYUVerFrame* frame ) { - if( !m_bInit || !m_bIsInput || m_pcHandler->m_uiCurrFrameFileIdx >= m_uiTotalFrameNum ) + if( !m_bInit || !m_bIsInput || m_pcHandler->m_uiCurrFrameFileIdx >= m_pcHandler->m_uiTotalNumberFrames ) return false; if( m_bLoadAll ) @@ -510,7 +508,7 @@ Bool PlaYUVerStream::setNextFrame() { Bool bEndOfSeq = false; - if( m_iCurrFrameNum + 1 < Int( m_uiTotalFrameNum ) ) + if( m_iCurrFrameNum + 1 < Int64( m_pcHandler->m_uiTotalNumberFrames ) ) { m_frameBuffer->setNextFrame(); m_iCurrFrameNum++; @@ -569,7 +567,7 @@ Bool PlaYUVerStream::seekInputRelative( Bool bIsFoward ) Bool PlaYUVerStream::seekInput( UInt64 new_frame_num ) { - if( !m_bInit || new_frame_num >= m_uiTotalFrameNum || (Int64)new_frame_num == m_iCurrFrameNum ) + if( !m_bInit || new_frame_num >= m_pcHandler->m_uiTotalNumberFrames || Int64( new_frame_num ) == m_iCurrFrameNum ) return false; m_iCurrFrameNum = new_frame_num; @@ -587,7 +585,7 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num ) m_frameBuffer->setIndex( 0 ); readFrame( m_frameBuffer->current() ); - if( m_uiTotalFrameNum > 1 ) + if( m_pcHandler->m_uiTotalNumberFrames > 1 ) readFrame( m_frameBuffer->next() ); return true; diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index 8937ee7..8e4cf4a 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -126,7 +126,6 @@ private: Bool m_bIsInput; String m_cFilename; - UInt64 m_uiTotalFrameNum; Int64 m_iCurrFrameNum; Bool m_bLoadAll; diff --git a/lib/PlaYUVerStreamHandlerIf.h b/lib/PlaYUVerStreamHandlerIf.h index 5ed8489..4c957fb 100644 --- a/lib/PlaYUVerStreamHandlerIf.h +++ b/lib/PlaYUVerStreamHandlerIf.h @@ -79,7 +79,9 @@ public: , m_uiBitsPerPixel( 8 ) , m_iEndianness( -1 ) , m_dFrameRate( 30 ) + , m_uiTotalNumberFrames( 0 ) , m_pStreamBuffer( NULL ) + , m_uiNBytesPerFrame( 0 ) { } virtual ~PlaYUVerStreamHandlerIf() {} @@ -88,17 +90,20 @@ public: virtual Bool openHandler( String strFilename, Bool bInput ) = 0; virtual Void closeHandler() = 0; virtual Bool configureBuffer( PlaYUVerFrame* pcFrame ) = 0; - virtual UInt64 calculateFrameNumber() = 0; virtual Bool seek( UInt64 iFrameNum ) = 0; virtual Bool read( PlaYUVerFrame* pcFrame ) = 0; virtual Bool write( PlaYUVerFrame* pcFrame ) = 0; - Void setBytesPerFrame( UInt64 uiNBytes ) { m_uiNBytesPerFrame = uiNBytes; } + virtual Void calculateFrameNumber(){}; + String getFormatName() { return m_strFormatName; } String getCodecName() { return m_strCodecName; } protected: const Char* m_pchHandlerName; + + String m_strFormatName; + String m_strCodecName; Bool m_bIsInput; UInt64 m_uiCurrFrameFileIdx; String m_cFilename; @@ -108,11 +113,9 @@ protected: UInt m_uiBitsPerPixel; Int m_iEndianness; Double m_dFrameRate; - + UInt64 m_uiTotalNumberFrames; Byte* m_pStreamBuffer; UInt64 m_uiNBytesPerFrame; - String m_strFormatName; - String m_strCodecName; }; #endif // __PLAYUVERSTREAMHANDLERIF_H__ diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index eb61d9a..16265da 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -167,6 +167,9 @@ Bool StreamHandlerLibav::openHandler( String strFilename, Bool bInput ) const char* name = avcodec_get_name( m_cCodedCtx->codec_id ); m_strCodecName = name; + // Set bits per pixel to default (8 bits) + m_uiBitsPerPixel = 8; + /** * Auxiliar conversation to re-use similar pixfmt */ @@ -223,8 +226,7 @@ Bool StreamHandlerLibav::openHandler( String strFilename, Bool bInput ) m_dFrameRate = fr; - // Set bits per pixel to default (8 bits) - m_uiBitsPerPixel = 8; + calculateFrameNumber(); /* dump input information to stderr */ av_dump_format( m_cFmtCtx, 0, filename, 0 ); @@ -275,15 +277,14 @@ Bool StreamHandlerLibav::configureBuffer( PlaYUVerFrame* pcFrame ) return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); } -UInt64 StreamHandlerLibav::calculateFrameNumber() +Void StreamHandlerLibav::calculateFrameNumber() { UInt64 num_frames; - // if( m_cStream->nb_frames ) - // { * - // num_frames = m_cStream->nb_frames; - // } - // else - if( m_cFmtCtx->duration != AV_NOPTS_VALUE ) + if( m_cStream->nb_frames ) + { + num_frames = m_cStream->nb_frames; + } + else if( m_cFmtCtx->duration != AV_NOPTS_VALUE ) { Int64 duration = m_cFmtCtx->duration + 5000; m_uiSecs = duration / AV_TIME_BASE; @@ -295,7 +296,7 @@ UInt64 StreamHandlerLibav::calculateFrameNumber() num_frames = 0; } num_frames = num_frames == 0 ? 1 : num_frames; - return num_frames; + m_uiTotalNumberFrames = num_frames; } Bool StreamHandlerLibav::read( PlaYUVerFrame* pcFrame ) diff --git a/lib/StreamHandlerLibav.h b/lib/StreamHandlerLibav.h index 66747fd..3a8cfb0 100644 --- a/lib/StreamHandlerLibav.h +++ b/lib/StreamHandlerLibav.h @@ -64,7 +64,7 @@ public: Bool openHandler( String strFilename, Bool bInput ); Void closeHandler(); Bool configureBuffer( PlaYUVerFrame* pcFrame ); - UInt64 calculateFrameNumber(); + Void calculateFrameNumber(); Bool seek( UInt64 iFrameNum ); Bool read( PlaYUVerFrame* pcFrame ); Bool write( PlaYUVerFrame* pcFrame ); diff --git a/lib/StreamHandlerOpenCV.cpp b/lib/StreamHandlerOpenCV.cpp index 0a23977..455a8b6 100644 --- a/lib/StreamHandlerOpenCV.cpp +++ b/lib/StreamHandlerOpenCV.cpp @@ -97,6 +97,12 @@ Bool StreamHandlerOpenCV::openHandler( String strFilename, Bool bInput ) } m_uiBitsPerPixel = 8; m_iPixelFormat = PlaYUVerFrame::findPixelFormat( "BGR" ); + + m_uiTotalNumberFrames = 1; + if( pcVideoCapture ) + { + m_uiTotalNumberFrames = 2; + } } return true; @@ -117,15 +123,6 @@ Bool StreamHandlerOpenCV::configureBuffer( PlaYUVerFrame* pcFrame ) return true; } -UInt64 StreamHandlerOpenCV::calculateFrameNumber() -{ - if( pcVideoCapture ) - { - return 2; - } - return 1; -} - Bool StreamHandlerOpenCV::seek( UInt64 iFrameNum ) { // m_uiCurrFrameFileIdx = diff --git a/lib/StreamHandlerOpenCV.h b/lib/StreamHandlerOpenCV.h index a5f229f..31fc4bd 100644 --- a/lib/StreamHandlerOpenCV.h +++ b/lib/StreamHandlerOpenCV.h @@ -45,7 +45,6 @@ public: Bool openHandler( String strFilename, Bool bInput ); Void closeHandler(); Bool configureBuffer( PlaYUVerFrame* pcFrame ); - UInt64 calculateFrameNumber(); Bool seek( UInt64 iFrameNum ); Bool read( PlaYUVerFrame* pcFrame ); Bool write( PlaYUVerFrame* pcFrame ); diff --git a/lib/StreamHandlerPortableMap.cpp b/lib/StreamHandlerPortableMap.cpp index 568cee8..a05f57e 100644 --- a/lib/StreamHandlerPortableMap.cpp +++ b/lib/StreamHandlerPortableMap.cpp @@ -105,6 +105,7 @@ Bool StreamHandlerPortableMap::openHandler( String strFilename, Bool bInput ) } m_iEndianness = 0; m_dFrameRate = 1; + m_uiTotalNumberFrames = 1; return true; } @@ -122,11 +123,6 @@ Bool StreamHandlerPortableMap::configureBuffer( PlaYUVerFrame* pcFrame ) return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); } -UInt64 StreamHandlerPortableMap::calculateFrameNumber() -{ - return 1; -} - Bool StreamHandlerPortableMap::seek( UInt64 iFrameNum ) { // m_uiCurrFrameFileIdx = diff --git a/lib/StreamHandlerPortableMap.h b/lib/StreamHandlerPortableMap.h index 628a88a..eb6e685 100644 --- a/lib/StreamHandlerPortableMap.h +++ b/lib/StreamHandlerPortableMap.h @@ -40,7 +40,6 @@ public: Bool openHandler( String strFilename, Bool bInput ); Void closeHandler(); Bool configureBuffer( PlaYUVerFrame* pcFrame ); - UInt64 calculateFrameNumber(); Bool seek( UInt64 iFrameNum ); Bool read( PlaYUVerFrame* pcFrame ); Bool write( PlaYUVerFrame* pcFrame ); diff --git a/lib/StreamHandlerRaw.cpp b/lib/StreamHandlerRaw.cpp index 8575061..e1ef6da 100644 --- a/lib/StreamHandlerRaw.cpp +++ b/lib/StreamHandlerRaw.cpp @@ -55,6 +55,7 @@ Bool StreamHandlerRaw::openHandler( String strFilename, Bool bInput ) { return false; } + calculateFrameNumber(); m_strFormatName = "YUV"; m_strCodecName = "Raw Video"; return true; @@ -73,14 +74,15 @@ Bool StreamHandlerRaw::configureBuffer( PlaYUVerFrame* pcFrame ) return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); } -UInt64 StreamHandlerRaw::calculateFrameNumber() +Void StreamHandlerRaw::calculateFrameNumber() { - if( !m_pFile || m_uiNBytesPerFrame == 0 ) - return 0; - fseek( m_pFile, 0, SEEK_END ); - UInt64 fileSize = ftell( m_pFile ); - fseek( m_pFile, 0, SEEK_SET ); - return ( fileSize / m_uiNBytesPerFrame ); + if( m_pFile && m_uiNBytesPerFrame > 0 ) + { + fseek( m_pFile, 0, SEEK_END ); + UInt64 fileSize = ftell( m_pFile ); + fseek( m_pFile, 0, SEEK_SET ); + m_uiTotalNumberFrames = fileSize / m_uiNBytesPerFrame; + } } Bool StreamHandlerRaw::seek( UInt64 iFrameNum ) @@ -96,6 +98,8 @@ Bool StreamHandlerRaw::seek( UInt64 iFrameNum ) Bool StreamHandlerRaw::read( PlaYUVerFrame* pcFrame ) { + if( !m_pFile || !m_pStreamBuffer || m_uiNBytesPerFrame == 0 ) + return false; UInt64 processed_bytes = fread( m_pStreamBuffer, sizeof( Byte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; diff --git a/lib/StreamHandlerRaw.h b/lib/StreamHandlerRaw.h index 5ccc928..0d6d036 100644 --- a/lib/StreamHandlerRaw.h +++ b/lib/StreamHandlerRaw.h @@ -45,7 +45,7 @@ public: Bool openHandler( String strFilename, Bool bInput ); Void closeHandler(); Bool configureBuffer( PlaYUVerFrame* pcFrame ); - UInt64 calculateFrameNumber(); + Void calculateFrameNumber(); Bool seek( UInt64 iFrameNum ); Bool read( PlaYUVerFrame* pcFrame ); Bool write( PlaYUVerFrame* pcFrame );