diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index d4a2cf3fb..2d62384fb 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -48,7 +48,7 @@ static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.resample"); #define DEFAULT_RATE 48000 #define DEFAULT_CHANNELS 2 -#define MAX_SAMPLES 8192 +#define MAX_SAMPLES 8192u #define MAX_ALIGN 16 #define MAX_BUFFERS 32 @@ -477,20 +477,26 @@ impl_node_port_enum_params(void *object, int seq, case SPA_PARAM_Buffers: { uint32_t buffers, size; + uint32_t rate; - if (!port->have_format) + if (!port->have_format || !other->have_format) return -EIO; if (result.index > 0) return 0; + if (direction == SPA_DIRECTION_OUTPUT) { + rate = (this->resample.o_rate + this->resample.i_rate - 1) / this->resample.i_rate; + } else { + rate = (this->resample.i_rate + this->resample.o_rate - 1) / this->resample.o_rate; + } if (other->n_buffers > 0) { buffers = other->n_buffers; - size = other->size / other->stride * 2; - } - else { + size = (other->size / other->stride) * rate; + } else { buffers = 1; - size = MAX_SAMPLES*2 * other->stride; + size = MAX_SAMPLES * rate; } + size = SPA_MAX(size, MAX_SAMPLES) * 2; param = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id,