mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-15 07:00:05 -05:00
filter: Better SPA_CHOICE_Step support
Allow comparing single values with step-ranges. An example where this can be useful is when trying to encode a screencast with a hardware encoder.
This commit is contained in:
parent
d4db7e1d9b
commit
0f4fcd63ac
1 changed files with 64 additions and 5 deletions
|
|
@ -123,6 +123,27 @@ static inline int spa_pod_filter_flags_value(struct spa_pod_builder *b,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static inline int spa_pod_filter_is_step_of(uint32_t type, const void *r1,
|
||||
const void *r2, uint32_t size)
|
||||
{
|
||||
switch (type) {
|
||||
case SPA_TYPE_Int:
|
||||
return *(int32_t *) r1 % *(int32_t *) r2 == 0;
|
||||
case SPA_TYPE_Long:
|
||||
return *(int64_t *) r1 % *(int64_t *) r2 == 0;
|
||||
case SPA_TYPE_Rectangle:
|
||||
{
|
||||
const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1,
|
||||
*rec2 = (struct spa_rectangle *) r2;
|
||||
|
||||
return (rec1->width % rec2->width == 0 &&
|
||||
rec1->height % rec2->height == 0);
|
||||
}
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_pod_filter_prop(struct spa_pod_builder *b,
|
||||
|
|
@ -209,7 +230,26 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
|
|||
|
||||
if ((p1c == SPA_CHOICE_None && p2c == SPA_CHOICE_Step) ||
|
||||
(p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Step)) {
|
||||
return -ENOTSUP;
|
||||
int n_copied = 0;
|
||||
for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 = SPA_PTROFF(a1,size,void)) {
|
||||
int res;
|
||||
if (spa_pod_compare_value(type, a1, a2, size) < 0)
|
||||
continue;
|
||||
if (spa_pod_compare_value(type, a1, SPA_PTROFF(a2,size,void), size) > 0)
|
||||
continue;
|
||||
|
||||
res = spa_pod_filter_is_step_of(type, a1, SPA_PTROFF(a2,size*2,void), size);
|
||||
if (res == 0)
|
||||
continue;
|
||||
if (res == -ENOTSUP)
|
||||
return -EINVAL;
|
||||
|
||||
spa_pod_builder_raw(b, a1, size);
|
||||
n_copied++;
|
||||
}
|
||||
if (n_copied == 0)
|
||||
return -EINVAL;
|
||||
nc->body.type = SPA_CHOICE_Enum;
|
||||
}
|
||||
|
||||
if ((p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_None) ||
|
||||
|
|
@ -263,10 +303,29 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
|
|||
if (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Flags)
|
||||
return -ENOTSUP;
|
||||
|
||||
if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_None)
|
||||
return -ENOTSUP;
|
||||
if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Enum)
|
||||
return -ENOTSUP;
|
||||
if ((p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_None) ||
|
||||
(p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Enum)) {
|
||||
int n_copied = 0;
|
||||
for (j = 0, a1 = alt1, a2 = alt2; j < nalt2; j++, a2 = SPA_PTROFF(a1,size,void)) {
|
||||
int res;
|
||||
if (spa_pod_compare_value(type, a2, a1, size) < 0)
|
||||
continue;
|
||||
if (spa_pod_compare_value(type, a2, SPA_PTROFF(a1,size,void), size) > 0)
|
||||
continue;
|
||||
|
||||
res = spa_pod_filter_is_step_of(type, a2, SPA_PTROFF(a1,size*2,void), size);
|
||||
if (res == 0)
|
||||
continue;
|
||||
if (res == -ENOTSUP)
|
||||
return -EINVAL;
|
||||
|
||||
spa_pod_builder_raw(b, a2, size);
|
||||
n_copied++;
|
||||
}
|
||||
if (n_copied == 0)
|
||||
return -EINVAL;
|
||||
nc->body.type = SPA_CHOICE_Enum;
|
||||
}
|
||||
if (p1c == SPA_CHOICE_Step && p2c == SPA_CHOICE_Flags)
|
||||
return -ENOTSUP;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue