From ffe1bf688d5457b81610ba3c2adc8ebb2ee1f0b9 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 7 Sep 2021 02:00:30 +0100 Subject: [PATCH] Improve the use of threads and sleep when not in use --- app/CMakeLists.txt | 1 + app/CalypAppModuleIf.cpp | 1 - app/ResourceHandle.cpp | 85 ++++++++++++++++++------------- app/ResourceHandle.h | 15 ++++-- app/VideoHandle.cpp | 6 +-- app/VideoSubWindow.cpp | 62 +++++++++++----------- app/VideoSubWindow.h | 9 ++-- app/dialog/SeekStreamDialog.cpp | 2 +- app/dialog/SeekStreamDialog.h | 2 +- app/docks/FramePropertiesDock.cpp | 4 +- app/docks/FramePropertiesDock.h | 2 +- config.h.in | 3 ++ lib/CalypStream.cpp | 75 +++++++++++++++------------ lib/CalypStream.h | 14 ++--- tools/CalypTools.cpp | 12 +---- 15 files changed, 164 insertions(+), 129 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 6efa880..e114a70 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES( OPTION(USE_QTDBUS "Build with QtDBus" ON) OPTION(USE_FERVOR "Add Fervor support" OFF) +OPTION(USE_RESOURCES "Handle streams in separate threads" ON) ADD_SUBDIRECTORY(external) diff --git a/app/CalypAppModuleIf.cpp b/app/CalypAppModuleIf.cpp index 4355952..8fd5ee0 100644 --- a/app/CalypAppModuleIf.cpp +++ b/app/CalypAppModuleIf.cpp @@ -225,7 +225,6 @@ void CalypAppModuleIf::destroy() } if( m_pcModuleStream ) { - m_pcModuleStream->close(); delete m_pcModuleStream; m_pcModuleStream = NULL; } diff --git a/app/ResourceHandle.cpp b/app/ResourceHandle.cpp index 0779e68..c61f7b7 100644 --- a/app/ResourceHandle.cpp +++ b/app/ResourceHandle.cpp @@ -44,13 +44,29 @@ void ResourceWorker::stop() wait(); } +void ResourceWorker::wake() +{ + m_Mutex.lock(); + m_ResourceIdle.wakeAll(); + m_Mutex.unlock(); +} + void ResourceWorker::run() { + // Loop forever while( !m_bStop ) { m_pcStream->readNextFrameFillRGBBuffer(); + if( !m_pcStream->hasWritingSlot() ) + { + m_Mutex.lock(); + m_ResourceIdle.wait( &m_Mutex ); + m_Mutex.unlock(); + } while( !m_bStop && !m_pcStream->hasWritingSlot() ) - ; // Keep + { + // Wait here + } } } @@ -58,73 +74,72 @@ ResourceHandle::ResourceHandle() { } -auto ResourceHandle::addResource() -> CalypStream* +auto ResourceHandle::addResource() -> std::size_t { auto newStreamResource = std::make_shared(); auto newStreamResourceWorker = std::make_unique( newStreamResource ); - CalypStream* ptr = newStreamResource.get(); - m_apcStreamResourcesList.push_back( newStreamResource ); m_apcStreamResourcesWorkersList.push_back( std::move( newStreamResourceWorker ) ); - return ptr; + return m_apcStreamResourcesList.size() - 1; } -auto ResourceHandle::getResource( CalypStream* ptr ) -> CalypStream* +auto ResourceHandle::getResource( CalypStream* ptr ) -> std::size_t { if( ptr != nullptr ) { - for( auto& resource_ptr : m_apcStreamResourcesList ) + for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ ) { - if( resource_ptr.get() == ptr ) - return resource_ptr.get(); + if( m_apcStreamResourcesList[i].get() == ptr ) + return i; } } return addResource(); } -void ResourceHandle::removeResource( CalypStream* ptr ) +auto ResourceHandle::getResourceAsset( std::size_t id ) -> CalypStream* { - std::optional posToRemove; - for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ ) + if( id < m_apcStreamResourcesList.size() ) { - if( m_apcStreamResourcesList[i].get() == ptr ) - { - posToRemove = i; - break; - } + return m_apcStreamResourcesList[id].get(); } - if( !posToRemove.has_value() ) + return nullptr; +} + +void ResourceHandle::removeResource( std::size_t id ) +{ + if( id >= m_apcStreamResourcesList.size() ) { assert( false ); return; } // Remove worker first - m_apcStreamResourcesWorkersList[*posToRemove]->stop(); - m_apcStreamResourcesWorkersList.erase( m_apcStreamResourcesWorkersList.begin() + *posToRemove ); + m_apcStreamResourcesWorkersList[id]->stop(); + m_apcStreamResourcesWorkersList.erase( m_apcStreamResourcesWorkersList.begin() + id ); // Then the underlying stream - m_apcStreamResourcesList.erase( m_apcStreamResourcesList.begin() + *posToRemove ); + m_apcStreamResourcesList.erase( m_apcStreamResourcesList.begin() + id ); } -void ResourceHandle::startResourceWorker( CalypStream* ptr ) +void ResourceHandle::startResourceWorker( std::size_t id ) { - std::optional position; - for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ ) - { - if( m_apcStreamResourcesList[i].get() == ptr ) - { - position = i; - break; - } - } - if( !position.has_value() ) + if( id >= m_apcStreamResourcesList.size() ) { assert( false ); return; } - m_apcStreamResourcesWorkersList[*position]->setObjectName( + m_apcStreamResourcesWorkersList[id]->setObjectName( "RW-" + - QFileInfo( QString::fromStdString( m_apcStreamResourcesList[*position]->getFileName() ) ).completeBaseName() ); - m_apcStreamResourcesWorkersList[*position]->start(); + QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() ); + m_apcStreamResourcesWorkersList[id]->start(); +} + +void ResourceHandle::wakeResourceWorker( std::size_t id ) +{ + if( id >= m_apcStreamResourcesList.size() ) + { + assert( false ); + return; + } + m_apcStreamResourcesWorkersList[id]->wake(); } \ No newline at end of file diff --git a/app/ResourceHandle.h b/app/ResourceHandle.h index 6ba7f46..29c05a6 100644 --- a/app/ResourceHandle.h +++ b/app/ResourceHandle.h @@ -25,8 +25,10 @@ #ifndef __RESOURCEHANDLE_H__ #define __RESOURCEHANDLE_H__ +#include #include #include +#include #include "CommonDefs.h" #include "lib/CalypStream.h" @@ -34,12 +36,15 @@ class ResourceWorker : public QThread { private: + QMutex m_Mutex; + QWaitCondition m_ResourceIdle; std::shared_ptr m_pcStream; bool m_bStop{ false }; public: ResourceWorker( std::shared_ptr stream ); void stop(); + void wake(); void run(); }; @@ -49,12 +54,14 @@ public: ResourceHandle(); ~ResourceHandle() = default; - auto getResource( CalypStream* ptr ) -> CalypStream*; - void removeResource( CalypStream* ptr ); - void startResourceWorker( CalypStream* ptr ); + auto getResource( CalypStream* ptr ) -> std::size_t; + auto getResourceAsset( std::size_t id ) -> CalypStream*; + void removeResource( std::size_t id ); + void startResourceWorker( std::size_t id ); + void wakeResourceWorker( std::size_t id ); private: - auto addResource() -> CalypStream*; + auto addResource() -> std::size_t; private: std::vector> m_apcStreamResourcesList; diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 21cf315..28d53cd 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -326,8 +326,8 @@ void VideoHandle::update() { if( m_pcCurrentVideoSubWindow ) { - CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream(); - CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); + const CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream(); + const CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() ); @@ -364,7 +364,7 @@ void VideoHandle::update() } m_pcResolutionLabel->setText( resolution ); - m_pcFramePropertiesSideBar->setFrame( pcFrame, m_pcCurrentVideoSubWindow->isPlaying() ); + m_pcFramePropertiesSideBar->setFrame( m_pcCurrentVideoSubWindow->getCurrFrameAsset(), m_pcCurrentVideoSubWindow->isPlaying() ); m_pcFrameNumInfo->setTotalFrameNum( total_frame_num ); m_pcFrameNumInfo->setCurrFrameNum( frame_num ); diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 813ece1..fbacffd 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -35,8 +35,7 @@ #include "ResourceHandle.h" #include "SubWindowAbstract.h" -//#define QT_NO_CONCURRENT -//#define USE_CALYPSTREAM_RETRIEVE +#define QT_NO_CONCURRENT /** * \brief Functions to control data stream from stream information @@ -200,7 +199,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* VideoSubWindow::~VideoSubWindow() { disableModule(); - m_pcResourceManager->removeResource( m_pCurrStream ); + m_pcResourceManager->removeResource( m_uiResourceId ); //delete m_cViewArea; delete m_pcUpdateTimer; } @@ -331,7 +330,9 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog ) if( m_pCurrStream ) m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, Endianness, FrameRate ); else - m_pCurrStream = m_pcResourceManager->getResource( nullptr ); + m_uiResourceId = m_pcResourceManager->getResource( nullptr ); + + m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId ); bool bConfig = true; if( !bForceDialog ) @@ -384,8 +385,8 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog ) var.setValue( BitsPel ); appSettings.setValue( "VideoSubWindow/LastBitsPerPixel", var ); -#ifdef USE_CALYPSTREAM_RETRIEVE - m_pcResourceManager->startResourceWorker( m_pCurrStream ); +#ifdef USE_RESOURCES + m_pcResourceManager->startResourceWorker( m_uiResourceId ); #endif QApplication::restoreOverrideCursor(); @@ -404,7 +405,8 @@ bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo ) { assert( m_pcResourceManager != nullptr ); - m_pCurrStream = m_pcResourceManager->getResource( m_pCurrStream ); + m_uiResourceId = m_pcResourceManager->getResource( m_pCurrStream ); + m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId ); if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight, streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness, @@ -415,8 +417,8 @@ bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo ) m_sStreamInfo = *streamInfo; -#ifdef USE_CALYPSTREAM_RETRIEVE - m_pcResourceManager->startResourceWorker( m_pCurrStream ); +#ifdef USE_RESOURCES + m_pcResourceManager->startResourceWorker( m_uiResourceId ); #endif QApplication::restoreOverrideCursor(); @@ -728,16 +730,22 @@ void VideoSubWindow::setCurrFrame( CalypFrame* pcCurrFrame ) m_cViewArea->setImage( m_pcCurrFrame ); } +void VideoSubWindow::setCurrFrame( std::shared_ptr pcCurrFrame ) +{ + m_pcCurrDisplayFrame = pcCurrFrame; + m_cViewArea->setImage( m_pcCurrDisplayFrame.get() ); +} + void VideoSubWindow::refreshFrameOperation() { bool bSetFrame = false; - if( m_pcCurrStreamFrame != nullptr ) - { - m_pcCurrFrame = m_pcCurrStreamFrame.get(); - } - else if( m_pCurrStream ) + if( m_pCurrStream ) { +#ifdef USE_RESOURCES + m_pcCurrFrame = m_pCurrStream->getCurrFrameAsset().get(); +#else m_pcCurrFrame = m_pCurrStream->getCurrFrame(); +#endif } bSetFrame = m_pcCurrFrame ? true : false; if( m_pcCurrentDisplayModule ) @@ -773,12 +781,13 @@ void VideoSubWindow::refreshFrame( bool bThreaded ) bool VideoSubWindow::goToNextFrame( bool bThreaded ) { -#ifdef USE_CALYPSTREAM_RETRIEVE - m_pcCurrStreamFrame = m_pCurrStream->retrieveNextFrame(); - if( m_pcCurrStreamFrame == nullptr ) - return true; - refreshFrame(); - return false; +#ifdef USE_RESOURCES + bool bEndOfSeq = m_pCurrStream->retrieveNextFrame(); + m_pcResourceManager->wakeResourceWorker( m_uiResourceId ); + if( !bEndOfSeq ) + { + refreshFrame(); + } #else #ifndef QT_NO_CONCURRENT m_cRefreshResult.waitForFinished(); @@ -801,8 +810,8 @@ bool VideoSubWindow::goToNextFrame( bool bThreaded ) m_pCurrStream->readNextFrameFillRGBBuffer(); } } - return bEndOfSeq; #endif + return bEndOfSeq; } bool VideoSubWindow::save( QString filename ) @@ -887,7 +896,7 @@ void VideoSubWindow::pause() void VideoSubWindow::seekAbsoluteEvent( unsigned int new_frame_num ) { - m_pcCurrStreamFrame = nullptr; + m_pcResourceManager->wakeResourceWorker( m_uiResourceId ); if( m_pCurrStream ) if( m_pCurrStream->seekInput( new_frame_num ) ) refreshFrame(); @@ -904,14 +913,9 @@ void VideoSubWindow::seekRelativeEvent( bool bIsFoward ) } else { - m_pcCurrStreamFrame = nullptr; bRefresh = m_pCurrStream->seekInputRelative( bIsFoward ); -#ifdef USE_CALYPSTREAM_RETRIEVE - if( bRefresh ) - { - m_pcCurrStreamFrame = m_pCurrStream->retrieveNextFrame(); - bRefresh &= m_pcCurrStreamFrame != nullptr; - } +#ifdef USE_RESOURCES + m_pcResourceManager->wakeResourceWorker( m_uiResourceId ); #endif } } diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 75b29b7..f6be66c 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -82,8 +82,9 @@ private: QString m_cFilename; QString m_cStreamInformation; CalypFileInfo m_sStreamInfo; + std::size_t m_uiResourceId; CalypStream* m_pCurrStream; - std::shared_ptr m_pcCurrStreamFrame; + std::shared_ptr m_pcCurrDisplayFrame; CalypFrame* m_pcCurrFrame; QRect m_cSelectedArea; @@ -139,12 +140,14 @@ public: void seekRelativeEvent( bool bIsFoward ); void setCurrFrame( CalypFrame* pcCurrFrame ); + void setCurrFrame( std::shared_ptr pcCurrFrame ); CalypFileInfo getStreamInfo() { return m_sStreamInfo; } QString getStreamInformation() { return m_cStreamInformation; } - CalypStream* getInputStream() { return m_pCurrStream; } - CalypStream* getCurrStream() { return m_pCurrStream; } + const CalypStream* getInputStream() { return m_pCurrStream; } + const CalypStream* getCurrStream() { return m_pCurrStream; } CalypFrame* getCurrFrame() { return m_pcCurrFrame; } + std::shared_ptr getCurrFrameAsset() { return m_pCurrStream->getCurrFrameAsset(); }; ViewArea* getViewArea() { return m_cViewArea; } void setRefSubWindow( VideoSubWindow* subWindow ) { diff --git a/app/dialog/SeekStreamDialog.cpp b/app/dialog/SeekStreamDialog.cpp index 1f6e961..0dd3669 100644 --- a/app/dialog/SeekStreamDialog.cpp +++ b/app/dialog/SeekStreamDialog.cpp @@ -33,7 +33,7 @@ #include "lib/CalypStream.h" -SeekStreamDialog::SeekStreamDialog( CalypStream* pcCurrStream, QWidget* parent ) +SeekStreamDialog::SeekStreamDialog( const CalypStream* pcCurrStream, QWidget* parent ) : QDialog( parent, Qt::Dialog | Qt::WindowTitleHint ), m_iSelectedFrameNum() { m_iSelectedFrameNum = pcCurrStream->getCurrFrameNum(); diff --git a/app/dialog/SeekStreamDialog.h b/app/dialog/SeekStreamDialog.h index 846b743..0d8f3f2 100644 --- a/app/dialog/SeekStreamDialog.h +++ b/app/dialog/SeekStreamDialog.h @@ -42,7 +42,7 @@ class SeekStreamDialog : public QDialog Q_OBJECT public: - SeekStreamDialog( CalypStream* pcCurrStream, QWidget* parent = 0 ); + SeekStreamDialog( const CalypStream* pcCurrStream, QWidget* parent = 0 ); int runDialog(); private: diff --git a/app/docks/FramePropertiesDock.cpp b/app/docks/FramePropertiesDock.cpp index d05c902..2ef18fb 100644 --- a/app/docks/FramePropertiesDock.cpp +++ b/app/docks/FramePropertiesDock.cpp @@ -297,7 +297,7 @@ void FramePropertiesDock::reset() setEnabled( false ); } -void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying ) +void FramePropertiesDock::setFrame( std::shared_ptr pcFrame, bool isPlaying ) { int colorSpace = pcFrame->getColorSpace(); if( m_iLastFrameType != colorSpace ) @@ -365,7 +365,7 @@ void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying ) if( pcFrame ) { m_bHasFrame = true; - m_pcFrame = std::make_shared( *pcFrame ); + m_pcFrame = pcFrame; } else { diff --git a/app/docks/FramePropertiesDock.h b/app/docks/FramePropertiesDock.h index cde3496..9048666 100644 --- a/app/docks/FramePropertiesDock.h +++ b/app/docks/FramePropertiesDock.h @@ -43,7 +43,7 @@ public: QSize sizeHint() const; - void setFrame( CalypFrame* m_pcFrame, bool isPlaying ); + void setFrame( std::shared_ptr m_pcFrame, bool isPlaying ); void setSelection( const QRect& selectionArea ); void reset(); void stopHistogram(); diff --git a/config.h.in b/config.h.in index 1edcbb9..31c2469 100644 --- a/config.h.in +++ b/config.h.in @@ -55,4 +55,7 @@ /* Fervor update lib */ #cmakedefine USE_FERVOR +/* Use a resource manager to manage streams in different threads */ +#cmakedefine USE_RESOURCES + #endif // __CONFIG_CALYP_H__ diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 74c5a07..32c9997 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -211,6 +211,7 @@ public: CreateStreamHandlerFn pfctCreateHandler; std::unique_ptr frameBuffer; + std::shared_ptr currentFrame; ClpString cFilename; long long int iCurrFrameNum; @@ -369,7 +370,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei { if( d->isInit ) { - close(); + d->close(); } d->isInit = false; d->isInput = bInput; @@ -399,13 +400,13 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei if( !d->handler->openHandler( d->cFilename, d->isInput ) ) { - close(); + d->close(); return d->isInit; } if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 ) { - close(); + d->close(); //throw CalypFailure( "CalypStream", "Incorrect configuration: width, height or pixel format" ); return d->isInit; } @@ -419,7 +420,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei } catch( CalypFailure& e ) { - close(); + d->close(); throw CalypFailure( "CalypStream", "Cannot allocated frame buffer" ); return d->isInit; } @@ -431,14 +432,14 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei if( d->isInput && d->handler->m_uiTotalNumberFrames == 0 ) { - close(); + d->close(); throw CalypFailure( "CalypStream", "Incorrect configuration: less than one frame" ); return d->isInit; } if( !d->handler->configureBuffer( d->frameBuffer->ref() ) ) { - close(); + d->close(); throw CalypFailure( "CalypStream", "Cannot allocated buffers" ); return d->isInit; } @@ -479,11 +480,6 @@ bool CalypStream::reload() return true; } -void CalypStream::close() -{ - d->close(); -} - ClpString CalypStream::getFileName() const { return d->cFilename; @@ -562,7 +558,7 @@ void CalypStream::loadAll() } catch( CalypFailure& e ) { - close(); + d->close(); throw CalypFailure( "CalypStream", "Cannot allocated frame buffer for the whole stream" ); } @@ -575,6 +571,38 @@ void CalypStream::loadAll() d->iCurrFrameNum = 0; } +// auto CalypStream::getNextFrame() -> CalypFrame& +// { +// CalypFrame& frameToTead = d->frameBuffer->readOneFrame(); +// d->readFrame( d->frameBuffer->writeOneFrame() ); +// return frameToTead; +// } + +auto CalypStream::retrieveNextFrame() -> bool +{ + const std::lock_guard lock( d->mutex ); + bool bEndOfSeq = false; + if( d->iCurrFrameNum + 1 < (long)( d->handler->m_uiTotalNumberFrames ) ) + { + d->iCurrFrameNum++; + d->currentFrame = d->frameBuffer->retrieveFrame(); + } + else + { + bEndOfSeq = true; + } + return bEndOfSeq; +} + +auto CalypStream::getCurrFrameAsset() -> std::shared_ptr +{ + if( d->currentFrame == nullptr ) + { + d->currentFrame = d->frameBuffer->retrieveFrame(); + } + return d->currentFrame; +} + CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image ) { if( pyuv_image == NULL ) @@ -589,25 +617,6 @@ CalypFrame* CalypStream::getCurrFrame() return &d->frameBuffer->currentRead(); } -auto CalypStream::getNextFrame() -> CalypFrame& -{ - CalypFrame& frameToTead = d->frameBuffer->readOneFrame(); - d->readFrame( d->frameBuffer->writeOneFrame() ); - return frameToTead; -} - -auto CalypStream::retrieveNextFrame() -> std::shared_ptr -{ - const std::lock_guard lock( d->mutex ); - - if( d->iCurrFrameNum + 1 < (long)( d->handler->m_uiTotalNumberFrames ) ) - { - d->iCurrFrameNum++; - return d->frameBuffer->retrieveFrame(); - } - return nullptr; -} - bool CalypStream::setNextFrame() { bool bEndOfSeq = false; @@ -675,7 +684,6 @@ bool CalypStream::saveFrame( const ClpString& filename, const CalypFrame& saveFr return false; } auxSaveStream.writeFrame( saveFrame ); - auxSaveStream.close(); return true; } @@ -703,6 +711,8 @@ bool CalypStream::seekInputRelative( bool bIsFoward ) bool CalypStream::seekInput( unsigned long new_frame_num ) { + const std::lock_guard lock( d->mutex ); + if( !d->isInit || new_frame_num >= d->handler->m_uiTotalNumberFrames || long( new_frame_num ) == d->iCurrFrameNum ) return false; @@ -719,6 +729,7 @@ bool CalypStream::seekInput( unsigned long new_frame_num ) throw CalypFailure( "CalypStream", "Cannot seek file into desired position" ); } + d->currentFrame = nullptr; d->frameBuffer->reset(); d->readFrame( d->frameBuffer->writeOneFrame() ); if( d->handler->m_uiTotalNumberFrames > 1 ) diff --git a/lib/CalypStream.h b/lib/CalypStream.h index 1ecb499..a7f7b1a 100644 --- a/lib/CalypStream.h +++ b/lib/CalypStream.h @@ -68,6 +68,10 @@ public: static std::vector stdResolutionSizes(); CalypStream(); + CalypStream( CalypStream&& other ) noexcept = delete; + CalypStream& operator=( CalypStream&& other ) noexcept = delete; + CalypStream( const CalypStream& other ) = delete; + CalypStream& operator=( const CalypStream& other ) = delete; ~CalypStream(); ClpString getFormatName() const; @@ -81,7 +85,6 @@ public: bool bInput ); bool reload(); - void close(); bool isNative() const; ClpString getFileName() const; @@ -97,14 +100,13 @@ public: void loadAll(); - CalypFrame* getCurrFrame( CalypFrame* ); - CalypFrame* getCurrFrame(); - // continuous read using smart ptrs - auto retrieveNextFrame() -> std::shared_ptr; + auto retrieveNextFrame() -> bool; + auto getCurrFrameAsset() -> std::shared_ptr; // continuous read control - auto getNextFrame() -> CalypFrame&; + CalypFrame* getCurrFrame( CalypFrame* ); + CalypFrame* getCurrFrame(); bool setNextFrame(); void readNextFrame(); void readNextFrameFillRGBBuffer(); diff --git a/tools/CalypTools.cpp b/tools/CalypTools.cpp index c8d3021..2ad8aa6 100644 --- a/tools/CalypTools.cpp +++ b/tools/CalypTools.cpp @@ -45,17 +45,7 @@ CalypTools::CalypTools() m_pcCurrModuleIf = NULL; } -CalypTools::~CalypTools() -{ - for( unsigned int i = 0; i < m_apcInputStreams.size(); i++ ) - { - m_apcInputStreams[i]->close(); - } - for( unsigned int i = 0; i < m_apcOutputStreams.size(); i++ ) - { - m_apcOutputStreams[i]->close(); - } -} +CalypTools::~CalypTools() = default; #define GET_PARAM( X, i ) X[X.size() > i ? i : X.size() - 1]