Make AllocParams into POD objects

Make allocparams into pod objects. This makes it easy to serialize,
copy, create and intersect them.
Add convenience macros for properties
Add helper function to collect object properties.
This commit is contained in:
Wim Taymans 2017-03-17 11:58:09 +01:00
parent b1f7df52e3
commit 8a6ce3b179
34 changed files with 948 additions and 1054 deletions

View file

@ -19,8 +19,9 @@
#include <string.h>
#include <spa/include/spa/video/format.h>
#include <spa/lib/debug.h>
#include <spa/include/spa/video/format.h>
#include <spa/include/spa/pod-utils.h>
#include "pinos/client/pinos.h"
#include "pinos/client/interfaces.h"
@ -145,7 +146,7 @@ find_param (const SpaPortInfo *info, SpaAllocParamType type)
uint32_t i;
for (i = 0; i < info->n_params; i++) {
if (info->params[i]->type == type)
if (spa_pod_is_object_type (&info->params[i]->pod, type))
return info->params[i];
}
return NULL;
@ -157,9 +158,15 @@ find_meta_enable (const SpaPortInfo *info, SpaMetaType type)
uint32_t i;
for (i = 0; i < info->n_params; i++) {
if (info->params[i]->type == SPA_ALLOC_PARAM_TYPE_META_ENABLE &&
((SpaAllocParamMetaEnable*)info->params[i])->type == type) {
return info->params[i];
if (spa_pod_is_object_type (&info->params[i]->pod, SPA_ALLOC_PARAM_TYPE_META_ENABLE)) {
uint32_t qtype;
if (spa_alloc_param_query (info->params[i],
SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, &qtype, 0) != 1)
continue;
if (qtype == type)
return info->params[i];
}
}
return NULL;
@ -201,11 +208,16 @@ alloc_buffers (PinosLink *this,
for (i = 0; i < n_params; i++) {
SpaAllocParam *ap = params[i];
if (ap->type == SPA_ALLOC_PARAM_TYPE_META_ENABLE) {
SpaAllocParamMetaEnable *pme = (SpaAllocParamMetaEnable *) ap;
if (ap->pod.type == SPA_ALLOC_PARAM_TYPE_META_ENABLE) {
uint32_t type;
metas[n_metas].type = pme->type;
metas[n_metas].size = spa_meta_type_get_size (pme->type);
if (spa_alloc_param_query (ap,
SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, &type,
0) != 1)
continue;
metas[n_metas].type = type;
metas[n_metas].size = spa_meta_type_get_size (type);
meta_size += metas[n_metas].size;
n_metas++;
skel_size += sizeof (SpaMeta);
@ -380,33 +392,60 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
return SPA_RESULT_OK;
if (impl->buffers == NULL) {
SpaAllocParamBuffers *in_alloc, *out_alloc;
SpaAllocParamMetaEnableRingbuffer *in_me, *out_me;
SpaAllocParam *in_alloc, *out_alloc;
SpaAllocParam *in_me, *out_me;
uint32_t max_buffers;
size_t minsize, stride, blocks;
size_t minsize = 1024, stride = 0;
in_me = find_meta_enable (iinfo, SPA_META_TYPE_RINGBUFFER);
out_me = find_meta_enable (oinfo, SPA_META_TYPE_RINGBUFFER);
if (in_me && out_me) {
uint32_t ms1, ms2, s1, s2;
max_buffers = 1;
minsize = SPA_MAX (out_me->minsize, in_me->minsize);
stride = SPA_MAX (out_me->stride, in_me->stride);
blocks = SPA_MAX (1, SPA_MAX (out_me->blocks, in_me->blocks));
if (spa_alloc_param_query (in_me,
SPA_ALLOC_PARAM_META_ENABLE_RB_SIZE, SPA_POD_TYPE_INT, &ms1,
SPA_ALLOC_PARAM_META_ENABLE_RB_STRIDE, SPA_POD_TYPE_INT, &s1, 0) == 2 &&
spa_alloc_param_query (in_me,
SPA_ALLOC_PARAM_META_ENABLE_RB_SIZE, SPA_POD_TYPE_INT, &ms2,
SPA_ALLOC_PARAM_META_ENABLE_RB_STRIDE, SPA_POD_TYPE_INT, &s2, 0) == 2) {
minsize = SPA_MAX (ms1, ms2);
stride = SPA_MAX (s1, s2);
}
} else {
max_buffers = MAX_BUFFERS;
minsize = stride = 0;
blocks = 1;
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);
minsize = SPA_MAX (minsize, in_alloc->minsize);
stride = SPA_MAX (stride, in_alloc->stride);
uint32_t qmax_buffers = max_buffers,
qminsize = minsize,
qstride = stride;
spa_alloc_param_query (in_alloc,
SPA_ALLOC_PARAM_BUFFERS_SIZE, SPA_POD_TYPE_INT, &qminsize,
SPA_ALLOC_PARAM_BUFFERS_STRIDE, SPA_POD_TYPE_INT, &qstride,
SPA_ALLOC_PARAM_BUFFERS_BUFFERS, SPA_POD_TYPE_INT, &qmax_buffers,
0);
max_buffers = qmax_buffers == 0 ? max_buffers : SPA_MIN (qmax_buffers, max_buffers);
minsize = SPA_MAX (minsize, qminsize);
stride = SPA_MAX (stride, qstride);
}
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);
minsize = SPA_MAX (minsize, out_alloc->minsize);
stride = SPA_MAX (stride, out_alloc->stride);
uint32_t qmax_buffers = max_buffers,
qminsize = minsize,
qstride = stride;
spa_alloc_param_query (out_alloc,
SPA_ALLOC_PARAM_BUFFERS_SIZE, SPA_POD_TYPE_INT, &qminsize,
SPA_ALLOC_PARAM_BUFFERS_STRIDE, SPA_POD_TYPE_INT, &qstride,
SPA_ALLOC_PARAM_BUFFERS_BUFFERS, SPA_POD_TYPE_INT, &qmax_buffers,
0);
max_buffers = qmax_buffers == 0 ? max_buffers : SPA_MIN (qmax_buffers, max_buffers);
minsize = SPA_MAX (minsize, qminsize);
stride = SPA_MAX (stride, qstride);
}
}

View file

@ -115,10 +115,8 @@ core_marshal_done (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, seq,
-SPA_POD_TYPE_STRUCT, &f, 0);
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq);
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
}
@ -142,12 +140,10 @@ core_marshal_error (void *object,
vsnprintf (buffer, sizeof (buffer), error, ap);
va_end (ap);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_INT, res,
SPA_POD_TYPE_STRING, buffer,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_STRING, buffer);
pinos_connection_end_write (connection, resource->id, 2, b.b.offset);
}
@ -163,10 +159,8 @@ core_marshal_remove_id (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, id,
-SPA_POD_TYPE_STRUCT, &f, 0);
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, id);
pinos_connection_end_write (connection, resource->id, 3, b.b.offset);
}
@ -377,11 +371,9 @@ registry_marshal_global (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_STRING, type,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_STRING, type);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
}
@ -397,10 +389,8 @@ registry_marshal_global_remove (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, id,
-SPA_POD_TYPE_STRUCT, &f, 0);
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, id);
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
}
@ -549,10 +539,8 @@ client_node_marshal_done (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, datafd),
-SPA_POD_TYPE_STRUCT, &f, 0);
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, datafd));
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
}
@ -568,10 +556,8 @@ client_node_marshal_event (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_POD, event,
-SPA_POD_TYPE_STRUCT, &f, 0);
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_POD, event);
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
}
@ -589,12 +575,10 @@ client_node_marshal_add_port (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_INT, port_id);
pinos_connection_end_write (connection, resource->id, 2, b.b.offset);
}
@ -612,12 +596,10 @@ client_node_marshal_remove_port (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_INT, port_id);
pinos_connection_end_write (connection, resource->id, 3, b.b.offset);
}
@ -665,12 +647,10 @@ client_node_marshal_set_property (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_BYTES, value, size,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_BYTES, value, size);
pinos_connection_end_write (connection, resource->id, 5, b.b.offset);
}
@ -693,8 +673,7 @@ client_node_marshal_add_mem (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id,
SPA_POD_TYPE_INT, mem_id,
@ -702,8 +681,7 @@ client_node_marshal_add_mem (void *object,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, memfd),
SPA_POD_TYPE_INT, flags,
SPA_POD_TYPE_INT, offset,
SPA_POD_TYPE_INT, size,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_INT, size);
pinos_connection_end_write (connection, resource->id, 6, b.b.offset);
}
@ -775,11 +753,9 @@ client_node_marshal_node_command (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_POD, command,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_POD, command);
pinos_connection_end_write (connection, resource->id, 8, b.b.offset);
}
@ -796,11 +772,9 @@ client_node_marshal_port_command (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, port_id,
SPA_POD_TYPE_POD, command,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_POD, command);
pinos_connection_end_write (connection, resource->id, 9, b.b.offset);
}
@ -818,12 +792,10 @@ client_node_marshal_transport (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, memfd),
SPA_POD_TYPE_INT, offset,
SPA_POD_TYPE_INT, size,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_INT, size);
pinos_connection_end_write (connection, resource->id, 10, b.b.offset);
}
@ -861,7 +833,7 @@ client_node_demarshal_port_update (void *object,
{
PinosResource *resource = object;
SpaPODIter it;
uint32_t i, t, direction, port_id, change_mask, n_possible_formats, sz;
uint32_t i, t, direction, port_id, change_mask, n_possible_formats;
const SpaProps *props = NULL;
const SpaFormat **possible_formats = NULL, *format = NULL;
SpaPortInfo info, *infop = NULL;
@ -905,7 +877,7 @@ client_node_demarshal_port_update (void *object,
info.params = alloca (info.n_params * sizeof (SpaAllocParam *));
for (i = 0; i < info.n_params; i++)
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_BYTES, &info.params[i], &sz, 0))
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &info.params[i], 0))
return false;
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &dict.n_items, 0))
@ -994,15 +966,13 @@ link_marshal_info (void *object,
core_update_map (resource->client);
spa_pod_builder_add (&b.b,
SPA_POD_TYPE_STRUCT, &f,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, info->id,
SPA_POD_TYPE_LONG, info->change_mask,
SPA_POD_TYPE_INT, info->output_node_id,
SPA_POD_TYPE_INT, info->output_port_id,
SPA_POD_TYPE_INT, info->input_node_id,
SPA_POD_TYPE_INT, info->input_port_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
SPA_POD_TYPE_INT, info->input_port_id);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
}