summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2017-04-17 19:36:22 +0200
committerWim Taymans <wtaymans@redhat.com>2017-04-17 19:36:22 +0200
commitc7333c46cc8fc3913cc2777ed7f58bd3469092cf (patch)
tree9dc6623527514e1a25f925abdb8047b04b021be0
parentbe528ba7c2a8ede730d927398f9b4a6d3535ff3c (diff)
types: remap ids
Remap ids between client and server
-rw-r--r--pinos/client/context.c2
-rw-r--r--pinos/client/map.h3
-rw-r--r--pinos/client/protocol-native.c5
-rw-r--r--pinos/client/type.c59
-rw-r--r--pinos/client/type.h8
-rw-r--r--pinos/daemon/pinos.conf.in1
-rw-r--r--pinos/modules/module-flatpak.c1
-rw-r--r--pinos/server/core.c2
-rw-r--r--pinos/server/node.c1
-rw-r--r--pinos/server/protocol-native.c3
10 files changed, 82 insertions, 3 deletions
diff --git a/pinos/client/context.c b/pinos/client/context.c
index bd31ec4b..ce90fb1a 100644
--- a/pinos/client/context.c
+++ b/pinos/client/context.c
@@ -172,7 +172,7 @@ core_event_update_types (void *object,
for (i = 0; i < n_types; i++, first_id++) {
SpaType this_id = spa_type_map_get_id (this->type.map, types[i]);
- if (!pinos_map_insert_at (&this->types, first_id, SPA_UINT32_TO_PTR (this_id)))
+ if (!pinos_map_insert_at (&this->types, first_id, PINOS_MAP_ID_TO_PTR (this_id)))
pinos_log_error ("can't add type for client");
}
}
diff --git a/pinos/client/map.h b/pinos/client/map.h
index 8913ddf6..47669c33 100644
--- a/pinos/client/map.h
+++ b/pinos/client/map.h
@@ -53,6 +53,9 @@ struct _PinosMap {
#define pinos_map_has_item(m,id) (pinos_map_check_id(m,id) && !pinos_map_id_is_free(m, id))
#define pinos_map_lookup_unchecked(m,id) pinos_map_get_item(m,id)->data
+#define PINOS_MAP_ID_TO_PTR(id) (SPA_UINT32_TO_PTR((id)<<1))
+#define PINOS_MAP_PTR_TO_ID(p) (SPA_PTR_TO_UINT32(p)>>1)
+
static inline void
pinos_map_init (PinosMap *map,
size_t size,
diff --git a/pinos/client/protocol-native.c b/pinos/client/protocol-native.c
index 97614eaa..739d3625 100644
--- a/pinos/client/protocol-native.c
+++ b/pinos/client/protocol-native.c
@@ -400,6 +400,7 @@ node_demarshal_info (void *object,
int i;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &info.id,
SPA_POD_TYPE_LONG, &info.change_mask,
@@ -599,6 +600,7 @@ client_node_demarshal_event (void *object,
const SpaEvent *event;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_OBJECT, &event,
0))
@@ -661,6 +663,7 @@ client_node_demarshal_set_format (void *object,
const SpaFormat *format = NULL;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &seq,
SPA_POD_TYPE_INT, &direction,
@@ -816,6 +819,7 @@ client_node_demarshal_node_command (void *object,
uint32_t seq;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &seq,
SPA_POD_TYPE_OBJECT, &command,
@@ -837,6 +841,7 @@ client_node_demarshal_port_command (void *object,
uint32_t port_id;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &proxy->context->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &port_id,
SPA_POD_TYPE_OBJECT, &command,
diff --git a/pinos/client/type.c b/pinos/client/type.c
index 5c396b79..079d2d75 100644
--- a/pinos/client/type.c
+++ b/pinos/client/type.c
@@ -56,3 +56,62 @@ pinos_type_init (PinosType *type)
spa_type_alloc_param_meta_enable_map (type->map, &type->alloc_param_meta_enable);
spa_type_alloc_param_video_padding_map (type->map, &type->alloc_param_video_padding);
}
+
+bool
+pinos_pod_remap_data (uint32_t type, void * body, uint32_t size, PinosMap *types)
+{
+ void *t;
+ switch (type) {
+ case SPA_POD_TYPE_ID:
+ if ((t = pinos_map_lookup (types, *(int32_t*)body)) == NULL)
+ return false;
+ *(int32_t*)body = PINOS_MAP_PTR_TO_ID (t);
+ break;
+
+ case SPA_POD_TYPE_PROP:
+ {
+ SpaPODPropBody *b = body;
+
+ if ((t = pinos_map_lookup (types, b->key)) == NULL)
+ return false;
+ b->key = PINOS_MAP_PTR_TO_ID (t);
+
+ if (b->value.type == SPA_POD_TYPE_ID) {
+ void *alt;
+ if (!pinos_pod_remap_data (b->value.type, SPA_POD_BODY (&b->value), b->value.size, types))
+ return false;
+
+ SPA_POD_PROP_ALTERNATIVE_FOREACH (b, size, alt)
+ if (!pinos_pod_remap_data (b->value.type, alt, b->value.size, types))
+ return false;
+ }
+ break;
+ }
+ case SPA_POD_TYPE_OBJECT:
+ {
+ SpaPODObjectBody *b = body;
+ SpaPOD *p;
+
+ if ((t = pinos_map_lookup (types, b->type)) == NULL)
+ return false;
+ b->type = PINOS_MAP_PTR_TO_ID (t);
+
+ SPA_POD_OBJECT_BODY_FOREACH (b, size, p)
+ if (!pinos_pod_remap_data (p->type, SPA_POD_BODY (p), p->size, types))
+ return false;
+ break;
+ }
+ case SPA_POD_TYPE_STRUCT:
+ {
+ SpaPOD *b = body, *p;
+
+ SPA_POD_FOREACH (b, size, p)
+ if (!pinos_pod_remap_data (p->type, SPA_POD_BODY (p), p->size, types))
+ return false;
+ break;
+ }
+ default:
+ break;
+ }
+ return true;
+}
diff --git a/pinos/client/type.h b/pinos/client/type.h
index 1e19ff08..8d0e8570 100644
--- a/pinos/client/type.h
+++ b/pinos/client/type.h
@@ -64,6 +64,14 @@ struct _PinosType {
void pinos_type_init (PinosType *type);
+bool pinos_pod_remap_data (uint32_t type, void *body, uint32_t size, PinosMap *types);
+
+static inline bool
+pinos_pod_remap (SpaPOD *pod, PinosMap *types)
+{
+ return pinos_pod_remap_data (pod->type, SPA_POD_BODY (pod), pod->size, types);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/pinos/daemon/pinos.conf.in b/pinos/daemon/pinos.conf.in
index 0a562022..41d79692 100644
--- a/pinos/daemon/pinos.conf.in
+++ b/pinos/daemon/pinos.conf.in
@@ -3,4 +3,5 @@ load-module libpinos-module-protocol-native
load-module libpinos-module-suspend-on-idle
load-module libpinos-module-spa --pattern snow
load-module libpinos-module-autolink
+#load-module libpinos-module-mixer
load-module libpinos-module-flatpak
diff --git a/pinos/modules/module-flatpak.c b/pinos/modules/module-flatpak.c
index e596523c..10620278 100644
--- a/pinos/modules/module-flatpak.c
+++ b/pinos/modules/module-flatpak.c
@@ -650,7 +650,6 @@ wakeup_main (void *userdata)
true);
}
-
static ModuleImpl *
module_new (PinosCore *core,
PinosProperties *properties)
diff --git a/pinos/server/core.c b/pinos/server/core.c
index a2f7e46b..04bee397 100644
--- a/pinos/server/core.c
+++ b/pinos/server/core.c
@@ -311,7 +311,7 @@ core_update_types (void *object,
for (i = 0; i < n_types; i++, first_id++) {
uint32_t this_id = spa_type_map_get_id (this->type.map, types[i]);
- if (!pinos_map_insert_at (&client->types, first_id, SPA_UINT32_TO_PTR (this_id)))
+ if (!pinos_map_insert_at (&client->types, first_id, PINOS_MAP_ID_TO_PTR (this_id)))
pinos_log_error ("can't add type for client");
}
}
diff --git a/pinos/server/node.c b/pinos/server/node.c
index 7e5024a9..f3ce85c8 100644
--- a/pinos/server/node.c
+++ b/pinos/server/node.c
@@ -282,6 +282,7 @@ do_pull (PinosNode *this)
/* pull */
*po = *pi;
+ pi->buffer_id = SPA_ID_INVALID;
pinos_log_trace ("node %p: process output %p %d", outport->node, po, po->buffer_id);
diff --git a/pinos/server/protocol-native.c b/pinos/server/protocol-native.c
index 36cfb982..1ffe515e 100644
--- a/pinos/server/protocol-native.c
+++ b/pinos/server/protocol-native.c
@@ -807,6 +807,7 @@ client_node_demarshal_update (void *object,
const SpaProps *props;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &change_mask,
SPA_POD_TYPE_INT, &max_input_ports,
@@ -833,6 +834,7 @@ client_node_demarshal_port_update (void *object,
SpaPOD *ipod;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) ||
!spa_pod_iter_get (&it,
SPA_POD_TYPE_INT, &direction,
SPA_POD_TYPE_INT, &port_id,
@@ -908,6 +910,7 @@ client_node_demarshal_event (void *object,
SpaEvent *event;
if (!spa_pod_iter_struct (&it, data, size) ||
+ !pinos_pod_remap_data (SPA_POD_TYPE_STRUCT, data, size, &resource->client->types) ||
!spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &event, 0))
return false;