From 59329635066d9cb5500d98f7a656cf582ee4989e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20P=C3=BCschel?= Date: Wed, 17 Jul 2024 14:38:32 +0200 Subject: [PATCH] spa: match camera property types with libcamera MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Pipewire libcamera spa plugin exposes multiple camera properties. Unlike v4l2, libcamera usually exposes these as normalized floating point values. But as the SPA_PROP types are based on v4l2, they are currently set to integers. This causes a problem when using pw-cli to change the properties, as the spa_json_to_pod_part function casts the properties according to their spa_type_info. Other software that doesn't depend on the spa_type_info can correctly set the properties, as the values are encoded in the spa_pod type and therefore also carry a type. As the limited range from switching integers to floats is likely not a problem, the affected spa properties were changed to the Float type. This will cause pw-cli to also generate spa_pod values of type float when setting v4l2 properties. Therefore the v4l2 spa plugin is also adapted to allow floating point properties and cast these to integers. Signed-off-by: Sven Püschel --- spa/include/spa/param/props-types.h | 10 +++++----- spa/plugins/v4l2/v4l2-utils.c | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/spa/include/spa/param/props-types.h b/spa/include/spa/param/props-types.h index e00f2f875..e66125992 100644 --- a/spa/include/spa/param/props-types.h +++ b/spa/include/spa/param/props-types.h @@ -64,14 +64,14 @@ static const struct spa_type_info spa_type_props[] = { { SPA_PROP_volumeRampStepTime, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "volumeRampStepTime", NULL }, { SPA_PROP_volumeRampScale, SPA_TYPE_Id, SPA_TYPE_INFO_PROPS_BASE "volumeRampScale", NULL }, - { SPA_PROP_brightness, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "brightness", NULL }, - { SPA_PROP_contrast, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "contrast", NULL }, - { SPA_PROP_saturation, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "saturation", NULL }, + { SPA_PROP_brightness, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "brightness", NULL }, + { SPA_PROP_contrast, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "contrast", NULL }, + { SPA_PROP_saturation, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "saturation", NULL }, { SPA_PROP_hue, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "hue", NULL }, { SPA_PROP_gamma, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "gamma", NULL }, { SPA_PROP_exposure, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "exposure", NULL }, - { SPA_PROP_gain, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "gain", NULL }, - { SPA_PROP_sharpness, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "sharpness", NULL }, + { SPA_PROP_gain, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "gain", NULL }, + { SPA_PROP_sharpness, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "sharpness", NULL }, { SPA_PROP_params, SPA_TYPE_Struct, SPA_TYPE_INFO_PROPS_BASE "params", NULL }, { 0, 0, NULL, NULL }, diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index cb48e9f69..4ea67bf11 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -1361,6 +1361,14 @@ spa_v4l2_set_control(struct impl *this, uint32_t id, control.value = val; break; } + case SPA_TYPE_Float: + { + float val; + if ((res = spa_pod_get_float(&prop->value, &val)) < 0) + goto done; + control.value = (int32_t) val; + break; + } case SPA_TYPE_Int: { int32_t val;