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:
Wim Taymans 2024-03-15 11:55:18 +01:00
parent afd0affd97
commit 7e9e261fa6
12 changed files with 178 additions and 41 deletions

View file

@ -40,11 +40,6 @@ context.properties = {
#
settings.check-quantum = true
settings.check-rate = true
#
# These overrides are only applied when running in a vm.
vm.overrides = {
default.clock.min-quantum = 1024
}
# This config can use udev or hardcoded ALSA devices. Make sure to
# change the alsa device below when disabling udev
@ -54,6 +49,17 @@ context.properties = {
minimal.use-pulse = true
}
context.properties.rules = [
{ matches = [ { cpu.vm.name = !null } ]
actions = {
update-props = {
# These overrides are only applied when running in a vm.
default.clock.min-quantum = 1024
}
}
}
}
context.spa-libs = {
#<factory-name regex> = <library-name>
#

View file

@ -67,7 +67,14 @@ avb.properties = {
# the addresses this server listens on
#ifname = "eth0.2"
ifname = "enp3s0"
# These overrides are only applied when running in a vm.
vm.overrides = {
}
avb.properties.rules = [
{ matches = [ { cpu.vm.name = !null } ]
actions = {
update-props = {
# These overrides are only applied when running in a vm.
}
}
}
}

View file

@ -110,12 +110,19 @@ pulse.properties = {
#pulse.idle.timeout = 0 # don't pause after underruns
#pulse.default.format = F32
#pulse.default.position = [ FL FR ]
# These overrides are only applied when running in a vm.
vm.overrides = {
pulse.min.quantum = 1024/48000 # 22ms
}
}
pulse.properties.rules = [
{ matches = [ { cpu.vm.name = !null } ]
actions = {
update-props = {
# These overrides are only applied when running in a vm.
pulse.min.quantum = 1024/48000 # 22ms
}
}
}
]
# client/stream specific properties
pulse.rules = [
{

View file

@ -40,11 +40,6 @@ context.properties = {
#
#settings.check-quantum = false
#settings.check-rate = false
#
# These overrides are only applied when running in a vm.
vm.overrides = {
default.clock.min-quantum = 1024
}
# keys checked below to disable module loading
module.x11.bell = true
@ -55,6 +50,17 @@ context.properties = {
module.jackdbus-detect = true
}
context.properties.rules = [
{ matches = [ { cpu.vm.name = !null } ]
actions = {
update-props = {
# These overrides are only applied when running in a vm.
default.clock.min-quantum = 1024
}
}
}
}
context.spa-libs = {
#<factory-name regex> = <library-name>
#

View file

@ -32,6 +32,8 @@ struct pw_avb *pw_avb_new(struct pw_context *context,
pw_context_conf_update_props(context, "avb.properties", props);
if ((str = pw_properties_get(props, "vm.overrides")) != NULL) {
pw_log_warn("vm.overrides in avb.properties are deprecated, "
"use avb.properties.rules instead");
if (cpu != NULL && spa_cpu_get_vm_type(cpu) != SPA_CPU_VM_NONE)
pw_properties_update_string(props, str, strlen(str));
pw_properties_set(props, "vm.overrides", NULL);

View file

@ -71,11 +71,17 @@
* #pulse.min.quantum = 128/48000 # 2.7ms
* #pulse.default.format = F32
* #pulse.default.position = [ FL FR ]
* # These overrides are only applied when running in a vm.
* vm.overrides = {
* pulse.min.quantum = 1024/48000 # 22ms
* }
* }
* pulse.properties.rules = [
* { matches = [ { cpu.vm.name = !null } ]
* actions = {
* update-props = {
* # These overrides are only applied when running in a vm.
* pulse.min.quantum = 1024/48000 # 22ms
* }
* }
* }
* ]
*\endcode
*
* ### Connection options
@ -185,19 +191,6 @@
* This is equivalent to the PulseAudio `default-sample-channels` and
* `default-channel-map` options in `/etc/pulse/daemon.conf`.
*
* ### VM options
*
*\code{.unparsed}
* vm.overrides = {
* pulse.min.quantum = 1024/48000 # 22ms
* }
*\endcode
*
* When running in a VM, the `vm.override` section will override the properties
* in pulse.properties with the given values. This might be interesting because
* VMs usually can't support the low latency settings that are possible on real
* hardware.
*
* ### Quirk options
*
*\code{.unparsed}
@ -240,6 +233,30 @@
* #{ cmd = "load-module" args = "module-gsettings" flags = [ "nofail" ] }
* ]
*\endcode
* ## Dynamic properties
*
* The pulse.properties can be dyanmically updated with rules. It supports
* an `update-props` action. The matches will be performed on the values in
* context.properties.
*
*\code{.unparsed}
* pulse.properties.rules = [
* { matches = [ { cpu.vm.name = !null } ]
* actions = {
* update-props = {
* # These overrides are only applied when running in a vm.
* pulse.min.quantum = 1024/48000 # 22ms
* }
* }
* }
* ]
*\endcode
*
* In the above example, when running in a VM, the rule will override the properties
* in pulse.properties with the given values. This might be interesting because
* VMs usually can't support the low latency settings that are possible on real
* hardware.
*
* ## Stream settings and rules
*

View file

@ -5502,6 +5502,8 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
pw_context_conf_update_props(context, "pulse.properties", props);
if ((str = pw_properties_get(props, "vm.overrides")) != NULL) {
pw_log_warn("vm.overrides in pulse.properties are deprecated, "
"use pulse.properties.rules instead");
if (cpu != NULL && spa_cpu_get_vm_type(cpu) != SPA_CPU_VM_NONE)
pw_properties_update_string(props, str, strlen(str));
pw_properties_set(props, "vm.overrides", NULL);

View file

@ -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

View file

@ -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),

View file

@ -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);
}