[libcamera-devel,v4,06/19] libcamera: ipu3: cio2: Report format and sizes

Message ID 20200720104736.19986-7-jacopo@jmondi.org
State Accepted
Headers show
Series
  • ipu3: rework pipe confiuguration
Related show

Commit Message

Jacopo Mondi July 20, 2020, 10:47 a.m. UTC
Add two methods to the CIO2Device class to retrieve all the supported
PixelFormats and sizes.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/cio2.cpp | 40 ++++++++++++++++++++++++++++
 src/libcamera/pipeline/ipu3/cio2.h   |  5 ++++
 2 files changed, 45 insertions(+)

Comments

Laurent Pinchart July 30, 2020, 4:40 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Mon, Jul 20, 2020 at 12:47:23PM +0200, Jacopo Mondi wrote:
> Add two methods to the CIO2Device class to retrieve all the supported
> PixelFormats and sizes.
> 
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

This feels a bit like an ad-hoc API, probably because it is :-) I'm sure
we'll rework the IPU3 code further, for now it should be fine.

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/pipeline/ipu3/cio2.cpp | 40 ++++++++++++++++++++++++++++
>  src/libcamera/pipeline/ipu3/cio2.h   |  5 ++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
> index 77f54da47e28..abe6d8a592d6 100644
> --- a/src/libcamera/pipeline/ipu3/cio2.cpp
> +++ b/src/libcamera/pipeline/ipu3/cio2.cpp
> @@ -10,6 +10,7 @@
>  #include <linux/media-bus-format.h>
>  
>  #include <libcamera/formats.h>
> +#include <libcamera/geometry.h>
>  #include <libcamera/stream.h>
>  
>  #include "libcamera/internal/camera_sensor.h"
> @@ -43,6 +44,45 @@ CIO2Device::~CIO2Device()
>  	delete sensor_;
>  }
>  
> +/**
> + * \brief Retrieve the list of supported PixelFormats
> + *
> + * Retrieve the list of supported pixel formats by matching the sensor produced
> + * media bus codes with the formats supported by the CIO2 unit.
> + *
> + * \return The list of supported PixelFormat
> + */
> +std::vector<PixelFormat> CIO2Device::formats() const
> +{
> +	if (!sensor_)
> +		return {};
> +
> +	std::vector<PixelFormat> formats;
> +	for (unsigned int code : sensor_->mbusCodes()) {
> +		auto it = mbusCodesToPixelFormat.find(code);
> +		if (it != mbusCodesToPixelFormat.end())
> +			formats.push_back(it->second);
> +	}
> +
> +	return formats;
> +}
> +
> +/**
> + * \brief Retrieve the list of supported size ranges
> + * \return The list of supported SizeRange
> + */
> +std::vector<SizeRange> CIO2Device::sizes() const
> +{
> +	if (!sensor_)
> +		return {};
> +
> +	std::vector<SizeRange> sizes;
> +	for (const Size &size : sensor_->sizes())
> +		sizes.emplace_back(size, size);
> +
> +	return sizes;
> +}
> +
>  /**
>   * \brief Initialize components of the CIO2 device with \a index
>   * \param[in] media The CIO2 media device
> diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h
> index 956355a0aa58..221cf817eee9 100644
> --- a/src/libcamera/pipeline/ipu3/cio2.h
> +++ b/src/libcamera/pipeline/ipu3/cio2.h
> @@ -20,8 +20,10 @@ namespace libcamera {
>  class CameraSensor;
>  class FrameBuffer;
>  class MediaDevice;
> +class PixelFormat;
>  class Request;
>  class Size;
> +class SizeRange;
>  class V4L2Subdevice;
>  struct StreamConfiguration;
>  
> @@ -33,6 +35,9 @@ public:
>  	CIO2Device();
>  	~CIO2Device();
>  
> +	std::vector<PixelFormat> formats() const;
> +	std::vector<SizeRange> sizes() const;
> +
>  	int init(const MediaDevice *media, unsigned int index);
>  	int configure(const Size &size, V4L2DeviceFormat *outputFormat);
>

Patch

diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
index 77f54da47e28..abe6d8a592d6 100644
--- a/src/libcamera/pipeline/ipu3/cio2.cpp
+++ b/src/libcamera/pipeline/ipu3/cio2.cpp
@@ -10,6 +10,7 @@ 
 #include <linux/media-bus-format.h>
 
 #include <libcamera/formats.h>
+#include <libcamera/geometry.h>
 #include <libcamera/stream.h>
 
 #include "libcamera/internal/camera_sensor.h"
@@ -43,6 +44,45 @@  CIO2Device::~CIO2Device()
 	delete sensor_;
 }
 
+/**
+ * \brief Retrieve the list of supported PixelFormats
+ *
+ * Retrieve the list of supported pixel formats by matching the sensor produced
+ * media bus codes with the formats supported by the CIO2 unit.
+ *
+ * \return The list of supported PixelFormat
+ */
+std::vector<PixelFormat> CIO2Device::formats() const
+{
+	if (!sensor_)
+		return {};
+
+	std::vector<PixelFormat> formats;
+	for (unsigned int code : sensor_->mbusCodes()) {
+		auto it = mbusCodesToPixelFormat.find(code);
+		if (it != mbusCodesToPixelFormat.end())
+			formats.push_back(it->second);
+	}
+
+	return formats;
+}
+
+/**
+ * \brief Retrieve the list of supported size ranges
+ * \return The list of supported SizeRange
+ */
+std::vector<SizeRange> CIO2Device::sizes() const
+{
+	if (!sensor_)
+		return {};
+
+	std::vector<SizeRange> sizes;
+	for (const Size &size : sensor_->sizes())
+		sizes.emplace_back(size, size);
+
+	return sizes;
+}
+
 /**
  * \brief Initialize components of the CIO2 device with \a index
  * \param[in] media The CIO2 media device
diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h
index 956355a0aa58..221cf817eee9 100644
--- a/src/libcamera/pipeline/ipu3/cio2.h
+++ b/src/libcamera/pipeline/ipu3/cio2.h
@@ -20,8 +20,10 @@  namespace libcamera {
 class CameraSensor;
 class FrameBuffer;
 class MediaDevice;
+class PixelFormat;
 class Request;
 class Size;
+class SizeRange;
 class V4L2Subdevice;
 struct StreamConfiguration;
 
@@ -33,6 +35,9 @@  public:
 	CIO2Device();
 	~CIO2Device();
 
+	std::vector<PixelFormat> formats() const;
+	std::vector<SizeRange> sizes() const;
+
 	int init(const MediaDevice *media, unsigned int index);
 	int configure(const Size &size, V4L2DeviceFormat *outputFormat);