Skip to content

Commit

Permalink
Synchronize interface to FlatBuffers HDR real state when no USB grabb…
Browse files Browse the repository at this point in the history
…ers are present
  • Loading branch information
awawa-dev committed Mar 28, 2022
1 parent eddb2b4 commit 6a74ded
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
12 changes: 8 additions & 4 deletions include/flatbufserver/FlatBufferServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FlatBufferServer : public QObject

signals:
void hdrToneMappingChanged(int mode, uint8_t* lutBuffer);
void HdrChanged(int mode);

public slots:
///
Expand All @@ -44,6 +45,8 @@ public slots:

void setHdrToneMappingEnabled(int mode);

int getHdrToneMappingEnabled();

private slots:
///
/// @brief Is called whenever a new socket wants to connect
Expand Down Expand Up @@ -94,8 +97,9 @@ private slots:
QVector<FlatBufferClient*> _openConnections;

// tone mapping
int _hdrToneMappingMode;
uint8_t* _lutBuffer;
bool _lutBufferInit;
QString _configurationPath;
int _hdrToneMappingMode;
int _realHdrToneMappingMode;
uint8_t* _lutBuffer;
bool _lutBufferInit;
QString _configurationPath;
};
7 changes: 6 additions & 1 deletion sources/api/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
// auth manager
#include <base/AuthManager.h>

#include <flatbufserver/FlatBufferServer.h>

using namespace hyperhdr;

JsonAPI::JsonAPI(QString peerAddress, Logger* log, bool localConnection, QObject* parent, bool noListener)
Expand Down Expand Up @@ -562,7 +564,10 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject& message, const QString&
}
else
{
info["videomodehdr"] = 0;
if (FlatBufferServer::getInstance() != nullptr)
info["videomodehdr"] = FlatBufferServer::getInstance()->getHdrToneMappingEnabled();
else
info["videomodehdr"] = 0;
}

// get available components
Expand Down
10 changes: 10 additions & 0 deletions sources/api/JsonCB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
// Image to led map helper
#include <base/ImageProcessor.h>

#include <flatbufserver/FlatBufferServer.h>

using namespace hyperhdr;

JsonCB::JsonCB(QObject* parent)
Expand Down Expand Up @@ -126,6 +128,14 @@ bool JsonCB::subscribeFor(const QString& type, bool unsubscribe)
connect(GrabberWrapper::instance, &GrabberWrapper::HdrChanged, this, &JsonCB::handleVideoModeHdrChange, Qt::UniqueConnection);
}

if (type == "videomodehdr-update" && GrabberWrapper::instance == nullptr && FlatBufferServer::instance != nullptr)
{
if (unsubscribe)
disconnect(FlatBufferServer::instance, &FlatBufferServer::HdrChanged, this, &JsonCB::handleVideoModeHdrChange);
else
connect(FlatBufferServer::instance, &FlatBufferServer::HdrChanged, this, &JsonCB::handleVideoModeHdrChange, Qt::UniqueConnection);
}

if (type == "effects-update")
{
if (unsubscribe)
Expand Down
25 changes: 18 additions & 7 deletions sources/flatbufserver/FlatBufferServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ FlatBufferServer::FlatBufferServer(const QJsonDocument& config, const QString& c
, _log(Logger::getInstance("FLATBUFSERVER"))
, _timeout(5000)
, _config(config)
, _hdrToneMappingMode(false)
, _hdrToneMappingMode(0)
, _realHdrToneMappingMode(0)
, _lutBuffer(nullptr)
, _lutBufferInit(false)
, _configurationPath(configurationPath)
Expand Down Expand Up @@ -71,13 +72,27 @@ void FlatBufferServer::initServer()

void FlatBufferServer::setHdrToneMappingEnabled(int mode)
{
bool status = _hdrToneMappingMode && mode;
bool status = (_hdrToneMappingMode != 0) && (mode != 0);

if (status)
loadLutFile();

_realHdrToneMappingMode = (_lutBufferInit && status) ? mode : 0;

// inform clients
emit hdrToneMappingChanged((_lutBufferInit && status)?mode :0, _lutBuffer);
emit hdrToneMappingChanged(_realHdrToneMappingMode, _lutBuffer);


#if !defined(ENABLE_MF) && !defined(ENABLE_AVF) && !defined(ENABLE_V4L2)
emit HdrChanged(_realHdrToneMappingMode);
emit HyperHdrIManager::getInstance()->setNewComponentStateToAllInstances(hyperhdr::Components::COMP_HDR, (_realHdrToneMappingMode != 0));
#endif

}

int FlatBufferServer::getHdrToneMappingEnabled()
{
return _realHdrToneMappingMode;
}

void FlatBufferServer::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
Expand All @@ -100,10 +115,6 @@ void FlatBufferServer::handleSettingsUpdate(settings::type type, const QJsonDocu

setHdrToneMappingEnabled(_hdrToneMappingMode);

#if !defined(ENABLE_MF) && !defined(ENABLE_AVF) && !defined(ENABLE_V4L2)
emit HyperHdrIManager::getInstance()->setNewComponentStateToAllInstances(hyperhdr::Components::COMP_HDR, (_hdrToneMappingMode != 0));
#endif

// new timeout just for new connections
_timeout = obj["timeout"].toInt(5000);
// enable check
Expand Down

0 comments on commit 6a74ded

Please sign in to comment.