From 03518891c83023080dfe60754525acd72fc32193 Mon Sep 17 00:00:00 2001 From: floele Date: Mon, 21 Feb 2022 22:29:12 +0100 Subject: [PATCH] libobs: Fix corruption of audio data in audio_input_buf Previously, source->next_audio_ts_min was incremented by conv_frames_to_time(sample_rate, in.frames) in each call of source_output_audio_data(), so only by the duration of the audio data itself. However, this does not take the current timestamp into account, which also includes execution time (audio source timestamps are not necessarily continuous). This causes the incoming audio timestamp to gradually deviate further from the expected next_audio_ts_min timestamp, eventually exceeding TS_SMOOTHING_THRESHOLD and then causing a call to source_output_audio_place() which either overwrites existing audio data and causes a glitch or puts data beyond the end of the buffer, inserting a gap and thus causing a dropout. Now use incoming timestamp for calculation of the next minimum timestamp. --- libobs/obs-source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index fb36660e1..86f63ed50 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1482,7 +1482,7 @@ static void source_output_audio_data(obs_source_t *source, source->last_audio_ts = in.timestamp; source->next_audio_ts_min = - in.timestamp + conv_frames_to_time(sample_rate, in.frames); + data->timestamp + conv_frames_to_time(sample_rate, in.frames); in.timestamp += source->timing_adjust;