Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Feb 26, 2022
1 parent 88054d0 commit f4f39d7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 21 deletions.
6 changes: 3 additions & 3 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span class='fw-bold'>'lut_lin_tables.3d'</span> is already included.<span class='fw-bold'> You can generate one and preview the effect using link in the 'Advanced menu'.</span><br/>Your typical hidden configuration folder to upload that file in is (check 'Logs' page to confirm):<br/> Rpi→&#47;home&#47;pi&#47;.hyperhdr<br/>Windows→c:&#47;Users&#47;NAME&#47;.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",
Expand Down Expand Up @@ -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 <span class='fw-bold'>'lut_lin_tables.3d'</span> is already included.<span class='fw-bold'> You can generate one and preview the effect using link in the 'Advanced menu'.</span><br/>Your typical hidden configuration folder to upload that file in is (check 'Logs' page to confirm):<br/> Rpi→&#47;home&#47;pi&#47;.hyperhdr<br/>Windows→c:&#47;Users&#47;NAME&#47;.hyperhdr",
"edt_conf_fbs_tonemapping_title": "HDR to SDR tone mapping"
}
3 changes: 3 additions & 0 deletions include/flatbufserver/FlatBufferConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,4 +134,5 @@ private slots:
flatbuffers::FlatBufferBuilder _builder;

bool _registered;
bool _free;
};
2 changes: 1 addition & 1 deletion include/flatbufserver/FlatBufferServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions sources/api/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <HyperhdrConfig.h>
#include <utils/SysInfo.h>
#include <utils/ColorSys.h>
#include <flatbufserver/FlatBufferServer.h>

// bonjour wrapper
#include <bonjour/bonjourbrowserwrapper.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sources/flatbufserver/FlatBufferClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// util includes
#include <utils/FrameDecoder.h>

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)
Expand Down
2 changes: 1 addition & 1 deletion sources/flatbufserver/FlatBufferClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down
11 changes: 11 additions & 0 deletions sources/flatbufserver/FlatBufferConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -126,6 +127,8 @@ void FlatBufferConnection::setColor(const ColorRgb& color, int priority, int dur

void FlatBufferConnection::setImage(const Image<ColorRgb>& image)
{
_free = false;

auto imgData = _builder.CreateVector(reinterpret_cast<const uint8_t*>(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);
Expand All @@ -134,6 +137,14 @@ void FlatBufferConnection::setImage(const Image<ColorRgb>& image)
_builder.Finish(req);
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
_builder.Clear();

_free = true;
}


bool FlatBufferConnection::isFree()
{
return _free;
}

void FlatBufferConnection::clear(int priority)
Expand Down
29 changes: 17 additions & 12 deletions sources/flatbufserver/FlatBufferServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QTcpSocket>
#include <QFile>
#include <QCoreApplication>
#include <QFileInfo>

#define LUT_FILE_SIZE 50331648

Expand Down Expand Up @@ -44,6 +45,8 @@ FlatBufferServer::~FlatBufferServer()
if (_lutBuffer != NULL)
free(_lutBuffer);
_lutBuffer = NULL;

FlatBufferServer::instance = nullptr;
}

void FlatBufferServer::initServer()
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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<QString> files({fileName1, fileName2});
QList<QString> files({ fileName1, fileName2 });

#ifdef __linux__
QString fileName3 = QString("/usr/share/hyperhdr/lut/lut_lin_tables.3d");
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -239,4 +244,4 @@ void FlatBufferServer::loadLutFile()

Error(_log, "Could not find any required LUT file");
}
}
}
3 changes: 2 additions & 1 deletion sources/hyperhdrbase/MessageForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit f4f39d7

Please sign in to comment.