From d43d59ca8a3b7eefb434263888e9dd8d8e3b4af4 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 30 Jan 2016 00:32:40 -0800 Subject: [PATCH] libobs: Remove seamless audio loop handling The seamless audio looping code would erroneously trigger for things that weren't loops, causing the audio data to continually push back and ignore timestamps, thus going out of sync. There does need to be loop handling code, but due to the fact that other things may need to trigger this code, it's best just to clear the audio data and start from a fresh sync point. Unfortunately for the case of loops, this means the window in which audio data loops and video frames loop need to be muted. --- libobs/obs-internal.h | 1 - libobs/obs-source.c | 33 +++++++++++++-------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 9c388e6f6..b4a8d8554 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -540,7 +540,6 @@ struct obs_source { bool audio_pending; bool user_muted; bool muted; - bool resync_audio_with_video; struct obs_source *next_audio_source; struct obs_source **prev_next_audio_source; uint64_t audio_ts; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index dd40ca934..5ce734f59 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1134,33 +1134,28 @@ static void source_output_audio_data(obs_source_t *source, in.timestamp += source->timing_adjust; + pthread_mutex_lock(&source->audio_buf_mutex); + if (source->next_audio_sys_ts_min == in.timestamp) { - if (source->resync_audio_with_video) - source->resync_audio_with_video = false; - else - push_back = true; + push_back = true; } else if (source->next_audio_sys_ts_min) { diff = uint64_diff(source->next_audio_sys_ts_min, in.timestamp); if (diff < TS_SMOOTHING_THRESHOLD) { - if (source->resync_audio_with_video) - source->resync_audio_with_video = false; - else - push_back = true; - - /* This only happens if used with async video when audio/video - * start transitioning in to a timestamp jump. Audio will - * typically have a timestamp jump, and then video will have a - * timestamp jump. It's important to not just push back the - * next non-reset audio data after this happens, as that will - * be the video re-syncing. */ + push_back = true; + + /* This typically only happens if used with async video when + * audio/video start transitioning in to a timestamp jump. + * Audio will typically have a timestamp jump, and then video + * will have a timestamp jump. If that case is encountered, + * just clear the audio data in that small window and force a + * resync. This handles all cases rather than just looping. */ } else if (in.timestamp < source->next_audio_sys_ts_min || diff > MAX_TS_VAR) { reset_audio_timing(source, data->timestamp, - source->next_audio_sys_ts_min); - push_back = true; - source->resync_audio_with_video = true; + os_time); + reset_audio_data(source, os_time); in.timestamp = data->timestamp + source->timing_adjust; } } @@ -1178,8 +1173,6 @@ static void source_output_audio_data(obs_source_t *source, source->last_sync_offset = sync_offset; } - pthread_mutex_lock(&source->audio_buf_mutex); - if (push_back) source_output_audio_push_back(source, &in); else -- GitLab