From e5ac60b2b230f37934384147fdee2fb6ce7b3e40 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 14 Dec 2022 12:27:33 +0100 Subject: [PATCH] alsa: increase target for a52 and dca For encoded format, we need to send bigger chunks to make the encoder happy. Add a new min_delay variable with this info so that we never leave less than that amount of samples in the ringbuffer. Fixes #2650 --- spa/plugins/alsa/alsa-pcm.c | 13 ++++++++++--- spa/plugins/alsa/alsa-pcm.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 177a2f763..76fe433b8 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1583,11 +1583,18 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ if (is_batch) state->headroom += period_size; + if (spa_strstartswith(state->props.device, "a52") || + spa_strstartswith(state->props.device, "dca")) + state->min_delay = SPA_MIN(2048u, state->buffer_frames); + else + state->min_delay = 0; + state->headroom = SPA_MIN(state->headroom, state->buffer_frames); state->start_delay = state->default_start_delay; - state->latency[state->port_direction].min_rate = state->headroom; - state->latency[state->port_direction].max_rate = state->headroom; + state->latency[state->port_direction].min_rate = + state->latency[state->port_direction].max_rate = + SPA_MAX(state->min_delay, state->headroom); spa_log_info(state->log, "%s (%s): format:%s access:%s-%s rate:%d channels:%d " "buffer frames %lu, period frames %lu, periods %u, frame_size %zd " @@ -1859,7 +1866,7 @@ static int get_status(struct state *state, uint64_t current_time, *delay = avail; *target = SPA_MAX(*target, state->read_size); } - *target = SPA_MIN(*target, state->buffer_frames); + *target = SPA_CLAMP(*target, state->min_delay, state->buffer_frames); return 0; } diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index c630de3ac..9c4a86862 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -197,6 +197,7 @@ struct state { uint32_t last_threshold; uint32_t headroom; uint32_t start_delay; + uint32_t min_delay; uint32_t duration; unsigned int alsa_started:1;