From 563ea1a5e7523522e2d5effd32d17716422c6657 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:57:45 +0200 Subject: [PATCH] Add workaround for obs_source_set_sync_offset() Calling obs_source_set_sync_offset() once with the desired value has no effect. The function needs to be called multiple times with different values in hopes of the sync offset being changed successfully. See https://github.com/obsproject/obs-studio/issues/7912 --- plugins/base/macro-action-audio.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/base/macro-action-audio.cpp b/plugins/base/macro-action-audio.cpp index ef0cf36a..fab8383b 100644 --- a/plugins/base/macro-action-audio.cpp +++ b/plugins/base/macro-action-audio.cpp @@ -4,6 +4,8 @@ #include "macro-helpers.hpp" #include "selection-helpers.hpp" +#include + namespace advss { constexpr int64_t nsPerMs = 1000000; @@ -231,6 +233,18 @@ static void setMixerEnable(obs_source_t *source, const int mixerIdx, obs_source_set_audio_mixers(source, new_mixers); } +static void setSyncOffsetHelper(obs_source_t *source, int64_t value) +{ + // Workaround for this issue: + // https://github.com/obsproject/obs-studio/issues/7912 + using namespace std::chrono_literals; + obs_source_set_sync_offset(source, value - 2); + std::this_thread::sleep_for(10ms); + obs_source_set_sync_offset(source, value - 1); + std::this_thread::sleep_for(10ms); + obs_source_set_sync_offset(source, value); +} + bool MacroActionAudio::PerformAction() { auto s = obs_weak_source_get_source(_audioSource.GetSource()); @@ -250,7 +264,7 @@ bool MacroActionAudio::PerformAction() } break; case Action::SYNC_OFFSET: - obs_source_set_sync_offset(s, _syncOffset * nsPerMs); + setSyncOffsetHelper(s, _syncOffset * nsPerMs); break; case Action::MONITOR: obs_source_set_monitoring_type(s, _monitorType);