summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pipewire/link.c110
1 files changed, 57 insertions, 53 deletions
diff --git a/src/pipewire/link.c b/src/pipewire/link.c
index 72fd5014..a5978141 100644
--- a/src/pipewire/link.c
+++ b/src/pipewire/link.c
@@ -484,6 +484,8 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
char *error = NULL;
struct pw_port *input, *output;
struct pw_type *t = &this->core->type;
+ struct spa_buffer **buffers;
+ uint32_t n_buffers;
if (in_state != PW_PORT_STATE_READY && out_state != PW_PORT_STATE_READY)
return 0;
@@ -553,13 +555,35 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
spa_debug_port_info(iinfo);
}
- if (this->buffers == NULL) {
+ if (this->n_buffers) {
+ buffers = this->buffers;
+ n_buffers = this->n_buffers;
+ this->buffer_owner = this;
+ pw_log_debug("link %p: reusing %d link buffers %p", this, n_buffers, buffers);
+ } else if (output->n_buffers) {
+ out_flags = 0;
+ in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
+ n_buffers = output->n_buffers;
+ buffers = output->buffers;
+ this->buffer_owner = input;
+ pw_log_debug("link %p: reusing %d output buffers %p", this, n_buffers, buffers);
+ } else if (input->n_buffers && input->mix == NULL) {
+ out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
+ in_flags = 0;
+ n_buffers = input->n_buffers;
+ buffers = input->buffers;
+ this->buffer_owner = input;
+ pw_log_debug("link %p: reusing %d input buffers %p", this, n_buffers, buffers);
+ } else {
struct spa_pod **params, *param;
uint8_t buffer[4096];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
int i, offset, n_params;
uint32_t max_buffers;
size_t minsize = 1024, stride = 0;
+ size_t data_sizes[1];
+ ssize_t data_strides[1];
+ struct pw_memblock *buffer_mem;
n_params = param_filter(this, input, output, t->param.idBuffers, &b);
n_params += param_filter(this, input, output, t->param.idMeta, &b);
@@ -605,76 +629,62 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
(out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS))
minsize = 0;
- if (output->n_buffers) {
- out_flags = 0;
- in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
- this->n_buffers = output->n_buffers;
- this->buffers = output->buffers;
- this->buffer_owner = output;
- pw_log_debug("link %p: reusing %d output buffers %p", this, this->n_buffers,
- this->buffers);
- } else if (input->n_buffers && input->mix == NULL) {
- out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
- in_flags = 0;
- this->n_buffers = input->n_buffers;
- this->buffers = input->buffers;
- this->buffer_owner = input;
- pw_log_debug("link %p: reusing %d input buffers %p", this, this->n_buffers,
- this->buffers);
- } else {
- size_t data_sizes[1];
- ssize_t data_strides[1];
- data_sizes[0] = minsize;
- data_strides[0] = stride;
+ data_sizes[0] = minsize;
+ data_strides[0] = stride;
- this->buffer_owner = this;
- this->n_buffers = max_buffers;
- this->buffers = alloc_buffers(this,
- this->n_buffers,
- n_params,
- params,
- 1,
- data_sizes, data_strides,
- &this->buffer_mem);
-
- pw_log_debug("link %p: allocating %d buffers %p %zd %zd", this,
- this->n_buffers, this->buffers, minsize, stride);
- }
+ n_buffers = max_buffers;
+ buffers = alloc_buffers(this,
+ n_buffers,
+ n_params,
+ params,
+ 1,
+ data_sizes, data_strides,
+ &buffer_mem);
+
+ pw_log_debug("link %p: allocating %d buffers %p %zd %zd", this,
+ n_buffers, buffers, minsize, stride);
if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
if ((res = pw_port_alloc_buffers(output,
params, n_params,
- this->buffers, &this->n_buffers)) < 0) {
+ buffers, &n_buffers)) < 0) {
asprintf(&error, "error alloc output buffers: %d", res);
goto error;
}
if (SPA_RESULT_IS_ASYNC(res))
pw_work_queue_add(impl->work, output->node, res, complete_paused, output);
- output->buffer_mem = this->buffer_mem;
+ output->buffer_mem = buffer_mem;
this->buffer_owner = output;
pw_log_debug("link %p: allocated %d buffers %p from output port", this,
- this->n_buffers, this->buffers);
+ n_buffers, buffers);
} else if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
if ((res = pw_port_alloc_buffers(input,
params, n_params,
- this->buffers, &this->n_buffers)) < 0) {
+ buffers, &n_buffers)) < 0) {
asprintf(&error, "error alloc input buffers: %d", res);
goto error;
}
if (SPA_RESULT_IS_ASYNC(res))
pw_work_queue_add(impl->work, input->node, res, complete_paused, input);
- input->buffer_mem = this->buffer_mem;
+ input->buffer_mem = buffer_mem;
this->buffer_owner = input;
pw_log_debug("link %p: allocated %d buffers %p from input port", this,
- this->n_buffers, this->buffers);
+ n_buffers, buffers);
+ } else {
+ this->buffer_owner = this;
+ this->buffers = buffers;
+ this->n_buffers = n_buffers;
+ this->buffer_mem = buffer_mem;
+ pw_log_debug("link %p: allocated %d buffers %p from link", this,
+ n_buffers, buffers);
}
}
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
pw_log_debug("link %p: using %d buffers %p on input port", this,
- this->n_buffers, this->buffers);
- if ((res = pw_port_use_buffers(input, this->buffers, this->n_buffers)) < 0) {
+ n_buffers, buffers);
+ if ((res = pw_port_use_buffers(input, buffers, n_buffers)) < 0) {
asprintf(&error, "error use input buffers: %d", res);
goto error;
}
@@ -682,8 +692,8 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
pw_work_queue_add(impl->work, input->node, res, complete_paused, input);
} else if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
pw_log_debug("link %p: using %d buffers %p on output port", this,
- this->n_buffers, this->buffers);
- if ((res = pw_port_use_buffers(output, this->buffers, this->n_buffers)) < 0) {
+ n_buffers, buffers);
+ if ((res = pw_port_use_buffers(output, buffers, n_buffers)) < 0) {
asprintf(&error, "error use output buffers: %d", res);
goto error;
}
@@ -697,12 +707,6 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
return 0;
error:
- output->buffers = NULL;
- output->n_buffers = 0;
- output->allocated = false;
- input->buffers = NULL;
- input->n_buffers = 0;
- input->allocated = false;
pw_link_update_state(this, PW_LINK_STATE_ERROR, error);
return res;
}
@@ -1136,9 +1140,9 @@ struct pw_link *pw_link_new(struct pw_core *core,
spa_list_append(&input->links, &this->input_link);
this->info.output_node_id = output_node->global->id;
- this->info.output_port_id = output->port_id;
+ this->info.output_port_id = output->global->id;
this->info.input_node_id = input_node->global->id;
- this->info.input_port_id = input->port_id;
+ this->info.input_port_id = input->global->id;
this->info.format = NULL;
this->info.props = this->properties ? &this->properties->dict : NULL;