Details coming soon.

This commit is contained in:
Paulchen-Panther
2018-12-27 23:11:32 +01:00
parent e3be03ea73
commit d762aa2f3e
186 changed files with 6156 additions and 5444 deletions

View File

@@ -1,7 +1,7 @@
#include <grabber/AmlogicWrapper.h>
AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("AmLogic", &_grabber, grabWidth, grabHeight, updateRate_Hz, priority, hyperion::COMP_GRABBER)
AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz)
: GrabberWrapper("AmLogic", &_grabber, grabWidth, grabHeight, updateRate_Hz)
, _grabber(grabWidth, grabHeight)
{}

View File

@@ -7,7 +7,7 @@
#include "grabber/DispmanxFrameGrabber.h"
DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height)
: Grabber("DISPMANXGRABBER", width, height)
: Grabber("DISPMANXGRABBER", 0, 0)
, _vc_display(0)
, _vc_resource(0)
, _vc_flags(0)
@@ -20,48 +20,60 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned
// Initiase BCM
bcm_host_init();
{
// Check if the display can be opened and display the current resolution
// Open the connection to the display
_vc_display = vc_dispmanx_display_open(0);
assert(_vc_display > 0);
// Check if the display can be opened and display the current resolution
// Open the connection to the display
_vc_display = vc_dispmanx_display_open(0);
assert(_vc_display > 0);
// Obtain the display information
DISPMANX_MODEINFO_T vc_info;
int result = vc_dispmanx_display_get_info(_vc_display, &vc_info);
// Keep compiler happy in 'release' mode
(void)result;
assert(result == 0);
Info(_log, "Display opened with resolution: %dx%d", vc_info.width, vc_info.height);
// Obtain the display information
DISPMANX_MODEINFO_T vc_info;
int result = vc_dispmanx_display_get_info(_vc_display, &vc_info);
// Keep compiler happy in 'release' mode
(void)result;
assert(result == 0);
Info(_log, "Display opened with resolution: %dx%d", vc_info.width, vc_info.height);
// Close the displaye
vc_dispmanx_display_close(_vc_display);
}
// Close the displaye
vc_dispmanx_display_close(_vc_display);
// Create the resources for capturing image
uint32_t vc_nativeImageHandle;
_vc_resource = vc_dispmanx_resource_create(
VC_IMAGE_RGBA32,
width,
height,
&vc_nativeImageHandle);
assert(_vc_resource);
// Define the capture rectangle with the same size
vc_dispmanx_rect_set(&_rectangle, 0, 0, width, height);
// init the resource and capture rectangle
setWidthHeight(width, height);
}
DispmanxFrameGrabber::~DispmanxFrameGrabber()
{
delete[] _captureBuffer;
// Clean up resources
vc_dispmanx_resource_delete(_vc_resource);
freeResources();
// De-init BCM
bcm_host_deinit();
}
void DispmanxFrameGrabber::freeResources()
{
delete[] _captureBuffer;
// Clean up resources
vc_dispmanx_resource_delete(_vc_resource);
}
void DispmanxFrameGrabber::setWidthHeight(int width, int height)
{
if(_width != width || _height != height)
{
freeResources();
// Create the resources for capturing image
uint32_t vc_nativeImageHandle;
_vc_resource = vc_dispmanx_resource_create(
VC_IMAGE_RGBA32,
width,
height,
&vc_nativeImageHandle);
assert(_vc_resource);
// Define the capture rectangle with the same size
vc_dispmanx_rect_set(&_rectangle, 0, 0, width, height);
}
}
void DispmanxFrameGrabber::setFlags(const int vc_flags)
{
_vc_flags = vc_flags;
@@ -143,8 +155,8 @@ int DispmanxFrameGrabber::grabFrame(Image<ColorRgb> & image)
unsigned capturePitch = (_rectangle.width * sizeof(ColorRgba) + 63) & (~63);
// grab to temp buffer if image pitch isn't valid or if we are cropping
if (imagePitch != capturePitch
|| (unsigned)_rectangle.width != imageWidth
if (imagePitch != capturePitch
|| (unsigned)_rectangle.width != imageWidth
|| (unsigned)_rectangle.height != imageHeight)
{
// check if we need to resize the capture buffer

View File

@@ -1,7 +1,7 @@
#include <grabber/DispmanxWrapper.h>
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("Dispmanx", &_grabber, grabWidth, grabHeight, updateRate_Hz, priority, hyperion::COMP_GRABBER)
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz)
: GrabberWrapper("Dispmanx", &_grabber, grabWidth, grabHeight, updateRate_Hz)
, _grabber(grabWidth, grabHeight)
{
setImageProcessorEnabled(false);

View File

@@ -16,31 +16,9 @@ FramebufferFrameGrabber::FramebufferFrameGrabber(const QString & device, const u
: Grabber("FRAMEBUFFERGRABBER", width, height)
, _fbfd(0)
, _fbp(0)
, _fbDevice(device)
, _fbDevice()
{
int result;
struct fb_var_screeninfo vinfo;
// Check if the framebuffer device can be opened and display the current resolution
_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
if (_fbfd == 0)
{
Error(_log, "Error openning %s", QSTRING_CSTR(_fbDevice));
}
else
{
// get variable screen information
result = ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
if (result != 0)
{
Error(_log, "Could not get screen information");
}
else
{
Info(_log, "Display opened with resolution: %dx%d@%dbit", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
}
close(_fbfd);
}
setDevicePath(device);
}
FramebufferFrameGrabber::~FramebufferFrameGrabber()
@@ -63,7 +41,7 @@ int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
bytesPerPixel = vinfo.bits_per_pixel / 8;
capSize = vinfo.xres * vinfo.yres * bytesPerPixel;
switch (vinfo.bits_per_pixel)
{
case 16: pixelFormat = PIXELFORMAT_BGR16; break;
@@ -76,7 +54,7 @@ int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
}
/* map the device to memory */
_fbp = (unsigned char*)mmap(0, capSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, _fbfd, 0);
_fbp = (unsigned char*)mmap(0, capSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, _fbfd, 0);
_imageResampler.setHorizontalPixelDecimation(vinfo.xres/_width);
_imageResampler.setVerticalPixelDecimation(vinfo.yres/_height);
@@ -86,9 +64,41 @@ int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
vinfo.xres * bytesPerPixel,
pixelFormat,
image);
munmap(_fbp, capSize);
close(_fbfd);
return 0;
}
void FramebufferFrameGrabber::setDevicePath(const QString& path)
{
if(_fbDevice != path)
{
_fbDevice = path;
int result;
struct fb_var_screeninfo vinfo;
// Check if the framebuffer device can be opened and display the current resolution
_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
if (_fbfd == 0)
{
Error(_log, "Error openning %s", QSTRING_CSTR(_fbDevice));
}
else
{
// get variable screen information
result = ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
if (result != 0)
{
Error(_log, "Could not get screen information");
}
else
{
Info(_log, "Display opened with resolution: %dx%d@%dbit", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
}
close(_fbfd);
}
}
}

View File

@@ -1,7 +1,7 @@
#include <grabber/FramebufferWrapper.h>
FramebufferWrapper::FramebufferWrapper(const QString & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("FrameBuffer", &_grabber, grabWidth, grabHeight, updateRate_Hz, priority, hyperion::COMP_GRABBER)
FramebufferWrapper::FramebufferWrapper(const QString & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz)
: GrabberWrapper("FrameBuffer", &_grabber, grabWidth, grabHeight, updateRate_Hz)
, _grabber(device, grabWidth, grabHeight)
{}

View File

@@ -7,30 +7,10 @@
OsxFrameGrabber::OsxFrameGrabber(const unsigned display, const unsigned width, const unsigned height)
: Grabber("OSXGRABBER", width, height)
, _screenIndex(display)
, _screenIndex(100)
{
CGImageRef image;
CGDisplayCount displayCount;
CGDirectDisplayID displays[8];
// get list of displays
CGGetActiveDisplayList(8, displays, &displayCount);
if (_screenIndex + 1 > displayCount)
{
Error(_log, "Display with index %d is not available. Using main display", _screenIndex);
_display = kCGDirectMainDisplay;
}
else
{
_display = displays[_screenIndex];
}
image = CGDisplayCreateImage(_display);
assert(image != NULL);
Info(_log, "Display opened with resolution: %dx%d@%dbit", CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerPixel(image));
CGImageRelease(image);
// check if display is available
setDisplayIndex(display);
}
OsxFrameGrabber::~OsxFrameGrabber()
@@ -43,11 +23,11 @@ int OsxFrameGrabber::grabFrame(Image<ColorRgb> & image)
CGImageRef dispImage;
CFDataRef imgData;
unsigned char * pImgData;
unsigned char * pImgData;
unsigned dspWidth, dspHeight;
dispImage = CGDisplayCreateImage(_display);
// display lost, use main
if (dispImage == NULL && _display)
{
@@ -63,7 +43,7 @@ int OsxFrameGrabber::grabFrame(Image<ColorRgb> & image)
pImgData = (unsigned char*) CFDataGetBytePtr(imgData);
dspWidth = CGImageGetWidth(dispImage);
dspHeight = CGImageGetHeight(dispImage);
_imageResampler.setHorizontalPixelDecimation(dspWidth/_width);
_imageResampler.setVerticalPixelDecimation(dspHeight/_height);
_imageResampler.processImage( pImgData,
@@ -72,9 +52,40 @@ int OsxFrameGrabber::grabFrame(Image<ColorRgb> & image)
CGImageGetBytesPerRow(dispImage),
PIXELFORMAT_BGR32,
image);
CFRelease(imgData);
CGImageRelease(dispImage);
return 0;
}
void OsxFrameGrabber::setDisplayIndex(int index)
{
if(_screenIndex != index)
{
_screenIndex = index;
CGImageRef image;
CGDisplayCount displayCount;
CGDirectDisplayID displays[8];
// get list of displays
CGGetActiveDisplayList(8, displays, &displayCount);
if (_screenIndex + 1 > displayCount)
{
Error(_log, "Display with index %d is not available. Using main display", _screenIndex);
_display = kCGDirectMainDisplay;
}
else
{
_display = displays[_screenIndex];
}
image = CGDisplayCreateImage(_display);
assert(image != NULL);
Info(_log, "Display opened with resolution: %dx%d@%dbit", CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerPixel(image));
CGImageRelease(image);
}
}

View File

@@ -1,7 +1,7 @@
#include <grabber/OsxWrapper.h>
OsxWrapper::OsxWrapper(const unsigned display, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("OSX FrameGrabber", &_grabber, grabWidth, grabHeight, updateRate_Hz, priority, hyperion::COMP_GRABBER)
OsxWrapper::OsxWrapper(const unsigned display, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz)
: GrabberWrapper("OSX FrameGrabber", &_grabber, grabWidth, grabHeight, updateRate_Hz)
, _grabber(display, grabWidth, grabHeight)
{}

View File

@@ -27,13 +27,9 @@ V4L2Grabber::V4L2Grabber(const QString & device
, int input
, VideoStandard videoStandard
, PixelFormat pixelFormat
, unsigned width
, unsigned height
, int frameDecimation
, int horizontalPixelDecimation
, int verticalPixelDecimation
, int pixelDecimation
)
: Grabber("V4L2:"+device, width, height)
: Grabber("V4L2:"+device)
, _deviceName(device)
, _input(input)
, _videoStandard(videoStandard)
@@ -41,9 +37,9 @@ V4L2Grabber::V4L2Grabber(const QString & device
, _fileDescriptor(-1)
, _buffers()
, _pixelFormat(pixelFormat)
, _pixelDecimation(pixelDecimation)
, _lineLength(-1)
, _frameByteSize(-1)
, _frameDecimation(qMax(1, frameDecimation))
, _noSignalCounterThreshold(50)
, _noSignalThresholdColor(ColorRgb{0,0,0})
, _signalDetectionEnabled(true)
@@ -53,14 +49,13 @@ V4L2Grabber::V4L2Grabber(const QString & device
, _y_frac_min(0.25)
, _x_frac_max(0.75)
, _y_frac_max(0.75)
, _currentFrame(0)
, _streamNotifier(nullptr)
, _initialized(false)
, _deviceAutoDiscoverEnabled(false)
{
_imageResampler.setHorizontalPixelDecimation(qMax(1, horizontalPixelDecimation));
_imageResampler.setVerticalPixelDecimation(qMax(1, verticalPixelDecimation));
//_imageResampler.setHorizontalPixelDecimation(pixelDecimation);
//_imageResampler.setVerticalPixelDecimation(pixelDecimation);
getV4Ldevices();
}
@@ -245,11 +240,13 @@ void V4L2Grabber::open_device()
if (-1 == stat(QSTRING_CSTR(_deviceName), &st))
{
throw_errno_exception("Cannot identify '" + _deviceName + "'");
return;
}
if (!S_ISCHR(st.st_mode))
{
throw_exception("'" + _deviceName + "' is no device");
return;
}
_fileDescriptor = open(QSTRING_CSTR(_deviceName), O_RDWR | O_NONBLOCK, 0);
@@ -257,6 +254,7 @@ void V4L2Grabber::open_device()
if (-1 == _fileDescriptor)
{
throw_errno_exception("Cannot open '" + _deviceName + "'");
return;
}
// create the notifier for when a new frame is available
@@ -268,7 +266,10 @@ void V4L2Grabber::open_device()
void V4L2Grabber::close_device()
{
if (-1 == close(_fileDescriptor))
{
throw_errno_exception("close");
return;
}
_fileDescriptor = -1;
@@ -288,6 +289,7 @@ void V4L2Grabber::init_read(unsigned int buffer_size)
if (!_buffers[0].start) {
throw_exception("Out of memory");
return;
}
}
@@ -304,13 +306,16 @@ void V4L2Grabber::init_mmap()
if (-1 == xioctl(VIDIOC_REQBUFS, &req)) {
if (EINVAL == errno) {
throw_exception("'" + _deviceName + "' does not support memory mapping");
return;
} else {
throw_errno_exception("VIDIOC_REQBUFS");
return;
}
}
if (req.count < 2) {
throw_exception("Insufficient buffer memory on " + _deviceName);
return;
}
_buffers.resize(req.count);
@@ -325,7 +330,10 @@ void V4L2Grabber::init_mmap()
buf.index = n_buffers;
if (-1 == xioctl(VIDIOC_QUERYBUF, &buf))
{
throw_errno_exception("VIDIOC_QUERYBUF");
return;
}
_buffers[n_buffers].length = buf.length;
_buffers[n_buffers].start =
@@ -336,7 +344,10 @@ void V4L2Grabber::init_mmap()
_fileDescriptor, buf.m.offset);
if (MAP_FAILED == _buffers[n_buffers].start)
{
throw_errno_exception("mmap");
return;
}
}
}
@@ -354,8 +365,10 @@ void V4L2Grabber::init_userp(unsigned int buffer_size)
if (EINVAL == errno)
{
throw_exception("'" + _deviceName + "' does not support user pointer");
return;
} else {
throw_errno_exception("VIDIOC_REQBUFS");
return;
}
}
@@ -367,6 +380,7 @@ void V4L2Grabber::init_userp(unsigned int buffer_size)
if (!_buffers[n_buffers].start) {
throw_exception("Out of memory");
return;
}
}
}
@@ -378,14 +392,17 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
{
if (EINVAL == errno) {
throw_exception("'" + _deviceName + "' is no V4L2 device");
return;
} else {
throw_errno_exception("VIDIOC_QUERYCAP");
return;
}
}
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
throw_exception("'" + _deviceName + "' is no video capture device");
return;
}
switch (_ioMethod) {
@@ -393,6 +410,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (!(cap.capabilities & V4L2_CAP_READWRITE))
{
throw_exception("'" + _deviceName + "' does not support read i/o");
return;
}
break;
@@ -401,6 +419,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (!(cap.capabilities & V4L2_CAP_STREAMING))
{
throw_exception("'" + _deviceName + "' does not support streaming i/o");
return;
}
break;
}
@@ -438,6 +457,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_INPUT, &input))
{
throw_errno_exception("VIDIOC_S_INPUT");
return;
}
}
@@ -450,6 +470,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_STD, &std_id))
{
throw_errno_exception("VIDIOC_S_STD");
return;
}
}
break;
@@ -459,6 +480,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_STD, &std_id))
{
throw_errno_exception("VIDIOC_S_STD");
return;
}
}
break;
@@ -468,6 +490,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_STD, &std_id))
{
throw_errno_exception("VIDIOC_S_STD");
return;
}
}
break;
@@ -485,6 +508,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_G_FMT, &fmt))
{
throw_errno_exception("VIDIOC_G_FMT");
return;
}
// set the requested pixel format
@@ -505,19 +529,9 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
break;
}
// set the requested withd and height
if (_width > 0 || _height > 0)
{
if (_width > 0)
{
fmt.fmt.pix.width = _width;
}
if (fmt.fmt.pix.height > 0)
{
fmt.fmt.pix.height = _height;
}
}
// calc the size based on pixelDecimation
fmt.fmt.pix.width = fmt.fmt.pix.width / _pixelDecimation;
fmt.fmt.pix.height = fmt.fmt.pix.height / _pixelDecimation;
// set the line length
_lineLength = fmt.fmt.pix.bytesperline;
@@ -526,6 +540,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_S_FMT, &fmt))
{
throw_errno_exception("VIDIOC_S_FMT");
return;
}
// get the format settings again
@@ -533,6 +548,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
if (-1 == xioctl(VIDIOC_G_FMT, &fmt))
{
throw_errno_exception("VIDIOC_G_FMT");
return;
}
// store width & height
@@ -563,6 +579,7 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
break;
default:
throw_exception("Only pixel formats UYVY, YUYV, and RGB32 are supported");
return;
}
switch (_ioMethod) {
@@ -590,7 +607,10 @@ void V4L2Grabber::uninit_device()
case IO_METHOD_MMAP:
for (size_t i = 0; i < _buffers.size(); ++i)
if (-1 == munmap(_buffers[i].start, _buffers[i].length))
{
throw_errno_exception("munmap");
return;
}
break;
case IO_METHOD_USERPTR:
@@ -620,11 +640,17 @@ void V4L2Grabber::start_capturing()
buf.index = i;
if (-1 == xioctl(VIDIOC_QBUF, &buf))
{
throw_errno_exception("VIDIOC_QBUF");
return;
}
}
v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1 == xioctl(VIDIOC_STREAMON, &type))
{
throw_errno_exception("VIDIOC_STREAMON");
return;
}
break;
}
case IO_METHOD_USERPTR:
@@ -640,11 +666,17 @@ void V4L2Grabber::start_capturing()
buf.length = _buffers[i].length;
if (-1 == xioctl(VIDIOC_QBUF, &buf))
{
throw_errno_exception("VIDIOC_QBUF");
return;
}
}
v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1 == xioctl(VIDIOC_STREAMON, &type))
{
throw_errno_exception("VIDIOC_STREAMON");
return;
}
break;
}
}
@@ -692,6 +724,7 @@ int V4L2Grabber::read_frame()
default:
throw_errno_exception("read");
return 0;
}
}
@@ -718,6 +751,7 @@ int V4L2Grabber::read_frame()
default:
throw_errno_exception("VIDIOC_DQBUF");
return 0;
}
}
@@ -728,6 +762,7 @@ int V4L2Grabber::read_frame()
if (-1 == xioctl(VIDIOC_QBUF, &buf))
{
throw_errno_exception("VIDIOC_QBUF");
return 0;
}
break;
@@ -752,6 +787,7 @@ int V4L2Grabber::read_frame()
default:
throw_errno_exception("VIDIOC_DQBUF");
return 0;
}
}
@@ -768,6 +804,7 @@ int V4L2Grabber::read_frame()
if (-1 == xioctl(VIDIOC_QBUF, &buf))
{
throw_errno_exception("VIDIOC_QBUF");
return 0;
}
break;
}
@@ -783,19 +820,15 @@ int V4L2Grabber::read_frame()
bool V4L2Grabber::process_image(const void *p, int size)
{
if (++_currentFrame >= _frameDecimation)
// We do want a new frame...
if (size != _frameByteSize)
{
// We do want a new frame...
if (size != _frameByteSize)
{
Error(_log, "Frame too small: %d != %d", size, _frameByteSize);
}
else
{
process_image(reinterpret_cast<const uint8_t *>(p));
_currentFrame = 0; // restart counting
return true;
}
Error(_log, "Frame too small: %d != %d", size, _frameByteSize);
}
else
{
process_image(reinterpret_cast<const uint8_t *>(p));
return true;
}
return false;
@@ -874,20 +907,44 @@ int V4L2Grabber::xioctl(int request, void *arg)
void V4L2Grabber::throw_exception(const QString & error)
{
throw std::runtime_error(error.toStdString());
Error(_log, "Throws error: %s", QSTRING_CSTR(error));
}
void V4L2Grabber::throw_errno_exception(const QString & error)
{
throw std::runtime_error(QString(error + " error code " + QString::number(errno) + ", " + strerror(errno)).toStdString());
Error(_log, "Throws error nr: %s", QSTRING_CSTR(QString(error + " error code " + QString::number(errno) + ", " + strerror(errno))));
}
void V4L2Grabber::setSignalDetectionEnable(bool enable)
{
_signalDetectionEnabled = enable;
if(_signalDetectionEnabled != enable)
{
_signalDetectionEnabled = enable;
Info(_log, "Signal detection is now %s", enable ? "enabled" : "disabled");
}
}
bool V4L2Grabber::getSignalDetectionEnabled()
{
return _signalDetectionEnabled;
}
void V4L2Grabber::setPixelDecimation(int pixelDecimation)
{
if(_pixelDecimation != pixelDecimation)
{
uninit();
init();
}
}
void V4L2Grabber::setInputVideoStandard(int input, VideoStandard videoStandard)
{
if(_input != input || _videoStandard != videoStandard)
{
_input = input;
_videoStandard = videoStandard;
uninit();
init();
}
}

View File

@@ -2,45 +2,29 @@
#include <grabber/V4L2Wrapper.h>
#include <hyperion/ImageProcessorFactory.h>
// qt
#include <QTimer>
V4L2Wrapper::V4L2Wrapper(const QString &device,
int input,
VideoStandard videoStandard,
PixelFormat pixelFormat,
unsigned width,
unsigned height,
int frameDecimation,
int pixelDecimation,
double redSignalThreshold,
double greenSignalThreshold,
double blueSignalThreshold,
const int priority)
: GrabberWrapper("V4L2:"+device, &_grabber, width, height, 8, priority, hyperion::COMP_V4L)
int pixelDecimation )
: GrabberWrapper("V4L2:"+device, &_grabber, 0, 0, 10)
, _grabber(device,
input,
videoStandard,
pixelFormat,
width,
height,
frameDecimation,
pixelDecimation,
pixelDecimation)
{
// set the signal detection threshold of the grabber
_grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50);
_ggrabber = &_grabber;
// register the image type
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
qRegisterMetaType<std::vector<ColorRgb>>("std::vector<ColorRgb>");
qRegisterMetaType<hyperion::Components>("hyperion::Components");
// 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);
QObject::connect(&_grabber, SIGNAL(readError(const char*)), this, SLOT(readError(const char*)), Qt::DirectConnection);
_timer.setInterval(500);
}
bool V4L2Wrapper::start()
@@ -54,6 +38,11 @@ void V4L2Wrapper::stop()
GrabberWrapper::stop();
}
void V4L2Wrapper::setSignalThreshold(double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold)
{
_grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50);
}
void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom)
{
_grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom);
@@ -66,11 +55,7 @@ void V4L2Wrapper::setSignalDetectionOffset(double verticalMin, double horizontal
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
{
emit emitImage(_priority, image, _timeout_ms);
// process the new image
_processor->process(image, _ledColors);
setColors(_ledColors, _timeout_ms);
emit systemImage(image);
}
void V4L2Wrapper::readError(const char* err)
@@ -79,21 +64,9 @@ void V4L2Wrapper::readError(const char* err)
stop();
}
void V4L2Wrapper::checkSources()
{
if ( _hyperion->isCurrentPriority(_priority))
{
_grabber.start();
}
else
{
_grabber.stop();
}
}
void V4L2Wrapper::action()
{
checkSources();
}
void V4L2Wrapper::setSignalDetectionEnable(bool enable)

View File

@@ -1,17 +1,15 @@
#include <utils/Logger.h>
#include <grabber/X11Grabber.h>
X11Grabber::X11Grabber(bool useXGetImage, int cropLeft, int cropRight, int cropTop, int cropBottom, int horizontalPixelDecimation, int verticalPixelDecimation)
X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation)
: Grabber("X11GRABBER", 0, 0, cropLeft, cropRight, cropTop, cropBottom)
, _useXGetImage(useXGetImage)
, _x11Display(nullptr)
, _pixmap(None)
, _srcFormat(nullptr)
, _dstFormat(nullptr)
, _srcPicture(None)
, _dstPicture(None)
, _horizontalDecimation(horizontalPixelDecimation)
, _verticalDecimation(verticalPixelDecimation)
, _pixelDecimation(pixelDecimation)
, _screenWidth(0)
, _screenHeight(0)
, _src_x(cropLeft)
@@ -37,13 +35,13 @@ void X11Grabber::freeResources()
{
// Cleanup allocated resources of the X11 grab
XDestroyImage(_xImage);
if(_XShmAvailable && !_useXGetImage)
if(_XShmAvailable)
{
XShmDetach(_x11Display, &_shminfo);
shmdt(_shminfo.shmaddr);
shmctl(_shminfo.shmid, IPC_RMID, 0);
}
if (_XRenderAvailable && !_useXGetImage)
if (_XRenderAvailable)
{
XRenderFreePicture(_x11Display, _srcPicture);
XRenderFreePicture(_x11Display, _dstPicture);
@@ -53,7 +51,7 @@ void X11Grabber::freeResources()
void X11Grabber::setupResources()
{
if(_XShmAvailable && !_useXGetImage)
if(_XShmAvailable)
{
_xImage = XShmCreateImage(_x11Display, _windowAttr.visual, _windowAttr.depth, ZPixmap, NULL, &_shminfo, _width, _height);
_shminfo.shmid = shmget(IPC_PRIVATE, _xImage->bytes_per_line * _xImage->height, IPC_CREAT|0777);
@@ -62,7 +60,7 @@ void X11Grabber::setupResources()
_shminfo.readOnly = False;
XShmAttach(_x11Display, &_shminfo);
}
if (_XRenderAvailable && !_useXGetImage)
if (_XRenderAvailable)
{
if(_XShmPixmapAvailable)
{
@@ -96,19 +94,19 @@ bool X11Grabber::Setup()
}
return false;
}
_window = DefaultRootWindow(_x11Display);
int dummy, pixmaps_supported;
_XRenderAvailable = XRenderQueryExtension(_x11Display, &dummy, &dummy);
_XShmAvailable = XShmQueryExtension(_x11Display);
XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported);
_XShmPixmapAvailable = pixmaps_supported && XShmPixmapFormat(_x11Display) == ZPixmap;
// Image scaling is performed by XRender when available, otherwise by ImageResampler
_imageResampler.setHorizontalPixelDecimation(_XRenderAvailable ? 1 : _horizontalDecimation);
_imageResampler.setVerticalPixelDecimation(_XRenderAvailable ? 1 : _verticalDecimation);
_imageResampler.setHorizontalPixelDecimation(_XRenderAvailable ? 1 : _pixelDecimation);
_imageResampler.setVerticalPixelDecimation(_XRenderAvailable ? 1 : _pixelDecimation);
bool result = (updateScreenDimensions(true) >=0);
ErrorIf(!result, _log, "X11 Grabber start failed");
@@ -119,14 +117,15 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
{
if (!_enabled) return 0;
updateScreenDimensions(forceUpdate);
if (_XRenderAvailable && !_useXGetImage)
if (forceUpdate)
updateScreenDimensions(forceUpdate);
if (_XRenderAvailable)
{
double scale_x = static_cast<double>(_windowAttr.width / _horizontalDecimation) / static_cast<double>(_windowAttr.width);
double scale_y = static_cast<double>(_windowAttr.height / _verticalDecimation) / static_cast<double>(_windowAttr.height);
double scale_x = static_cast<double>(_windowAttr.width / _pixelDecimation) / static_cast<double>(_windowAttr.width);
double scale_y = static_cast<double>(_windowAttr.height / _pixelDecimation) / static_cast<double>(_windowAttr.height);
double scale = qMin(scale_y, scale_x);
_transform =
{
{
@@ -147,27 +146,27 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
}
}
};
XRenderSetPictureTransform (_x11Display, _srcPicture, &_transform);
// display, op, src, mask, dest, src_x = cropLeft,
// src_y = cropTop, mask_x, mask_y, dest_x, dest_y, width, height
// src_y = cropTop, mask_x, mask_y, dest_x, dest_y, width, height
XRenderComposite(
_x11Display, PictOpSrc, _srcPicture, None, _dstPicture, ( _src_x/_horizontalDecimation),
(_src_y/_verticalDecimation), 0, 0, 0, 0, _width, _height);
_x11Display, PictOpSrc, _srcPicture, None, _dstPicture, ( _src_x/_pixelDecimation),
(_src_y/_pixelDecimation), 0, 0, 0, 0, _width, _height);
XSync(_x11Display, False);
if (_XShmAvailable)
{
XShmGetImage(_x11Display, _pixmap, _xImage, 0, 0, AllPlanes);
}
else
{
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _width, _height, AllPlanes, ZPixmap);
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _width, _height, AllPlanes, ZPixmap);
}
}
else if (_XShmAvailable && !_useXGetImage)
else if (_XShmAvailable)
{
// use xshm
XShmGetImage(_x11Display, _window, _xImage, _src_x, _src_y, AllPlanes);
@@ -212,20 +211,20 @@ int X11Grabber::updateScreenDimensions(bool force)
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _screenWidth, _screenHeight, _windowAttr.width, _windowAttr.height);
_screenWidth = _windowAttr.width;
_screenHeight = _windowAttr.height;
int width=0, height=0;
// Image scaling is performed by XRender when available, otherwise by ImageResampler
if (_XRenderAvailable && !_useXGetImage)
if (_XRenderAvailable)
{
width = (_screenWidth > unsigned(_cropLeft + _cropRight))
? ((_screenWidth - _cropLeft - _cropRight) / _horizontalDecimation)
: _screenWidth / _horizontalDecimation;
? ((_screenWidth - _cropLeft - _cropRight) / _pixelDecimation)
: _screenWidth / _pixelDecimation;
height = (_screenHeight > unsigned(_cropTop + _cropBottom))
? ((_screenHeight - _cropTop - _cropBottom) / _verticalDecimation)
: _screenHeight / _verticalDecimation;
? ((_screenHeight - _cropTop - _cropBottom) / _pixelDecimation)
: _screenHeight / _pixelDecimation;
Info(_log, "Using XRender for grabbing");
}
else
@@ -233,11 +232,11 @@ int X11Grabber::updateScreenDimensions(bool force)
width = (_screenWidth > unsigned(_cropLeft + _cropRight))
? (_screenWidth - _cropLeft - _cropRight)
: _screenWidth;
height = (_screenHeight > unsigned(_cropTop + _cropBottom))
? (_screenHeight - _cropTop - _cropBottom)
: _screenHeight;
Info(_log, "Using XGetImage for grabbing");
}
@@ -264,7 +263,7 @@ int X11Grabber::updateScreenDimensions(bool force)
_src_y = _cropTop;
break;
}
Info(_log, "Update output image resolution: [%dx%d] to [%dx%d]", _image.width(), _image.height(), _width, _height);
_image.resize(_width, _height);
@@ -275,7 +274,26 @@ int X11Grabber::updateScreenDimensions(bool force)
void X11Grabber::setVideoMode(VideoMode mode)
{
Info(_log, "a %d", mode);
Grabber::setVideoMode(mode);
updateScreenDimensions(true);
}
void X11Grabber::setWidthHeight(int width, int height)
{
// empty overwrite
}
void X11Grabber::setPixelDecimation(int pixelDecimation)
{
if(_pixelDecimation != pixelDecimation)
{
_pixelDecimation = pixelDecimation;
updateScreenDimensions(true);
}
}
void X11Grabber::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom)
{
Grabber::setCropping(cropLeft, cropRight, cropTop, cropBottom);
if(_x11Display != nullptr) updateScreenDimensions(true); // segfault on init
}

View File

@@ -1,8 +1,8 @@
#include <grabber/X11Wrapper.h>
X11Wrapper::X11Wrapper(bool useXGetImage, int cropLeft, int cropRight, int cropTop, int cropBottom, int horizontalPixelDecimation, int verticalPixelDecimation, const unsigned updateRate_Hz, const int priority)
: GrabberWrapper("X11", &_grabber, 0, 0, updateRate_Hz, priority, hyperion::COMP_GRABBER)
, _grabber(useXGetImage, cropLeft, cropRight, cropTop, cropBottom, horizontalPixelDecimation, verticalPixelDecimation)
X11Wrapper::X11Wrapper(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, const unsigned updateRate_Hz)
: GrabberWrapper("X11", &_grabber, 0, 0, updateRate_Hz)
, _grabber(cropLeft, cropRight, cropTop, cropBottom, pixelDecimation)
, _init(false)
{}