From f4f39d7d72619a97f86baf382d2cbdb5d0f4e4e6 Mon Sep 17 00:00:00 2001 From: Awawa Date: Sat, 26 Feb 2022 17:20:35 +0100 Subject: [PATCH] fixes --- assets/webconfig/i18n/en.json | 6 ++-- include/flatbufserver/FlatBufferConnection.h | 3 ++ include/flatbufserver/FlatBufferServer.h | 2 +- sources/api/API.cpp | 9 ++++-- sources/flatbufserver/FlatBufferClient.cpp | 2 +- sources/flatbufserver/FlatBufferClient.h | 2 +- .../flatbufserver/FlatBufferConnection.cpp | 11 +++++++ sources/flatbufserver/FlatBufferServer.cpp | 29 +++++++++++-------- sources/hyperhdrbase/MessageForwarder.cpp | 3 +- 9 files changed, 46 insertions(+), 21 deletions(-) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 2d6ff3d2f..bad34af35 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -299,8 +299,6 @@ "edt_conf_fbs_heading_title": "Flatbuffers Server", "edt_conf_fbs_timeout_expl": "If no data are received for the given period, the component will be (soft) disabled.", "edt_conf_fbs_timeout_title": "Timeout", - "edt_conf_fbs_tonemapping_expl": "If enabled, HyperHDR will try to correct colors of the HDR10 content that was received by flatbuffers as SDR format. Default 3D LUT file 'lut_lin_tables.3d' is already included. You can generate one and preview the effect using link in the 'Advanced menu'.
Your typical hidden configuration folder to upload that file in is (check 'Logs' page to confirm):
Rpi→/home/pi/.hyperhdr
Windows→c:/Users/NAME/.hyperhdr", - "edt_conf_fbs_tonemapping_title": "HDR to SDR tone mapping", "edt_conf_fg_display_expl": "Select which desktop should be captured (multi monitor setup)", "edt_conf_fg_display_title": "Display", "edt_conf_fg_frequency_Hz_expl": "How fast new pictures are captured", @@ -1146,5 +1144,7 @@ "perf_no" : "No", "perf_decoding_time": "time", "perf_frames" : "frames", - "perf_invalid_frames" : "invalid frames" + "perf_invalid_frames" : "invalid frames", + "edt_conf_fbs_tonemapping_expl": "If enabled, HyperHDR will try to correct colors of the HDR10 content that was received by flatbuffers as SDR format. Default 3D LUT file 'lut_lin_tables.3d' is already included. You can generate one and preview the effect using link in the 'Advanced menu'.
Your typical hidden configuration folder to upload that file in is (check 'Logs' page to confirm):
Rpi→/home/pi/.hyperhdr
Windows→c:/Users/NAME/.hyperhdr", + "edt_conf_fbs_tonemapping_title": "HDR to SDR tone mapping" } diff --git a/include/flatbufserver/FlatBufferConnection.h b/include/flatbufserver/FlatBufferConnection.h index 220eb232c..91f3c27f1 100644 --- a/include/flatbufserver/FlatBufferConnection.h +++ b/include/flatbufserver/FlatBufferConnection.h @@ -75,6 +75,8 @@ class FlatBufferConnection : public QObject /// void sendMessage(const uint8_t* buffer, uint32_t size); + bool isFree(); + public slots: /// /// @brief Set the leds according to the given image @@ -132,4 +134,5 @@ private slots: flatbuffers::FlatBufferBuilder _builder; bool _registered; + bool _free; }; diff --git a/include/flatbufserver/FlatBufferServer.h b/include/flatbufserver/FlatBufferServer.h index ababa575b..730dff4ff 100644 --- a/include/flatbufserver/FlatBufferServer.h +++ b/include/flatbufserver/FlatBufferServer.h @@ -25,7 +25,7 @@ class FlatBufferServer : public QObject ~FlatBufferServer() override; static FlatBufferServer* instance; - static FlatBufferServer* getInstance(){ return instance; } + static FlatBufferServer* getInstance() { return instance; } signals: void hdrToneMappingChanged(bool enabled, uint8_t* lutBuffer); diff --git a/sources/api/API.cpp b/sources/api/API.cpp index 60a1b70bf..04bb799b7 100644 --- a/sources/api/API.cpp +++ b/sources/api/API.cpp @@ -25,6 +25,7 @@ #include #include #include +#include // bonjour wrapper #include @@ -211,7 +212,7 @@ bool API::setComponentState(const QString& comp, bool& compState, QString& reply input = "VIDEOGRABBER"; Components component = stringToComponent(input); if (component == COMP_ALL) - { + { QMetaObject::invokeMethod(HyperHdrIManager::getInstance(), "toggleStateAllInstances", Qt::QueuedConnection, Q_ARG(bool, compState)); return true; @@ -237,7 +238,11 @@ void API::setLedMappingType(int type, hyperhdr::Components callerComp) void API::setVideoModeHdr(int hdr, hyperhdr::Components callerComp) { - QMetaObject::invokeMethod(GrabberWrapper::getInstance(), "setHdrToneMappingEnabled", Qt::QueuedConnection, Q_ARG(int, hdr)); + if (GrabberWrapper::getInstance() != nullptr) + QMetaObject::invokeMethod(GrabberWrapper::getInstance(), "setHdrToneMappingEnabled", Qt::QueuedConnection, Q_ARG(int, hdr)); + + if (FlatBufferServer::getInstance() != nullptr) + QMetaObject::invokeMethod(FlatBufferServer::getInstance(), "setHdrToneMappingEnabled", Qt::QueuedConnection, Q_ARG(bool, hdr)); } bool API::setEffect(const EffectCmdData& dat, hyperhdr::Components callerComp) diff --git a/sources/flatbufserver/FlatBufferClient.cpp b/sources/flatbufserver/FlatBufferClient.cpp index bba83ecd9..2a9efd5cf 100644 --- a/sources/flatbufserver/FlatBufferClient.cpp +++ b/sources/flatbufserver/FlatBufferClient.cpp @@ -9,7 +9,7 @@ // util includes #include -FlatBufferClient::FlatBufferClient(QTcpSocket* socket, int timeout, bool hdrToneMappingEnabled, uint8_t* lutBuffer, QObject *parent) +FlatBufferClient::FlatBufferClient(QTcpSocket* socket, int timeout, bool hdrToneMappingEnabled, uint8_t* lutBuffer, QObject* parent) : QObject(parent) , _log(Logger::getInstance("FLATBUFSERVER")) , _socket(socket) diff --git a/sources/flatbufserver/FlatBufferClient.h b/sources/flatbufserver/FlatBufferClient.h index 7dd918e53..90e3b805c 100644 --- a/sources/flatbufserver/FlatBufferClient.h +++ b/sources/flatbufserver/FlatBufferClient.h @@ -26,7 +26,7 @@ class FlatBufferClient : public QObject /// @param timeout The timeout when a client is automatically disconnected and the priority unregistered /// @param parent The parent /// - explicit FlatBufferClient(QTcpSocket* socket, int timeout, bool hdrToneMappingEnabled, uint8_t* lutBuffer, QObject *parent = nullptr); + explicit FlatBufferClient(QTcpSocket* socket, int timeout, bool hdrToneMappingEnabled, uint8_t* lutBuffer, QObject* parent = nullptr); signals: /// diff --git a/sources/flatbufserver/FlatBufferConnection.cpp b/sources/flatbufserver/FlatBufferConnection.cpp index 48133721c..6aecc661e 100644 --- a/sources/flatbufserver/FlatBufferConnection.cpp +++ b/sources/flatbufserver/FlatBufferConnection.cpp @@ -18,6 +18,7 @@ FlatBufferConnection::FlatBufferConnection(const QString& origin, const QString& , _prevSocketState(QAbstractSocket::UnconnectedState) , _log(Logger::getInstance("FLATBUFCONN")) , _registered(false) + , _free(true) { QStringList parts = address.split(":"); if (parts.size() != 2) @@ -126,6 +127,8 @@ void FlatBufferConnection::setColor(const ColorRgb& color, int priority, int dur void FlatBufferConnection::setImage(const Image& image) { + _free = false; + auto imgData = _builder.CreateVector(reinterpret_cast(image.memptr()), image.size()); auto rawImg = hyperhdrnet::CreateRawImage(_builder, imgData, image.width(), image.height()); auto imageReq = hyperhdrnet::CreateImage(_builder, hyperhdrnet::ImageType_RawImage, rawImg.Union(), -1); @@ -134,6 +137,14 @@ void FlatBufferConnection::setImage(const Image& image) _builder.Finish(req); sendMessage(_builder.GetBufferPointer(), _builder.GetSize()); _builder.Clear(); + + _free = true; +} + + +bool FlatBufferConnection::isFree() +{ + return _free; } void FlatBufferConnection::clear(int priority) diff --git a/sources/flatbufserver/FlatBufferServer.cpp b/sources/flatbufserver/FlatBufferServer.cpp index bde2f2c1e..c6c6fb78f 100644 --- a/sources/flatbufserver/FlatBufferServer.cpp +++ b/sources/flatbufserver/FlatBufferServer.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #define LUT_FILE_SIZE 50331648 @@ -44,6 +45,8 @@ FlatBufferServer::~FlatBufferServer() if (_lutBuffer != NULL) free(_lutBuffer); _lutBuffer = NULL; + + FlatBufferServer::instance = nullptr; } void FlatBufferServer::initServer() @@ -59,12 +62,13 @@ void FlatBufferServer::initServer() void FlatBufferServer::setHdrToneMappingEnabled(bool enabled) { - _hdrToneMappingEnabled = enabled; - if (_hdrToneMappingEnabled) + bool status = _hdrToneMappingEnabled && enabled; + + if (status) loadLutFile(); // inform clients - emit hdrToneMappingChanged(_hdrToneMappingEnabled && _lutBufferInit, _lutBuffer); + emit hdrToneMappingChanged(status && _lutBufferInit, _lutBuffer); } void FlatBufferServer::handleSettingsUpdate(settings::type type, const QJsonDocument& config) @@ -81,9 +85,10 @@ void FlatBufferServer::handleSettingsUpdate(settings::type type, const QJsonDocu stopServer(); _port = port; } - + // HDR tone mapping - setHdrToneMappingEnabled(obj["hdrToneMapping"].toBool()); + _hdrToneMappingEnabled = obj["hdrToneMapping"].toBool(); + setHdrToneMappingEnabled(_hdrToneMappingEnabled); // new timeout just for new connections _timeout = obj["timeout"].toInt(5000); @@ -101,7 +106,7 @@ void FlatBufferServer::newConnection() if (_netOrigin->accessAllowed(socket->peerAddress(), socket->localAddress())) { Debug(_log, "New connection from %s", QSTRING_CSTR(socket->peerAddress().toString())); - FlatBufferClient *client = new FlatBufferClient(socket, _timeout, _hdrToneMappingEnabled, _lutBuffer, this); + FlatBufferClient* client = new FlatBufferClient(socket, _timeout, _hdrToneMappingEnabled, _lutBuffer, this); // internal connect(client, &FlatBufferClient::clientDisconnected, this, &FlatBufferServer::clientDisconnected); connect(client, &FlatBufferClient::registerGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput); @@ -185,7 +190,7 @@ void FlatBufferServer::loadLutFile() { QString fileName1 = QString("%1%2").arg(_configurationPath).arg("/lut_lin_tables.3d"); QString fileName2 = QString("%1%2").arg(GetSharedLut()).arg("/lut_lin_tables.3d"); - QList files({fileName1, fileName2}); + QList files({ fileName1, fileName2 }); #ifdef __linux__ QString fileName3 = QString("/usr/share/hyperhdr/lut/lut_lin_tables.3d"); @@ -196,15 +201,15 @@ void FlatBufferServer::loadLutFile() if (_hdrToneMappingEnabled) { - for(QString fileName3d : files) + for (QString fileName3d : files) { QFile file(fileName3d); - + if (file.open(QIODevice::ReadOnly)) { size_t length; Debug(_log, "LUT file found: %s", QSTRING_CSTR(fileName3d)); - + length = file.size(); if (length == LUT_FILE_SIZE * 3) @@ -228,7 +233,7 @@ void FlatBufferServer::loadLutFile() } else Error(_log, "LUT file has invalid length: %i %s. Please generate new one LUT table using the generator page.", length, QSTRING_CSTR(fileName3d)); - + file.close(); return; @@ -239,4 +244,4 @@ void FlatBufferServer::loadLutFile() Error(_log, "Could not find any required LUT file"); } -} \ No newline at end of file +} diff --git a/sources/hyperhdrbase/MessageForwarder.cpp b/sources/hyperhdrbase/MessageForwarder.cpp index 81382ea13..837ae8c1f 100644 --- a/sources/hyperhdrbase/MessageForwarder.cpp +++ b/sources/hyperhdrbase/MessageForwarder.cpp @@ -242,7 +242,8 @@ void MessageForwarder::forwardFlatbufferMessage(const QString& name, const Image if (_forwarder_enabled) { for (int i = 0; i < _forwardClients.size(); i++) - _forwardClients.at(i)->setImage(image); + if (_forwardClients.at(i)->isFree()) + emit _forwardClients.at(i)->setImage(image); } }