From da6ab064d21f983c3bc6e9e81e2b36554e7dc995 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 21 Apr 2022 16:28:08 +0200 Subject: [PATCH] stream: add stream.rules and filter.rules --- src/pipewire/filter.c | 16 ++++++++++++++++ src/pipewire/stream.c | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index 23e6ff598..d01b0b1f5 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -1175,6 +1175,15 @@ static const struct pw_core_events core_events = { .error = on_core_error, }; +static int execute_match(void *data, const char *location, const char *action, + const char *val, size_t len) +{ + struct pw_filter *this = data; + if (spa_streq(action, "update-props")) + pw_properties_update_string(this->properties, val, len); + return 1; +} + static struct filter * filter_new(struct pw_context *context, const char *name, struct pw_properties *props, const struct pw_properties *extra) @@ -1229,6 +1238,9 @@ filter_new(struct pw_context *context, const char *name, spa_hook_list_init(&impl->hooks); this->properties = props; + pw_context_conf_section_match_rules(impl->context, "filter.rules", + &this->properties->dict, execute_match, this); + this->name = name ? strdup(name) : NULL; this->node_id = SPA_ID_INVALID; @@ -1455,6 +1467,10 @@ int pw_filter_update_properties(struct pw_filter *filter, void *port_data, const } } else { changed = pw_properties_update(filter->properties, dict); + + pw_context_conf_section_match_rules(impl->context, "filter.rules", + &filter->properties->dict, execute_match, filter); + impl->info.props = &filter->properties->dict; if (changed > 0) { impl->info.change_mask |= SPA_NODE_CHANGE_MASK_PROPS; diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 01a53c6d4..a572eb009 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1370,6 +1370,15 @@ static const struct pw_context_driver_events context_events = { .drained = context_drained, }; +static int execute_match(void *data, const char *location, const char *action, + const char *val, size_t len) +{ + struct pw_stream *this = data; + if (spa_streq(action, "update-props")) + pw_properties_update_string(this->properties, val, len); + return 1; +} + static struct stream * stream_new(struct pw_context *context, const char *name, struct pw_properties *props, const struct pw_properties *extra) @@ -1428,10 +1437,12 @@ stream_new(struct pw_context *context, const char *name, "%u/%u", q.num, q.denom); } } - spa_hook_list_init(&impl->hooks); this->properties = props; + pw_context_conf_section_match_rules(context, "stream.rules", + &this->properties->dict, execute_match, this); + this->name = name ? strdup(name) : NULL; this->node_id = SPA_ID_INVALID; @@ -1642,10 +1653,12 @@ int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict int changed, res = 0; changed = pw_properties_update(stream->properties, dict); - if (!changed) return 0; + pw_context_conf_section_match_rules(impl->context, "stream.rules", + &stream->properties->dict, execute_match, stream); + if (impl->node) res = pw_impl_node_update_properties(impl->node, dict);