12 Commits
34 changed files with 185 additions and 206 deletions

No files matched your search

+3
View File
@@ -34,6 +34,9 @@ jobs:
- name: Build without threads
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DCALYP_MANAGED_RESOURCES=OFF -DCALYP_THREADED_MODULES=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build without dependencies
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DUSE_OPENCV=OFF -DUSE_FFMPEG=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
check-tests:
runs-on: ubuntu-latest
steps:
+5 -5
View File
@@ -20,10 +20,10 @@ repos:
entry: cmake -B build
pass_filenames: false
language: system
- id: cmake-build
name: Cmake Build
entry: cmake --build build
pass_filenames: false
language: system
#- id: cmake-build
#name: Cmake Build
#entry: cmake --build build
#pass_filenames: false
#language: system
+2 -21
View File
@@ -18,7 +18,7 @@ SET(PROJECT_LIBRARY
)
SET(CALYP_VERSION_MAJOR "2")
SET(CALYP_VERSION_MINOR "1")
SET(CALYP_VERSION_MINOR "2")
SET(CALYP_VERSION_PATCH "0")
SET(CALYP_VERSION
"${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}"
@@ -104,7 +104,7 @@ SET(UPDATE_CHANNEL
# ####################################################################################################################################################
INCLUDE(FetchContent)
SET(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/deps")
SET(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/deps")
# Doxygen
IF(BUILD_DOC)
@@ -118,24 +118,6 @@ SET_PACKAGE_PROPERTIES(
TYPE OPTIONAL
)
# Type safe
FETCHCONTENT_DECLARE(
type_safe
GIT_REPOSITORY https://github.com/foonathan/type_safe
GIT_TAG v0.2.2
SOURCE_DIR "${CMAKE_BINARY_DIR}/deps/type_safe"
)
SET_PACKAGE_PROPERTIES(
type_safe PROPERTIES
URL "https://github.com/foonathan/type_safe"
DESCRIPTION "Zero overhead abstractions that use the C++ type system to prevent bugs."
TYPE REQUIRED
)
FETCHCONTENT_MAKEAVAILABLE(type_safe)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/deps/type_safe/include/ ${CMAKE_BINARY_DIR}/deps/type_safe/external/debug_assert/)
ADD_DEFINITIONS(-DTYPE_SAFE_ENABLE_ASSERTIONS=0 -DTYPE_SAFE_ENABLE_PRECONDITION_CHECKS=0 -DDEBUG_ASSERT_DISABLE)
# Catch2 and Google Tests
IF(BUILD_TESTS)
FETCHCONTENT_DECLARE(googletest URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip)
@@ -175,7 +157,6 @@ IF(BUILD_TESTS)
)
ENDIF()
# OpenCV
OPTION(USE_OPENCV "Add OpenCV support" ON)
IF(USE_OPENCV)
+1 -1
View File
@@ -131,7 +131,7 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
}
}
if( !( isPlaying && m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::SkipWhilePlaying ) ) )
if( !( isPlaying && m_pcModule->has( ClpModuleFeature::SkipWhilePlaying ) ) )
{
m_frameList.clear();
for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ )
+1 -2
View File
@@ -81,12 +81,11 @@ public:
auto getSubWindowList() const -> const std::vector<VideoSubWindow*>& { return m_pcSubWindow; }
CalypModuleIf* getModule() { return m_pcModule.get(); }
auto getModuleRequirements() const -> ClpModuleFeatures { return m_pcModule->m_uiModuleRequirements; }
auto hasFeature( ClpModuleFeature feature ) const -> bool { return m_pcModule->has( feature ); }
std::string moduleInfo() const { return m_pcModule->moduleInfo(); }
void update( bool isPlaying );
bool apply( bool isPlaying = false, bool disableThreads = false );
bool process();
// void setPlaying( bool isPlaying );
bool isRunning() const;
void show();
void disable();
+1 -1
View File
@@ -69,7 +69,7 @@ void ModuleSubWindow::updateVideoWindowInfo()
}
}
}
if( module_ptr->getModuleRequirements().is_set( ClpModuleFeature::HasInfo ) )
if( module_ptr->hasFeature( ClpModuleFeature::HasInfo ) )
{
QStringList list = QString::fromStdString( module_ptr->moduleInfo() ).split( '\n' );
windowInfoList.append( list );
+8 -9
View File
@@ -100,12 +100,11 @@ void ModulesHandle::buildMenu()
m_pcModulesMenu->clear();
m_pcModulesSubMenuList.clear();
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( ; it != moduleFactoryMap.end(); ++it )
const auto& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
for( auto& [name, create_fct] : moduleFactoryMap )
{
auto pcCurrModuleIf = it->second();
QString ModuleIfinternalName = QString::fromLocal8Bit( it->first );
auto pcCurrModuleIf = create_fct();
QString moduleIfInternalName = QString::fromStdString( name );
QMenu* currSubMenu{ nullptr };
if( pcCurrModuleIf->m_iModuleAPI <= CLP_MODULE_API_2 )
@@ -134,7 +133,7 @@ void ModulesHandle::buildMenu()
moduleTooltip += QString( " | Requires %1 frames" ).arg( pcCurrModuleIf->m_uiNumberOfFrames );
currAction->setStatusTip( moduleTooltip );
currAction->setData( ModuleIfinternalName );
currAction->setData( moduleIfInternalName );
currAction->setCheckable( false );
connect( currAction, &QAction::triggered, this, &ModulesHandle::activateModule );
m_arrayModulesActions.append( currAction );
@@ -283,7 +282,7 @@ void ModulesHandle::activateModule()
{
int minNumFrames = numberOfFrames;
int maxNumFrames = numberOfFrames;
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::VariableNumOfFrames ) )
if( pcCurrAppModuleIf->m_pcModule->has( ClpModuleFeature::VariableNumOfFrames ) )
{
minNumFrames = numberOfFrames;
maxNumFrames = 255;
@@ -356,7 +355,7 @@ void ModulesHandle::activateModule()
pcCurrAppModuleIf->m_pcSubWindow[i] = videoSubWindowList.at( i );
}
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::Options ) )
if( pcCurrAppModuleIf->m_pcModule->has( ClpModuleFeature::Options ) )
{
ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf.get() );
if( moduleOptDialog.runConfiguration() == QDialog::Rejected )
@@ -373,7 +372,7 @@ void ModulesHandle::activateModule()
if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == ClpModuleType::FrameProcessing )
{
if( bShowModulesNewWindow || pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::NewWindow ) )
if( bShowModulesNewWindow || pcCurrAppModuleIf->m_pcModule->has( ClpModuleFeature::NewWindow ) )
{
auto pcModuleSubWindow = new ModuleSubWindow( pcCurrAppModuleIf.get() );
pcModuleSubWindow->resetWindowName();
+10 -8
View File
@@ -36,8 +36,8 @@
#include <optional>
ResourceWorker::ResourceWorker( std::shared_ptr<CalypStream> stream )
: m_pcStream{ stream }
{
m_pcStream = stream;
}
void ResourceWorker::stop()
@@ -57,25 +57,23 @@ void ResourceWorker::wake()
void ResourceWorker::run()
{
m_bStop = false;
// Loop forever
while( !m_bStop )
{
//auto start = std::chrono::steady_clock::now();
// auto start = std::chrono::steady_clock::now();
m_pcStream->readNextFrameFillRGBBuffer();
// auto end = std::chrono::steady_clock::now();
// std::cout << "Elapsed time reading and processing a frame: "
// << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count()
// << " ms" << std::endl;
// if( !m_pcStream->hasWritingSlot() )
// {
// m_Mutex.lock();
// m_ResourceIdle.wait( &m_Mutex );
// m_Mutex.unlock();
// }
while( !m_bStop && !m_pcStream->hasWritingSlot() )
{
// Wait here
m_Mutex.lock();
m_ResourceIdle.wait( &m_Mutex );
m_Mutex.unlock();
}
}
}
@@ -150,6 +148,10 @@ void ResourceHandle::startResourceWorker( std::size_t id )
assert( false );
return;
}
if( m_apcStreamResourcesList[id]->getFrameNum() < 2 )
{
return; // No work to be done!
}
m_apcStreamResourcesWorkersList[id]->setObjectName(
"RW-" +
QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() );
+2 -1
View File
@@ -29,6 +29,7 @@
#include <QThread>
#include <QVector>
#include <QWaitCondition>
#include <atomic>
#include "CommonDefs.h"
#include "lib/CalypStream.h"
@@ -39,7 +40,7 @@ private:
QMutex m_Mutex;
QWaitCondition m_ResourceIdle;
std::shared_ptr<CalypStream> m_pcStream;
bool m_bStop{ false };
std::atomic<bool> m_bStop{ false };
public:
ResourceWorker( std::shared_ptr<CalypStream> stream );
+1 -6
View File
@@ -35,7 +35,7 @@
#include "MdiSubWindow.h"
SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category )
: QWidget( parent ), m_cSubWindow( NULL )
: QWidget{ parent }, m_uiCategory{ category }, m_cWindowName{ " " }
{
setParent( parent );
setVisible( false );
@@ -46,11 +46,6 @@ SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category )
setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) );
// setWidgetResizable( true );
m_pcLayout = NULL;
m_uiCategory = category;
m_cWindowName = QString( " " );
connect( this, SIGNAL( destroyed() ), this, SLOT( onDestroyed() ) );
}
+3 -3
View File
@@ -56,11 +56,11 @@ class SubWindowAbstract : public QWidget
Q_OBJECT
private:
QHBoxLayout* m_pcLayout;
QHBoxLayout* m_pcLayout{ nullptr };
unsigned int m_uiCategory;
QString m_cWindowName;
MdiSubWindow* m_cSubWindow;
MdiSubWindow* m_cSubWindow{ nullptr };
public:
enum SubWindowCategory
@@ -90,7 +90,7 @@ public:
*/
virtual void zoomToFit() = 0;
/**
* Scale the image (zoomed in or out) to speficied absolute zoom value (1.0 =
* Scale the image (zoomed in or out) to specified absolute zoom value (1.0 =
* original size).
*/
virtual void zoomToFactor( double factor, QPoint center = QPoint() ) = 0;
+1 -1
View File
@@ -121,7 +121,7 @@ void VideoStreamSubWindow::updateVideoWindowInfo()
}
}
}
if( m_pcDisplayModule->getModuleRequirements() & ClpModuleFeature::HasInfo )
if( m_pcDisplayModule->hasFeature( ClpModuleFeature::HasInfo ) )
{
QStringList list = QString::fromStdString( m_pcDisplayModule->moduleInfo() ).split( '\n' );
windowInfoList.append( list );
+8 -9
View File
@@ -156,7 +156,7 @@ void VideoSubWindow::keyPressEvent( QKeyEvent* event )
{
if( m_pcDisplayModule )
{
if( m_pcDisplayModule->getModuleRequirements().is_set( ClpModuleFeature::KeysShortcuts ) )
if( m_pcDisplayModule->hasFeature( ClpModuleFeature::KeysShortcuts ) )
{
bool bRet = false;
switch( event->key() )
@@ -455,19 +455,19 @@ void VideoSubWindow::adjustScrollBarByScale( double scale, QPoint center )
void VideoSubWindow::updateScrollValues()
{
double xPos = m_pcScrollArea->horizontalScrollBar()->value();
double yPos = m_pcScrollArea->verticalScrollBar()->value();
auto xPos = m_pcScrollArea->horizontalScrollBar()->value();
auto yPos = m_pcScrollArea->verticalScrollBar()->value();
m_cCurrScroll.setX( xPos != 0 );
m_cCurrScroll.setY( yPos != 0 );
m_cCurrScroll.setX( xPos );
m_cCurrScroll.setY( yPos );
m_dHorScroll = m_dVerScroll = 0;
if( xPos != 0 )
m_dHorScroll = xPos / double( m_pcScrollArea->horizontalScrollBar()->maximum() );
m_dHorScroll = static_cast<double>( xPos ) / static_cast<double>( m_pcScrollArea->horizontalScrollBar()->maximum() );
if( yPos != 0 )
m_dVerScroll = yPos / double( m_pcScrollArea->verticalScrollBar()->maximum() );
m_dVerScroll = static_cast<double>( yPos ) / static_cast<double>( m_pcScrollArea->verticalScrollBar()->maximum() );
}
void VideoSubWindow::normalSize()
@@ -476,8 +476,7 @@ void VideoSubWindow::normalSize()
double curFactor = getScaleFactor();
if( factor != curFactor )
{
double usedScale;
usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, QPoint(), QSize() );
double usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, QPoint(), QSize() );
adjustScrollBarByScale( usedScale, QPoint() );
}
}
+6 -3
View File
@@ -81,7 +81,8 @@ void ViewArea::setImage( std::shared_ptr<CalypFrame> frame )
m_nextFrame->fillRGBBuffer();
}
m_image = QImage( m_nextFrame->getRGBBuffer(),
auto rgb_buffer = *m_nextFrame->getRGBBuffer();
m_image = QImage( rgb_buffer.data(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
@@ -115,7 +116,8 @@ void ViewArea::setFilteredChannel( std::size_t channel )
if( m_nextFrame != nullptr )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
m_image = QImage( m_nextFrame->getRGBBuffer(),
auto rgb_buffer = *m_nextFrame->getRGBBuffer();
m_image = QImage( rgb_buffer.data(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
@@ -129,7 +131,8 @@ void ViewArea::clearFilteredChannel()
if( m_nextFrame != nullptr )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
m_image = QImage( m_nextFrame->getRGBBuffer(),
auto rgb_buffer = *m_nextFrame->getRGBBuffer();
m_image = QImage( rgb_buffer.data(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
+1 -3
View File
@@ -22,7 +22,7 @@ SET(Calyp_Lib_Stream_SRCS
SET(Calyp_Lib_OptionParser_SRCS CalypOptions.h CalypOptions.cpp)
SET(Calyp_Lib_Modules_SRCS CalypOptions.h CalypOptions.cpp)
SET(Calyp_Lib_Modules_SRCS CalypModuleIf.h CalypModuleIf.cpp)
SET(Calyp_Lib_SRCS CalypLib.h CalypDefs.h ${Calyp_Lib_Frame_SRCS} ${Calyp_Lib_Stream_SRCS} ${Calyp_Lib_OptionParser_SRCS} ${Calyp_Lib_Modules_SRCS})
@@ -44,8 +44,6 @@ IF(USE_OPENCV)
LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.h)
LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.cpp)
LIST(APPEND Calyp_Lib_SRCS CalypOpenCVModuleIf.cpp)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS})
+1 -1
View File
@@ -20,7 +20,7 @@
/**
* \file CalypDefs.h
* \ingroup CalypLibGrp
* \brief Define basic types, new types and enumerations
* \brief Define basic types, new types and enumerations (private use only)
*/
#ifndef __CALYPDEFS_H__
+5 -5
View File
@@ -97,7 +97,7 @@ auto CalypFrame::findPixelFormat( const std::string_view name ) -> std::optional
return {};
}
auto CalypFrame::pelformatColorSpace( ClpPixelFormats idx ) -> int
auto CalypFrame::pelFormatColorSpace( ClpPixelFormats idx ) -> int
{
return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace;
}
@@ -536,13 +536,13 @@ ClpPel*** CalypFrame::getPelBufferYUV()
return d->m_pppcInputPel;
}
auto CalypFrame::getRGBBuffer() const -> const unsigned char*
auto CalypFrame::getRGBBuffer() const -> std::optional<std::span<const std::uint8_t>>
{
if( d->m_bHasRGBPel )
if( !d->m_bHasRGBPel )
{
return d->m_pcARGB32.data();
return std::nullopt;
}
return NULL;
return std::span{ d->m_pcARGB32 };
}
ClpPel CalypFrame::operator()( unsigned int ch, unsigned int xPos, unsigned int yPos, bool absolute ) const
+2 -2
View File
@@ -222,7 +222,7 @@ public:
static constexpr auto numberOfFormats() -> std::size_t;
static auto findPixelFormat( const std::string& name ) -> std::optional<ClpPixelFormats>;
static auto findPixelFormat( const std::string_view name ) -> std::optional<ClpPixelFormats>;
static auto pelformatColorSpace( ClpPixelFormats idx ) -> int;
static auto pelFormatColorSpace( ClpPixelFormats idx ) -> int;
static auto supportedPixelFormatListNames() -> std::map<ClpPixelFormats, std::string_view>;
static auto supportedPixelFormatListNames( int colorSpace ) -> std::map<ClpPixelFormats, std::string_view>;
static auto pixelFormatName( ClpPixelFormats idx ) -> const std::string_view;
@@ -416,7 +416,7 @@ public:
ClpPel*** getPelBufferYUV() const;
ClpPel*** getPelBufferYUV();
auto getRGBBuffer() const -> const unsigned char*;
auto getRGBBuffer() const -> std::optional<std::span<const std::uint8_t>>;
/**
* Get pixel value at coordinates
@@ -22,16 +22,19 @@
* \brief Calyp modules interface for OpenCV
*/
#include "CalypFrame.h"
#include "CalypModuleIf.h"
// OpenCV
#include <opencv2/opencv.hpp>
#include "CalypFrame.h"
#include "PixelFormats.h"
#include "config.h"
#ifdef USE_OPENCV
#include <opencv2/opencv.hpp>
#endif
bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
{
#ifdef USE_OPENCV
_BASIC_MODULE_API_2_CHECK_
bool bRet = false;
std::vector<Mat> acMatList( apcFrameList.size() );
@@ -51,10 +54,14 @@ bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
return false;
}
return bRet;
#else
return false;
#endif
}
CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList )
{
#ifdef USE_OPENCV
m_pcOutputFrame->reset();
std::vector<Mat> acMatList( apcFrameList.size() );
for( unsigned i = 0; i < apcFrameList.size(); i++ )
@@ -64,8 +71,35 @@ CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList
Mat* cvOutput = process_using_opencv( acMatList );
m_pcOutputFrame->fromMat( *cvOutput );
return m_pcOutputFrame.get();
#else
return nullptr;
#endif
}
void CalypOpenCVModuleIf::destroy()
{
}
ClpModuleFeature operator|( ClpModuleFeature lhs, ClpModuleFeature rhs )
{
return static_cast<ClpModuleFeature>(
static_cast<std::underlying_type_t<ClpModuleFeature>>( lhs ) |
static_cast<std::underlying_type_t<ClpModuleFeature>>( rhs ) );
}
ClpModuleFeature operator&( ClpModuleFeature lhs, ClpModuleFeature rhs )
{
return static_cast<ClpModuleFeature>(
static_cast<std::underlying_type_t<ClpModuleFeature>>( lhs ) &
static_cast<std::underlying_type_t<ClpModuleFeature>>( rhs ) );
}
auto CalypModuleIf::getModuleLongName() -> const char*
{
return m_pchModuleLongName ? m_pchModuleLongName : m_pchModuleName;
}
auto CalypModuleIf::has( ClpModuleFeature feature ) -> bool
{
return ( m_uiModuleRequirements & feature ) != ClpModuleFeature::None;
}
+16 -18
View File
@@ -35,7 +35,6 @@
*/
#include <memory>
#include <type_safe/flag_set.hpp>
#include <vector>
#include "CalypFrame.h"
@@ -95,19 +94,18 @@ enum class ClpModuleType : std::uint8_t
* Features/Requirements of a module
* @see m_uiModuleRequirements
*/
enum class ClpModuleFeature
enum class ClpModuleFeature : std::uint64_t
{
None,
SkipWhilePlaying,
Options,
NewWindow,
KeysShortcuts,
VariableNumOfFrames,
HasInfo,
_flag_set_size
None = 0,
SkipWhilePlaying = 1,
Options = 2,
NewWindow = 4,
KeysShortcuts = 8,
VariableNumOfFrames = 16,
HasInfo = 32,
};
using ClpModuleFeatures = type_safe::flag_set<ClpModuleFeature>;
auto operator|( ClpModuleFeature lhs, ClpModuleFeature rhs ) -> ClpModuleFeature;
enum Module_Key_Supported
{
@@ -117,6 +115,8 @@ enum Module_Key_Supported
MODULE_KEY_DOWN,
};
class CalypFrame;
/**
* \class CalypModuleIf
* \ingroup CalypLib Calyp_Modules
@@ -134,10 +134,8 @@ public:
virtual ~CalypModuleIf() = default;
virtual void destroy(){};
const char* getModuleLongName()
{
return m_pchModuleLongName ? m_pchModuleLongName : m_pchModuleName;
}
auto getModuleLongName() -> const char*;
auto has( ClpModuleFeature feature ) -> bool;
/**
* Module API version 1
@@ -175,7 +173,7 @@ public:
//! Number of frames
unsigned int m_uiNumberOfFrames{ 1 };
//! Features/Requirements
ClpModuleFeatures m_uiModuleRequirements{ ClpModuleFeature::None };
ClpModuleFeature m_uiModuleRequirements{ ClpModuleFeature::None };
unsigned int m_iFrameBufferCount{ 0 };
@@ -197,7 +195,7 @@ class CalypOpenCVModuleIf : public CalypModuleIf
using Mat = cv::Mat;
public:
CalypOpenCVModuleIf() { m_bConvertToGray = false; };
CalypOpenCVModuleIf() = default;
virtual ~CalypOpenCVModuleIf() {}
// Common API
@@ -216,7 +214,7 @@ public:
protected:
// const char* m_pchPythonFunctionName;
std::unique_ptr<CalypFrame> m_pcOutputFrame;
bool m_bConvertToGray;
bool m_bConvertToGray{ false };
};
using CalypModulePtr = std::unique_ptr<CalypModuleIf>;
+2 -1
View File
@@ -38,12 +38,13 @@
#include "CalypOptions.h"
#include <cstring>
#include <functional>
#include <iostream>
#include <memory>
#include <sstream>
#include "config.h"
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
struct ParseFailure : public std::exception
+2 -2
View File
@@ -42,10 +42,10 @@
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "CalypDefs.h"
/**
* \class CalypOptions
* \ingroup CalypLibGrp
+1 -1
View File
@@ -84,7 +84,7 @@ bool StreamHandlerPortableMap::openHandler( std::string strFilename, bool bInput
}
else
{
int colorSpace = CalypFrame::pelformatColorSpace( m_iPixelFormat );
int colorSpace = CalypFrame::pelFormatColorSpace( m_iPixelFormat );
m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1;
if( m_uiBitsPerPixel == 1 )
{
+35 -33
View File
@@ -24,9 +24,6 @@
#include "CalypModulesFactory.h"
#include <cstring>
#include <functional>
#include "config.h"
#ifdef USE_DYNLOAD
#include <dlfcn.h>
@@ -37,45 +34,50 @@
// Generated by cmake
#include "ModulesListHeader.h"
CalypModulesFactory::CalypModulesFactory(){ REGISTER_ALL_MODULES }
CalypModulesFactory::CalypModulesFactory()
{
REGISTER_ALL_MODULES
}
void CalypModulesFactory::Register( const char* moduleName, CreateModuleFn pfnCreate )
void CalypModulesFactory::Register( const std::string& moduleName, std::function<CalypModulePtr( void )> pfnCreate )
{
m_FactoryMap[moduleName] = pfnCreate;
}
bool CalypModulesFactory::RegisterDl( const char* dlName )
void CalypModulesFactory::Register( const char* moduleName, std::function<CalypModulePtr( void )> pfnCreate )
{
#ifdef USE_DYNLOAD
void* pHndl = dlopen( dlName, RTLD_NOW );
if( pHndl == NULL )
{
std::cerr << dlerror() << std::endl;
return false;
}
CreateModuleFn pfnCreate = (CreateModuleFn)dlsym( pHndl, "Maker" );
if( pfnCreate == NULL )
{
return false;
}
Register( dlName, pfnCreate );
return true;
#else
return false;
#endif
Register( std::string{ moduleName }, pfnCreate );
}
CalypModulePtr CalypModulesFactory::CreateModule( const char* moduleName )
bool CalypModulesFactory::RegisterDl( const char* dlName )
{
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( ; it != moduleFactoryMap.end(); ++it )
// #ifdef USE_DYNLOAD
// void* pHndl = dlopen( dlName, RTLD_NOW );
// if( pHndl == NULL )
// {
// std::cerr << dlerror() << std::endl;
// return false;
// }
// CreateModuleFn pfnCreate = (CreateModuleFn)dlsym( pHndl, "Maker" );
// if( pfnCreate == NULL )
// {
// return false;
// }
// Register( dlName, pfnCreate );
// return true;
// #else
return false;
// #endif
}
CalypModulePtr CalypModulesFactory::CreateModule( const std::string& moduleName ) const
{
const auto& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
if( moduleFactoryMap.contains( moduleName ) )
{
if( !strcmp( it->first, moduleName ) )
{
return it->second();
}
auto createFct = moduleFactoryMap.at( moduleName );
return createFct();
}
return nullptr;
}
}
+6 -10
View File
@@ -25,37 +25,33 @@
#ifndef __CALYPMODULESFACTORY_H__
#define __CALYPMODULESFACTORY_H__
#include <functional>
#include <map>
// CalypLib
#include "lib/CalypModuleIf.h"
#define REGISTER_MODULE( X ) Register( "X", &( X::Create ) );
typedef CalypModulePtr ( *CreateModuleFn )( void );
typedef std::map<const char*, CreateModuleFn> CalypModulesFactoryMap;
// Factory for creating instances of CalypModuleIf
class CalypModulesFactory
{
using CalypModulesFactoryMap = std::map<std::string, std::function<CalypModulePtr( void )>>;
private:
CalypModulesFactory();
CalypModulesFactory& operator=( const CalypModulesFactory& ) { return *this; }
CalypModulesFactoryMap m_FactoryMap;
public:
~CalypModulesFactory() = default;
static CalypModulesFactory* Get()
{
static CalypModulesFactory instance;
return &instance;
}
void Register( const char* moduleName, CreateModuleFn pfnCreate );
void Register( const std::string& moduleName, std::function<CalypModulePtr( void )> pfnCreate );
void Register( const char* moduleName, std::function<CalypModulePtr( void )> pfnCreate );
bool RegisterDl( const char* dlName );
CalypModulePtr CreateModule( const char* moduleName );
CalypModulePtr CreateModule( const std::string& moduleName ) const;
CalypModulesFactoryMap& getMap() { return m_FactoryMap; }
};
+1
View File
@@ -26,6 +26,7 @@
#define __FILTERCOMPONENT_H__
// CalypLib
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
class FilterComponentModule : public CalypModuleIf
+2
View File
@@ -24,6 +24,8 @@
#include "FrameDifference.h"
#include "lib/CalypFrame.h"
FrameDifference::FrameDifference()
{
/* Module Definition */
+2
View File
@@ -24,6 +24,8 @@
#include "FrameMask.h"
#include "lib/CalypFrame.h"
FrameMask::FrameMask()
{
/* Module Definition */
+1
View File
@@ -26,6 +26,7 @@
#define __INTERFRAMEVARIANCE_H__
// CalypLib
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
class InterFrameVariance : public CalypModuleIf
+2 -12
View File
@@ -55,17 +55,7 @@ protected:
void SetUp()
{
std::string moduleName = CALYP_TEST_MODULE_NAME;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
pcModule = it->second();
break;
}
}
pcModule = CalypModulesFactory::Get()->CreateModule( moduleName );
}
// Called after each test
@@ -89,7 +79,7 @@ TEST_F( TestModuleCreate, FIND_MODULE )
TEST_F( TestModuleCreate, CREATE_OK )
{
bool moduleRequireOptions = false;
if( pcModule->m_uiModuleRequirements & ClpModuleFeature::Options )
if( pcModule->has( ClpModuleFeature::Options ) )
{
moduleRequireOptions = true;
}
@@ -55,16 +55,7 @@ protected:
pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::YUV420p, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
pcModule = it->second();
break;
}
}
pcModule = CalypModulesFactory::Get()->CreateModule( moduleName );
}
void TearDown()
+2 -11
View File
@@ -303,23 +303,14 @@ int CalypTools::Open( int argc, char* argv[] )
{
std::string moduleName = m_strModule;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
m_pcCurrModuleIf = it->second();
break;
}
}
m_pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( moduleName );
if( !m_pcCurrModuleIf )
{
log( CLP_LOG_ERROR, "Invalid module! " );
return -1;
}
if( m_pcCurrModuleIf->m_uiModuleRequirements & ClpModuleFeature::VariableNumOfFrames )
if( m_pcCurrModuleIf->has( ClpModuleFeature::VariableNumOfFrames ) )
{
m_pcCurrModuleIf->m_uiNumberOfFrames = m_apcInputStreams.size();
}
+12 -23
View File
@@ -118,20 +118,10 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] )
void CalypToolsCmdParser::listModuleHelp()
{
std::string moduleName = m_strModule;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
break;
}
}
auto pcCurrModuleIf = it->second();
auto pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( moduleName );
if( pcCurrModuleIf )
{
printf( "Usage: calypTools --module=%s options:\n", it->first );
printf( "Usage: calypTools --module=%s options:\n", moduleName.c_str() );
pcCurrModuleIf->m_cModuleOptions.doHelp( std::cout );
}
}
@@ -143,27 +133,26 @@ void CalypToolsCmdParser::listModules()
if( m_cOptions.hasOpt( "module_list_full" ) )
bDetailed = true;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
const auto& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
printf( "Calyp available modules: \n" );
printf( " [Internal Name] " );
std::cout << "Calyp available modules:" << std::endl;
std::cout << " [Internal Name] ";
if( bDetailed )
{
printf( " [Full Name] " );
printf( " [Type] " );
printf( " [Description]" );
std::cout << " [Full Name] ";
std::cout << " [Type] ";
std::cout << " [Description]";
}
printf( " \n" );
std::cout << std::endl;
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
for( const auto& [name, moduleFct] : moduleFactoryMap )
{
printf( " " );
printf( "%-33s", it->first );
printf( "%-33s", name.c_str() );
if( bDetailed )
{
std::string ModuleNameString;
auto pcCurrModuleIf = it->second();
auto pcCurrModuleIf = moduleFct();
if( pcCurrModuleIf->m_pchModuleCategory )
{
+1
View File
@@ -28,6 +28,7 @@
#include <vector>
#include "config.h"
#include "lib/CalypDefs.h"
#include "lib/CalypOptions.h"
class CalypToolsCmdParser