[libcamera-devel] [RFC PATCH] libcamera: camera_sensor: Report mandatory control names

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Feb 6 08:43:53 CET 2021


Hi Kieran,

Thank you for the patch.

On Fri, Feb 05, 2021 at 05:03:17PM +0000, Kieran Bingham wrote:
> We can not obtain the control names directly from V4L2 so create
> a map of the control name, when declaring the list of mandatory
> controls to enable a human readable print of any missing requirements.

If we want to print V4L2 controls by name to ease debugging, it would be
best not to limit the feature to this particular instance. I've been
toying for a long time with the idea of creating Control instances for
V4L2 controls, which would also allow the usage of a nicer get() and
set() in the ControlList class.

> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
>  src/libcamera/camera_sensor.cpp | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
> index c9e8d49b7935..9a510108f171 100644
> --- a/src/libcamera/camera_sensor.cpp
> +++ b/src/libcamera/camera_sensor.cpp
> @@ -346,18 +346,23 @@ int CameraSensor::validateSensorDriver()
>  	 * For raw sensors, make sure the sensor driver supports the controls
>  	 * required by the CameraSensor class.
>  	 */
> -	static constexpr uint32_t mandatoryControls[] = {
> -		V4L2_CID_EXPOSURE,
> -		V4L2_CID_HBLANK,
> -		V4L2_CID_PIXEL_RATE,
> -		V4L2_CID_VBLANK,
> +	static struct {
> +		uint32_t ctrl;
> +		std::string name;
> +	} mandatoryControls[] = {
> +#define MANDATORY_CONTROL(__ctrl) { __ctrl, #__ctrl }
> +		MANDATORY_CONTROL(V4L2_CID_EXPOSURE),
> +		MANDATORY_CONTROL(V4L2_CID_HBLANK),
> +		MANDATORY_CONTROL(V4L2_CID_PIXEL_RATE),
> +		MANDATORY_CONTROL(V4L2_CID_VBLANK),
> +#undef MANDATORY_CONTROL
>  	};
>  
>  	err = 0;
> -	for (uint32_t ctrl : mandatoryControls) {
> -		if (!controls.count(ctrl)) {
> +	for (auto &c : mandatoryControls) {
> +		if (!controls.count(c.ctrl)) {
>  			LOG(CameraSensor, Error)
> -				<< "Mandatory V4L2 control " << utils::hex(ctrl)
> +				<< "Mandatory V4L2 control " << c.name
>  				<< " not available";
>  			err = -EINVAL;
>  		}

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list