summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2017-09-28 16:57:16 +0200
committerWim Taymans <wtaymans@redhat.com>2017-09-28 16:57:16 +0200
commitf86541287fac876f4d4d73e42af985e92bd47fdf (patch)
treea89c66e3714f471cf6005f5f38ab2a4b5a9293e4
parentde41c89d021424cf13d2637b8a595a40c6b88d25 (diff)
move type remap to native protocoljson
-rw-r--r--src/modules/module-protocol-native.c63
-rw-r--r--src/pipewire/type.c59
-rw-r--r--src/pipewire/type.h9
3 files changed, 61 insertions, 70 deletions
diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c
index 6824df38..35790a2f 100644
--- a/src/modules/module-protocol-native.c
+++ b/src/modules/module-protocol-native.c
@@ -96,6 +96,65 @@ struct client_data {
bool busy;
};
+static bool pod_remap_data(uint32_t type, void *body, uint32_t size, struct pw_map *types)
+{
+ void *t;
+ switch (type) {
+ case SPA_POD_TYPE_ID:
+ if ((t = pw_map_lookup(types, *(int32_t *) body)) == NULL)
+ return false;
+ *(int32_t *) body = PW_MAP_PTR_TO_ID(t);
+ break;
+
+ case SPA_POD_TYPE_PROP:
+ {
+ struct spa_pod_prop_body *b = body;
+
+ if ((t = pw_map_lookup(types, b->key)) == NULL)
+ return false;
+ b->key = PW_MAP_PTR_TO_ID(t);
+
+ if (b->value.type == SPA_POD_TYPE_ID) {
+ void *alt;
+ if (!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 (!pod_remap_data(b->value.type, alt, b->value.size, types))
+ return false;
+ }
+ break;
+ }
+ case SPA_POD_TYPE_OBJECT:
+ {
+ struct spa_pod_object_body *b = body;
+ struct spa_pod *p;
+
+ if ((t = pw_map_lookup(types, b->type)) == NULL)
+ return false;
+ b->type = PW_MAP_PTR_TO_ID(t);
+
+ SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
+ if (!pod_remap_data(p->type, SPA_POD_BODY(p), p->size, types))
+ return false;
+ break;
+ }
+ case SPA_POD_TYPE_STRUCT:
+ {
+ struct spa_pod *b = body, *p;
+
+ SPA_POD_FOREACH(b, size, p)
+ if (!pod_remap_data(p->type, SPA_POD_BODY(p), p->size, types))
+ return false;
+ break;
+ }
+ default:
+ break;
+ }
+ return true;
+}
+
static void
process_messages(struct client_data *data)
{
@@ -149,7 +208,7 @@ process_messages(struct client_data *data)
}
if (demarshal[opcode].flags & PW_PROTOCOL_NATIVE_REMAP)
- if (!pw_pod_remap_data(SPA_POD_TYPE_STRUCT, message, size, &client->types))
+ if (!pod_remap_data(SPA_POD_TYPE_STRUCT, message, size, &client->types))
goto invalid_message;
if (!demarshal[opcode].func (resource, message, size))
@@ -513,7 +572,7 @@ on_remote_data(void *data, int fd, enum spa_io mask)
}
if (demarshal[opcode].flags & PW_PROTOCOL_NATIVE_REMAP) {
- if (!pw_pod_remap_data(SPA_POD_TYPE_STRUCT, message, size, &this->types)) {
+ if (!pod_remap_data(SPA_POD_TYPE_STRUCT, message, size, &this->types)) {
pw_log_error
("protocol-native %p: invalid message received %u for %u", this,
opcode, id);
diff --git a/src/pipewire/type.c b/src/pipewire/type.c
index f5664d82..7c7ea1dc 100644
--- a/src/pipewire/type.c
+++ b/src/pipewire/type.c
@@ -61,62 +61,3 @@ void pw_type_init(struct pw_type *type)
spa_type_param_alloc_meta_enable_map(type->map, &type->param_alloc_meta_enable);
spa_type_param_alloc_video_padding_map(type->map, &type->param_alloc_video_padding);
}
-
-bool pw_pod_remap_data(uint32_t type, void *body, uint32_t size, struct pw_map *types)
-{
- void *t;
- switch (type) {
- case SPA_POD_TYPE_ID:
- if ((t = pw_map_lookup(types, *(int32_t *) body)) == NULL)
- return false;
- *(int32_t *) body = PW_MAP_PTR_TO_ID(t);
- break;
-
- case SPA_POD_TYPE_PROP:
- {
- struct spa_pod_prop_body *b = body;
-
- if ((t = pw_map_lookup(types, b->key)) == NULL)
- return false;
- b->key = PW_MAP_PTR_TO_ID(t);
-
- if (b->value.type == SPA_POD_TYPE_ID) {
- void *alt;
- if (!pw_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 (!pw_pod_remap_data(b->value.type, alt, b->value.size, types))
- return false;
- }
- break;
- }
- case SPA_POD_TYPE_OBJECT:
- {
- struct spa_pod_object_body *b = body;
- struct spa_pod *p;
-
- if ((t = pw_map_lookup(types, b->type)) == NULL)
- return false;
- b->type = PW_MAP_PTR_TO_ID(t);
-
- SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
- if (!pw_pod_remap_data(p->type, SPA_POD_BODY(p), p->size, types))
- return false;
- break;
- }
- case SPA_POD_TYPE_STRUCT:
- {
- struct spa_pod *b = body, *p;
-
- SPA_POD_FOREACH(b, size, p)
- if (!pw_pod_remap_data(p->type, SPA_POD_BODY(p), p->size, types))
- return false;
- break;
- }
- default:
- break;
- }
- return true;
-}
diff --git a/src/pipewire/type.h b/src/pipewire/type.h
index 77243a7a..2268a7d4 100644
--- a/src/pipewire/type.h
+++ b/src/pipewire/type.h
@@ -76,15 +76,6 @@ struct pw_type {
void
pw_type_init(struct pw_type *type);
-bool
-pw_pod_remap_data(uint32_t type, void *body, uint32_t size, struct pw_map *types);
-
-static inline bool
-pw_pod_remap(struct spa_pod *pod, struct pw_map *types)
-{
- return pw_pod_remap_data(pod->type, SPA_POD_BODY(pod), pod->size, types);
-}
-
#ifdef __cplusplus
}
#endif