From b952d52b5982f9f9f015da70fb3288c20111b096 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Fri, 25 Nov 2022 01:46:14 +0100 Subject: [PATCH] libcamera: Handle missing control info default values Libcamera does not always provide default values for all control infos, see https://git.libcamera.org/libcamera/libcamera.git/tree/src/ipa/rkisp1/rkisp1.cpp?h=v0.0.2#n98 Sanitize those values, avoiding crashes. --- spa/plugins/libcamera/libcamera-utils.cpp | 50 ++++++++++++++++------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-utils.cpp b/spa/plugins/libcamera/libcamera-utils.cpp index 446220bd1..a5b2f8fd2 100644 --- a/spa/plugins/libcamera/libcamera-utils.cpp +++ b/spa/plugins/libcamera/libcamera-utils.cpp @@ -500,28 +500,48 @@ next: 0); switch (ctrl_id->type()) { - case ControlTypeBool: + case ControlTypeBool: { + bool def; + if (ctrl_info.def().isNone()) + def = ctrl_info.min().get(); + else + def = ctrl_info.def().get(); + spa_pod_builder_add(&b, - SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool( - (bool)ctrl_info.def().get()), - 0); - break; - case ControlTypeFloat: + SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool( + def), + 0); + } break; + case ControlTypeFloat: { + float min = ctrl_info.min().get(); + float max = ctrl_info.max().get(); + float def; + + if (ctrl_info.def().isNone()) + def = (min + max) / 2; + else + def = ctrl_info.def().get(); + spa_pod_builder_add(&b, SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float( - (float)ctrl_info.def().get(), - (float)ctrl_info.min().get(), - (float)ctrl_info.max().get()), + def, min, max), 0); - break; - case ControlTypeInteger32: + } break; + case ControlTypeInteger32: { + int32_t min = ctrl_info.min().get(); + int32_t max = ctrl_info.max().get(); + int32_t def; + + if (ctrl_info.def().isNone()) + def = (min + max) / 2; + else + def = ctrl_info.def().get(); + spa_pod_builder_add(&b, SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int( - (int32_t)ctrl_info.def().get(), - (int32_t)ctrl_info.min().get(), - (int32_t)ctrl_info.max().get()), + def, min, max), 0); - break; + } break; default: goto next; }