settings: add an option to check quantum/rate in settings

Add an option to check if the rate and quantum configured with the
settings metadata is in the allowed range.

This is false by default, you can use metadata to set any rate/quantum
but in a minimal controlled setup you might want to restrict this.
This commit is contained in:
Wim Taymans 2022-01-19 15:55:43 +01:00
parent d2114c3f2e
commit b3e7d2b72a
4 changed files with 28 additions and 4 deletions

View file

@ -32,6 +32,9 @@ context.properties = {
#default.video.rate.num = 25
#default.video.rate.denom = 1
#
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

View file

@ -32,6 +32,9 @@ context.properties = {
#default.video.rate.num = 25
#default.video.rate.denom = 1
#
#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

View file

@ -68,6 +68,8 @@ struct settings {
unsigned int mem_warn_mlock:1;
unsigned int mem_allow_mlock:1;
unsigned int clock_power_of_two_quantum:1;
unsigned int check_quantum:1;
unsigned int check_rate:1;
#define CLOCK_RATE_UPDATE_MODE_HARD 0
#define CLOCK_RATE_UPDATE_MODE_SOFT 1
int clock_rate_update_mode;

View file

@ -53,6 +53,8 @@
#define DEFAULT_LINK_MAX_BUFFERS 64u
#define DEFAULT_MEM_WARN_MLOCK false
#define DEFAULT_MEM_ALLOW_MLOCK true
#define DEFAULT_CHECK_QUANTUM false
#define DEFAULT_CHECK_RATE false
struct impl {
struct pw_context *context;
@ -185,12 +187,23 @@ static int metadata_property(void *data, uint32_t subject, const char *key,
recalc = true;
} else if (spa_streq(key, "clock.force-rate")) {
v = value ? atoi(value) : 0;
s->clock_force_rate = v;
recalc = true;
if (v != 0 && s->check_rate &&
!uint32_array_contains(s->clock_rates, s->n_clock_rates, v)) {
pw_log_info("invalid %s: %d not in allowed rates", key, v);
} else {
s->clock_force_rate = v;
recalc = true;
}
} else if (spa_streq(key, "clock.force-quantum")) {
v = value ? atoi(value) : 0;
s->clock_force_quantum = v;
recalc = true;
if (v != 0 && s->check_quantum &&
(v < s->clock_min_quantum || v > s->clock_max_quantum)) {
pw_log_info("invalid %s: %d not in (%d-%d)", key, v,
s->clock_min_quantum, s->clock_max_quantum);
} else {
s->clock_force_quantum = v;
recalc = true;
}
}
if (recalc)
pw_context_recalc_graph(context, "settings changed");
@ -227,6 +240,9 @@ void pw_settings_init(struct pw_context *this)
d->mem_warn_mlock = get_default_bool(p, "mem.warn-mlock", DEFAULT_MEM_WARN_MLOCK);
d->mem_allow_mlock = get_default_bool(p, "mem.allow-mlock", DEFAULT_MEM_ALLOW_MLOCK);
d->check_quantum = get_default_bool(p, "settings.check-quantum", DEFAULT_CHECK_QUANTUM);
d->check_rate = get_default_bool(p, "settings.check-rate", DEFAULT_CHECK_RATE);
d->clock_quantum_limit = SPA_CLAMP(d->clock_quantum_limit,
CLOCK_MIN_QUANTUM, CLOCK_MAX_QUANTUM);
d->clock_max_quantum = SPA_CLAMP(d->clock_max_quantum,