V4L2 enhanced (#766)

* fix v4l2 standard
* ignore v4l2 meta devices
* added resolution, framerate and device dropdown list to WebUI (thx to @Lord-Grey & @b1rdhous3)

* Fix for kernels prior to v4.16
* Device names added & WebUI adapted
This commit is contained in:
Paulchen Panther
2020-04-17 16:59:20 +02:00
committed by GitHub
parent b92af63cef
commit 10f11c2d89
20 changed files with 717 additions and 175 deletions

View File

@@ -216,7 +216,7 @@ private:
///
void handleConfigCommand(const QJsonObject &message, const QString &command, const int tan);
/// Handle an incoming JSON GetConfig message from handleConfigCommand()
/// Handle an incoming JSON GetSchema message from handleConfigCommand()
///
/// @param message the incoming message
///
@@ -297,4 +297,4 @@ private:
/// @brief Kill all signal/slot connections to stop possible data emitter
///
void stopDataConnections(void);
};
};

View File

@@ -8,6 +8,7 @@
#include <QObject>
#include <QSocketNotifier>
#include <QRectF>
#include <QMap>
// util includes
#include <utils/PixelFormat.h>
@@ -40,6 +41,13 @@ class V4L2Grabber : public Grabber
Q_OBJECT
public:
struct DeviceProperties
{
QString name = QString();
QStringList resolutions = QStringList();
QStringList framerates = QStringList();
};
V4L2Grabber(const QString & device,
const unsigned width,
const unsigned height,
@@ -48,7 +56,7 @@ public:
PixelFormat pixelFormat,
int pixelDecimation
);
virtual ~V4L2Grabber();
~V4L2Grabber() override;
QRectF getSignalDetectionOffset()
{
@@ -63,44 +71,64 @@ public:
/// @brief set new PixelDecimation value to ImageResampler
/// @param pixelDecimation The new pixelDecimation value
///
virtual void setPixelDecimation(int pixelDecimation);
void setPixelDecimation(int pixelDecimation) override;
///
/// @brief overwrite Grabber.h implementation
///
virtual void setSignalThreshold(
void setSignalThreshold(
double redSignalThreshold,
double greenSignalThreshold,
double blueSignalThreshold,
int noSignalCounterThreshold = 50);
int noSignalCounterThreshold = 50) override;
///
/// @brief overwrite Grabber.h implementation
///
virtual void setSignalDetectionOffset(
void setSignalDetectionOffset(
double verticalMin,
double horizontalMin,
double verticalMax,
double horizontalMax);
double horizontalMax) override;
///
/// @brief overwrite Grabber.h implementation
///
virtual void setSignalDetectionEnable(bool enable);
///
/// @brief overwrite Grabber.h implementation
///
virtual void setDeviceVideoStandard(QString device, VideoStandard videoStandard);
///
/// @brief overwrite Grabber.h implementation
///
virtual bool setFramerate(int fps);
void setSignalDetectionEnable(bool enable) override;
///
/// @brief overwrite Grabber.h implementation
///
virtual bool setWidthHeight(int width, int height);
void setDeviceVideoStandard(QString device, VideoStandard videoStandard) override;
///
/// @brief overwrite Grabber.h implementation
///
bool setFramerate(int fps) override;
///
/// @brief overwrite Grabber.h implementation
///
bool setWidthHeight(int width, int height) override;
///
/// @brief overwrite Grabber.h implementation
///
QStringList getV4L2devices() override;
///
/// @brief overwrite Grabber.h implementation
///
QString getV4L2deviceName(QString devicePath) override;
///
/// @brief overwrite Grabber.h implementation
///
QStringList getResolutions(QString devicePath) override;
///
/// @brief overwrite Grabber.h implementation
///
QStringList getFramerates(QString devicePath) override;
public slots:
@@ -145,6 +173,8 @@ private:
int xioctl(int request, void *arg);
int xioctl(int fileDescriptor, int request, void *arg);
void throw_exception(const QString & error)
{
Error(_log, "Throws error: %s", QSTRING_CSTR(error));
@@ -198,12 +228,13 @@ private:
private:
QString _deviceName;
std::map<QString,QString> _v4lDevices;
int _input;
VideoStandard _videoStandard;
io_method _ioMethod;
int _fileDescriptor;
std::vector<buffer> _buffers;
std::map<QString, QString> _v4lDevices;
QMap<QString, V4L2Grabber::DeviceProperties> _deviceProperties;
int _input;
VideoStandard _videoStandard;
io_method _ioMethod;
int _fileDescriptor;
std::vector<buffer> _buffers;
PixelFormat _pixelFormat;
int _pixelDecimation;
@@ -225,4 +256,7 @@ private:
bool _initialized;
bool _deviceAutoDiscoverEnabled;
protected:
void enumFrameIntervals(QStringList &framerates, int fileDescriptor, int pixelformat, int width, int height);
};

View File

@@ -20,7 +20,7 @@ class Grabber : public QObject
Q_OBJECT
public:
Grabber(QString grabberName, int width=0, int height=0, int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0);
Grabber(QString grabberName = "", int width=0, int height=0, int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0);
virtual ~Grabber();
///
@@ -42,14 +42,14 @@ public:
///
/// @brief Apply new framerate (used from v4l)
/// @param fps framesPerSecond
/// @param fps framesPerSecond
///
virtual bool setFramerate(int fps);
///
/// @brief Apply new pixelDecimation (used from x11 and qt)
///
virtual void setPixelDecimation(int pixelDecimation) {};
virtual void setPixelDecimation(int pixelDecimation) {}
///
/// @brief Apply new signalThreshold (used from v4l)
@@ -58,7 +58,7 @@ public:
double redSignalThreshold,
double greenSignalThreshold,
double blueSignalThreshold,
int noSignalCounterThreshold = 50) {};
int noSignalCounterThreshold = 50) {}
///
/// @brief Apply new SignalDetectionOffset (used from v4l)
///
@@ -66,43 +66,70 @@ public:
double verticalMin,
double horizontalMin,
double verticalMax,
double horizontalMax) {};
double horizontalMax) {}
///
/// @brief Apply SignalDetectionEnable (used from v4l)
///
virtual void setSignalDetectionEnable(bool enable) {};
virtual void setSignalDetectionEnable(bool enable) {}
///
/// @brief Apply device and videoStanded (used from v4l)
///
virtual void setDeviceVideoStandard(QString device, VideoStandard videoStandard) {};
virtual void setDeviceVideoStandard(QString device, VideoStandard videoStandard) {}
///
/// @brief Apply display index (used from qt)
///
virtual void setDisplayIndex(int index) {};
virtual void setDisplayIndex(int index) {}
///
/// @brief Apply path for device (used from framebuffer)
///
virtual void setDevicePath(const QString& path) {};
virtual void setDevicePath(const QString& path) {}
///
/// @brief get current resulting height of image (after crop)
///
virtual int getImageWidth() { return _width; };
virtual int getImageWidth() { return _width; }
///
/// @brief get current resulting width of image (after crop)
///
virtual int getImageHeight() { return _height; };
virtual int getImageHeight() { return _height; }
///
/// @brief Prevent the real capture implementation from capturing if disabled
///
void setEnabled(bool enable);
///
/// @brief Get a list of all available V4L devices
/// @return List of all available V4L devices on success else empty List
///
virtual QStringList getV4L2devices() { return QStringList(); }
///
/// @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) { return QString(); }
///
/// @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) { return QStringList(); }
///
/// @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) { return QStringList(); }
protected:
ImageResampler _imageResampler;

View File

@@ -32,6 +32,9 @@ public:
virtual ~GrabberWrapper();
static GrabberWrapper* instance;
static GrabberWrapper* getInstance(){ return instance; }
///
/// Starts the grabber wich produces led values with the specified update rate
///
@@ -47,6 +50,33 @@ public:
///
virtual void stop();
///
/// @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);
///
/// @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);
static QStringList availableGrabbers();
public: