[libcamera-devel] [PATCH] libcamera: v4l2: Pass set colorspace flags

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Jul 31 22:17:44 CEST 2022


Hi Umang,

Thank you for the patch.

On Fri, Jul 29, 2022 at 08:20:42PM +0530, Umang Jain via libcamera-devel wrote:
> The colorspace fields as read-only from an application point of view,

s/as read-only/are read-only/

> both on video devices and on subdevs, unless the
> V4L2_PIX_FMT_FLAG_SET_CSC or V4L2_MBUS_FRAMEFMT_SET_CSC flags
> (respectively) are set when calling the S_FMT ioctl.
> 
> Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
>  src/libcamera/v4l2_subdevice.cpp   | 3 ++-
>  src/libcamera/v4l2_videodevice.cpp | 6 ++++--
>  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 98a3911a..815c676e 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -459,7 +459,8 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
>  	subdevFmt.format.height = format->size.height;
>  	subdevFmt.format.code = format->mbus_code;
>  	subdevFmt.format.field = V4L2_FIELD_NONE;
> -	fromColorSpace(format->colorSpace, subdevFmt.format);
> +	if (fromColorSpace(format->colorSpace, subdevFmt.format) == 0)

If format->colorSpace is nullopt, should be set the CSC flag ?

> +		subdevFmt.format.flags |= V4L2_MBUS_FRAMEFMT_SET_CSC;

The flag is meant for source pads only, can you avoid setting it on sink
pads ?

>  
>  	int ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);
>  	if (ret) {
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 63911339..a969f7fa 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -940,7 +940,8 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)
>  	pix->pixelformat = format->fourcc;
>  	pix->num_planes = format->planesCount;
>  	pix->field = V4L2_FIELD_NONE;
> -	fromColorSpace(format->colorSpace, *pix);
> +	if (fromColorSpace(format->colorSpace, *pix) == 0)
> +		pix->flags |= V4L2_PIX_FMT_FLAG_SET_CSC;

Similarly, the CSC flag is meant for capture devices only.

>  
>  	ASSERT(pix->num_planes <= std::size(pix->plane_fmt));
>  
> @@ -1010,7 +1011,8 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)
>  	pix->pixelformat = format->fourcc;
>  	pix->bytesperline = format->planes[0].bpl;
>  	pix->field = V4L2_FIELD_NONE;
> -	fromColorSpace(format->colorSpace, *pix);
> +	if (fromColorSpace(format->colorSpace, *pix) == 0)
> +		pix->flags |= V4L2_PIX_FMT_FLAG_SET_CSC;
>  
>  	ret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);
>  	if (ret) {

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list