From 21392d898e72550e7a8b7015749696d7de6894b6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 31 Aug 2023 14:28:56 +0200 Subject: [PATCH] alsa: improve xrun clock field calculation We're missing the delay in samples plus all of the extra samples of silence we use to restart the device. This is in the samplerate of the device. Convert this to the time domain of the graph before adding it to xrun. --- spa/plugins/alsa/alsa-pcm.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index dd764c1ae..e8899266f 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1945,16 +1945,15 @@ static int alsa_recover(struct state *state, int err) delay = SPA_TIMEVAL_TO_USEC(&diff); missing = delay * state->rate / SPA_USEC_PER_SEC; - if (missing == 0) - missing = state->threshold; + missing += state->start_delay + state->threshold + state->headroom; spa_log_trace(state->log, "%p: xrun of %"PRIu64" usec %"PRIu64, state, delay, missing); - if (state->clock) - state->clock->xrun += missing; - state->sample_count += missing; - + if (state->clock) { + state->clock->xrun += SPA_SCALE32_UP(missing, + state->clock->rate.denom, state->rate); + } spa_node_call_xrun(&state->callbacks, SPA_TIMEVAL_TO_USEC(&trigger), delay, NULL); break;