[libcamera-devel] [PATCH 2/4] libcamera: v4l2_pixelformat: Use multiplanar if single is unavailable

Paul Elder paul.elder at ideasonboard.com
Thu Jul 7 17:03:08 CEST 2022


Some formats, such as YVU422 (but *not* YUV422), YUV444, and YVU444,
have only a multiplanar v4l2 format and no singleplanar format. When
using V4L2PixelFormat::fromPixelFormat() to convert a libcamera format
to V4L2PixelFormat, the default is to fetch the singleplanar format, and
for those three formats an invalid format will be returned. The caller
shouldn't be expected to check first if it should request the
singleplanar or multiplanar version (that's the whole point of
V4L2PixelFormat::fromPixelFormat()), so the solution that this patch
implements is if fetching singleplanar/multiplanar fails, try fetching
the other one.

The side effect is that as most formats have only singleplanar v4l2
format and no multiplanar format, if a multiplanar format is request for
these formats then the singleplanar one will be automatically returned.
Since currently all callers of V4L2PixelFormat::fromPixelFormat() use
the default singleplanar call, it is reasoned that this is not an issue.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
 src/libcamera/v4l2_pixelformat.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 58fc4e9d..0d2bc350 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -321,7 +321,14 @@ V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat,
 	if (!info.isValid())
 		return V4L2PixelFormat();
 
-	return multiplanar ? info.v4l2Formats.multi : info.v4l2Formats.single;
+	V4L2PixelFormat ret = multiplanar ? info.v4l2Formats.multi
+					  : info.v4l2Formats.single;
+	/* Try the other of multi/single if the proper one doesn't exist */
+	if (!ret.isValid())
+		ret = multiplanar ? info.v4l2Formats.single
+				  : info.v4l2Formats.multi;
+
+	return ret;
 }
 
 /**
-- 
2.30.2



More information about the libcamera-devel mailing list