From 11cb77c5773208141e2ecbe40662d508b64da9a2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 25 Aug 2021 09:28:23 +0200 Subject: [PATCH] context: fall back to default rate in case of errors When the allowed rates does not contain the default rate, also fall back to only the default rate. See the configured rates in the properties so it can be inspected. --- src/pipewire/context.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 0b87d1a63..dc821697d 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -137,6 +137,15 @@ static bool get_default_bool(struct pw_properties *properties, const char *name, return val; } +static bool rates_contains(uint32_t *rates, uint32_t n_rates, uint32_t rate) +{ + uint32_t i; + for (i = 0; i < n_rates; i++) + if (rates[i] == rate) + return true; + return false; +} + static uint32_t parse_clock_rate(struct pw_properties *properties, const char *name, uint32_t *rates, uint32_t def) { @@ -157,11 +166,13 @@ static uint32_t parse_clock_rate(struct pw_properties *properties, const char *n if (spa_atou32(v, &r, 0)) rates[count++] = r; } - if (count == 0) + if (count == 0 ||!rates_contains(rates, count, def)) goto fallback; + return count; fallback: rates[0] = def; + pw_properties_setf(properties, name, "[ %u ]", def); return 1; } @@ -1048,15 +1059,6 @@ static inline uint32_t *get_rates(struct pw_context *context, uint32_t *def, uin return s->clock_rates; } } -static bool rates_contains(uint32_t *rates, uint32_t n_rates, uint32_t rate) -{ - uint32_t i; - for (i = 0; i < n_rates; i++) - if (rates[i] == rate) - return true; - return false; -} - static void suspend_driver(struct pw_context *context, struct pw_impl_node *n) { struct pw_impl_node *s;