2014-03-04 20:17:38 +01:00
|
|
|
#include <QMetaType>
|
|
|
|
|
2014-02-23 22:39:23 +01:00
|
|
|
#include <grabber/V4L2Wrapper.h>
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// qt
|
|
|
|
#include <QTimer>
|
2014-02-23 22:39:23 +01:00
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
V4L2Wrapper::V4L2Wrapper(const QString &device,
|
2020-08-08 23:12:43 +02:00
|
|
|
unsigned grabWidth,
|
|
|
|
unsigned grabHeight,
|
|
|
|
unsigned fps,
|
|
|
|
unsigned input,
|
2014-02-23 22:39:23 +01:00
|
|
|
VideoStandard videoStandard,
|
2014-03-31 17:36:36 +02:00
|
|
|
PixelFormat pixelFormat,
|
2018-12-27 23:11:32 +01:00
|
|
|
int pixelDecimation )
|
2020-03-27 23:13:58 +01:00
|
|
|
: GrabberWrapper("V4L2:"+device, &_grabber, grabWidth, grabHeight, 10)
|
2016-07-15 23:08:55 +02:00
|
|
|
, _grabber(device,
|
2020-03-27 23:13:58 +01:00
|
|
|
grabWidth,
|
|
|
|
grabHeight,
|
|
|
|
fps,
|
2020-06-17 20:55:57 +02:00
|
|
|
input,
|
2014-03-04 22:04:15 +01:00
|
|
|
videoStandard,
|
2014-03-31 17:36:36 +02:00
|
|
|
pixelFormat,
|
2016-07-15 23:08:55 +02:00
|
|
|
pixelDecimation)
|
2014-02-23 22:39:23 +01:00
|
|
|
{
|
2017-08-12 07:55:32 +02:00
|
|
|
_ggrabber = &_grabber;
|
2016-07-15 23:08:55 +02:00
|
|
|
|
2014-03-04 20:17:38 +01:00
|
|
|
// register the image type
|
|
|
|
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
|
|
|
|
|
2014-03-04 20:32:54 +01:00
|
|
|
// Handle the image in the captured thread using a direct connection
|
2020-08-02 22:32:00 +02:00
|
|
|
connect(&_grabber, &V4L2Grabber::newFrame, this, &V4L2Wrapper::newFrame, Qt::DirectConnection);
|
|
|
|
connect(&_grabber, &V4L2Grabber::readError, this, &V4L2Wrapper::readError, Qt::DirectConnection);
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 18:27:24 +02:00
|
|
|
V4L2Wrapper::~V4L2Wrapper()
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:40:10 +02:00
|
|
|
bool V4L2Wrapper::start()
|
2014-02-23 22:39:23 +01:00
|
|
|
{
|
2016-08-11 07:13:55 +02:00
|
|
|
return ( _grabber.start() && GrabberWrapper::start());
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::stop()
|
|
|
|
{
|
|
|
|
_grabber.stop();
|
2016-08-11 07:13:55 +02:00
|
|
|
GrabberWrapper::stop();
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
void V4L2Wrapper::setSignalThreshold(double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold)
|
|
|
|
{
|
|
|
|
_grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50);
|
|
|
|
}
|
|
|
|
|
2020-05-25 21:51:11 +02:00
|
|
|
void V4L2Wrapper::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom)
|
2014-02-23 22:39:23 +01:00
|
|
|
{
|
|
|
|
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
|
|
|
}
|
|
|
|
|
2016-12-16 19:48:43 +01:00
|
|
|
void V4L2Wrapper::setSignalDetectionOffset(double verticalMin, double horizontalMin, double verticalMax, double horizontalMax)
|
|
|
|
{
|
|
|
|
_grabber.setSignalDetectionOffset(verticalMin, horizontalMin, verticalMax, horizontalMax);
|
|
|
|
}
|
|
|
|
|
2014-02-23 22:39:23 +01:00
|
|
|
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
|
|
|
{
|
2019-02-17 15:26:11 +01:00
|
|
|
emit systemImage(_grabberName, image);
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
2016-08-12 09:39:41 +02:00
|
|
|
void V4L2Wrapper::readError(const char* err)
|
|
|
|
{
|
|
|
|
Error(_log, "stop grabber, because reading device failed. (%s)", err);
|
|
|
|
stop();
|
|
|
|
}
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
void V4L2Wrapper::action()
|
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
// dummy as v4l get notifications from stream
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
2017-03-15 20:33:11 +01:00
|
|
|
|
|
|
|
void V4L2Wrapper::setSignalDetectionEnable(bool enable)
|
|
|
|
{
|
|
|
|
_grabber.setSignalDetectionEnable(enable);
|
|
|
|
}
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
bool V4L2Wrapper::getSignalDetectionEnable() const
|
2017-03-15 20:33:11 +01:00
|
|
|
{
|
|
|
|
return _grabber.getSignalDetectionEnabled();
|
|
|
|
}
|
2019-02-13 09:09:34 +01:00
|
|
|
|
2020-07-20 20:06:41 +02:00
|
|
|
void V4L2Wrapper::setCecDetectionEnable(bool enable)
|
|
|
|
{
|
|
|
|
_grabber.setCecDetectionEnable(enable);
|
|
|
|
}
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
bool V4L2Wrapper::getCecDetectionEnable() const
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
|
|
|
return _grabber.getCecDetectionEnabled();
|
|
|
|
}
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
void V4L2Wrapper::setDeviceVideoStandard(const QString& device, VideoStandard videoStandard)
|
2019-02-13 09:09:34 +01:00
|
|
|
{
|
|
|
|
_grabber.setDeviceVideoStandard(device, videoStandard);
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
|
|
|
void V4L2Wrapper::handleCecEvent(CECEvent event)
|
|
|
|
{
|
|
|
|
_grabber.handleCecEvent(event);
|
|
|
|
}
|
2020-07-23 16:50:37 +02:00
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void V4L2Wrapper::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
2020-07-23 16:50:37 +02:00
|
|
|
{
|
|
|
|
if(type == settings::V4L2 && _grabberName.startsWith("V4L"))
|
|
|
|
{
|
|
|
|
// extract settings
|
|
|
|
const QJsonObject& obj = config.object();
|
|
|
|
|
|
|
|
// pixel decimation for v4l
|
|
|
|
_grabber.setPixelDecimation(obj["sizeDecimation"].toInt(8));
|
|
|
|
|
|
|
|
// crop for v4l
|
|
|
|
_grabber.setCropping(
|
|
|
|
obj["cropLeft"].toInt(0),
|
|
|
|
obj["cropRight"].toInt(0),
|
|
|
|
obj["cropTop"].toInt(0),
|
|
|
|
obj["cropBottom"].toInt(0));
|
|
|
|
|
|
|
|
// device input
|
|
|
|
_grabber.setInput(obj["input"].toInt(-1));
|
|
|
|
|
|
|
|
// device resolution
|
|
|
|
_grabber.setWidthHeight(obj["width"].toInt(0), obj["height"].toInt(0));
|
|
|
|
|
|
|
|
// device framerate
|
|
|
|
_grabber.setFramerate(obj["fps"].toInt(15));
|
|
|
|
|
|
|
|
// CEC Standby
|
|
|
|
_grabber.setCecDetectionEnable(obj["cecDetection"].toBool(true));
|
|
|
|
|
|
|
|
_grabber.setSignalDetectionEnable(obj["signalDetection"].toBool(true));
|
|
|
|
_grabber.setSignalDetectionOffset(
|
|
|
|
obj["sDHOffsetMin"].toDouble(0.25),
|
|
|
|
obj["sDVOffsetMin"].toDouble(0.25),
|
|
|
|
obj["sDHOffsetMax"].toDouble(0.75),
|
|
|
|
obj["sDVOffsetMax"].toDouble(0.75));
|
|
|
|
_grabber.setSignalThreshold(
|
|
|
|
obj["redSignalThreshold"].toDouble(0.0)/100.0,
|
|
|
|
obj["greenSignalThreshold"].toDouble(0.0)/100.0,
|
|
|
|
obj["blueSignalThreshold"].toDouble(0.0)/100.0);
|
|
|
|
_grabber.setDeviceVideoStandard(
|
|
|
|
obj["device"].toString("auto"),
|
|
|
|
parseVideoStandard(obj["standard"].toString("no-change")));
|
|
|
|
}
|
|
|
|
}
|