[libcamera-devel] [RFC 6/6] v4l2: camera_proxy: Switch to PixelFormat

Niklas Söderlund niklas.soderlund at ragnatech.se
Fri Feb 28 04:29:13 CET 2020


Remove proxies for PixelFormat and use the interface directly.

Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
 src/v4l2/v4l2_camera_proxy.cpp | 28 +++++++++-------------------
 src/v4l2/v4l2_camera_proxy.h   |  3 ---
 2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index e9d7bfd8ee243b78..7ea3039e0455c3f9 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -141,7 +141,7 @@ void V4L2CameraProxy::setFmtFromConfig(StreamConfiguration &streamConfig)
 {
 	curV4L2Format_.fmt.pix.width = streamConfig.size.width;
 	curV4L2Format_.fmt.pix.height = streamConfig.size.height;
-	curV4L2Format_.fmt.pix.pixelformat = drmToV4L2(streamConfig.pixelFormat);
+	curV4L2Format_.fmt.pix.pixelformat = streamConfig.pixelFormat.v4l2();
 	curV4L2Format_.fmt.pix.field = V4L2_FIELD_NONE;
 	curV4L2Format_.fmt.pix.bytesperline =
 		bplMultiplier(curV4L2Format_.fmt.pix.pixelformat) *
@@ -159,7 +159,7 @@ unsigned int V4L2CameraProxy::calculateSizeImage(StreamConfiguration &streamConf
 	 * \todo Merge this method with setFmtFromConfig (need imageSize to
 	 * support all libcamera formats first, or filter out MJPEG for now).
 	 */
-	return imageSize(drmToV4L2(streamConfig.pixelFormat),
+	return imageSize(streamConfig.pixelFormat.v4l2(),
 			 streamConfig.size.width,
 			 streamConfig.size.height);
 }
@@ -229,7 +229,7 @@ int V4L2CameraProxy::vidioc_enum_fmt(struct v4l2_fmtdesc *arg)
 	/* \todo Add map from format to description. */
 	utils::strlcpy(reinterpret_cast<char *>(arg->description), "Video Format Description",
 		       sizeof(arg->description));
-	arg->pixelformat = drmToV4L2(streamConfig_.formats().pixelformats()[arg->index]);
+	arg->pixelformat = streamConfig_.formats().pixelformats()[arg->index].v4l2();
 
 	return 0;
 }
@@ -249,7 +249,7 @@ int V4L2CameraProxy::vidioc_g_fmt(struct v4l2_format *arg)
 
 void V4L2CameraProxy::tryFormat(struct v4l2_format *arg)
 {
-	PixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat);
+	PixelFormat format = PixelFormat(arg->fmt.pix.pixelformat);
 	const std::vector<PixelFormat> &formats =
 		streamConfig_.formats().pixelformats();
 	if (std::find(formats.begin(), formats.end(), format) == formats.end())
@@ -262,11 +262,11 @@ void V4L2CameraProxy::tryFormat(struct v4l2_format *arg)
 
 	arg->fmt.pix.width        = size.width;
 	arg->fmt.pix.height       = size.height;
-	arg->fmt.pix.pixelformat  = drmToV4L2(format);
+	arg->fmt.pix.pixelformat  = format.v4l2();
 	arg->fmt.pix.field        = V4L2_FIELD_NONE;
-	arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) *
+	arg->fmt.pix.bytesperline = bplMultiplier(format.v4l2()) *
 				    arg->fmt.pix.width;
-	arg->fmt.pix.sizeimage    = imageSize(drmToV4L2(format),
+	arg->fmt.pix.sizeimage    = imageSize(format.v4l2(),
 					      arg->fmt.pix.width,
 					      arg->fmt.pix.height);
 	arg->fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;
@@ -283,7 +283,7 @@ int V4L2CameraProxy::vidioc_s_fmt(struct v4l2_format *arg)
 
 	Size size(arg->fmt.pix.width, arg->fmt.pix.height);
 	int ret = vcam_->configure(&streamConfig_, size,
-				   v4l2ToDrm(arg->fmt.pix.pixelformat),
+				   PixelFormat(arg->fmt.pix.pixelformat),
 				   bufferCount_);
 	if (ret < 0)
 		return -EINVAL;
@@ -345,7 +345,7 @@ int V4L2CameraProxy::vidioc_reqbufs(struct v4l2_requestbuffers *arg)
 
 	Size size(curV4L2Format_.fmt.pix.width, curV4L2Format_.fmt.pix.height);
 	ret = vcam_->configure(&streamConfig_, size,
-			       v4l2ToDrm(curV4L2Format_.fmt.pix.pixelformat),
+			       PixelFormat(curV4L2Format_.fmt.pix.pixelformat),
 			       arg->count);
 	if (ret < 0)
 		return -EINVAL;
@@ -584,13 +584,3 @@ unsigned int V4L2CameraProxy::imageSize(uint32_t format, unsigned int width,
 
 	return width * height * multiplier / 8;
 }
-
-PixelFormat V4L2CameraProxy::v4l2ToDrm(uint32_t format)
-{
-	return PixelFormat(format);
-}
-
-uint32_t V4L2CameraProxy::drmToV4L2(PixelFormat format)
-{
-	return format.v4l2();
-}
diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h
index c8e61adf80f1b93b..03495d6266ef610a 100644
--- a/src/v4l2/v4l2_camera_proxy.h
+++ b/src/v4l2/v4l2_camera_proxy.h
@@ -59,9 +59,6 @@ private:
 	static unsigned int imageSize(uint32_t format, unsigned int width,
 				      unsigned int height);
 
-	static PixelFormat v4l2ToDrm(uint32_t format);
-	static uint32_t drmToV4L2(PixelFormat format);
-
 	unsigned int refcount_;
 	unsigned int index_;
 	bool nonBlocking_;
-- 
2.25.1



More information about the libcamera-devel mailing list