mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-15 21:44:17 -04:00
conf: support property rules
Add pw_conf_section_update_props_rules() that will not only update the properties of a section but wil also apply rules in section.rules and match against the context properties. Use this by default when using pw_context_conf_update_props(). Add a new method to get a string name of the VM type. Place the cpu.vm.name in the context properties. This makes it possible to deprecate the vm.overrides with something more flexible based on rules. Update the conf files and docs to refect this.
This commit is contained in:
parent
afd0affd97
commit
7e9e261fa6
12 changed files with 178 additions and 41 deletions
|
|
@ -986,26 +986,38 @@ static int update_props(void *user_data, const char *location, const char *key,
|
|||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_conf_section_update_props(const struct spa_dict *conf,
|
||||
const char *section, struct pw_properties *props)
|
||||
int pw_conf_section_update_props_rules(const struct spa_dict *conf,
|
||||
const struct spa_dict *context, const char *section,
|
||||
struct pw_properties *props)
|
||||
{
|
||||
struct data data = { .props = props };
|
||||
int res;
|
||||
const char *str;
|
||||
char key[128];
|
||||
|
||||
res = pw_conf_section_for_each(conf, section,
|
||||
update_props, &data);
|
||||
|
||||
str = pw_properties_get(props, "config.ext");
|
||||
if (res == 0 && str != NULL) {
|
||||
char key[128];
|
||||
snprintf(key, sizeof(key), "%s.%s", section, str);
|
||||
res = pw_conf_section_for_each(conf, key,
|
||||
update_props, &data);
|
||||
}
|
||||
if (res == 0 && context != NULL) {
|
||||
snprintf(key, sizeof(key), "%s.rules", section);
|
||||
res = pw_conf_section_match_rules(conf, key, context, update_props, &data);
|
||||
}
|
||||
return res == 0 ? data.count : res;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_conf_section_update_props(const struct spa_dict *conf,
|
||||
const char *section, struct pw_properties *props)
|
||||
{
|
||||
return pw_conf_section_update_props_rules(conf, NULL, section, props);
|
||||
}
|
||||
|
||||
static bool valid_conf_name(const char *str)
|
||||
{
|
||||
return spa_streq(str, "null") || spa_strendswith(str, ".conf");
|
||||
|
|
@ -1208,8 +1220,8 @@ SPA_EXPORT
|
|||
int pw_context_conf_update_props(struct pw_context *context,
|
||||
const char *section, struct pw_properties *props)
|
||||
{
|
||||
return pw_conf_section_update_props(&context->conf->dict,
|
||||
section, props);
|
||||
return pw_conf_section_update_props_rules(&context->conf->dict,
|
||||
&context->properties->dict, section, props);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ int pw_conf_save_state(const char *prefix, const char *name, const struct pw_pro
|
|||
int pw_conf_section_update_props(const struct spa_dict *conf,
|
||||
const char *section, struct pw_properties *props);
|
||||
|
||||
int pw_conf_section_update_props_rules(const struct spa_dict *conf,
|
||||
const struct spa_dict *context, const char *section,
|
||||
struct pw_properties *props);
|
||||
|
||||
int pw_conf_section_for_each(const struct spa_dict *conf, const char *section,
|
||||
int (*callback) (void *data, const char *location, const char *section,
|
||||
const char *str, size_t len),
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop,
|
|||
struct pw_context *this;
|
||||
const char *lib, *str;
|
||||
void *dbus_iface = NULL;
|
||||
uint32_t n_support;
|
||||
uint32_t n_support, vm_type;
|
||||
struct pw_properties *pr, *conf;
|
||||
struct spa_cpu *cpu;
|
||||
int res = 0;
|
||||
|
|
@ -244,6 +244,10 @@ 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);
|
||||
|
||||
vm_type = SPA_CPU_VM_NONE;
|
||||
if (cpu != NULL && (vm_type = spa_cpu_get_vm_type(cpu)) != SPA_CPU_VM_NONE)
|
||||
pw_properties_set(properties, "cpu.vm.name", spa_cpu_vm_type_to_string(vm_type));
|
||||
|
||||
res = pw_context_conf_update_props(this, "context.properties", properties);
|
||||
pw_log_info("%p: parsed %d context.properties items", this, res);
|
||||
|
||||
|
|
@ -253,7 +257,9 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop,
|
|||
}
|
||||
|
||||
if ((str = pw_properties_get(properties, "vm.overrides")) != NULL) {
|
||||
if (cpu != NULL && spa_cpu_get_vm_type(cpu) != SPA_CPU_VM_NONE)
|
||||
pw_log_warn("vm.overrides in context.properties are deprecated, "
|
||||
"use context.properties.rules instead");
|
||||
if (vm_type != SPA_CPU_VM_NONE)
|
||||
pw_properties_update_string(properties, str, strlen(str));
|
||||
pw_properties_set(properties, "vm.overrides", NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue