Fix start streaming action only working every second attempt

This commit is contained in:
WarmUpTill 2022-03-18 19:36:15 +01:00 committed by WarmUpTill
parent 1d45072c58
commit 11fede6cc3
2 changed files with 17 additions and 7 deletions

View File

@ -1,10 +1,10 @@
#pragma once
#include "macro-action-edit.hpp"
#include "duration-control.hpp"
#include <QDoubleSpinBox>
#include <QComboBox>
#include <QHBoxLayout>
#include <chrono>
enum class StreamAction {
STOP,
@ -27,9 +27,8 @@ public:
StreamAction _action = StreamAction::STOP;
private:
// Acts as a safeguard for misconfigured streaming setups leading to an
// endless error spam.
Duration _retryCooldown;
bool CooldownDurationReached();
static std::chrono::high_resolution_clock::time_point s_lastAttempt;
static bool _registered;
static const std::string id;

View File

@ -14,6 +14,17 @@ const static std::map<StreamAction, std::string> actionTypes = {
{StreamAction::START, "AdvSceneSwitcher.action.streaming.type.start"},
};
constexpr int streamStartCooldown = 5;
std::chrono::high_resolution_clock::time_point MacroActionStream::s_lastAttempt =
std::chrono::high_resolution_clock::now();
bool MacroActionStream::CooldownDurationReached()
{
auto timePassed = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::high_resolution_clock::now() - s_lastAttempt);
return timePassed.count() >= streamStartCooldown;
}
bool MacroActionStream::PerformAction()
{
switch (_action) {
@ -24,10 +35,10 @@ bool MacroActionStream::PerformAction()
break;
case StreamAction::START:
if (!obs_frontend_streaming_active() &&
_retryCooldown.DurationReached()) {
CooldownDurationReached()) {
obs_frontend_streaming_start();
_retryCooldown.seconds++;
_retryCooldown.Reset();
s_lastAttempt =
std::chrono::high_resolution_clock::now();
}
break;
default: