Improve the use of threads and sleep when not in use
This commit is contained in:
15 files changed
+164
-129
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
@@ -225,7 +225,6 @@ void CalypAppModuleIf::destroy()
|
||||
}
|
||||
if( m_pcModuleStream )
|
||||
{
|
||||
m_pcModuleStream->close();
|
||||
delete m_pcModuleStream;
|
||||
m_pcModuleStream = NULL;
|
||||
}
|
||||
|
||||
+50
-35
@@ -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<CalypStream>();
|
||||
auto newStreamResourceWorker = std::make_unique<ResourceWorker>( 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<std::size_t> 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<std::size_t> 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();
|
||||
}
|
||||
+11
-4
@@ -25,8 +25,10 @@
|
||||
#ifndef __RESOURCEHANDLE_H__
|
||||
#define __RESOURCEHANDLE_H__
|
||||
|
||||
#include <QMutex>
|
||||
#include <QThread>
|
||||
#include <QVector>
|
||||
#include <QWaitCondition>
|
||||
|
||||
#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<CalypStream> m_pcStream;
|
||||
bool m_bStop{ false };
|
||||
|
||||
public:
|
||||
ResourceWorker( std::shared_ptr<CalypStream> 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<std::shared_ptr<CalypStream>> m_apcStreamResourcesList;
|
||||
|
||||
+3
-3
@@ -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 );
|
||||
|
||||
+33
-29
@@ -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<unsigned int>( 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<CalypFrame> 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<CalypFrame> m_pcCurrStreamFrame;
|
||||
std::shared_ptr<CalypFrame> 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<CalypFrame> 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<CalypFrame> getCurrFrameAsset() { return m_pCurrStream->getCurrFrameAsset(); };
|
||||
ViewArea* getViewArea() { return m_cViewArea; }
|
||||
void setRefSubWindow( VideoSubWindow* subWindow )
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -297,7 +297,7 @@ void FramePropertiesDock::reset()
|
||||
setEnabled( false );
|
||||
}
|
||||
|
||||
void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
|
||||
void FramePropertiesDock::setFrame( std::shared_ptr<CalypFrame> 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<CalypFrame>( *pcFrame );
|
||||
m_pcFrame = pcFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
void setFrame( CalypFrame* m_pcFrame, bool isPlaying );
|
||||
void setFrame( std::shared_ptr<CalypFrame> m_pcFrame, bool isPlaying );
|
||||
void setSelection( const QRect& selectionArea );
|
||||
void reset();
|
||||
void stopHistogram();
|
||||
|
||||
@@ -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__
|
||||
+43
-32
@@ -211,6 +211,7 @@ public:
|
||||
CreateStreamHandlerFn pfctCreateHandler;
|
||||
|
||||
std::unique_ptr<CalypStreamBufferPrivate> frameBuffer;
|
||||
std::shared_ptr<CalypFrame> 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<std::mutex> 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<CalypFrame>
|
||||
{
|
||||
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<CalypFrame>
|
||||
{
|
||||
const std::lock_guard<std::mutex> 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<std::mutex> 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 )
|
||||
|
||||
+8
-6
@@ -68,6 +68,10 @@ public:
|
||||
static std::vector<CalypStandardResolution> 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<CalypFrame>;
|
||||
auto retrieveNextFrame() -> bool;
|
||||
auto getCurrFrameAsset() -> std::shared_ptr<CalypFrame>;
|
||||
|
||||
// continuous read control
|
||||
auto getNextFrame() -> CalypFrame&;
|
||||
CalypFrame* getCurrFrame( CalypFrame* );
|
||||
CalypFrame* getCurrFrame();
|
||||
bool setNextFrame();
|
||||
void readNextFrame();
|
||||
void readNextFrameFillRGBBuffer();
|
||||
|
||||
+1
-11
@@ -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]
|
||||
|
||||
|
||||
Reference in new issue
Block a user