client-node: implement node property update

Make it possible to update the node properties
Make it possible to update the remote properties
This commit is contained in:
Wim Taymans 2018-06-07 10:23:41 +02:00
parent b029000610
commit 3d25e254ef
5 changed files with 75 additions and 9 deletions

View file

@ -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_INPUTS (1 << 0)
#define PW_CLIENT_NODE_UPDATE_MAX_OUTPUTS (1 << 1) #define PW_CLIENT_NODE_UPDATE_MAX_OUTPUTS (1 << 1)
#define PW_CLIENT_NODE_UPDATE_PARAMS (1 << 2) #define PW_CLIENT_NODE_UPDATE_PARAMS (1 << 2)
#define PW_CLIENT_NODE_UPDATE_PROPS (1 << 3)
uint32_t change_mask, uint32_t change_mask,
uint32_t max_input_ports, uint32_t max_input_ports,
uint32_t max_output_ports, uint32_t max_output_ports,
uint32_t n_params, uint32_t n_params,
const struct spa_pod **params); const struct spa_pod **params,
const struct spa_dict *props);
/** /**
* Update a node port * 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_input_ports,
uint32_t max_output_ports, uint32_t max_output_ports,
uint32_t n_params, 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, pw_proxy_do((struct pw_proxy*)p, struct pw_client_node_proxy_methods, update, change_mask,
max_input_ports, max_input_ports,
max_output_ports, max_output_ports,
n_params, n_params, params, props);
params);
} }
static inline void static inline void

View file

@ -935,7 +935,8 @@ client_node_update(void *data,
uint32_t max_input_ports, uint32_t max_input_ports,
uint32_t max_output_ports, uint32_t max_output_ports,
uint32_t n_params, uint32_t n_params,
const struct spa_pod **params) const struct spa_pod **params,
const struct spa_dict *props)
{ {
struct impl *impl = data; struct impl *impl = data;
struct node *this = &impl->node; struct node *this = &impl->node;
@ -956,6 +957,9 @@ client_node_update(void *data,
for (i = 0; i < this->n_params; i++) for (i = 0; i < this->n_params; i++)
this->params[i] = pw_spa_pod_copy(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, spa_log_debug(this->log, "node %p: got node update max_in %u, max_out %u", this,
this->max_inputs, this->max_outputs); this->max_inputs, this->max_outputs);
} }

View file

@ -51,11 +51,12 @@ client_node_marshal_update(void *object,
uint32_t max_input_ports, uint32_t max_input_ports,
uint32_t max_output_ports, uint32_t max_output_ports,
uint32_t n_params, 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 pw_proxy *proxy = object;
struct spa_pod_builder *b; struct spa_pod_builder *b;
int i; int i, n_items;
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_UPDATE); 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++) for (i = 0; i < n_params; i++)
spa_pod_builder_add(b, "P", params[i], NULL); 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); spa_pod_builder_add(b, "]", NULL);
pw_protocol_native_end_proxy(proxy, b); 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; struct spa_pod_parser prs;
uint32_t change_mask, max_input_ports, max_output_ports, n_params; uint32_t change_mask, max_input_ports, max_output_ports, n_params;
const struct spa_pod **params; const struct spa_pod **params;
struct spa_dict props;
int i; int i;
spa_pod_parser_init(&prs, data, size, 0); 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", &params[i], NULL) < 0) if (spa_pod_parser_get(&prs, "O", &params[i], NULL) < 0)
return -EINVAL; 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, pw_resource_do(resource, struct pw_client_node_proxy_methods, update, change_mask,
max_input_ports, max_input_ports,
max_output_ports, max_output_ports,
n_params, n_params,
params); params,
props.n_items > 0 ?
&props : NULL);
return 0; return 0;
} }

View file

@ -331,6 +331,18 @@ const struct pw_properties *pw_remote_get_properties(struct pw_remote *remote)
return remote->properties; 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) void *pw_remote_get_user_data(struct pw_remote *remote)
{ {
return remote->user_data; return remote->user_data;
@ -1256,7 +1268,7 @@ static void do_node_init(struct pw_proxy *proxy)
PW_CLIENT_NODE_UPDATE_PARAMS, PW_CLIENT_NODE_UPDATE_PARAMS,
data->node->info.max_input_ports, data->node->info.max_input_ports,
data->node->info.max_output_ports, data->node->info.max_output_ports,
0, NULL); 0, NULL, NULL);
spa_list_for_each(port, &data->node->input_ports, link) { spa_list_for_each(port, &data->node->input_ports, link) {
add_port_update(proxy, port, add_port_update(proxy, port,
@ -1279,6 +1291,26 @@ static void node_destroy(void *data)
pw_proxy_destroy((struct pw_proxy *)d->node_proxy); 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) static void node_active_changed(void *data, bool active)
{ {
struct node_data *d = data; 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 = { static const struct pw_node_events node_events = {
PW_VERSION_NODE_EVENTS, PW_VERSION_NODE_EVENTS,
.destroy = node_destroy, .destroy = node_destroy,
.info_changed = node_info_changed,
.active_changed = node_active_changed, .active_changed = node_active_changed,
.process = node_process, .process = node_process,
.finish = node_finish, .finish = node_finish,

View file

@ -160,6 +160,9 @@ struct pw_core *pw_remote_get_core(struct pw_remote *remote);
/** Get the remote properties */ /** Get the remote properties */
const struct pw_properties *pw_remote_get_properties(struct pw_remote *remote); 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 */ /** Get the user_data. The size was given in \ref pw_remote_new */
void *pw_remote_get_user_data(struct pw_remote *remote); void *pw_remote_get_user_data(struct pw_remote *remote);