2016-08-11 07:13:55 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
2018-12-28 18:12:45 +01:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2017-02-17 08:33:34 +01:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2020-06-17 20:55:57 +02:00
|
|
|
#include <QMultiMap>
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <utils/Components.h>
|
2017-08-12 07:55:32 +02:00
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
|
|
|
#include <utils/VideoMode.h>
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <utils/settings.h>
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
class Grabber;
|
2019-01-01 19:47:07 +01:00
|
|
|
class GlobalSignals;
|
2018-12-27 23:11:32 +01:00
|
|
|
class QTimer;
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2020-03-26 17:49:36 +01:00
|
|
|
/// List of Hyperion instances that requested screen capt
|
|
|
|
static QList<int> GRABBER_SYS_CLIENTS;
|
|
|
|
static QList<int> GRABBER_V4L_CLIENTS;
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// This class will be inherted by FramebufferWrapper and others which contains the real capture interface
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
class GrabberWrapper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2017-11-22 00:52:55 +01:00
|
|
|
public:
|
2019-03-27 09:07:20 +01:00
|
|
|
GrabberWrapper(QString grabberName, Grabber * ggrabber, unsigned width, unsigned height, const unsigned updateRate_Hz = 0);
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual ~GrabberWrapper();
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2020-04-17 16:59:20 +02:00
|
|
|
static GrabberWrapper* instance;
|
|
|
|
static GrabberWrapper* getInstance(){ return instance; }
|
|
|
|
|
2016-08-12 23:07:32 +02:00
|
|
|
///
|
|
|
|
/// Starts the grabber wich produces led values with the specified update rate
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual bool start();
|
2016-08-12 23:07:32 +02:00
|
|
|
|
2020-03-26 17:49:36 +01:00
|
|
|
///
|
|
|
|
/// Starts maybe the grabber wich produces led values with the specified update rate
|
|
|
|
///
|
|
|
|
virtual void tryStart();
|
|
|
|
|
2016-08-12 23:07:32 +02:00
|
|
|
///
|
|
|
|
/// Stop grabber
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual void stop();
|
|
|
|
|
2020-04-17 16:59:20 +02:00
|
|
|
///
|
|
|
|
/// @brief Get a list of all available V4L devices
|
|
|
|
/// @return List of all available V4L devices on success else empty List
|
|
|
|
///
|
|
|
|
virtual QStringList getV4L2devices();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get the V4L device name
|
|
|
|
/// @param devicePath The device path
|
|
|
|
/// @return The name of the V4L device on success else empty String
|
|
|
|
///
|
|
|
|
virtual QString getV4L2deviceName(QString devicePath);
|
|
|
|
|
2020-06-17 20:55:57 +02:00
|
|
|
///
|
|
|
|
/// @brief Get a name/index pair of supported device inputs
|
|
|
|
/// @param devicePath The device path
|
|
|
|
/// @return multi pair of name/index on success else empty pair
|
|
|
|
///
|
|
|
|
virtual QMultiMap<QString, int> getV4L2deviceInputs(QString devicePath);
|
|
|
|
|
2020-04-17 16:59:20 +02:00
|
|
|
///
|
|
|
|
/// @brief Get a list of supported device resolutions
|
|
|
|
/// @param devicePath The device path
|
|
|
|
/// @return List of resolutions on success else empty List
|
|
|
|
///
|
|
|
|
virtual QStringList getResolutions(QString devicePath);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get a list of supported device framerates
|
|
|
|
/// @param devicePath The device path
|
|
|
|
/// @return List of framerates on success else empty List
|
|
|
|
///
|
|
|
|
virtual QStringList getFramerates(QString devicePath);
|
|
|
|
|
2017-02-17 08:33:34 +01:00
|
|
|
static QStringList availableGrabbers();
|
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
public:
|
|
|
|
template <typename Grabber_T>
|
2017-09-01 08:50:37 +02:00
|
|
|
bool transferFrame(Grabber_T &grabber)
|
2017-08-12 07:55:32 +02:00
|
|
|
{
|
|
|
|
unsigned w = grabber.getImageWidth();
|
|
|
|
unsigned h = grabber.getImageHeight();
|
2018-12-27 23:11:32 +01:00
|
|
|
if ( _image.width() != w || _image.height() != h)
|
2017-08-12 07:55:32 +02:00
|
|
|
{
|
|
|
|
_image.resize(w, h);
|
|
|
|
}
|
|
|
|
|
2017-09-01 08:50:37 +02:00
|
|
|
int ret = grabber.grabFrame(_image);
|
|
|
|
if (ret >= 0)
|
2017-08-12 07:55:32 +02:00
|
|
|
{
|
2019-02-17 15:26:11 +01:00
|
|
|
emit systemImage(_grabberName, _image);
|
2017-09-01 08:50:37 +02:00
|
|
|
return true;
|
2017-08-12 07:55:32 +02:00
|
|
|
}
|
2017-09-01 08:50:37 +02:00
|
|
|
return false;
|
2017-08-12 07:55:32 +02:00
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
public slots:
|
2016-08-12 23:07:32 +02:00
|
|
|
///
|
|
|
|
/// virtual method, should perform single frame grab and computes the led-colors
|
|
|
|
///
|
2016-08-11 07:13:55 +02:00
|
|
|
virtual void action() = 0;
|
|
|
|
|
2017-08-04 23:08:15 +02:00
|
|
|
///
|
|
|
|
/// Set the video mode (2D/3D)
|
|
|
|
/// @param[in] mode The new video mode
|
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
virtual void setVideoMode(const VideoMode& videoMode);
|
2017-08-04 23:08:15 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// Set the crop values
|
|
|
|
/// @param cropLeft Left pixel crop
|
|
|
|
/// @param cropRight Right pixel crop
|
|
|
|
/// @param cropTop Top pixel crop
|
|
|
|
/// @param cropBottom Bottom pixel crop
|
|
|
|
///
|
2017-08-12 07:55:32 +02:00
|
|
|
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
|
2017-08-04 23:08:15 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Handle settings update from HyperionDaemon Settingsmanager emit
|
|
|
|
/// @param type settingyType from enum
|
|
|
|
/// @param config configuration object
|
|
|
|
///
|
|
|
|
virtual void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
signals:
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Emit the final processed image
|
|
|
|
///
|
2019-02-17 15:26:11 +01:00
|
|
|
void systemImage(const QString& name, const Image<ColorRgb>& image);
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2020-03-26 17:49:36 +01:00
|
|
|
private slots:
|
|
|
|
/// @brief Handle a source request event from Hyperion.
|
|
|
|
/// Will start and stop grabber based on active listeners count
|
|
|
|
void handleSourceRequest(const hyperion::Components& component, const int hyperionInd, const bool listen);
|
2016-08-12 23:07:32 +02:00
|
|
|
|
2020-03-26 17:49:36 +01:00
|
|
|
protected:
|
2017-02-17 08:33:34 +01:00
|
|
|
QString _grabberName;
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
/// The timer for generating events with the specified update rate
|
2018-12-27 23:11:32 +01:00
|
|
|
QTimer* _timer;
|
2017-08-12 07:55:32 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
/// The calced update rate [ms]
|
|
|
|
int _updateInterval_ms;
|
2017-08-12 07:55:32 +02:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
/// The Logger instance
|
|
|
|
Logger * _log;
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
Grabber *_ggrabber;
|
|
|
|
|
|
|
|
/// The image used for grabbing frames
|
|
|
|
Image<ColorRgb> _image;
|
2016-08-11 07:13:55 +02:00
|
|
|
};
|