enable components at runtime + grabber refactoring (#160)

* implement enable/disable on runtime for:
- smoothing
- kodi
- udplistener
- boblight

* implement enable/disable for forwarder
refactor component

* - implement grabber enable/disable at runtime
- big grabber refactoring. now with common base class for all grabbers

* implement enable/disable at runtime for bb detector

* osx fix

* try to fix cutted travis output for osx build
This commit is contained in:
redPanther
2016-08-11 07:13:55 +02:00
committed by GitHub
parent 0d3f6c7ba1
commit f1cc82b8c7
36 changed files with 471 additions and 495 deletions

View File

@@ -12,45 +12,28 @@
AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: _updateInterval_ms(1000/updateRate_Hz)
: GrabberWrapper("AmLogic", priority)
, _updateInterval_ms(1000/updateRate_Hz)
, _timeout_ms(2 * _updateInterval_ms)
, _priority(priority)
, _timer()
, _image(grabWidth, grabHeight)
, _frameGrabber(new AmlogicGrabber(grabWidth, grabHeight))
, _processor(ImageProcessorFactory::getInstance().newImageProcessor())
, _grabber(new AmlogicGrabber(grabWidth, grabHeight))
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
, _hyperion(Hyperion::getInstance())
{
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
_processor->setSize(grabWidth, grabHeight);
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
AmlogicWrapper::~AmlogicWrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _frameGrabber;
}
void AmlogicWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
_hyperion->registerPriority("Amlogic Grabber",_priority);
delete _grabber;
}
void AmlogicWrapper::action()
{
// Grab frame into the allocated image
if (_frameGrabber->grabFrame(_image) < 0)
if (_grabber->grabFrame(_image) < 0)
{
// Frame grab failed, maybe nothing playing or ....
return;
@@ -67,21 +50,13 @@ void AmlogicWrapper::action()
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}
void AmlogicWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
_hyperion->unRegisterPriority("Amlogic Grabber");
}
void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode)
{
switch (mode)
{
case GRABBINGMODE_VIDEO:
case GRABBINGMODE_PAUSE:
// _frameGrabber->setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
// _grabber->setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
start();
break;
case GRABBINGMODE_AUDIO:
@@ -89,7 +64,7 @@ void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode)
case GRABBINGMODE_MENU:
case GRABBINGMODE_SCREENSAVER:
case GRABBINGMODE_INVALID:
// _frameGrabber->setFlags(0);
// _grabber->setFlags(0);
start();
break;
case GRABBINGMODE_OFF:
@@ -100,5 +75,5 @@ void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode)
void AmlogicWrapper::setVideoMode(const VideoMode mode)
{
_frameGrabber->setVideoMode(mode);
_grabber->setVideoMode(mode);
}

View File

@@ -11,46 +11,29 @@
#include <grabber/DispmanxFrameGrabber.h>
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority) :
_updateInterval_ms(1000/updateRate_Hz),
_timeout_ms(2 * _updateInterval_ms),
_priority(priority),
_timer(),
_image(grabWidth, grabHeight),
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}),
_hyperion(Hyperion::getInstance())
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("Dispmanx", priority)
, _updateInterval_ms(1000/updateRate_Hz)
, _timeout_ms(2 * _updateInterval_ms)
, _image(grabWidth, grabHeight)
, _grabber(new DispmanxFrameGrabber(grabWidth, grabHeight))
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
{
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
_processor->setSize(grabWidth, grabHeight);
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
DispmanxWrapper::~DispmanxWrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _frameGrabber;
}
void DispmanxWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
_hyperion->registerPriority("Dispmanx Grabber", _priority);
delete _grabber;
}
void DispmanxWrapper::action()
{
// Grab frame into the allocated image
_frameGrabber->grabFrame(_image);
_grabber->grabFrame(_image);
if ( _forward )
{
@@ -63,20 +46,13 @@ void DispmanxWrapper::action()
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}
void DispmanxWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
_hyperion->unRegisterPriority("Dispmanx Grabber");
}
void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode)
{
switch (mode)
{
case GRABBINGMODE_VIDEO:
case GRABBINGMODE_PAUSE:
_frameGrabber->setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
_grabber->setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
start();
break;
case GRABBINGMODE_AUDIO:
@@ -84,7 +60,7 @@ void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode)
case GRABBINGMODE_MENU:
case GRABBINGMODE_SCREENSAVER:
case GRABBINGMODE_INVALID:
_frameGrabber->setFlags(0);
_grabber->setFlags(0);
start();
break;
case GRABBINGMODE_OFF:
@@ -95,11 +71,11 @@ void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode)
void DispmanxWrapper::setVideoMode(const VideoMode mode)
{
_frameGrabber->setVideoMode(mode);
_grabber->setVideoMode(mode);
}
void DispmanxWrapper::setCropping(const unsigned cropLeft, const unsigned cropRight,
const unsigned cropTop, const unsigned cropBottom)
{
_frameGrabber->setCropping(cropLeft, cropRight, cropTop, cropBottom);
_grabber->setCropping(cropLeft, cropRight, cropTop, cropBottom);
}

View File

@@ -7,57 +7,38 @@
#include <grabber/FramebufferWrapper.h>
#include <grabber/FramebufferFrameGrabber.h>
FramebufferWrapper::FramebufferWrapper(const std::string & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority) :
_updateInterval_ms(1000/updateRate_Hz),
_timeout_ms(2 * _updateInterval_ms),
_priority(priority),
_timer(),
_image(grabWidth, grabHeight),
_frameGrabber(new FramebufferFrameGrabber(device, grabWidth, grabHeight)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}),
_hyperion(Hyperion::getInstance())
FramebufferWrapper::FramebufferWrapper(const std::string & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("FrameBuffer", priority)
, _updateInterval_ms(1000/updateRate_Hz)
, _timeout_ms(2 * _updateInterval_ms)
, _image(grabWidth, grabHeight)
, _grabber(new FramebufferFrameGrabber(device, grabWidth, grabHeight))
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
{
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
_processor->setSize(grabWidth, grabHeight);
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
FramebufferWrapper::~FramebufferWrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _frameGrabber;
}
void FramebufferWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
_hyperion->registerPriority("FrameBuffer Grabber", _priority);
delete _grabber;
}
void FramebufferWrapper::action()
{
// Grab frame into the allocated image
_frameGrabber->grabFrame(_image);
emit emitImage(_priority, _image, _timeout_ms);
_grabber->grabFrame(_image);
if ( _forward )
{
emit emitImage(_priority, _image, _timeout_ms);
}
_processor->process(_image, _ledColors);
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}
void FramebufferWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
_hyperion->unRegisterPriority("FrameBuffer Grabber");
}
void FramebufferWrapper::setGrabbingMode(const GrabbingMode mode)
{
@@ -80,5 +61,5 @@ void FramebufferWrapper::setGrabbingMode(const GrabbingMode mode)
void FramebufferWrapper::setVideoMode(const VideoMode mode)
{
_frameGrabber->setVideoMode(mode);
_grabber->setVideoMode(mode);
}

View File

@@ -7,57 +7,38 @@
#include <grabber/OsxWrapper.h>
#include <grabber/OsxFrameGrabber.h>
OsxWrapper::OsxWrapper(const unsigned display, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority) :
_updateInterval_ms(1000/updateRate_Hz),
_timeout_ms(2 * _updateInterval_ms),
_priority(priority),
_timer(),
_image(grabWidth, grabHeight),
_frameGrabber(new OsxFrameGrabber(display, grabWidth, grabHeight)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}),
_hyperion(Hyperion::getInstance())
OsxWrapper::OsxWrapper(const unsigned display, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("OSX FrameGrabber", priority)
, _updateInterval_ms(1000/updateRate_Hz)
, _timeout_ms(2 * _updateInterval_ms)
, _image(grabWidth, grabHeight)
, _grabber(new OsxFrameGrabber(display, grabWidth, grabHeight))
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
{
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
_processor->setSize(grabWidth, grabHeight);
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
OsxWrapper::~OsxWrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _frameGrabber;
}
void OsxWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
_hyperion->registerPriority("OsxFrameGrabber", _priority);
delete _grabber;
}
void OsxWrapper::action()
{
// Grab frame into the allocated image
_frameGrabber->grabFrame(_image);
_grabber->grabFrame(_image);
emit emitImage(_priority, _image, _timeout_ms);
if ( _forward )
{
emit emitImage(_priority, _image, _timeout_ms);
}
_processor->process(_image, _ledColors);
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}
void OsxWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
_hyperion->unRegisterPriority("OsxFrameGrabber");
}
void OsxWrapper::setGrabbingMode(const GrabbingMode mode)
{
@@ -80,5 +61,5 @@ void OsxWrapper::setGrabbingMode(const GrabbingMode mode)
void OsxWrapper::setVideoMode(const VideoMode mode)
{
_frameGrabber->setVideoMode(mode);
_grabber->setVideoMode(mode);
}

View File

@@ -15,9 +15,9 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
double redSignalThreshold,
double greenSignalThreshold,
double blueSignalThreshold,
int hyperionPriority)
: _timeout_ms(1000)
, _priority(hyperionPriority)
const int priority)
: GrabberWrapper("V4L2", priority)
, _timeout_ms(1000)
, _grabber(device,
input,
videoStandard,
@@ -27,10 +27,7 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
frameDecimation,
pixelDecimation,
pixelDecimation)
, _processor(ImageProcessorFactory::getInstance().newImageProcessor())
, _hyperion(Hyperion::getInstance())
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
, _timer()
{
// set the signal detection threshold of the grabber
_grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50);
@@ -46,44 +43,30 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
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);
// QObject::connect(
// this, SIGNAL(emitColors(int,std::vector<ColorRgb>,int)),
// _hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)),
// Qt::QueuedConnection);
// setup the higher prio source checker
// this will disable the v4l2 grabber when a source with hisher priority is active
// this will disable the v4l2 grabber when a source with higher priority is active
_timer.setInterval(500);
_timer.setSingleShot(false);
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(checkSources()));
}
V4L2Wrapper::~V4L2Wrapper()
{
delete _processor;
}
bool V4L2Wrapper::start()
{
_timer.start();
bool grabber_started = _grabber.start();
if ( ! grabber_started )
{
_timer.stop();
}
else
{
_hyperion->registerPriority("V4L2", _priority);
}
return grabber_started;
return ( _grabber.start() && GrabberWrapper::start());
}
void V4L2Wrapper::stop()
{
_grabber.stop();
_hyperion->unRegisterPriority("V4L2");
GrabberWrapper::stop();
}
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
@@ -98,14 +81,15 @@ void V4L2Wrapper::set3D(VideoMode mode)
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
{
// forward to other hyperions
if ( _forward )
{
emit emitImage(_priority, image, _timeout_ms);
}
// process the new image
_processor->process(image, _ledColors);
// forward to other hyperions
emit emitImage(_priority, image, _timeout_ms);
// send colors to Hyperion
emit emitColors(_priority, _ledColors, _timeout_ms);
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}
void V4L2Wrapper::checkSources()
@@ -125,3 +109,8 @@ void V4L2Wrapper::checkSources()
// no higher priority source was found: grabber should be enabled
_grabber.start();
}
void V4L2Wrapper::action()
{
checkSources();
}

View File

@@ -8,34 +8,24 @@
#include <grabber/X11Grabber.h>
X11Wrapper::X11Wrapper(bool useXGetImage, int cropLeft, int cropRight, int cropTop, int cropBottom, int horizontalPixelDecimation, int verticalPixelDecimation, const unsigned updateRate_Hz, const int priority)
: _updateInterval_ms(1000/updateRate_Hz)
: GrabberWrapper("X11", priority)
, _updateInterval_ms(1000/updateRate_Hz)
, _timeout_ms(2 * _updateInterval_ms)
, _priority(priority)
, _timer()
// , _image(grabWidth, grabHeight)
, _grabber(new X11Grabber(useXGetImage, cropLeft, cropRight, cropTop, cropBottom, horizontalPixelDecimation, verticalPixelDecimation))
, _processor(ImageProcessorFactory::getInstance().newImageProcessor())
, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0})
, _hyperion(Hyperion::getInstance())
, _init(false)
, _x11SetupSuccess(false)
{
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
X11Wrapper::~X11Wrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _grabber;
}
void X11Wrapper::start()
bool X11Wrapper::start()
{
if (! _init )
{
@@ -51,11 +41,11 @@ void X11Wrapper::start()
// Start the timer with the pre configured interval
if ( _x11SetupSuccess )
{
_timer.start();
_hyperion->registerPriority("X11 Grabber", _priority);
GrabberWrapper::start();
}
ErrorIf( ! _x11SetupSuccess, Logger::getInstance("X11"), "X11 Grabber start failed");
ErrorIf( ! _x11SetupSuccess, _log, "X11 Grabber start failed");
return _x11SetupSuccess;
}
@@ -74,17 +64,14 @@ void X11Wrapper::action()
// Grab frame into the allocated image
_grabber->grabFrame(_image);
emit emitImage(_priority, _image, _timeout_ms);
if ( _forward )
{
emit emitImage(_priority, _image, _timeout_ms);
}
_processor->process(_image, _ledColors);
_hyperion->setColors(_priority, _ledColors, _timeout_ms);
}
void X11Wrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
_hyperion->unRegisterPriority("X11 Grabber");
}
void X11Wrapper::setGrabbingMode(const GrabbingMode mode)
{