Skip to content

Commit

Permalink
New feature to pause the USB grabber when all LEDs are off
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Jul 23, 2023
1 parent 69da76c commit 326109f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 11 deletions.
11 changes: 7 additions & 4 deletions include/base/GrabberWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
class GlobalSignals;
class QTimer;

/// List of HyperHDR instances that requested screen capt
static QList<int> GRABBER_VIDEO_CLIENTS;

///
/// This class will be inherted by FramebufferWrapper and others which contains the real capture interface
///
Expand Down Expand Up @@ -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:
///
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -112,7 +111,11 @@ public slots:
int _cecHdrStart;
int _cecHdrStop;
bool _autoResume;
bool _isPaused;
bool _pausingModeEnabled;

int _benchmarkStatus;
QString _benchmarkMessage;
QList<int> _running_clients;
QList<int> _paused_clients;
};
87 changes: 81 additions & 6 deletions sources/base/GrabberWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber)
, _cecHdrStart(0)
, _cecHdrStop(0)
, _autoResume(false)
, _isPaused(false)
, _pausingModeEnabled(false)
, _benchmarkStatus(-1)
, _benchmarkMessage("")
{
Expand All @@ -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)
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ void HyperHdrInstance::setNewComponentState(hyperhdr::Components component, bool
emit PerformanceCounters::getInstance()->newCounter(PerformanceReport(static_cast<int>(PerformanceReportType::LED), -1, "", -1, -1, -1, -1, getInstanceIndex()));
else
emit PerformanceCounters::getInstance()->removeCounter(static_cast<int>(PerformanceReportType::LED), getInstanceIndex());

if (GrabberWrapper::getInstance() != nullptr)
{
emit GrabberWrapper::getInstance()->instancePauseChanged(_instIndex, state);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions sources/base/schema/schema-videoGrabber.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!<br>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"
}

0 comments on commit 326109f

Please sign in to comment.