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:
kevin 2019-06-24 09:18:22 -04:00
parent e737d18121
commit 07ba3830a3
5 changed files with 11 additions and 20 deletions

View File

@ -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})

View File

@ -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

View File

@ -129,28 +129,17 @@ 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();
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]);
}
}
imgdata_m = QByteArray::fromRawData(reinterpret_cast<const char *>(qimg.bits()), qimg.byteCount());
_freeResources();

View File

@ -3,6 +3,7 @@
#include <QObject>
#include <QDebug>
#include <QImage>
#include <X11/extensions/Xrender.h>
#include <X11/extensions/XShm.h>
#include <sys/shm.h>

View File

@ -6,12 +6,12 @@
static hgx11 *grab;
static QCoreApplication *qapp;
static void quit(int sig)
static void quit(int)
{
if (grab != nullptr) {
grab->~hgx11();
}
qapp->exit(sig);
qapp->exit();
}
int main(int argc, char *argv[])