From 261fb64849b552f3947782641bc9032345d62fab Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 10 Apr 2023 16:28:55 +0200 Subject: [PATCH] alsa: separate max_error and max_resync Use a separate variable to hold the maximum amount of drift we allow between driver and follower. Ensure this value is smaller than the max_error and period size so that we have at most 1 period of drift. --- spa/plugins/alsa/alsa-pcm.c | 11 +++++++---- spa/plugins/alsa/alsa-pcm.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 793c88054..53407f4b0 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1969,12 +1969,14 @@ static int update_time(struct state *state, uint64_t current_time, snd_pcm_sfram state->alsa_sync = true; state->alsa_sync_warning = false; } - if (err > state->max_error) { - err = state->max_error; + if (err > state->max_resync) { state->alsa_sync = true; - } else if (err < -state->max_error) { - err = -state->max_error; + if (err > state->max_error) + err = state->max_error; + } else if (err < -state->max_resync) { state->alsa_sync = true; + if (err < -state->max_error) + err = -state->max_error; } if (!follower || state->matching) @@ -2079,6 +2081,7 @@ static inline int check_position_config(struct state *state) return -EIO; state->threshold = SPA_SCALE32_UP(state->duration, state->rate, state->rate_denom); state->max_error = SPA_MAX(256.0f, state->threshold / 2.0f); + state->max_resync = SPA_MIN(state->threshold, state->max_error); state->resample = ((uint32_t)state->rate != state->rate_denom) || state->matching; state->alsa_sync = true; } diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index 63a8f8f4f..be8972adb 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -213,6 +213,7 @@ struct state { struct spa_dll dll; double max_error; + double max_resync; struct spa_latency_info latency[2]; struct spa_process_latency_info process_latency;