mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
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:
parent
50ce9a794f
commit
1637013401
2 changed files with 28 additions and 6 deletions
|
|
@ -181,7 +181,8 @@ struct impl {
|
||||||
|
|
||||||
struct spa_latency_info latency[2];
|
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)
|
#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 impl *this = object;
|
||||||
struct port *port;
|
struct port *port;
|
||||||
uint32_t i, j;
|
uint32_t i, j, maxsize;
|
||||||
|
|
||||||
spa_return_val_if_fail(this != NULL, -EINVAL);
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
||||||
|
|
||||||
|
|
@ -1238,6 +1239,7 @@ impl_node_port_use_buffers(void *object,
|
||||||
|
|
||||||
clear_buffers(this, port);
|
clear_buffers(this, port);
|
||||||
|
|
||||||
|
maxsize = 0;
|
||||||
for (i = 0; i < n_buffers; i++) {
|
for (i = 0; i < n_buffers; i++) {
|
||||||
struct buffer *b;
|
struct buffer *b;
|
||||||
uint32_t n_datas = buffers[i]->n_datas;
|
uint32_t n_datas = buffers[i]->n_datas;
|
||||||
|
|
@ -1268,11 +1270,19 @@ impl_node_port_use_buffers(void *object,
|
||||||
if (direction == SPA_DIRECTION_OUTPUT &&
|
if (direction == SPA_DIRECTION_OUTPUT &&
|
||||||
!SPA_FLAG_IS_SET(d[j].flags, SPA_DATA_FLAG_DYNAMIC))
|
!SPA_FLAG_IS_SET(d[j].flags, SPA_DATA_FLAG_DYNAMIC))
|
||||||
this->is_passthrough = false;
|
this->is_passthrough = false;
|
||||||
}
|
|
||||||
|
|
||||||
|
maxsize = SPA_MAX(maxsize, d[j].maxsize);
|
||||||
|
}
|
||||||
if (direction == SPA_DIRECTION_OUTPUT)
|
if (direction == SPA_DIRECTION_OUTPUT)
|
||||||
queue_buffer(this, port, i);
|
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;
|
port->n_buffers = n_buffers;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1530,6 +1540,7 @@ static int impl_clear(struct spa_handle *handle)
|
||||||
free(this->in_ports[i]);
|
free(this->in_ports[i]);
|
||||||
for (i = 0; i < MAX_PORTS+1; i++)
|
for (i = 0; i < MAX_PORTS+1; i++)
|
||||||
free(this->out_ports[i]);
|
free(this->out_ports[i]);
|
||||||
|
free(this->empty);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,8 @@ struct impl {
|
||||||
uint32_t src_remap[SPA_AUDIO_MAX_CHANNELS];
|
uint32_t src_remap[SPA_AUDIO_MAX_CHANNELS];
|
||||||
uint32_t dst_remap[SPA_AUDIO_MAX_CHANNELS];
|
uint32_t dst_remap[SPA_AUDIO_MAX_CHANNELS];
|
||||||
|
|
||||||
float empty[MAX_SAMPLES + MAX_ALIGN];
|
uint32_t empty_size;
|
||||||
|
float *empty;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHECK_OUT_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < this->port_count)
|
#define CHECK_OUT_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < this->port_count)
|
||||||
|
|
@ -884,7 +885,7 @@ impl_node_port_use_buffers(void *object,
|
||||||
{
|
{
|
||||||
struct impl *this = object;
|
struct impl *this = object;
|
||||||
struct port *port;
|
struct port *port;
|
||||||
uint32_t i, j;
|
uint32_t i, j, maxsize;
|
||||||
|
|
||||||
spa_return_val_if_fail(this != NULL, -EINVAL);
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
||||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||||
|
|
@ -897,6 +898,7 @@ impl_node_port_use_buffers(void *object,
|
||||||
|
|
||||||
clear_buffers(this, port);
|
clear_buffers(this, port);
|
||||||
|
|
||||||
|
maxsize = 0;
|
||||||
for (i = 0; i < n_buffers; i++) {
|
for (i = 0; i < n_buffers; i++) {
|
||||||
struct buffer *b;
|
struct buffer *b;
|
||||||
uint32_t n_datas = buffers[i]->n_datas;
|
uint32_t n_datas = buffers[i]->n_datas;
|
||||||
|
|
@ -924,11 +926,19 @@ impl_node_port_use_buffers(void *object,
|
||||||
|
|
||||||
spa_log_debug(this->log, "%p: buffer %d data %d flags:%08x %p",
|
spa_log_debug(this->log, "%p: buffer %d data %d flags:%08x %p",
|
||||||
this, i, j, d[j].flags, b->datas[j]);
|
this, i, j, d[j].flags, b->datas[j]);
|
||||||
}
|
|
||||||
|
|
||||||
|
maxsize = SPA_MAX(maxsize, d[j].maxsize);
|
||||||
|
}
|
||||||
if (direction == SPA_DIRECTION_OUTPUT)
|
if (direction == SPA_DIRECTION_OUTPUT)
|
||||||
queue_buffer(this, port, i);
|
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;
|
port->n_buffers = n_buffers;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1119,6 +1129,7 @@ static int impl_clear(struct spa_handle *handle)
|
||||||
|
|
||||||
for (i = 0; i < MAX_PORTS; i++)
|
for (i = 0; i < MAX_PORTS; i++)
|
||||||
free(this->out_ports[i]);
|
free(this->out_ports[i]);
|
||||||
|
free(this->empty);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue