Minor fixes in Modules handles and introduction of threads into each module
The modules are applied inside a different thread in order to avoid lag in the main window while processing. This still need further testing A new flag is added to selected if the threads should be used in this purpose
This commit is contained in:
1 parent
13f39eee4b
commit
0fe1cdce48
8 files changed
+169
-52
No files matched your search
+7
-6
@@ -45,11 +45,12 @@ SET( CMAKE_CXX_FLAGS "" )
|
||||
######################################################################################
|
||||
# Variables
|
||||
######################################################################################
|
||||
ADD_OPTION(USE_WERROR "Warnings as errors" OFF )
|
||||
ADD_OPTION(USE_QT4 "Build with QT4" OFF )
|
||||
ADD_OPTION(USE_OPENCV "Add OpenCV support" OFF )
|
||||
ADD_OPTION(USE_PIXFC "Add PIXFC support" OFF )
|
||||
ADD_OPTION(USE_FFMPEG "Add FFMPEG support" OFF )
|
||||
ADD_OPTION(PLAYUVER_WERROR "Warnings as errors" OFF )
|
||||
ADD_OPTION(PLAYUVER_THREADED_MODULES "Warnings as errors" ON )
|
||||
ADD_OPTION(USE_QT4 "Build with QT4" OFF )
|
||||
ADD_OPTION(USE_OPENCV "Add OpenCV support" OFF )
|
||||
ADD_OPTION(USE_PIXFC "Add PIXFC support" OFF )
|
||||
ADD_OPTION(USE_FFMPEG "Add FFMPEG support" OFF )
|
||||
|
||||
######################################################################################
|
||||
# Dependencies
|
||||
@@ -103,7 +104,7 @@ SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )
|
||||
SET( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g" )
|
||||
SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3" )
|
||||
|
||||
IF( USE_WERROR )
|
||||
IF( PLAYUVER_WERROR )
|
||||
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" )
|
||||
ENDIF()
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#define QT_VERSION_PLAYUVER 4
|
||||
#endif
|
||||
|
||||
#cmakedefine PLAYUVER_THREADED_MODULES
|
||||
|
||||
/* OpenCV */
|
||||
#cmakedefine USE_OPENCV
|
||||
|
||||
|
||||
@@ -74,7 +74,6 @@ SubWindowHandle* ModulesHandle::processModuleHandlingOpt()
|
||||
else
|
||||
{
|
||||
destroyModuleIf( pcCurrModuleIf );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -154,6 +153,8 @@ SubWindowHandle* ModulesHandle::enableModuleIf( PlaYUVerModuleIf *pcCurrModuleIf
|
||||
{
|
||||
pcCurrModuleIf->m_pcSubWindow[i]->enableModule( pcCurrModuleIf );
|
||||
}
|
||||
applyModuleIf( pcCurrModuleIf, false );
|
||||
|
||||
return interfaceChild;
|
||||
}
|
||||
|
||||
@@ -186,32 +187,18 @@ Void ModulesHandle::destroyAllModulesIf()
|
||||
|
||||
Bool ModulesHandle::applyModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, Bool isPlaying )
|
||||
{
|
||||
PlaYUVerFrame* processedFrame = NULL;
|
||||
Bool bRet = false;
|
||||
if( !isPlaying || ( isPlaying && pcCurrModuleIf->m_cModuleDef.m_bApplyWhilePlaying ) )
|
||||
{
|
||||
switch( pcCurrModuleIf->m_cModuleDef.m_uiNumberOfFrames )
|
||||
{
|
||||
case MODULE_REQUIRES_ONE_FRAME:
|
||||
processedFrame = pcCurrModuleIf->process( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame() );
|
||||
break;
|
||||
case MODULE_REQUIRES_TWO_FRAMES:
|
||||
processedFrame = pcCurrModuleIf->process( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame(), pcCurrModuleIf->m_pcSubWindow[1]->getCurrFrame() );
|
||||
break;
|
||||
case MODULE_REQUIRES_THREE_FRAMES:
|
||||
processedFrame = pcCurrModuleIf->process( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame(), pcCurrModuleIf->m_pcSubWindow[1]->getCurrFrame(),
|
||||
pcCurrModuleIf->m_pcSubWindow[2]->getCurrFrame() );
|
||||
break;
|
||||
}
|
||||
#ifdef PLAYUVER_THREADED_MODULES
|
||||
pcCurrModuleIf->start();
|
||||
#else
|
||||
pcCurrModuleIf->run();
|
||||
#endif
|
||||
if( pcCurrModuleIf->m_pcDisplaySubWindow )
|
||||
{
|
||||
pcCurrModuleIf->m_pcDisplaySubWindow->setCurrFrame( processedFrame );
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcCurrModuleIf->m_pcSubWindow[0]->setCurrFrame( processedFrame );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -220,6 +207,21 @@ Bool ModulesHandle::applyModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, Bool isPlay
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Bool ModulesHandle::showModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, PlaYUVerFrame* processedFrame )
|
||||
{
|
||||
Bool bRet = false;
|
||||
if( pcCurrModuleIf->m_pcDisplaySubWindow )
|
||||
{
|
||||
pcCurrModuleIf->m_pcDisplaySubWindow->setCurrFrame( processedFrame );
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pcCurrModuleIf->m_pcSubWindow[0]->setCurrFrame( processedFrame );
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Void ModulesHandle::swapModulesWindowsIf( PlaYUVerModuleIf *pcCurrModuleIf )
|
||||
{
|
||||
if( pcCurrModuleIf->m_cModuleDef.m_uiNumberOfFrames == MODULE_REQUIRES_TWO_FRAMES )
|
||||
@@ -230,6 +232,19 @@ Void ModulesHandle::swapModulesWindowsIf( PlaYUVerModuleIf *pcCurrModuleIf )
|
||||
}
|
||||
}
|
||||
|
||||
Void ModulesHandle::customEvent( QEvent *event )
|
||||
{
|
||||
if( !event )
|
||||
{
|
||||
return;
|
||||
}
|
||||
PlaYUVerModuleIf::EventData *eventData = ( PlaYUVerModuleIf::EventData* )event;
|
||||
if( eventData->m_bSuccess )
|
||||
{
|
||||
showModuleIf( eventData->m_pcModule, eventData->m_pcProcessedFrame );
|
||||
}
|
||||
}
|
||||
|
||||
QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar )
|
||||
{
|
||||
PlaYUVerModuleIf* pcCurrModuleIf;
|
||||
@@ -246,6 +261,7 @@ QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar )
|
||||
for( Int i = 0; i < m_pcPlaYUVerModules.size(); i++ )
|
||||
{
|
||||
pcCurrModuleIf = m_pcPlaYUVerModules.at( i );
|
||||
pcCurrModuleIf->setParent( this );
|
||||
|
||||
currSubMenu = NULL;
|
||||
if( pcCurrModuleIf->m_cModuleDef.m_pchModuleCategory )
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
static Void destroyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf );
|
||||
static Bool applyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf, Bool isPlaying = false );
|
||||
static Void swapModulesWindowsIf( PlaYUVerModuleIf *pcCurrModuleIf );
|
||||
static Bool showModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, PlaYUVerFrame* processedFrame );
|
||||
|
||||
private:
|
||||
QWidget *m_pcParent;
|
||||
@@ -89,6 +90,7 @@ private:
|
||||
|
||||
Void appendModule( PlaYUVerModuleIf* pcCurrModuleIf );
|
||||
SubWindowHandle* enableModuleIf( PlaYUVerModuleIf* pcCurrModuleIf );
|
||||
Void customEvent( QEvent *event );
|
||||
|
||||
private Q_SLOTS:
|
||||
void selectModule( int index );
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/* This file is a part of plaYUVer project
|
||||
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
|
||||
* Joao Carreira (jfmcarreira@gmail.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file PlaYUVerModuleIf.cpp
|
||||
* \brief PlaYUVer modules interface
|
||||
*/
|
||||
|
||||
#include "PlaYUVerModuleIf.h"
|
||||
#include "SubWindowHandle.h"
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
PlaYUVerModuleIf::PlaYUVerModuleIf() :
|
||||
m_pcAction( NULL ),
|
||||
m_pcDisplaySubWindow( NULL )
|
||||
{
|
||||
for( Int i = 0; i < MAX_NUMBER_FRAMES; i++ )
|
||||
{
|
||||
m_pcSubWindow[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void PlaYUVerModuleIf::run()
|
||||
{
|
||||
PlaYUVerFrame* pcProcessedFrame;
|
||||
switch( m_cModuleDef.m_uiNumberOfFrames )
|
||||
{
|
||||
case MODULE_REQUIRES_ONE_FRAME:
|
||||
pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame() );
|
||||
break;
|
||||
case MODULE_REQUIRES_TWO_FRAMES:
|
||||
pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() );
|
||||
break;
|
||||
case MODULE_REQUIRES_THREE_FRAMES:
|
||||
pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame(), m_pcSubWindow[2]->getCurrFrame() );
|
||||
break;
|
||||
}
|
||||
postProgress( true, pcProcessedFrame );
|
||||
}
|
||||
|
||||
Void PlaYUVerModuleIf::postProgress( Bool success, PlaYUVerFrame* pcProcessedFrame )
|
||||
{
|
||||
EventData *eventData = new EventData();
|
||||
eventData->m_bSuccess = success;
|
||||
eventData->m_pcProcessedFrame = pcProcessedFrame;
|
||||
eventData->m_pcModule = this;
|
||||
if( parent() )
|
||||
QCoreApplication::postEvent( parent(), eventData );
|
||||
}
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
@@ -31,13 +31,12 @@
|
||||
#include <cstdio>
|
||||
#include "PlaYUVerFrame.h"
|
||||
|
||||
class QImage;
|
||||
class QAction;
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
enum __PlaYUVerModuleTypes
|
||||
enum // Module type
|
||||
{
|
||||
FRAME_LEVEL_MODULE,
|
||||
VIDEO_LEVEL_MODULE,
|
||||
@@ -46,17 +45,15 @@ enum __PlaYUVerModuleTypes
|
||||
#define APPLY_WHILE_PLAYING true
|
||||
#define MAX_NUMBER_FRAMES 3
|
||||
|
||||
enum __PlaYUVerModuleNumberOfFrames
|
||||
enum // Number of frames
|
||||
{
|
||||
// Number of frames
|
||||
MODULE_REQUIRES_ONE_FRAME = 1,
|
||||
MODULE_REQUIRES_TWO_FRAMES = 2,
|
||||
MODULE_REQUIRES_THREE_FRAMES = 3,
|
||||
};
|
||||
|
||||
enum __PlaYUVerModuleRequirements
|
||||
enum // Requirements
|
||||
{
|
||||
// Requirements
|
||||
MODULE_REQUIRES_NOTHING = 0,
|
||||
MODULE_REQUIRES_NEW_WINDOW = 2,
|
||||
MODULE_REQUIRES_SIDEBAR = 4,
|
||||
@@ -72,7 +69,7 @@ enum __PlaYUVerModuleRequirements
|
||||
} \
|
||||
}
|
||||
|
||||
typedef struct __PlaYUVerModuleDefinition
|
||||
typedef struct
|
||||
{
|
||||
Int m_iModuleType;
|
||||
const Char* m_pchModuleCategory;
|
||||
@@ -86,36 +83,57 @@ typedef struct __PlaYUVerModuleDefinition
|
||||
class SubWindowHandle;
|
||||
|
||||
class PlaYUVerModuleIf
|
||||
#ifdef PLAYUVER_THREADED_MODULES
|
||||
: QThread
|
||||
#else
|
||||
: QObject
|
||||
#endif
|
||||
{
|
||||
friend class ModulesHandle;
|
||||
|
||||
private:
|
||||
QAction* m_pcAction;
|
||||
SubWindowHandle* m_pcSubWindow[MAX_NUMBER_FRAMES];
|
||||
SubWindowHandle* m_pcDisplaySubWindow;
|
||||
PlaYUVerModuleDefinition m_cModuleDef;
|
||||
|
||||
Void postProgress( Bool success, PlaYUVerFrame* pcProcessedFrame );
|
||||
public:
|
||||
PlaYUVerModuleIf() :
|
||||
m_pcAction( NULL ),
|
||||
m_pcDisplaySubWindow( NULL )
|
||||
class EventData: public QEvent
|
||||
{
|
||||
for( Int i = 0; i < MAX_NUMBER_FRAMES; i++ )
|
||||
public:
|
||||
EventData() :
|
||||
QEvent( QEvent::User )
|
||||
{
|
||||
m_pcSubWindow[i] = NULL;
|
||||
m_bSuccess = false;
|
||||
m_pcProcessedFrame = NULL;
|
||||
m_pcModule = NULL;
|
||||
}
|
||||
}
|
||||
virtual ~PlaYUVerModuleIf() { }
|
||||
Bool m_bSuccess;
|
||||
PlaYUVerFrame* m_pcProcessedFrame;
|
||||
PlaYUVerModuleIf* m_pcModule;
|
||||
};
|
||||
|
||||
virtual Void create() { }
|
||||
virtual Void create( PlaYUVerFrame* ) { }
|
||||
PlaYUVerModuleIf();
|
||||
virtual ~PlaYUVerModuleIf() {}
|
||||
|
||||
virtual Void process() { }
|
||||
virtual PlaYUVerFrame* process( PlaYUVerFrame* ) { return NULL; }
|
||||
virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame* ) { return NULL; }
|
||||
virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame*, PlaYUVerFrame* ) { return NULL; }
|
||||
|
||||
virtual Void destroy(){ }
|
||||
virtual Void create() {}
|
||||
virtual Void create( PlaYUVerFrame* ) {}
|
||||
|
||||
Void setModuleDefinition( PlaYUVerModuleDefinition def ) { m_cModuleDef = def; }
|
||||
virtual Void process() {}
|
||||
virtual PlaYUVerFrame* process( PlaYUVerFrame* ) { return NULL; }
|
||||
virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame* ) { return NULL; }
|
||||
virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame*, PlaYUVerFrame* ) { return NULL; }
|
||||
|
||||
virtual Void destroy() { }
|
||||
|
||||
//PlaYUVerFrame* getProcessedFrame() { return m_pcProcessedFrame; }
|
||||
|
||||
Void setModuleDefinition( PlaYUVerModuleDefinition def ) { m_cModuleDef = def; }
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
@@ -36,6 +36,7 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) :
|
||||
|
||||
setAttribute( Qt::WA_DeleteOnClose );
|
||||
setBackgroundRole( QPalette::Light );
|
||||
setVisible( false );
|
||||
|
||||
// Create a new scroll area inside the sub-window
|
||||
m_cScrollArea = new QScrollArea( this );
|
||||
@@ -121,7 +122,7 @@ Void SubWindowHandle::enableModule( PlaYUVerModuleIf* select_module )
|
||||
disableModule();
|
||||
}
|
||||
m_pcCurrentModule = select_module;
|
||||
refreshFrame();
|
||||
// refreshFrame();
|
||||
}
|
||||
|
||||
Void SubWindowHandle::disableModule()
|
||||
@@ -148,6 +149,13 @@ Void SubWindowHandle::setCurrFrame( PlaYUVerFrame* pcCurrFrame )
|
||||
{
|
||||
m_pcCurrFrame = pcCurrFrame;
|
||||
m_cViewArea->setImage( m_pcCurrFrame );
|
||||
if( !isVisible() )
|
||||
{
|
||||
show();
|
||||
resize( sizeHint() );
|
||||
zoomToFit();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Void SubWindowHandle::refreshFrame()
|
||||
@@ -390,7 +398,8 @@ QSize SubWindowHandle::sizeHint() const
|
||||
if( m_pcCurrFrame )
|
||||
isize = QSize( m_pcCurrFrame->getWidth() + 50, m_pcCurrFrame->getHeight() + 50 );
|
||||
else
|
||||
isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 );
|
||||
if( m_pCurrStream )
|
||||
isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 );
|
||||
|
||||
// If the SubWindowHandle needs more space that the avaiable, we'll give
|
||||
// to the subwindow a reasonable size preserving the image aspect ratio.
|
||||
|
||||
@@ -245,8 +245,7 @@ Void plaYUVerApp::ModuleHandling( QAction *curr_action )
|
||||
if( interfaceChild )
|
||||
{
|
||||
mdiArea->addSubWindow( interfaceChild );
|
||||
interfaceChild->show();
|
||||
interfaceChild->zoomToFit();
|
||||
|
||||
interfaceChild->getViewArea()->setTool( m_appTool );
|
||||
}
|
||||
if( activeSubWindow() )
|
||||
|
||||
Reference in new issue
Block a user