Reduce CPU usage by more than half by using QImage to do ABGR -> RGB conversion.
Now the main CPU hog is base64encoding the image data to send to Hyperion. Don't sent signal as exit code.
This commit is contained in:
parent
e737d18121
commit
07ba3830a3
@ -8,9 +8,10 @@ set(CMAKE_BUILD_TYPE Desktop)
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5Network REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
find_package(X11 REQUIRED)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lXrender -lXdamage")
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
add_executable(${PROJECT_NAME} "main.cpp" "hgx11.h" "hgx11.cpp" "hgx11net.h" "hgx11net.cpp" "hgx11damage.h" "hgx11damage.cpp" "hgx11grab.h" "hgx11grab.cpp")
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network ${X11_LIBRARIES})
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Widgets ${X11_LIBRARIES})
|
||||
|
||||
@ -32,7 +32,7 @@ You should set this option so the image resolution sent to Hyperion is at least
|
||||
Ideally you want a perfect dividor, for example if your LED array is 70x39 and screen sis 3840x2160, then you get (3840/70) 54.86 for the width and (2160/39) 55.38 for the height, the nearest perfect dividor is 48 (3840/48 = 80 ; 2160/48 = 45), if you were to use 54, then there would be rounding error (3840/54 = 71.111, but is truncated to 71) and the image sent to hyperion will not be correctly scaled.
|
||||
|
||||
|
||||
While watching a video with a 3840x2160 60hz display, frameskip at 1 (30fps), divisor at 24 (160x90 output resolution) CPU usage is about 2% of one cpu thread, memory usage is 17.3 KB according to HTOP. CPU usage is 0% when nothing is changing on the display.
|
||||
While watching a video with a 3840x2160 60hz display, frameskip at 1 (30fps), divisor at 24 (160x90 output resolution) CPU usage is about 0.7% of one cpu thread, memory usage is 17.3 KB according to HTOP. CPU usage is 0% when nothing is changing on the display.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ void hgx11grab::_grabFrame()
|
||||
_dstPicture_m = XRenderCreatePicture(_x11Display_p, _pixmap_m, _dstFormat_p, CPRepeat, &_pictAttr_m);
|
||||
|
||||
XRenderSetPictureFilter(_x11Display_p, _srcPicture_m, FilterBilinear, nullptr, 0);
|
||||
XRenderSetPictureTransform (_x11Display_p, _srcPicture_m, &_mTransform_m);
|
||||
XRenderSetPictureTransform(_x11Display_p, _srcPicture_m, &_mTransform_m);
|
||||
|
||||
XRenderComposite(
|
||||
_x11Display_p, // *dpy,
|
||||
@ -129,29 +129,18 @@ void hgx11grab::_grabFrame()
|
||||
|
||||
XSync(_x11Display_p, false);
|
||||
|
||||
XShmGetImage(_x11Display_p, _pixmap_m, _xImage_p, 0, 0, 0x00FFFFFF);
|
||||
XShmGetImage(_x11Display_p, _pixmap_m, _xImage_p, 0, 0, 0xFFFFFFFF);
|
||||
|
||||
if (_xImage_p == nullptr) {
|
||||
qWarning() << "Failed to get image from X11 server.";
|
||||
return;
|
||||
}
|
||||
|
||||
QImage qimg = *new QImage(reinterpret_cast<const uchar *>(_xImage_p->data), _destWidth_m, _destHeight_m, _xImage_p->bytes_per_line, QImage::Format_RGBA8888);
|
||||
qimg = qimg.convertToFormat(QImage::Format_RGB888);
|
||||
imgdata_m.clear();
|
||||
imgdata_m = QByteArray::fromRawData(reinterpret_cast<const char *>(qimg.bits()), qimg.byteCount());
|
||||
|
||||
if (_xImage_p->byte_order == 0) { // BGR
|
||||
for (int i = 0; i < _imgSize_m; i += 4) {
|
||||
imgdata_m.append(_xImage_p->data[i+2]);
|
||||
imgdata_m.append(_xImage_p->data[i+1]);
|
||||
imgdata_m.append(_xImage_p->data[i]);
|
||||
}
|
||||
} else { // RGB
|
||||
for (int i = 0; i < _imgSize_m; i += 4) {
|
||||
imgdata_m.append(_xImage_p->data[i]);
|
||||
imgdata_m.append(_xImage_p->data[i+1]);
|
||||
imgdata_m.append(_xImage_p->data[i+2]);
|
||||
}
|
||||
}
|
||||
|
||||
_freeResources();
|
||||
|
||||
imageCreated();
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QImage>
|
||||
#include <X11/extensions/Xrender.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user