diff --git a/CMakeLists.txt b/CMakeLists.txt index ea744ae..8aaa4ed 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/config.h.in b/config.h.in index b7bf1c6..13bc617 100644 --- a/config.h.in +++ b/config.h.in @@ -36,6 +36,8 @@ #define QT_VERSION_PLAYUVER 4 #endif +#cmakedefine PLAYUVER_THREADED_MODULES + /* OpenCV */ #cmakedefine USE_OPENCV diff --git a/source/app/ModulesHandle.cpp b/source/app/ModulesHandle.cpp index ce1f8af..f8c8a70 100644 --- a/source/app/ModulesHandle.cpp +++ b/source/app/ModulesHandle.cpp @@ -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 ) diff --git a/source/app/ModulesHandle.h b/source/app/ModulesHandle.h index d22e032..d363f58 100644 --- a/source/app/ModulesHandle.h +++ b/source/app/ModulesHandle.h @@ -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 ); diff --git a/source/app/PlaYUVerModuleIf.cpp b/source/app/PlaYUVerModuleIf.cpp new file mode 100644 index 0000000..8d81381 --- /dev/null +++ b/source/app/PlaYUVerModuleIf.cpp @@ -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 + diff --git a/source/app/PlaYUVerModuleIf.h b/source/app/PlaYUVerModuleIf.h index 28ceb52..55327ca 100644 --- a/source/app/PlaYUVerModuleIf.h +++ b/source/app/PlaYUVerModuleIf.h @@ -31,13 +31,12 @@ #include #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 diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 032d015..2198288 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -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. diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index d6c7e29..939fb38 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -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() )