From db245fd0ce24d6bc83b8379c25861de94f44c6e8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 8 Jun 2021 16:56:22 +0200 Subject: [PATCH] context: override the CORE_NAME in context Override the CORE_NAME using the env variable in the context instead of pipewire.c. This avoids needing the _add_string() property method. Remove the properties_add_string() method, there are new improved plans for property parsing and merging: See #207 --- src/daemon/pipewire.c | 6 ------ src/pipewire/context.c | 7 ++++++- src/pipewire/properties.c | 43 ++++++++++----------------------------- src/pipewire/properties.h | 3 --- 4 files changed, 17 insertions(+), 42 deletions(-) diff --git a/src/daemon/pipewire.c b/src/daemon/pipewire.c index 15a919553..753248e6b 100644 --- a/src/daemon/pipewire.c +++ b/src/daemon/pipewire.c @@ -65,7 +65,6 @@ int main(int argc, char *argv[]) int c; char path[PATH_MAX]; const char *config_name; - const char *core_name; if (setenv("PIPEWIRE_INTERNAL", "1", 1) < 0) fprintf(stderr, "can't set PIPEWIRE_INTERNAL env: %m"); @@ -100,11 +99,6 @@ int main(int argc, char *argv[]) PW_KEY_CONFIG_NAME, config_name, NULL); - if ((core_name = getenv("PIPEWIRE_CORE"))) { - pw_log_info("using core.name from environment: %s", core_name); - pw_properties_set(properties, PW_KEY_CORE_NAME, core_name); - } - loop = pw_main_loop_new(&properties->dict); if (loop == NULL) { pw_log_error("failed to create main-loop: %m"); diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 3990d87ca..b5d2c36a0 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -250,10 +250,15 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop, cpu = spa_support_find(this->support, n_support, SPA_TYPE_INTERFACE_CPU); if ((str = pw_properties_get(conf, "context.properties")) != NULL) { - pw_properties_add_string(properties, str, strlen(str)); + pw_properties_update_string(properties, str, strlen(str)); pw_log_info(NAME" %p: parsed context.properties section", this); } + if ((str = getenv("PIPEWIRE_CORE"))) { + pw_log_info("using core.name from environment: %s", str); + pw_properties_set(properties, PW_KEY_CORE_NAME, str); + } + if ((str = pw_properties_get(properties, "vm.overrides")) != NULL) { if (cpu != NULL && spa_cpu_get_vm_type(cpu) != SPA_CPU_VM_NONE) pw_properties_update_string(properties, str, strlen(str)); diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index cbb388c65..c004c12a9 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -146,7 +146,16 @@ struct pw_properties *pw_properties_new_dict(const struct spa_dict *dict) return &impl->this; } -static int update_from_string(struct pw_properties *props, const char *str, size_t size, bool overwrite) +/** Update the properties from the given string, overwriting any + * existing keys with the new values from \a str. + * + * \a str should be a whitespace separated list of key=value + * strings or a json object, see pw_properties_new_string(). + * + * \return The number of properties added or updated + */ +SPA_EXPORT +int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size) { struct properties *impl = SPA_CONTAINER_OF(props, struct properties, this); struct spa_json it[2]; @@ -175,42 +184,12 @@ static int update_from_string(struct pw_properties *props, const char *str, size if ((val = malloc(len+1)) != NULL) spa_json_parse_string(value, len, val); } - if (overwrite || pw_properties_get(&impl->this, key) == NULL) - count += pw_properties_set(&impl->this, key, val); + count += pw_properties_set(&impl->this, key, val); free(val); } return count; } -/** - * Update the properties from the given string, adding any new - * keys from \a str but leaving existing keys in \a props unmodified. - * - * \a str should be a whitespace separated list of key=value - * strings or a json object, see pw_properties_new_string(). - * - * \return The number of properties added - */ -SPA_EXPORT -int pw_properties_add_string(struct pw_properties *props, const char *str, size_t size) -{ - return update_from_string(props, str, size, false); -} - -/** Update the properties from the given string, overwriting any - * existing keys with the new values from \a str. - * - * \a str should be a whitespace separated list of key=value - * strings or a json object, see pw_properties_new_string(). - * - * \return The number of properties added or updated - */ -SPA_EXPORT -int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size) -{ - return update_from_string(props, str, size, true); -} - /** Make a new properties object from the given str * * \a object should be a whitespace separated list of key=value diff --git a/src/pipewire/properties.h b/src/pipewire/properties.h index 4155dc0e9..3f2110ce4 100644 --- a/src/pipewire/properties.h +++ b/src/pipewire/properties.h @@ -74,9 +74,6 @@ int pw_properties_update(struct pw_properties *props, /* Update props with all key/value pairs from str */ int pw_properties_update_string(struct pw_properties *props, const char *str, size_t size); -/* Update props with only new key/value from str */ -int pw_properties_add_string(struct pw_properties *props, - const char *str, size_t size); int pw_properties_add(struct pw_properties *oldprops, const struct spa_dict *dict);