impl-link: improve negotiation

Make a function to create a filter. This is a pod that has all valid
defaults fixated and the invalid ones left unfixated.

Use this filter is a first attempt to negotiate a link format. The
effect is that a format will be chosen first that matches all the valid
defaults as much as possible instead of negotiating to the first thing
that matches.

Suppose we have a higher priority port with the format:

 foo/bar
    key: { default:1024, min:1, max:2048 }

And another port with two params:

 foo/bar
    key: 512
    rate: 2/1
 foo/bar
    key: 1024
    rate: 30/1

By first trying key: 1024 we negotiate to the more specific second property
with the higher rate.
This commit is contained in:
Wim Taymans 2025-05-05 10:12:26 +02:00
parent 9255e07c3a
commit faf5ae0c2f
2 changed files with 40 additions and 1 deletions

View file

@ -379,6 +379,32 @@ spa_pod_filter(struct spa_pod_builder *b,
return res;
}
SPA_API_POD_FILTER int spa_pod_filter_object_make(struct spa_pod_object *pod)
{
struct spa_pod_prop *res;
int count = 0;
SPA_POD_OBJECT_FOREACH(pod, res) {
if (res->value.type == SPA_TYPE_Choice &&
!SPA_FLAG_IS_SET(res->flags, SPA_POD_PROP_FLAG_DONT_FIXATE)) {
uint32_t nvals, choice;
struct spa_pod *v = spa_pod_get_values(&res->value, &nvals, &choice);
const void *vals = SPA_POD_BODY(v);
if (spa_pod_compare_is_valid_choice(v->type, v->size,
vals, vals, nvals, choice)) {
((struct spa_pod_choice*)&res->value)->body.type = SPA_CHOICE_None;
count++;
}
}
}
return count;
}
SPA_API_POD_FILTER int spa_pod_filter_make(struct spa_pod *pod)
{
if (!spa_pod_is_object(pod))
return -EINVAL;
return spa_pod_filter_object_make((struct spa_pod_object *)pod);
}
/**
* \}
*/