LordGrey a1f0821f33
Introduce Event Services (#1653)
* Allow to enable/disable suspend & lock event handling

* Fix Windows

* Refactor event handling incl.CEC

* Revert "Auxiliary commit to revert individual files from 0d9a8b8a3a4a09609a339f54c7d8a9384c561282"

This reverts commit 80737d926ad151a07b2493dd1685ed502975cb2e.

* Support Events for Grabbers generically

* Have CECEvent to actions configurable, further clean-ups

* Remove handleEvent from V4L2grabber, as grabber will be stopped on suspend

* Validate that one CEC Event can only trigger one action

* MacOS lock/unlock added

* fast windows fix

* Corrections

* Fix CodeQL findings

* add macos lock/unlock handler

* Migration of CEC-config and have default actions

* Correct target_link_libraries

* Include Foundation

* macOS include AppKit

* Support Scheduled Events, cleanups.

* Fix destructing

* Fix coredump during free

* Consider additional error sceanrio

* Fix missing code

* install desktop icons

* correct bash logic

---------

Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2023-11-27 09:06:43 +01:00

178 lines
3.8 KiB
C++

#pragma once
#include <QObject>
#include <cstdint>
#include <utils/ColorRgb.h>
#include <utils/Image.h>
#include <utils/VideoMode.h>
#include <utils/VideoStandard.h>
#include <utils/ImageResampler.h>
#include <utils/Logger.h>
#include <utils/Components.h>
#include <events/EventEnum.h>
///
/// @brief The Grabber class is responsible to apply image resizes (with or without ImageResampler)
class Grabber : public QObject
{
Q_OBJECT
public:
Grabber(const QString& grabberName = "", int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0);
///
/// Set the video mode (2D/3D)
/// @param[in] mode The new video mode
///
virtual void setVideoMode(VideoMode mode);
///
/// Apply new flip mode (vertical/horizontal/both)
/// @param[in] mode The new flip mode
///
virtual void setFlipMode(FlipMode mode);
///
/// @brief Apply new crop values, on errors reject the values
///
virtual void setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom);
///
/// @brief Apply new video input (used from v4l2/MediaFoundation)
/// @param input device input
///
virtual bool setInput(int input);
///
/// @brief Apply new width/height values, on errors (collide with cropping) reject the values
/// @return True on success else false
///
virtual bool setWidthHeight(int width, int height);
///
/// @brief Apply new capture framerate in Hz
/// @param fps framesPerSecond
///
virtual bool setFramerate(int fps);
///
/// @brief Apply new framerate software decimation (used from v4l2/MediaFoundation)
/// @param decimation how many frames per second to omit
///
virtual void setFpsSoftwareDecimation(int decimation);
///
/// @brief Apply videoStandard (used from v4l2)
///
virtual void setVideoStandard(VideoStandard videoStandard);
///
/// @brief Apply new pixelDecimation
///
virtual bool setPixelDecimation(int pixelDecimation);
///
/// @brief Apply display index (used from qt)
///
virtual bool setDisplayIndex(int /*index*/) { return true; }
///
/// @brief Prevent the real capture implementation from capturing if disabled
///
virtual void setEnabled(bool enable);
///
/// @brief get current resulting height of image (after crop)
///
int getImageWidth() const { return _width; }
///
/// @brief get current resulting width of image (after crop)
///
int getImageHeight() const { return _height; }
///
/// @brief Get current capture framerate in Hz
/// @param fps framesPerSecond
///
int getFramerate() const { return _fps; }
///
/// @brief Get capture interval in ms
///
int getUpdateInterval() const { return 1000/_fps; }
///
/// @brief Get pixelDecimation
///
int getPixelDecimation() const { return _pixelDecimation; }
QString getGrabberName() const { return _grabberName; }
public slots:
virtual void handleEvent(Event event) {}
protected slots:
///
/// @brief Set device in error state
///
/// @param[in] errorMsg The error message to be logged
///
virtual void setInError( const QString& errorMsg);
protected:
QString _grabberName;
/// logger instance
Logger * _log;
ImageResampler _imageResampler;
bool _useImageResampler;
/// the selected VideoMode
VideoMode _videoMode;
/// the used video standard
VideoStandard _videoStandard;
/// Image size decimation
int _pixelDecimation;
/// the used Flip Mode
FlipMode _flipMode;
/// With of the captured snapshot [pixels]
int _width;
/// Height of the captured snapshot [pixels]
int _height;
/// frame per second
int _fps;
/// fps software decimation
int _fpsSoftwareDecimation;
/// device input
int _input;
/// number of pixels to crop after capturing
int _cropLeft, _cropRight, _cropTop, _cropBottom;
// Device states
/// Is the device enabled?
bool _isEnabled;
/// Is the device in error state and stopped?
bool _isDeviceInError;
};