From 001c0a5217597c62dfddfa29ac89f07559fe0ef8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 30 Aug 2019 16:31:51 +0200 Subject: [PATCH] alsa: don't compensate for rate match for very low latencies For very small buffer sizes, don't try to attempt to compensate for the rate matching because we would come dangerously close to the read/write pointers and cause dropouts. Instead this latency should be reported on the ports later. --- spa/plugins/alsa/alsa-utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index 2d58858fa..ec6d1811b 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -612,6 +612,12 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del if (state->rate_match) { state->delay = state->rate_match->delay; state->read_size = state->rate_match->size; + /* We try to compensate for the latency introduced by rate matching + * by moving a little closer to the device read/write pointers. + * Don't try to get closer than 32 samples but instead increase the + * reported latency on the port (TODO). */ + if ((int)state->last_threshold <= state->delay + 32) + state->delay = SPA_MAX(0, (int)state->last_threshold + 32 - state->delay); } if (state->stream == SND_PCM_STREAM_PLAYBACK) @@ -644,8 +650,8 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del else if (state->bw == BW_MED) set_loop(state, BW_MIN); - spa_log_debug(state->log, "slave:%d rate:%f bw:%f thr:%d err:%f (%f %f %f)", - slave, corr, state->bw, state->threshold, + spa_log_debug(state->log, "slave:%d rate:%f bw:%f del:%d thr:%d err:%f (%f %f %f)", + slave, corr, state->bw, state->delay, state->threshold, err, state->z1, state->z2, state->z3); }