From 3d25e254ef067233cf34a071e83fcdebc70ffda7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 7 Jun 2018 10:23:41 +0200 Subject: [PATCH] client-node: implement node property update Make it possible to update the node properties Make it possible to update the remote properties --- src/extensions/client-node.h | 10 +++--- src/modules/module-client-node/client-node.c | 6 +++- .../module-client-node/protocol-native.c | 30 ++++++++++++++-- src/pipewire/remote.c | 35 ++++++++++++++++++- src/pipewire/remote.h | 3 ++ 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/extensions/client-node.h b/src/extensions/client-node.h index 43bf94b82..c91e3fad0 100644 --- a/src/extensions/client-node.h +++ b/src/extensions/client-node.h @@ -84,11 +84,13 @@ struct pw_client_node_proxy_methods { #define PW_CLIENT_NODE_UPDATE_MAX_INPUTS (1 << 0) #define PW_CLIENT_NODE_UPDATE_MAX_OUTPUTS (1 << 1) #define PW_CLIENT_NODE_UPDATE_PARAMS (1 << 2) +#define PW_CLIENT_NODE_UPDATE_PROPS (1 << 3) uint32_t change_mask, uint32_t max_input_ports, uint32_t max_output_ports, uint32_t n_params, - const struct spa_pod **params); + const struct spa_pod **params, + const struct spa_dict *props); /** * Update a node port @@ -137,13 +139,13 @@ pw_client_node_proxy_update(struct pw_client_node_proxy *p, uint32_t max_input_ports, uint32_t max_output_ports, uint32_t n_params, - const struct spa_pod **params) + const struct spa_pod **params, + const struct spa_dict *props) { pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, update, change_mask, max_input_ports, max_output_ports, - n_params, - params); + n_params, params, props); } static inline void diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index 9f0cb807b..71dfa9f67 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -935,7 +935,8 @@ client_node_update(void *data, uint32_t max_input_ports, uint32_t max_output_ports, uint32_t n_params, - const struct spa_pod **params) + const struct spa_pod **params, + const struct spa_dict *props) { struct impl *impl = data; struct node *this = &impl->node; @@ -956,6 +957,9 @@ client_node_update(void *data, for (i = 0; i < this->n_params; i++) this->params[i] = pw_spa_pod_copy(params[i]); } + if (change_mask & PW_CLIENT_NODE_UPDATE_PROPS) { + pw_node_update_properties(impl->this.node, props); + } spa_log_debug(this->log, "node %p: got node update max_in %u, max_out %u", this, this->max_inputs, this->max_outputs); } diff --git a/src/modules/module-client-node/protocol-native.c b/src/modules/module-client-node/protocol-native.c index a2c3d2ebc..a4aa49090 100644 --- a/src/modules/module-client-node/protocol-native.c +++ b/src/modules/module-client-node/protocol-native.c @@ -51,11 +51,12 @@ client_node_marshal_update(void *object, uint32_t max_input_ports, uint32_t max_output_ports, uint32_t n_params, - const struct spa_pod **params) + const struct spa_pod **params, + const struct spa_dict *props) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; - int i; + int i, n_items; b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_UPDATE); @@ -69,6 +70,13 @@ client_node_marshal_update(void *object, for (i = 0; i < n_params; i++) spa_pod_builder_add(b, "P", params[i], NULL); + n_items = props ? props->n_items : 0; + spa_pod_builder_add(b, "i", n_items, NULL); + for (i = 0; i < n_items; i++) { + spa_pod_builder_add(b, + "s", props->items[i].key, + "s", props->items[i].value, NULL); + } spa_pod_builder_add(b, "]", NULL); pw_protocol_native_end_proxy(proxy, b); @@ -730,6 +738,7 @@ static int client_node_demarshal_update(void *object, void *data, size_t size) struct spa_pod_parser prs; uint32_t change_mask, max_input_ports, max_output_ports, n_params; const struct spa_pod **params; + struct spa_dict props; int i; spa_pod_parser_init(&prs, data, size, 0); @@ -746,11 +755,26 @@ static int client_node_demarshal_update(void *object, void *data, size_t size) if (spa_pod_parser_get(&prs, "O", ¶ms[i], NULL) < 0) return -EINVAL; + if (spa_pod_parser_get(&prs, + "i", &props.n_items, NULL) < 0) + return -EINVAL; + + props.items = alloca(props.n_items * sizeof(struct spa_dict_item)); + for (i = 0; i < props.n_items; i++) { + if (spa_pod_parser_get(&prs, + "s", &props.items[i].key, + "s", &props.items[i].value, + NULL) < 0) + return -EINVAL; + } + pw_resource_do(resource, struct pw_client_node_proxy_methods, update, change_mask, max_input_ports, max_output_ports, n_params, - params); + params, + props.n_items > 0 ? + &props : NULL); return 0; } diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index c82017586..8e89c8737 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -331,6 +331,18 @@ const struct pw_properties *pw_remote_get_properties(struct pw_remote *remote) return remote->properties; } +int pw_remote_update_properties(struct pw_remote *remote, const struct spa_dict *dict) +{ + uint32_t i; + + for (i = 0; i < dict->n_items; i++) + pw_properties_set(remote->properties, dict->items[i].key, dict->items[i].value); + + if (remote->core_proxy) + pw_core_proxy_client_update(remote->core_proxy, &remote->properties->dict); + + return 0; +} void *pw_remote_get_user_data(struct pw_remote *remote) { return remote->user_data; @@ -1256,7 +1268,7 @@ static void do_node_init(struct pw_proxy *proxy) PW_CLIENT_NODE_UPDATE_PARAMS, data->node->info.max_input_ports, data->node->info.max_output_ports, - 0, NULL); + 0, NULL, NULL); spa_list_for_each(port, &data->node->input_ports, link) { add_port_update(proxy, port, @@ -1279,6 +1291,26 @@ static void node_destroy(void *data) pw_proxy_destroy((struct pw_proxy *)d->node_proxy); } +static void node_info_changed(void *data, struct pw_node_info *info) +{ + struct node_data *d = data; + uint32_t change_mask = 0; + + pw_log_debug("info changed %p", d); + + if (info->change_mask & PW_NODE_CHANGE_MASK_ENUM_PARAMS) { + change_mask |= PW_CLIENT_NODE_UPDATE_PARAMS; + } + if (info->change_mask & PW_NODE_CHANGE_MASK_PROPS) { + change_mask |= PW_CLIENT_NODE_UPDATE_PROPS; + } + pw_client_node_proxy_update(d->node_proxy, + change_mask, + 0, 0, + 0, NULL, + info->props); +} + static void node_active_changed(void *data, bool active) { struct node_data *d = data; @@ -1290,6 +1322,7 @@ static void node_active_changed(void *data, bool active) static const struct pw_node_events node_events = { PW_VERSION_NODE_EVENTS, .destroy = node_destroy, + .info_changed = node_info_changed, .active_changed = node_active_changed, .process = node_process, .finish = node_finish, diff --git a/src/pipewire/remote.h b/src/pipewire/remote.h index e88267be1..0a0261d92 100644 --- a/src/pipewire/remote.h +++ b/src/pipewire/remote.h @@ -160,6 +160,9 @@ struct pw_core *pw_remote_get_core(struct pw_remote *remote); /** Get the remote properties */ const struct pw_properties *pw_remote_get_properties(struct pw_remote *remote); +/** Update properties */ +int pw_remote_update_properties(struct pw_remote *remote, const struct spa_dict *dict); + /** Get the user_data. The size was given in \ref pw_remote_new */ void *pw_remote_get_user_data(struct pw_remote *remote);