2014-03-04 20:17:38 +01:00
|
|
|
#include <QMetaType>
|
|
|
|
|
2014-02-23 22:39:23 +01:00
|
|
|
#include <grabber/V4L2Wrapper.h>
|
|
|
|
|
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
|
|
|
|
|
|
|
V4L2Wrapper::V4L2Wrapper(const std::string &device,
|
|
|
|
int input,
|
|
|
|
VideoStandard videoStandard,
|
2014-03-31 17:36:36 +02:00
|
|
|
PixelFormat pixelFormat,
|
2014-02-23 22:39:23 +01:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int frameDecimation,
|
|
|
|
int pixelDecimation,
|
2014-03-04 22:04:15 +01:00
|
|
|
double redSignalThreshold,
|
|
|
|
double greenSignalThreshold,
|
|
|
|
double blueSignalThreshold,
|
2016-08-11 07:13:55 +02:00
|
|
|
const int priority)
|
2016-08-31 00:54:47 +02:00
|
|
|
: GrabberWrapper("V4L2:"+device, priority, hyperion::COMP_V4L)
|
2016-08-11 07:13:55 +02:00
|
|
|
, _timeout_ms(1000)
|
2016-07-15 23:08:55 +02:00
|
|
|
, _grabber(device,
|
2014-03-04 22:04:15 +01:00
|
|
|
input,
|
|
|
|
videoStandard,
|
2014-03-31 17:36:36 +02:00
|
|
|
pixelFormat,
|
2014-03-04 22:04:15 +01:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
frameDecimation,
|
|
|
|
pixelDecimation,
|
2016-07-15 23:08:55 +02:00
|
|
|
pixelDecimation)
|
|
|
|
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
|
2014-02-23 22:39:23 +01:00
|
|
|
{
|
2014-03-04 22:04:15 +01:00
|
|
|
// set the signal detection threshold of the grabber
|
2016-07-15 23:08:55 +02:00
|
|
|
_grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50);
|
|
|
|
|
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
|
|
|
qRegisterMetaType<std::vector<ColorRgb>>("std::vector<ColorRgb>");
|
2016-10-10 18:29:54 +02:00
|
|
|
qRegisterMetaType<hyperion::Components>("hyperion::Components");
|
2014-03-04 20:17:38 +01:00
|
|
|
|
2014-03-04 20:32:54 +01:00
|
|
|
// Handle the image in the captured thread using a direct connection
|
2016-08-12 09:39:41 +02:00
|
|
|
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::DirectConnection);
|
|
|
|
|
|
|
|
QObject::connect(&_grabber, SIGNAL(readError(const char*)), this, SLOT(readError(const char*)), Qt::DirectConnection);
|
2014-03-04 20:32:54 +01:00
|
|
|
|
|
|
|
// send color data to Hyperion using a queued connection to handle the data over to the main event loop
|
2016-08-11 07:13:55 +02:00
|
|
|
// QObject::connect(
|
|
|
|
// this, SIGNAL(emitColors(int,std::vector<ColorRgb>,int)),
|
|
|
|
// _hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)),
|
|
|
|
// Qt::QueuedConnection);
|
2014-03-22 15:35:25 +01:00
|
|
|
|
2016-07-15 23:08:55 +02:00
|
|
|
|
2014-03-22 15:35:25 +01:00
|
|
|
// setup the higher prio source checker
|
2016-08-11 07:13:55 +02:00
|
|
|
// this will disable the v4l2 grabber when a source with higher priority is active
|
2014-03-22 15:35:25 +01:00
|
|
|
_timer.setInterval(500);
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
V4L2Wrapper::~V4L2Wrapper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
|
|
|
{
|
|
|
|
_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::set3D(VideoMode mode)
|
|
|
|
{
|
|
|
|
_grabber.set3D(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
|
|
|
{
|
2016-12-24 10:02:12 +01:00
|
|
|
emit emitImage(_priority, image, _timeout_ms);
|
2016-02-16 15:41:40 +01:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
// process the new image
|
|
|
|
_processor->process(image, _ledColors);
|
2016-10-10 18:29:54 +02:00
|
|
|
setColors(_ledColors, _timeout_ms);
|
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();
|
|
|
|
}
|
|
|
|
|
2014-03-22 15:35:25 +01:00
|
|
|
void V4L2Wrapper::checkSources()
|
|
|
|
{
|
|
|
|
QList<int> activePriorities = _hyperion->getActivePriorities();
|
|
|
|
|
|
|
|
for (int x : activePriorities)
|
|
|
|
{
|
|
|
|
if (x < _priority)
|
|
|
|
{
|
|
|
|
// found a higher priority source: grabber should be disabled
|
|
|
|
_grabber.stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no higher priority source was found: grabber should be enabled
|
|
|
|
_grabber.start();
|
|
|
|
}
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
void V4L2Wrapper::action()
|
|
|
|
{
|
|
|
|
checkSources();
|
|
|
|
}
|