From 65c487564b41d283c62d00e0c6c566ce8f60d891 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 1 Feb 2022 15:11:45 +0100 Subject: [PATCH] context: add a function to merge config properties Add a function that takes a section and merges the properties into a target properties. Replace some usage of get_config_section(). --- pipewire-jack/src/pipewire-jack.c | 5 ++--- src/pipewire/context.c | 20 ++++++++++++++++---- src/pipewire/context.h | 4 ++++ src/pipewire/filter.c | 3 +-- src/pipewire/stream.c | 3 +-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 3579c0fb0..192b0d1b6 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -3150,9 +3150,8 @@ jack_client_t * jack_client_open (const char *client_name, client->allow_mlock = client->context.context->settings.mem_allow_mlock; client->warn_mlock = client->context.context->settings.mem_warn_mlock; - if ((str = pw_context_get_conf_section(client->context.context, - "jack.properties")) != NULL) - pw_properties_update_string(client->props, str, strlen(str)); + pw_context_conf_update_props(client->context.context, + "jack.properties", client->props); if ((str = getenv("PIPEWIRE_PROPS")) != NULL) pw_properties_update_string(client->props, str, strlen(str)); diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 5949c4ec9..554ff23b0 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -273,10 +273,8 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop, n_support = pw_get_support(this->support, SPA_N_ELEMENTS(this->support) - 6); cpu = spa_support_find(this->support, n_support, SPA_TYPE_INTERFACE_CPU); - if ((str = pw_properties_get(conf, "context.properties")) != NULL) { - pw_properties_update_string(properties, str, strlen(str)); - pw_log_info("%p: parsed context.properties section", this); - } + res = pw_context_conf_update_props(this, "context.properties", properties); + pw_log_info("%p: parsed %d context.properties items", this, res); if ((str = getenv("PIPEWIRE_CORE"))) { pw_log_info("using core.name from environment: %s", str); @@ -539,6 +537,20 @@ const char *pw_context_get_conf_section(struct pw_context *context, const char * return pw_properties_get(context->conf, section); } +SPA_EXPORT +int pw_context_conf_update_props(struct pw_context *context, + const char *section, struct pw_properties *props) +{ + struct pw_properties *conf = context->conf; + const char *str; + int count = 0; + + if ((str = pw_properties_get(conf, section)) != NULL) + count = pw_properties_update_string(props, str, strlen(str)); + + return count; +} + /** Update context properties * * \param context a context diff --git a/src/pipewire/context.h b/src/pipewire/context.h index ebe5dae11..1ef287cd9 100644 --- a/src/pipewire/context.h +++ b/src/pipewire/context.h @@ -111,6 +111,10 @@ int pw_context_update_properties(struct pw_context *context, const struct spa_di /** Get a config section for this context. Since 0.3.22 */ const char *pw_context_get_conf_section(struct pw_context *context, const char *section); +/** update properties from section into props. Since 0.3.45 */ +int pw_context_conf_update_props(struct pw_context *context, const char *section, + struct pw_properties *props); + /** Get the context support objects */ const struct spa_support *pw_context_get_support(struct pw_context *context, uint32_t *n_support); diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c index 090061d8a..70d5fa2f3 100644 --- a/src/pipewire/filter.c +++ b/src/pipewire/filter.c @@ -1209,8 +1209,7 @@ filter_new(struct pw_context *context, const char *name, res = -errno; goto error_properties; } - if ((str = pw_context_get_conf_section(context, "filter.properties")) != NULL) - pw_properties_update_string(props, str, strlen(str)); + pw_context_conf_update_props(context, "filter.properties", props); if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL && extra) { str = pw_properties_get(extra, PW_KEY_APP_NAME); diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 909a8eacf..e563ab4f2 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -1342,8 +1342,7 @@ stream_new(struct pw_context *context, const char *name, res = -errno; goto error_properties; } - if ((str = pw_context_get_conf_section(context, "stream.properties")) != NULL) - pw_properties_update_string(props, str, strlen(str)); + pw_context_conf_update_props(context, "stream.properties", props); if (pw_properties_get(props, PW_KEY_STREAM_IS_LIVE) == NULL) pw_properties_set(props, PW_KEY_STREAM_IS_LIVE, "true");