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

@ -369,20 +369,10 @@ iter_parse_port_update (struct stack_iter *si, SpaControlCmdPortUpdate *pu)
}
if (pu->format)
pu->format = spa_format_deserialize (p, SPA_PTR_TO_INT (pu->format));
if (pu->props)
pu->props = spa_props_deserialize (p, SPA_PTR_TO_INT (pu->props));
if (pu->info) {
SpaPortInfo *pi;
pu->info = p = SPA_MEMBER (p, SPA_PTR_TO_INT (pu->info), SpaPortInfo);
pi = (SpaPortInfo *) pu->info;
pi->params = SPA_MEMBER (p, SPA_PTR_TO_INT (pi->params), SpaAllocParam *);
for (i = 0; i < pi->n_params; i++) {
pi->params[i] = SPA_MEMBER (p, SPA_PTR_TO_INT (pi->params[i]), SpaAllocParam);
}
}
if (pu->info)
pu->info = spa_port_info_deserialize (p, SPA_PTR_TO_INT (pu->info));
}
static void
@ -759,39 +749,6 @@ builder_add_cmd (struct stack_builder *sb, SpaControlCmd cmd, size_t size)
return p;
}
static size_t
write_port_info (void *p, const SpaPortInfo *info)
{
SpaPortInfo *tp;
SpaAllocParam **ap;
int i;
size_t len;
if (info == NULL)
return 0;
tp = p;
memcpy (tp, info, sizeof (SpaPortInfo));
p = SPA_MEMBER (tp, sizeof (SpaPortInfo), SpaAllocParam *);
ap = p;
if (info->n_params)
tp->params = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
else
tp->params = 0;
tp->features = 0;
p = SPA_MEMBER (p, sizeof (SpaAllocParam*) * info->n_params, void);
for (i = 0; i < info->n_params; i++) {
len = info->params[i]->size;
memcpy (p, info->params[i], len);
ap[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p = SPA_MEMBER (p, len, void);
}
return SPA_PTRDIFF (p, tp);
}
static void
builder_add_node_update (struct stack_builder *sb, SpaControlCmdNodeUpdate *nu)
{
@ -833,12 +790,8 @@ builder_add_port_update (struct stack_builder *sb, SpaControlCmdPortUpdate *pu)
}
len += spa_format_get_size (pu->format);
len += spa_props_get_size (pu->props);
if (pu->info) {
len += sizeof (SpaPortInfo);
len += pu->info->n_params * sizeof (SpaAllocParam *);
for (i = 0; i < pu->info->n_params; i++)
len += pu->info->params[i]->size;
}
if (pu->info)
len += spa_port_info_get_size (pu->info);
p = builder_add_cmd (sb, SPA_CONTROL_CMD_PORT_UPDATE, len);
memcpy (p, pu, sizeof (SpaControlCmdPortUpdate));
@ -873,7 +826,7 @@ builder_add_port_update (struct stack_builder *sb, SpaControlCmdPortUpdate *pu)
d->props = 0;
}
if (pu->info) {
len = write_port_info (p, pu->info);
len = spa_port_info_serialize (p, pu->info);
d->info = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
p = SPA_MEMBER (p, len, void);
} else {

View file

@ -3,6 +3,7 @@ spalib_sources = ['audio-raw.c',
'control.c',
'debug.c',
'format.c',
'port.c',
'props.c',
'ringbuffer.c',
'video-raw.c']

101
spa/lib/port.c Normal file
View file

@ -0,0 +1,101 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <spa/port.h>
#include <spa/debug.h>
size_t
spa_port_info_get_size (const SpaPortInfo *info)
{
size_t len;
unsigned int i;
if (info == NULL)
return 0;
len = sizeof (SpaPortInfo);
len += info->n_params * sizeof (SpaAllocParam *);
for (i = 0; i < info->n_params; i++)
len += info->params[i]->size;
return len;
}
size_t
spa_port_info_serialize (void *p, const SpaPortInfo *info)
{
SpaPortInfo *pi;
SpaAllocParam **ap;
int i;
size_t len;
if (info == NULL)
return 0;
pi = p;
memcpy (pi, info, sizeof (SpaPortInfo));
ap = SPA_MEMBER (pi, sizeof (SpaPortInfo), SpaAllocParam *);
if (info->n_params)
pi->params = SPA_INT_TO_PTR (SPA_PTRDIFF (ap, pi));
else
pi->params = 0;
pi->features = 0;
p = SPA_MEMBER (ap, sizeof (SpaAllocParam*) * info->n_params, void);
for (i = 0; i < info->n_params; i++) {
len = info->params[i]->size;
memcpy (p, info->params[i], len);
ap[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, pi));
p = SPA_MEMBER (p, len, void);
}
return SPA_PTRDIFF (p, pi);
}
SpaPortInfo *
spa_port_info_deserialize (void *p, off_t offset)
{
SpaPortInfo *pi;
unsigned int i;
pi = SPA_MEMBER (p, offset, SpaPortInfo);
if (pi->params)
pi->params = SPA_MEMBER (pi, SPA_PTR_TO_INT (pi->params), SpaAllocParam *);
for (i = 0; i < pi->n_params; i++) {
pi->params[i] = SPA_MEMBER (pi, SPA_PTR_TO_INT (pi->params[i]), SpaAllocParam);
}
return pi;
}
SpaPortInfo *
spa_port_info_copy_into (void *dest, const SpaPortInfo *info)
{
if (info == NULL)
return NULL;
spa_port_info_serialize (dest, info);
return spa_port_info_deserialize (dest, 0);
}