Skip to content

Commit

Permalink
Add popular 'UDP raw' receiver for HyperHDR
Browse files Browse the repository at this point in the history
compatible with other applications
per instance settings
Advanced → Network services → UDP raw receiver
  • Loading branch information
awawa-dev committed Mar 28, 2022
1 parent 6a74ded commit 5fb1be1
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 2 deletions.
6 changes: 4 additions & 2 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,10 @@
"perf_undervoltage" : "Undervoltage detected",
"perf_no" : "No",
"perf_invalid_frames" : "invalid frames",
"edt_conf_fbs_tonemapping_expl": "If enabled, HyperHDR will apply LUT correction for the incoming stream. Make sure you have got the correct LUT table. Default 3D LUT file <span class='fw-bold'>for HDR10: '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_expl": "If enabled, HyperHDR will apply LUT correction for the incoming stream. Make sure you have got the correct LUT table. Default 3D LUT file <span class='fw-bold'>for HDR10: 'lut_lin_tables.3d'</span> (filename 'flat_lut_lin_tables.3d' is also accepted) 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_fbs_hdrToneMappingMode_title": "Area for LUT mode effect",
"edt_conf_fbs_hdrToneMappingMode_expl": "Fullscreen or faster Border Mode"
"edt_conf_fbs_hdrToneMappingMode_expl": "Fullscreen or faster Border Mode",
"general_comp_RAWUDPSERVER" : "UDP raw receiver",
"edt_udp_raw_server" : "A lightweight server for remote synchronization of HyperHDR instances using UDP and raw RGB LED colors. Use the 'udpraw' light source in the sender. Important: both instances should have the same number of LEDs and same geometry for this to work."
}
27 changes: 27 additions & 0 deletions assets/webconfig/js/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $(document).ready( function() {
var conf_editor_fbs = null;
var conf_editor_bobl = null;
var conf_editor_forw = null;
var conf_editor_rawUdp = null;

{
$('#conf_cont').append(createOptPanel('fa-wrench', $.i18n("edt_conf_webc_heading_title"), 'editor_container', 'btn_submit_www'));
Expand All @@ -34,6 +35,9 @@ $(document).ready( function() {
$('#conf_cont').append(createHelpTable(window.schema.protoServer.properties, $.i18n("edt_conf_pbs_heading_title")));
}

$('#conf_cont').append(createOptPanel('fa-sitemap', $.i18n("general_comp_RAWUDPSERVER"), 'editor_container_rawUdpServer', 'btn_submit_rawUdpServer'));
$('#conf_cont').append(createHelpTable(window.schema.rawUdpServer.properties, $.i18n("general_comp_RAWUDPSERVER")));

//boblight
if (BOBLIGHT_ENABLED)
{
Expand Down Expand Up @@ -123,6 +127,20 @@ $(document).ready( function() {
});
}

conf_editor_rawUdp = createJsonEditor('editor_container_rawUdpServer', {
rawUdpServer : window.schema.rawUdpServer
}, true, true);

conf_editor_rawUdp.on('change',function() {
conf_editor_rawUdp.validate().length || window.readOnlyMode ? $('#btn_submit_rawUdpServer').attr('disabled', true) : $('#btn_submit_rawUdpServer').attr('disabled', false);
});

$('#btn_submit_rawUdpServer').off().on('click',function() {
requestWriteConfig(conf_editor_rawUdp.getValue());
});

document.getElementById('editor_container_rawUdpServer').parentElement.firstElementChild.classList.add('is-instance');

//boblight
if (BOBLIGHT_ENABLED)
{
Expand All @@ -137,6 +155,8 @@ $(document).ready( function() {
$('#btn_submit_boblightserver').off().on('click',function() {
requestWriteConfig(conf_editor_bobl.getValue());
});

document.getElementById('editor_container_boblightserver').parentElement.firstElementChild.classList.add('is-instance');
}

if(storedAccess != 'default')
Expand All @@ -162,6 +182,7 @@ $(document).ready( function() {
createHint("intro", $.i18n('conf_network_net_intro'), "editor_container_net");
createHint("intro", $.i18n('conf_network_json_intro'), "editor_container_jsonserver");
createHint("intro", $.i18n('conf_network_fbs_intro'), "editor_container_fbserver");
createHint("intro", $.i18n('edt_udp_raw_server'), "editor_container_rawUdpServer");

if (window.serverInfo.hasPROTOBUF == 1)
{
Expand Down Expand Up @@ -239,5 +260,11 @@ $(document).ready( function() {

checkApiTokenState(window.serverConfig.network.apiAuth);

var instHeaders = document.getElementsByClassName("card-header");
Array.prototype.forEach.call(instHeaders, function(instHeader, index) {
if (instHeader.classList.contains('is-instance'))
putInstanceName(instHeader);
});

removeOverlay();
});
3 changes: 3 additions & 0 deletions assets/webconfig/js/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ $(document).ready(function()
case "PROTOSERVER":
owner = $.i18n('general_comp_PROTOSERVER');
break;
case "RAWUDPSERVER":
owner = $.i18n('general_comp_RAWUDPSERVER');
break;
}

if (duration && compId != "GRABBER" && compId != "FLATBUFSERVER" && compId != "PROTOSERVER")
Expand Down
2 changes: 2 additions & 0 deletions include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class BGEffectHandler;
class VideoControl;
class SystemControl;
class BoblightServer;
class RawUdpServer;
class LedDeviceWrapper;
class ImageProcessingUnit;
class Logger;
Expand Down Expand Up @@ -519,6 +520,7 @@ private slots:

/// Boblight instance
BoblightServer* _boblightServer;
RawUdpServer* _rawUdpServer;

QString _name;

Expand Down
4 changes: 4 additions & 0 deletions include/utils/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace hyperhdr
COMP_EFFECT,
COMP_LEDDEVICE,
COMP_FLATBUFSERVER,
COMP_RAWUDPSERVER,
COMP_PROTOSERVER
};

Expand All @@ -43,6 +44,7 @@ namespace hyperhdr
case COMP_IMAGE: return "Image";
case COMP_LEDDEVICE: return "LED device";
case COMP_FLATBUFSERVER: return "Image Receiver";
case COMP_RAWUDPSERVER: return "Raw RGB UDP Server";
case COMP_PROTOSERVER: return "Proto Server";
default: return "";
}
Expand All @@ -65,6 +67,7 @@ namespace hyperhdr
case COMP_IMAGE: return "IMAGE";
case COMP_LEDDEVICE: return "LEDDEVICE";
case COMP_FLATBUFSERVER: return "FLATBUFSERVER";
case COMP_RAWUDPSERVER: return "RAWUDPSERVER";
case COMP_PROTOSERVER: return "PROTOSERVER";
default: return "";
}
Expand All @@ -86,6 +89,7 @@ namespace hyperhdr
if (cmp == "IMAGE") return COMP_IMAGE;
if (cmp == "LEDDEVICE") return COMP_LEDDEVICE;
if (cmp == "FLATBUFSERVER") return COMP_FLATBUFSERVER;
if (cmp == "RAWUDPSERVER") return COMP_RAWUDPSERVER;
if (cmp == "PROTOSERVER") return COMP_PROTOSERVER;
return COMP_INVALID;
}
Expand Down
85 changes: 85 additions & 0 deletions include/utils/RawUdpServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#pragma once

/* RawUdpServer.h
*
* MIT License
*
* Copyright (c) 2022 awawa-dev
*
* Project homesite: https://github.com/awawa-dev/HyperHDR
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

// utils
#include <utils/Logger.h>
#include <utils/settings.h>

// qt
#include <QVector>

class QUdpSocket;
class NetOrigin;
class HyperHdrInstance;
class QTimer;

class RawUdpServer : public QObject
{
Q_OBJECT

public:
RawUdpServer(HyperHdrInstance* hyperhdr, const QJsonDocument& config, QObject* parent = nullptr);
~RawUdpServer() override;

public slots:
///
/// @brief Handle settings update
/// @param type The type from enum
/// @param config The configuration
///
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);

void initServer();

void readPendingDatagrams();

void dataTimeout();

private:
///
/// @brief Start the server with current _port
///
void startServer();

///
/// @brief Stop server
///
void stopServer();

private:
QUdpSocket* _server;
Logger* _log;
quint16 _port;
int _priority;
bool _initialized;

HyperHdrInstance* _hyperhdr;
const QJsonDocument _config;
QTimer* _inactiveTimer;
};
3 changes: 3 additions & 0 deletions include/utils/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace settings {
VIDEODETECTION,
NETWORK,
FLATBUFSERVER,
RAWUDPSERVER,
PROTOSERVER,
INVALID
};
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace settings {
case type::VIDEODETECTION:return "videoDetection";
case type::NETWORK: return "network";
case type::FLATBUFSERVER: return "flatbufServer";
case type::RAWUDPSERVER: return "rawUdpServer";
case type::PROTOSERVER: return "protoServer";
default: return "invalid";
}
Expand Down Expand Up @@ -102,6 +104,7 @@ namespace settings {
else if (type == "videoDetection") return type::VIDEODETECTION;
else if (type == "network") return type::NETWORK;
else if (type == "flatbufServer") return type::FLATBUFSERVER;
else if (type == "rawUdpServer") return type::RAWUDPSERVER;
else if (type == "protoServer") return type::PROTOSERVER;
else return type::INVALID;
}
Expand Down
7 changes: 7 additions & 0 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
class BoblightServer {};
#endif

#include <utils/RawUdpServer.h>



HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, QString name)
Expand All @@ -74,6 +76,7 @@ HyperHdrInstance::HyperHdrInstance(quint8 instance, bool readonlyMode, QString n
, _systemControl(nullptr)
, _globalLedBuffer(_ledString.leds().size(), ColorRgb::BLACK)
, _boblightServer(nullptr)
, _rawUdpServer(nullptr)
, _name((name.isEmpty()) ? QString("INSTANCE%1").arg(instance):name)
, _readOnlyMode(readonlyMode)

Expand Down Expand Up @@ -191,6 +194,9 @@ void HyperHdrInstance::start()
connect(this, &HyperHdrInstance::settingsChanged, _boblightServer, &BoblightServer::handleSettingsUpdate);
#endif

_rawUdpServer = new RawUdpServer(this, getSetting(settings::type::RAWUDPSERVER));
connect(this, &HyperHdrInstance::settingsChanged, _rawUdpServer, &RawUdpServer::handleSettingsUpdate);

// instance initiated, enter thread event loop
emit started();
}
Expand All @@ -212,6 +218,7 @@ void HyperHdrInstance::freeObjects()

// delete components on exit
delete _boblightServer;
delete _rawUdpServer;
delete _videoControl;
delete _systemControl;
delete _effectEngine;
Expand Down
4 changes: 4 additions & 0 deletions sources/base/hyperhdr.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
{
"$ref": "schema-flatbufServer.json"
},
"rawUdpServer":
{
"$ref": "schema-rawUdpServer.json"
},
"protoServer" :
{
"$ref": "schema-protoServer.json"
Expand Down
1 change: 1 addition & 0 deletions sources/base/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<file alias="schema-forwarder.json">schema/schema-forwarder.json</file>
<file alias="schema-jsonServer.json">schema/schema-jsonServer.json</file>
<file alias="schema-flatbufServer.json">schema/schema-flatbufServer.json</file>
<file alias="schema-rawUdpServer.json">schema/schema-rawUdpServer.json</file>
<file alias="schema-protoServer.json">schema/schema-protoServer.json</file>
<file alias="schema-boblightServer.json">schema/schema-boblightServer.json</file>
<file alias="schema-webConfig.json">schema/schema-webConfig.json</file>
Expand Down
37 changes: 37 additions & 0 deletions sources/base/schema/schema-rawUdpServer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"type" : "object",
"title" : "general_comp_RAWUDPSERVER",
"properties" :
{
"enable" :
{
"type" : "boolean",
"format": "checkbox",
"title" : "edt_conf_general_enable_title",
"default" : false,
"required" : true,
"propertyOrder" : 1
},
"port" :
{
"type" : "integer",
"required" : true,
"title" : "edt_conf_general_port_title",
"default" : 5568,
"minimum" : 1024,
"maximum" : 65535,
"propertyOrder" : 2
},
"priority" :
{
"type" : "integer",
"title" : "edt_conf_general_priority_title",
"minimum" : 100,
"maximum" : 254,
"default" : 109,
"required" : true,
"propertyOrder" : 3
}
},
"additionalProperties" : false
}
Loading

0 comments on commit 5fb1be1

Please sign in to comment.