[libcamera-devel,v2,6/8] libcamera: v4l2_videodevice: Add multiplanar argument to toV4L2PixelFormat
diff mbox series

Message ID 20220723095330.43542-7-jacopo@jmondi.org
State Superseded, archived
Headers show
Series
  • libcamera: Map multiple V4L2 formats to a single libcamera::format
Related show

Commit Message

Jacopo Mondi July 23, 2022, 9:53 a.m. UTC
The toV4L2PixelFormat() function selects which V4L2 format variant to
use (contiguous planes vs non-contiguous version) by using video device
multiplanar API from the capabilities.

The isMultiplanar() function however verifies if the video device uses
the singleplanar or the multiplanar V4L2 API, something which is
unrelated to the format variant to use.

Add a 'multiplanar' flag, which defaults to false, to the
toV4L2PixelFormat() function to allow explicit selection of the format
variant.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 include/libcamera/internal/v4l2_videodevice.h |  3 ++-
 src/libcamera/v4l2_videodevice.cpp            | 13 +++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

Comments

Laurent Pinchart July 23, 2022, 5:46 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Sat, Jul 23, 2022 at 11:53:28AM +0200, Jacopo Mondi via libcamera-devel wrote:
> The toV4L2PixelFormat() function selects which V4L2 format variant to
> use (contiguous planes vs non-contiguous version) by using video device
> multiplanar API from the capabilities.
> 
> The isMultiplanar() function however verifies if the video device uses
> the singleplanar or the multiplanar V4L2 API, something which is
> unrelated to the format variant to use.
> 
> Add a 'multiplanar' flag, which defaults to false, to the
> toV4L2PixelFormat() function to allow explicit selection of the format
> variant.

None of the callers set multiplanar to true in this series, so I'd drop
this patch (see the review of the previous patch for more details).

> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  include/libcamera/internal/v4l2_videodevice.h |  3 ++-
>  src/libcamera/v4l2_videodevice.cpp            | 13 +++++++------
>  2 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
> index 6d8850c99afd..64296c5849f2 100644
> --- a/include/libcamera/internal/v4l2_videodevice.h
> +++ b/include/libcamera/internal/v4l2_videodevice.h
> @@ -228,7 +228,8 @@ public:
>  	static std::unique_ptr<V4L2VideoDevice>
>  	fromEntityName(const MediaDevice *media, const std::string &entity);
>  
> -	V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat) const;
> +	V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat,
> +					  bool multiplanar = false) const;
>  
>  protected:
>  	std::string logPrefix() const override;
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index a3242ba755c0..767ab2361ef5 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1992,23 +1992,24 @@ V4L2VideoDevice::fromEntityName(const MediaDevice *media,
>  /**
>   * \brief Convert \a PixelFormat to one of the device supported V4L2 FourCC
>   * \param[in] pixelFormat The PixelFormat to convert
> + * \param[in] multiplanar Use the multiplanar format version, default to false
>   *
>   * Convert a\ pixelformat to a V4L2 FourCC that is known to be supported by
>   * the video device.
>   *
> - * For multiplanar formats, the V4L2 format variant (contiguous or
> - * non-contiguous planes) is selected automatically based on the capabilities
> - * of the video device. If the video device supports the V4L2 multiplanar API,
> - * non-contiguous formats are preferred.
> + * V4L2 defines different format variants for the same format when using
> + * contiguous or non-contiguous planes. The \a multiplanar parameter allows
> + * to select which variant to use.
>   *
>   * \return The V4L2PixelFormat corresponding to \a pixelFormat or an invalid
>   * PixelFormat if \a pixelFormat is not supported by the video device
>   */
> -V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat) const
> +V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat,
> +						   bool multiplanar) const
>  {
>  	std::vector<V4L2PixelFormat> deviceFormats = enumPixelformats(0);
>  	std::vector<V4L2PixelFormat> v4l2PixelFormats =
> -		V4L2PixelFormat::fromPixelFormat(pixelFormat, caps_.isMultiplanar());
> +		V4L2PixelFormat::fromPixelFormat(pixelFormat, multiplanar);
>  
>  	for (const V4L2PixelFormat &v4l2Format : v4l2PixelFormats) {
>  		auto it = std::find_if(deviceFormats.begin(), deviceFormats.end(),

Patch
diff mbox series

diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
index 6d8850c99afd..64296c5849f2 100644
--- a/include/libcamera/internal/v4l2_videodevice.h
+++ b/include/libcamera/internal/v4l2_videodevice.h
@@ -228,7 +228,8 @@  public:
 	static std::unique_ptr<V4L2VideoDevice>
 	fromEntityName(const MediaDevice *media, const std::string &entity);
 
-	V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat) const;
+	V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat,
+					  bool multiplanar = false) const;
 
 protected:
 	std::string logPrefix() const override;
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index a3242ba755c0..767ab2361ef5 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1992,23 +1992,24 @@  V4L2VideoDevice::fromEntityName(const MediaDevice *media,
 /**
  * \brief Convert \a PixelFormat to one of the device supported V4L2 FourCC
  * \param[in] pixelFormat The PixelFormat to convert
+ * \param[in] multiplanar Use the multiplanar format version, default to false
  *
  * Convert a\ pixelformat to a V4L2 FourCC that is known to be supported by
  * the video device.
  *
- * For multiplanar formats, the V4L2 format variant (contiguous or
- * non-contiguous planes) is selected automatically based on the capabilities
- * of the video device. If the video device supports the V4L2 multiplanar API,
- * non-contiguous formats are preferred.
+ * V4L2 defines different format variants for the same format when using
+ * contiguous or non-contiguous planes. The \a multiplanar parameter allows
+ * to select which variant to use.
  *
  * \return The V4L2PixelFormat corresponding to \a pixelFormat or an invalid
  * PixelFormat if \a pixelFormat is not supported by the video device
  */
-V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat) const
+V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat,
+						   bool multiplanar) const
 {
 	std::vector<V4L2PixelFormat> deviceFormats = enumPixelformats(0);
 	std::vector<V4L2PixelFormat> v4l2PixelFormats =
-		V4L2PixelFormat::fromPixelFormat(pixelFormat, caps_.isMultiplanar());
+		V4L2PixelFormat::fromPixelFormat(pixelFormat, multiplanar);
 
 	for (const V4L2PixelFormat &v4l2Format : v4l2PixelFormats) {
 		auto it = std::find_if(deviceFormats.begin(), deviceFormats.end(),