[libcamera-devel] [PATCH v3 2/4] libcamera: v4l2_subdevice: Provide Formats type alias

Jacopo Mondi jacopo at jmondi.org
Mon Jun 29 13:53:26 CEST 2020


Provide a type definition for ImageFormats<uint32_t> to allow
users of V4L2Subdevice to refer to it as V4L2Subdevice::Formats.

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 include/libcamera/internal/camera_sensor.h  |  6 ++----
 include/libcamera/internal/v4l2_subdevice.h |  4 +++-
 src/libcamera/v4l2_subdevice.cpp            | 10 ++++++++--
 test/v4l2_subdevice/list_formats.cpp        |  2 +-
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index d5814a26a121..06c8292ca301 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -16,13 +16,11 @@

 #include "libcamera/internal/formats.h"
 #include "libcamera/internal/log.h"
+#include "libcamera/internal/v4l2_subdevice.h"

 namespace libcamera {

 class MediaEntity;
-class V4L2Subdevice;
-
-struct V4L2SubdeviceFormat;

 struct CameraSensorInfo {
 	std::string model;
@@ -75,7 +73,7 @@ private:

 	std::string model_;

-	ImageFormats<uint32_t> formats_;
+	V4L2Subdevice::Formats formats_;
 	Size resolution_;
 	std::vector<unsigned int> mbusCodes_;
 	std::vector<Size> sizes_;
diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
index f811d316dada..c678fc87e80f 100644
--- a/include/libcamera/internal/v4l2_subdevice.h
+++ b/include/libcamera/internal/v4l2_subdevice.h
@@ -32,6 +32,8 @@ struct V4L2SubdeviceFormat {
 class V4L2Subdevice : public V4L2Device
 {
 public:
+	using Formats = ImageFormats<uint32_t>;
+
 	enum Whence {
 		ActiveFormat,
 		TryFormat,
@@ -51,7 +53,7 @@ public:
 	int setSelection(unsigned int pad, unsigned int target,
 			 Rectangle *rect);

-	ImageFormats<uint32_t> formats(unsigned int pad);
+	Formats formats(unsigned int pad);

 	int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
 		      Whence whence = ActiveFormat);
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index 231473ba3d06..372283cbdeb6 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -217,6 +217,12 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const
  * any device left open will be closed, and any resources released.
  */

+/**
+ * \typedef V4L2Subdevice::Formats
+ * \brief An ImageFormats specialization mapping uint32_t media bus codes to
+ * image resolutions
+ */
+
 /**
  * \enum V4L2Subdevice::Whence
  * \brief Specify the type of format for getFormat() and setFormat() operations
@@ -340,9 +346,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
  *
  * \return A list of the supported device formats
  */
-ImageFormats<uint32_t> V4L2Subdevice::formats(unsigned int pad)
+V4L2Subdevice::Formats V4L2Subdevice::formats(unsigned int pad)
 {
-	ImageFormats<uint32_t> formats;
+	Formats formats;

 	if (pad >= entity_->pads().size()) {
 		LOG(V4L2, Error) << "Invalid pad: " << pad;
diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp
index 3e8d4cdba045..7f0b3333f617 100644
--- a/test/v4l2_subdevice/list_formats.cpp
+++ b/test/v4l2_subdevice/list_formats.cpp
@@ -47,7 +47,7 @@ void ListFormatsTest::printFormats(unsigned int pad,
 int ListFormatsTest::run()
 {
 	/* List all formats available on existing "Scaler" pads. */
-	ImageFormats<uint32_t> formats;
+	V4L2Subdevice::Formats formats;

 	formats = scaler_->formats(0);
 	if (formats.isEmpty()) {
--
2.27.0



More information about the libcamera-devel mailing list