From dc4e205008e53fd146595bbfd2b753c51c792c31 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 27 Mar 2017 09:01:13 -0700 Subject: [PATCH] libobs: Delay stop detection of audio source Delay the "audio stopped" detection by one audio tick to ensure that audio doesn't get intentionally cut out in some situations --- libobs/obs-audio.c | 11 +++++++++++ libobs/obs-internal.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libobs/obs-audio.c b/libobs/obs-audio.c index e4932c355..e99f2575b 100644 --- a/libobs/obs-audio.c +++ b/libobs/obs-audio.c @@ -108,10 +108,20 @@ static bool discard_if_stopped(obs_source_t *source, size_t channels) /* if perpetually pending data, it means the audio has stopped, * so clear the audio data */ if (last_size == size) { + if (!source->pending_stop) { + source->pending_stop = true; +#if DEBUG_AUDIO == 1 + blog(LOG_DEBUG, "doing pending stop trick: '%s'", + source->context.name); +#endif + return true; + } + for (size_t ch = 0; ch < channels; ch++) circlebuf_pop_front(&source->audio_input_buf[ch], NULL, source->audio_input_buf[ch].size); + source->pending_stop = false; source->audio_ts = 0; source->last_audio_input_buf_size = 0; #if DEBUG_AUDIO == 1 @@ -212,6 +222,7 @@ static inline void discard_audio(struct obs_core_audio *audio, ts->end); #endif + source->pending_stop = false; source->audio_ts = ts->end; } diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index f6f2450b9..de07ff9f5 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -562,6 +562,7 @@ struct obs_source { /* audio */ bool audio_failed; bool audio_pending; + bool pending_stop; bool user_muted; bool muted; struct obs_source *next_audio_source;