From 48416b32ad14b2e406346be8b93fa2fa6a0e5f94 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 9 Jan 2025 11:30:02 +0100 Subject: [PATCH] audioconvert: improve Buffer params Make sure we only make the buffer for the follower larger when we downsample because then we need to ask for more data from the follower to fill up a quantum. Never try to make the follower buffer smaller than the quantum limit. The reason is that the graph rate could be decreased dynamically and then we would end up with too small buffers. See #4490 --- spa/plugins/audioconvert/audioconvert.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 6d91c3576..f24dc6207 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -2527,29 +2527,30 @@ impl_node_port_enum_params(void *object, int seq, if (result.index > 0) return 0; - if (PORT_IS_DSP(this, direction, port_id)) { - /* DSP ports always use the quantum_limit as the buffer - * size. */ - size = this->quantum_limit; - } else { + size = this->quantum_limit; + + if (!PORT_IS_DSP(this, direction, port_id)) { uint32_t irate, orate; struct dir *dir = &this->dir[direction]; /* Convert ports are scaled so that they can always - * provide one quantum of data */ + * provide one quantum of data. irate is the rate of the + * data before it goes into the resampler. */ irate = dir->format.info.raw.rate; + /* scale the size for adaptive resampling */ + size += size/2; - /* collect the other port rate */ + /* collect the other port rate. This is the output of the resampler + * and is usually one quantum. */ dir = &this->dir[SPA_DIRECTION_REVERSE(direction)]; if (dir->mode == SPA_PARAM_PORT_CONFIG_MODE_dsp) - orate = this->io_position ? this->io_position->clock.target_rate.denom : DEFAULT_RATE; + orate = this->io_position ? this->io_position->clock.target_rate.denom : DEFAULT_RATE; else orate = dir->format.info.raw.rate; - /* always keep some extra room for adaptive resampling */ - size = this->quantum_limit * 2; - /* scale the buffer size when we can. */ - if (irate != 0 && orate != 0) + /* scale the buffer size when we can. Only do this when we downsample because + * then we need to ask more input data for one quantum. */ + if (irate != 0 && orate != 0 && irate > orate) size = SPA_SCALE32_UP(size, irate, orate); }