params: count params per id from 0

Only increment the index when we find the requirested param, this
makes the params go from index 0 to the last instead of starting at some
random index. The random index is not really a problem but it is also
no so nice.
This commit is contained in:
Wim Taymans 2022-10-27 19:20:40 +02:00
parent f0328a1f8d
commit 552d4516b6
5 changed files with 23 additions and 14 deletions

View file

@ -419,16 +419,16 @@ static int enum_params(struct filter *d, struct spa_list *param_list, int seq,
spa_list_for_each(p, param_list, link) {
struct spa_pod *param;
result.index = result.next++;
if (result.index < start)
continue;
param = p->param;
if (param == NULL || p->id != id)
continue;
found = true;
result.index = result.next++;
if (result.index < start)
continue;
spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096);
if (spa_pod_filter(&b.b, &result.param, param, filter) == 0) {
spa_node_emit_result(&d->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);

View file

@ -328,15 +328,18 @@ int pw_impl_device_for_each_param(struct pw_impl_device *device,
struct spa_pod_dynamic_builder b;
struct spa_result_device_params result;
uint32_t count = 0;
bool found = false;
result.id = param_id;
result.next = 0;
spa_list_for_each(p, &impl->param_list, link) {
result.index = result.next++;
if (p->id != param_id)
continue;
found = true;
result.index = result.next++;
if (result.index < index)
continue;
@ -351,7 +354,7 @@ int pw_impl_device_for_each_param(struct pw_impl_device *device,
if (count == max)
break;
}
res = 0;
res = found ? 0 : -ENOENT;
} else {
user_data.cache = impl->cache_params &&
(filter == NULL && index == 0 && max == UINT32_MAX);

View file

@ -2015,15 +2015,18 @@ int pw_impl_node_for_each_param(struct pw_impl_node *node,
struct spa_pod_dynamic_builder b;
struct spa_result_node_params result;
uint32_t count = 0;
bool found = false;
result.id = param_id;
result.next = 0;
spa_list_for_each(p, &impl->param_list, link) {
result.index = result.next++;
if (p->id != param_id)
continue;
found = true;
result.index = result.next++;
if (result.index < index)
continue;
@ -2039,7 +2042,7 @@ int pw_impl_node_for_each_param(struct pw_impl_node *node,
if (count == max)
break;
}
res = 0;
res = found ? 0 : -ENOENT;
} else {
user_data.cache = impl->cache_params &&
(filter == NULL && index == 0 && max == UINT32_MAX);

View file

@ -1248,15 +1248,18 @@ int pw_impl_port_for_each_param(struct pw_impl_port *port,
struct spa_pod_dynamic_builder b;
struct spa_result_node_params result;
uint32_t count = 0;
bool found = false;
result.id = param_id;
result.next = 0;
spa_list_for_each(p, &impl->param_list, link) {
result.index = result.next++;
if (p->id != param_id)
continue;
found = true;
result.index = result.next++;
if (result.index < index)
continue;
@ -1272,7 +1275,7 @@ int pw_impl_port_for_each_param(struct pw_impl_port *port,
if (count == max)
break;
}
res = 0;
res = found ? 0 : -ENOENT;
} else {
user_data.cache = impl->cache_params &&
(filter == NULL && index == 0 && max == UINT32_MAX);

View file

@ -544,16 +544,16 @@ static int enum_params(void *object, bool is_port, int seq, uint32_t id, uint32_
spa_list_for_each(p, &d->param_list, link) {
struct spa_pod *param;
result.index = result.next++;
if (result.index < start)
continue;
param = p->param;
if (param == NULL || p->id != id)
continue;
found = true;
result.index = result.next++;
if (result.index < start)
continue;
spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096);
if (spa_pod_filter(&b.b, &result.param, param, filter) == 0) {
spa_node_emit_result(&d->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);