Add port direction again

simplify port numbering again by using 0->max_ports for bot input ports
and output ports. This means we need to tall what direction the port is.
Add port_info serialize functions
Copy metadata and data when we are not sharing buffers.
Make pinossink work again.
This commit is contained in:
Wim Taymans 2016-10-03 19:43:42 +02:00
parent b208e8b690
commit d828073bb8
26 changed files with 1104 additions and 648 deletions

View file

@ -237,6 +237,7 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
g_debug ("link %p: doing negotiate format", this);
again:
if ((res = spa_node_port_enum_formats (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
&filter,
NULL,
@ -253,6 +254,7 @@ again:
spa_debug_format (filter);
if ((res = spa_node_port_enum_formats (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
&format,
filter,
@ -273,6 +275,7 @@ again:
} else if (in_state == SPA_NODE_STATE_CONFIGURE && out_state > SPA_NODE_STATE_CONFIGURE) {
/* only input needs format */
if ((res = spa_node_port_get_format (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
(const SpaFormat **)&format)) < 0) {
g_set_error (&error,
@ -284,6 +287,7 @@ again:
} else if (out_state == SPA_NODE_STATE_CONFIGURE && in_state > SPA_NODE_STATE_CONFIGURE) {
/* only output needs format */
if ((res = spa_node_port_get_format (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
(const SpaFormat **)&format)) < 0) {
g_set_error (&error,
@ -301,6 +305,7 @@ again:
if (out_state == SPA_NODE_STATE_CONFIGURE) {
g_debug ("link %p: doing set format on output", this);
if ((res = spa_node_port_set_format (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
SPA_PORT_FORMAT_FLAG_NEAREST,
format)) < 0) {
@ -313,6 +318,7 @@ again:
} else if (in_state == SPA_NODE_STATE_CONFIGURE) {
g_debug ("link %p: doing set format on input", this);
if ((res = spa_node_port_set_format (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
SPA_PORT_FORMAT_FLAG_NEAREST,
format)) < 0) {
@ -360,14 +366,20 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
g_debug ("link %p: doing alloc buffers %p %p", this, this->output->node, this->input->node);
/* find out what's possible */
if ((res = spa_node_port_get_info (this->output->node->node, this->output->port, &oinfo)) < 0) {
if ((res = spa_node_port_get_info (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
&oinfo)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,
"error get output port info: %d", res);
goto error;
}
if ((res = spa_node_port_get_info (this->input->node->node, this->input->port, &iinfo)) < 0) {
if ((res = spa_node_port_get_info (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
&iinfo)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,
@ -421,16 +433,20 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
if (priv->buffers == NULL) {
SpaAllocParamBuffers *in_alloc, *out_alloc;
guint max_buffers = MAX_BUFFERS;
guint max_buffers = MAX_BUFFERS, min_size = 4096;
gboolean alloc_data = TRUE;
max_buffers = MAX_BUFFERS;
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
if (in_alloc)
if (in_alloc) {
max_buffers = in_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (in_alloc->max_buffers, max_buffers);
min_size = SPA_MAX (min_size, in_alloc->minsize);
}
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
if (out_alloc)
if (out_alloc) {
max_buffers = out_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (out_alloc->max_buffers, max_buffers);
min_size = SPA_MAX (min_size, out_alloc->minsize);
}
if ((in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) ||
(out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS))
@ -445,23 +461,29 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
g_debug ("reusing %d output buffers %p", priv->n_buffers, priv->buffers);
} else {
guint i;
size_t hdr_size;
size_t hdr_size, data_size, buf_size;
void *p;
spa_alloc_params_get_header_size (oinfo->params, oinfo->n_params, 1, &hdr_size);
if (alloc_data)
data_size = min_size;
else
data_size = 0;
buf_size = hdr_size + data_size;
priv->n_buffers = max_buffers;
pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD |
PINOS_MEMBLOCK_FLAG_MAP_READWRITE |
PINOS_MEMBLOCK_FLAG_SEAL,
priv->n_buffers * (sizeof (SpaBuffer*) + hdr_size),
priv->n_buffers * (sizeof (SpaBuffer*) + buf_size),
&priv->buffer_mem);
priv->buffers = p = priv->buffer_mem.ptr;
p = SPA_MEMBER (p, priv->n_buffers * sizeof (SpaBuffer*), void);
for (i = 0; i < priv->n_buffers; i++)
priv->buffers[i] = SPA_MEMBER (p, hdr_size * i, SpaBuffer);
priv->buffers[i] = SPA_MEMBER (p, buf_size * i, SpaBuffer);
if ((res = spa_buffer_init_headers (oinfo->params,
oinfo->n_params,
@ -474,12 +496,25 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
"error buffer alloc: %d", res);
goto error;
}
for (i = 0; i < priv->n_buffers; i++) {
SpaData *d = &priv->buffers[i]->datas[0];
g_debug (" buffers %p %d", priv->buffers[i], priv->buffers[i]->id);
d->type = SPA_DATA_TYPE_MEMPTR;
d->data = SPA_MEMBER (priv->buffers[i], hdr_size, void);
d->size = data_size;
d->maxsize = data_size;
d->offset = 0;
d->stride = 0;
}
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,
if ((res = spa_node_port_alloc_buffers (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
oinfo->params, oinfo->n_params,
priv->buffers, &priv->n_buffers)) < 0) {
g_set_error (&error,
@ -496,7 +531,9 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
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,
if ((res = spa_node_port_alloc_buffers (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
iinfo->params, iinfo->n_params,
priv->buffers, &priv->n_buffers)) < 0) {
g_set_error (&error,
@ -516,8 +553,11 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_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,
priv->buffers, priv->n_buffers)) < 0) {
if ((res = spa_node_port_use_buffers (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
priv->buffers,
priv->n_buffers)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,
@ -530,8 +570,11 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
}
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_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,
priv->buffers, priv->n_buffers)) < 0) {
if ((res = spa_node_port_use_buffers (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
priv->buffers,
priv->n_buffers)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,