mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-19 21:37:36 -04:00
settings: clamp the clock rate to avoid 0 division
Setting the rate to 0 could in some cases result in a division by zero, avoid that by clamping to a min value.
This commit is contained in:
parent
e5ff44910e
commit
a74109eef3
1 changed files with 6 additions and 1 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
#define NAME "settings"
|
#define NAME "settings"
|
||||||
|
|
||||||
#define DEFAULT_CLOCK_RATE 48000u
|
#define DEFAULT_CLOCK_RATE 48000u
|
||||||
|
#define DEFAULT_CLOCK_MIN_RATE 1u
|
||||||
#define DEFAULT_CLOCK_RATES "[ 48000 ]"
|
#define DEFAULT_CLOCK_RATES "[ 48000 ]"
|
||||||
#define DEFAULT_CLOCK_QUANTUM 1024u
|
#define DEFAULT_CLOCK_QUANTUM 1024u
|
||||||
#define DEFAULT_CLOCK_MIN_QUANTUM 32u
|
#define DEFAULT_CLOCK_MIN_QUANTUM 32u
|
||||||
|
|
@ -111,7 +112,7 @@ static uint32_t parse_clock_rate(struct pw_properties *properties, const char *n
|
||||||
uint32_t *rates, const char *def_rates, uint32_t def)
|
uint32_t *rates, const char *def_rates, uint32_t def)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
uint32_t count = 0;
|
uint32_t i, count = 0;
|
||||||
|
|
||||||
if ((str = pw_properties_get(properties, name)) == NULL)
|
if ((str = pw_properties_get(properties, name)) == NULL)
|
||||||
str = def_rates;
|
str = def_rates;
|
||||||
|
|
@ -122,6 +123,9 @@ static uint32_t parse_clock_rate(struct pw_properties *properties, const char *n
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
goto fallback;
|
goto fallback;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
rates[i] = SPA_MAX(rates[i], DEFAULT_CLOCK_MIN_RATE);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
fallback:
|
fallback:
|
||||||
rates[0] = def;
|
rates[0] = def;
|
||||||
|
|
@ -207,6 +211,7 @@ void pw_settings_init(struct pw_context *this)
|
||||||
struct settings *d = &this->defaults;
|
struct settings *d = &this->defaults;
|
||||||
|
|
||||||
d->clock_rate = get_default_int(p, "default.clock.rate", DEFAULT_CLOCK_RATE);
|
d->clock_rate = get_default_int(p, "default.clock.rate", DEFAULT_CLOCK_RATE);
|
||||||
|
d->clock_rate = SPA_MAX(d->clock_rate, DEFAULT_CLOCK_MIN_RATE);
|
||||||
d->n_clock_rates = parse_clock_rate(p, "default.clock.allowed-rates", d->clock_rates,
|
d->n_clock_rates = parse_clock_rate(p, "default.clock.allowed-rates", d->clock_rates,
|
||||||
DEFAULT_CLOCK_RATES, d->clock_rate);
|
DEFAULT_CLOCK_RATES, d->clock_rate);
|
||||||
d->clock_quantum = get_default_int(p, "default.clock.quantum", DEFAULT_CLOCK_QUANTUM);
|
d->clock_quantum = get_default_int(p, "default.clock.quantum", DEFAULT_CLOCK_QUANTUM);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue