[libcamera-devel,v3,4/7] libcamera: v4l2_pixelformat: Add helper function to get the description
diff mbox series

Message ID 20210909080902.239533-5-paul.elder@ideasonboard.com
State Accepted
Headers show
Series
  • v4l2-compat fixes
Related show

Commit Message

Paul Elder Sept. 9, 2021, 8:08 a.m. UTC
Add a helper function to V4L2PixelFormat for retrieving the V4L2
description string.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/internal/v4l2_pixelformat.h |  1 +
 src/libcamera/v4l2_pixelformat.cpp            | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+)

Comments

Jean-Michel Hautbois Sept. 9, 2021, 8:34 a.m. UTC | #1
Hi Paul,

On 09/09/2021 10:08, Paul Elder wrote:
> Add a helper function to V4L2PixelFormat for retrieving the V4L2
> description string.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  include/libcamera/internal/v4l2_pixelformat.h |  1 +
>  src/libcamera/v4l2_pixelformat.cpp            | 21 +++++++++++++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h
> index 87872542..e3cda699 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 *description() 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 2c8167a7..fed31238 100644
> --- a/src/libcamera/v4l2_pixelformat.cpp
> +++ b/src/libcamera/v4l2_pixelformat.cpp
> @@ -250,6 +250,27 @@ std::string V4L2PixelFormat::toString() const
>  	return ss;
>  }
>  
> +/**
> + * \brief Retrieve the V4L2 description for the format
> + *
> + * The description matches the value used by the kernel, as would be reported
> + * by the VIDIOC_ENUM_FMT ioctl.
> + *
> + * \return The V4L2 description corresponding to the V4L2 format
Or an error message if not found ?

Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> + */
> +const char *V4L2PixelFormat::description() const
> +{
> +	const auto iter = vpf2pf.find(*this);
> +	if (iter == vpf2pf.end()) {
> +		LOG(V4L2, Warning)
> +			<< "Unsupported V4L2 pixel format "
> +			<< toString();
> +		return "Unsupported format";
> +	}
> +
> +	return iter->second.description;
> +}
> +
>  /**
>   * \brief Convert the V4L2 pixel format to the corresponding PixelFormat
>   * \return The PixelFormat corresponding to the V4L2 pixel format
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h
index 87872542..e3cda699 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 *description() 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 2c8167a7..fed31238 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -250,6 +250,27 @@  std::string V4L2PixelFormat::toString() const
 	return ss;
 }
 
+/**
+ * \brief Retrieve the V4L2 description for the format
+ *
+ * The description matches the value used by the kernel, as would be reported
+ * by the VIDIOC_ENUM_FMT ioctl.
+ *
+ * \return The V4L2 description corresponding to the V4L2 format
+ */
+const char *V4L2PixelFormat::description() const
+{
+	const auto iter = vpf2pf.find(*this);
+	if (iter == vpf2pf.end()) {
+		LOG(V4L2, Warning)
+			<< "Unsupported V4L2 pixel format "
+			<< toString();
+		return "Unsupported format";
+	}
+
+	return iter->second.description;
+}
+
 /**
  * \brief Convert the V4L2 pixel format to the corresponding PixelFormat
  * \return The PixelFormat corresponding to the V4L2 pixel format