2020-12-18 17:38:21 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-22 21:29:47 +01:00
|
|
|
// Windows include
|
|
|
|
#include <Windows.h>
|
|
|
|
|
2020-12-18 17:38:21 +01:00
|
|
|
// COM includes
|
|
|
|
#include <Guiddef.h>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QObject>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMultiMap>
|
|
|
|
|
|
|
|
// utils includes
|
|
|
|
#include <utils/PixelFormat.h>
|
|
|
|
#include <utils/Components.h>
|
|
|
|
#include <hyperion/Grabber.h>
|
|
|
|
|
|
|
|
// decoder thread includes
|
|
|
|
#include <grabber/MFThread.h>
|
|
|
|
|
|
|
|
// TurboJPEG decoder
|
|
|
|
#ifdef HAVE_TURBO_JPEG
|
|
|
|
#include <turbojpeg.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/// Forward class declaration
|
|
|
|
class SourceReaderCB;
|
|
|
|
/// Forward struct declaration
|
|
|
|
struct IMFSourceReader;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Media Foundation capture class
|
|
|
|
///
|
|
|
|
|
|
|
|
class MFGrabber : public Grabber
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
friend class SourceReaderCB;
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct DevicePropertiesItem
|
|
|
|
{
|
|
|
|
int x, y,fps,fps_a,fps_b;
|
|
|
|
PixelFormat pf;
|
|
|
|
GUID guid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeviceProperties
|
|
|
|
{
|
2021-01-22 21:29:47 +01:00
|
|
|
QString name = QString();
|
|
|
|
QMultiMap<QString, int> inputs = QMultiMap<QString, int>();
|
|
|
|
QStringList displayResolutions = QStringList();
|
|
|
|
QStringList framerates = QStringList();
|
|
|
|
QList<DevicePropertiesItem> valid = QList<DevicePropertiesItem>();
|
2020-12-18 17:38:21 +01:00
|
|
|
};
|
|
|
|
|
2021-01-24 12:16:16 +01:00
|
|
|
MFGrabber(const QString & device, const unsigned width, const unsigned height, const unsigned fps, const unsigned input, int pixelDecimation, QString flipMode);
|
2020-12-18 17:38:21 +01:00
|
|
|
~MFGrabber() override;
|
|
|
|
|
2021-01-22 21:29:47 +01:00
|
|
|
void receive_image(const void *frameImageBuffer, int size);
|
2020-12-18 17:38:21 +01:00
|
|
|
QRectF getSignalDetectionOffset() const { return QRectF(_x_frac_min, _y_frac_min, _x_frac_max, _y_frac_max); }
|
|
|
|
bool getSignalDetectionEnabled() const { return _signalDetectionEnabled; }
|
|
|
|
bool getCecDetectionEnabled() const { return _cecDetectionEnabled; }
|
|
|
|
QStringList getV4L2devices() const override;
|
|
|
|
QString getV4L2deviceName(const QString& devicePath) const override { return devicePath; }
|
|
|
|
QMultiMap<QString, int> getV4L2deviceInputs(const QString& devicePath) const override { return _deviceProperties.value(devicePath).inputs; }
|
|
|
|
QStringList getResolutions(const QString& devicePath) const override { return _deviceProperties.value(devicePath).displayResolutions; }
|
|
|
|
QStringList getFramerates(const QString& devicePath) const override { return _deviceProperties.value(devicePath).framerates; }
|
|
|
|
QStringList getV4L2EncodingFormats(const QString& devicePath) const override;
|
|
|
|
void setSignalThreshold(double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold, int noSignalCounterThreshold) override;
|
|
|
|
void setSignalDetectionOffset( double verticalMin, double horizontalMin, double verticalMax, double horizontalMax) override;
|
|
|
|
void setSignalDetectionEnable(bool enable) override;
|
|
|
|
void setPixelDecimation(int pixelDecimation) override;
|
|
|
|
void setCecDetectionEnable(bool enable) override;
|
|
|
|
void setDeviceVideoStandard(QString device, VideoStandard videoStandard) override;
|
|
|
|
bool setInput(int input) override;
|
|
|
|
bool setWidthHeight(int width, int height) override;
|
|
|
|
bool setFramerate(int fps) override;
|
|
|
|
void setFpsSoftwareDecimation(int decimation);
|
|
|
|
void setEncoding(QString enc);
|
2021-01-24 12:16:16 +01:00
|
|
|
void setFlipMode(QString flipMode);
|
2020-12-18 17:38:21 +01:00
|
|
|
void setBrightnessContrastSaturationHue(int brightness, int contrast, int saturation, int hue);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
bool start();
|
|
|
|
void stop();
|
|
|
|
void newThreadFrame(unsigned int _workerIndex, const Image<ColorRgb>& image,unsigned int sourceCount);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void newFrame(const Image<ColorRgb> & image);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool init();
|
|
|
|
void uninit();
|
2021-01-22 21:29:47 +01:00
|
|
|
HRESULT init_device(QString device, DevicePropertiesItem props);
|
2020-12-18 17:38:21 +01:00
|
|
|
void uninit_device();
|
|
|
|
void enumVideoCaptureDevices();
|
|
|
|
void start_capturing();
|
2021-01-22 21:29:47 +01:00
|
|
|
void process_image(const void *frameImageBuffer, int size);
|
2020-12-18 17:38:21 +01:00
|
|
|
void checkSignalDetectionEnabled(Image<ColorRgb> image);
|
|
|
|
|
2021-01-22 21:29:47 +01:00
|
|
|
QString _deviceName;
|
|
|
|
QMap<QString, MFGrabber::DeviceProperties> _deviceProperties;
|
|
|
|
HRESULT _hr;
|
|
|
|
SourceReaderCB* _sourceReaderCB;
|
|
|
|
PixelFormat _pixelFormat;
|
|
|
|
int _pixelDecimation,
|
|
|
|
_lineLength,
|
|
|
|
_frameByteSize,
|
|
|
|
_noSignalCounterThreshold,
|
|
|
|
_noSignalCounter,
|
|
|
|
_fpsSoftwareDecimation,
|
|
|
|
_brightness,
|
|
|
|
_contrast,
|
|
|
|
_saturation,
|
|
|
|
_hue;
|
|
|
|
volatile unsigned int _currentFrame;
|
|
|
|
ColorRgb _noSignalThresholdColor;
|
|
|
|
bool _signalDetectionEnabled,
|
|
|
|
_cecDetectionEnabled,
|
|
|
|
_noSignalDetected,
|
|
|
|
_initialized;
|
|
|
|
double _x_frac_min,
|
|
|
|
_y_frac_min,
|
|
|
|
_x_frac_max,
|
|
|
|
_y_frac_max;
|
|
|
|
MFThreadManager _threadManager;
|
|
|
|
IMFSourceReader* _sourceReader;
|
2020-12-18 17:38:21 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_TURBO_JPEG
|
2021-01-22 21:29:47 +01:00
|
|
|
int _subsamp;
|
2020-12-18 17:38:21 +01:00
|
|
|
#endif
|
|
|
|
};
|