implement set videomode via json api (#457)

* implement set videomode via json api

* refactor grabbers:
- new base class
- move shared code to base class

* fix osx

* rework all cmakelist files with auto file collection. except leddevices (need further restructuring)

* store current video and grabbing mode

* add json stuff

* remove grabbingmode - we do not want to expose it
This commit is contained in:
redPanther
2017-08-04 23:08:15 +02:00
committed by GitHub
parent 3612ccda75
commit 569e59110e
54 changed files with 375 additions and 659 deletions

View File

@@ -5,27 +5,14 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/x11)
# Find X11
find_package(X11 REQUIRED)
include_directories(
${X11_INCLUDES}
)
include_directories( ${X11_INCLUDES} )
SET(X11_HEADERS
${CURRENT_HEADER_DIR}/X11Wrapper.h
${CURRENT_HEADER_DIR}/X11Grabber.h
)
FILE ( GLOB X11_SOURCES "${CURRENT_HEADER_DIR}/X11*.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.cpp" )
SET(X11_SOURCES
${CURRENT_SOURCE_DIR}/X11Grabber.cpp
${CURRENT_SOURCE_DIR}/X11Wrapper.cpp
)
add_library(x11-grabber
${X11_HEADERS}
${X11_SOURCES}
)
add_library(x11-grabber ${X11_SOURCES} )
target_link_libraries(x11-grabber
hyperion
${X11_LIBRARIES}
${X11_Xrender_LIB}
${X11_LIBRARIES}
${X11_Xrender_LIB}
)

View File

@@ -2,12 +2,8 @@
#include <grabber/X11Grabber.h>
X11Grabber::X11Grabber(bool useXGetImage, int cropLeft, int cropRight, int cropTop, int cropBottom, int horizontalPixelDecimation, int verticalPixelDecimation)
: _imageResampler()
: Grabber("X11GRABBER", 0, 0, cropLeft, cropRight, cropTop, cropBottom)
, _useXGetImage(useXGetImage)
, _cropLeft(cropLeft)
, _cropRight(cropRight)
, _cropTop(cropTop)
, _cropBottom(cropBottom)
, _x11Display(nullptr)
, _pixmap(None)
, _srcFormat(nullptr)
@@ -18,10 +14,7 @@ X11Grabber::X11Grabber(bool useXGetImage, int cropLeft, int cropRight, int cropT
, _verticalDecimation(verticalPixelDecimation)
, _screenWidth(0)
, _screenHeight(0)
, _croppedWidth(0)
, _croppedHeight(0)
, _image(0,0)
, _log(Logger::getInstance("X11GRABBER"))
{
_imageResampler.setCropping(0, 0, 0, 0); // cropping is performed by XRender, XShmGetImage or XGetImage
memset(&_pictAttr, 0, sizeof(_pictAttr));
@@ -37,11 +30,6 @@ X11Grabber::~X11Grabber()
}
}
void X11Grabber::setVideoMode(const VideoMode videoMode)
{
_imageResampler.set3D(videoMode);
}
void X11Grabber::freeResources()
{
// Cleanup allocated resources of the X11 grab
@@ -66,7 +54,7 @@ void X11Grabber::setupResources()
{
_xImage = XShmCreateImage(_x11Display, _windowAttr.visual,
_windowAttr.depth, ZPixmap, NULL, &_shminfo,
_croppedWidth, _croppedHeight);
_width, _height);
_shminfo.shmid = shmget(IPC_PRIVATE, _xImage->bytes_per_line * _xImage->height, IPC_CREAT|0777);
_xImage->data = (char*)shmat(_shminfo.shmid,0,0);
_shminfo.shmaddr = _xImage->data;
@@ -77,11 +65,11 @@ void X11Grabber::setupResources()
{
if(_XShmPixmapAvailable)
{
_pixmap = XShmCreatePixmap(_x11Display, _window, _xImage->data, &_shminfo, _croppedWidth, _croppedHeight, _windowAttr.depth);
_pixmap = XShmCreatePixmap(_x11Display, _window, _xImage->data, &_shminfo, _width, _height, _windowAttr.depth);
}
else
{
_pixmap = XCreatePixmap(_x11Display, _window, _croppedWidth, _croppedHeight, _windowAttr.depth);
_pixmap = XCreatePixmap(_x11Display, _window, _width, _height, _windowAttr.depth);
}
_srcFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual);
_dstFormat = XRenderFindVisualFormat(_x11Display, _windowAttr.visual);
@@ -168,8 +156,8 @@ Image<ColorRgb> & X11Grabber::grab()
0, // mask_y
0, // dst_x
0, // dst_y
_croppedWidth, // width
_croppedHeight); // height
_width, // width
_height); // height
XSync(_x11Display, False);
@@ -179,7 +167,7 @@ Image<ColorRgb> & X11Grabber::grab()
}
else
{
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _croppedWidth, _croppedHeight, AllPlanes, ZPixmap);
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _width, _height, AllPlanes, ZPixmap);
}
}
else
@@ -189,7 +177,7 @@ Image<ColorRgb> & X11Grabber::grab()
}
else
{
_xImage = XGetImage(_x11Display, _window, _cropLeft, _cropTop, _croppedWidth, _croppedHeight, AllPlanes, ZPixmap);
_xImage = XGetImage(_x11Display, _window, _cropLeft, _cropTop, _width, _height, AllPlanes, ZPixmap);
}
}
@@ -246,8 +234,8 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image)
0, // mask_y
0, // dst_x
0, // dst_y
_croppedWidth, // width
_croppedHeight); // height
_width, // width
_height); // height
XSync(_x11Display, False);
@@ -257,7 +245,7 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image)
}
else
{
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _croppedWidth, _croppedHeight, AllPlanes, ZPixmap);
_xImage = XGetImage(_x11Display, _pixmap, 0, 0, _width, _height, AllPlanes, ZPixmap);
}
}
else
@@ -267,7 +255,7 @@ int X11Grabber::grabFrame(Image<ColorRgb> & image)
}
else
{
_xImage = XGetImage(_x11Display, _window, _cropLeft, _cropTop, _croppedWidth, _croppedHeight, AllPlanes, ZPixmap);
_xImage = XGetImage(_x11Display, _window, _cropLeft, _cropTop, _width, _height, AllPlanes, ZPixmap);
}
}
@@ -309,11 +297,11 @@ int X11Grabber::updateScreenDimensions()
// Image scaling is performed by XRender when available, otherwise by ImageResampler
if (_XRenderAvailable && !_useXGetImage)
{
_croppedWidth = (_screenWidth > unsigned(_cropLeft + _cropRight))
_width = (_screenWidth > unsigned(_cropLeft + _cropRight))
? ((_screenWidth - _cropLeft - _cropRight) / _horizontalDecimation)
: _screenWidth / _horizontalDecimation;
_croppedHeight = (_screenHeight > unsigned(_cropTop + _cropBottom))
_height = (_screenHeight > unsigned(_cropTop + _cropBottom))
? ((_screenHeight - _cropTop - _cropBottom) / _verticalDecimation)
: _screenHeight / _verticalDecimation;
@@ -321,18 +309,18 @@ int X11Grabber::updateScreenDimensions()
}
else
{
_croppedWidth = (_screenWidth > unsigned(_cropLeft + _cropRight))
_width = (_screenWidth > unsigned(_cropLeft + _cropRight))
? (_screenWidth - _cropLeft - _cropRight)
: _screenWidth;
_croppedHeight = (_screenHeight > unsigned(_cropTop + _cropBottom))
_height = (_screenHeight > unsigned(_cropTop + _cropBottom))
? (_screenHeight - _cropTop - _cropBottom)
: _screenHeight;
Info(_log, "Using XGetImage for grabbing");
}
_image.resize(_croppedWidth, _croppedHeight);
_image.resize(_width, _height);
setupResources();
return 1;

View File

@@ -1,3 +1,4 @@
// Hyperion includes
#include <hyperion/Hyperion.h>
#include <hyperion/ImageProcessorFactory.h>