From 3fb9fa06a951c505da18f333e6dd799d6f4cdc28 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 14 Mar 2019 16:40:17 +0100 Subject: [PATCH] client-stream: emit property change events Emit a property (param) change event when the volume or mute is changed on a stream. --- spa/plugins/audioconvert/channelmix.c | 36 ++++++++------ .../module-client-node/client-stream.c | 49 ++++++++++++------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index 8ca250234..548709e72 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -521,20 +521,23 @@ static int apply_props(struct impl *this, const struct spa_pod *param) struct spa_pod_prop *prop; struct spa_pod_object *obj = (struct spa_pod_object *) param; struct props *p = &this->props; + int changed = 0; SPA_POD_OBJECT_FOREACH(obj, prop) { switch (prop->key) { case SPA_PROP_volume: - spa_pod_get_float(&prop->value, &p->volume); + if (spa_pod_get_float(&prop->value, &p->volume) == 0) + changed++; break; case SPA_PROP_mute: - spa_pod_get_bool(&prop->value, &p->mute); + if (spa_pod_get_bool(&prop->value, &p->mute) == 0) + changed++; break; default: break; } } - return 0; + return changed; } static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) @@ -542,6 +545,16 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size return -ENOTSUP; } +static void emit_info(struct impl *this, bool full) +{ + if (full) + this->info.change_mask = this->info_all; + if (this->info.change_mask) { + spa_node_emit_info(&this->hooks, &this->info); + this->info.change_mask = 0; + } +} + static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, const struct spa_pod *param) { @@ -553,7 +566,12 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag switch (id) { case SPA_PARAM_Props: - return apply_props(this, param); + if (apply_props(this, param) > 0) { + this->info.change_mask = SPA_NODE_CHANGE_MASK_PARAMS; + this->params[1].flags ^= SPA_PARAM_INFO_SERIAL; + emit_info(this, false); + } + break; default: return -ENOENT; } @@ -582,16 +600,6 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman return 0; } -static void emit_info(struct impl *this, bool full) -{ - if (full) - this->info.change_mask = this->info_all; - if (this->info.change_mask) { - spa_node_emit_info(&this->hooks, &this->info); - this->info.change_mask = 0; - } -} - static void emit_port_info(struct impl *this, struct port *port, bool full) { if (full) diff --git a/src/modules/module-client-node/client-stream.c b/src/modules/module-client-node/client-stream.c index 7e46b34f1..efe449238 100644 --- a/src/modules/module-client-node/client-stream.c +++ b/src/modules/module-client-node/client-stream.c @@ -67,6 +67,10 @@ struct node { struct spa_log *log; + uint64_t info_all; + struct spa_node_info info; + struct spa_param_info params[4]; + struct spa_hook_list hooks; const struct spa_node_callbacks *callbacks; void *callbacks_data; @@ -210,6 +214,16 @@ static void try_link_controls(struct impl *impl) } } +static void emit_node_info(struct node *this, bool full) +{ + if (full) + this->info.change_mask = this->info_all; + if (this->info.change_mask) { + spa_node_emit_info(&this->hooks, &this->info); + this->info.change_mask = 0; + } +} + static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, const struct spa_pod *param) { @@ -236,6 +250,10 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag if (impl->adapter && impl->adapter != impl->cnode) { if ((res = spa_node_set_param(impl->adapter, id, flags, param)) < 0) return res; + + this->info.change_mask = SPA_NODE_CHANGE_MASK_PARAMS; + this->params[1].flags ^= SPA_PARAM_INFO_SERIAL; + emit_node_info(this, false); } break; default: @@ -314,24 +332,6 @@ static const struct spa_node_events adapter_node_events = { .result = adapter_result, }; -static void emit_node_info(struct node *this) -{ - struct spa_node_info info; - struct spa_param_info params[4]; - - info = SPA_NODE_INFO_INIT(); - info.max_input_ports = 0; - info.max_output_ports = 0; - info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS; - params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ); - params[1] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE); - params[2] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ); - params[3] = SPA_PARAM_INFO(SPA_PARAM_Profile, SPA_PARAM_INFO_WRITE); - info.params = params; - info.n_params = 4; - spa_node_emit_info(&this->hooks, &info); -} - static int impl_node_add_listener(struct spa_node *node, struct spa_hook *listener, const struct spa_node_events *events, @@ -350,7 +350,7 @@ static int impl_node_add_listener(struct spa_node *node, pw_log_debug("%p: add listener %p", this, listener); spa_hook_list_isolate(&this->hooks, &save, listener, events, data); - emit_node_info(this); + emit_node_info(this, true); if (impl->adapter && impl->adapter != impl->cnode) { spa_zero(l); @@ -923,6 +923,17 @@ node_init(struct node *this, this->node = impl_node; spa_hook_list_init(&this->hooks); + this->info_all = SPA_NODE_CHANGE_MASK_PARAMS; + this->info = SPA_NODE_INFO_INIT(); + this->info.max_input_ports = 0; + this->info.max_output_ports = 0; + this->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ); + this->params[1] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE); + this->params[2] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ); + this->params[3] = SPA_PARAM_INFO(SPA_PARAM_Profile, SPA_PARAM_INFO_WRITE); + this->info.params = this->params; + this->info.n_params = 4; + return 0; }