even more changes

Signed-off-by: Paulchen-Panther <Paulchen--Panter@gmx.net>
This commit is contained in:
Paulchen-Panther
2018-12-28 18:12:45 +01:00
parent 3700566d10
commit 2a77f6f012
99 changed files with 2610 additions and 673 deletions

View File

@@ -30,12 +30,19 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned
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
// Close the display
vc_dispmanx_display_close(_vc_display);
if(result != 0)
{
Error(_log, "Failed to open display! Probably no permissions to access the capture interface");
setEnabled(false);
return;
}
else
Info(_log, "Display opened with resolution: %dx%d", vc_info.width, vc_info.height);
// init the resource and capture rectangle
setWidthHeight(width, height);
}
@@ -55,11 +62,12 @@ void DispmanxFrameGrabber::freeResources()
vc_dispmanx_resource_delete(_vc_resource);
}
void DispmanxFrameGrabber::setWidthHeight(int width, int height)
bool DispmanxFrameGrabber::setWidthHeight(int width, int height)
{
if(_width != width || _height != height)
if(Grabber::setWidthHeight(width, height))
{
freeResources();
if(_vc_resource != 0)
vc_dispmanx_resource_delete(_vc_resource);
// Create the resources for capturing image
uint32_t vc_nativeImageHandle;
_vc_resource = vc_dispmanx_resource_create(
@@ -71,7 +79,9 @@ void DispmanxFrameGrabber::setWidthHeight(int width, int height)
// Define the capture rectangle with the same size
vc_dispmanx_rect_set(&_rectangle, 0, 0, width, height);
return true;
}
return false;
}
void DispmanxFrameGrabber::setFlags(const int vc_flags)

View File

@@ -4,7 +4,7 @@ DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHe
: GrabberWrapper("Dispmanx", &_grabber, grabWidth, grabHeight, updateRate_Hz)
, _grabber(grabWidth, grabHeight)
{
setImageProcessorEnabled(false);
}
void DispmanxWrapper::action()

View File

@@ -82,7 +82,14 @@ void OsxFrameGrabber::setDisplayIndex(int index)
}
image = CGDisplayCreateImage(_display);
assert(image != NULL);
if(image == NULL)
{
Error(_log, "Failed to open main display, disable capture interface");
setEnabled(false);
return;
}
else
setEnabled(true);
Info(_log, "Display opened with resolution: %dx%d@%dbit", CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerPixel(image));

View File

@@ -18,29 +18,29 @@
#include <QDirIterator>
#include <QFileInfo>
#include <QTimer>
#include "grabber/V4L2Grabber.h"
#define CLEAR(x) memset(&(x), 0, sizeof(x))
V4L2Grabber::V4L2Grabber(const QString & device
, int input
, VideoStandard videoStandard
, PixelFormat pixelFormat
, int pixelDecimation
)
: Grabber("V4L2:"+device)
, _deviceName(device)
, _input(input)
, _deviceName()
, _input(-1)
, _videoStandard(videoStandard)
, _ioMethod(IO_METHOD_MMAP)
, _fileDescriptor(-1)
, _buffers()
, _pixelFormat(pixelFormat)
, _pixelDecimation(pixelDecimation)
, _pixelDecimation(-1)
, _lineLength(-1)
, _frameByteSize(-1)
, _noSignalCounterThreshold(50)
, _noSignalCounterThreshold(40)
, _noSignalThresholdColor(ColorRgb{0,0,0})
, _signalDetectionEnabled(true)
, _noSignalDetected(false)
@@ -52,12 +52,17 @@ V4L2Grabber::V4L2Grabber(const QString & device
, _streamNotifier(nullptr)
, _initialized(false)
, _deviceAutoDiscoverEnabled(false)
, _readFrameAdaptTimer(new QTimer(this))
{
//_imageResampler.setHorizontalPixelDecimation(pixelDecimation);
//_imageResampler.setVerticalPixelDecimation(pixelDecimation);
// setup stream notify locker with 10hz
connect(_readFrameAdaptTimer, &QTimer::timeout, this, &V4L2Grabber::unlockReadFrame);
_readFrameAdaptTimer->setInterval(100);
setPixelDecimation(pixelDecimation);
getV4Ldevices();
// init
setDeviceVideoStandard(device, videoStandard);
}
V4L2Grabber::~V4L2Grabber()
@@ -67,10 +72,12 @@ V4L2Grabber::~V4L2Grabber()
void V4L2Grabber::uninit()
{
Debug(_log,"uninit grabber: %s", QSTRING_CSTR(_deviceName));
// stop if the grabber was not stopped
if (_initialized)
{
Debug(_log,"uninit grabber: %s", QSTRING_CSTR(_deviceName));
_readFrameAdaptTimer->stop();
stop();
uninit_device();
close_device();
@@ -78,7 +85,6 @@ void V4L2Grabber::uninit()
}
}
bool V4L2Grabber::init()
{
if (! _initialized)
@@ -133,10 +139,15 @@ bool V4L2Grabber::init()
bool opened = false;
try
{
open_device();
opened = true;
init_device(_videoStandard, _input);
_initialized = true;
// do not init with unknown device
if(_deviceName != "unknown")
{
open_device();
opened = true;
init_device(_videoStandard, _input);
_initialized = true;
_readFrameAdaptTimer->start();
}
}
catch(std::exception& e)
{
@@ -529,13 +540,13 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
break;
}
// TODO Does never accept own sizes? use always _imageResampler instead
/*
// 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;
// set the settings
if (-1 == xioctl(VIDIOC_S_FMT, &fmt))
{
@@ -550,6 +561,9 @@ void V4L2Grabber::init_device(VideoStandard videoStandard, int input)
throw_errno_exception("VIDIOC_G_FMT");
return;
}
*/
// set the line length
_lineLength = fmt.fmt.pix.bytesperline;
// store width & height
_width = fmt.fmt.pix.width;
@@ -701,6 +715,10 @@ void V4L2Grabber::stop_capturing()
int V4L2Grabber::read_frame()
{
// read_frame() is called with 25Hz, adapt to 10Hz. In the end it's up to the stream notifier if we get calls or not
if(!_readFrame) return -1;
_readFrame = false;
bool rc = false;
try
@@ -933,18 +951,30 @@ void V4L2Grabber::setPixelDecimation(int pixelDecimation)
{
if(_pixelDecimation != pixelDecimation)
{
_pixelDecimation = pixelDecimation;
uninit();
init();
// start if init is a success
if(init())
start();
_imageResampler.setHorizontalPixelDecimation(pixelDecimation);
_imageResampler.setVerticalPixelDecimation(pixelDecimation);
}
}
void V4L2Grabber::setInputVideoStandard(int input, VideoStandard videoStandard)
void V4L2Grabber::setDeviceVideoStandard(QString device, VideoStandard videoStandard)
{
if(_input != input || _videoStandard != videoStandard)
if(_deviceName != device || _videoStandard != videoStandard)
{
_input = input;
_videoStandard = videoStandard;
// extract input of device
QChar input = device.at(device.size() - 1);
_input = input.isNumber() ? input.digitValue() : -1;
uninit();
init();
_deviceName = device;
_videoStandard = videoStandard;
// start if init is a success
if(init())
start();
}
}

View File

@@ -6,13 +6,11 @@
#include <QTimer>
V4L2Wrapper::V4L2Wrapper(const QString &device,
int input,
VideoStandard videoStandard,
PixelFormat pixelFormat,
int pixelDecimation )
: GrabberWrapper("V4L2:"+device, &_grabber, 0, 0, 10)
, _grabber(device,
input,
videoStandard,
pixelFormat,
pixelDecimation)
@@ -66,7 +64,7 @@ void V4L2Wrapper::readError(const char* err)
void V4L2Wrapper::action()
{
// dummy as v4l get notifications from stream
}
void V4L2Wrapper::setSignalDetectionEnable(bool enable)

View File

@@ -110,6 +110,7 @@ bool X11Grabber::Setup()
bool result = (updateScreenDimensions(true) >=0);
ErrorIf(!result, _log, "X11 Grabber start failed");
setEnabled(result);
return result;
}
@@ -278,11 +279,6 @@ void X11Grabber::setVideoMode(VideoMode mode)
updateScreenDimensions(true);
}
void X11Grabber::setWidthHeight(int width, int height)
{
// empty overwrite
}
void X11Grabber::setPixelDecimation(int pixelDecimation)
{
if(_pixelDecimation != pixelDecimation)