25 Commits
Author SHA1 Message Date
jfmcarreira 4aebcb979c Version bump 2.0.1 2021-09-26 01:13:24 +01:00
jfmcarreira f8aa92b7fa Remove C++20 methods not available on Windows 2021-09-26 01:11:44 +01:00
jfmcarreira a2f7f10fea Merge remote-tracking branch 'upstream/master' 2021-09-25 17:56:17 +01:00
jfmcarreira 223bd859a9 Version bump 2.0.0 2021-09-25 17:47:18 +01:00
jfmcarreira b148f28dab Update README.md 2021-09-25 17:44:23 +01:00
jfmcarreira b383eff34f Update CI and fix compilation errors on windows 2021-09-25 17:41:16 +01:00
jfmcarreira 1ec77b64c6 Merge remote-tracking branch 'upstream/master' 2021-09-25 17:25:24 +01:00
jfmcarreira 237bc1cc2e CI - Fix cmake config step 2021-09-25 17:20:38 +01:00
jfmcarreira d4913ed2d2 Update build.yml 2021-09-25 17:18:17 +01:00
jfmcarreira 113e86e583 Updata build action 2021-09-25 17:16:29 +01:00
jfmcarreira 9ea9d845c7 Update version CI config and README 2021-09-25 17:02:03 +01:00
jfmcarreira 48afd0be45 Remove the use of QRecursiveMutex 2021-09-22 01:20:01 +01:00
jfmcarreira 1e4de99fba Remove span include 2021-09-22 00:59:13 +01:00
jfmcarreira d446ee7ac1 Fix compiler flags 2021-09-22 00:31:45 +01:00
jfmcarreira 357971c68b Make the use of FetchContent optional 2021-09-21 22:31:08 +01:00
jfmcarreira 6be534d00c Fix warnings 2021-09-21 01:09:37 +01:00
jfmcarreira 437325c96f Clean up some redundant code 2021-09-20 01:51:54 +01:00
jfmcarreira 94444e38ec Refactor modules ownership 2021-09-19 21:50:15 +01:00
jfmcarreira a093efce9c Changes in CalypStream buffers 2021-09-18 16:26:14 +01:00
jfmcarreira de80c85596 Refactor the use of multiple threads for streams 2021-09-12 23:43:11 +01:00
jfmcarreira 9a63a57458 Reset window title when the last subwindow is closed 2021-09-12 14:35:44 +01:00
jfmcarreira 2451494677 Change CalypStream to RAII management with two buffers 2021-09-12 13:01:26 +01:00
jfmcarreira ffe1bf688d Improve the use of threads and sleep when not in use 2021-09-07 02:00:30 +01:00
jfmcarreira bf5235352b Start using resource handler to manage different streams 2021-09-06 22:43:21 +01:00
jfmcarreira 463e1a58b9 Make module instances unique ptrs 2021-09-04 13:57:12 +01:00
45 changed files with 1228 additions and 715 deletions

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
- key: llvm-else-after-return.WarnOnConditionVariables
value: '0'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: '0'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: llvm-qualified-auto.AddConstToQualified
value: '0'
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: llvm-else-after-return.WarnOnUnfixable
value: '0'
- key: google-readability-function-size.StatementThreshold
value: '800'
-31
View File
@@ -1,31 +0,0 @@
name: Build and Test
on:
push:
branches:
- devel
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install Dependencies
run: sudo apt-get install cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev
- name: Build CMake
uses: ashutoshvarma/action-cmake-build@v1
with:
build-dir: ${{ runner.workspace }}/build
# will set the CC & CXX for cmake
cc: gcc
cxx: g++
build-type: Release
# Extra options pass to cmake while configuring project
configure-options: -DBUILD_TESTS=ON -DUSE_WERROR=ON
run-test: true
#ctest-options: -R mytest
# install the build using cmake --install
install-build: true
# run build using '-j [parallel]' to use multiple threads to build
parallel: 14
+35
View File
@@ -0,0 +1,35 @@
name: Build on Linux
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev
- uses: actions/checkout@v2
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=OFF
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
+3
View File
@@ -144,3 +144,6 @@ doc/
# CLang
compile_commands.json
# Build dirs
build*
+1 -1
View File
@@ -1,5 +1,5 @@
language: cpp
dist: xenial
dist: bionic
before_install:
- sudo apt-get -qq update
- sudo apt-get install build-essential cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev libgtest-dev
+14 -7
View File
@@ -17,8 +17,8 @@ SET(PROJECT_LIBRARY
CACHE INTERNAL "" FORCE
)
SET(CALYP_VERSION_MAJOR "1")
SET(CALYP_VERSION_MINOR "2")
SET(CALYP_VERSION_MAJOR "2")
SET(CALYP_VERSION_MINOR "0")
SET(CALYP_VERSION_PATCH "1")
SET(CALYP_VERSION
"${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}"
@@ -49,11 +49,13 @@ OPTION(BUILD_EXAMPLES "Build Examples" OFF)
OPTION(BUILD_DOC "Build Documentation" OFF)
OPTION(BUILD_TESTS "Build Google Tests" OFF)
OPTION(BUILD_TESTS_CATCH2 "Build Catch2 Tests" OFF)
OPTION(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
OPTION(BUILD_WITH_THREAD_SANITIZER "Build with thread sanitizer" OFF)
OPTION(USE_FERVOR "Add Fervor support" OFF)
OPTION(USE_DYNLOAD "Use dynamic load of modules" ON)
OPTION(USE_SSE "Build with SSE support" OFF)
OPTION(USE_SSE "Build with SSE support" ON)
OPTION(USE_WERROR "Warnings as errors" OFF)
OPTION(USE_STATIC "Use static libs" OFF)
@@ -112,9 +114,8 @@ SET_PACKAGE_PROPERTIES(
TYPE OPTIONAL
)
INCLUDE(FetchContent)
IF(BUILD_TESTS)
INCLUDE(FetchContent)
FETCHCONTENT_DECLARE(googletest URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip)
# For Windows: Prevent overriding the parent project's compiler/linker settings
SET(gtest_force_shared_crt
@@ -136,7 +137,7 @@ IF(BUILD_TESTS)
ENDIF()
IF(BUILD_TESTS_CATCH2)
INCLUDE(FetchContent)
FETCHCONTENT_DECLARE(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
@@ -219,7 +220,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
# ####################################################################################################################################################
SET(CMAKE_CXX_STANDARD 20)
ADD_DEFINITIONS(-std=gnu++20)
ADD_DEFINITIONS(-std=gnu++2a)
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "No build type selected, default to Release")
@@ -250,6 +251,12 @@ IF(USE_WERROR)
ENDIF()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
IF(BUILD_WITH_SANITIZERS)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fsanitize=undefined")
ENDIF()
IF(BUILD_WITH_THREAD_SANITIZER)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread")
ENDIF()
# ####################################################################################################################################################
# Configure targets
+7 -7
View File
@@ -3,9 +3,9 @@
## Build Status
Master branch | Development branch
------------ | -------------
[![Linux Status](https://travis-ci.org/pixlra/calyp.svg?branch=master)](https://travis-ci.org/pixlra/calyp.svg?branch=master) [![Windows status](https://ci.appveyor.com/api/projects/status/ea2ktvtg7uqwrika/branch/master?svg=true)](https://ci.appveyor.com/project/jfmcarreira/calyp/branch/master) | Comming soon!
![Build Action](https://github.com/pixlra/calyp/actions/workflows/build.yml/badge.svg?branch=master) [![Linux Status](https://travis-ci.org/pixlra/calyp.svg?branch=master)](https://travis-ci.org/pixlra/calyp.svg?branch=master)
[![Windows status](https://ci.appveyor.com/api/projects/status/ea2ktvtg7uqwrika/branch/master?svg=true)](https://ci.appveyor.com/project/jfmcarreira/calyp/branch/master)
## Features
@@ -20,7 +20,7 @@ Master branch | Development branch
- Constant growing libs for stream and frame processing (CalypStream and CalypFrame)
- Advanced API for frame/video processing algorithms
- Frame level quality measurement API based on the CalypFrame class
- Powefull command-line tool for quality and frame processing algorithms (uses the referred APIs)
- Powerful command-line tool for quality and frame processing algorithms (uses the referred APIs)
## Modules
- CalypLib: Low level library
@@ -30,7 +30,7 @@ Master branch | Development branch
## Supported Quality Metrics
- Peak Signal-to-Noise Ratio (PSNR)
- Structural SIMilarity (SSIM)
- Structural SIMilarity (SSIM)
- Mean Square Error (MSE)
- Weighted Spherical PSNR (WS-PSNR)
@@ -73,13 +73,13 @@ Master branch | Development branch
* **Dependencies**
1. an ordinary C++ development environment (g++, make, C++ libraries and headers, ...)
2. cmake
3. a Qt development environment: QtCore, QtGui, QtWidgets, QtPrintSupport and QtConcurrent (version 4 or higher)
3. a Qt development environment: QtCore, QtGui, QtWidgets, QtPrintSupport and QtConcurrent (version 5 or higher)
4. Optional: QtDBus, OpenCV, FFmpeg
* **List of required commands**
```
mkdir build
cd build
cmake -DUSE_QT4=OFF -DUSE_FFMPEG=ON -DUSE_OPENCV=ON .. (for FFmpeg and OpenCV support)
cmake -DUSE_FFMPEG=ON -DUSE_OPENCV=ON .. (for FFmpeg and OpenCV support)
make
make install
```
+3
View File
@@ -9,6 +9,8 @@ INCLUDE_DIRECTORIES(
OPTION(USE_QTDBUS "Build with QtDBus" ON)
OPTION(USE_FERVOR "Add Fervor support" OFF)
OPTION(CALYP_MANAGED_RESOURCES "Handle streams in separate threads" ON)
OPTION(CALYP_THREADED_MODULES "Use threads for modules" ON)
ADD_SUBDIRECTORY(external)
@@ -43,6 +45,7 @@ SET(Calyp_App_SRCS
MdiSubWindow.cpp
SubWindowAbstract.cpp
# Module Video
ResourceHandle.cpp
VideoHandle.cpp
VideoSubWindow.cpp
ViewArea.cpp
+112 -93
View File
@@ -28,23 +28,48 @@
#include <QApplication>
#include <QDockWidget>
#include "ModuleHandleDock.h"
#include "VideoSubWindow.h"
#include "lib/CalypFrame.h"
#include "lib/CalypStream.h"
CalypAppModuleIf::CalypAppModuleIf( QObject* parent, QAction* action, CalypModuleIf* module )
: m_bIsRunning( false )
, m_pcModuleAction( action )
, m_pcModule( module )
, m_pcDisplaySubWindow( NULL )
, m_pcDockWidget( NULL )
, m_pcModuleDock( NULL )
, m_pcModuleStream( NULL )
, m_pcProcessedFrame( NULL )
, m_dMeasurementResult( 0 )
CalypAppModuleIf::CalypAppModuleIf( QObject* parent, QAction* action, CalypModulePtr&& module )
: m_pcModuleAction( action ), m_pcModule( std ::move( module ) )
{
setParent( parent );
for( int i = 0; i < CLP_MODULE_MAX_NUM_FRAMES; i++ )
#ifdef CALYP_THREADED_MODULES
setObjectName( m_pcModule->m_pchModuleName );
#endif
m_frameList.reserve( m_pcModule->m_uiNumberOfFrames );
m_frameListPtr.reserve( m_pcModule->m_uiNumberOfFrames );
m_pcSubWindow.resize( m_pcModule->m_uiNumberOfFrames, nullptr );
}
CalypAppModuleIf::~CalypAppModuleIf()
{
#ifdef CALYP_THREADED_MODULES
wait();
#endif
if( m_pcModuleDock )
{
m_pcSubWindow[i] = NULL;
auto* ptr = m_pcModuleDock;
m_pcModuleDock = NULL;
ptr->close();
}
if( m_pcDisplaySubWindow )
{
auto* ptr = m_pcDisplaySubWindow;
m_pcDisplaySubWindow = NULL;
ptr->closeSubWindow();
}
if( m_pcDockWidget )
{
m_pcDockWidget->close();
}
if( m_pcModule )
{
m_pcModule->destroy();
m_pcModule = nullptr;
}
}
@@ -77,11 +102,19 @@ bool CalypAppModuleIf::isRunning()
#endif
}
void CalypAppModuleIf::run()
{
bool result = process();
if( result )
{
EventData* eventData = new EventData( m_bSuccess, this );
QCoreApplication::postEvent( parent(), eventData );
}
}
bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
{
bool bRet = false;
QApplication::setOverrideCursor( Qt::WaitCursor );
bool moduleExecuted = false;
if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
{
if( m_pcDisplaySubWindow )
@@ -95,6 +128,17 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
}
if( !( isPlaying && ( m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY ) ) )
{
m_frameList.clear();
for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ )
{
m_frameList.push_back( m_pcSubWindow[i]->getCurrFrameAsset() );
}
// Skip module is is already running
if( isRunning() )
return moduleExecuted;
moduleExecuted = true;
#ifdef CALYP_THREADED_MODULES
if( !disableThreads )
{
@@ -104,49 +148,52 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
else
#endif
{
run();
QApplication::setOverrideCursor( Qt::WaitCursor );
process();
QApplication::restoreOverrideCursor();
show();
}
}
if( m_pcDisplaySubWindow || m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE )
{
bRet = true;
}
}
else
{
bRet = true;
}
QApplication::restoreOverrideCursor();
return bRet;
return moduleExecuted;
}
void CalypAppModuleIf::run()
bool CalypAppModuleIf::process()
{
m_bIsRunning = true;
m_bSuccess = false;
std::vector<CalypFrame*> apcFrameList;
for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ )
if( m_frameList.empty() )
return false;
#ifdef CALYP_THREADED_MODULES
QMutexLocker locker( &m_Mutex );
#endif
m_frameListPtr.clear();
for( auto& frame : m_frameList )
{
apcFrameList.push_back( m_pcSubWindow[i]->getCurrFrame() );
m_frameListPtr.push_back( frame.get() );
}
if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
{
CalypFrame* framePtr{ nullptr };
if( m_pcModule->m_iModuleAPI >= CLP_MODULE_API_2 )
{
m_pcProcessedFrame = m_pcModule->process( apcFrameList );
framePtr = m_pcModule->process( m_frameListPtr );
}
else
{
m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() );
framePtr = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() );
}
assert( framePtr != nullptr );
m_pcProcessedFrame = std::shared_ptr<CalypFrame>{ framePtr, []( CalypFrame* ptr ) {} };
}
else if( m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE )
{
if( m_pcModule->m_iModuleAPI >= CLP_MODULE_API_2 )
{
m_dMeasurementResult = m_pcModule->measure( apcFrameList );
m_dMeasurementResult = m_pcModule->measure( m_frameListPtr );
}
else
{
@@ -155,82 +202,54 @@ void CalypAppModuleIf::run()
}
else
{
return;
return false;
}
m_bSuccess = true;
m_bIsRunning = false;
#ifdef CALYP_THREADED_MODULES
EventData* eventData = new EventData( m_bSuccess, this );
if( parent() )
QCoreApplication::postEvent( parent(), eventData );
#endif
return;
return true;
}
void CalypAppModuleIf::show()
{
switch( m_pcModule->m_iModuleType )
{
case CLP_FRAME_PROCESSING_MODULE:
if( m_pcDisplaySubWindow )
case CLP_FRAME_PROCESSING_MODULE: {
auto displayWindow = m_pcDisplaySubWindow;
if( displayWindow == nullptr )
displayWindow = m_pcSubWindow[0];
#ifdef CALYP_THREADED_MODULES
if( m_Mutex.try_lock() )
{
m_pcDisplaySubWindow->setFillWindow( false );
m_pcDisplaySubWindow->setCurrFrame( m_pcProcessedFrame );
m_pcDisplaySubWindow->setFillWindow( isRunning() );
}
else
{
m_pcSubWindow[0]->setCurrFrame( m_pcProcessedFrame );
m_pcSubWindow[0]->setFillWindow( isRunning() );
m_Mutex.unlock();
}
#endif
m_pcDisplaySubWindow->setFillWindow( false );
m_pcDisplaySubWindow->setCurrFrame( m_pcProcessedFrame );
break;
}
case CLP_FRAME_MEASUREMENT_MODULE:
m_pcModuleDock->setModulueReturnValue( m_dMeasurementResult );
m_pcModuleDock->setModuleReturnValue( m_dMeasurementResult );
break;
}
}
void CalypAppModuleIf::destroy()
void CalypAppModuleIf::disable()
{
if( m_bIsRunning )
QApplication::setOverrideCursor( Qt::WaitCursor );
#ifdef CALYP_THREADED_MODULES
QMutexLocker locker( &m_Mutex );
m_Mutex.lock();
m_Mutex.unlock();
#endif
m_frameList.clear();
m_frameListPtr.clear();
while( m_pcSubWindow.size() > 0 )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
while( m_bIsRunning )
{
}
QApplication::restoreOverrideCursor();
}
if( m_pcModuleDock )
{
m_pcModuleDock->close();
m_pcModuleDock = NULL;
}
if( m_pcDockWidget )
{
m_pcDockWidget->close();
m_pcDockWidget = NULL;
}
if( m_pcDisplaySubWindow )
m_pcDisplaySubWindow->closeSubWindow();
m_pcDisplaySubWindow = NULL;
for( int i = 0; i < CLP_MODULE_MAX_NUM_FRAMES; i++ )
{
if( m_pcSubWindow[i] )
{
m_pcSubWindow[i]->disableModule( this );
m_pcSubWindow[i] = NULL;
}
}
if( m_pcModuleStream )
{
m_pcModuleStream->close();
delete m_pcModuleStream;
m_pcModuleStream = NULL;
}
if( m_pcModule )
{
m_pcModule->destroy();
m_pcModule->Delete();
m_pcModule = NULL;
auto window = m_pcSubWindow.back();
m_pcSubWindow.erase( m_pcSubWindow.end() - 1 );
if( window != nullptr )
window->disableModule( this );
}
QApplication::restoreOverrideCursor();
}
+44 -39
View File
@@ -26,6 +26,7 @@
#define __CALYPAPPMODULESIF_H__
#include <QEvent>
#include <QPointer>
#include <QVector>
#include <cstdio>
#include <iostream>
@@ -33,88 +34,92 @@
#include "config.h"
#ifdef CALYP_THREADED_MODULES
#include <QMutex>
#include <QThread>
#endif
#include "CommonDefs.h"
#include "ModuleHandleDock.h"
#include "lib/CalypFrame.h"
// #include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
#include "lib/CalypStream.h"
// #include "lib/CalypStream.h"
class QAction;
class QDockWidget;
class CalypStream;
class CalypFrame;
#define CLP_MODULE_MAX_NUM_FRAMES 5
class VideoSubWindow;
class CalypAppModuleIf
class CalypAppModuleIf : std::enable_shared_from_this<CalypAppModuleIf>,
#ifdef CALYP_THREADED_MODULES
: public QThread
public QThread
#else
: public QObject
public QObject
#endif
{
friend class ModulesHandle;
friend class ModuleHandleDock;
friend class ModulesHandleOptDialog;
private:
bool m_bIsRunning;
bool m_bSuccess;
QAction* m_pcModuleAction;
CalypModuleIf* m_pcModule;
VideoSubWindow* m_pcSubWindow[CLP_MODULE_MAX_NUM_FRAMES];
VideoSubWindow* m_pcDisplaySubWindow;
QDockWidget* m_pcDockWidget;
ModuleHandleDock* m_pcModuleDock;
CalypStream* m_pcModuleStream;
CalypFrame* m_pcProcessedFrame;
double m_dMeasurementResult;
public:
class EventData : public QEvent
{
public:
EventData( bool success, CalypAppModuleIf* module )
: QEvent( QEvent::User )
: QEvent( QEvent::User ), m_bSuccess{ success }, m_pcModule{ module }
{
m_bSuccess = success;
m_pcModule = module;
}
bool m_bSuccess;
CalypAppModuleIf* m_pcModule;
QPointer<CalypAppModuleIf> m_pcModule;
};
CalypAppModuleIf( QObject* parent, QAction* action, CalypModuleIf* module );
virtual ~CalypAppModuleIf() {}
QList<VideoSubWindow*> getSubWindowList()
{
QList<VideoSubWindow*> arraySubWindows;
for( int i = 0; i < CLP_MODULE_MAX_NUM_FRAMES; i++ )
if( m_pcSubWindow[i] )
arraySubWindows.append( m_pcSubWindow[i] );
return arraySubWindows;
}
CalypAppModuleIf( QObject* parent, QAction* action, CalypModulePtr&& module );
~CalypAppModuleIf();
CalypModuleIf* getModule() { return m_pcModule; }
auto getSubWindowList() -> const std::vector<VideoSubWindow*>& { return m_pcSubWindow; }
CalypModuleIf* getModule() { return m_pcModule.get(); }
unsigned int getModuleRequirements() { return m_pcModule->m_uiModuleRequirements; }
ClpString moduleInfo() { return m_pcModule->moduleInfo(); }
void update( bool isPlaying );
bool apply( bool isPlaying = false, bool disableThreads = false );
bool process();
void setPlaying( bool isPlaying );
bool isRunning();
void show();
void destroy();
void disable();
protected:
virtual void run();
private:
bool m_bSuccess{ false };
QAction* m_pcModuleAction{ nullptr };
CalypModulePtr m_pcModule{ nullptr };
std::vector<VideoSubWindow*> m_pcSubWindow;
// The module owns the related widgets
VideoSubWindow* m_pcDisplaySubWindow{ nullptr };
QDockWidget* m_pcDockWidget{ nullptr };
ModuleHandleDock* m_pcModuleDock{ nullptr };
std::unique_ptr<CalypStream> m_pcModuleStream{ nullptr };
std::vector<std::shared_ptr<CalypFrame>> m_frameList;
std::vector<CalypFrame*> m_frameListPtr;
std::shared_ptr<CalypFrame> m_pcProcessedFrame{ nullptr };
double m_dMeasurementResult{ 0 };
#ifdef CALYP_THREADED_MODULES
QMutex m_Mutex;
#endif
};
#endif // __CALYPAPPMODULESIF_H__
+1 -1
View File
@@ -52,7 +52,7 @@ void GridManager::setGridSize( int newsize )
////////////////////////////////////////////////////////////////////////////////
// Grid Drawer
////////////////////////////////////////////////////////////////////////////////
void GridManager::drawGrid( QPixmap& image, const QRect& area, QPainter* painter )
void GridManager::drawGrid( const QImage& image, const QRect& area, QPainter* painter )
{
int offsetx = 0; // Grid offset doesn't applies to SCODE
int offsety = 0; // project for now...
+1 -1
View File
@@ -55,7 +55,7 @@ public:
void setGridSize( int newsize );
void drawGrid( QPixmap& image, const QRect& area, QPainter* painter );
void drawGrid( const QImage& image, const QRect& area, QPainter* painter );
/**
* @returns a QRect defined by the grid that contains the point (x, y).
+10 -5
View File
@@ -33,6 +33,7 @@
#include <QDropEvent>
#include <QSignalMapper>
#include <QtDebug>
#include <memory>
#include "AboutDialog.h"
#include "ModulesHandle.h"
@@ -58,6 +59,8 @@ MainWindow::MainWindow()
m_pDBusAdaptor = new DBusAppAdaptor( this );
#endif
m_appResourceHandle = std::make_unique<ResourceHandle>();
m_pcWindowHandle = new SubWindowHandle( this );
m_appModuleVideo = new VideoHandle( this, m_pcWindowHandle );
@@ -80,11 +83,11 @@ MainWindow::MainWindow()
setAcceptDrops( true );
setBackgroundRole( QPalette::Background );
connect( m_pcWindowHandle, SIGNAL( windowActivated() ), this, SLOT( update() ) );
connect( m_pcWindowHandle, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_appModuleVideo, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_appModuleQuality, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_appModuleExtensions, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::update );
connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::update, Qt::QueuedConnection );
connect( m_appModuleVideo, &VideoHandle::changed, this, &MainWindow::update, Qt::QueuedConnection );
connect( m_appModuleQuality, &QualityHandle::changed, this, &MainWindow::update, Qt::QueuedConnection );
connect( m_appModuleExtensions, &ModulesHandle::changed, this, &MainWindow::update, Qt::QueuedConnection );
}
bool MainWindow::parseArgs( int argc, char* argv[] )
@@ -196,6 +199,8 @@ void MainWindow::loadFile( QString fileName, CalypFileInfo* pStreamInfo )
return;
}
videoSubWindow = new VideoSubWindow( VideoSubWindow::VIDEO_STREAM_SUBWINDOW ); // createSubWindow();
videoSubWindow->setResourceManaget( m_appResourceHandle.get() );
if( !pStreamInfo )
{
int idx = findCalypStreamInfo( m_aRecentFileStreamInfo, fileName );
+6 -4
View File
@@ -36,16 +36,17 @@
#ifndef __MAINWINDOW_H__
#define __MAINWINDOW_H__
#include <QMainWindow>
#include <QString>
#include <QVector>
#include "CommonDefs.h"
#include "VideoSubWindow.h"
#include "config.h"
#ifdef USE_QTDBUS
#include "DBusAppAdaptor.h"
#endif
#include <QMainWindow>
#include <QString>
#include <QVector>
#include "ResourceHandle.h"
class QCloseEvent;
class QDragEnterEvent;
@@ -158,6 +159,7 @@ private:
* Quality
* Modules
*/
std::unique_ptr<ResourceHandle> m_appResourceHandle;
VideoHandle* m_appModuleVideo;
QualityHandle* m_appModuleQuality;
ModulesHandle* m_appModuleExtensions;
+42 -54
View File
@@ -91,7 +91,6 @@ QMenu* ModulesHandle::createMenu()
void ModulesHandle::buildMenu()
{
CalypModuleIf* pcCurrModuleIf;
QString ModuleIfinternalName;
QAction* currAction;
QMenu* currSubMenu;
@@ -108,7 +107,7 @@ void ModulesHandle::buildMenu()
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( ; it != moduleFactoryMap.end(); ++it )
{
pcCurrModuleIf = it->second();
auto pcCurrModuleIf = it->second();
ModuleIfinternalName = QString::fromLocal8Bit( it->first );
currSubMenu = NULL;
@@ -147,8 +146,6 @@ void ModulesHandle::buildMenu()
currSubMenu->addAction( currAction );
else
m_pcModulesMenu->addAction( currAction );
pcCurrModuleIf->Delete();
}
m_pcModulesMenu->addAction( m_arrayActions[LOAD_EXTERNAL_ACT] );
@@ -183,11 +180,11 @@ void ModulesHandle::updateMenus()
}
m_arrayActions[LOAD_EXTERNAL_ACT]->setEnabled( true );
m_arrayActions[FORCE_NEW_WINDOW_ACT]->setEnabled( hasSubWindow );
m_arrayActions[DISABLE_ALL_ACT]->setEnabled( m_pcCalypAppModuleIfList.size() > 0 );
m_arrayActions[DISABLE_ALL_ACT]->setEnabled( true );
if( pcSubWindow )
{
QList<CalypAppModuleIf*> apcCurrentModule = pcSubWindow->getModuleArray();
auto apcCurrentModule = pcSubWindow->getModuleArray();
m_arrayActions[DISABLE_ACT]->setEnabled( apcCurrentModule.size() > 0 );
if( pcSubWindow->getDisplayModule() )
{
@@ -278,9 +275,8 @@ void ModulesHandle::activateModule()
}
QString ModuleIfName = pcAction->data().toString();
CalypModuleIf* pcCurrModuleIf =
CalypModulesFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() );
CalypAppModuleIf* pcCurrAppModuleIf = new CalypAppModuleIf( this, pcAction, pcCurrModuleIf );
auto pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() );
auto pcCurrAppModuleIf = std::make_shared<CalypAppModuleIf>( this, pcAction, std::move( pcCurrModuleIf ) );
QList<VideoSubWindow*> videoSubWindowList;
int numberOfFrames = pcCurrAppModuleIf->m_pcModule->m_uiNumberOfFrames;
@@ -337,7 +333,7 @@ void ModulesHandle::activateModule()
{
videoSubWindowList.clear();
qobject_cast<MainWindow*>( m_pcParent )->printMessage( "Error! Incompatible frames", CLP_LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
//destroyModuleIf( pcCurrAppModuleIf );
return;
}
}
@@ -352,7 +348,7 @@ void ModulesHandle::activateModule()
{
qobject_cast<MainWindow*>( m_pcParent )
->printMessage( "Error! There is no windows to apply the module", CLP_LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
//destroyModuleIf( pcCurrAppModuleIf );
return;
}
@@ -363,11 +359,11 @@ void ModulesHandle::activateModule()
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_OPTIONS )
{
ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf );
ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf.get() );
if( moduleOptDialog.runConfiguration() == QDialog::Rejected )
{
qobject_cast<MainWindow*>( m_pcParent )->printMessage( "Module canceled by user!", CLP_LOG_WARNINGS );
destroyModuleIf( pcCurrAppModuleIf );
//destroyModuleIf( pcCurrAppModuleIf );
return;
}
}
@@ -381,7 +377,7 @@ void ModulesHandle::activateModule()
{
if( ( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow )
{
pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW );
pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW, pcCurrAppModuleIf.get() );
windowName.append( QStringLiteral( "Module " ) );
windowName.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleLongName );
pcCurrAppModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow;
@@ -392,11 +388,15 @@ void ModulesHandle::activateModule()
// connect( pcModuleSubWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), m_appModuleVideo,
// SLOT( moveAllScrollBars( const QPoint ) ) );
}
else
{
pcCurrAppModuleIf->m_pcSubWindow[0]->setDisplayModule( pcCurrAppModuleIf.get() );
}
}
else if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE )
{
pcCurrAppModuleIf->m_pcDisplaySubWindow = NULL;
pcCurrAppModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrAppModuleIf );
pcCurrAppModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrAppModuleIf.get() );
QString titleDockWidget;
titleDockWidget.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleName );
titleDockWidget.append( " Information" );
@@ -408,19 +408,9 @@ void ModulesHandle::activateModule()
->addDockWidget( Qt::RightDockWidgetArea, pcCurrAppModuleIf->m_pcDockWidget );
}
// Associate module with subwindows
if( !pcCurrAppModuleIf->m_pcDisplaySubWindow && !pcCurrAppModuleIf->m_pcModuleDock )
for( int i = 0; i < videoSubWindowList.size(); i++ )
{
pcCurrAppModuleIf->m_pcSubWindow[0]->enableModule( pcCurrAppModuleIf );
}
else
{
if( pcCurrAppModuleIf->m_pcDisplaySubWindow )
pcCurrAppModuleIf->m_pcDisplaySubWindow->enableModule( pcCurrAppModuleIf );
for( int i = 0; i < videoSubWindowList.size(); i++ )
{
pcCurrAppModuleIf->m_pcSubWindow[i]->associateModule( pcCurrAppModuleIf );
}
pcCurrAppModuleIf->m_pcSubWindow[i]->associateModule( pcCurrAppModuleIf );
}
// Create Module
@@ -443,11 +433,12 @@ void ModulesHandle::activateModule()
if( !moduleCreated )
{
qobject_cast<MainWindow*>( m_pcParent )->printMessage( "Error! Module cannot be created", CLP_LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
//destroyModuleIf( pcCurrAppModuleIf );
return;
}
pcCurrAppModuleIf->apply( false, true );
QCoreApplication::processEvents();
if( pcModuleSubWindow )
@@ -465,44 +456,39 @@ void ModulesHandle::activateModule()
videoSubWindowList.at( 0 )->setWindowName( windowName );
}
m_pcCalypAppModuleIfList.append( pcCurrAppModuleIf );
// Change ownership of the module
// if( !pcCurrAppModuleIf->m_pcDisplaySubWindow && !pcCurrAppModuleIf->m_pcModuleDock )
// {
// pcCurrAppModuleIf->m_pcSubWindow[0]->enableModule( pcCurrAppModuleIf );
// }
// else if( pcCurrAppModuleIf->m_pcDisplaySubWindow )
// {
// pcCurrAppModuleIf->m_pcDisplaySubWindow->enableModule( pcCurrAppModuleIf );
// }
emit changed();
}
void ModulesHandle::destroyModuleIf( CalypAppModuleIf* pcCurrModuleIf )
{
if( pcCurrModuleIf )
{
pcCurrModuleIf->destroy();
}
}
void ModulesHandle::destroyWindowModules()
{
VideoSubWindow* pcVideoSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
if( pcVideoSubWindow )
{
pcVideoSubWindow->disableModule();
pcVideoSubWindow->disableAllModules();
emit changed();
}
}
void ModulesHandle::destroyAllModulesIf()
{
for( int i = 0; i < m_pcCalypAppModuleIfList.size(); i++ )
bool emit_changed = false;
QList<SubWindowAbstract*> windowsList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( auto window : windowsList )
{
destroyModuleIf( m_pcCalypAppModuleIfList.at( i ) );
}
emit changed();
}
void ModulesHandle::applyModuleIf( QList<CalypAppModuleIf*> pcCurrModuleIfList, bool isPlaying, bool disableThreads )
{
for( int i = 0; i < pcCurrModuleIfList.size() && !isPlaying; i++ )
{
pcCurrModuleIfList.at( i )->apply( isPlaying, disableThreads );
emit_changed |= qobject_cast<VideoSubWindow*>( window )->disableAllModules();
}
if( emit_changed )
emit changed();
}
void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
@@ -552,12 +538,11 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
BitsPixel = pcCurrModuleIf->m_pcProcessedFrame->getBitsPel();
FrameRate = pcCurrModuleIf->m_pcSubWindow[0]->getInputStream()->getFrameRate();
pcCurrModuleIf->m_pcModuleStream = new CalypStream;
pcCurrModuleIf->m_pcModuleStream = std::unique_ptr<CalypStream>();
if( !pcCurrModuleIf->m_pcModuleStream->open( fileName.toStdString(), Width, Height, InputFormat, BitsPixel,
CLP_LITTLE_ENDIAN, FrameRate, false ) )
{
delete pcCurrModuleIf->m_pcModuleStream;
pcCurrModuleIf->m_pcModuleStream = NULL;
pcCurrModuleIf->m_pcModuleStream = nullptr;
return;
}
}
@@ -609,12 +594,15 @@ void ModulesHandle::swapModulesWindowsIf( CalypAppModuleIf* pcCurrModuleIf )
void ModulesHandle::customEvent( QEvent* event )
{
if( !event )
{
return;
}
CalypAppModuleIf::EventData* eventData = (CalypAppModuleIf::EventData*)event;
if( eventData->m_bSuccess )
{
event->accept();
// The module could be freed by the time the event is processed
if( eventData->m_pcModule.isNull() )
return;
eventData->m_pcModule->show();
}
}
-4
View File
@@ -55,10 +55,6 @@ public:
void readSettings();
void writeSettings();
static void destroyModuleIf( CalypAppModuleIf* pcCurrModuleIf );
static void applyModuleIf( QList<CalypAppModuleIf*> pcCurrModuleIfList, bool isPlaying = false,
bool disableThreads = false );
private:
QWidget* m_pcParent;
SubWindowHandle* m_pcMainWindowManager;
+167
View File
@@ -0,0 +1,167 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
* Joao Santos (joaompssantos@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 ResourceHandle.cpp
* \brief Handle resources
*/
#include "ResourceHandle.h"
#include <QCoreApplication>
#include <QEvent>
#include <QFileInfo>
#include <QMutex>
#include <QThread>
#include <chrono>
#include <iostream>
#include <memory>
#include <optional>
ResourceWorker::ResourceWorker( std::shared_ptr<CalypStream> stream )
{
m_pcStream = stream;
}
void ResourceWorker::stop()
{
m_bStop = true;
wake();
wait();
}
void ResourceWorker::wake()
{
m_Mutex.lock();
m_ResourceIdle.wakeAll();
m_Mutex.unlock();
}
void ResourceWorker::run()
{
m_bStop = false;
// Loop forever
while( !m_bStop )
{
//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
}
}
}
ResourceHandle::ResourceHandle()
{
}
auto ResourceHandle::addResource() -> std::size_t
{
auto resource_id = unique_id;
unique_id++;
auto newStreamResource = std::make_shared<CalypStream>();
auto newStreamResourceWorker = std::make_unique<ResourceWorker>( newStreamResource );
m_apcStreamResourcesList[resource_id] = newStreamResource;
m_apcStreamResourcesWorkersList[resource_id] = std::move( newStreamResourceWorker );
return resource_id;
}
auto ResourceHandle::getResource( CalypStream* ptr ) -> std::size_t
{
if( ptr != nullptr )
{
for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ )
{
if( m_apcStreamResourcesList[i].get() == ptr )
return i;
}
}
return addResource();
}
auto ResourceHandle::getResourceAsset( std::size_t id ) -> CalypStream*
{
if( m_apcStreamResourcesWorkersList.count( id ) )
{
return m_apcStreamResourcesList[id].get();
}
return nullptr;
}
void ResourceHandle::removeResource( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
// Remove worker first
m_apcStreamResourcesWorkersList[id]->stop();
m_apcStreamResourcesWorkersList[id] = nullptr;
// Then the underlying stream
m_apcStreamResourcesList[id] = nullptr;
}
void ResourceHandle::stopResourceWorker( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
m_apcStreamResourcesWorkersList[id]->stop();
}
void ResourceHandle::startResourceWorker( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
m_apcStreamResourcesWorkersList[id]->setObjectName(
"RW-" +
QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() );
m_apcStreamResourcesWorkersList[id]->start();
}
void ResourceHandle::wakeResourceWorker( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
m_apcStreamResourcesWorkersList[id]->wake();
}
+73
View File
@@ -0,0 +1,73 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 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 ResourceHandle.h
* \brief Handle multiple sub-windows
*/
#ifndef __RESOURCEHANDLE_H__
#define __RESOURCEHANDLE_H__
#include <QMutex>
#include <QThread>
#include <QVector>
#include <QWaitCondition>
#include "CommonDefs.h"
#include "lib/CalypStream.h"
class ResourceWorker : public QThread
{
private:
QMutex m_Mutex;
QWaitCondition m_ResourceIdle;
std::shared_ptr<CalypStream> m_pcStream;
bool m_bStop{ false };
public:
ResourceWorker( std::shared_ptr<CalypStream> stream );
void stop();
void wake();
void run();
};
class ResourceHandle
{
public:
ResourceHandle();
~ResourceHandle() = default;
auto getResource( CalypStream* ptr ) -> std::size_t;
auto getResourceAsset( std::size_t id ) -> CalypStream*;
void removeResource( std::size_t id );
void stopResourceWorker( std::size_t id );
void startResourceWorker( std::size_t id );
void wakeResourceWorker( std::size_t id );
private:
auto addResource() -> std::size_t;
private:
std::size_t unique_id{ 0 };
std::map<std::size_t, std::shared_ptr<CalypStream>> m_apcStreamResourcesList;
std::map<std::size_t, std::unique_ptr<ResourceWorker>> m_apcStreamResourcesWorkersList;
};
#endif // __RESOURCEHANDLE_H__
+16 -3
View File
@@ -182,6 +182,10 @@ void SubWindowHandle::setWindowMode( int iWindowMode )
{
m_pcApp->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() );
}
else
{
m_pcApp->setWindowTitle( QApplication::applicationName() );
}
}
m_iWindowMode = iWindowMode;
// tileSubWindows();
@@ -218,6 +222,10 @@ void SubWindowHandle::updateActiveSubWindow( SubWindowAbstract* window )
{
m_pcApp->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() );
}
else
{
m_pcApp->setWindowTitle( QApplication::applicationName() );
}
}
}
@@ -237,9 +245,9 @@ void SubWindowHandle::addSubWindow( SubWindowAbstract* window )
if( window )
{
connect( window, SIGNAL( updateStatusBar( const QString& ) ), m_pcApp,
SLOT( printMessage( const QString& ) ) );
SLOT( printMessage( const QString& ) ) );
connect( window, SIGNAL( zoomFactorChanged( const double, const QPoint ) ), m_pcApp,
SLOT( updateZoomFactorSBox() ) );
SLOT( updateZoomFactorSBox() ) );
if( m_iWindowMode == DETACHEDSUBWINDOWMODE )
{
connect( window, SIGNAL( aboutToActivate( SubWindowAbstract* ) ), this,
@@ -278,7 +286,12 @@ void SubWindowHandle::removeSubWindow( int windowIdx )
if( !m_apcSubWindowList.isEmpty() )
m_apcSubWindowList.front()->setFocus();
else
m_pcActiveWindow = NULL;
m_pcActiveWindow = nullptr;
if( m_pcActiveWindow == nullptr )
{
m_pcApp->setWindowTitle( QApplication::applicationName() );
}
emit changed();
}
+23 -14
View File
@@ -29,8 +29,10 @@
#include <QLabel>
#include <QSignalMapper>
#include <QSlider>
#include <QTimer>
#include <QToolBar>
#include <QtGui>
#include <memory>
#include "FrameNumberWidget.h"
#include "FramePropertiesDock.h"
@@ -45,18 +47,15 @@ VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager )
{
m_pcCurrentVideoSubWindow = NULL;
m_bIsPlaying = false;
m_pcPlayingTimer = new QTimer;
m_pcFrameRateFeedbackTimer = new QElapsedTimer;
m_pcPlayingTimer = new QTimer( this );
m_pcFrameRateFeedbackTimer = std::make_unique<QElapsedTimer>();
m_pcPlayingTimer->setTimerType( Qt::PreciseTimer );
connect( m_pcPlayingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) );
connect( m_pcPlayingTimer, &QTimer::timeout,
this, &VideoHandle::playEvent );
m_acPlayingSubWindows.clear();
}
VideoHandle::~VideoHandle()
{
delete m_pcPlayingTimer;
delete m_pcFrameRateFeedbackTimer;
}
VideoHandle::~VideoHandle() = default;
void VideoHandle::createActions()
{
@@ -326,8 +325,8 @@ void VideoHandle::update()
{
if( m_pcCurrentVideoSubWindow )
{
CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream();
CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame();
const CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream();
const CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame();
m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() );
@@ -363,8 +362,7 @@ void VideoHandle::update()
}
}
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->setCurrFrameNum( frame_num );
@@ -440,13 +438,17 @@ void VideoHandle::closeSubWindow( SubWindowAbstract* subWindow )
if( m_acPlayingSubWindows.contains( videoSubWindow ) )
{
int pos = m_acPlayingSubWindows.indexOf( videoSubWindow );
m_acPlayingSubWindows.at( pos )->stop();
// m_acPlayingSubWindows.at( pos )->stop();
m_acPlayingSubWindows.remove( pos );
if( m_acPlayingSubWindows.size() < 2 )
{
m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false );
}
}
if( subWindow == m_pcCurrentVideoSubWindow )
{
m_pcFramePropertiesSideBar->reset();
}
}
void VideoHandle::zoomToFactorAll( const double scale, const QPoint center )
@@ -673,8 +675,10 @@ void VideoHandle::calculateRealFrameRate()
void VideoHandle::playEvent()
{
auto start = std::chrono::steady_clock::now();
// This value should only be true if it is really needed to refresh the UI after this play event
// Lets assum the current window is not playing. Nothing changes in the UI expect the playing windows
// Lets assume the current window is not playing. Nothing changes in the UI expect the playing windows
// So no changed is emmited
bool bShouldRefreshUI = false;
calculateRealFrameRate();
@@ -717,6 +721,11 @@ void VideoHandle::playEvent()
}
if( bShouldRefreshUI )
emit changed();
// auto end = std::chrono::steady_clock::now();
// std::cout << "Elapsed time going to next frame: "
// << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count()
// << " ms" << std::endl;
}
void VideoHandle::seekEvent( int direction )
+5 -4
View File
@@ -25,6 +25,7 @@
#ifndef __VIDEOHANDLE_H__
#define __VIDEOHANDLE_H__
#include <QElapsedTimer>
#include <QMenu>
#include <QPoint>
#include <QThread>
@@ -39,13 +40,13 @@ class QDockWidget;
class QSignalMapper;
class QLabel;
class QSlider;
class QElapsedTimer;
class SubWindowHandle;
class SubWindowAbstract;
class VideoSubWindow;
class FramePropertiesDock;
class FrameNumberWidget;
class QTimer;
class VideoHandle : public QObject
{
@@ -121,9 +122,9 @@ private:
QTimer* m_pcPlayingTimer;
bool m_bIsPlaying;
unsigned int m_uiNumberPlayedFrames;
unsigned int m_uiRealAverageFrameRate;
QElapsedTimer* m_pcFrameRateFeedbackTimer;
unsigned int m_uiNumberPlayedFrames{ 0 };
unsigned int m_uiRealAverageFrameRate{ 0 };
std::unique_ptr<QElapsedTimer> m_pcFrameRateFeedbackTimer;
void configureFrameRateTimer();
void calculateRealFrameRate();
+215 -106
View File
@@ -32,9 +32,10 @@
#include "ConfigureFormatDialog.h"
#include "ModulesHandle.h"
#include "QtConcurrent/qtconcurrentrun.h"
#include "ResourceHandle.h"
#include "SubWindowAbstract.h"
//#define QT_NO_CONCURRENT
#define QT_NO_CONCURRENT
/**
* \brief Functions to control data stream from stream information
@@ -56,7 +57,7 @@ QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& array )
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& array )
{
CalypFileInfo d;
int array_size;
int array_size{ 0 };
in >> array_size;
for( int i = 0; i < array_size; i++ )
{
@@ -105,7 +106,6 @@ public:
m_cCenterTextFont.setPointSize( 12 );
m_pcRefreshTimer = new QTimer;
m_pcRefreshTimer->setSingleShot( true );
connect( m_pcRefreshTimer, SIGNAL( timeout() ), this, SLOT( update() ) );
}
void setInformationTopLeft( const QStringList& textLines )
{
@@ -118,6 +118,7 @@ public:
void setBusyWindow( bool bFlag )
{
m_bBusyWindow = bFlag;
// Do not show the refresh screen if it takes less than 500 ms
m_pcRefreshTimer->start( 500 );
}
@@ -135,7 +136,7 @@ protected:
topLeftCorner += QPoint( 0, 15 );
}
}
if( m_bBusyWindow )
if( m_bBusyWindow && !m_pcRefreshTimer->isActive() )
{
painter.setFont( m_cCenterTextFont );
painter.drawText( rect(), Qt::AlignHCenter | Qt::AlignVCenter, QStringLiteral( "Refreshing..." ) );
@@ -146,10 +147,9 @@ protected:
VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent )
: SubWindowAbstract( parent, SubWindowAbstract::VIDEO_SUBWINDOW | category )
, m_pcResourceManager( nullptr )
, m_bWindowBusy( false )
, m_pCurrStream( NULL )
, m_pcCurrFrame( NULL )
, m_pcCurrentDisplayModule( NULL )
, m_pcReferenceSubWindow( NULL )
, m_bIsPlaying( false )
, m_pcUpdateTimer( NULL )
@@ -184,7 +184,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget*
m_pcScrollArea->setWidgetResizable( true );
setWidget( m_pcScrollArea );
m_apcCurrentModule.clear();
m_associatedModules.clear();
m_pcUpdateTimer = new QTimer();
m_pcUpdateTimer->setInterval( 800 );
@@ -194,14 +194,18 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget*
m_pcVideoInfo = new VideoInformation( this );
}
VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, CalypAppModuleIf* displayModule, QWidget* parent )
: VideoSubWindow( category, parent )
{
m_pcCurrentDisplayModule = displayModule;
}
VideoSubWindow::~VideoSubWindow()
{
m_pcCurrFrame = NULL;
disableModule();
delete m_cViewArea;
m_pcCurrFrameAsset = nullptr;
if( m_pcResourceManager )
m_pcResourceManager->removeResource( m_uiResourceId );
delete m_pcUpdateTimer;
if( m_pCurrStream )
delete m_pCurrStream;
}
/**
@@ -210,7 +214,19 @@ VideoSubWindow::~VideoSubWindow()
void VideoSubWindow::closeEvent( QCloseEvent* event )
{
stop();
//stop();
auto tmpModules = m_associatedModules;
m_associatedModules.clear();
for( auto module : tmpModules )
{
module->disable();
}
if( m_pcCurrentDisplayModule )
{
m_pcCurrentDisplayModule->disable();
event->ignore();
return;
}
SubWindowAbstract::closeEvent( event );
}
@@ -275,8 +291,8 @@ QSize VideoSubWindow::sizeHint() const
QSize VideoSubWindow::sizeHint( const QSize& maxSize ) const
{
QSize isize;
if( m_pcCurrFrame )
isize = QSize( m_pcCurrFrame->getWidth() + 50, m_pcCurrFrame->getHeight() + 50 );
if( m_pcCurrFrameAsset )
isize = QSize( m_pcCurrFrameAsset->getWidth() + 50, m_pcCurrFrameAsset->getHeight() + 50 );
else if( m_pCurrStream )
isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 );
@@ -306,12 +322,17 @@ void VideoSubWindow::refreshSubWindow()
{
if( getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW )
{
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->stopResourceWorker( m_uiResourceId );
#endif
if( !m_pCurrStream->reload() )
{
close();
return;
}
// seekAbsoluteEvent( currFrameNum );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
}
updateVideoWindowInfo();
refreshFrame();
@@ -319,6 +340,8 @@ void VideoSubWindow::refreshSubWindow()
bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
{
assert( m_pcResourceManager != nullptr );
ConfigureFormatDialog formatDialog( this );
unsigned int Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
int Endianness = CLP_LITTLE_ENDIAN;
@@ -327,11 +350,11 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
if( m_pCurrStream )
m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
else
m_uiResourceId = m_pcResourceManager->getResource( nullptr );
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
if( !m_pCurrStream )
{
m_pCurrStream = new CalypStream;
}
bool bConfig = true;
if( !bForceDialog )
{
@@ -383,6 +406,10 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
var.setValue<unsigned int>( BitsPel );
appSettings.setValue( "VideoSubWindow/LastBitsPerPixel", var );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
@@ -397,10 +424,10 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo )
{
if( !m_pCurrStream )
{
m_pCurrStream = new CalypStream;
}
assert( m_pcResourceManager != nullptr );
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,
streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness,
@@ -411,6 +438,10 @@ bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo )
m_sStreamInfo = *streamInfo;
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
@@ -427,15 +458,15 @@ void VideoSubWindow::updateVideoWindowInfo()
if( m_pcCurrentDisplayModule )
{
m_cStreamInformation = "Module";
QList<VideoSubWindow*> arraySubWindows = m_pcCurrentDisplayModule->getSubWindowList();
const auto& arraySubWindows = m_pcCurrentDisplayModule->getSubWindowList();
QStringList windowInfoList;
if( arraySubWindows.size() > 0 )
{
for( int i = 0; i < arraySubWindows.size(); i++ )
for( std::size_t i = 0; i < arraySubWindows.size(); i++ )
{
if( arraySubWindows.at( i )->getWindowName() != getWindowName() )
if( arraySubWindows[i]->getWindowName() != getWindowName() )
{
windowInfoList.append( QString( "Input %1 - " + arraySubWindows.at( i )->getWindowName() ).arg( i + 1 ) );
windowInfoList.append( QString( "Input %1 - " + arraySubWindows[i]->getWindowName() ).arg( i + 1 ) );
}
}
}
@@ -444,7 +475,6 @@ void VideoSubWindow::updateVideoWindowInfo()
QStringList list = QString::fromStdString( m_pcCurrentDisplayModule->moduleInfo() ).split( '\n' );
windowInfoList.append( list );
}
// qDebug( ) << sourceWindowList;
if( windowInfoList.size() > 0 )
{
m_pcVideoInfo->setInformationTopLeft( windowInfoList );
@@ -456,16 +486,14 @@ void VideoSubWindow::updateVideoWindowInfo()
QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() );
m_cStreamInformation = m_cFormatName + " | " + m_cCodedName;
}
//#if 0
if( m_pcCurrFrame )
if( m_pcCurrFrameAsset )
{
QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrame->getPelFmtName() );
QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrameAsset->getPelFmtName() );
if( m_pCurrStream )
if( !m_pCurrStream->isNative() )
m_cPelFmtName += "*";
m_cStreamInformation += " | " + m_cPelFmtName;
}
//#endif
if( m_cStreamInformation.isEmpty() )
{
m_cStreamInformation = " ";
@@ -633,78 +661,127 @@ void VideoSubWindow::updateSelectedArea( QRect area )
* Functions to enable a module in the
* current SubWindow
*/
void VideoSubWindow::enableModule( CalypAppModuleIf* pcModule )
// void VideoSubWindow::enableModule( std::shared_ptr<CalypAppModuleIf> pcModule )
// {
// auto it = std::find_if( m_associatedModules.begin(), m_associatedModules.end(),
// [&]( const auto& module ) { return module.get() == pcModule.get(); } );
// if( it != m_associatedModules.end() )
// {
// m_associatedModules.erase( it );
// }
// m_pcCurrentDisplayModule = std::move( pcModule );
// updateVideoWindowInfo();
// }
bool VideoSubWindow::hasAssociatedModule()
{
if( m_pcCurrentDisplayModule )
if( m_pcCurrentDisplayModule == nullptr )
return !m_associatedModules.empty();
return m_associatedModules.size() > 1;
}
void VideoSubWindow::setDisplayModule( CalypAppModuleIf* pcModule )
{
if( m_pcCurrentDisplayModule != nullptr )
{
disableModule( m_pcCurrentDisplayModule );
m_pcCurrentDisplayModule->disable();
}
m_pcCurrentDisplayModule = pcModule;
updateVideoWindowInfo();
}
void VideoSubWindow::associateModule( std::shared_ptr<CalypAppModuleIf> pcModule )
{
auto it = std::find_if( m_associatedModules.begin(), m_associatedModules.end(),
[&]( const auto& module ) { return module.get() == pcModule.get(); } );
if( it == m_associatedModules.end() )
{
m_associatedModules.push_back( std::move( pcModule ) );
}
}
void VideoSubWindow::disableModule( CalypAppModuleIf* pcModule )
{
if( pcModule == nullptr )
return;
bool bRefresh = false;
if( pcModule )
auto it = std::find_if( m_associatedModules.begin(), m_associatedModules.end(),
[&]( const auto& module ) { return module.get() == pcModule; } );
if( it != m_associatedModules.end() )
{
int modIdx = m_apcCurrentModule.indexOf( pcModule );
if( modIdx != -1 )
{
m_apcCurrentModule.removeAt( modIdx );
ModulesHandle::destroyModuleIf( pcModule );
bRefresh |= true;
}
if( pcModule == m_pcCurrentDisplayModule )
{
pcModule = m_pcCurrentDisplayModule;
m_pcCurrentDisplayModule = 0;
ModulesHandle::destroyModuleIf( pcModule );
setWindowName( QFileInfo( m_cFilename ).fileName() );
bRefresh |= true;
}
m_associatedModules.erase( it );
}
else
if( pcModule == m_pcCurrentDisplayModule )
{
QList<CalypAppModuleIf*> apcCurrentModule = m_apcCurrentModule;
for( int i = 0; i < apcCurrentModule.size(); i++ )
{
m_apcCurrentModule.removeOne( apcCurrentModule.at( i ) );
ModulesHandle::destroyModuleIf( apcCurrentModule.at( i ) );
bRefresh |= true;
}
assert( m_apcCurrentModule.size() == 0 );
if( m_pcCurrentDisplayModule )
{
pcModule = m_pcCurrentDisplayModule;
m_pcCurrentDisplayModule = NULL;
ModulesHandle::destroyModuleIf( pcModule );
setWindowName( QFileInfo( m_cFilename ).fileName() );
bRefresh |= true;
}
bRefresh |= true;
m_pcCurrentDisplayModule = nullptr;
setWindowName( QFileInfo( m_cFilename ).fileName() );
}
if( bRefresh )
{
refreshFrame();
updateVideoWindowInfo();
}
// if( pcModule )
// {
// int modIdx = m_apcCurrentModule.indexOf( pcModule );
// if( modIdx != -1 )
// {
// m_apcCurrentModule.removeAt( modIdx );
// ModulesHandle::destroyModuleIf( pcModule );
// bRefresh |= true;
// }
// if( pcModule == m_pcCurrentDisplayModule )
// {
// pcModule = m_pcCurrentDisplayModule;
// m_pcCurrentDisplayModule = 0;
// ModulesHandle::destroyModuleIf( pcModule );
// setWindowName( QFileInfo( m_cFilename ).fileName() );
// bRefresh |= true;
// }
// }
// else
// {
// QList<CalypAppModuleIf*> apcCurrentModule = m_apcCurrentModule;
// for( int i = 0; i < apcCurrentModule.size(); i++ )
// {
// m_apcCurrentModule.removeOne( apcCurrentModule.at( i ) );
// ModulesHandle::destroyModuleIf( apcCurrentModule.at( i ) );
// bRefresh |= true;
// }
// assert( m_apcCurrentModule.size() == 0 );
// if( m_pcCurrentDisplayModule )
// {
// pcModule = m_pcCurrentDisplayModule;
// m_pcCurrentDisplayModule = NULL;
// ModulesHandle::destroyModuleIf( pcModule );
// setWindowName( QFileInfo( m_cFilename ).fileName() );
// bRefresh |= true;
// }
// }
}
void VideoSubWindow::associateModule( CalypAppModuleIf* pcModule )
bool VideoSubWindow::disableAllModules()
{
m_apcCurrentModule.append( pcModule );
if( m_associatedModules.empty() )
return false;
// For loop is required as we will invalidate the iterator
while( m_associatedModules.size() > 0 )
{
auto module = m_associatedModules.back();
module->disable();
m_associatedModules.pop_back();
}
return true;
}
bool VideoSubWindow::hasRunningModule()
{
bool bRet = false;
if( m_pcCurrentDisplayModule )
for( int i = 0; i < m_associatedModules.size() && !bRet; i++ )
{
bRet |= m_pcCurrentDisplayModule->isRunning();
}
for( int i = 0; i < m_apcCurrentModule.size() && !bRet; i++ )
{
bRet |= m_apcCurrentModule.at( i )->isRunning();
bRet |= m_associatedModules.at( i )->isRunning();
}
return bRet;
}
@@ -714,10 +791,24 @@ void VideoSubWindow::setFillWindow( bool bFlag )
m_pcVideoInfo->setBusyWindow( bFlag );
}
void VideoSubWindow::setCurrFrame( CalypFrame* pcCurrFrame )
std::shared_ptr<CalypFrame> VideoSubWindow::getCurrFrameAsset()
{
m_pcCurrFrame = pcCurrFrame;
m_cViewArea->setImage( m_pcCurrFrame );
if( m_pcCurrFrameAsset == nullptr && m_pCurrStream != nullptr )
{
m_pcCurrFrameAsset = m_pCurrStream->getCurrFrameAsset();
}
return m_pcCurrFrameAsset;
};
void VideoSubWindow::setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame )
{
m_pcCurrFrameAsset = std::move( pcCurrFrame );
m_cViewArea->setImage( m_pcCurrFrameAsset );
for( auto& module : m_associatedModules )
{
if( module.get() != m_pcCurrentDisplayModule )
module->update( m_bIsPlaying );
}
}
void VideoSubWindow::refreshFrameOperation()
@@ -725,22 +816,25 @@ void VideoSubWindow::refreshFrameOperation()
bool bSetFrame = false;
if( m_pCurrStream )
{
m_pcCurrFrame = m_pCurrStream->getCurrFrame();
bSetFrame = m_pcCurrFrame ? true : false;
m_pcCurrFrameAsset = m_pCurrStream->getCurrFrameAsset();
bSetFrame |= true;
}
if( m_pcCurrentDisplayModule )
{
m_bWindowBusy = true;
m_pcCurrentDisplayModule->apply( m_bIsPlaying, !m_bIsPlaying && m_apcCurrentModule.size() );
bool disableThreads = !m_bIsPlaying && hasAssociatedModule();
m_pcCurrentDisplayModule->apply( m_bIsPlaying, disableThreads );
bSetFrame = false;
}
if( bSetFrame )
{
m_cViewArea->setImage( m_pcCurrFrame );
}
for( int i = 0; i < m_apcCurrentModule.size(); i++ )
{
m_apcCurrentModule.at( i )->update( m_bIsPlaying );
m_cViewArea->setImage( m_pcCurrFrameAsset );
for( auto& module : m_associatedModules )
{
if( module.get() != m_pcCurrentDisplayModule )
module->update( m_bIsPlaying );
}
}
}
@@ -764,8 +858,16 @@ bool VideoSubWindow::goToNextFrame( bool bThreaded )
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
m_cReadResult.waitForFinished();
#endif
#ifdef CALYP_MANAGED_RESOURCES
while( !m_pCurrStream->hasNextFrame() && !m_pCurrStream->isEof() )
;
#endif
bool bEndOfSeq = m_pCurrStream->setNextFrame();
#ifdef CALYP_MANAGED_RESOURCES
bThreaded = false;
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
if( !bEndOfSeq )
{
#ifndef QT_NO_CONCURRENT
@@ -773,13 +875,15 @@ bool VideoSubWindow::goToNextFrame( bool bThreaded )
if( bThreaded )
{
m_cReadResult = QtConcurrent::run( m_pCurrStream, &CalypStream::readNextFrameFillRGBBuffer );
refreshFrame();
refreshFrame( bThreaded );
}
else
#endif
{
refreshFrame();
refreshFrame( bThreaded );
#ifndef CALYP_MANAGED_RESOURCES
m_pCurrStream->readNextFrameFillRGBBuffer();
#endif
}
}
return bEndOfSeq;
@@ -790,10 +894,10 @@ bool VideoSubWindow::save( QString filename )
bool iRet = false;
QApplication::setOverrideCursor( Qt::WaitCursor );
CalypFrame* saveFrame = m_pcCurrFrame;
CalypFrame* saveFrame = m_pcCurrFrameAsset.get();
if( m_cSelectedArea.isValid() )
{
saveFrame = new CalypFrame( m_pcCurrFrame, m_cSelectedArea.x(), m_cSelectedArea.y(), m_cSelectedArea.width(),
saveFrame = new CalypFrame( m_pcCurrFrameAsset.get(), m_cSelectedArea.x(), m_cSelectedArea.y(), m_cSelectedArea.width(),
m_cSelectedArea.height() );
}
if( !saveFrame )
@@ -818,7 +922,7 @@ bool VideoSubWindow::saveStream( QString filename )
void VideoSubWindow::setPlaying( bool isPlaying )
{
m_bIsPlaying = isPlaying;
for( auto module : m_apcCurrentModule )
for( auto module : m_associatedModules )
{
module->setPlaying( isPlaying );
}
@@ -868,13 +972,18 @@ void VideoSubWindow::pause()
void VideoSubWindow::seekAbsoluteEvent( unsigned int new_frame_num )
{
if( m_pCurrStream )
{
if( m_pCurrStream->seekInput( new_frame_num ) )
refreshFrame();
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
}
}
void VideoSubWindow::seekRelativeEvent( bool bIsFoward )
{
bool bRefresh = false;
if( m_pCurrStream )
{
if( bIsFoward )
@@ -883,13 +992,13 @@ void VideoSubWindow::seekRelativeEvent( bool bIsFoward )
}
else
{
bRefresh = m_pCurrStream->seekInputRelative( bIsFoward );
m_pCurrStream->seekInputRelative( bIsFoward );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
refreshFrame();
}
}
if( bRefresh )
{
refreshFrame();
}
}
void VideoSubWindow::stop()
@@ -1038,8 +1147,8 @@ void VideoSubWindow::scaleView( double scale, QPoint center )
void VideoSubWindow::scaleView( const QSize& size, QPoint center )
{
QSize imgViewSize;
if( m_pcCurrFrame )
imgViewSize = QSize( m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight() );
if( m_pcCurrFrameAsset )
imgViewSize = QSize( m_pcCurrFrameAsset->getWidth(), m_pcCurrFrameAsset->getHeight() );
else
imgViewSize = QSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() );
QSize newSize = imgViewSize;
@@ -1069,22 +1178,22 @@ void VideoSubWindow::scaleView( const QSize& size, QPoint center )
void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos )
{
if( m_pcCurrFrame )
if( m_pcCurrFrameAsset )
{
int iWidth, iHeight;
int posX = pos.x();
int posY = pos.y();
QString strStatus;
iWidth = m_pcCurrFrame->getWidth();
iHeight = m_pcCurrFrame->getHeight();
iWidth = m_pcCurrFrameAsset->getWidth();
iHeight = m_pcCurrFrameAsset->getHeight();
if( ( posX < iWidth ) && ( posX >= 0 ) && ( posY < iHeight ) && ( posY >= 0 ) )
{
strStatus = QString( "(%1,%2) " ).arg( posX ).arg( posY );
int colorSpace = m_pcCurrFrame->getColorSpace();
CalypPixel pixelValue = m_pcCurrFrame->getPixel( pos.x(), pos.y() );
int colorSpace = m_pcCurrFrameAsset->getColorSpace();
CalypPixel pixelValue = m_pcCurrFrameAsset->getPixel( pos.x(), pos.y() );
switch( colorSpace )
{
case CLP_COLOR_GRAY:
+36 -20
View File
@@ -31,6 +31,7 @@
#include <QString>
#include <QVector>
#include "CalypAppModuleIf.h"
#include "CommonDefs.h"
#include "SubWindowAbstract.h"
#include "ViewArea.h"
@@ -41,6 +42,7 @@ class QScrollArea;
class VideoInformation;
class VideoSubWindow;
class ResourceHandle;
class CalypAppModuleIf;
typedef struct
@@ -65,6 +67,8 @@ class VideoSubWindow : public SubWindowAbstract
Q_OBJECT
private:
ResourceHandle* m_pcResourceManager;
bool m_bWindowBusy;
QScrollArea* m_pcScrollArea;
@@ -79,13 +83,15 @@ private:
QString m_cFilename;
QString m_cStreamInformation;
CalypFileInfo m_sStreamInfo;
std::size_t m_uiResourceId;
CalypStream* m_pCurrStream;
CalypFrame* m_pcCurrFrame;
std::shared_ptr<CalypFrame> m_pcCurrFrameAsset;
//CalypFrame* m_pcCurrFrame;
QRect m_cSelectedArea;
CalypAppModuleIf* m_pcCurrentDisplayModule;
QList<CalypAppModuleIf*> m_apcCurrentModule;
CalypAppModuleIf* m_pcCurrentDisplayModule{ nullptr };
std::vector<std::shared_ptr<CalypAppModuleIf>> m_associatedModules;
bool m_hasAssociatedModules;
VideoSubWindow* m_pcReferenceSubWindow;
@@ -109,8 +115,11 @@ public:
MODULE_SUBWINDOW = SubWindowAbstract::MODULE_SUBWINDOW,
};
VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent = 0 );
VideoSubWindow( enum VideoSubWindowCategories category, CalypAppModuleIf* displayModule, QWidget* parent = 0 );
~VideoSubWindow();
void setResourceManaget( ResourceHandle* resourceManager ) { m_pcResourceManager = resourceManager; }
void updateVideoWindowInfo();
bool loadFile( QString cFilename, bool bForceDialog = false );
@@ -132,19 +141,20 @@ public:
void seekAbsoluteEvent( unsigned int new_frame_num );
void seekRelativeEvent( bool bIsFoward );
void setCurrFrame( CalypFrame* pcCurrFrame );
void setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame );
CalypFileInfo getStreamInfo() { return m_sStreamInfo; }
QString getStreamInformation() { return m_cStreamInformation; }
CalypStream* getInputStream() { return m_pCurrStream; }
CalypStream* getCurrStream() { return m_pCurrStream; }
CalypFrame* getCurrFrame() { return m_pcCurrFrame; }
const CalypStream* getInputStream() { return m_pCurrStream; }
const CalypStream* getCurrStream() { return m_pCurrStream; }
CalypFrame* getCurrFrame() { return m_pcCurrFrameAsset.get(); }
std::shared_ptr<CalypFrame> getCurrFrameAsset();
ViewArea* getViewArea() { return m_cViewArea; }
void setRefSubWindow( VideoSubWindow* subWindow )
{
m_pcReferenceSubWindow = NULL;
if( subWindow )
if( m_pcCurrFrame->haveSameFmt( subWindow->getCurrFrame() ) )
if( m_pcCurrFrameAsset->haveSameFmt( subWindow->getCurrFrame() ) )
m_pcReferenceSubWindow = subWindow;
}
@@ -153,17 +163,23 @@ public:
* Functions to enable a module in the
* current SubWindow
*/
void enableModule( CalypAppModuleIf* pcModule );
void disableModule( CalypAppModuleIf* pcModule = NULL );
void associateModule( CalypAppModuleIf* pcModule );
//void enableModule( std::shared_ptr<CalypAppModuleIf> pcModule );
bool hasAssociatedModule();
void setDisplayModule( CalypAppModuleIf* pcModule );
void associateModule( std::shared_ptr<CalypAppModuleIf> pcModule );
void disableModule( CalypAppModuleIf* pcModule );
bool disableAllModules();
CalypAppModuleIf* getDisplayModule() { return m_pcCurrentDisplayModule; }
QList<CalypAppModuleIf*> getModuleArray()
QVector<CalypAppModuleIf*> getModuleArray()
{
QList<CalypAppModuleIf*> apcModulesArray;
QVector<CalypAppModuleIf*> apcModulesArray;
if( m_pcCurrentDisplayModule )
apcModulesArray.append( m_pcCurrentDisplayModule );
apcModulesArray.append( m_apcCurrentModule );
for( const auto& module : m_associatedModules )
{
apcModulesArray.append( module.get() );
}
return apcModulesArray;
}
@@ -206,9 +222,9 @@ private:
QSize getScrollSize();
protected:
void keyPressEvent( QKeyEvent* event );
void resizeEvent( QResizeEvent* event );
void closeEvent( QCloseEvent* event );
void keyPressEvent( QKeyEvent* event ) override;
void resizeEvent( QResizeEvent* event ) override;
void closeEvent( QCloseEvent* event ) override;
public Q_SLOTS:
void updateWindowOnTimeout();
@@ -219,7 +235,7 @@ public Q_SLOTS:
void updatePixelValueStatusBar( const QPoint& pos );
};
Q_DECLARE_METATYPE( CalypFileInfo )
Q_DECLARE_METATYPE( CalypFileInfoVector )
Q_DECLARE_METATYPE( CalypFileInfo ) // NOLINT
Q_DECLARE_METATYPE( CalypFileInfoVector ) // NOLINT
#endif // __VIDEOSUBWINDOW_H__
+59 -68
View File
@@ -48,9 +48,6 @@ ViewArea::ViewArea( QWidget* parent )
: QWidget( parent )
{
setMouseTracking( true );
m_pcCurrFrame = NULL;
m_pixmap = QPixmap();
m_grid = GridManager();
m_mask = QBitmap();
m_selectedArea = QRect();
@@ -69,31 +66,27 @@ ViewArea::ViewArea( QWidget* parent )
connect( &m_zoomWinTimer, SIGNAL( timeout() ), this, SLOT( update() ) );
}
void ViewArea::setImage( CalypFrame* pcFrame )
void ViewArea::setImage( std::shared_ptr<CalypFrame> frame )
{
m_pcCurrFrame = pcFrame;
m_uiPixelHalfScale = 1 << ( m_pcCurrFrame->getBitsPel() - 1 );
m_pcCurrFrame->fillRGBBuffer();
QImage qimg = QImage( m_pcCurrFrame->getRGBBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(),
QImage::Format_ARGB32 );
setImage( QPixmap::fromImage( qimg ) );
}
m_nextFrame = frame;
m_uiPixelHalfScale = 1 << ( m_nextFrame->getBitsPel() - 1 );
m_nextFrame->fillRGBBuffer();
m_image = QImage( m_nextFrame->getRGBBuffer(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
void ViewArea::setImage( const QPixmap& pixmap )
{
m_pixmap = pixmap;
m_mask = QBitmap( pixmap.width(), pixmap.height() );
m_mask.clear();
// m_mask = QBitmap( pixmap.width(), pixmap.height() );
// m_mask.clear();
updateSize();
update();
updateGeometry();
initZoomWinRect();
}
void ViewArea::clear()
{
m_pixmap = QPixmap();
m_image = QImage();
m_mask = QBitmap();
m_mode = NormalMode;
updateSize();
@@ -167,7 +160,7 @@ void ViewArea::setZoomFactor( double f )
double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize )
{
double maxZoom = 100.0;
double minZoom = 0.01; //( 1.0 / m_pixmap.width() );
double minZoom = 0.01; //( 1.0 / m_image.width() );
double new_scale = 1.0;
if( ( m_dZoomFactor == minZoom ) && ( scale < 1 ) )
@@ -183,10 +176,10 @@ double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize
if( !minimumSize.isNull() )
{
double cw = m_pixmap.width() * m_dZoomFactor;
double ch = m_pixmap.height() * m_dZoomFactor;
double fw = m_pixmap.width() * newZoomFactor;
double fh = m_pixmap.height() * newZoomFactor;
double cw = m_image.width() * m_dZoomFactor;
double ch = m_image.height() * m_dZoomFactor;
double fw = m_image.width() * newZoomFactor;
double fh = m_image.height() * newZoomFactor;
double mw = minimumSize.width();
double mh = minimumSize.height();
@@ -319,45 +312,45 @@ void ViewArea::setSnapToGrid( bool enable )
void ViewArea::initZoomWinRect()
{
int iMinX = 80;
int iMinY = 80;
double iMinX = 80;
double iMinY = 80;
int iMaxX = iMinX * 5;
int iMaxY = iMinY * 5;
double iMaxX = iMinX * 5;
double iMaxY = iMinY * 5;
double dSizeRatio, dWinZoomRatio;
int iHorizontalImg = ( m_pixmap.width() > m_pixmap.height() ) ? 1 : 0;
bool iHorizontalImg = m_image.width() > m_image.height();
if( iHorizontalImg )
{
dSizeRatio = (double)m_pixmap.width() / (double)m_pixmap.height();
dSizeRatio = (double)m_image.width() / (double)m_image.height();
}
else
{
dSizeRatio = (double)m_pixmap.height() / (double)m_pixmap.width();
dSizeRatio = (double)m_image.height() / (double)m_image.width();
}
if( dSizeRatio > 5.0 )
{
if( iHorizontalImg )
{
dWinZoomRatio = (double)( m_pixmap.width() * 1024 / iMaxX ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.width() ) * 1024.0 / iMaxX / 1000.0;
}
else
{
dWinZoomRatio = (double)( m_pixmap.height() * 1024 / iMaxY ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.height() ) * 1024.0 / iMaxY / 1000.0;
}
}
else
{
if( iHorizontalImg )
{
dWinZoomRatio = (double)( m_pixmap.height() * 1024 / iMinY ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.height() ) * 1024.0 / iMinY / 1000.0;
}
else
{
dWinZoomRatio = (double)( m_pixmap.width() * 1024 / iMinX ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.width() ) * 1024.0 / iMinX / 1000.0;
}
}
@@ -369,8 +362,8 @@ void ViewArea::initZoomWinRect()
////////////////////////////////////////////////////////////////////////////////
void ViewArea::updateSize()
{
int w = m_pixmap.width() * m_dZoomFactor;
int h = m_pixmap.height() * m_dZoomFactor;
int w = m_image.width() * m_dZoomFactor;
int h = m_image.height() * m_dZoomFactor;
setMinimumSize( w, h );
QWidget* p = parentWidget();
@@ -388,17 +381,17 @@ void ViewArea::updateSize()
void ViewArea::updateOffset()
{
if( width() > m_pixmap.width() * m_dZoomFactor )
if( width() > m_image.width() * m_dZoomFactor )
{
m_xOffset = ( width() - m_pixmap.width() * m_dZoomFactor ) / 2;
m_xOffset = ( width() - m_image.width() * m_dZoomFactor ) / 2;
}
else
{
m_xOffset = 0;
}
if( height() > m_pixmap.height() * m_dZoomFactor )
if( height() > m_image.height() * m_dZoomFactor )
{
m_yOffset = ( height() - m_pixmap.height() * m_dZoomFactor ) / 2;
m_yOffset = ( height() - m_image.height() * m_dZoomFactor ) / 2;
}
else
{
@@ -411,7 +404,7 @@ void ViewArea::updateOffset()
////////////////////////////////////////////////////////////////////////////////
void ViewArea::resizeEvent( QResizeEvent* event )
{
if( size().isEmpty() || m_pixmap.isNull() )
if( size().isEmpty() || m_image.isNull() )
return;
updateOffset();
@@ -424,12 +417,11 @@ void ViewArea::resizeEvent( QResizeEvent* event )
void ViewArea::paintEvent( QPaintEvent* event )
{
m_currFrame = m_nextFrame;
QRect winRect = event->rect();
if( visibleRegion().isEmpty() )
return;
if( size().isEmpty() || m_pixmap.isNull() )
if( visibleRegion().isEmpty() || size().isEmpty() || m_image.isNull() || m_currFrame == nullptr )
return;
QSize windowSize = parentWidget()->size();
@@ -442,15 +434,14 @@ void ViewArea::paintEvent( QPaintEvent* event )
// This line is for fast paiting. Only visible area of the image is painted.
// We take the exposed rect from the event (that gives us scroll/expose
// optimizations for free – no need
// to draw the whole pixmap if your widget is only partially exposed), and
// reverse map it with the painter matrix.
// optimizations for free – no need to draw the whole pixmap if your widget
// is only partially exposed), and reverse map it with the painter matrix.
// That gives us the part of the pixmap that has actually been exposed.
// See:
// http://blog.qt.digia.com/blog/2006/05/13/fast-transformed-pixmapimage-drawing/
QRect exposedRect = painter.worldTransform().inverted().mapRect( event->rect() ).adjusted( -1, -1, 1, 1 );
// See: http://blog.qt.digia.com/blog/2006/05/13/fast-transformed-pixmapimage-drawing/
QRect exposedRect = painter.worldTransform().inverted().mapRect( winRect ).adjusted( -1, -1, 1, 1 );
// Draw the pixmap.
painter.drawPixmap( exposedRect, m_pixmap, exposedRect );
// painter.drawPixmap( exposedRect, m_pixmap, exposedRect );
painter.drawImage( exposedRect, m_image, exposedRect );
// Draw the Grid if it's visible.
if( m_bGridVisible )
@@ -468,13 +459,13 @@ void ViewArea::paintEvent( QPaintEvent* event )
// is, is referenced to the not scaled image.
// To know what image area we need to update, just intersects the
// rectangle area with the image area.
vr &= QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
vr &= QRect( 0, 0, m_image.width(), m_image.height() );
// Set up for the grid drawer.
painter.setRenderHint( QPainter::Antialiasing );
// Draw grid.
m_grid.drawGrid( m_pixmap, vr, &painter );
m_grid.drawGrid( m_image, vr, &painter );
}
painter.restore();
@@ -483,18 +474,18 @@ void ViewArea::paintEvent( QPaintEvent* event )
/* if( m_xOffset || m_yOffset )
{
painter.setPen( Qt::black );
painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_pixmap.width() *
m_dZoomFactor + 1, m_pixmap.height() *
painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_image.width() *
m_dZoomFactor + 1, m_image.height() *
m_dZoomFactor + 1 );
}*/
int frFormat = m_pcCurrFrame->getColorSpace();
int frFormat = m_currFrame->getColorSpace();
// Draw pixel values in grid
if( m_dZoomFactor >= 60.0 || ( frFormat != CLP_COLOR_RGBA && m_dZoomFactor >= 50.0 ) )
{
int imageWidth = m_pixmap.width();
int imageHeight = m_pixmap.height();
int imageWidth = m_image.width();
int imageHeight = m_image.height();
;
QFont font( "Helvetica" );
@@ -512,7 +503,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
QRect pixelRect( viewToWindow( pixelTopLeft ), QSize( m_dZoomFactor, m_dZoomFactor ) );
QString pixelValue;
CalypPixel pixel = m_pcCurrFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
CalypPixel pixel = m_currFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
if( frFormat == CLP_COLOR_YUV || frFormat == CLP_COLOR_GRAY )
{
@@ -559,15 +550,15 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.drawLine( viewToWindow( QPoint( 0, y ) ), viewToWindow( QPoint( imageWidth, y ) ) );
}
}
bool showZoomRect = m_pixmap.width() * m_dZoomFactor > windowSize.width() ||
m_pixmap.height() * m_dZoomFactor > windowSize.height();
bool showZoomRect = m_image.width() * m_dZoomFactor > windowSize.width() ||
m_image.height() * m_dZoomFactor > windowSize.height();
// VISIBLE ZOOM RECT
if( m_visibleZoomRect && m_zoomWinTimer.isActive() && showZoomRect )
{
double dRatio = m_dZoomWinRatio;
QRect cImg = QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
QRect cImg = QRect( 0, 0, m_image.width(), m_image.height() );
QPoint cZWinRBpos = QPoint( winRect.bottomRight() ) - QPoint( 15, 15 );
QRect cImgWinRect( 0, 0, round( (double)cImg.width() / dRatio ), round( (double)cImg.height() / dRatio ) );
cImgWinRect.moveBottomRight( cZWinRBpos );
@@ -585,7 +576,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.setPen( QColor( 50, 50, 50, 128 ) );
//painter.drawRect( cImgWinRect );
painter.setOpacity( 0.7 );
painter.drawPixmap( cImgWinRect, m_pixmap );
painter.drawImage( cImgWinRect, m_image );
painter.setOpacity( 1 );
cVisibleWinRect.moveTopLeft( cImgWinRect.topLeft() + cVisibleWinRect.topLeft() );
@@ -642,7 +633,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.setBrush( fill );
painter.setPen( Qt::NoPen );
QPainterPath myPath;
QRect imgr = viewToWindow( QRect( 0, 0, m_pixmap.width(), m_pixmap.height() ) );
QRect imgr = viewToWindow( QRect( 0, 0, m_image.width(), m_image.height() ) );
myPath.addRect( imgr );
myPath.addRect( sr ); // m_selectedArea
@@ -916,7 +907,7 @@ void ViewArea::mouseMoveEvent( QMouseEvent* event )
// intercept the selected area with the image area to limit the
// selection only to the image area, preventing it to come outside
// the image.
m_selectedArea &= QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
m_selectedArea &= QRect( 0, 0, m_image.width(), m_image.height() );
// Update only the united area
// updateRect = updateRect.united( viewToWindow( m_selectedArea ) );
@@ -1000,7 +991,7 @@ void ViewArea::mouseReleaseEvent( QMouseEvent* event )
bool ViewArea::isPosValid( const QPoint& pos ) const
{
if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_pixmap.width() || pos.y() >= m_pixmap.height() )
if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_image.width() || pos.y() >= m_image.height() )
return false;
else
return true;
@@ -1091,6 +1082,6 @@ void ViewArea::updateMask( const QRect& rect )
break;
}
default: /* Do Nothing */
;
;
}
}
+6 -6
View File
@@ -56,8 +56,8 @@ public:
ViewArea( QWidget* parent = 0 );
void setImage( CalypFrame* pcFrame );
void setImage( const QPixmap& pixmap );
QImage& image() { return m_image; };
void setImage( std::shared_ptr<CalypFrame> frame );
void setMode( int mode );
void setMaskColor( const QColor& color = QColor() );
@@ -83,8 +83,6 @@ public:
*/
void clearMask();
QPixmap image() const { return m_pixmap; }
QBitmap mask() const { return m_mask; }
QRect selectedArea() const { return m_selectedArea; }
GridManager gridManager() const { return m_grid; }
QColor maskColor() const { return m_maskColor; }
@@ -150,7 +148,8 @@ private:
QPoint viewToWindow( const QPoint& pt ) const;
QRect viewToWindow( const QRect& rc ) const;
CalypFrame* m_pcCurrFrame;
std::shared_ptr<CalypFrame> m_currFrame;
std::shared_ptr<CalypFrame> m_nextFrame;
ClpPel m_uiPixelHalfScale;
@@ -161,7 +160,8 @@ private:
double m_dZoomWinRatio;
double m_dZoomFactor;
QPixmap m_pixmap;
QImage m_image;
//QPixmap m_pixmap;
QBitmap m_mask;
QRect m_selectedArea;
QPoint m_lastPos;
+1 -1
View File
@@ -33,7 +33,7 @@
#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()
{
m_iSelectedFrameNum = pcCurrStream->getCurrFrameNum();
+1 -1
View File
@@ -42,7 +42,7 @@ class SeekStreamDialog : public QDialog
Q_OBJECT
public:
SeekStreamDialog( CalypStream* pcCurrStream, QWidget* parent = 0 );
SeekStreamDialog( const CalypStream* pcCurrStream, QWidget* parent = 0 );
int runDialog();
private:
+9 -2
View File
@@ -230,6 +230,8 @@ FramePropertiesDock::FramePropertiesDock( QWidget* parent, bool* pbMainPlaySwitc
statisticsLayout->addWidget( labelStdDevValue, gridRow++, 1 );
statisticsLayout->addWidget( medianLabel, gridRow, 0 );
statisticsLayout->addWidget( labelMedianValue, gridRow++, 1 );
statisticsLayout->addWidget( percentileLabel, gridRow, 0 );
statisticsLayout->addWidget( labelPercentileValue, gridRow++, 1 );
statisticsLayout->addWidget( entropyLabel, gridRow, 0 );
statisticsLayout->addWidget( labelEntropyValue, gridRow++, 1 );
@@ -278,11 +280,15 @@ QSize FramePropertiesDock::sizeHint() const
void FramePropertiesDock::reset()
{
m_pcFrame = nullptr;
m_pcSelectedFrame = nullptr;
m_bHasFrame = false;
m_cSelectionArea = QRect();
m_iLastFrameType = -1;
labelRangeValue->clear();
labelNEBinsValue->clear();
labelMeanValue->clear();
labelPixelsValue->clear();
@@ -290,6 +296,7 @@ void FramePropertiesDock::reset()
labelCountValue->clear();
labelMedianValue->clear();
labelPercentileValue->clear();
labelEntropyValue->clear();
// Remove the histogram data from memory
histogramWidget->reset();
@@ -297,7 +304,7 @@ void FramePropertiesDock::reset()
setEnabled( false );
}
void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
void FramePropertiesDock::setFrame( std::shared_ptr<CalypFrame> pcFrame, bool isPlaying )
{
int colorSpace = pcFrame->getColorSpace();
if( m_iLastFrameType != colorSpace )
@@ -365,7 +372,7 @@ void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
if( pcFrame )
{
m_bHasFrame = true;
m_pcFrame = std::make_shared<CalypFrame>( *pcFrame );
m_pcFrame = pcFrame;
}
else
{
+1 -1
View File
@@ -43,7 +43,7 @@ public:
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 reset();
void stopHistogram();
+4 -6
View File
@@ -58,9 +58,9 @@ ModuleHandleDock::ModuleHandleDock( QWidget* parent, CalypAppModuleIf* moduleIf
setEnabled( true );
}
ModuleHandleDock::~ModuleHandleDock() {}
ModuleHandleDock::~ModuleHandleDock() = default;
void ModuleHandleDock::setModulueReturnValue( double value )
void ModuleHandleDock::setModuleReturnValue( double value )
{
labelModulueReturnValue->clear();
QString strValue = QString( "%1" ).arg( value );
@@ -69,11 +69,9 @@ void ModuleHandleDock::setModulueReturnValue( double value )
void ModuleHandleDock::visibilityChangedSlot( bool visiblity )
{
if( !visiblity && m_pcCurrModuleIf )
if( !visiblity )
{
CalypAppModuleIf* pcCurrentModule = m_pcCurrModuleIf;
m_pcCurrModuleIf = NULL;
ModulesHandle::destroyModuleIf( pcCurrentModule );
m_pcCurrModuleIf->disable();
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ public:
ModuleHandleDock( QWidget* parent, CalypAppModuleIf* moduleIf );
~ModuleHandleDock();
void setModulueReturnValue( double value );
void setModuleReturnValue( double value );
QSize sizeHint() const;
+9 -2
View File
@@ -49,6 +49,11 @@ public:
m_parent = parent;
}
void reset()
{
m_pcFrame = nullptr;
}
void setup( std::shared_ptr<CalypFrame> frame )
{
m_pcFrame = frame;
@@ -230,8 +235,10 @@ void HistogramWidget::reset()
d->guideVisible = false;
d->clearFlag = HistogramWidgetPrivate::HistogramNone;
// Remove histogram data from memory.
m_fullImage = NULL;
m_selectionImage = NULL;
m_fullImage = nullptr;
m_selectionImage = nullptr;
m_imageWorker->setup( nullptr );
m_selectionWorker->setup( nullptr );
update();
}
+3
View File
@@ -55,4 +55,7 @@
/* Fervor update lib */
#cmakedefine USE_FERVOR
/* Use a resource manager to manage streams in different threads */
#cmakedefine CALYP_MANAGED_RESOURCES
#endif // __CONFIG_CALYP_H__
+4 -2
View File
@@ -26,6 +26,8 @@
#ifndef __CALYPDEFS_H__
#define __CALYPDEFS_H__
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
@@ -106,14 +108,14 @@ static const double S_PI_2 = 1.57079632679489661923;
inline ClpString clpLowercase( const ClpString& in )
{
ClpString out;
transform( in.begin(), in.end(), std::back_inserter( out ), tolower );
std::transform( in.begin(), in.end(), std::back_inserter( out ), tolower );
return out;
}
inline ClpString clpUppercase( const ClpString& in )
{
ClpString out;
transform( in.begin(), in.end(), std::back_inserter( out ), toupper );
std::transform( in.begin(), in.end(), std::back_inserter( out ), toupper );
return out;
}
+40 -43
View File
@@ -28,7 +28,6 @@
#include <cmath>
#include <cstdint>
#include <memory>
#include <span>
#include <vector>
#include "LibMemory.h"
@@ -41,6 +40,9 @@
#include <opencv2/imgproc/imgproc.hpp>
#endif
constexpr auto kMinBitsPerPixel = 8;
constexpr auto kMaxBitsPerPixel = 16;
std::vector<ClpString> CalypFrame::supportedColorSpacesListNames()
{
return std::vector<ClpString>{
@@ -74,7 +76,7 @@ std::vector<ClpString> CalypFrame::supportedPixelFormatListNames( int colorSpace
int CalypFrame::numberOfFormats()
{
return g_CalypPixFmtDescriptorsMap.size();
return static_cast<int>( g_CalypPixFmtDescriptorsMap.size() );
}
int CalypFrame::findPixelFormat( const ClpString& name )
@@ -95,40 +97,39 @@ int CalypFrame::pelformatColorSpace( const int idx )
class CalypFrame::CalypFramePrivate
{
public:
bool m_bInit;
bool m_bInit{ false };
//! Struct with the pixel format description.
const CalypPixelFormatDescriptor* m_pcPelFormat;
const CalypPixelFormatDescriptor* m_pcPelFormat{ nullptr };
ClpString m_cPelFmtName;
unsigned int m_uiWidth; //!< Width of the frame
unsigned int m_uiHeight; //!< Height of the frame
int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats)
unsigned int m_uiBitsPel; //!< Bits per pixel/channel
unsigned int m_uiHalfPelValue; //!< Bits per pixel/channel
bool m_bHasNegativeValues; //!< Half of the scale correspond to negative values
unsigned int m_uiWidth{ 0 }; //!< Width of the frame
unsigned int m_uiHeight{ 0 }; //!< Height of the frame
int m_iPixelFormat{ 0 }; //!< Pixel format number (it follows the list of supported pixel formats)
unsigned int m_uiBitsPel{ 0 }; //!< Bits per pixel/channel
unsigned int m_uiHalfPelValue{ 0 }; //!< Bits per pixel/channel
bool m_bHasNegativeValues{ false }; //!< Half of the scale correspond to negative values
ClpPel*** m_pppcInputPel;
ClpPel*** m_pppcInputPel{ nullptr };
bool m_bHasRGBPel; //!< Flag indicating that the ARGB buffer was computed
bool m_bHasRGBPel{ false }; //!< Flag indicating that the ARGB buffer was computed
std::vector<std::uint8_t> m_pcARGB32; //!< Buffer with the ARGB pixels used in Qt libs
/** Histogram control variables **/
bool m_bHasHistogram;
bool m_bHistogramRunning;
bool m_bHasHistogram{ false };
bool m_bHistogramRunning{ false };
/** The histogram data.*/
std::vector<unsigned int> m_puiHistogram;
/** If the image is RGB and calcLuma is true, we have 1 more channel */
unsigned int m_uiHistoChannels;
unsigned int m_uiHistoChannels{ 0 };
/** Numbers of histogram segments depending of image bytes depth*/
unsigned int m_uiHistoSegments;
unsigned int m_uiHistoSegments{ 0 };
CalypFramePrivate()
{
m_bInit = false;
m_bHasRGBPel = false;
m_pppcInputPel = nullptr;
}
CalypFramePrivate() = default;
CalypFramePrivate( const CalypFramePrivate& ) = delete;
CalypFramePrivate( CalypFramePrivate&& ) = delete;
CalypFramePrivate& operator=( const CalypFramePrivate& ) = delete;
CalypFramePrivate& operator=( CalypFramePrivate&& ) = delete;
void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel )
{
@@ -140,11 +141,11 @@ public:
m_uiWidth = width;
m_uiHeight = height;
m_iPixelFormat = pel_format;
m_uiBitsPel = bitsPixel < 8 ? 8 : bitsPixel;
m_uiBitsPel = bitsPixel < kMinBitsPerPixel ? kMinBitsPerPixel : bitsPixel;
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
m_bHasNegativeValues = has_negative_values;
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > kMaxBitsPerPixel )
{
throw CalypFailure( "CalypFrame", "Cannot create a CalypFrame of this type" );
}
@@ -519,7 +520,7 @@ ClpPel*** CalypFrame::getPelBufferYUV()
return d->m_pppcInputPel;
}
unsigned char* CalypFrame::getRGBBuffer() const
auto CalypFrame::getRGBBuffer() const -> const unsigned char*
{
if( d->m_bHasRGBPel )
{
@@ -797,7 +798,7 @@ void fillRGBBufferYUV420p( ClpPel*** pppInputPel, uint32_t* pARGB, unsigned uiWi
}
}
void CalypFrame::fillRGBBuffer()
void CalypFrame::fillRGBBuffer() const
{
if( d->m_bHasRGBPel )
return;
@@ -809,7 +810,7 @@ void CalypFrame::fillRGBBuffer()
if( d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY )
{
ClpPel* pY = d->m_pppcInputPel[CLP_LUMA][0];
unsigned char finalPel;
unsigned char finalPel{ 0 };
for( unsigned int i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ )
{
finalPel = ( *pY++ ) >> shiftBits;
@@ -844,32 +845,28 @@ void CalypFrame::fillRGBBuffer()
ClpPel* pLineU = d->m_pppcInputPel[CLP_CHROMA_U][0];
ClpPel* pLineV = d->m_pppcInputPel[CLP_CHROMA_V][0];
unsigned int uiChromaStride = CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth );
ClpPel* pY;
ClpPel* pU;
ClpPel* pV;
int iY, iU, iV, iR, iG, iB;
int iR, iG, iB;
uint32_t* pARGBLine = pARGB;
uint32_t* pARGBAux;
unsigned int y, x;
int i, j;
for( y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ )
for( int y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ )
{
for( i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ )
for( int i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ )
{
pY = pLineY;
pU = pLineU;
pV = pLineV;
ClpPel* pY = pLineY;
ClpPel* pU = pLineU;
ClpPel* pV = pLineV;
pARGBAux = pARGBLine;
for( x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ )
for( int x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ )
{
iU = *pU++;
int iU = *pU++;
iU >>= shiftBits;
iV = *pV++;
int iV = *pV++;
iV >>= shiftBits;
for( j = 0; j < ( 1 << d->m_pcPelFormat->log2ChromaWidth ); j++ )
for( int j = 0; j < ( 1 << d->m_pcPelFormat->log2ChromaWidth ); j++ )
{
iY = *pY++;
int iY = *pY++;
iY >>= shiftBits;
YUV2RGB( iY, iU, iV, iR, iG, iB );
*pARGBAux++ = PEL_RGB( iR, iG, iB );
+2 -3
View File
@@ -26,7 +26,6 @@
#ifndef __CALYPFRAME_H__
#define __CALYPFRAME_H__
#include <span>
#include <vector>
#include "CalypDefs.h"
@@ -295,7 +294,7 @@ public:
ClpPel*** getPelBufferYUV() const;
ClpPel*** getPelBufferYUV();
unsigned char* getRGBBuffer() const;
auto getRGBBuffer() const -> const unsigned char*;
/**
* Get pixel value at coordinates
@@ -371,7 +370,7 @@ public:
void frameFromBuffer( const std::vector<ClpByte>&, int );
void frameToBuffer( std::vector<ClpByte>&, int ) const;
void fillRGBBuffer();
void fillRGBBuffer() const;
/**
* Histogram
+7 -6
View File
@@ -34,17 +34,17 @@
* @}
*/
#include <memory>
#include <vector>
#include "CalypFrame.h"
#include "CalypOptions.h"
#define REGISTER_CLASS_MAKER( X ) \
extern "C" CalypModuleIf* Maker() { return new X; }
#define REGISTER_CLASS_FACTORY( X ) \
public: \
static CalypModuleIf* Create() { return new X(); } \
void Delete() { delete this; }
extern "C" CalypModulePtr Maker() { return std::make_unique<X>(); }
#define REGISTER_CLASS_FACTORY( X ) \
public: \
static CalypModulePtr Create() { return std::make_unique<X>(); }
#define _BASIC_MODULE_API_2_CHECK_ \
if( apcFrameList.size() != m_uiNumberOfFrames ) \
return false; \
@@ -140,7 +140,6 @@ public:
m_iFrameBufferCount = 0;
}
virtual ~CalypModuleIf() {}
virtual void Delete() = 0;
virtual void destroy() = 0;
const char* getModuleLongName()
@@ -174,4 +173,6 @@ public:
};
};
using CalypModulePtr = std::unique_ptr<CalypModuleIf>;
#endif // __CALYPMODULESIF_H__
+194 -128
View File
@@ -25,6 +25,12 @@
// Self
#include "CalypStream.h"
#include <cassert>
#include <deque>
#include <iostream>
#include <memory>
#include <mutex>
#include "CalypFrame.h"
#include "CalypStreamHandlerIf.h"
#include "LibMemory.h"
@@ -40,6 +46,9 @@
#include <cstdio>
constexpr auto kDefaultBitsPerPixel = 8;
constexpr auto kDefaultFrameRate = 30;
std::vector<CalypStreamFormat> CalypStream::supportedReadFormats()
{
INI_REGIST_CALYP_SUPPORTED_FMT;
@@ -96,94 +105,139 @@ std::vector<CalypStandardResolution> CalypStream::stdResolutionSizes()
return stdResList;
}
class CalypStreamBufferPrivate
struct CalypStreamFrameBuffer : std::enable_shared_from_this<CalypStreamFrameBuffer>
{
private:
std::vector<CalypFrame> m_apcFrameBuffer;
unsigned int m_uiIndex;
std::mutex buffer_mutex;
std::vector<std::unique_ptr<CalypFrame>> framePool;
std::size_t bufferIdx{ 0 };
public:
CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, unsigned int bitsPixel, bool hasNegative )
CalypStreamFrameBuffer( std::size_t size, unsigned int width, unsigned int height, int pelFormat, unsigned int bitsPixel, bool hasNegative )
{
for( unsigned int i = 0; i < size; i++ )
framePool.reserve( size );
for( std::size_t i = 0; i < size; i++ )
{
m_apcFrameBuffer.push_back( CalypFrame{ width, height, pelFormat, bitsPixel, hasNegative } );
framePool.push_back( std::make_unique<CalypFrame>( width, height, pelFormat, bitsPixel, hasNegative ) );
}
m_uiIndex = 0;
bufferIdx = framePool.size();
}
~CalypStreamBufferPrivate() = default;
CalypStreamFrameBuffer( const CalypStreamFrameBuffer& ) = delete;
CalypStreamFrameBuffer( CalypStreamFrameBuffer&& ) = delete;
CalypStreamFrameBuffer& operator=( const CalypStreamFrameBuffer& ) = delete;
CalypStreamFrameBuffer& operator=( CalypStreamFrameBuffer&& ) = delete;
void increase( unsigned int newSize )
~CalypStreamFrameBuffer() = default;
void increase( std::size_t newSize )
{
for( unsigned int i = m_apcFrameBuffer.size(); i < newSize; i++ )
framePool.reserve( newSize );
auto oldSize = framePool.size();
for( std::size_t i = oldSize; i < newSize; i++ )
{
m_apcFrameBuffer.push_back( CalypFrame{ m_apcFrameBuffer[0].getWidth(),
m_apcFrameBuffer[0].getHeight(),
m_apcFrameBuffer[0].getPelFormat(),
m_apcFrameBuffer[0].getBitsPel(),
m_apcFrameBuffer[0].getHasNegativeValues() } );
framePool.push_back( std::make_unique<CalypFrame>( framePool[0]->getWidth(),
framePool[0]->getHeight(),
framePool[0]->getPelFormat(),
framePool[0]->getBitsPel(),
framePool[0]->getHasNegativeValues() ) );
}
bufferIdx += newSize - oldSize;
}
unsigned int size() { return m_apcFrameBuffer.size(); }
void setIndex( unsigned int i ) { m_uiIndex = i; }
CalypFrame& frame( int i ) { return m_apcFrameBuffer.at( i ); }
CalypFrame& current() { return m_apcFrameBuffer.at( m_uiIndex ); }
CalypFrame& next() { return m_apcFrameBuffer.at( nextIndex() ); }
void setNextFrame() { m_uiIndex = nextIndex(); }
CalypFrame* ref() { return framePool[0].get(); }
private:
inline int nextIndex() { return m_uiIndex + 1 >= m_apcFrameBuffer.size() ? 0 : m_uiIndex + 1; }
inline int prevIndex() { return m_uiIndex - 1 < 0 ? m_apcFrameBuffer.size() - 1 : m_uiIndex - 1; }
std::shared_ptr<CalypFrame> getFrame()
{
const std::lock_guard<std::mutex> lock( buffer_mutex );
assert( bufferIdx > 0 );
bufferIdx--;
auto frame = framePool[bufferIdx].release();
auto deleter = [this, lifetime = shared_from_this()]( CalypFrame* p ) {
const std::lock_guard<std::mutex> lock( buffer_mutex );
framePool[bufferIdx].reset( p );
bufferIdx++;
};
return std::shared_ptr<CalypFrame>{ frame, deleter };
}
};
class CalypStream::CalypStreamPrivate
{
public:
std::recursive_mutex stream_mutex;
bool isInit;
bool isInput;
CalypStreamHandlerIf* handler;
CreateStreamHandlerFn pfctCreateHandler;
CalypStreamBufferPrivate* frameBuffer;
std::shared_ptr<CalypStreamFrameBuffer> frameBuffer;
std::deque<std::shared_ptr<CalypFrame>> frameFifo;
// std::vector<std::unique_ptr<CalypFrame>> framePool;
// std::deque<std::shared_ptr<CalypFrame>> frameFifo;
// std::size_t bufferIdx{ 0 };
ClpString cFilename;
long long int iCurrFrameNum;
bool bLoadAll;
CalypStreamPrivate( const CalypStreamPrivate& ) = delete;
CalypStreamPrivate( CalypStreamPrivate&& ) = delete;
CalypStreamPrivate& operator=( const CalypStreamPrivate& ) = delete;
CalypStreamPrivate& operator=( CalypStreamPrivate&& ) = delete;
CalypStreamPrivate()
{
handler = nullptr;
pfctCreateHandler = nullptr;
frameBuffer = nullptr;
isInput = true;
isInit = false;
bLoadAll = false;
iCurrFrameNum = -1;
cFilename = "";
}
~CalypStreamPrivate()
{
close();
}
void close()
{
if( !isInit )
return;
if( handler )
{
handler->closeHandler();
handler->Delete();
}
if( frameBuffer )
delete frameBuffer;
bLoadAll = false;
isInit = false;
}
bool readNextFrame( bool fillRgbBuffer = false )
{
const std::lock_guard<std::recursive_mutex> lock( stream_mutex );
if( !isInit || !isInput || handler->m_uiCurrFrameFileIdx >= handler->m_uiTotalNumberFrames )
return false;
if( bLoadAll )
return true;
auto frame = frameBuffer->getFrame();
if( !handler->read( *frame ) )
{
throw CalypFailure( "CalypStream", "Cannot read frame from stream" );
return false;
}
frameFifo.push_back( frame );
if( fillRgbBuffer )
{
frame->fillRGBBuffer();
}
return true;
}
};
std::vector<ClpString> CalypStreamFormat::getExts()
@@ -290,7 +344,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
{
if( d->isInit )
{
close();
d->close();
}
d->isInit = false;
d->isInput = bInput;
@@ -320,45 +374,54 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
if( !d->handler->openHandler( d->cFilename, d->isInput ) )
{
close();
d->close();
return d->isInit;
}
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" );
return d->isInit;
}
d->frameFifo.clear();
// Keep past, current and future frames
std::size_t bufferSize = d->isInput ? 6 : 1;
try
{
d->frameBuffer = new CalypStreamBufferPrivate( d->isInput ? 3 : 1, d->handler->m_uiWidth, d->handler->m_uiHeight,
d->handler->m_iPixelFormat, d->handler->m_uiBitsPerPixel, hasNegative );
d->frameBuffer = std::make_shared<CalypStreamFrameBuffer>( bufferSize,
d->handler->m_uiWidth,
d->handler->m_uiHeight,
d->handler->m_iPixelFormat,
d->handler->m_uiBitsPerPixel,
hasNegative );
}
catch( CalypFailure& e )
{
close();
d->close();
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer" );
return d->isInit;
}
d->handler->m_uiNBytesPerFrame = d->frameBuffer->current().getBytesPerFrame();
const CalypFrame* refFrame = d->frameBuffer->ref();
d->handler->m_uiNBytesPerFrame = refFrame->getBytesPerFrame();
// Some handlers need to know how long is a frame to get frame number
d->handler->calculateFrameNumber();
if( d->isInput && d->handler->m_uiTotalNumberFrames == 0 )
{
close();
d->close();
throw CalypFailure( "CalypStream", "Incorrect configuration: less than one frame" );
return d->isInit;
}
if( !d->handler->configureBuffer( d->frameBuffer->current() ) )
if( !d->handler->configureBuffer( *refFrame ) )
{
close();
d->close();
throw CalypFailure( "CalypStream", "Cannot allocated buffers" );
return d->isInit;
}
@@ -374,15 +437,17 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
bool CalypStream::reload()
{
d->frameFifo.clear();
d->handler->closeHandler();
if( !d->handler->openHandler( d->cFilename, d->isInput ) )
{
throw CalypFailure( "CalypStream", "Cannot open stream " + d->cFilename + " with the " +
ClpString( d->handler->m_pchHandlerName ) + " handler" );
}
d->handler->m_uiNBytesPerFrame = d->frameBuffer->current().getBytesPerFrame();
const CalypFrame* refFrame = d->frameBuffer->ref();
d->handler->m_uiNBytesPerFrame = refFrame->getBytesPerFrame();
d->handler->calculateFrameNumber();
d->handler->configureBuffer( d->frameBuffer->current() );
d->handler->configureBuffer( *refFrame );
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 ||
d->handler->m_uiBitsPerPixel == 0 || d->handler->m_uiTotalNumberFrames == 0 )
@@ -393,17 +458,12 @@ bool CalypStream::reload()
{
d->iCurrFrameNum = 0;
}
int currFrameNum = d->iCurrFrameNum;
auto currFrameNum = d->iCurrFrameNum;
d->iCurrFrameNum = -1;
seekInput( currFrameNum );
return true;
}
void CalypStream::close()
{
d->close();
}
ClpString CalypStream::getFileName() const
{
return d->cFilename;
@@ -454,21 +514,36 @@ void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, int& r
rInputFormat = d->handler->m_iPixelFormat;
rBitsPerPel = d->handler->m_uiBitsPerPixel;
rEndianness = d->handler->m_iEndianness;
rFrameRate = d->handler->m_dFrameRate;
rFrameRate = static_cast<unsigned>( std::max( 0.0, d->handler->m_dFrameRate ) );
}
else
{
rWidth = 0;
rHeight = 0;
rInputFormat = CLP_YUV420P;
rBitsPerPel = 8;
rBitsPerPel = kDefaultBitsPerPixel;
rEndianness = 0;
rFrameRate = 30;
rFrameRate = kDefaultFrameRate;
}
}
auto CalypStream::hasNextFrame() -> bool
{
return d->frameFifo.size() > 1;
}
auto CalypStream::hasWritingSlot() -> bool
{
return !d->bLoadAll && d->frameBuffer->bufferIdx > 0;
}
/**
* @brief Read operations
*/
void CalypStream::loadAll()
{
const std::lock_guard<std::recursive_mutex> lock( d->stream_mutex );
if( d->bLoadAll || !d->isInput )
return;
@@ -478,40 +553,78 @@ void CalypStream::loadAll()
}
catch( CalypFailure& e )
{
close();
d->close();
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer for the whole stream" );
}
seekInput( 0 );
for( unsigned int i = 2; i < d->frameBuffer->size(); i++ )
for( unsigned int i = 2; i < d->handler->m_uiTotalNumberFrames; i++ )
{
readFrame( d->frameBuffer->frame( i ) );
d->readNextFrame( false );
}
d->bLoadAll = true;
d->iCurrFrameNum = 0;
}
bool CalypStream::readFrame( CalypFrame& frame )
std::unique_ptr<CalypFrame> CalypStream::getCurrFrame( std::unique_ptr<CalypFrame> buffer )
{
if( !d->isInit || !d->isInput || d->handler->m_uiCurrFrameFileIdx >= d->handler->m_uiTotalNumberFrames )
return false;
if( buffer == nullptr )
buffer = std::make_unique<CalypFrame>( *d->frameFifo.front() );
else
buffer->copyFrom( *d->frameFifo.front() );
return buffer;
}
auto CalypStream::getCurrFrameAsset() -> std::shared_ptr<CalypFrame>
{
if( d->bLoadAll )
return true;
if( !d->handler->read( frame ) )
{
throw CalypFailure( "CalypStream", "Cannot read frame from stream" );
return false;
}
return true;
return d->frameFifo[d->iCurrFrameNum];
return d->frameFifo.front();
}
void CalypStream::writeFrame()
auto CalypStream::getCurrFrame() -> CalypFrame*
{
writeFrame( d->frameBuffer->current() );
if( d->bLoadAll )
return d->frameFifo[d->iCurrFrameNum].get();
return d->frameFifo.front().get();
}
bool CalypStream::isEof()
{
if( d->iCurrFrameNum + 1 >= (long)( d->handler->m_uiTotalNumberFrames ) )
{
return true;
}
return false;
}
bool CalypStream::setNextFrame()
{
if( isEof() )
{
return true;
}
d->iCurrFrameNum++;
if( !d->bLoadAll )
{
assert( d->frameFifo.size() > 1 );
d->frameFifo.pop_front();
}
return false;
}
void CalypStream::readNextFrame()
{
d->readNextFrame();
}
void CalypStream::readNextFrameFillRGBBuffer()
{
d->readNextFrame( true );
}
/**
* @brief Write operations
*/
void CalypStream::writeFrame( const CalypFrame& pcFrame )
{
if( !d->handler->write( pcFrame ) )
@@ -523,7 +636,7 @@ void CalypStream::writeFrame( const CalypFrame& pcFrame )
bool CalypStream::saveFrame( const ClpString& filename )
{
return saveFrame( filename, d->frameBuffer->current() );
return saveFrame( filename, *getCurrFrame() );
}
bool CalypStream::saveFrame( const ClpString& filename, const CalypFrame& saveFrame )
@@ -535,57 +648,12 @@ bool CalypStream::saveFrame( const ClpString& filename, const CalypFrame& saveFr
return false;
}
auxSaveStream.writeFrame( saveFrame );
auxSaveStream.close();
return true;
}
bool CalypStream::setNextFrame()
{
bool bEndOfSeq = false;
if( d->iCurrFrameNum + 1 < (long)( d->handler->m_uiTotalNumberFrames ) )
{
d->frameBuffer->setNextFrame();
d->iCurrFrameNum++;
}
else
{
bEndOfSeq = true;
}
return bEndOfSeq;
}
void CalypStream::readNextFrame()
{
readFrame( d->frameBuffer->next() );
}
void CalypStream::readNextFrameFillRGBBuffer()
{
readNextFrame();
d->frameBuffer->next().fillRGBBuffer();
return;
}
CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image )
{
if( pyuv_image == NULL )
pyuv_image = new CalypFrame( d->frameBuffer->current() );
else
pyuv_image->copyFrom( d->frameBuffer->current() );
return pyuv_image;
}
CalypFrame* CalypStream::getCurrFrame()
{
return &d->frameBuffer->current();
}
const CalypFrame& CalypStream::getCurrFrameConst() const
{
return d->frameBuffer->current();
}
/**
* @brief Seek operations
*/
bool CalypStream::seekInputRelative( bool bIsFoward )
{
if( !d->isInit || !d->isInput )
@@ -595,7 +663,7 @@ bool CalypStream::seekInputRelative( bool bIsFoward )
if( bIsFoward )
{
bRet = !setNextFrame();
readFrame( d->frameBuffer->next() );
d->readNextFrame();
}
else
{
@@ -607,26 +675,24 @@ bool CalypStream::seekInputRelative( bool bIsFoward )
bool CalypStream::seekInput( unsigned long new_frame_num )
{
const std::lock_guard<std::recursive_mutex> lock( d->stream_mutex );
if( !d->isInit || new_frame_num >= d->handler->m_uiTotalNumberFrames || long( new_frame_num ) == d->iCurrFrameNum )
return false;
d->iCurrFrameNum = new_frame_num;
if( d->bLoadAll )
{
d->frameBuffer->setIndex( d->iCurrFrameNum );
return true;
}
d->frameFifo.clear();
if( !d->handler->seek( d->iCurrFrameNum ) )
{
throw CalypFailure( "CalypStream", "Cannot seek file into desired position" );
}
d->frameBuffer->setIndex( 0 );
readFrame( d->frameBuffer->current() );
d->readNextFrame();
if( d->handler->m_uiTotalNumberFrames > 1 )
readFrame( d->frameBuffer->next() );
d->readNextFrame();
return true;
}
+17 -16
View File
@@ -26,11 +26,12 @@
#ifndef __CALYPSTREAM_H__
#define __CALYPSTREAM_H__
#include <memory>
#include <vector>
#include "CalypDefs.h"
#include "CalypFrame.h"
class CalypFrame;
class CalypStreamHandlerIf;
typedef CalypStreamHandlerIf* ( *CreateStreamHandlerFn )( void );
@@ -67,6 +68,10 @@ public:
static std::vector<CalypStandardResolution> stdResolutionSizes();
CalypStream();
CalypStream( CalypStream&& other ) noexcept = delete;
CalypStream& operator=( CalypStream&& other ) noexcept = delete;
CalypStream( const CalypStream& other ) = delete;
CalypStream& operator=( const CalypStream& other ) = delete;
~CalypStream();
ClpString getFormatName() const;
@@ -80,7 +85,6 @@ public:
bool bInput );
bool reload();
void close();
bool isNative() const;
ClpString getFileName() const;
@@ -94,29 +98,26 @@ public:
void getFormat( unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
unsigned int& rFrameRate ) const;
void loadAll();
auto hasNextFrame() -> bool;
auto hasWritingSlot() -> bool;
void loadAll();
std::unique_ptr<CalypFrame> getCurrFrame( std::unique_ptr<CalypFrame> buffer );
auto getCurrFrameAsset() -> std::shared_ptr<CalypFrame>;
auto getCurrFrame() -> CalypFrame*;
bool isEof();
bool setNextFrame();
void readNextFrame();
void readNextFrameFillRGBBuffer();
void writeFrame();
void writeFrame( const CalypFrame& pcFrame );
bool saveFrame( const ClpString& filename );
static bool saveFrame( const ClpString& filename, const CalypFrame& saveFrame );
CalypFrame* getCurrFrame( CalypFrame* );
// continuous read control
bool setNextFrame();
void readNextFrame();
void readNextFrameFillRGBBuffer();
CalypFrame* getCurrFrame();
const CalypFrame& getCurrFrameConst() const;
bool seekInputRelative( bool bIsFoward );
bool seekInput( unsigned long new_frame_num );
private:
bool readFrame( CalypFrame& frame );
private:
class CalypStreamPrivate;
std::unique_ptr<CalypStreamPrivate> d;
-2
View File
@@ -1,8 +1,6 @@
#
# CMakeLists for calyp modules component
#
OPTION(CALYP_THREADED_MODULES "Use threads for modules" ON)
SET(CALYP_EXTRA_MODULES_DIR
"CALYP_EXTRA_MODULES_DIR"
CACHE PATH "Location of extra Calyp modules"
+2 -6
View File
@@ -39,10 +39,6 @@
CalypModulesFactory::CalypModulesFactory(){ REGISTER_ALL_MODULES }
CalypModulesFactory::~CalypModulesFactory()
{
m_FactoryMap.clear();
}
void CalypModulesFactory::Register( const char* moduleName, CreateModuleFn pfnCreate )
{
@@ -70,7 +66,7 @@ bool CalypModulesFactory::RegisterDl( const char* dlName )
#endif
}
CalypModuleIf* CalypModulesFactory::CreateModule( const char* moduleName )
CalypModulePtr CalypModulesFactory::CreateModule( const char* moduleName )
{
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -81,5 +77,5 @@ CalypModuleIf* CalypModulesFactory::CreateModule( const char* moduleName )
return it->second();
}
}
return NULL;
return nullptr;
}
+3 -3
View File
@@ -32,7 +32,7 @@
#define REGISTER_MODULE( X ) Register( "X", &( X::Create ) );
typedef CalypModuleIf* ( *CreateModuleFn )( void );
typedef CalypModulePtr ( *CreateModuleFn )( void );
typedef std::map<const char*, CreateModuleFn> CalypModulesFactoryMap;
// Factory for creating instances of CalypModuleIf
@@ -44,7 +44,7 @@ private:
CalypModulesFactoryMap m_FactoryMap;
public:
~CalypModulesFactory();
~CalypModulesFactory() = default;
static CalypModulesFactory* Get()
{
@@ -55,7 +55,7 @@ public:
void Register( const char* moduleName, CreateModuleFn pfnCreate );
bool RegisterDl( const char* dlName );
CalypModuleIf* CreateModule( const char* moduleName );
CalypModulePtr CreateModule( const char* moduleName );
CalypModulesFactoryMap& getMap() { return m_FactoryMap; }
};
+4 -15
View File
@@ -45,17 +45,7 @@ CalypTools::CalypTools()
m_pcCurrModuleIf = NULL;
}
CalypTools::~CalypTools()
{
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();
}
}
CalypTools::~CalypTools() = default;
#define GET_PARAM( X, i ) X[X.size() > i ? i : X.size() - 1]
@@ -246,7 +236,7 @@ int CalypTools::Open( int argc, char* argv[] )
if( Opts().hasOpt( "output" ) )
m_pcOutputFileNames.push_back( m_strOutput );
CalypFrame* pcInputFrame = m_apcInputStreams[0]->getCurrFrame();
const CalypFrame* pcInputFrame = m_apcInputStreams[0]->getCurrFrame();
CalypStream* pcOutputStream = new CalypStream;
try
{
@@ -479,7 +469,7 @@ int CalypTools::RateReductionOperation()
if( ( frame % m_iRateReductionFactor ) == 0 )
{
log( CLP_LOG_INFO, "Writing", frame );
m_apcOutputStreams[0]->writeFrame( m_apcInputStreams[0]->getCurrFrameConst() );
m_apcOutputStreams[0]->writeFrame( *m_apcInputStreams[0]->getCurrFrame() );
}
abEOF = m_apcInputStreams[0]->setNextFrame();
if( !abEOF )
@@ -692,7 +682,6 @@ int CalypTools::ListStatistics()
{
log( CLP_LOG_RESULT, "\n\x1B[35mCalyp Statistics:\x1B[0m\n\n" );
CalypFrame* currFrame;
bool abEOF;
unsigned min[MAX_NUMBER_CHANNELS], max[MAX_NUMBER_CHANNELS];
@@ -706,7 +695,7 @@ int CalypTools::ListStatistics()
{
log( CLP_LOG_RESULT, "\x1B[34m Frame: %d\x1B[0m\n", frame );
currFrame = m_apcInputStreams[input]->getCurrFrame();
auto currFrame = m_apcInputStreams[input]->getCurrFrame();
abEOF = m_apcInputStreams[input]->setNextFrame();
if( !abEOF )
{
+2 -4
View File
@@ -47,11 +47,10 @@
#include <vector>
#include "CalypToolsCmdParser.h"
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
class CalypFrame;
class CalypStream;
class CalypModuleIf;
#define MAX_NUMBER_INPUTS 255
#define MAX_NUMBER_CHANNELS 4
@@ -101,8 +100,7 @@ private:
int m_uiQualityMetric;
int QualityOperation();
CalypModuleIf* m_pcCurrModuleIf;
//CalypFrame* applyFrameModule();
CalypModulePtr m_pcCurrModuleIf;
int ModuleOperation();
int ListStatistics();
};
+2 -5
View File
@@ -110,7 +110,6 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] )
void CalypToolsCmdParser::listModuleHelp()
{
ClpString moduleName = m_strModule;
CalypModuleIf* pcCurrModuleIf = NULL;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -118,10 +117,10 @@ void CalypToolsCmdParser::listModuleHelp()
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
pcCurrModuleIf = it->second();
break;
}
}
auto pcCurrModuleIf = it->second();
if( pcCurrModuleIf )
{
printf( "Usage: calypTools --module=%s options:\n", it->first );
@@ -136,7 +135,6 @@ void CalypToolsCmdParser::listModules()
if( m_cOptions.hasOpt( "module_list_full" ) )
bDetailed = true;
CalypModuleIf* pcCurrModuleIf;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -157,7 +155,7 @@ void CalypToolsCmdParser::listModules()
if( bDetailed )
{
ClpString ModuleNameString;
pcCurrModuleIf = it->second();
auto pcCurrModuleIf = it->second();
if( pcCurrModuleIf->m_pchModuleCategory )
{
@@ -176,7 +174,6 @@ void CalypToolsCmdParser::listModules()
break;
}
printf( " %s", pcCurrModuleIf->m_pchModuleTooltip );
pcCurrModuleIf->Delete();
}
printf( "\n" );
}