From b3e7d2b72a06fe5c5e4513741222875be6dbbf02 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 19 Jan 2022 15:55:43 +0100 Subject: [PATCH] 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. --- src/daemon/minimal.conf.in | 3 +++ src/daemon/pipewire.conf.in | 3 +++ src/pipewire/private.h | 2 ++ src/pipewire/settings.c | 24 ++++++++++++++++++++---- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/daemon/minimal.conf.in b/src/daemon/minimal.conf.in index 78f857a57..9ee4a1e28 100644 --- a/src/daemon/minimal.conf.in +++ b/src/daemon/minimal.conf.in @@ -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 diff --git a/src/daemon/pipewire.conf.in b/src/daemon/pipewire.conf.in index f415ff4d1..7d35f75b5 100644 --- a/src/daemon/pipewire.conf.in +++ b/src/daemon/pipewire.conf.in @@ -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 diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 8a5623e7b..9af21a5e5 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -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; diff --git a/src/pipewire/settings.c b/src/pipewire/settings.c index ca58af747..98180cc2e 100644 --- a/src/pipewire/settings.c +++ b/src/pipewire/settings.c @@ -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,