From 44c05cfa7bd35afddc03dc8ce75df4707f49b0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 23 Jul 2025 14:06:11 +0200 Subject: [PATCH] spa: libcamera: source: move control enumeration to loop Remove the `goto`s and instead move everything into a loop. --- spa/plugins/libcamera/libcamera-source.cpp | 55 +++++++++------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index ef0209f0d..f7d21a780 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -811,44 +811,35 @@ spa_libcamera_enum_controls(struct impl *impl, struct port *port, int seq, const ControlInfoMap &info = impl->camera->controls(); uint8_t buffer[1024]; struct spa_pod_builder b = { 0 }; - struct spa_result_node_params result; - struct spa_pod *ctrl; - uint32_t count = 0, skip; - int res; - - result.id = SPA_PARAM_PropInfo; - result.next = start; + spa_result_node_params result = { + .id = SPA_PARAM_PropInfo, + }; auto it = info.begin(); - for (skip = result.next - offset; skip && it != info.end(); skip--) + for (auto skip = start - offset; skip && it != info.end(); skip--) it++; - if (false) { -next: - it++; + for (result.index = start; num > 0 && it != info.end(); ++it, result.index++) { + spa_log_debug(impl->log, "%p: controls[%" PRIu32 "]: %s::%s", + impl, result.index, it->first->vendor().c_str(), + it->first->name().c_str()); + + spa_pod_builder_init(&b, buffer, sizeof(buffer)); + + const auto *ctrl = control_details_to_pod(b, *it->first, it->second); + if (!ctrl) + continue; + + if (spa_pod_filter(&b, &result.param, ctrl, filter) < 0) + continue; + + result.next = result.index + 1; + + spa_node_emit_result(&impl->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result); + num -= 1; } - result.index = result.next++; - if (it == info.end()) - goto enum_end; - - spa_pod_builder_init(&b, buffer, sizeof(buffer)); - - ctrl = control_details_to_pod(b, *it->first, it->second); - if (!ctrl) - goto next; - - if (spa_pod_filter(&b, &result.param, ctrl, filter) < 0) - goto next; - - spa_node_emit_result(&impl->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result); - - if (++count != num) - goto next; - -enum_end: - res = 0; - return res; + return 0; } struct val {