audioconvert: allocate empty space dynamically

Based on the max buffer size so that we don't need to preallocate and
can addapt to larger buffer sizes.
This commit is contained in:
Wim Taymans 2022-01-12 17:25:59 +01:00
parent 50ce9a794f
commit 1637013401
2 changed files with 28 additions and 6 deletions

View file

@ -181,7 +181,8 @@ struct impl {
struct spa_latency_info latency[2];
float empty[MAX_SAMPLES + MAX_ALIGN];
uint32_t empty_size;
float *empty;
};
#define CHECK_IN_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) < this->port_count)
@ -1223,7 +1224,7 @@ impl_node_port_use_buffers(void *object,
{
struct impl *this = object;
struct port *port;
uint32_t i, j;
uint32_t i, j, maxsize;
spa_return_val_if_fail(this != NULL, -EINVAL);
@ -1238,6 +1239,7 @@ impl_node_port_use_buffers(void *object,
clear_buffers(this, port);
maxsize = 0;
for (i = 0; i < n_buffers; i++) {
struct buffer *b;
uint32_t n_datas = buffers[i]->n_datas;
@ -1268,11 +1270,19 @@ impl_node_port_use_buffers(void *object,
if (direction == SPA_DIRECTION_OUTPUT &&
!SPA_FLAG_IS_SET(d[j].flags, SPA_DATA_FLAG_DYNAMIC))
this->is_passthrough = false;
}
maxsize = SPA_MAX(maxsize, d[j].maxsize);
}
if (direction == SPA_DIRECTION_OUTPUT)
queue_buffer(this, port, i);
}
if (maxsize > this->empty_size) {
this->empty = realloc(this->empty, maxsize + MAX_ALIGN);
if (this->empty == NULL)
return -errno;
memset(this->empty, 0, maxsize + MAX_ALIGN);
this->empty_size = maxsize;
}
port->n_buffers = n_buffers;
return 0;
@ -1530,6 +1540,7 @@ static int impl_clear(struct spa_handle *handle)
free(this->in_ports[i]);
for (i = 0; i < MAX_PORTS+1; i++)
free(this->out_ports[i]);
free(this->empty);
return 0;
}