Fix usage of _width/_height (they are the output resolution, not the screen resolution)

That avoids unnecessary resizing of the output image with every transferFrame call
This commit is contained in:
LordGrey
2024-01-01 12:32:30 +01:00
parent 77f7a6b3ba
commit 6df45507bf
5 changed files with 130 additions and 119 deletions

View File

@@ -113,8 +113,8 @@ private:
int _display; int _display;
int _numberOfSDisplays; int _numberOfSDisplays;
int _calculatedWidth; int _screenWidth;
int _calculatedHeight; int _screenHeight;
int _src_x; int _src_x;
int _src_y; int _src_y;
int _src_x_max; int _src_x_max;

View File

@@ -57,7 +57,7 @@ public:
/// ///
/// @brief Apply new width/height values, overwrite Grabber.h implementation as X11 doesn't use width/height, just pixelDecimation to calc dimensions /// @brief Apply new width/height values, overwrite Grabber.h implementation as X11 doesn't use width/height, just pixelDecimation to calc dimensions
/// ///
bool setWidthHeight(int width, int height) override { return true; } bool setWidthHeight(int /*width*/, int /*height*/) override { return true; }
/// ///
/// @brief Apply new pixelDecimation /// @brief Apply new pixelDecimation
@@ -109,19 +109,19 @@ private:
Picture _srcPicture; Picture _srcPicture;
Picture _dstPicture; Picture _dstPicture;
int _XRandREventBase; int _xRandREventBase;
XTransform _transform; XTransform _transform;
unsigned _calculatedWidth; int _screenWidth;
unsigned _calculatedHeight; int _screenHeight;
unsigned _src_x; int _src_x;
unsigned _src_y; int _src_y;
bool _XShmAvailable; bool _xShmAvailable;
bool _XShmPixmapAvailable; bool _xShmPixmapAvailable;
bool _XRenderAvailable; bool _xRenderAvailable;
bool _XRandRAvailable; bool _xRandRAvailable;
bool _isWayland; bool _isWayland;
Logger * _logger; Logger * _logger;

View File

@@ -5,7 +5,6 @@
AudioWrapper::AudioWrapper() AudioWrapper::AudioWrapper()
: GrabberWrapper("AudioGrabber", &_grabber) : GrabberWrapper("AudioGrabber", &_grabber)
, _grabber()
{ {
// register the image type // register the image type
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>"); qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");

View File

@@ -22,8 +22,8 @@ const bool verbose = false;
QtGrabber::QtGrabber(int display, int cropLeft, int cropRight, int cropTop, int cropBottom) QtGrabber::QtGrabber(int display, int cropLeft, int cropRight, int cropTop, int cropBottom)
: Grabber("QTGRABBER", cropLeft, cropRight, cropTop, cropBottom) : Grabber("QTGRABBER", cropLeft, cropRight, cropTop, cropBottom)
, _display(display) , _display(display)
, _calculatedWidth(0) , _screenWidth(0)
, _calculatedHeight(0) , _screenHeight(0)
, _src_x(0) , _src_x(0)
, _src_y(0) , _src_y(0)
, _src_x_max(0) , _src_x_max(0)
@@ -233,8 +233,8 @@ int QtGrabber::grabFrame(Image<ColorRgb>& image)
} }
else else
{ {
QImage imageFrame = originalPixmap.toImage().scaled(_calculatedWidth, _calculatedHeight).convertToFormat(QImage::Format_RGB888); QImage imageFrame = originalPixmap.toImage().scaled(_width, _height).convertToFormat(QImage::Format_RGB888);
image.resize(static_cast<uint>(_calculatedWidth), static_cast<uint>(_calculatedHeight)); image.resize(_width, _height);
for (int y = 0; y < imageFrame.height(); y++) for (int y = 0; y < imageFrame.height(); y++)
{ {
@@ -263,27 +263,27 @@ int QtGrabber::updateScreenDimensions(bool force)
{ {
geo = _screen->geometry(); geo = _screen->geometry();
} }
if (!force && _width == geo.width() && _height == geo.height()) if (!force && _screenWidth == geo.width() && _height == geo.height())
{ {
// No update required // No update required
return 0; return 0;
} }
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _width, _height, geo.width(), geo.height()); Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _screenWidth, _screenHeight, geo.width(), geo.height());
_width = geo.width(); _screenWidth = geo.width();
_height = geo.height(); _screenHeight = geo.height();
int width = 0; int width = 0;
int height = 0; int height = 0;
// Image scaling is performed by Qt // Image scaling is performed by Qt
width = (_width > (_cropLeft + _cropRight)) width = (_screenWidth > (_cropLeft + _cropRight))
? ((_width - _cropLeft - _cropRight) / _pixelDecimation) ? ((_screenWidth - _cropLeft - _cropRight) / _pixelDecimation)
: (_width / _pixelDecimation); : (_screenWidth / _pixelDecimation);
height = (_height > (_cropTop + _cropBottom)) height = (_screenHeight > (_cropTop + _cropBottom))
? ((_height - _cropTop - _cropBottom) / _pixelDecimation) ? ((_screenHeight - _cropTop - _cropBottom) / _pixelDecimation)
: (_height / _pixelDecimation); : (_screenHeight / _pixelDecimation);
// calculate final image dimensions and adjust top/left cropping in 3D modes // calculate final image dimensions and adjust top/left cropping in 3D modes
if (_isVirtual) if (_isVirtual)
@@ -300,33 +300,33 @@ int QtGrabber::updateScreenDimensions(bool force)
switch (_videoMode) switch (_videoMode)
{ {
case VideoMode::VIDEO_3DSBS: case VideoMode::VIDEO_3DSBS:
_calculatedWidth = width / 2; _width = width / 2;
_calculatedHeight = height; _height = height;
_src_x = _src_x + (_cropLeft / 2); _src_x = _src_x + (_cropLeft / 2);
_src_y = _src_y + _cropTop; _src_y = _src_y + _cropTop;
_src_x_max = (_width / 2) - _cropRight - _cropLeft; _src_x_max = (_screenWidth / 2) - _cropRight - _cropLeft;
_src_y_max = _height - _cropBottom - _cropTop; _src_y_max = _screenHeight - _cropBottom - _cropTop;
break; break;
case VideoMode::VIDEO_3DTAB: case VideoMode::VIDEO_3DTAB:
_calculatedWidth = width; _width = width;
_calculatedHeight = height / 2; _height = height / 2;
_src_x = _src_x + _cropLeft; _src_x = _src_x + _cropLeft;
_src_y = _src_y + (_cropTop / 2); _src_y = _src_y + (_cropTop / 2);
_src_x_max = _width - _cropRight - _cropLeft; _src_x_max = _screenWidth - _cropRight - _cropLeft;
_src_y_max = (_height / 2) - _cropBottom - _cropTop; _src_y_max = (_screenHeight / 2) - _cropBottom - _cropTop;
break; break;
case VideoMode::VIDEO_2D: case VideoMode::VIDEO_2D:
default: default:
_calculatedWidth = width; _width = width;
_calculatedHeight = height; _height = height;
_src_x = _src_x + _cropLeft; _src_x = _src_x + _cropLeft;
_src_y = _src_y + _cropTop; _src_y = _src_y + _cropTop;
_src_x_max = _width - _cropRight - _cropLeft; _src_x_max = _screenWidth - _cropRight - _cropLeft;
_src_y_max = _height - _cropBottom - _cropTop; _src_y_max = _screenHeight - _cropBottom - _cropTop;
break; break;
} }
Info(_log, "Update output image resolution to [%dx%d]", _calculatedWidth, _calculatedHeight); Info(_log, "Update output image resolution to [%dx%d]", _width, _height);
Debug(_log, "Grab screen area: %d,%d,%d,%d", _src_x, _src_y, _src_x_max, _src_y_max); Debug(_log, "Grab screen area: %d,%d,%d,%d", _src_x, _src_y, _src_x_max, _src_y_max);
return 1; return 1;
@@ -433,10 +433,10 @@ QJsonObject QtGrabber::discover(const QJsonObject& params)
if (screens.at(0)->size() != screens.at(0)->virtualSize()) if (screens.at(0)->size() != screens.at(0)->virtualSize())
{ {
QJsonObject in; QJsonObject input;
in["name"] = "All Displays"; input["name"] = "All Displays";
in["inputIdx"] = screens.size(); input["inputIdx"] = screens.size();
in["virtual"] = true; input["virtual"] = true;
QJsonArray formats; QJsonArray formats;
QJsonObject format; QJsonObject format;
@@ -454,15 +454,19 @@ QJsonObject QtGrabber::discover(const QJsonObject& params)
format["resolutions"] = resolutionArray; format["resolutions"] = resolutionArray;
formats.append(format); formats.append(format);
in["formats"] = formats; input["formats"] = formats;
video_inputs.append(in); video_inputs.append(input);
} }
inputsDiscovered["video_inputs"] = video_inputs; inputsDiscovered["video_inputs"] = video_inputs;
QJsonObject defaults, video_inputs_default, resolution_default; QJsonObject resolution_default;
resolution_default["fps"] = _fps; resolution_default["fps"] = _fps;
QJsonObject video_inputs_default;
video_inputs_default["resolution"] = resolution_default; video_inputs_default["resolution"] = resolution_default;
video_inputs_default["inputIdx"] = 0; video_inputs_default["inputIdx"] = 0;
QJsonObject defaults;
defaults["video_input"] = video_inputs_default; defaults["video_input"] = video_inputs_default;
inputsDiscovered["default"] = defaults; inputsDiscovered["default"] = defaults;
} }

View File

@@ -18,13 +18,13 @@ X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom)
, _dstFormat(nullptr) , _dstFormat(nullptr)
, _srcPicture(None) , _srcPicture(None)
, _dstPicture(None) , _dstPicture(None)
, _calculatedWidth(0) , _screenWidth(0)
, _calculatedHeight(0) , _screenHeight(0)
, _src_x(cropLeft) , _src_x(cropLeft)
, _src_y(cropTop) , _src_y(cropTop)
, _XShmAvailable(false) , _xShmAvailable(false)
, _XRenderAvailable(false) , _xRenderAvailable(false)
, _XRandRAvailable(false) , _xRandRAvailable(false)
, _isWayland (false) , _isWayland (false)
, _logger{} , _logger{}
{ {
@@ -52,17 +52,17 @@ void X11Grabber::freeResources()
{ {
XDestroyImage(_xImage); XDestroyImage(_xImage);
} }
if (_XRandRAvailable) if (_xRandRAvailable)
{ {
qApp->removeNativeEventFilter(this); qApp->removeNativeEventFilter(this);
} }
if(_XShmAvailable) if(_xShmAvailable)
{ {
XShmDetach(_x11Display, &_shminfo); XShmDetach(_x11Display, &_shminfo);
shmdt(_shminfo.shmaddr); shmdt(_shminfo.shmaddr);
shmctl(_shminfo.shmid, IPC_RMID, 0); shmctl(_shminfo.shmid, IPC_RMID, nullptr);
} }
if (_XRenderAvailable) if (_xRenderAvailable)
{ {
XRenderFreePicture(_x11Display, _srcPicture); XRenderFreePicture(_x11Display, _srcPicture);
XRenderFreePicture(_x11Display, _dstPicture); XRenderFreePicture(_x11Display, _dstPicture);
@@ -72,41 +72,41 @@ void X11Grabber::freeResources()
void X11Grabber::setupResources() void X11Grabber::setupResources()
{ {
if (_XRandRAvailable) if (_xRandRAvailable)
{ {
qApp->installNativeEventFilter(this); qApp->installNativeEventFilter(this);
} }
if(_XShmAvailable) if(_xShmAvailable)
{ {
_xImage = XShmCreateImage(_x11Display, _windowAttr.visual, _windowAttr.depth, ZPixmap, NULL, &_shminfo, _calculatedWidth, _calculatedHeight); _xImage = XShmCreateImage(_x11Display, _windowAttr.visual, _windowAttr.depth, ZPixmap, nullptr, &_shminfo, _width, _height);
_shminfo.shmid = shmget(IPC_PRIVATE, (size_t) _xImage->bytes_per_line * _xImage->height, IPC_CREAT|0777); _shminfo.shmid = shmget(IPC_PRIVATE, (size_t) _xImage->bytes_per_line * _xImage->height, IPC_CREAT|0777);
_xImage->data = (char*)shmat(_shminfo.shmid,0,0); _xImage->data = (char*)shmat(_shminfo.shmid,nullptr,0);
_shminfo.shmaddr = _xImage->data; _shminfo.shmaddr = _xImage->data;
_shminfo.readOnly = False; _shminfo.readOnly = False;
XShmAttach(_x11Display, &_shminfo); XShmAttach(_x11Display, &_shminfo);
} }
if (_XRenderAvailable) if (_xRenderAvailable)
{ {
_useImageResampler = false; _useImageResampler = false;
_imageResampler.setHorizontalPixelDecimation(1); _imageResampler.setHorizontalPixelDecimation(1);
_imageResampler.setVerticalPixelDecimation(1); _imageResampler.setVerticalPixelDecimation(1);
if(_XShmPixmapAvailable) if(_xShmPixmapAvailable)
{ {
_pixmap = XShmCreatePixmap(_x11Display, _window, _xImage->data, &_shminfo, _calculatedWidth, _calculatedHeight, _windowAttr.depth); _pixmap = XShmCreatePixmap(_x11Display, _window, _xImage->data, &_shminfo, _width, _height, _windowAttr.depth);
} }
else else
{ {
_pixmap = XCreatePixmap(_x11Display, _window, _calculatedWidth, _calculatedHeight, _windowAttr.depth); _pixmap = XCreatePixmap(_x11Display, _window, _width, _height, _windowAttr.depth);
} }
_srcFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual); _srcFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual);
_dstFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual); _dstFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual);
_srcPicture = XRenderCreatePicture(_x11Display, _window, _srcFormat, CPRepeat, &_pictAttr); _srcPicture = XRenderCreatePicture(_x11Display, _window, _srcFormat, CPRepeat, &_pictAttr);
_dstPicture = XRenderCreatePicture(_x11Display, _pixmap, _dstFormat, CPRepeat, &_pictAttr); _dstPicture = XRenderCreatePicture(_x11Display, _pixmap, _dstFormat, CPRepeat, &_pictAttr);
XRenderSetPictureFilter(_x11Display, _srcPicture, FilterBilinear, NULL, 0); XRenderSetPictureFilter(_x11Display, _srcPicture, FilterBilinear, nullptr, 0);
} }
else else
{ {
@@ -161,19 +161,20 @@ bool X11Grabber::setupDisplay()
{ {
_window = DefaultRootWindow(_x11Display); _window = DefaultRootWindow(_x11Display);
int dummy, pixmaps_supported; int dummy;
int pixmaps_supported;
_XRandRAvailable = XRRQueryExtension(_x11Display, &_XRandREventBase, &dummy); _xRandRAvailable = (XRRQueryExtension(_x11Display, &_xRandREventBase, &dummy) != 0);
_XRenderAvailable = XRenderQueryExtension(_x11Display, &dummy, &dummy); _xRenderAvailable = (XRenderQueryExtension(_x11Display, &dummy, &dummy) != 0);
_XShmAvailable = XShmQueryExtension(_x11Display); _xShmAvailable = (XShmQueryExtension(_x11Display) != 0);
XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported); XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported);
_XShmPixmapAvailable = pixmaps_supported && XShmPixmapFormat(_x11Display) == ZPixmap; _xShmPixmapAvailable = (pixmaps_supported != 0) && XShmPixmapFormat(_x11Display) == ZPixmap;
Info(_log, "%s", QSTRING_CSTR(QString("XRandR=[%1] XRender=[%2] XShm=[%3] XPixmap=[%4]") Info(_log, "%s", QSTRING_CSTR(QString("XRandR=[%1] XRender=[%2] XShm=[%3] XPixmap=[%4]")
.arg(_XRandRAvailable ? "available" : "unavailable", .arg(_xRandRAvailable ? "available" : "unavailable",
_XRenderAvailable ? "available" : "unavailable", _xRenderAvailable ? "available" : "unavailable",
_XShmAvailable ? "available" : "unavailable", _xShmAvailable ? "available" : "unavailable",
_XShmPixmapAvailable ? "available" : "unavailable")) _xShmPixmapAvailable ? "available" : "unavailable"))
); );
result = (updateScreenDimensions(true) >=0); result = (updateScreenDimensions(true) >=0);
@@ -185,12 +186,17 @@ bool X11Grabber::setupDisplay()
int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate) int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
{ {
if (!_isEnabled) return 0; if (!_isEnabled)
{
return 0;
}
if (forceUpdate) if (forceUpdate)
{
updateScreenDimensions(forceUpdate); updateScreenDimensions(forceUpdate);
}
if (_XRenderAvailable) if (_xRenderAvailable)
{ {
double scale_x = static_cast<double>(_windowAttr.width / _pixelDecimation) / static_cast<double>(_windowAttr.width); 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_y = static_cast<double>(_windowAttr.height / _pixelDecimation) / static_cast<double>(_windowAttr.height);
@@ -223,20 +229,20 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
// 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( XRenderComposite(
_x11Display, PictOpSrc, _srcPicture, None, _dstPicture, ( _src_x/_pixelDecimation), _x11Display, PictOpSrc, _srcPicture, None, _dstPicture, ( _src_x/_pixelDecimation),
(_src_y/_pixelDecimation), 0, 0, 0, 0, _calculatedWidth, _calculatedHeight); (_src_y/_pixelDecimation), 0, 0, 0, 0, _width, _height);
XSync(_x11Display, False); XSync(_x11Display, False);
if (_XShmAvailable) if (_xShmAvailable)
{ {
XShmGetImage(_x11Display, _pixmap, _xImage, 0, 0, AllPlanes); XShmGetImage(_x11Display, _pixmap, _xImage, 0, 0, AllPlanes);
} }
else else
{ {
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _calculatedWidth, _calculatedHeight, AllPlanes, ZPixmap); _xImage = XGetImage(_x11Display, _pixmap, 0, 0, _width, _height, AllPlanes, ZPixmap);
} }
} }
else if (_XShmAvailable) else if (_xShmAvailable)
{ {
// use xshm // use xshm
XShmGetImage(_x11Display, _window, _xImage, _src_x, _src_y, AllPlanes); XShmGetImage(_x11Display, _window, _xImage, _src_x, _src_y, AllPlanes);
@@ -244,7 +250,7 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image, bool forceUpdate)
else else
{ {
// all things done by xgetimage // all things done by xgetimage
_xImage = XGetImage(_x11Display, _window, _src_x, _src_y, _calculatedWidth, _calculatedHeight, AllPlanes, ZPixmap); _xImage = XGetImage(_x11Display, _window, _src_x, _src_y, _width, _height, AllPlanes, ZPixmap);
} }
if (_xImage == nullptr) if (_xImage == nullptr)
@@ -267,46 +273,46 @@ int X11Grabber::updateScreenDimensions(bool force)
return -1; return -1;
} }
if (!force && _width == _windowAttr.width && _height == _windowAttr.height) if (!force && _screenWidth == _windowAttr.width && _screenHeight == _windowAttr.height)
{ {
// No update required // No update required
return 0; return 0;
} }
if (_width || _height) if ((_screenWidth != 0) || _screenHeight != 0)
{ {
freeResources(); freeResources();
} }
Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _width, _height, _windowAttr.width, _windowAttr.height); Info(_log, "Update of screen resolution: [%dx%d] to [%dx%d]", _screenWidth, _screenHeight, _windowAttr.width, _windowAttr.height);
_width = _windowAttr.width; _screenWidth = _windowAttr.width;
_height = _windowAttr.height; _screenHeight = _windowAttr.height;
int width=0; int width=0;
int height=0; int height=0;
// Image scaling is performed by XRender when available, otherwise by ImageResampler // Image scaling is performed by XRender when available, otherwise by ImageResampler
if (_XRenderAvailable) if (_xRenderAvailable)
{ {
width = (_width > (_cropLeft + _cropRight)) width = (_screenWidth > (_cropLeft + _cropRight))
? ((_width - _cropLeft - _cropRight) / _pixelDecimation) ? ((_screenWidth - _cropLeft - _cropRight) / _pixelDecimation)
: _width / _pixelDecimation; : _screenWidth / _pixelDecimation;
height = (_height > (_cropTop + _cropBottom)) height = (_screenHeight > (_cropTop + _cropBottom))
? ((_height - _cropTop - _cropBottom) / _pixelDecimation) ? ((_screenHeight - _cropTop - _cropBottom) / _pixelDecimation)
: _height / _pixelDecimation; : _screenHeight / _pixelDecimation;
Info(_log, "Using XRender for grabbing"); Info(_log, "Using XRender for grabbing");
} }
else else
{ {
width = (_width > (_cropLeft + _cropRight)) width = (_screenWidth > (_cropLeft + _cropRight))
? (_width - _cropLeft - _cropRight) ? (_screenWidth - _cropLeft - _cropRight)
: _width; : _screenWidth;
height = (_height > (_cropTop + _cropBottom)) height = (_screenHeight > (_cropTop + _cropBottom))
? (_height - _cropTop - _cropBottom) ? (_screenHeight - _cropTop - _cropBottom)
: _height; : _screenHeight;
Info(_log, "Using XGetImage for grabbing"); Info(_log, "Using XGetImage for grabbing");
} }
@@ -315,29 +321,28 @@ int X11Grabber::updateScreenDimensions(bool force)
switch (_videoMode) switch (_videoMode)
{ {
case VideoMode::VIDEO_3DSBS: case VideoMode::VIDEO_3DSBS:
_calculatedWidth = width /2; _width = width /2;
_calculatedHeight = height; _height = height;
_src_x = _cropLeft / 2; _src_x = _cropLeft / 2;
_src_y = _cropTop; _src_y = _cropTop;
break; break;
case VideoMode::VIDEO_3DTAB: case VideoMode::VIDEO_3DTAB:
_calculatedWidth = width; _width = width;
_calculatedHeight = height / 2; _height = height / 2;
_src_x = _cropLeft; _src_x = _cropLeft;
_src_y = _cropTop / 2; _src_y = _cropTop / 2;
break; break;
case VideoMode::VIDEO_2D: case VideoMode::VIDEO_2D:
default: default:
_calculatedWidth = width; _width = width;
_calculatedHeight = height; _height = height;
_src_x = _cropLeft; _src_x = _cropLeft;
_src_y = _cropTop; _src_y = _cropTop;
break; break;
} }
Info(_log, "Update output image resolution: [%dx%d] to [%dx%d]", _image.width(), _image.height(), _calculatedWidth, _calculatedHeight); Info(_log, "Update output image resolution to [%dx%d]", _width, _height);
_image.resize(_width, _height);
_image.resize(_calculatedWidth, _calculatedHeight);
setupResources(); setupResources();
return 1; return 1;
@@ -383,14 +388,14 @@ bool X11Grabber::nativeEventFilter(const QByteArray & eventType, void * message,
bool X11Grabber::nativeEventFilter(const QByteArray & eventType, void * message, long int * /*result*/) bool X11Grabber::nativeEventFilter(const QByteArray & eventType, void * message, long int * /*result*/)
#endif #endif
{ {
if (!_XRandRAvailable || eventType != "xcb_generic_event_t") { if (!_xRandRAvailable || eventType != "xcb_generic_event_t") {
return false; return false;
} }
xcb_generic_event_t *e = static_cast<xcb_generic_event_t*>(message); xcb_generic_event_t *event = static_cast<xcb_generic_event_t*>(message);
const uint8_t xEventType = XCB_EVENT_RESPONSE_TYPE(e); const uint8_t xEventType = XCB_EVENT_RESPONSE_TYPE(event);
if (xEventType == _XRandREventBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY) if (xEventType == _xRandREventBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
{ {
updateScreenDimensions(true); updateScreenDimensions(true);
} }
@@ -427,7 +432,7 @@ QJsonObject X11Grabber::discover(const QJsonObject& params)
} }
else else
{ {
QJsonObject in; QJsonObject input;
QString displayName; QString displayName;
char* name; char* name;
@@ -439,8 +444,8 @@ QJsonObject X11Grabber::discover(const QJsonObject& params)
displayName = QString("Display:%1").arg(i); displayName = QString("Display:%1").arg(i);
} }
in["name"] = displayName; input["name"] = displayName;
in["inputIdx"] = i; input["inputIdx"] = i;
QJsonArray formats; QJsonArray formats;
QJsonArray resolutionArray; QJsonArray resolutionArray;
@@ -456,19 +461,22 @@ QJsonObject X11Grabber::discover(const QJsonObject& params)
format["resolutions"] = resolutionArray; format["resolutions"] = resolutionArray;
formats.append(format); formats.append(format);
in["formats"] = formats; input["formats"] = formats;
video_inputs.append(in); video_inputs.append(input);
} }
} }
if ( !video_inputs.isEmpty() ) if ( !video_inputs.isEmpty() )
{ {
inputsDiscovered["video_inputs"] = video_inputs; inputsDiscovered["video_inputs"] = video_inputs;
QJsonObject resolution_default;
QJsonObject defaults, video_inputs_default, resolution_default;
resolution_default["fps"] = _fps; resolution_default["fps"] = _fps;
QJsonObject video_inputs_default;
video_inputs_default["resolution"] = resolution_default; video_inputs_default["resolution"] = resolution_default;
video_inputs_default["inputIdx"] = 0; video_inputs_default["inputIdx"] = 0;
QJsonObject defaults;
defaults["video_input"] = video_inputs_default; defaults["video_input"] = video_inputs_default;
inputsDiscovered["default"] = defaults; inputsDiscovered["default"] = defaults;
} }