[libcamera-devel] [PATCH v2] libcamera: v4l2_device: Workaround faulty control menus

Jacopo Mondi jacopo at jmondi.org
Wed Nov 2 17:22:37 CET 2022


Hi Kieran

On Wed, Nov 02, 2022 at 10:38:04AM +0000, Kieran Bingham via libcamera-devel wrote:
> Some UVC cameras have been identified that can provide V4L2 menu
> controls without any menu items.
>
> This leads to a segfault where we try to construct a
> ControlInfo(Span<>,default) with an empty span.
>
> Returning ControlInfo(); instead results in a Fatal log error due to the
> control validation failing.
>
> Provide the default value as the only acceptable menu control item, and
> report the issue on the debug log.
>
> Bug: https://bugs.libcamera.org/show_bug.cgi?id=167
> Reported-by: Marian Buschsieweke <marian.buschsieweke at ovgu.de>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> v2:
>  - Sigh, I forgot the SoB/Trailers in the commit message.
>
>  src/libcamera/v4l2_device.cpp | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index c17b323f8af0..f35820271f51 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -583,6 +583,16 @@ ControlInfo V4L2Device::v4l2MenuControlInfo(const struct v4l2_query_ext_ctrl &ct
>  		indices.push_back(index);
>  	}
>
> +	/*
> +	 * Some faulty UVC drivers are known to return an empty menu control.
> +	 * In that event, populate the indicies with the default value only.
> +	 */

Not sure what this mean in practice... The bug report says:

"Exposure Auto" menu has not a single supported item

However it is reported as listing 3 menu entries by v4l2-ctl -l

        exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=0 value=0

I guess the issue is then that QUERYMENU is not supported ? How does this
work in UVC, I guess the uvcdriver supports the ioctl, is it the
device fw which wrongly implements the uvcvideo specification ?

If that's the case why only push the default to indices ? Aren't min
and max selectable too ? (yes, we're going to miss all other values in
between min/max which are != default, but if the device is buggy we
can't do more than this...)

As this fix a user bug I don't want to get into the way of this fix,
but just to validate my understanding can you clarify this last part ?

> +	if (indices.size() == 0) {
> +		LOG(V4L2, Debug)
> +			<< "Menu control '" << ctrl.name << "' has no entries";
> +		indices.push_back(static_cast<int32_t>(ctrl.default_value));
> +	}
> +
>  	return ControlInfo(indices,
>  			   ControlValue(static_cast<int32_t>(ctrl.default_value)));
>  }
> --
> 2.34.1
>


More information about the libcamera-devel mailing list