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_QTDBUS "Build with QtDBus" ON)
|
||||||
OPTION(USE_FERVOR "Add Fervor support" OFF)
|
OPTION(USE_FERVOR "Add Fervor support" OFF)
|
||||||
|
OPTION(USE_RESOURCES "Handle streams in separate threads" ON)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(external)
|
ADD_SUBDIRECTORY(external)
|
||||||
|
|
||||||
|
|||||||
@@ -225,7 +225,6 @@ void CalypAppModuleIf::destroy()
|
|||||||
}
|
}
|
||||||
if( m_pcModuleStream )
|
if( m_pcModuleStream )
|
||||||
{
|
{
|
||||||
m_pcModuleStream->close();
|
|
||||||
delete m_pcModuleStream;
|
delete m_pcModuleStream;
|
||||||
m_pcModuleStream = NULL;
|
m_pcModuleStream = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-35
@@ -44,13 +44,29 @@ void ResourceWorker::stop()
|
|||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceWorker::wake()
|
||||||
|
{
|
||||||
|
m_Mutex.lock();
|
||||||
|
m_ResourceIdle.wakeAll();
|
||||||
|
m_Mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void ResourceWorker::run()
|
void ResourceWorker::run()
|
||||||
{
|
{
|
||||||
|
// Loop forever
|
||||||
while( !m_bStop )
|
while( !m_bStop )
|
||||||
{
|
{
|
||||||
m_pcStream->readNextFrameFillRGBBuffer();
|
m_pcStream->readNextFrameFillRGBBuffer();
|
||||||
|
if( !m_pcStream->hasWritingSlot() )
|
||||||
|
{
|
||||||
|
m_Mutex.lock();
|
||||||
|
m_ResourceIdle.wait( &m_Mutex );
|
||||||
|
m_Mutex.unlock();
|
||||||
|
}
|
||||||
while( !m_bStop && !m_pcStream->hasWritingSlot() )
|
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 newStreamResource = std::make_shared<CalypStream>();
|
||||||
auto newStreamResourceWorker = std::make_unique<ResourceWorker>( newStreamResource );
|
auto newStreamResourceWorker = std::make_unique<ResourceWorker>( newStreamResource );
|
||||||
CalypStream* ptr = newStreamResource.get();
|
|
||||||
|
|
||||||
m_apcStreamResourcesList.push_back( newStreamResource );
|
m_apcStreamResourcesList.push_back( newStreamResource );
|
||||||
m_apcStreamResourcesWorkersList.push_back( std::move( newStreamResourceWorker ) );
|
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 )
|
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 )
|
if( m_apcStreamResourcesList[i].get() == ptr )
|
||||||
return resource_ptr.get();
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return addResource();
|
return addResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceHandle::removeResource( CalypStream* ptr )
|
auto ResourceHandle::getResourceAsset( std::size_t id ) -> CalypStream*
|
||||||
{
|
{
|
||||||
std::optional<std::size_t> posToRemove;
|
if( id < m_apcStreamResourcesList.size() )
|
||||||
for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ )
|
|
||||||
{
|
{
|
||||||
if( m_apcStreamResourcesList[i].get() == ptr )
|
return m_apcStreamResourcesList[id].get();
|
||||||
{
|
|
||||||
posToRemove = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( !posToRemove.has_value() )
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceHandle::removeResource( std::size_t id )
|
||||||
|
{
|
||||||
|
if( id >= m_apcStreamResourcesList.size() )
|
||||||
{
|
{
|
||||||
assert( false );
|
assert( false );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove worker first
|
// Remove worker first
|
||||||
m_apcStreamResourcesWorkersList[*posToRemove]->stop();
|
m_apcStreamResourcesWorkersList[id]->stop();
|
||||||
m_apcStreamResourcesWorkersList.erase( m_apcStreamResourcesWorkersList.begin() + *posToRemove );
|
m_apcStreamResourcesWorkersList.erase( m_apcStreamResourcesWorkersList.begin() + id );
|
||||||
|
|
||||||
// Then the underlying stream
|
// 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;
|
if( id >= m_apcStreamResourcesList.size() )
|
||||||
for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ )
|
|
||||||
{
|
|
||||||
if( m_apcStreamResourcesList[i].get() == ptr )
|
|
||||||
{
|
|
||||||
position = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !position.has_value() )
|
|
||||||
{
|
{
|
||||||
assert( false );
|
assert( false );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_apcStreamResourcesWorkersList[*position]->setObjectName(
|
m_apcStreamResourcesWorkersList[id]->setObjectName(
|
||||||
"RW-" +
|
"RW-" +
|
||||||
QFileInfo( QString::fromStdString( m_apcStreamResourcesList[*position]->getFileName() ) ).completeBaseName() );
|
QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() );
|
||||||
m_apcStreamResourcesWorkersList[*position]->start();
|
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__
|
#ifndef __RESOURCEHANDLE_H__
|
||||||
#define __RESOURCEHANDLE_H__
|
#define __RESOURCEHANDLE_H__
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QWaitCondition>
|
||||||
|
|
||||||
#include "CommonDefs.h"
|
#include "CommonDefs.h"
|
||||||
#include "lib/CalypStream.h"
|
#include "lib/CalypStream.h"
|
||||||
@@ -34,12 +36,15 @@
|
|||||||
class ResourceWorker : public QThread
|
class ResourceWorker : public QThread
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
QMutex m_Mutex;
|
||||||
|
QWaitCondition m_ResourceIdle;
|
||||||
std::shared_ptr<CalypStream> m_pcStream;
|
std::shared_ptr<CalypStream> m_pcStream;
|
||||||
bool m_bStop{ false };
|
bool m_bStop{ false };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ResourceWorker( std::shared_ptr<CalypStream> stream );
|
ResourceWorker( std::shared_ptr<CalypStream> stream );
|
||||||
void stop();
|
void stop();
|
||||||
|
void wake();
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,12 +54,14 @@ public:
|
|||||||
ResourceHandle();
|
ResourceHandle();
|
||||||
~ResourceHandle() = default;
|
~ResourceHandle() = default;
|
||||||
|
|
||||||
auto getResource( CalypStream* ptr ) -> CalypStream*;
|
auto getResource( CalypStream* ptr ) -> std::size_t;
|
||||||
void removeResource( CalypStream* ptr );
|
auto getResourceAsset( std::size_t id ) -> CalypStream*;
|
||||||
void startResourceWorker( CalypStream* ptr );
|
void removeResource( std::size_t id );
|
||||||
|
void startResourceWorker( std::size_t id );
|
||||||
|
void wakeResourceWorker( std::size_t id );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto addResource() -> CalypStream*;
|
auto addResource() -> std::size_t;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<CalypStream>> m_apcStreamResourcesList;
|
std::vector<std::shared_ptr<CalypStream>> m_apcStreamResourcesList;
|
||||||
|
|||||||
+3
-3
@@ -326,8 +326,8 @@ void VideoHandle::update()
|
|||||||
{
|
{
|
||||||
if( m_pcCurrentVideoSubWindow )
|
if( m_pcCurrentVideoSubWindow )
|
||||||
{
|
{
|
||||||
CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream();
|
const CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream();
|
||||||
CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame();
|
const CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame();
|
||||||
|
|
||||||
m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() );
|
m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() );
|
||||||
|
|
||||||
@@ -364,7 +364,7 @@ void VideoHandle::update()
|
|||||||
}
|
}
|
||||||
m_pcResolutionLabel->setText( resolution );
|
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->setTotalFrameNum( total_frame_num );
|
||||||
m_pcFrameNumInfo->setCurrFrameNum( frame_num );
|
m_pcFrameNumInfo->setCurrFrameNum( frame_num );
|
||||||
|
|||||||
+33
-29
@@ -35,8 +35,7 @@
|
|||||||
#include "ResourceHandle.h"
|
#include "ResourceHandle.h"
|
||||||
#include "SubWindowAbstract.h"
|
#include "SubWindowAbstract.h"
|
||||||
|
|
||||||
//#define QT_NO_CONCURRENT
|
#define QT_NO_CONCURRENT
|
||||||
//#define USE_CALYPSTREAM_RETRIEVE
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Functions to control data stream from stream information
|
* \brief Functions to control data stream from stream information
|
||||||
@@ -200,7 +199,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget*
|
|||||||
VideoSubWindow::~VideoSubWindow()
|
VideoSubWindow::~VideoSubWindow()
|
||||||
{
|
{
|
||||||
disableModule();
|
disableModule();
|
||||||
m_pcResourceManager->removeResource( m_pCurrStream );
|
m_pcResourceManager->removeResource( m_uiResourceId );
|
||||||
//delete m_cViewArea;
|
//delete m_cViewArea;
|
||||||
delete m_pcUpdateTimer;
|
delete m_pcUpdateTimer;
|
||||||
}
|
}
|
||||||
@@ -331,7 +330,9 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
|
|||||||
if( m_pCurrStream )
|
if( m_pCurrStream )
|
||||||
m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
|
m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
|
||||||
else
|
else
|
||||||
m_pCurrStream = m_pcResourceManager->getResource( nullptr );
|
m_uiResourceId = m_pcResourceManager->getResource( nullptr );
|
||||||
|
|
||||||
|
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
|
||||||
|
|
||||||
bool bConfig = true;
|
bool bConfig = true;
|
||||||
if( !bForceDialog )
|
if( !bForceDialog )
|
||||||
@@ -384,8 +385,8 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
|
|||||||
var.setValue<unsigned int>( BitsPel );
|
var.setValue<unsigned int>( BitsPel );
|
||||||
appSettings.setValue( "VideoSubWindow/LastBitsPerPixel", var );
|
appSettings.setValue( "VideoSubWindow/LastBitsPerPixel", var );
|
||||||
|
|
||||||
#ifdef USE_CALYPSTREAM_RETRIEVE
|
#ifdef USE_RESOURCES
|
||||||
m_pcResourceManager->startResourceWorker( m_pCurrStream );
|
m_pcResourceManager->startResourceWorker( m_uiResourceId );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
@@ -404,7 +405,8 @@ bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo )
|
|||||||
{
|
{
|
||||||
assert( m_pcResourceManager != nullptr );
|
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,
|
if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight,
|
||||||
streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness,
|
streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness,
|
||||||
@@ -415,8 +417,8 @@ bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo )
|
|||||||
|
|
||||||
m_sStreamInfo = *streamInfo;
|
m_sStreamInfo = *streamInfo;
|
||||||
|
|
||||||
#ifdef USE_CALYPSTREAM_RETRIEVE
|
#ifdef USE_RESOURCES
|
||||||
m_pcResourceManager->startResourceWorker( m_pCurrStream );
|
m_pcResourceManager->startResourceWorker( m_uiResourceId );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
@@ -728,16 +730,22 @@ void VideoSubWindow::setCurrFrame( CalypFrame* pcCurrFrame )
|
|||||||
m_cViewArea->setImage( m_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()
|
void VideoSubWindow::refreshFrameOperation()
|
||||||
{
|
{
|
||||||
bool bSetFrame = false;
|
bool bSetFrame = false;
|
||||||
if( m_pcCurrStreamFrame != nullptr )
|
if( m_pCurrStream )
|
||||||
{
|
|
||||||
m_pcCurrFrame = m_pcCurrStreamFrame.get();
|
|
||||||
}
|
|
||||||
else if( m_pCurrStream )
|
|
||||||
{
|
{
|
||||||
|
#ifdef USE_RESOURCES
|
||||||
|
m_pcCurrFrame = m_pCurrStream->getCurrFrameAsset().get();
|
||||||
|
#else
|
||||||
m_pcCurrFrame = m_pCurrStream->getCurrFrame();
|
m_pcCurrFrame = m_pCurrStream->getCurrFrame();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
bSetFrame = m_pcCurrFrame ? true : false;
|
bSetFrame = m_pcCurrFrame ? true : false;
|
||||||
if( m_pcCurrentDisplayModule )
|
if( m_pcCurrentDisplayModule )
|
||||||
@@ -773,12 +781,13 @@ void VideoSubWindow::refreshFrame( bool bThreaded )
|
|||||||
|
|
||||||
bool VideoSubWindow::goToNextFrame( bool bThreaded )
|
bool VideoSubWindow::goToNextFrame( bool bThreaded )
|
||||||
{
|
{
|
||||||
#ifdef USE_CALYPSTREAM_RETRIEVE
|
#ifdef USE_RESOURCES
|
||||||
m_pcCurrStreamFrame = m_pCurrStream->retrieveNextFrame();
|
bool bEndOfSeq = m_pCurrStream->retrieveNextFrame();
|
||||||
if( m_pcCurrStreamFrame == nullptr )
|
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
|
||||||
return true;
|
if( !bEndOfSeq )
|
||||||
refreshFrame();
|
{
|
||||||
return false;
|
refreshFrame();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef QT_NO_CONCURRENT
|
#ifndef QT_NO_CONCURRENT
|
||||||
m_cRefreshResult.waitForFinished();
|
m_cRefreshResult.waitForFinished();
|
||||||
@@ -801,8 +810,8 @@ bool VideoSubWindow::goToNextFrame( bool bThreaded )
|
|||||||
m_pCurrStream->readNextFrameFillRGBBuffer();
|
m_pCurrStream->readNextFrameFillRGBBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bEndOfSeq;
|
|
||||||
#endif
|
#endif
|
||||||
|
return bEndOfSeq;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoSubWindow::save( QString filename )
|
bool VideoSubWindow::save( QString filename )
|
||||||
@@ -887,7 +896,7 @@ void VideoSubWindow::pause()
|
|||||||
|
|
||||||
void VideoSubWindow::seekAbsoluteEvent( unsigned int new_frame_num )
|
void VideoSubWindow::seekAbsoluteEvent( unsigned int new_frame_num )
|
||||||
{
|
{
|
||||||
m_pcCurrStreamFrame = nullptr;
|
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
|
||||||
if( m_pCurrStream )
|
if( m_pCurrStream )
|
||||||
if( m_pCurrStream->seekInput( new_frame_num ) )
|
if( m_pCurrStream->seekInput( new_frame_num ) )
|
||||||
refreshFrame();
|
refreshFrame();
|
||||||
@@ -904,14 +913,9 @@ void VideoSubWindow::seekRelativeEvent( bool bIsFoward )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_pcCurrStreamFrame = nullptr;
|
|
||||||
bRefresh = m_pCurrStream->seekInputRelative( bIsFoward );
|
bRefresh = m_pCurrStream->seekInputRelative( bIsFoward );
|
||||||
#ifdef USE_CALYPSTREAM_RETRIEVE
|
#ifdef USE_RESOURCES
|
||||||
if( bRefresh )
|
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
|
||||||
{
|
|
||||||
m_pcCurrStreamFrame = m_pCurrStream->retrieveNextFrame();
|
|
||||||
bRefresh &= m_pcCurrStreamFrame != nullptr;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,9 @@ private:
|
|||||||
QString m_cFilename;
|
QString m_cFilename;
|
||||||
QString m_cStreamInformation;
|
QString m_cStreamInformation;
|
||||||
CalypFileInfo m_sStreamInfo;
|
CalypFileInfo m_sStreamInfo;
|
||||||
|
std::size_t m_uiResourceId;
|
||||||
CalypStream* m_pCurrStream;
|
CalypStream* m_pCurrStream;
|
||||||
std::shared_ptr<CalypFrame> m_pcCurrStreamFrame;
|
std::shared_ptr<CalypFrame> m_pcCurrDisplayFrame;
|
||||||
|
|
||||||
CalypFrame* m_pcCurrFrame;
|
CalypFrame* m_pcCurrFrame;
|
||||||
QRect m_cSelectedArea;
|
QRect m_cSelectedArea;
|
||||||
@@ -139,12 +140,14 @@ public:
|
|||||||
void seekRelativeEvent( bool bIsFoward );
|
void seekRelativeEvent( bool bIsFoward );
|
||||||
|
|
||||||
void setCurrFrame( CalypFrame* pcCurrFrame );
|
void setCurrFrame( CalypFrame* pcCurrFrame );
|
||||||
|
void setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame );
|
||||||
|
|
||||||
CalypFileInfo getStreamInfo() { return m_sStreamInfo; }
|
CalypFileInfo getStreamInfo() { return m_sStreamInfo; }
|
||||||
QString getStreamInformation() { return m_cStreamInformation; }
|
QString getStreamInformation() { return m_cStreamInformation; }
|
||||||
CalypStream* getInputStream() { return m_pCurrStream; }
|
const CalypStream* getInputStream() { return m_pCurrStream; }
|
||||||
CalypStream* getCurrStream() { return m_pCurrStream; }
|
const CalypStream* getCurrStream() { return m_pCurrStream; }
|
||||||
CalypFrame* getCurrFrame() { return m_pcCurrFrame; }
|
CalypFrame* getCurrFrame() { return m_pcCurrFrame; }
|
||||||
|
std::shared_ptr<CalypFrame> getCurrFrameAsset() { return m_pCurrStream->getCurrFrameAsset(); };
|
||||||
ViewArea* getViewArea() { return m_cViewArea; }
|
ViewArea* getViewArea() { return m_cViewArea; }
|
||||||
void setRefSubWindow( VideoSubWindow* subWindow )
|
void setRefSubWindow( VideoSubWindow* subWindow )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "lib/CalypStream.h"
|
#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()
|
: QDialog( parent, Qt::Dialog | Qt::WindowTitleHint ), m_iSelectedFrameNum()
|
||||||
{
|
{
|
||||||
m_iSelectedFrameNum = pcCurrStream->getCurrFrameNum();
|
m_iSelectedFrameNum = pcCurrStream->getCurrFrameNum();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class SeekStreamDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SeekStreamDialog( CalypStream* pcCurrStream, QWidget* parent = 0 );
|
SeekStreamDialog( const CalypStream* pcCurrStream, QWidget* parent = 0 );
|
||||||
int runDialog();
|
int runDialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ void FramePropertiesDock::reset()
|
|||||||
setEnabled( false );
|
setEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
|
void FramePropertiesDock::setFrame( std::shared_ptr<CalypFrame> pcFrame, bool isPlaying )
|
||||||
{
|
{
|
||||||
int colorSpace = pcFrame->getColorSpace();
|
int colorSpace = pcFrame->getColorSpace();
|
||||||
if( m_iLastFrameType != colorSpace )
|
if( m_iLastFrameType != colorSpace )
|
||||||
@@ -365,7 +365,7 @@ void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
|
|||||||
if( pcFrame )
|
if( pcFrame )
|
||||||
{
|
{
|
||||||
m_bHasFrame = true;
|
m_bHasFrame = true;
|
||||||
m_pcFrame = std::make_shared<CalypFrame>( *pcFrame );
|
m_pcFrame = pcFrame;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
QSize sizeHint() const;
|
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 setSelection( const QRect& selectionArea );
|
||||||
void reset();
|
void reset();
|
||||||
void stopHistogram();
|
void stopHistogram();
|
||||||
|
|||||||
@@ -55,4 +55,7 @@
|
|||||||
/* Fervor update lib */
|
/* Fervor update lib */
|
||||||
#cmakedefine USE_FERVOR
|
#cmakedefine USE_FERVOR
|
||||||
|
|
||||||
|
/* Use a resource manager to manage streams in different threads */
|
||||||
|
#cmakedefine USE_RESOURCES
|
||||||
|
|
||||||
#endif // __CONFIG_CALYP_H__
|
#endif // __CONFIG_CALYP_H__
|
||||||
+43
-32
@@ -211,6 +211,7 @@ public:
|
|||||||
CreateStreamHandlerFn pfctCreateHandler;
|
CreateStreamHandlerFn pfctCreateHandler;
|
||||||
|
|
||||||
std::unique_ptr<CalypStreamBufferPrivate> frameBuffer;
|
std::unique_ptr<CalypStreamBufferPrivate> frameBuffer;
|
||||||
|
std::shared_ptr<CalypFrame> currentFrame;
|
||||||
|
|
||||||
ClpString cFilename;
|
ClpString cFilename;
|
||||||
long long int iCurrFrameNum;
|
long long int iCurrFrameNum;
|
||||||
@@ -369,7 +370,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
|
|||||||
{
|
{
|
||||||
if( d->isInit )
|
if( d->isInit )
|
||||||
{
|
{
|
||||||
close();
|
d->close();
|
||||||
}
|
}
|
||||||
d->isInit = false;
|
d->isInit = false;
|
||||||
d->isInput = bInput;
|
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 ) )
|
if( !d->handler->openHandler( d->cFilename, d->isInput ) )
|
||||||
{
|
{
|
||||||
close();
|
d->close();
|
||||||
return d->isInit;
|
return d->isInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 )
|
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" );
|
//throw CalypFailure( "CalypStream", "Incorrect configuration: width, height or pixel format" );
|
||||||
return d->isInit;
|
return d->isInit;
|
||||||
}
|
}
|
||||||
@@ -419,7 +420,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
|
|||||||
}
|
}
|
||||||
catch( CalypFailure& e )
|
catch( CalypFailure& e )
|
||||||
{
|
{
|
||||||
close();
|
d->close();
|
||||||
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer" );
|
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer" );
|
||||||
return d->isInit;
|
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 )
|
if( d->isInput && d->handler->m_uiTotalNumberFrames == 0 )
|
||||||
{
|
{
|
||||||
close();
|
d->close();
|
||||||
throw CalypFailure( "CalypStream", "Incorrect configuration: less than one frame" );
|
throw CalypFailure( "CalypStream", "Incorrect configuration: less than one frame" );
|
||||||
return d->isInit;
|
return d->isInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !d->handler->configureBuffer( d->frameBuffer->ref() ) )
|
if( !d->handler->configureBuffer( d->frameBuffer->ref() ) )
|
||||||
{
|
{
|
||||||
close();
|
d->close();
|
||||||
throw CalypFailure( "CalypStream", "Cannot allocated buffers" );
|
throw CalypFailure( "CalypStream", "Cannot allocated buffers" );
|
||||||
return d->isInit;
|
return d->isInit;
|
||||||
}
|
}
|
||||||
@@ -479,11 +480,6 @@ bool CalypStream::reload()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalypStream::close()
|
|
||||||
{
|
|
||||||
d->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
ClpString CalypStream::getFileName() const
|
ClpString CalypStream::getFileName() const
|
||||||
{
|
{
|
||||||
return d->cFilename;
|
return d->cFilename;
|
||||||
@@ -562,7 +558,7 @@ void CalypStream::loadAll()
|
|||||||
}
|
}
|
||||||
catch( CalypFailure& e )
|
catch( CalypFailure& e )
|
||||||
{
|
{
|
||||||
close();
|
d->close();
|
||||||
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer for the whole stream" );
|
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer for the whole stream" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,6 +571,38 @@ void CalypStream::loadAll()
|
|||||||
d->iCurrFrameNum = 0;
|
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 )
|
CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image )
|
||||||
{
|
{
|
||||||
if( pyuv_image == NULL )
|
if( pyuv_image == NULL )
|
||||||
@@ -589,25 +617,6 @@ CalypFrame* CalypStream::getCurrFrame()
|
|||||||
return &d->frameBuffer->currentRead();
|
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 CalypStream::setNextFrame()
|
||||||
{
|
{
|
||||||
bool bEndOfSeq = false;
|
bool bEndOfSeq = false;
|
||||||
@@ -675,7 +684,6 @@ bool CalypStream::saveFrame( const ClpString& filename, const CalypFrame& saveFr
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auxSaveStream.writeFrame( saveFrame );
|
auxSaveStream.writeFrame( saveFrame );
|
||||||
auxSaveStream.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,6 +711,8 @@ bool CalypStream::seekInputRelative( bool bIsFoward )
|
|||||||
|
|
||||||
bool CalypStream::seekInput( unsigned long new_frame_num )
|
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 )
|
if( !d->isInit || new_frame_num >= d->handler->m_uiTotalNumberFrames || long( new_frame_num ) == d->iCurrFrameNum )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -719,6 +729,7 @@ bool CalypStream::seekInput( unsigned long new_frame_num )
|
|||||||
throw CalypFailure( "CalypStream", "Cannot seek file into desired position" );
|
throw CalypFailure( "CalypStream", "Cannot seek file into desired position" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->currentFrame = nullptr;
|
||||||
d->frameBuffer->reset();
|
d->frameBuffer->reset();
|
||||||
d->readFrame( d->frameBuffer->writeOneFrame() );
|
d->readFrame( d->frameBuffer->writeOneFrame() );
|
||||||
if( d->handler->m_uiTotalNumberFrames > 1 )
|
if( d->handler->m_uiTotalNumberFrames > 1 )
|
||||||
|
|||||||
+8
-6
@@ -68,6 +68,10 @@ public:
|
|||||||
static std::vector<CalypStandardResolution> stdResolutionSizes();
|
static std::vector<CalypStandardResolution> stdResolutionSizes();
|
||||||
|
|
||||||
CalypStream();
|
CalypStream();
|
||||||
|
CalypStream( CalypStream&& other ) noexcept = delete;
|
||||||
|
CalypStream& operator=( CalypStream&& other ) noexcept = delete;
|
||||||
|
CalypStream( const CalypStream& other ) = delete;
|
||||||
|
CalypStream& operator=( const CalypStream& other ) = delete;
|
||||||
~CalypStream();
|
~CalypStream();
|
||||||
|
|
||||||
ClpString getFormatName() const;
|
ClpString getFormatName() const;
|
||||||
@@ -81,7 +85,6 @@ public:
|
|||||||
bool bInput );
|
bool bInput );
|
||||||
|
|
||||||
bool reload();
|
bool reload();
|
||||||
void close();
|
|
||||||
|
|
||||||
bool isNative() const;
|
bool isNative() const;
|
||||||
ClpString getFileName() const;
|
ClpString getFileName() const;
|
||||||
@@ -97,14 +100,13 @@ public:
|
|||||||
|
|
||||||
void loadAll();
|
void loadAll();
|
||||||
|
|
||||||
CalypFrame* getCurrFrame( CalypFrame* );
|
|
||||||
CalypFrame* getCurrFrame();
|
|
||||||
|
|
||||||
// continuous read using smart ptrs
|
// continuous read using smart ptrs
|
||||||
auto retrieveNextFrame() -> std::shared_ptr<CalypFrame>;
|
auto retrieveNextFrame() -> bool;
|
||||||
|
auto getCurrFrameAsset() -> std::shared_ptr<CalypFrame>;
|
||||||
|
|
||||||
// continuous read control
|
// continuous read control
|
||||||
auto getNextFrame() -> CalypFrame&;
|
CalypFrame* getCurrFrame( CalypFrame* );
|
||||||
|
CalypFrame* getCurrFrame();
|
||||||
bool setNextFrame();
|
bool setNextFrame();
|
||||||
void readNextFrame();
|
void readNextFrame();
|
||||||
void readNextFrameFillRGBBuffer();
|
void readNextFrameFillRGBBuffer();
|
||||||
|
|||||||
+1
-11
@@ -45,17 +45,7 @@ CalypTools::CalypTools()
|
|||||||
m_pcCurrModuleIf = NULL;
|
m_pcCurrModuleIf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalypTools::~CalypTools()
|
CalypTools::~CalypTools() = default;
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define GET_PARAM( X, i ) X[X.size() > i ? i : X.size() - 1]
|
#define GET_PARAM( X, i ) X[X.size() > i ? i : X.size() - 1]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user