diff --git a/CompileHowto.md b/CompileHowto.md index d3a0957c..04f3ecd8 100644 --- a/CompileHowto.md +++ b/CompileHowto.md @@ -40,7 +40,7 @@ wget -qN https://raw.github.com/hyperion-project/hyperion.ng/master/bin/scripts/ ``` sudo apt-get update -sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev +sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev ``` **on RPI you need the videocore IV headers** diff --git a/CrossCompileHowto.md b/CrossCompileHowto.md index ac71d574..e17f13d6 100644 --- a/CrossCompileHowto.md +++ b/CrossCompileHowto.md @@ -4,14 +4,14 @@ Use a clean Raspbian Stretch Lite (on target) and Ubuntu 18/19 (on host) to exec ## On the Target system (here Raspberry Pi) Install required additional packages. ``` -sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite aptitude qt5-default rsync libssl-dev zlib1g-dev +sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite aptitude qt5-default rsync libssl-dev zlib1g-dev ``` ## On the Host system (here Ubuntu) Update the Ubuntu environment to the latest stage and install required additional packages. ``` sudo apt-get update sudo apt-get upgrade -sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev +sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libjpeg-dev libturbojpeg0-dev libqt5sql5-sqlite libssl-dev zlib1g-dev ``` Refine the target IP or hostname, plus userID as required and set-up cross-compilation environment: diff --git a/bin/compile.sh b/bin/compile.sh index 5a282bd1..75adfc4f 100755 --- a/bin/compile.sh +++ b/bin/compile.sh @@ -5,7 +5,7 @@ CFG="${2:-Release}" INST="$( [ "${3:-}" = "install" ] && echo true || echo false )" sudo apt-get update -sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev libturbojpeg0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libssl-dev libjpeg-dev libqt5sql5-sqlite zlib1g-dev || exit 1 +sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev libturbojpeg0-dev python3-dev libxcb-util0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libssl-dev libjpeg-dev libqt5sql5-sqlite zlib1g-dev || exit 1 if [ -e /dev/vc-cma -a -e /dev/vc-mem ] then diff --git a/bin/create_oe_depedencies.sh b/bin/create_oe_depedencies.sh index 194da7a8..0971468f 100644 --- a/bin/create_oe_depedencies.sh +++ b/bin/create_oe_depedencies.sh @@ -18,8 +18,11 @@ tar --create --verbose --gzip --absolute-names --show-transformed-names --derefe "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libX11.so.6" \ "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXau.so.6" \ "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libxcb.so.1" \ + "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libxcb-util.so" \ + "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libxcb-randr.so" \ "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXdmcp.so.6" \ "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXext.so.6" \ + "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXrandr.so.2" \ "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXrender.so.1" \ "$IMX6_ROOTFS/usr/lib/arm-linux-gnueabihf/libXt.so.6" \ "./openelec/hyperiond.sh" \ diff --git a/include/grabber/X11Grabber.h b/include/grabber/X11Grabber.h index fabc2612..f39d5aa8 100644 --- a/include/grabber/X11Grabber.h +++ b/include/grabber/X11Grabber.h @@ -1,5 +1,7 @@ #pragma once - +#include +#include +#include #include // Hyperion-utils includes @@ -8,12 +10,13 @@ // X11 includes #include +#include #include #include #include #include -class X11Grabber : public Grabber +class X11Grabber : public Grabber , public QAbstractNativeEventFilter { public: @@ -58,8 +61,11 @@ public: /// virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom); +protected: + bool nativeEventFilter(const QByteArray & eventType, void * message, long int * result) override; + private: - bool _XShmAvailable, _XShmPixmapAvailable, _XRenderAvailable; + bool _XShmAvailable, _XShmPixmapAvailable, _XRenderAvailable, _XRandRAvailable; XImage* _xImage; XShmSegmentInfo _shminfo; @@ -76,6 +82,8 @@ private: Picture _srcPicture; Picture _dstPicture; + int _XRandREventBase; + XTransform _transform; int _pixelDecimation; diff --git a/libsrc/grabber/x11/CMakeLists.txt b/libsrc/grabber/x11/CMakeLists.txt index 4d5914e5..06dcf6d5 100644 --- a/libsrc/grabber/x11/CMakeLists.txt +++ b/libsrc/grabber/x11/CMakeLists.txt @@ -4,6 +4,7 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/x11) # Find X11 find_package(X11 REQUIRED) +find_package(Qt5Widgets REQUIRED) include_directories( ${X11_INCLUDES} ) @@ -18,5 +19,7 @@ add_library(x11-grabber ${X11_SOURCES} ) target_link_libraries(x11-grabber hyperion ${X11_LIBRARIES} + ${X11_Xrandr_LIB} ${X11_Xrender_LIB} + Qt5::Widgets ) diff --git a/libsrc/grabber/x11/X11Grabber.cpp b/libsrc/grabber/x11/X11Grabber.cpp index 855ea4c0..130c9ed9 100644 --- a/libsrc/grabber/x11/X11Grabber.cpp +++ b/libsrc/grabber/x11/X11Grabber.cpp @@ -1,6 +1,9 @@ #include #include +#include +#include + X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation) : Grabber("X11GRABBER", 0, 0, cropLeft, cropRight, cropTop, cropBottom) , _x11Display(nullptr) @@ -35,6 +38,10 @@ void X11Grabber::freeResources() { // Cleanup allocated resources of the X11 grab XDestroyImage(_xImage); + if (_XRandRAvailable) + { + qApp->removeNativeEventFilter(this); + } if(_XShmAvailable) { XShmDetach(_x11Display, &_shminfo); @@ -51,6 +58,11 @@ void X11Grabber::freeResources() void X11Grabber::setupResources() { + if (_XRandRAvailable) + { + qApp->installNativeEventFilter(this); + } + if(_XShmAvailable) { _xImage = XShmCreateImage(_x11Display, _windowAttr.visual, _windowAttr.depth, ZPixmap, NULL, &_shminfo, _width, _height); @@ -99,6 +111,7 @@ bool X11Grabber::Setup() int dummy, pixmaps_supported; + _XRandRAvailable = XRRQueryExtension(_x11Display, &_XRandREventBase, &dummy); _XRenderAvailable = XRenderQueryExtension(_x11Display, &dummy, &dummy); _XShmAvailable = XShmQueryExtension(_x11Display); XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported); @@ -293,3 +306,20 @@ void X11Grabber::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cro Grabber::setCropping(cropLeft, cropRight, cropTop, cropBottom); if(_x11Display != nullptr) updateScreenDimensions(true); // segfault on init } + +bool X11Grabber::nativeEventFilter(const QByteArray & eventType, void * message, long int * /*result*/) +{ + if (!_XRandRAvailable || eventType != "xcb_generic_event_t") { + return false; + } + + xcb_generic_event_t *e = static_cast(message); + const uint8_t xEventType = XCB_EVENT_RESPONSE_TYPE(e); + + if (xEventType == _XRandREventBase + XCB_RANDR_SCREEN_CHANGE_NOTIFY) + { + updateScreenDimensions(true); + } + + return false; +} diff --git a/src/hyperion-x11/CMakeLists.txt b/src/hyperion-x11/CMakeLists.txt index b34d226c..fc47c489 100644 --- a/src/hyperion-x11/CMakeLists.txt +++ b/src/hyperion-x11/CMakeLists.txt @@ -36,10 +36,12 @@ target_link_libraries(${PROJECT_NAME} x11-grabber ssdp ${X11_LIBRARIES} + ${X11_Xrandr_LIB} ${X11_Xrender_LIB} Qt5::Core Qt5::Gui Qt5::Network + Qt5::Widgets ) install ( TARGETS ${PROJECT_NAME} DESTINATION "share/hyperion/bin" COMPONENT "hyperion_x11" ) diff --git a/src/hyperion-x11/hyperion-x11.cpp b/src/hyperion-x11/hyperion-x11.cpp index 31d9a2b3..08a624a0 100644 --- a/src/hyperion-x11/hyperion-x11.cpp +++ b/src/hyperion-x11/hyperion-x11.cpp @@ -1,6 +1,6 @@ // QT includes -#include +#include #include #include @@ -28,8 +28,7 @@ int main(int argc, char ** argv) << "\tVersion : " << HYPERION_VERSION << " (" << HYPERION_BUILD_ID << ")" << std::endl << "\tbuild time: " << __DATE__ << " " << __TIME__ << std::endl; - QCoreApplication app(argc, argv); - + QApplication app(argc, argv); try { // create the option parser and initialize all parameters