diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 5e2b26383..6da75c049 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -1597,6 +1597,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ if (is_batch) state->headroom += period_size; + state->max_delay = state->buffer_frames / 2; if (spa_strstartswith(state->props.device, "a52") || spa_strstartswith(state->props.device, "dca")) state->min_delay = SPA_MIN(2048u, state->buffer_frames); @@ -1608,7 +1609,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ state->latency[state->port_direction].min_rate = state->latency[state->port_direction].max_rate = - SPA_MAX(state->min_delay, state->headroom); + SPA_MAX(state->min_delay, SPA_MIN(state->max_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 " @@ -1882,7 +1883,7 @@ static int get_status(struct state *state, uint64_t current_time, if (state->matching) *target += 32; } - *target = SPA_CLAMP(*target, state->min_delay, state->buffer_frames); + *target = SPA_CLAMP(*target, state->min_delay, state->max_delay); return 0; } diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h index 3ac9f1fe3..7017d3a6d 100644 --- a/spa/plugins/alsa/alsa-pcm.h +++ b/spa/plugins/alsa/alsa-pcm.h @@ -178,6 +178,7 @@ struct state { uint32_t headroom; uint32_t start_delay; uint32_t min_delay; + uint32_t max_delay; uint32_t duration; unsigned int alsa_started:1;