mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
Reorganize serialization code a bit
Move the proxy plugin to the client-node Move serialization code to pinos because its specific to pinos Move some functions to the .h files Make the mapper dynamic
This commit is contained in:
parent
8520246a1b
commit
d8903b708d
25 changed files with 1950 additions and 3858 deletions
113
spa/lib/buffer.c
113
spa/lib/buffer.c
|
|
@ -1,113 +0,0 @@
|
|||
/* 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/buffer.h>
|
||||
#include <spa/port.h>
|
||||
|
||||
static const size_t header_sizes[] = {
|
||||
0,
|
||||
sizeof (SpaMetaHeader),
|
||||
sizeof (SpaMetaPointer),
|
||||
sizeof (SpaMetaVideoCrop),
|
||||
sizeof (SpaMetaRingbuffer),
|
||||
};
|
||||
|
||||
size_t
|
||||
spa_meta_type_get_size (SpaMetaType type)
|
||||
{
|
||||
if (type <= 0 || type >= SPA_N_ELEMENTS (header_sizes))
|
||||
return 0;
|
||||
|
||||
return header_sizes[type];
|
||||
}
|
||||
|
||||
size_t
|
||||
spa_buffer_get_size (const SpaBuffer *buffer)
|
||||
{
|
||||
size_t size;
|
||||
unsigned int i;
|
||||
|
||||
if (buffer == NULL)
|
||||
return 0;
|
||||
|
||||
size = sizeof (SpaBuffer);
|
||||
for (i = 0; i < buffer->n_metas; i++)
|
||||
size += sizeof (SpaMeta) + buffer->metas[i].size;
|
||||
for (i = 0; i < buffer->n_datas; i++)
|
||||
size += sizeof (SpaData);
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t
|
||||
spa_buffer_serialize (void *dest, const SpaBuffer *buffer)
|
||||
{
|
||||
SpaBuffer *tb;
|
||||
SpaMeta *mp;
|
||||
SpaData *dp;
|
||||
void *p;
|
||||
unsigned int i;
|
||||
|
||||
if (buffer == NULL)
|
||||
return 0;
|
||||
|
||||
tb = dest;
|
||||
memcpy (tb, buffer, sizeof (SpaBuffer));
|
||||
mp = SPA_MEMBER (tb, sizeof(SpaBuffer), SpaMeta);
|
||||
dp = SPA_MEMBER (mp, sizeof(SpaMeta) * tb->n_metas, SpaData);
|
||||
p = SPA_MEMBER (dp, sizeof(SpaData) * tb->n_datas, void);
|
||||
|
||||
tb->metas = SPA_INT_TO_PTR (SPA_PTRDIFF (mp, tb));
|
||||
tb->datas = SPA_INT_TO_PTR (SPA_PTRDIFF (dp, tb));
|
||||
|
||||
for (i = 0; i < tb->n_metas; i++) {
|
||||
memcpy (&mp[i], &buffer->metas[i], sizeof (SpaMeta));
|
||||
memcpy (p, mp[i].data, mp[i].size);
|
||||
mp[i].data = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tb));
|
||||
p += mp[i].size;
|
||||
}
|
||||
for (i = 0; i < tb->n_datas; i++)
|
||||
memcpy (&dp[i], &buffer->datas[i], sizeof (SpaData));
|
||||
|
||||
return SPA_PTRDIFF (p, tb);
|
||||
}
|
||||
|
||||
SpaBuffer *
|
||||
spa_buffer_deserialize (void *src, off_t offset)
|
||||
{
|
||||
SpaBuffer *b;
|
||||
unsigned int i;
|
||||
|
||||
b = SPA_MEMBER (src, offset, SpaBuffer);
|
||||
if (b->metas)
|
||||
b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
|
||||
for (i = 0; i < b->n_metas; i++) {
|
||||
SpaMeta *m = &b->metas[i];
|
||||
if (m->data)
|
||||
m->data = SPA_MEMBER (b, SPA_PTR_TO_INT (m->data), void);
|
||||
}
|
||||
if (b->datas)
|
||||
b->datas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->datas), SpaData);
|
||||
|
||||
return b;
|
||||
}
|
||||
1198
spa/lib/control.c
1198
spa/lib/control.c
File diff suppressed because it is too large
Load diff
|
|
@ -1,87 +0,0 @@
|
|||
/* 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/format.h>
|
||||
#include <spa/debug.h>
|
||||
|
||||
|
||||
SpaResult
|
||||
spa_format_fixate (SpaFormat *format)
|
||||
{
|
||||
if (format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
format->props.unset_mask = 0;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
size_t
|
||||
spa_format_get_size (const SpaFormat *format)
|
||||
{
|
||||
if (format == NULL)
|
||||
return 0;
|
||||
|
||||
return spa_props_get_size (&format->props) - sizeof (SpaProps) + sizeof (SpaFormat);
|
||||
}
|
||||
|
||||
size_t
|
||||
spa_format_serialize (void *dest, const SpaFormat *format)
|
||||
{
|
||||
SpaFormat *tf;
|
||||
size_t size;
|
||||
|
||||
if (format == NULL)
|
||||
return 0;
|
||||
|
||||
tf = dest;
|
||||
tf->media_type = format->media_type;
|
||||
tf->media_subtype = format->media_subtype;
|
||||
|
||||
dest = SPA_MEMBER (tf, offsetof (SpaFormat, props), void);
|
||||
size = spa_props_serialize (dest, &format->props) - sizeof (SpaProps) + sizeof (SpaFormat);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
SpaFormat *
|
||||
spa_format_deserialize (void *src, off_t offset)
|
||||
{
|
||||
SpaFormat *f;
|
||||
|
||||
f = SPA_MEMBER (src, offset, SpaFormat);
|
||||
spa_props_deserialize (f, offsetof (SpaFormat, props));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
SpaFormat *
|
||||
spa_format_copy_into (void *dest, const SpaFormat *format)
|
||||
{
|
||||
if (format == NULL)
|
||||
return NULL;
|
||||
|
||||
spa_format_serialize (dest, format);
|
||||
return spa_format_deserialize (dest, 0);
|
||||
}
|
||||
|
|
@ -38,54 +38,53 @@
|
|||
#include <spa/ringbuffer.h>
|
||||
#include <spa/debug.h>
|
||||
|
||||
static const char *uris[] = {
|
||||
NULL,
|
||||
SPA_ID_MAP_URI,
|
||||
SPA_LOG_URI,
|
||||
SPA_BUFFER_URI,
|
||||
SPA_CLOCK_URI,
|
||||
SPA_MONITOR_URI,
|
||||
SPA_NODE_URI,
|
||||
SPA_NODE_COMMAND_URI,
|
||||
SPA_NODE_EVENT_URI,
|
||||
SPA_ALLOC_PARAM_URI,
|
||||
SPA_PROPS_URI,
|
||||
SPA_QUEUE_URI,
|
||||
SPA_RINGBUFFER_URI,
|
||||
SPA_POLL__MainLoop,
|
||||
SPA_POLL__DataLoop,
|
||||
};
|
||||
#define MAX_URIS 4096
|
||||
|
||||
typedef struct {
|
||||
SpaIDMap map;
|
||||
char *uris[MAX_URIS];
|
||||
unsigned int n_uris;
|
||||
} IDMap;
|
||||
|
||||
static uint32_t
|
||||
id_map_get_id (SpaIDMap *map, const char *uri)
|
||||
{
|
||||
IDMap *this = SPA_CONTAINER_OF (map, IDMap, map);
|
||||
unsigned int i = 0;
|
||||
|
||||
if (uri != NULL) {
|
||||
unsigned int i;
|
||||
for (i = 1; i < SPA_N_ELEMENTS (uris); i++) {
|
||||
if (strcmp (uris[i], uri) == 0)
|
||||
for (i = 1; i <= this->n_uris; i++) {
|
||||
if (strcmp (this->uris[i], uri) == 0)
|
||||
return i;
|
||||
}
|
||||
this->uris[i] = (char *)uri;
|
||||
this->n_uris++;
|
||||
}
|
||||
return 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
static const char *
|
||||
id_map_get_uri (SpaIDMap *map, uint32_t id)
|
||||
{
|
||||
if (id < SPA_N_ELEMENTS (uris))
|
||||
return uris[id];
|
||||
IDMap *this = SPA_CONTAINER_OF (map, IDMap, map);
|
||||
|
||||
if (id < this->n_uris)
|
||||
return this->uris[id];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SpaIDMap default_map = {
|
||||
sizeof (SpaIDMap),
|
||||
NULL,
|
||||
id_map_get_id,
|
||||
id_map_get_uri,
|
||||
static IDMap default_id_map = {
|
||||
{ sizeof (SpaIDMap),
|
||||
NULL,
|
||||
id_map_get_id,
|
||||
id_map_get_uri,
|
||||
},
|
||||
{ NULL, },
|
||||
0
|
||||
};
|
||||
|
||||
SpaIDMap *
|
||||
spa_id_map_get_default (void)
|
||||
{
|
||||
return (SpaIDMap *) &default_map;
|
||||
return &default_id_map.map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
spalib_sources = ['audio-raw.c',
|
||||
'buffer.c',
|
||||
'control.c',
|
||||
'debug.c',
|
||||
'format.c',
|
||||
'mapper.c',
|
||||
'port.c',
|
||||
'props.c',
|
||||
'video-raw.c']
|
||||
|
||||
|
|
|
|||
101
spa/lib/port.c
101
spa/lib/port.c
|
|
@ -1,101 +0,0 @@
|
|||
/* 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->extra = 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);
|
||||
}
|
||||
140
spa/lib/props.c
140
spa/lib/props.c
|
|
@ -102,143 +102,3 @@ spa_props_copy_values (const SpaProps *src,
|
|||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
size_t
|
||||
spa_props_get_size (const SpaProps *props)
|
||||
{
|
||||
size_t len;
|
||||
unsigned int i, j;
|
||||
SpaPropInfo *pi;
|
||||
SpaPropRangeInfo *ri;
|
||||
|
||||
if (props == NULL)
|
||||
return 0;
|
||||
|
||||
len = sizeof (SpaProps);
|
||||
for (i = 0; i < props->n_prop_info; i++) {
|
||||
pi = (SpaPropInfo *) &props->prop_info[i];
|
||||
len += sizeof (SpaPropInfo);
|
||||
len += pi->name ? strlen (pi->name) + 1 : 0;
|
||||
/* for the value */
|
||||
len += pi->maxsize;
|
||||
for (j = 0; j < pi->n_range_values; j++) {
|
||||
ri = (SpaPropRangeInfo *)&pi->range_values[j];
|
||||
len += sizeof (SpaPropRangeInfo);
|
||||
len += ri->name ? strlen (ri->name) + 1 : 0;
|
||||
/* the size of the range value */
|
||||
len += ri->val.size;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t
|
||||
spa_props_serialize (void *p, const SpaProps *props)
|
||||
{
|
||||
size_t len, slen;
|
||||
unsigned int i, j, c;
|
||||
SpaProps *tp;
|
||||
SpaPropInfo *pi;
|
||||
SpaPropRangeInfo *ri;
|
||||
|
||||
if (props == NULL)
|
||||
return 0;
|
||||
|
||||
tp = p;
|
||||
memcpy (tp, props, sizeof (SpaProps));
|
||||
pi = SPA_MEMBER (tp, sizeof(SpaProps), SpaPropInfo);
|
||||
ri = SPA_MEMBER (pi, sizeof(SpaPropInfo) * tp->n_prop_info, SpaPropRangeInfo);
|
||||
|
||||
tp->prop_info = SPA_INT_TO_PTR (SPA_PTRDIFF (pi, tp));
|
||||
|
||||
/* write propinfo array */
|
||||
for (i = 0, c = 0; i < tp->n_prop_info; i++) {
|
||||
memcpy (&pi[i], &props->prop_info[i], sizeof (SpaPropInfo));
|
||||
pi[i].range_values = SPA_INT_TO_PTR (SPA_PTRDIFF (&ri[c], tp));
|
||||
for (j = 0; j < pi[i].n_range_values; j++, c++) {
|
||||
memcpy (&ri[c], &props->prop_info[i].range_values[j], sizeof (SpaPropRangeInfo));
|
||||
}
|
||||
}
|
||||
p = &ri[c];
|
||||
/* strings and default values from props and ranges */
|
||||
for (i = 0, c = 0; i < tp->n_prop_info; i++) {
|
||||
if (pi[i].name) {
|
||||
slen = strlen (pi[i].name) + 1;
|
||||
memcpy (p, pi[i].name, slen);
|
||||
pi[i].name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
|
||||
p += slen;
|
||||
} else {
|
||||
pi[i].name = 0;
|
||||
}
|
||||
for (j = 0; j < pi[i].n_range_values; j++, c++) {
|
||||
if (ri[c].name) {
|
||||
slen = strlen (ri[c].name) + 1;
|
||||
memcpy (p, ri[c].name, slen);
|
||||
ri[c].name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
|
||||
p += slen;
|
||||
} else {
|
||||
ri[c].name = 0;
|
||||
}
|
||||
if (ri[c].val.size) {
|
||||
memcpy (p, ri[c].val.value, ri[c].val.size);
|
||||
ri[c].val.value = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
|
||||
p += ri[c].val.size;
|
||||
} else {
|
||||
ri[c].val.value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* and the actual values */
|
||||
for (i = 0; i < tp->n_prop_info; i++) {
|
||||
if (pi[i].offset) {
|
||||
memcpy (p, SPA_MEMBER (props, pi[i].offset, void), pi[i].maxsize);
|
||||
pi[i].offset = SPA_PTRDIFF (p, tp);
|
||||
p += pi[i].maxsize;
|
||||
} else {
|
||||
pi[i].offset = 0;
|
||||
}
|
||||
}
|
||||
len = SPA_PTRDIFF (p, tp);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
SpaProps *
|
||||
spa_props_deserialize (void *p, off_t offset)
|
||||
{
|
||||
SpaProps *tp;
|
||||
unsigned int i, j;
|
||||
SpaPropInfo *pi;
|
||||
SpaPropRangeInfo *ri;
|
||||
|
||||
tp = SPA_MEMBER (p, offset, SpaProps);
|
||||
if (tp->prop_info)
|
||||
tp->prop_info = SPA_MEMBER (tp, SPA_PTR_TO_INT (tp->prop_info), SpaPropInfo);
|
||||
/* now fix all the pointers */
|
||||
for (i = 0; i < tp->n_prop_info; i++) {
|
||||
pi = (SpaPropInfo *) &tp->prop_info[i];
|
||||
if (pi->name)
|
||||
pi->name = SPA_MEMBER (tp, SPA_PTR_TO_INT (pi->name), char);
|
||||
if (pi->range_values)
|
||||
pi->range_values = SPA_MEMBER (tp, SPA_PTR_TO_INT (pi->range_values), SpaPropRangeInfo);
|
||||
|
||||
for (j = 0; j < pi->n_range_values; j++) {
|
||||
ri = (SpaPropRangeInfo *) &pi->range_values[j];
|
||||
if (ri->name)
|
||||
ri->name = SPA_MEMBER (tp, SPA_PTR_TO_INT (ri->name), char);
|
||||
if (ri->val.value)
|
||||
ri->val.value = SPA_MEMBER (tp, SPA_PTR_TO_INT (ri->val.value), void);
|
||||
}
|
||||
}
|
||||
return tp;
|
||||
}
|
||||
|
||||
SpaProps *
|
||||
spa_props_copy_into (void *dest, const SpaProps *props)
|
||||
{
|
||||
if (props == NULL)
|
||||
return NULL;
|
||||
|
||||
spa_props_serialize (dest, props);
|
||||
return spa_props_deserialize (dest, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue