diff --git a/app/CalypAppModuleIf.cpp b/app/CalypAppModuleIf.cpp index c8abd5b..14c10e7 100644 --- a/app/CalypAppModuleIf.cpp +++ b/app/CalypAppModuleIf.cpp @@ -74,19 +74,19 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads ) bool bRet = false; QApplication::setOverrideCursor( Qt::WaitCursor ); - if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) - { - if( m_pcDisplaySubWindow ) - { - m_pcDisplaySubWindow->setFillWindow( true ); - } - else - { - m_pcSubWindow[0]->setFillWindow( true ); - } - } if( !( isPlaying && ( m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY ) ) ) { + if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) + { + if( m_pcDisplaySubWindow ) + { + m_pcDisplaySubWindow->setFillWindow( true ); + } + else + { + m_pcSubWindow[0]->setFillWindow( true ); + } + } #ifdef CALYP_THREADED_MODULES if( !disableThreads ) { @@ -123,27 +123,27 @@ void CalypAppModuleIf::run() apcFrameList.push_back( m_pcSubWindow[i]->getCurrFrame() ); } - if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) + if( m_pcModule->m_iModuleAPI == CLP_MODULE_API_1 ) { - if( m_pcModule->m_iModuleAPI == CLP_MODULE_API_2 ) + if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) + { + m_pcProcessedFrame = m_pcModule->process( apcFrameList[0] ); + } + else if( m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE ) + { + m_dMeasurementResult = m_pcModule->measure( apcFrameList[0] ); + } + } + else if( m_pcModule->m_iModuleAPI == CLP_MODULE_API_2 ) + { + if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) { m_pcProcessedFrame = m_pcModule->process( apcFrameList ); } - else - { - m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() ); - } - } - else if( m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE ) - { - if( m_pcModule->m_iModuleAPI == CLP_MODULE_API_2 ) + else if( m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE ) { m_dMeasurementResult = m_pcModule->measure( apcFrameList ); } - else - { - m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame() ); - } } else { diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index f2ebef4..4c7933c 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -325,9 +325,9 @@ void ModulesHandle::activateModule() } } } + // Check for same fmt in more than one frame modules if( pcCurrAppModuleIf->m_pcModule->m_iModuleAPI == CLP_MODULE_API_1 ) { - // Check for same fmt in more than one frame modules for( int i = 1; i < videoSubWindowList.size(); i++ ) { if( !videoSubWindowList.at( i )->getCurrFrame()->haveSameFmt( videoSubWindowList.at( 0 )->getCurrFrame() ) ) @@ -369,28 +369,30 @@ void ModulesHandle::activateModule() } } - bool bShowModulesNewWindow = m_arrayActions[FORCE_NEW_WINDOW_ACT]->isChecked() | bTmpForceNewWindow; + bool bRequiresWindow = ( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_NEW_WINDOW ) || + m_arrayActions[FORCE_NEW_WINDOW_ACT]->isChecked() || + bTmpForceNewWindow; + + bool bRequiresDock = ( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE ); QString windowName; - VideoSubWindow* pcModuleSubWindow = NULL; - if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) + + if( bRequiresWindow ) { - if( ( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) - { - pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW ); - windowName.append( QStringLiteral( "Module " ) ); - windowName.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleName ); - pcCurrAppModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow; - // connect( pcModuleSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo, - // SLOT( updateSelectionArea( QRect ) ) ); - // connect( pcModuleSubWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_appModuleVideo, - // SLOT( zoomToFactorAll( double, QPoint ) ) ); - // connect( pcModuleSubWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), m_appModuleVideo, - // SLOT( moveAllScrollBars( const QPoint ) ) ); - } + pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW ); + windowName.append( QStringLiteral( "Module " ) ); + windowName.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleName ); + pcCurrAppModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow; + // connect( pcModuleSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo, + // SLOT( updateSelectionArea( QRect ) ) ); + // connect( pcModuleSubWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_appModuleVideo, + // SLOT( zoomToFactorAll( double, QPoint ) ) ); + // connect( pcModuleSubWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), m_appModuleVideo, + // SLOT( moveAllScrollBars( const QPoint ) ) ); } - else if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE ) + + if( bRequiresDock ) { pcCurrAppModuleIf->m_pcDisplaySubWindow = NULL; pcCurrAppModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrAppModuleIf ); @@ -420,20 +422,24 @@ void ModulesHandle::activateModule() } } + std::vector apcFrameList; + for( int i = 0; i < videoSubWindowList.size(); i++ ) + { + apcFrameList.push_back( pcCurrAppModuleIf->m_pcSubWindow[i]->getCurrFrame() ); + } + // Create Module bool moduleCreated = false; - if( pcCurrAppModuleIf->m_pcModule->m_iModuleAPI == CLP_MODULE_API_2 ) + if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_STREAM_PROCESSING_MODULE ) + { + } + else if( pcCurrAppModuleIf->m_pcModule->m_iModuleAPI == CLP_MODULE_API_2 ) { - std::vector apcFrameList; - for( int i = 0; i < videoSubWindowList.size(); i++ ) - { - apcFrameList.push_back( pcCurrAppModuleIf->m_pcSubWindow[i]->getCurrFrame() ); - } moduleCreated = pcCurrAppModuleIf->m_pcModule->create( apcFrameList ); } else if( pcCurrAppModuleIf->m_pcModule->m_iModuleAPI == CLP_MODULE_API_1 ) { - pcCurrAppModuleIf->m_pcModule->create( pcCurrAppModuleIf->m_pcSubWindow[0]->getCurrFrame() ); + pcCurrAppModuleIf->m_pcModule->create( apcFrameList[0] ); moduleCreated = true; } diff --git a/lib/CalypModuleIf.h b/lib/CalypModuleIf.h index 4ad2cdb..5ad1e51 100644 --- a/lib/CalypModuleIf.h +++ b/lib/CalypModuleIf.h @@ -36,6 +36,7 @@ #include "CalypFrame.h" #include "CalypOptions.h" +#include "CalypStream.h" #define REGISTER_CLASS_MAKER( X ) \ extern "C" CalypModuleIf* Maker() { return new X; } @@ -70,6 +71,7 @@ enum Module_Type { CLP_FRAME_PROCESSING_MODULE, CLP_FRAME_MEASUREMENT_MODULE, + CLP_STREAM_PROCESSING_MODULE, CLP_MODULE_TYPE_MAX = 255, }; @@ -144,11 +146,14 @@ public: /** * Module API version 2 */ - virtual bool create( std::vector apcFrameList ) { return false; } + virtual bool create( std::vector ) { return false; } virtual CalypFrame* process( std::vector ) { return NULL; } virtual double measure( std::vector ) { return 0; } virtual bool keyPressed( enum Module_Key_Supported ) { return false; } virtual ClpString moduleInfo() { return ClpString(); } + + virtual bool create( std::vector ) { return false; }; + virtual CalypStream* process( std::vector ) { return NULL; } }; #endif // __CALYPMODULESIF_H__ diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index b427985..87c5a56 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -42,6 +42,10 @@ ADD_MODULE_USE_OPENCV( SaliencyDetectionSpectral "SaliencyDetection" VERSION 3.3 ADD_MODULE_USE_OPENCV( SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) ADD_MODULE_USE_OPENCV( SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) +IF( USE_FFMPEG ) + ADD_MODULE( StreamCodingH264 "StreamCodingH264" ) +ENDIF() + # # Create header and auxiliar files @@ -49,7 +53,7 @@ ADD_MODULE_USE_OPENCV( SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSI CREATE_MODULE_MACROS() INCLUDE_DIRECTORIES( ${OpenCV_INCLUDE_DIRS} ) ADD_LIBRARY( CalypModules ${Calyp_Mod_SRCS} ) -TARGET_LINK_LIBRARIES( CalypModules ${PROJECT_LIBRARY} ${OpenCV_LIBRARIES} ) +TARGET_LINK_LIBRARIES( CalypModules ${PROJECT_LIBRARY} ${OpenCV_LIBRARIES} ${FFMPEG_LIBRARIES} ) IF( USE_DYNLOAD ) TARGET_LINK_LIBRARIES( CalypModules -ldl ) ENDIF() diff --git a/modules/StreamCodingH264.cpp b/modules/StreamCodingH264.cpp new file mode 100644 index 0000000..d3625a3 --- /dev/null +++ b/modules/StreamCodingH264.cpp @@ -0,0 +1,58 @@ +/* This file is a part of Calyp project + * Copyright (C) 2014-2018 by Joao Carreira (jfmcarreira@gmail.com) + * Luis Lucas (luisfrlucas@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 StreamCodingH264.cpp + * \brief Compress a stream using H.264 + */ + +#include "StreamCodingH264.h" + +StreamCodingH264::StreamCodingH264() +{ + /* Module Definition */ + m_iModuleAPI = CLP_MODULE_API_2; + m_iModuleType = CLP_STREAM_PROCESSING_MODULE; + m_pchModuleCategory = "Video Coding"; + m_pchModuleLongName = "H.264/AVC"; + m_pchModuleName = "H264StreamCoding"; + m_pchModuleTooltip = "Encode video stream using H.264/AVC standard (libx264)"; + m_uiNumberOfFrames = 2; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS | CLP_MODULE_REQUIRES_NEW_WINDOW; + + m_cModuleOptions.addOptions() /**/ + ( "QP", m_iCRF, "Quantization parameter" ); + + m_pcProcessedFrame = NULL; + m_iCRF = 23; +} + +bool StreamCodingH264::create( std::vector apcStreamList ) +{ + return false; +} + +CalypStream* StreamCodingH264::process( std::vector apcStreamList ) +{ + return NULL; +} + +void StreamCodingH264::destroy() +{ +} diff --git a/modules/StreamCodingH264.h b/modules/StreamCodingH264.h new file mode 100644 index 0000000..58fc6b6 --- /dev/null +++ b/modules/StreamCodingH264.h @@ -0,0 +1,47 @@ +/* This file is a part of Calyp project + * Copyright (C) 2014-2018 by Joao Carreira (jfmcarreira@gmail.com) + * Luis Lucas (luisfrlucas@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 StreamCodingH264.h + * \brief Compress a stream using H.264 + */ + +#ifndef __STREAMCODINGH264_H__ +#define __STREAMCODINGH264_H__ + +// CalypLib +#include "lib/CalypModuleIf.h" + +class StreamCodingH264 : public CalypModuleIf +{ + REGISTER_CLASS_FACTORY( StreamCodingH264 ) + +private: + CalypFrame* m_pcProcessedFrame; + int m_iCRF; + +public: + StreamCodingH264(); + virtual ~StreamCodingH264() {} + bool create( std::vector apcStreamList ); + CalypStream* process( std::vector apcFrameList ); + void destroy(); +}; + +#endif // __STREAMCODINGH264_H__