mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
mem: remove memory stuff
Remove the memory stuff from the spa API, we can do thing more simple and efficiently if we always allocate buffers outside of the plugins and only implement an alloc function on the node when it can do something clever. Move serialize code to the props/format/buffer code Make it possible to copy a format and properties.
This commit is contained in:
parent
fe37e2bc1b
commit
24108e01c1
46 changed files with 901 additions and 1546 deletions
|
|
@ -350,8 +350,6 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
const SpaPortInfo *iinfo, *oinfo;
|
||||
SpaPortInfoFlags in_flags, out_flags;
|
||||
GError *error = NULL;
|
||||
unsigned int max_buffers = MAX_BUFFERS;
|
||||
SpaAllocParamBuffers *in_alloc, *out_alloc;
|
||||
|
||||
if (in_state != SPA_NODE_STATE_READY && out_state != SPA_NODE_STATE_READY)
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -377,14 +375,6 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
in_flags = iinfo->flags;
|
||||
out_flags = oinfo->flags;
|
||||
|
||||
max_buffers = MAX_BUFFERS;
|
||||
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (in_alloc)
|
||||
max_buffers = in_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (in_alloc->max_buffers, max_buffers);
|
||||
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (out_alloc)
|
||||
max_buffers = out_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (out_alloc->max_buffers, max_buffers);
|
||||
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_LIVE) {
|
||||
this->output->node->live = true;
|
||||
this->input->node->live = true;
|
||||
|
|
@ -401,27 +391,8 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else if ((out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) &&
|
||||
(in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
||||
priv->n_buffers = max_buffers;
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
|
||||
if ((res = spa_buffer_alloc (oinfo->params, oinfo->n_params,
|
||||
priv->buffers,
|
||||
&priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error buffer alloc: %d", res);
|
||||
goto error;
|
||||
}
|
||||
priv->allocated = TRUE;
|
||||
memcpy (this->output->buffers, priv->buffers, priv->n_buffers * sizeof (SpaBuffer*));
|
||||
memcpy (this->input->buffers, priv->buffers, priv->n_buffers * sizeof (SpaBuffer*));
|
||||
this->output->n_buffers = priv->n_buffers;
|
||||
this->input->n_buffers = priv->n_buffers;
|
||||
this->output->allocated = FALSE;
|
||||
this->input->allocated = FALSE;
|
||||
g_debug ("allocated %d buffers %p", priv->n_buffers, priv->buffers);
|
||||
} else if ((out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
||||
(in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS)) {
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
|
|
@ -446,38 +417,68 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
spa_debug_port_info (oinfo);
|
||||
spa_debug_port_info (iinfo);
|
||||
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS && this->input->n_buffers == 0) {
|
||||
this->input->n_buffers = max_buffers;
|
||||
if ((res = spa_node_port_alloc_buffers (this->input->node->node, this->input->port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
this->input->buffers, &this->input->n_buffers)) < 0) {
|
||||
if (!priv->allocated) {
|
||||
SpaAllocParamBuffers *in_alloc, *out_alloc;
|
||||
guint max_buffers = MAX_BUFFERS;
|
||||
SpaBufferAllocFlags flags = 0;
|
||||
|
||||
max_buffers = MAX_BUFFERS;
|
||||
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (in_alloc)
|
||||
max_buffers = in_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (in_alloc->max_buffers, max_buffers);
|
||||
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (out_alloc)
|
||||
max_buffers = out_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (out_alloc->max_buffers, max_buffers);
|
||||
|
||||
if ((in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) ||
|
||||
(out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS))
|
||||
flags |= SPA_BUFFER_ALLOC_FLAG_NO_MEM;
|
||||
|
||||
priv->n_buffers = max_buffers;
|
||||
if ((res = spa_buffer_alloc (flags,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->buffers,
|
||||
&priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc input buffers: %d", res);
|
||||
"error buffer alloc: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->input->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from input port", this->input->n_buffers, this->input->buffers);
|
||||
}
|
||||
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS && this->output->n_buffers == 0) {
|
||||
this->output->n_buffers = max_buffers;
|
||||
if ((res = spa_node_port_alloc_buffers (this->output->node->node, this->output->port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
this->output->buffers, &this->output->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc output buffers: %d", res);
|
||||
goto error;
|
||||
g_debug ("allocated %d buffers %p", priv->n_buffers, priv->buffers);
|
||||
priv->allocated = TRUE;
|
||||
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (this->input->node->node, this->input->port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->buffers, &priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc input buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->input->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from input port", priv->n_buffers, priv->buffers);
|
||||
}
|
||||
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (this->output->node->node, this->output->port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
priv->buffers, &priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc output buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->output->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from output port", priv->n_buffers, priv->buffers);
|
||||
}
|
||||
this->output->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from output port", this->output->n_buffers, this->output->buffers);
|
||||
}
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
g_debug ("using output buffers %p on input port", this->output->buffers);
|
||||
g_debug ("using %d buffers %p on input port", priv->n_buffers, priv->buffers);
|
||||
if ((res = spa_node_port_use_buffers (this->input->node->node, this->input->port,
|
||||
this->output->buffers, this->output->n_buffers)) < 0) {
|
||||
priv->buffers, priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
|
|
@ -487,9 +488,9 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
this->input->allocated = FALSE;
|
||||
}
|
||||
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
g_debug ("using %d in_buffers %p on output port", this->input->n_buffers, this->input->buffers);
|
||||
g_debug ("using %d buffers %p on output port", priv->n_buffers, priv->buffers);
|
||||
if ((res = spa_node_port_use_buffers (this->output->node->node, this->output->port,
|
||||
this->input->buffers, this->input->n_buffers)) < 0) {
|
||||
priv->buffers, priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue