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,
|
2014-02-23 22:39:23 +01:00
|
|
|
int hyperionPriority) :
|
|
|
|
_timeout_ms(1000),
|
|
|
|
_priority(hyperionPriority),
|
|
|
|
_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,
|
|
|
|
pixelDecimation),
|
2014-02-23 22:39:23 +01:00
|
|
|
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
2016-06-17 01:25:40 +02:00
|
|
|
_hyperion(Hyperion::getInstance()),
|
|
|
|
_ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}),
|
2014-03-22 15:35:25 +01:00
|
|
|
_timer()
|
2014-02-23 22:39:23 +01:00
|
|
|
{
|
2014-03-04 22:04:15 +01:00
|
|
|
// set the signal detection threshold of the grabber
|
|
|
|
_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>");
|
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
|
|
|
|
QObject::connect(
|
|
|
|
&_grabber, SIGNAL(newFrame(Image<ColorRgb>)),
|
|
|
|
this, SLOT(newFrame(Image<ColorRgb>)),
|
|
|
|
Qt::DirectConnection);
|
|
|
|
|
|
|
|
// send color data to Hyperion using a queued connection to handle the data over to the main event loop
|
|
|
|
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
|
|
|
|
|
|
|
// setup the higher prio source checker
|
|
|
|
// this will disable the v4l2 grabber when a source with hisher priority is active
|
|
|
|
_timer.setInterval(500);
|
|
|
|
_timer.setSingleShot(false);
|
|
|
|
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(checkSources()));
|
|
|
|
_timer.start();
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
V4L2Wrapper::~V4L2Wrapper()
|
|
|
|
{
|
|
|
|
delete _processor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::start()
|
|
|
|
{
|
|
|
|
_grabber.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::stop()
|
|
|
|
{
|
|
|
|
_grabber.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
|
|
|
|
{
|
|
|
|
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::set3D(VideoMode mode)
|
|
|
|
{
|
|
|
|
_grabber.set3D(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
|
|
|
{
|
|
|
|
// process the new image
|
|
|
|
_processor->process(image, _ledColors);
|
|
|
|
|
2016-02-16 15:41:40 +01:00
|
|
|
// forward to other hyperions
|
|
|
|
emit emitImage(_priority, image, _timeout_ms);
|
|
|
|
|
2014-02-23 22:39:23 +01:00
|
|
|
// send colors to Hyperion
|
2014-03-04 20:32:54 +01:00
|
|
|
emit emitColors(_priority, _ledColors, _timeout_ms);
|
2014-02-23 22:39:23 +01:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|