2016-08-11 07:13:55 +02:00
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
|
|
|
#include <hyperion/ImageProcessor.h>
|
|
|
|
#include <hyperion/GrabberWrapper.h>
|
2017-08-12 07:55:32 +02:00
|
|
|
#include <hyperion/Grabber.h>
|
2017-02-17 08:33:34 +01:00
|
|
|
#include <HyperionConfig.h>
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
GrabberWrapper::GrabberWrapper(QString grabberName, Grabber * ggrabber, unsigned width, unsigned height, const unsigned updateRate_Hz, const int priority, hyperion::Components grabberComponentId)
|
2016-08-11 07:13:55 +02:00
|
|
|
: _grabberName(grabberName)
|
|
|
|
, _hyperion(Hyperion::getInstance())
|
|
|
|
, _priority(priority)
|
|
|
|
, _timer()
|
2017-08-12 07:55:32 +02:00
|
|
|
, _updateInterval_ms(1000/updateRate_Hz)
|
|
|
|
, _timeout_ms(2 * _updateInterval_ms)
|
2017-02-17 08:33:34 +01:00
|
|
|
, _log(Logger::getInstance(grabberName))
|
2016-08-11 07:13:55 +02:00
|
|
|
, _forward(true)
|
|
|
|
, _processor(ImageProcessorFactory::getInstance().newImageProcessor())
|
2016-08-31 00:54:47 +02:00
|
|
|
, _grabberComponentId(grabberComponentId)
|
2017-08-12 07:55:32 +02:00
|
|
|
, _ggrabber(ggrabber)
|
|
|
|
, _image(0,0)
|
|
|
|
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
|
|
|
|
, _imageProcessorEnabled(true)
|
2016-08-11 07:13:55 +02:00
|
|
|
{
|
|
|
|
_timer.setSingleShot(false);
|
2017-08-12 07:55:32 +02:00
|
|
|
// Configure the timer to generate events every n milliseconds
|
|
|
|
_timer.setInterval(_updateInterval_ms);
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2017-08-12 07:55:32 +02:00
|
|
|
_image.resize(width, height);
|
|
|
|
_processor->setSize(width, height);
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
|
2016-09-07 20:10:37 +02:00
|
|
|
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_BLACKBORDER, _processor->blackBorderDetectorEnabled());
|
2016-10-10 18:29:54 +02:00
|
|
|
qRegisterMetaType<hyperion::Components>("hyperion::Components");
|
|
|
|
|
2017-11-22 00:52:55 +01:00
|
|
|
connect(_hyperion, SIGNAL(imageToLedsMappingChanged(int)), _processor, SLOT(setLedMappingType(int)));
|
2016-08-11 07:13:55 +02:00
|
|
|
connect(_hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool)));
|
2017-08-04 23:08:15 +02:00
|
|
|
connect(_hyperion, SIGNAL(videoMode(VideoMode)), this, SLOT(setVideoMode(VideoMode)));
|
|
|
|
connect(this, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _hyperion, SLOT(setImage(int, const Image<ColorRgb>&, const int)) );
|
2017-09-01 08:50:37 +02:00
|
|
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(actionWrapper()));
|
2017-08-12 07:55:32 +02:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GrabberWrapper::~GrabberWrapper()
|
|
|
|
{
|
2017-01-22 14:31:11 +01:00
|
|
|
stop();
|
2017-02-17 08:33:34 +01:00
|
|
|
Debug(_log,"Close grabber: %s", QSTRING_CSTR(_grabberName));
|
2016-08-11 07:13:55 +02:00
|
|
|
delete _processor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GrabberWrapper::start()
|
|
|
|
{
|
|
|
|
// Start the timer with the pre configured interval
|
|
|
|
_timer.start();
|
2017-03-01 15:23:53 +01:00
|
|
|
_hyperion->registerPriority(_grabberName, _priority);
|
2016-08-11 07:13:55 +02:00
|
|
|
return _timer.isActive();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrabberWrapper::stop()
|
|
|
|
{
|
|
|
|
// Stop the timer, effectivly stopping the process
|
|
|
|
_timer.stop();
|
2017-03-01 15:23:53 +01:00
|
|
|
_hyperion->unRegisterPriority(_grabberName);
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
|
|
|
|
2017-09-01 08:50:37 +02:00
|
|
|
void GrabberWrapper::actionWrapper()
|
|
|
|
{
|
|
|
|
_ggrabber->setEnabled(_hyperion->isCurrentPriority(_priority));
|
|
|
|
action();
|
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
void GrabberWrapper::componentStateChanged(const hyperion::Components component, bool enable)
|
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
if (component == _grabberComponentId)
|
2016-08-11 07:13:55 +02:00
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
if (_timer.isActive() != enable)
|
|
|
|
{
|
|
|
|
if (enable) start();
|
|
|
|
else stop();
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
if ( enable == _timer.isActive() )
|
|
|
|
{
|
|
|
|
Info(_log, "grabber change state to %s", (_timer.isActive() ? "enabled" : "disabled") );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WarningIf( enable, _log, "enable grabber failed");
|
|
|
|
}
|
2016-08-12 09:39:41 +02:00
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
_hyperion->getComponentRegister().componentStateChanged(component, _timer.isActive());
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
if (component == hyperion::COMP_BLACKBORDER)
|
2016-08-11 07:13:55 +02:00
|
|
|
{
|
2016-09-07 20:10:37 +02:00
|
|
|
if (_processor->blackBorderDetectorEnabled() != enable)
|
|
|
|
{
|
|
|
|
_processor->enableBlackBorderDetector(enable);
|
|
|
|
Info(_log, "bb detector change state to %s", (_processor->blackBorderDetectorEnabled() ? "enabled" : "disabled") );
|
|
|
|
}
|
|
|
|
_hyperion->getComponentRegister().componentStateChanged(component, _processor->blackBorderDetectorEnabled());
|
2016-08-11 07:13:55 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 23:07:32 +02:00
|
|
|
|
2016-10-10 18:29:54 +02:00
|
|
|
void GrabberWrapper::setColors(const std::vector<ColorRgb> &ledColors, const int timeout_ms)
|
|
|
|
{
|
|
|
|
_hyperion->setColors(_priority, ledColors, timeout_ms, true, _grabberComponentId);
|
|
|
|
}
|
2017-02-17 08:33:34 +01:00
|
|
|
|
|
|
|
QStringList GrabberWrapper::availableGrabbers()
|
|
|
|
{
|
|
|
|
QStringList grabbers;
|
|
|
|
|
|
|
|
#ifdef ENABLE_DISPMANX
|
|
|
|
grabbers << "dispmanx";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_V4L2
|
|
|
|
grabbers << "v4l2";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_FB
|
|
|
|
grabbers << "framebuffer";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_AMLOGIC
|
|
|
|
grabbers << "amlogic";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_OSX
|
|
|
|
grabbers << "osx";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_X11
|
|
|
|
grabbers << "x11";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return grabbers;
|
|
|
|
}
|
2017-08-12 07:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
void GrabberWrapper::setVideoMode(const VideoMode mode)
|
|
|
|
{
|
|
|
|
if (_ggrabber != nullptr)
|
|
|
|
{
|
|
|
|
Info(_log,"setvideomode");
|
|
|
|
_ggrabber->setVideoMode(mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrabberWrapper::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom)
|
|
|
|
{
|
|
|
|
_ggrabber->setCropping(cropLeft, cropRight, cropTop, cropBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrabberWrapper::setImageProcessorEnabled(bool enable)
|
|
|
|
{
|
|
|
|
_imageProcessorEnabled = enable;
|
|
|
|
}
|