diff --git a/src/headers/macro-action-streaming.hpp b/src/headers/macro-action-streaming.hpp index 5147aaec..cf04cef4 100644 --- a/src/headers/macro-action-streaming.hpp +++ b/src/headers/macro-action-streaming.hpp @@ -1,10 +1,10 @@ #pragma once #include "macro-action-edit.hpp" -#include "duration-control.hpp" #include #include #include +#include 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; diff --git a/src/macro-action-streaming.cpp b/src/macro-action-streaming.cpp index b9abda30..8aef172d 100644 --- a/src/macro-action-streaming.cpp +++ b/src/macro-action-streaming.cpp @@ -14,6 +14,17 @@ const static std::map 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::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: