From 326109f6b60bd9fe698f2b3d0048e246c621029e Mon Sep 17 00:00:00 2001 From: Awawa Date: Sun, 23 Jul 2023 19:24:30 +0200 Subject: [PATCH] New feature to pause the USB grabber when all LEDs are off --- include/base/GrabberWrapper.h | 11 ++- sources/base/GrabberWrapper.cpp | 87 ++++++++++++++++++-- sources/base/HyperHdrInstance.cpp | 5 ++ sources/base/schema/schema-videoGrabber.json | 9 ++ www/i18n/en.json | 4 +- 5 files changed, 105 insertions(+), 11 deletions(-) diff --git a/include/base/GrabberWrapper.h b/include/base/GrabberWrapper.h index a76be295f..6c6639f56 100644 --- a/include/base/GrabberWrapper.h +++ b/include/base/GrabberWrapper.h @@ -18,9 +18,6 @@ class GlobalSignals; class QTimer; -/// List of HyperHDR instances that requested screen capt -static QList GRABBER_VIDEO_CLIENTS; - /// /// This class will be inherted by FramebufferWrapper and others which contains the real capture interface /// @@ -69,7 +66,7 @@ public slots: void stop(); private slots: - void handleSourceRequest(hyperhdr::Components component, int hyperHdrInd, bool listen); + void handleSourceRequest(hyperhdr::Components component, int instanceIndex, bool listen); signals: /// @@ -81,6 +78,7 @@ private slots: void cecKeyPressed(int key); void benchmarkUpdate(int status, QString message); void setBrightnessContrastSaturationHue(int brightness, int contrast, int saturation, int hue); + void instancePauseChanged(int instance, bool isEnabled); public: int getHdrToneMappingEnabled(); @@ -97,6 +95,7 @@ public slots: void setBrightnessContrastSaturationHueHandler(int brightness, int contrast, int saturation, int hue); void setQFrameDecimation(int setQframe); void handleSettingsUpdate(settings::type type, const QJsonDocument& config); + void instancePauseChangedHandler(int instance, bool isEnabled); protected: DetectionAutomatic::calibrationPoint parsePoint(int width, int height, QJsonObject element, bool& ok); @@ -112,7 +111,11 @@ public slots: int _cecHdrStart; int _cecHdrStop; bool _autoResume; + bool _isPaused; + bool _pausingModeEnabled; int _benchmarkStatus; QString _benchmarkMessage; + QList _running_clients; + QList _paused_clients; }; diff --git a/sources/base/GrabberWrapper.cpp b/sources/base/GrabberWrapper.cpp index f31976172..e24280fe1 100644 --- a/sources/base/GrabberWrapper.cpp +++ b/sources/base/GrabberWrapper.cpp @@ -49,6 +49,8 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber) , _cecHdrStart(0) , _cecHdrStop(0) , _autoResume(false) + , _isPaused(false) + , _pausingModeEnabled(false) , _benchmarkStatus(-1) , _benchmarkMessage("") { @@ -65,6 +67,64 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber) connect(this, &GrabberWrapper::setBrightnessContrastSaturationHue, this, &GrabberWrapper::setBrightnessContrastSaturationHueHandler); + connect(this, &GrabberWrapper::instancePauseChanged, this, &GrabberWrapper::instancePauseChangedHandler); +} + +void GrabberWrapper::instancePauseChangedHandler(int instance, bool isEnabled) +{ + static int signature = 0; + int trigger = 0; + + if (!_pausingModeEnabled) + return; + + if (!isEnabled) + { + if (!_paused_clients.contains(instance)) + { + _paused_clients.append(instance); + trigger = 10000; + } + } + else if (isEnabled) + { + if (_paused_clients.contains(instance)) + { + _paused_clients.removeOne(instance); + trigger = 1000; + } + } + + if (trigger > 0) + { + int newSignature = ++signature; + QTimer::singleShot(trigger, Qt::TimerType::PreciseTimer, this, [this, newSignature]() { + if (signature == newSignature) + { + if (_paused_clients.length() == _running_clients.length() && _paused_clients.length() > 0) + { + if (!_isPaused) + { + Warning(_log, "LEDs are off and you have enabled the pausing feature for the USB grabber. Pausing the video grabber now."); + auto _running_clients_copy = _running_clients; + _running_clients.clear(); + handleSourceRequest(hyperhdr::Components::COMP_VIDEOGRABBER, -1, false); + _running_clients = _running_clients_copy; + _isPaused = true; + } + } + else if (_paused_clients.length() < _running_clients.length() && _running_clients.length() > 0) + { + if (_isPaused) + { + Warning(_log, "LEDs are on. Resuming the video grabber now."); + handleSourceRequest(hyperhdr::Components::COMP_VIDEOGRABBER, -1, true); + _isPaused = false; + } + } + } + }); + } } void GrabberWrapper::setCecStartStop(int cecHdrStart, int cecHdrStop) @@ -208,16 +268,25 @@ QJsonObject GrabberWrapper::getJsonInfo() return grabbers; } -void GrabberWrapper::handleSourceRequest(hyperhdr::Components component, int hyperhdrInd, bool listen) +void GrabberWrapper::handleSourceRequest(hyperhdr::Components component, int instanceIndex, bool listen) { if (component == hyperhdr::Components::COMP_VIDEOGRABBER) { - if (listen && !GRABBER_VIDEO_CLIENTS.contains(hyperhdrInd)) - GRABBER_VIDEO_CLIENTS.append(hyperhdrInd); - else if (!listen) - GRABBER_VIDEO_CLIENTS.removeOne(hyperhdrInd); + if (instanceIndex >= 0) + { + if (listen && !_running_clients.contains(instanceIndex)) + { + _running_clients.append(instanceIndex); + _paused_clients.removeOne(instanceIndex); + } + else if (!listen) + { + _running_clients.removeOne(instanceIndex); + _paused_clients.removeOne(instanceIndex); + } + } - if (GRABBER_VIDEO_CLIENTS.empty()) + if (_running_clients.empty()) { stop(); @@ -465,6 +534,12 @@ void GrabberWrapper::handleSettingsUpdate(settings::type type, const QJsonDocume Debug(_log, "Auto resume is: %s", (_autoResume) ? "enabled" : "disabled"); } + if (_pausingModeEnabled != obj["led_off_pause"].toBool(false)) + { + _pausingModeEnabled = obj["led_off_pause"].toBool(false); + Debug(_log, "Pausing mode is: %s", (_pausingModeEnabled) ? "enabled" : "disabled"); + } + // crop for video _grabber->setCropping( obj["cropLeft"].toInt(0), diff --git a/sources/base/HyperHdrInstance.cpp b/sources/base/HyperHdrInstance.cpp index 940adc6f8..36de00335 100644 --- a/sources/base/HyperHdrInstance.cpp +++ b/sources/base/HyperHdrInstance.cpp @@ -367,6 +367,11 @@ void HyperHdrInstance::setNewComponentState(hyperhdr::Components component, bool emit PerformanceCounters::getInstance()->newCounter(PerformanceReport(static_cast(PerformanceReportType::LED), -1, "", -1, -1, -1, -1, getInstanceIndex())); else emit PerformanceCounters::getInstance()->removeCounter(static_cast(PerformanceReportType::LED), getInstanceIndex()); + + if (GrabberWrapper::getInstance() != nullptr) + { + emit GrabberWrapper::getInstance()->instancePauseChanged(_instIndex, state); + } } } diff --git a/sources/base/schema/schema-videoGrabber.json b/sources/base/schema/schema-videoGrabber.json index 3bee240c4..856f4ef3b 100644 --- a/sources/base/schema/schema-videoGrabber.json +++ b/sources/base/schema/schema-videoGrabber.json @@ -476,6 +476,15 @@ "hidden":true }, "propertyOrder" : 70 + }, + "led_off_pause" : + { + "type" : "boolean", + "format": "checkbox", + "title" : "edt_conf_stream_ledoff_title", + "default" : false, + "required" : true, + "propertyOrder" : 72 } }, "additionalProperties" : false diff --git a/www/i18n/en.json b/www/i18n/en.json index 6cb74e0f0..35c175a64 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -1209,5 +1209,7 @@ "main_menu_grabber_lut_path_found_CRC" : "File CRC: $1", "main_menu_grabber_lut_path_found_NOCRC" : "enable HDR in USB grabber options and refresh the page", "main_menu_grabber_lut_restart" : "Please restart your system for the changes to take effect fully!
USB grabber config with Brightness=$1, Contrast=$2, Saturation=$3 was saved.", - "main_menu_grabber_lut_confirm" : "Are you sure to download and install new LUT file for your grabber?" + "main_menu_grabber_lut_confirm" : "Are you sure to download and install new LUT file for your grabber?", + "edt_conf_stream_ledoff_expl": "Turn off the USB gripper completely after 10 seconds when all LED devices are off. Resume again when the LED device is enabled.", + "edt_conf_stream_ledoff_title": "Pause when LEDs are off" }