[libcamera-devel] [PATCH v2 4/7] libcamera: v4l2_pixelformat: Add helper function to get the description

Paul Elder paul.elder at ideasonboard.com
Wed Sep 8 10:14:34 CEST 2021


Add a helper function to V4L2PixelFormat for retrieving the V4L2
description string.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
 include/libcamera/internal/v4l2_pixelformat.h |  1 +
 src/libcamera/v4l2_pixelformat.cpp            | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h
index 36c690db..3b24bc73 100644
--- a/include/libcamera/internal/v4l2_pixelformat.h
+++ b/include/libcamera/internal/v4l2_pixelformat.h
@@ -40,6 +40,7 @@ public:
 	operator uint32_t() const { return fourcc_; }
 
 	std::string toString() const;
+	const char *toDescription() const;
 
 	PixelFormat toPixelFormat() const;
 	static V4L2PixelFormat fromPixelFormat(const PixelFormat &pixelFormat,
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 0a8312c4..f5598d9d 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -250,6 +250,23 @@ std::string V4L2PixelFormat::toString() const
 	return ss;
 }
 
+/**
+ * \brief Return the V4L2 description corresponding to the V4L2 format
+ * \return The V4L2 description corresponding to the V4L2 format
+ */
+const char *V4L2PixelFormat::toDescription() const
+{
+	const auto iter = vpf2pf.find(*this);
+	if (iter == vpf2pf.end()) {
+		LOG(V4L2, Warning)
+			<< "Unsupported V4L2 pixel format "
+			<< toString();
+		return "";
+	}
+
+	return iter->second.name;
+}
+
 /**
  * \brief Convert the V4L2 pixel format to the corresponding PixelFormat
  * \return The PixelFormat corresponding to the V4L2 pixel format
-- 
2.27.0



More information about the libcamera-devel mailing list