From 1ef3a106f1a96ca3d52d4719fa29dfdf6f69b6a1 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:56:06 +0200 Subject: [PATCH] Smoothing Fixes, Optimizations (#1295) * Fix #1098, Removed Continuous Output as being obsolete * Pause output processing when no input source is available * Only show configurable options for Linear smoothing --- config/hyperion.config.json.default | 3 +- include/hyperion/Hyperion.h | 7 +- libsrc/hyperion/Hyperion.cpp | 13 +- libsrc/hyperion/LinearColorSmoothing.cpp | 56 ++---- libsrc/hyperion/LinearColorSmoothing.h | 6 - libsrc/hyperion/schema/schema-smoothing.json | 197 ++++++++++--------- 6 files changed, 134 insertions(+), 148 deletions(-) diff --git a/config/hyperion.config.json.default b/config/hyperion.config.json.default index 910980f1..fc7c1803 100644 --- a/config/hyperion.config.json.default +++ b/config/hyperion.config.json.default @@ -58,8 +58,7 @@ "outputRate" : 25.0000, "decay" : 1, "dithering" : false, - "updateDelay" : 0, - "continuousOutput" : true + "updateDelay" : 0 }, "grabberV4L2" : diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 4b4e138a..07f2d750 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -476,8 +476,11 @@ private slots: /// void handleNewVideoMode(VideoMode mode) { _currVideoMode = mode; } - - void handlePriorityChangedLedDevice(const quint8& priority); + /// + /// @brief Handle the scenario when no/an input source is available + /// @param priority Current priority + /// + void handleSourceAvailability(const quint8& priority); private: friend class HyperionDaemon; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 23ba6e82..69d02e09 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -93,7 +93,7 @@ void Hyperion::start() // connect Hyperion::update with Muxer visible priority changes as muxer updates independent connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::update); - connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handlePriorityChangedLedDevice); + connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability); connect(&_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged); // listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions @@ -552,22 +552,23 @@ void Hyperion::handleVisibleComponentChanged(hyperion::Components comp) _raw2ledAdjustment->setBacklightEnabled((comp != hyperion::COMP_COLOR && comp != hyperion::COMP_EFFECT)); } -void Hyperion::handlePriorityChangedLedDevice(const quint8& priority) -{ - int previousPriority = _muxer.getPreviousPriority(); +void Hyperion::handleSourceAvailability(const quint8& priority) +{ int previousPriority = _muxer.getPreviousPriority(); Debug(_log,"priority[%d], previousPriority[%d]", priority, previousPriority); if ( priority == PriorityMuxer::LOWEST_PRIORITY) { - Debug(_log,"No source left -> switch LED-Device off"); + Debug(_log,"No source left -> Pause output processing and switch LED-Device off"); emit _ledDeviceWrapper->switchOff(); + emit _deviceSmooth->setPause(true); } else { if ( previousPriority == PriorityMuxer::LOWEST_PRIORITY ) { - Debug(_log,"new source available -> switch LED-Device on"); + Debug(_log,"new source available -> Resume output processing and switch LED-Device on"); emit _ledDeviceWrapper->switchOn(); + emit _deviceSmooth->setPause(false); } } } diff --git a/libsrc/hyperion/LinearColorSmoothing.cpp b/libsrc/hyperion/LinearColorSmoothing.cpp index 0af1128f..7d244bee 100644 --- a/libsrc/hyperion/LinearColorSmoothing.cpp +++ b/libsrc/hyperion/LinearColorSmoothing.cpp @@ -50,19 +50,17 @@ const unsigned DEFAUL_OUTPUTDEPLAY = 0; // outputdelay in ms LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion) : QObject(hyperion) - , _log(Logger::getInstance("SMOOTHING")) - , _hyperion(hyperion) - , _updateInterval(DEFAUL_UPDATEINTERVALL.count()) - , _settlingTime(DEFAUL_SETTLINGTIME) - , _timer(new QTimer(this)) - , _outputDelay(DEFAUL_OUTPUTDEPLAY) - , _smoothingType(SmoothingType::Linear) - , _writeToLedsEnable(false) - , _continuousOutput(false) - , _pause(false) - , _currentConfigId(0) - , _enabled(false) - , tempValues(std::vector(0, 0L)) + , _log(Logger::getInstance("SMOOTHING")) + , _hyperion(hyperion) + , _updateInterval(DEFAUL_UPDATEINTERVALL.count()) + , _settlingTime(DEFAUL_SETTLINGTIME) + , _timer(new QTimer(this)) + , _outputDelay(DEFAUL_OUTPUTDEPLAY) + , _smoothingType(SmoothingType::Linear) + , _pause(false) + , _currentConfigId(0) + , _enabled(false) + , tempValues(std::vector(0, 0L)) { // init cfg 0 (default) addConfig(DEFAUL_SETTLINGTIME, DEFAUL_UPDATEFREQUENCY, DEFAUL_OUTPUTDEPLAY); @@ -94,8 +92,6 @@ void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJson setEnable(obj["enable"].toBool(true)); } - _continuousOutput = obj["continuousOutput"].toBool(true); - SMOOTHING_CFG cfg = {SmoothingType::Linear,true, 0, 0, 0, 0, 0, false, 1}; const QString typeString = obj[SETTINGS_KEY_SMOOTHING_TYPE].toString(); @@ -192,7 +188,6 @@ void LinearColorSmoothing::writeDirect() _previousWriteTime = now; queueColors(_previousValues); - _writeToLedsEnable = _continuousOutput; } @@ -201,7 +196,6 @@ void LinearColorSmoothing::writeFrame() const int64_t now = micros(); _previousWriteTime = now; queueColors(_previousValues); - _writeToLedsEnable = _continuousOutput; } @@ -402,12 +396,12 @@ void LinearColorSmoothing::performDecay(const int64_t now) { if ((now > (_renderedStatTime + 30 * 1000000)) && (_renderedCounter > _renderedStatCounter)) { Debug(_log, "decay - rendered frames [%d] (%f/s), interpolated frames [%d] (%f/s) in [%f ms]" - , _renderedCounter - _renderedStatCounter - , (1.0F * (_renderedCounter - _renderedStatCounter) / ((now - _renderedStatTime) / 1000000.0F)) - , _interpolationCounter - _interpolationStatCounter - , (1.0F * (_interpolationCounter - _interpolationStatCounter) / ((now - _renderedStatTime) / 1000000.0F)) - , (now - _renderedStatTime) / 1000.0F - ); + , _renderedCounter - _renderedStatCounter + , (1.0F * (_renderedCounter - _renderedStatCounter) / ((now - _renderedStatTime) / 1000000.0F)) + , _interpolationCounter - _interpolationStatCounter + , (1.0F * (_interpolationCounter - _interpolationStatCounter) / ((now - _renderedStatTime) / 1000000.0F)) + , (now - _renderedStatTime) / 1000.0F + ); _renderedStatTime = now; _renderedStatCounter = _renderedCounter; _interpolationStatCounter = _interpolationCounter; @@ -505,30 +499,23 @@ void LinearColorSmoothing::clearRememberedFrames() void LinearColorSmoothing::queueColors(const std::vector &ledColors) { - //Debug(_log, "queueColors - _outputDelay[%d] _outputQueue.size() [%d], _writeToLedsEnable[%d]", _outputDelay, _outputQueue.size(), _writeToLedsEnable); if (_outputDelay == 0) { // No output delay => immediate write - if (_writeToLedsEnable && !_pause) + if (!_pause) { - // if ( ledColors.size() == 0 ) - // qFatal ("No LedValues! - in LinearColorSmoothing::queueColors() - _outputDelay == 0"); - // else emit _hyperion->ledDeviceData(ledColors); } } else { // Push new colors in the delay-buffer - if (_writeToLedsEnable) - { - _outputQueue.push_back(ledColors); - } + _outputQueue.push_back(ledColors); // If the delay-buffer is filled pop the front and write to device if (!_outputQueue.empty()) { - if (_outputQueue.size() > _outputDelay || !_writeToLedsEnable) + if (_outputQueue.size() > _outputDelay) { if (!_pause) { @@ -552,7 +539,6 @@ void LinearColorSmoothing::clearQueuedColors() void LinearColorSmoothing::componentStateChange(hyperion::Components component, bool state) { - _writeToLedsEnable = state; if (component == hyperion::COMP_LEDDEVICE) { clearQueuedColors(); @@ -682,7 +668,7 @@ bool LinearColorSmoothing::selectConfig(unsigned cfg, bool force) QMetaObject::invokeMethod(_timer, "stop", Qt::QueuedConnection); _updateInterval = _cfgList[cfg].updateInterval; - if (this->enabled() && this->_writeToLedsEnable) + if (this->enabled()) { //Debug( _log, "_cfgList[cfg].updateInterval != _updateInterval - Restart timer - _updateInterval [%d]", _updateInterval); QMetaObject::invokeMethod(_timer, "start", Qt::QueuedConnection, Q_ARG(int, _updateInterval)); diff --git a/libsrc/hyperion/LinearColorSmoothing.h b/libsrc/hyperion/LinearColorSmoothing.h index d9f2d355..3eed8451 100644 --- a/libsrc/hyperion/LinearColorSmoothing.h +++ b/libsrc/hyperion/LinearColorSmoothing.h @@ -222,12 +222,6 @@ private: /// The queue of temporarily remembered frames std::deque _frameQueue; - /// Prevent sending data to device when no intput data is sent - bool _writeToLedsEnable; - - /// Flag for dis/enable continuous output to led device regardless there is new data or not - bool _continuousOutput; - /// Flag for pausing bool _pause; diff --git a/libsrc/hyperion/schema/schema-smoothing.json b/libsrc/hyperion/schema/schema-smoothing.json index fcf0835a..7d2cb7c0 100644 --- a/libsrc/hyperion/schema/schema-smoothing.json +++ b/libsrc/hyperion/schema/schema-smoothing.json @@ -1,99 +1,102 @@ { - "type" : "object", - "title" : "edt_conf_smooth_heading_title", - "properties" : - { - "enable" : - { - "type" : "boolean", - "title" : "edt_conf_general_enable_title", - "default" : true, - "propertyOrder" : 1 - }, - "type" : - { - "type" : "string", - "title" : "edt_conf_smooth_type_title", - "enum" : ["linear", "decay"], - "default" : "linear", - "options" : { - "enum_titles" : ["edt_conf_enum_linear", "edt_conf_enum_decay"] - }, - "propertyOrder" : 2 - }, - "time_ms" : - { - "type" : "integer", - "title" : "edt_conf_smooth_time_ms_title", - "minimum" : 25, - "maximum": 5000, - "default" : 200, - "append" : "edt_append_ms", - "propertyOrder" : 3 - }, - "updateFrequency" : - { - "type" : "number", - "title" : "edt_conf_smooth_updateFrequency_title", - "minimum" : 1.0, - "maximum" : 2000.0, - "default" : 25.0, - "append" : "edt_append_hz", - "propertyOrder" : 4 - }, - "interpolationRate" : - { - "type" : "number", - "title" : "edt_conf_smooth_interpolationRate_title", - "minimum" : 1.0, - "maximum": 1000.0, - "default" : 1.0, - "append" : "edt_append_hz", - "propertyOrder" : 5 - }, - "outputRate" : - { - "type" : "number", - "title" : "edt_conf_smooth_outputRate_title", - "minimum" : 1.0, - "maximum": 1000.0, - "default" : 1.0, - "append" : "edt_append_hz", - "propertyOrder" : 6 - }, - "decay" : - { - "type" : "number", - "title" : "edt_conf_smooth_decay_title", - "default" : 1.0, - "minimum" : 1.0, - "maximum": 20.0, - "propertyOrder" : 7 - }, - "dithering" : - { - "type" : "boolean", - "title" : "edt_conf_smooth_dithering_title", - "default" : true, - "propertyOrder" : 8 - }, - "updateDelay" : - { - "type" : "integer", - "title" : "edt_conf_smooth_updateDelay_title", - "minimum" : 0, - "maximum": 2048, - "default" : 0, - "append" : "edt_append_ms", - "propertyOrder" : 9 - }, - "continuousOutput" : - { - "type" : "boolean", - "title" : "edt_conf_smooth_continuousOutput_title", - "default" : true, - "propertyOrder" : 10 - } - }, - "additionalProperties" : false + "type": "object", + "title": "edt_conf_smooth_heading_title", + "properties": { + "enable": { + "type": "boolean", + "title": "edt_conf_general_enable_title", + "default": true, + "propertyOrder": 1 + }, + "type": { + "type": "string", + "title": "edt_conf_smooth_type_title", + "enum": [ "linear", "decay" ], + "default": "linear", + "options": { + "enum_titles": [ "edt_conf_enum_linear", "edt_conf_enum_decay" ] + }, + "propertyOrder": 2 + }, + "time_ms": { + "type": "integer", + "title": "edt_conf_smooth_time_ms_title", + "minimum": 25, + "maximum": 5000, + "default": 200, + "append": "edt_append_ms", + "propertyOrder": 3 + }, + "updateFrequency": { + "type": "number", + "title": "edt_conf_smooth_updateFrequency_title", + "minimum": 1.0, + "maximum": 2000.0, + "default": 25.0, + "append": "edt_append_hz", + "propertyOrder": 4 + }, + "interpolationRate": { + "type": "number", + "title": "edt_conf_smooth_interpolationRate_title", + "minimum": 1.0, + "maximum": 1000.0, + "default": 1.0, + "append": "edt_append_hz", + "propertyOrder": 5, + "options": { + "dependencies": { + "type": "decay" + } + } + }, + "outputRate": { + "type": "number", + "title": "edt_conf_smooth_outputRate_title", + "minimum": 1.0, + "maximum": 1000.0, + "default": 1.0, + "append": "edt_append_hz", + "propertyOrder": 6, + "options": { + "dependencies": { + "type": "decay" + } + } + }, + "decay": { + "type": "number", + "title": "edt_conf_smooth_decay_title", + "default": 1.0, + "minimum": 1.0, + "maximum": 20.0, + "propertyOrder": 7, + "options": { + "dependencies": { + "type": "decay" + } + } + }, + "dithering": { + "type": "boolean", + "title": "edt_conf_smooth_dithering_title", + "default": true, + "propertyOrder": 8, + "options": { + "dependencies": { + "type": "decay" + } + } + }, + "updateDelay": { + "type": "integer", + "title": "edt_conf_smooth_updateDelay_title", + "minimum": 0, + "maximum": 2048, + "default": 0, + "append": "edt_append_ms", + "propertyOrder": 9 + } + }, + "additionalProperties": false }