[libcamera-devel] [RFC PATCH v1 04/12] libcamera: formats: Support V4L2 non-contiguous formats

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Sep 2 20:36:36 CEST 2021


Hi Kieran,

On Thu, Sep 02, 2021 at 10:23:48AM +0100, Kieran Bingham wrote:
> On 02/09/2021 05:22, Laurent Pinchart wrote:
> > V4L2 describes multi-planar formats with different 4CCs depending on
> > whether or not the planes are stored contiguously in memory. Support
> > this when translating between PixelFormat and V4L2PixelFormat.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> > ---
> >  include/libcamera/internal/formats.h |   2 +-
> >  src/libcamera/formats.cpp            | 141 ++++++++++++++++-----------
> >  src/libcamera/pipeline/ipu3/cio2.cpp |   2 +-
> >  src/libcamera/v4l2_pixelformat.cpp   |  11 ++-
> >  src/v4l2/v4l2_camera_proxy.cpp       |   6 +-
> >  5 files changed, 99 insertions(+), 63 deletions(-)
> > 
> > diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h
> > index 8f314e99889b..f9ce5f0834fa 100644
> > --- a/include/libcamera/internal/formats.h
> > +++ b/include/libcamera/internal/formats.h
> > @@ -55,7 +55,7 @@ public:
> >  	/* \todo Add support for non-contiguous memory planes */
> >  	const char *name;
> >  	PixelFormat format;
> > -	V4L2PixelFormat v4l2Format;
> > +	std::array<V4L2PixelFormat, 2> v4l2Format;
> 
> As discussed below, I'm curious if a struct would be clearer here and
> help prevent bugs later...
> 
> 	struct {
> 		V4L2PixelFormat planar;
> 		V4L2PixelFormat multiplanar;
> 	} v4l2Format;
> 
> >  	unsigned int bitsPerPixel;
> >  	enum ColourEncoding colourEncoding;
> >  	bool packed;
> > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
> > index 76be93bc1c5c..ce7c5a2d267e 100644
> > --- a/src/libcamera/formats.cpp
> > +++ b/src/libcamera/formats.cpp
> > @@ -56,7 +56,14 @@ LOG_DEFINE_CATEGORY(Formats)
> >   * \brief The PixelFormat described by this instance
> >   *
> >   * \var PixelFormatInfo::v4l2Format
> > - * \brief The V4L2 pixel format corresponding to the PixelFormat
> > + * \brief The V4L2 pixel formats corresponding to the PixelFormat
> > + *
> > + * Multiple V4L2 formats may exist for one PixelFormat when the format uses
> > + * multiple planes, as V4L2 defines separate 4CCs for contiguous and separate
> > + * planes formats. The two entries in the array store the contiguous and
> > + * non-contiguous V4L2 formats respectively. If the PixelFormat isn't a
> > + * multiplanar format, or if no corresponding non-contiguous V4L2 format
> > + * exists, the second entry is invalid.
> >   *
> >   * \var PixelFormatInfo::bitsPerPixel
> >   * \brief The average number of bits per pixel
> > @@ -149,7 +156,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::RGB565, {
> >  		.name = "RGB565",
> >  		.format = formats::RGB565,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_RGB565), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -159,7 +166,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::RGB565_BE, {
> >  		.name = "RGB565_BE",
> >  		.format = formats::RGB565_BE,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB565X),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_RGB565X), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -169,7 +176,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::BGR888, {
> >  		.name = "BGR888",
> >  		.format = formats::BGR888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_RGB24), },
> >  		.bitsPerPixel = 24,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -179,7 +186,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::RGB888, {
> >  		.name = "RGB888",
> >  		.format = formats::RGB888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_BGR24), },
> >  		.bitsPerPixel = 24,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -189,7 +196,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::XRGB8888, {
> >  		.name = "XRGB8888",
> >  		.format = formats::XRGB8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_XBGR32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_XBGR32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -199,7 +206,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::XBGR8888, {
> >  		.name = "XBGR8888",
> >  		.format = formats::XBGR8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBX32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_RGBX32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -209,7 +216,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::BGRX8888, {
> >  		.name = "BGRX8888",
> >  		.format = formats::BGRX8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_XRGB32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_XRGB32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -219,7 +226,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::ABGR8888, {
> >  		.name = "ABGR8888",
> >  		.format = formats::ABGR8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_RGBA32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -229,7 +236,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::ARGB8888, {
> >  		.name = "ARGB8888",
> >  		.format = formats::ARGB8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_ABGR32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -239,7 +246,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::BGRA8888, {
> >  		.name = "BGRA8888",
> >  		.format = formats::BGRA8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_ARGB32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -249,7 +256,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::RGBA8888, {
> >  		.name = "RGBA8888",
> >  		.format = formats::RGBA8888,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_BGRA32), },
> >  		.bitsPerPixel = 32,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRGB,
> >  		.packed = false,
> > @@ -261,7 +268,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::YUYV, {
> >  		.name = "YUYV",
> >  		.format = formats::YUYV,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_YUYV), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -271,7 +278,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::YVYU, {
> >  		.name = "YVYU",
> >  		.format = formats::YVYU,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_YVYU), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -281,7 +288,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::UYVY, {
> >  		.name = "UYVY",
> >  		.format = formats::UYVY,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_UYVY), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -291,7 +298,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::VYUY, {
> >  		.name = "VYUY",
> >  		.format = formats::VYUY,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_VYUY), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -303,7 +310,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::NV12, {
> >  		.name = "NV12",
> >  		.format = formats::NV12,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV12),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV12M),
> > +		},
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -313,7 +323,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::NV21, {
> >  		.name = "NV21",
> >  		.format = formats::NV21,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV21),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV21M),
> > +		},
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -323,7 +336,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::NV16, {
> >  		.name = "NV16",
> >  		.format = formats::NV16,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV16),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV16M),
> > +		},
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -333,7 +349,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::NV61, {
> >  		.name = "NV61",
> >  		.format = formats::NV61,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV61),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_NV61M),
> > +		},
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -343,7 +362,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::NV24, {
> >  		.name = "NV24",
> >  		.format = formats::NV24,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV24),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_NV24), },
> >  		.bitsPerPixel = 24,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -353,7 +372,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::NV42, {
> >  		.name = "NV42",
> >  		.format = formats::NV42,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV42),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_NV42), },
> >  		.bitsPerPixel = 24,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -363,7 +382,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::YUV420, {
> >  		.name = "YUV420",
> >  		.format = formats::YUV420,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_YUV420),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_YUV420M),
> > +		},
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -373,7 +395,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::YVU420, {
> >  		.name = "YVU420",
> >  		.format = formats::YVU420,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVU420),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_YVU420),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_YVU420M),
> > +		},
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -383,7 +408,10 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::YUV422, {
> >  		.name = "YUV422",
> >  		.format = formats::YUV422,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P),
> > +		.v4l2Format = {
> > +			V4L2PixelFormat(V4L2_PIX_FMT_YUV422P),
> > +			V4L2PixelFormat(V4L2_PIX_FMT_YUV422M),
> > +		},
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -395,7 +423,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::R8, {
> >  		.name = "R8",
> >  		.format = formats::R8,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_GREY), },
> >  		.bitsPerPixel = 8,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -407,7 +435,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR8, {
> >  		.name = "SBGGR8",
> >  		.format = formats::SBGGR8,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8), },
> >  		.bitsPerPixel = 8,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -417,7 +445,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG8, {
> >  		.name = "SGBRG8",
> >  		.format = formats::SGBRG8,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8), },
> >  		.bitsPerPixel = 8,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -427,7 +455,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG8, {
> >  		.name = "SGRBG8",
> >  		.format = formats::SGRBG8,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8), },
> >  		.bitsPerPixel = 8,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -437,7 +465,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB8, {
> >  		.name = "SRGGB8",
> >  		.format = formats::SRGGB8,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8), },
> >  		.bitsPerPixel = 8,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -447,7 +475,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR10, {
> >  		.name = "SBGGR10",
> >  		.format = formats::SBGGR10,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -457,7 +485,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG10, {
> >  		.name = "SGBRG10",
> >  		.format = formats::SGBRG10,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -467,7 +495,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG10, {
> >  		.name = "SGRBG10",
> >  		.format = formats::SGRBG10,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -477,7 +505,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB10, {
> >  		.name = "SRGGB10",
> >  		.format = formats::SRGGB10,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -487,7 +515,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR10_CSI2P, {
> >  		.name = "SBGGR10_CSI2P",
> >  		.format = formats::SBGGR10_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -497,7 +525,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG10_CSI2P, {
> >  		.name = "SGBRG10_CSI2P",
> >  		.format = formats::SGBRG10_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -507,7 +535,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG10_CSI2P, {
> >  		.name = "SGRBG10_CSI2P",
> >  		.format = formats::SGRBG10_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -517,7 +545,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB10_CSI2P, {
> >  		.name = "SRGGB10_CSI2P",
> >  		.format = formats::SRGGB10_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -527,7 +555,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR12, {
> >  		.name = "SBGGR12",
> >  		.format = formats::SBGGR12,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -537,7 +565,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG12, {
> >  		.name = "SGBRG12",
> >  		.format = formats::SGBRG12,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -547,7 +575,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG12, {
> >  		.name = "SGRBG12",
> >  		.format = formats::SGRBG12,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -557,7 +585,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB12, {
> >  		.name = "SRGGB12",
> >  		.format = formats::SRGGB12,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -567,7 +595,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR12_CSI2P, {
> >  		.name = "SBGGR12_CSI2P",
> >  		.format = formats::SBGGR12_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR12P), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -577,7 +605,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG12_CSI2P, {
> >  		.name = "SGBRG12_CSI2P",
> >  		.format = formats::SGBRG12_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG12P), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -587,7 +615,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG12_CSI2P, {
> >  		.name = "SGRBG12_CSI2P",
> >  		.format = formats::SGRBG12_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG12P), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -597,7 +625,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB12_CSI2P, {
> >  		.name = "SRGGB12_CSI2P",
> >  		.format = formats::SRGGB12_CSI2P,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB12P), },
> >  		.bitsPerPixel = 12,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -607,7 +635,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR16, {
> >  		.name = "SBGGR16",
> >  		.format = formats::SBGGR16,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SBGGR16), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -617,7 +645,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG16, {
> >  		.name = "SGBRG16",
> >  		.format = formats::SGBRG16,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGBRG16), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -627,7 +655,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG16, {
> >  		.name = "SGRBG16",
> >  		.format = formats::SGRBG16,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SGRBG16), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -637,7 +665,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB16, {
> >  		.name = "SRGGB16",
> >  		.format = formats::SRGGB16,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16), },
> >  		.bitsPerPixel = 16,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = false,
> > @@ -647,7 +675,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SBGGR10_IPU3, {
> >  		.name = "SBGGR10_IPU3",
> >  		.format = formats::SBGGR10_IPU3,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -658,7 +686,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGBRG10_IPU3, {
> >  		.name = "SGBRG10_IPU3",
> >  		.format = formats::SGBRG10_IPU3,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -668,7 +696,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SGRBG10_IPU3, {
> >  		.name = "SGRBG10_IPU3",
> >  		.format = formats::SGRBG10_IPU3,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -678,7 +706,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::SRGGB10_IPU3, {
> >  		.name = "SRGGB10_IPU3",
> >  		.format = formats::SRGGB10_IPU3,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10), },
> >  		.bitsPerPixel = 10,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingRAW,
> >  		.packed = true,
> > @@ -690,7 +718,7 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
> >  	{ formats::MJPEG, {
> >  		.name = "MJPEG",
> >  		.format = formats::MJPEG,
> > -		.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),
> > +		.v4l2Format = { V4L2PixelFormat(V4L2_PIX_FMT_MJPEG), },
> >  		.bitsPerPixel = 0,
> >  		.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
> >  		.packed = false,
> > @@ -736,7 +764,8 @@ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
> >  {
> >  	const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
> >  					[format](auto pair) {
> > -						return pair.second.v4l2Format == format;
> > +						return pair.second.v4l2Format[0] == format ||
> > +						       pair.second.v4l2Format[1] == format;
> >  					});
> >  	if (info == pixelFormatInfo.end())
> >  		return pixelFormatInfoInvalid;
> > diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
> > index 9cedcb5b2879..5a9cffc80c8d 100644
> > --- a/src/libcamera/pipeline/ipu3/cio2.cpp
> > +++ b/src/libcamera/pipeline/ipu3/cio2.cpp
> > @@ -205,7 +205,7 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat)
> >  
> >  	const PixelFormatInfo &info = PixelFormatInfo::info(itInfo->second);
> >  
> > -	outputFormat->fourcc = info.v4l2Format;
> > +	outputFormat->fourcc = info.v4l2Format[0];
> >  	outputFormat->size = sensorFormat.size;
> >  	outputFormat->planesCount = 1;
> >  
> > diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
> > index 93fc4446cc64..93ead8928ed7 100644
> > --- a/src/libcamera/v4l2_pixelformat.cpp
> > +++ b/src/libcamera/v4l2_pixelformat.cpp
> > @@ -67,12 +67,19 @@ const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
> >  
> >  	/* YUV planar formats. */
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_NV16), formats::NV16 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_NV16M), formats::NV16 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_NV61), formats::NV61 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_NV61M), formats::NV61 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_NV12), formats::NV12 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_NV12M), formats::NV12 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_NV21), formats::NV21 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_NV21M), formats::NV21 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_YUV420), formats::YUV420 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_YUV420M), formats::YUV420 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_YVU420), formats::YVU420 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_YVU420M), formats::YVU420 },
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), formats::YUV422 },
> > +	{ V4L2PixelFormat(V4L2_PIX_FMT_YUV422M), formats::YUV422 },
> 
> I'm worried that we're losing information here.
> But presumably it's handled by whether we use mplane or not on the
> device...?

We don't expose to applications whether the camera requires contiguous
buffers or can support non-contiguous buffers. We don't otherwise lose
information, as we pick a specific V4L2 format from the PixelFormat,
based on an explicit selection of multiplanar or singleplanar V4L2
format by the pipeline handler.

> >  	/* Greyscale formats. */
> >  	{ V4L2PixelFormat(V4L2_PIX_FMT_GREY), formats::R8 },
> > @@ -202,13 +209,13 @@ PixelFormat V4L2PixelFormat::toPixelFormat() const
> >   * \return The V4L2PixelFormat corresponding to \a pixelFormat
> >   */
> >  V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat,
> > -						 [[maybe_unused]] bool multiplanar)
> > +						 bool multiplanar)
> >  {
> >  	const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);
> >  	if (!info.isValid())
> >  		return V4L2PixelFormat();
> >  
> > -	return info.v4l2Format;
> > +	return info.v4l2Format[multiplanar ? 1 : 0];
> 
> I was going to say, a struct with named fields of 'planar', and
> 'multiplanar' might be a better, though I like the simplicity of this bit.

Would be easy to rewrite though.

> >  }
> >  
> >  } /* namespace libcamera */
> > diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> > index 7682c4bddf90..8d8ee395954f 100644
> > --- a/src/v4l2/v4l2_camera_proxy.cpp
> > +++ b/src/v4l2/v4l2_camera_proxy.cpp
> > @@ -169,7 +169,7 @@ void V4L2CameraProxy::setFmtFromConfig(const StreamConfiguration &streamConfig)
> >  
> >  	v4l2PixFormat_.width        = size.width;
> >  	v4l2PixFormat_.height       = size.height;
> > -	v4l2PixFormat_.pixelformat  = info.v4l2Format;
> > +	v4l2PixFormat_.pixelformat  = info.v4l2Format[0];
> >  	v4l2PixFormat_.field        = V4L2_FIELD_NONE;
> >  	v4l2PixFormat_.bytesperline = streamConfig.stride;
> >  	v4l2PixFormat_.sizeimage    = streamConfig.frameSize;
> > @@ -276,7 +276,7 @@ int V4L2CameraProxy::vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc *
> >  	/* \todo Add map from format to description. */
> >  	utils::strlcpy(reinterpret_cast<char *>(arg->description),
> >  		       "Video Format Description", sizeof(arg->description));
> > -	arg->pixelformat = PixelFormatInfo::info(format).v4l2Format;
> > +	arg->pixelformat = PixelFormatInfo::info(format).v4l2Format[0];
> >  
> >  	memset(arg->reserved, 0, sizeof(arg->reserved));
> >  
> > @@ -315,7 +315,7 @@ int V4L2CameraProxy::tryFormat(struct v4l2_format *arg)
> >  
> >  	arg->fmt.pix.width        = config.size.width;
> >  	arg->fmt.pix.height       = config.size.height;
> > -	arg->fmt.pix.pixelformat  = info.v4l2Format;
> > +	arg->fmt.pix.pixelformat  = info.v4l2Format[0];
> 
> But for occasions like here, and in the CIO2
> 	arg->fmt.pix.pixelformat  = info.v4l2Format.planar;
> 
> Would be far more descriptive over which one is being chosen, and might
> help make it easier to spot issues when debugging multiplanar format
> bugs ...

I agree. I don't like the names "planar" and "multiplanar" though, as
that's a bit ambiguous. V4L2 did a really bad job when it comes to
naming here. I'll try to think of better names after sleeping over it,
but please feel free to suggest alternatives :-) Bonus points of they're
short and have the same length :-)

> >  	arg->fmt.pix.field        = V4L2_FIELD_NONE;
> >  	arg->fmt.pix.bytesperline = config.stride;
> >  	arg->fmt.pix.sizeimage    = config.frameSize;
> > 

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list