[libcamera-devel,03/15] libcamera: ipu3: cio2: Report format and sizes

Message ID 20200701123036.51922-4-jacopo@jmondi.org
State Accepted
Headers show
Series
  • libcamera: ipu3: Rework streams configuration
Related show

Commit Message

Jacopo Mondi July 1, 2020, 12:30 p.m. UTC
Add two methods to the CIO2Device class to retrieve all the supported
PixelFormats and sizes.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/cio2.cpp | 43 +++++++++++++++++++++++++++-
 src/libcamera/pipeline/ipu3/cio2.h   |  7 +++++
 2 files changed, 49 insertions(+), 1 deletion(-)

Comments

Niklas Söderlund July 1, 2020, 4:23 p.m. UTC | #1
Hi Jacopo,

Thanks for your work.

On 2020-07-01 14:30:24 +0200, Jacopo Mondi wrote:
> Add two methods to the CIO2Device class to retrieve all the supported
> PixelFormats and sizes.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/libcamera/pipeline/ipu3/cio2.cpp | 43 +++++++++++++++++++++++++++-
>  src/libcamera/pipeline/ipu3/cio2.h   |  7 +++++
>  2 files changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
> index 2ec8fcb42d92..b34194c5097f 100644
> --- a/src/libcamera/pipeline/ipu3/cio2.cpp
> +++ b/src/libcamera/pipeline/ipu3/cio2.cpp
> @@ -33,7 +33,7 @@ static const std::map<uint32_t, PixelFormat> mbusCodesToPixelFormat = {
>  } /* namespace */
>  
>  CIO2Device::CIO2Device()
> -	: sensor_(nullptr), csi2_(nullptr), output_(nullptr)
> +	: sensor_(nullptr), csi2_(nullptr), output_(nullptr), initialized_(false)
>  {
>  }
>  
> @@ -44,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 (!initialized_)
> +		return {};

Would it not be neater to check if sensor_ is null or not?

> +
> +	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 (!initialized_)
> +		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
> @@ -127,6 +166,8 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)
>  
>  	output_->bufferReady.connect(this, &CIO2Device::cio2BufferReady);
>  
> +	initialized_ = true;
> +
>  	return 0;
>  }
>  
> diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h
> index dc764b101f11..7e793e8450f5 100644
> --- a/src/libcamera/pipeline/ipu3/cio2.h
> +++ b/src/libcamera/pipeline/ipu3/cio2.h
> @@ -18,7 +18,9 @@ namespace libcamera {
>  class CameraSensor;
>  class FrameBuffer;
>  class MediaDevice;
> +class PixelFormat;
>  class Request;
> +class SizeRange;
>  class V4L2DeviceFormat;
>  class V4L2Subdevice;
>  class V4L2VideoDevice;
> @@ -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);
>  
> @@ -61,6 +66,8 @@ private:
>  
>  	std::vector<std::unique_ptr<FrameBuffer>> buffers_;
>  	std::queue<FrameBuffer *> availableBuffers_;
> +
> +	bool initialized_;
>  };
>  
>  } /* namespace libcamera */
> -- 
> 2.27.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Jacopo Mondi July 2, 2020, 7:34 a.m. UTC | #2
Hi Niklas,

On Wed, Jul 01, 2020 at 06:23:49PM +0200, Niklas Söderlund wrote:
> Hi Jacopo,
>
> Thanks for your work.
>
> On 2020-07-01 14:30:24 +0200, Jacopo Mondi wrote:
> > Add two methods to the CIO2Device class to retrieve all the supported
> > PixelFormats and sizes.
> >
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > ---
> >  src/libcamera/pipeline/ipu3/cio2.cpp | 43 +++++++++++++++++++++++++++-
> >  src/libcamera/pipeline/ipu3/cio2.h   |  7 +++++
> >  2 files changed, 49 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
> > index 2ec8fcb42d92..b34194c5097f 100644
> > --- a/src/libcamera/pipeline/ipu3/cio2.cpp
> > +++ b/src/libcamera/pipeline/ipu3/cio2.cpp
> > @@ -33,7 +33,7 @@ static const std::map<uint32_t, PixelFormat> mbusCodesToPixelFormat = {
> >  } /* namespace */
> >
> >  CIO2Device::CIO2Device()
> > -	: sensor_(nullptr), csi2_(nullptr), output_(nullptr)
> > +	: sensor_(nullptr), csi2_(nullptr), output_(nullptr), initialized_(false)
> >  {
> >  }
> >
> > @@ -44,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 (!initialized_)
> > +		return {};
>
> Would it not be neater to check if sensor_ is null or not?
>

Ah yes, it would, and it would save the initialized_ flag.
Thanks for suggestion.

> > +
> > +	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 (!initialized_)
> > +		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
> > @@ -127,6 +166,8 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)
> >
> >  	output_->bufferReady.connect(this, &CIO2Device::cio2BufferReady);
> >
> > +	initialized_ = true;
> > +
> >  	return 0;
> >  }
> >
> > diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h
> > index dc764b101f11..7e793e8450f5 100644
> > --- a/src/libcamera/pipeline/ipu3/cio2.h
> > +++ b/src/libcamera/pipeline/ipu3/cio2.h
> > @@ -18,7 +18,9 @@ namespace libcamera {
> >  class CameraSensor;
> >  class FrameBuffer;
> >  class MediaDevice;
> > +class PixelFormat;
> >  class Request;
> > +class SizeRange;
> >  class V4L2DeviceFormat;
> >  class V4L2Subdevice;
> >  class V4L2VideoDevice;
> > @@ -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);
> >
> > @@ -61,6 +66,8 @@ private:
> >
> >  	std::vector<std::unique_ptr<FrameBuffer>> buffers_;
> >  	std::queue<FrameBuffer *> availableBuffers_;
> > +
> > +	bool initialized_;
> >  };
> >
> >  } /* namespace libcamera */
> > --
> > 2.27.0
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel
>
> --
> Regards,
> Niklas Söderlund

Patch

diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
index 2ec8fcb42d92..b34194c5097f 100644
--- a/src/libcamera/pipeline/ipu3/cio2.cpp
+++ b/src/libcamera/pipeline/ipu3/cio2.cpp
@@ -33,7 +33,7 @@  static const std::map<uint32_t, PixelFormat> mbusCodesToPixelFormat = {
 } /* namespace */
 
 CIO2Device::CIO2Device()
-	: sensor_(nullptr), csi2_(nullptr), output_(nullptr)
+	: sensor_(nullptr), csi2_(nullptr), output_(nullptr), initialized_(false)
 {
 }
 
@@ -44,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 (!initialized_)
+		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 (!initialized_)
+		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
@@ -127,6 +166,8 @@  int CIO2Device::init(const MediaDevice *media, unsigned int index)
 
 	output_->bufferReady.connect(this, &CIO2Device::cio2BufferReady);
 
+	initialized_ = true;
+
 	return 0;
 }
 
diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h
index dc764b101f11..7e793e8450f5 100644
--- a/src/libcamera/pipeline/ipu3/cio2.h
+++ b/src/libcamera/pipeline/ipu3/cio2.h
@@ -18,7 +18,9 @@  namespace libcamera {
 class CameraSensor;
 class FrameBuffer;
 class MediaDevice;
+class PixelFormat;
 class Request;
+class SizeRange;
 class V4L2DeviceFormat;
 class V4L2Subdevice;
 class V4L2VideoDevice;
@@ -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);
 
@@ -61,6 +66,8 @@  private:
 
 	std::vector<std::unique_ptr<FrameBuffer>> buffers_;
 	std::queue<FrameBuffer *> availableBuffers_;
+
+	bool initialized_;
 };
 
 } /* namespace libcamera */