mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
new frame grabber handling (#137)
* - implement framegrabber type option - framegrabber autoselect - integrate x11 grabber in hyperiond * add doxy * v4l: select device by name hyperiond: fix x11 grabber connection to kodichecker config: tune default prios of boblight and v4l * make v4l name finding case insensitive
This commit is contained in:
@@ -9,6 +9,9 @@ include_directories(
|
||||
${QT_INCLUDES}
|
||||
${X11_INCLUDES}
|
||||
)
|
||||
SET(X11_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/X11Wrapper.h
|
||||
)
|
||||
|
||||
SET(X11_HEADERS
|
||||
${CURRENT_HEADER_DIR}/X11Grabber.h
|
||||
@@ -16,6 +19,7 @@ SET(X11_HEADERS
|
||||
|
||||
SET(X11_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/X11Grabber.cpp
|
||||
${CURRENT_SOURCE_DIR}/X11Wrapper.cpp
|
||||
)
|
||||
|
||||
QT5_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
|
||||
@@ -29,5 +33,7 @@ add_library(x11-grabber
|
||||
|
||||
target_link_libraries(x11-grabber
|
||||
hyperion
|
||||
${QT_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${X11_Xrender_LIB}
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
@@ -162,6 +162,49 @@ Image<ColorRgb> & X11Grabber::grab()
|
||||
return _image;
|
||||
}
|
||||
|
||||
int X11Grabber::grabFrame(Image<ColorRgb> & image)
|
||||
{
|
||||
if (_XRenderAvailable && !_useXGetImage) {
|
||||
XRenderComposite( _x11Display, // *dpy,
|
||||
PictOpSrc, // op,
|
||||
_srcPicture, // src
|
||||
None, // mask
|
||||
_dstPicture, // dst
|
||||
_cropLeft, // src_x
|
||||
_cropTop, // src_y
|
||||
0, // mask_x
|
||||
0, // mask_y
|
||||
0, // dst_x
|
||||
0, // dst_y
|
||||
_croppedWidth, // width
|
||||
_croppedHeight); // height
|
||||
|
||||
XSync(_x11Display, False);
|
||||
|
||||
if (_XShmAvailable) {
|
||||
XShmGetImage(_x11Display, _pixmap, _xImage, 0, 0, AllPlanes);
|
||||
} else {
|
||||
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _croppedWidth, _croppedHeight, AllPlanes, ZPixmap);
|
||||
}
|
||||
} else {
|
||||
if (_XShmAvailable && !_useXGetImage) {
|
||||
XShmGetImage(_x11Display, _window, _xImage, _cropLeft, _cropTop, AllPlanes);
|
||||
} else {
|
||||
_xImage = XGetImage(_x11Display, _window, _cropLeft, _cropTop, _croppedWidth, _croppedHeight, AllPlanes, ZPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
if (_xImage == nullptr)
|
||||
{
|
||||
Error(_log, "Grab Failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
_imageResampler.processImage(reinterpret_cast<const uint8_t *>(_xImage->data), _xImage->width, _xImage->height, _xImage->bytes_per_line, PIXELFORMAT_BGR32, image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int X11Grabber::updateScreenDimensions()
|
||||
{
|
||||
const Status status = XGetWindowAttributes(_x11Display, _window, &_windowAttr);
|
||||
@@ -176,18 +219,15 @@ int X11Grabber::updateScreenDimensions()
|
||||
// No update required
|
||||
return 0;
|
||||
}
|
||||
|
||||
Info(_log, "Update of screen resolution: [%dx%d]", _screenWidth, _screenHeight);
|
||||
|
||||
if (_screenWidth || _screenHeight) {
|
||||
freeResources();
|
||||
}
|
||||
|
||||
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _screenWidth, _screenHeight, _windowAttr.width, _windowAttr.height);
|
||||
_screenWidth = _windowAttr.width;
|
||||
_screenHeight = _windowAttr.height;
|
||||
|
||||
Info(_log, " to [%dx%d]", _screenWidth, _screenHeight);
|
||||
|
||||
_croppedWidth = (_screenWidth > unsigned(_cropLeft + _cropRight))
|
||||
? (_screenWidth - _cropLeft - _cropRight)
|
||||
: _screenWidth;
|
||||
@@ -204,5 +244,5 @@ int X11Grabber::updateScreenDimensions()
|
||||
|
||||
setupResources();
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
111
libsrc/grabber/x11/X11Wrapper.cpp
Normal file
111
libsrc/grabber/x11/X11Wrapper.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
|
||||
// X11 grabber includes
|
||||
#include <grabber/X11Wrapper.h>
|
||||
#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)
|
||||
, _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()
|
||||
{
|
||||
if (! _init )
|
||||
{
|
||||
_init = true;
|
||||
_x11SetupSuccess = _grabber->Setup();
|
||||
if ( _x11SetupSuccess )
|
||||
{
|
||||
_x11SetupSuccess = (_grabber->updateScreenDimensions() >= 0);
|
||||
_processor->setSize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
||||
_image.resize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
||||
}
|
||||
}
|
||||
// Start the timer with the pre configured interval
|
||||
if ( _x11SetupSuccess )
|
||||
{
|
||||
_timer.start();
|
||||
_hyperion->registerPriority("X11 Grabber", _priority);
|
||||
}
|
||||
|
||||
ErrorIf( ! _x11SetupSuccess, Logger::getInstance("X11"), "X11 Grabber start failed");
|
||||
}
|
||||
|
||||
|
||||
void X11Wrapper::action()
|
||||
{
|
||||
int result = _grabber->updateScreenDimensions();
|
||||
if (result < 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( result > 0 )
|
||||
{
|
||||
_processor->setSize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
||||
_image.resize(_grabber->getImageWidth(), _grabber->getImageHeight());
|
||||
}
|
||||
// Grab frame into the allocated image
|
||||
_grabber->grabFrame(_image);
|
||||
|
||||
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)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case GRABBINGMODE_VIDEO:
|
||||
case GRABBINGMODE_PAUSE:
|
||||
case GRABBINGMODE_AUDIO:
|
||||
case GRABBINGMODE_PHOTO:
|
||||
case GRABBINGMODE_MENU:
|
||||
case GRABBINGMODE_SCREENSAVER:
|
||||
case GRABBINGMODE_INVALID:
|
||||
start();
|
||||
break;
|
||||
case GRABBINGMODE_OFF:
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void X11Wrapper::setVideoMode(const VideoMode mode)
|
||||
{
|
||||
_grabber->setVideoMode(mode);
|
||||
}
|
Reference in New Issue
Block a user