mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-08 13:30:08 -05:00
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:
parent
d2114c3f2e
commit
b3e7d2b72a
4 changed files with 28 additions and 4 deletions
|
|
@ -32,6 +32,9 @@ context.properties = {
|
||||||
#default.video.rate.num = 25
|
#default.video.rate.num = 25
|
||||||
#default.video.rate.denom = 1
|
#default.video.rate.denom = 1
|
||||||
#
|
#
|
||||||
|
settings.check-quantum = true
|
||||||
|
settings.check-rate = true
|
||||||
|
#
|
||||||
# These overrides are only applied when running in a vm.
|
# These overrides are only applied when running in a vm.
|
||||||
vm.overrides = {
|
vm.overrides = {
|
||||||
default.clock.min-quantum = 1024
|
default.clock.min-quantum = 1024
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ context.properties = {
|
||||||
#default.video.rate.num = 25
|
#default.video.rate.num = 25
|
||||||
#default.video.rate.denom = 1
|
#default.video.rate.denom = 1
|
||||||
#
|
#
|
||||||
|
#settings.check-quantum = false
|
||||||
|
#settings.check-rate = false
|
||||||
|
#
|
||||||
# These overrides are only applied when running in a vm.
|
# These overrides are only applied when running in a vm.
|
||||||
vm.overrides = {
|
vm.overrides = {
|
||||||
default.clock.min-quantum = 1024
|
default.clock.min-quantum = 1024
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ struct settings {
|
||||||
unsigned int mem_warn_mlock:1;
|
unsigned int mem_warn_mlock:1;
|
||||||
unsigned int mem_allow_mlock:1;
|
unsigned int mem_allow_mlock:1;
|
||||||
unsigned int clock_power_of_two_quantum: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_HARD 0
|
||||||
#define CLOCK_RATE_UPDATE_MODE_SOFT 1
|
#define CLOCK_RATE_UPDATE_MODE_SOFT 1
|
||||||
int clock_rate_update_mode;
|
int clock_rate_update_mode;
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@
|
||||||
#define DEFAULT_LINK_MAX_BUFFERS 64u
|
#define DEFAULT_LINK_MAX_BUFFERS 64u
|
||||||
#define DEFAULT_MEM_WARN_MLOCK false
|
#define DEFAULT_MEM_WARN_MLOCK false
|
||||||
#define DEFAULT_MEM_ALLOW_MLOCK true
|
#define DEFAULT_MEM_ALLOW_MLOCK true
|
||||||
|
#define DEFAULT_CHECK_QUANTUM false
|
||||||
|
#define DEFAULT_CHECK_RATE false
|
||||||
|
|
||||||
struct impl {
|
struct impl {
|
||||||
struct pw_context *context;
|
struct pw_context *context;
|
||||||
|
|
@ -185,12 +187,23 @@ static int metadata_property(void *data, uint32_t subject, const char *key,
|
||||||
recalc = true;
|
recalc = true;
|
||||||
} else if (spa_streq(key, "clock.force-rate")) {
|
} else if (spa_streq(key, "clock.force-rate")) {
|
||||||
v = value ? atoi(value) : 0;
|
v = value ? atoi(value) : 0;
|
||||||
s->clock_force_rate = v;
|
if (v != 0 && s->check_rate &&
|
||||||
recalc = true;
|
!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")) {
|
} else if (spa_streq(key, "clock.force-quantum")) {
|
||||||
v = value ? atoi(value) : 0;
|
v = value ? atoi(value) : 0;
|
||||||
s->clock_force_quantum = v;
|
if (v != 0 && s->check_quantum &&
|
||||||
recalc = true;
|
(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)
|
if (recalc)
|
||||||
pw_context_recalc_graph(context, "settings changed");
|
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_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->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,
|
d->clock_quantum_limit = SPA_CLAMP(d->clock_quantum_limit,
|
||||||
CLOCK_MIN_QUANTUM, CLOCK_MAX_QUANTUM);
|
CLOCK_MIN_QUANTUM, CLOCK_MAX_QUANTUM);
|
||||||
d->clock_max_quantum = SPA_CLAMP(d->clock_max_quantum,
|
d->clock_max_quantum = SPA_CLAMP(d->clock_max_quantum,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue