From abfad78fb3ba97fe2eea2828029d20852f897287 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 15 Apr 2025 18:33:48 +0200 Subject: [PATCH] pod: swap inputs for filter when invalid default We usualy want to prefer the filter default value. When this value is not within the valid range/alternatives, swap the logic and prefer the defaults of the other pod. This way we can have a filter with an invalid default that will then use the preference of the other pod but still enforce some bounds. --- spa/include/spa/pod/filter.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spa/include/spa/pod/filter.h b/spa/include/spa/pod/filter.h index 66f9ae083..331999738 100644 --- a/spa/include/spa/pod/filter.h +++ b/spa/include/spa/pod/filter.h @@ -94,11 +94,18 @@ spa_pod_filter_prop(struct spa_pod_builder *b, if (nc == NULL) nc = &dummy; - /* we should prefer alt2 values but only if they are within the - * range, start with an empty child and we will select a good default + /* start with an empty child and we will select a good default * below */ spa_pod_builder_child(b, size, type); + /* we should prefer alt2 values but only if they are within the + * range. Swap the order otherwise. */ + if (!spa_pod_compare_is_valid_choice(type, size, alt2, alt2, nalt2, p2c)) { + SPA_SWAP(alt2, alt1); + SPA_SWAP(nalt2, nalt1); + SPA_SWAP(p2c, p1c); + } + if ((p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_None) || (p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_Enum) || (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_None) ||