alsa: increase buffers when using small buffer

We can increase the MAX_LATENCY again if we increase the amount of
buffers when we are using a small buffer.

Normally we ask for 4 * quantum-limit as the buffer. This should be good
to use 1 buffer and quantum-limit as the quantum with enough headroom
to not run out of buffers.

If we are however using less buffer-frames we need to be careful and
allocate an extra buffer. Imagine using a buffer of 4096 frames, we can
support a quantum of up to 2048 frames if we use 2 buffers.

See #3744
This commit is contained in:
Wim Taymans 2024-01-22 12:10:51 +01:00
parent c5b845bc90
commit 846f994ac8
2 changed files with 8 additions and 2 deletions

View file

@ -458,14 +458,19 @@ impl_node_port_enum_params(void *object, int seq,
break;
case SPA_PARAM_Buffers:
{
uint32_t min_buffers;
if (!this->have_format)
return -EIO;
if (result.index > 0)
return 0;
min_buffers = (this->quantum_limit * 4 * this->frame_scale) > this->buffer_frames ? 2 : 1;
param = spa_pod_builder_add_object(&b.b,
SPA_TYPE_OBJECT_ParamBuffers, id,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS),
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(min_buffers, min_buffers, MAX_BUFFERS),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(this->blocks),
SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int(
this->quantum_limit * this->frame_size * this->frame_scale,
@ -473,6 +478,7 @@ impl_node_port_enum_params(void *object, int seq,
INT32_MAX),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(this->frame_size));
break;
}
case SPA_PARAM_Meta:
switch (result.index) {

View file

@ -3536,7 +3536,7 @@ void spa_alsa_emit_node_info(struct state *state, bool full)
if (state->have_format)
snprintf(latency, sizeof(latency), "%lu/%d",
state->buffer_frames / (4 * state->frame_scale), state->rate);
state->buffer_frames / (2 * state->frame_scale), state->rate);
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency[0] ? latency : NULL);
if (state->have_format)