From 63d2102594e1404961fef9232d5f8022b66db2f8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 27 May 2022 21:20:51 +0200 Subject: [PATCH] alsa: do resync based on current measurements Call update time with the currently measured delay and then resync when needed. Previously we would do the resync in the next cycle. See #2257 --- spa/plugins/alsa/alsa-pcm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 61101f34d..165833d4f 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1902,6 +1902,9 @@ int spa_alsa_write(struct state *state) if (SPA_UNLIKELY((res = get_status(state, current_time, &delay, &target)) < 0)) return res; + if (SPA_UNLIKELY((res = update_time(state, current_time, delay, target, true)) < 0)) + return res; + if (SPA_UNLIKELY(state->alsa_sync)) { if (SPA_UNLIKELY(state->alsa_sync_warning)) { spa_log_warn(state->log, "%s: follower delay:%ld target:%ld thr:%u, resync", @@ -1918,8 +1921,6 @@ int spa_alsa_write(struct state *state) delay = target; state->alsa_sync = false; } - if (SPA_UNLIKELY((res = update_time(state, current_time, delay, target, true)) < 0)) - return res; } total_written = 0; @@ -2146,6 +2147,9 @@ int spa_alsa_read(struct state *state) avail = delay; + if (SPA_UNLIKELY((res = update_time(state, current_time, delay, target, true)) < 0)) + return res; + if (state->alsa_sync) { if (SPA_UNLIKELY(state->alsa_sync_warning)) { spa_log_warn(state->log, "%s: follower delay:%lu target:%lu thr:%u, resync", @@ -2163,9 +2167,6 @@ int spa_alsa_read(struct state *state) state->alsa_sync = false; } - if ((res = update_time(state, current_time, delay, target, true)) < 0) - return res; - if (avail < state->read_size) max_read = 0; }