[libcamera-devel] [PATCH 07/10] libcamera: v4l2_controls: Store a ControlRange in V4L2ControlInfoMap

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Oct 14 01:27:53 CEST 2019


V4L2ControlRange only offers a convenience constructor for a
ControlRange. Store the ControlRange instead of V4L2ControlRange in
V4L2ControlInfoMap to make the map less dependent on V4L2 types.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/include/v4l2_controls.h | 34 +++++++++++++--------------
 src/libcamera/pipeline/uvcvideo.cpp   |  2 +-
 src/libcamera/pipeline/vimc.cpp       |  2 +-
 src/libcamera/v4l2_controls.cpp       |  6 ++---
 src/libcamera/v4l2_device.cpp         |  6 ++---
 test/v4l2_videodevice/controls.cpp    |  6 ++---
 6 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h
index 741569824b68..7d3528b07f94 100644
--- a/src/libcamera/include/v4l2_controls.h
+++ b/src/libcamera/include/v4l2_controls.h
@@ -31,27 +31,27 @@ public:
 	V4L2ControlRange(const struct v4l2_query_ext_ctrl &ctrl);
 };
 
-class V4L2ControlInfoMap : private std::map<const ControlId *, V4L2ControlRange>
+class V4L2ControlInfoMap : private std::map<const ControlId *, ControlRange>
 {
 public:
-	V4L2ControlInfoMap &operator=(std::map<const ControlId *, V4L2ControlRange> &&info);
+	V4L2ControlInfoMap &operator=(std::map<const ControlId *, ControlRange> &&info);
 
-	using std::map<const ControlId *, V4L2ControlRange>::key_type;
-	using std::map<const ControlId *, V4L2ControlRange>::mapped_type;
-	using std::map<const ControlId *, V4L2ControlRange>::value_type;
-	using std::map<const ControlId *, V4L2ControlRange>::size_type;
-	using std::map<const ControlId *, V4L2ControlRange>::iterator;
-	using std::map<const ControlId *, V4L2ControlRange>::const_iterator;
+	using std::map<const ControlId *, ControlRange>::key_type;
+	using std::map<const ControlId *, ControlRange>::mapped_type;
+	using std::map<const ControlId *, ControlRange>::value_type;
+	using std::map<const ControlId *, ControlRange>::size_type;
+	using std::map<const ControlId *, ControlRange>::iterator;
+	using std::map<const ControlId *, ControlRange>::const_iterator;
 
-	using std::map<const ControlId *, V4L2ControlRange>::begin;
-	using std::map<const ControlId *, V4L2ControlRange>::cbegin;
-	using std::map<const ControlId *, V4L2ControlRange>::end;
-	using std::map<const ControlId *, V4L2ControlRange>::cend;
-	using std::map<const ControlId *, V4L2ControlRange>::at;
-	using std::map<const ControlId *, V4L2ControlRange>::empty;
-	using std::map<const ControlId *, V4L2ControlRange>::size;
-	using std::map<const ControlId *, V4L2ControlRange>::count;
-	using std::map<const ControlId *, V4L2ControlRange>::find;
+	using std::map<const ControlId *, ControlRange>::begin;
+	using std::map<const ControlId *, ControlRange>::cbegin;
+	using std::map<const ControlId *, ControlRange>::end;
+	using std::map<const ControlId *, ControlRange>::cend;
+	using std::map<const ControlId *, ControlRange>::at;
+	using std::map<const ControlId *, ControlRange>::empty;
+	using std::map<const ControlId *, ControlRange>::size;
+	using std::map<const ControlId *, ControlRange>::count;
+	using std::map<const ControlId *, ControlRange>::find;
 
 	mapped_type &at(unsigned int key);
 	const mapped_type &at(unsigned int key) const;
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 7356585b982e..018c7691d263 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -337,7 +337,7 @@ int UVCCameraData::init(MediaEntity *entity)
 	/* Initialise the supported controls. */
 	const V4L2ControlInfoMap &controls = video_->controls();
 	for (const auto &ctrl : controls) {
-		const V4L2ControlRange &range = ctrl.second;
+		const ControlRange &range = ctrl.second;
 		const ControlId *id;
 
 		switch (ctrl.first->id()) {
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index 87e7e54e964f..f7f82edc6530 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -413,7 +413,7 @@ int VimcCameraData::init(MediaDevice *media)
 	/* Initialise the supported controls. */
 	const V4L2ControlInfoMap &controls = sensor_->controls();
 	for (const auto &ctrl : controls) {
-		const V4L2ControlRange &range = ctrl.second;
+		const ControlRange &range = ctrl.second;
 		const ControlId *id;
 
 		switch (ctrl.first->id()) {
diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp
index 4aab34b9a2b4..e27c70eeec87 100644
--- a/src/libcamera/v4l2_controls.cpp
+++ b/src/libcamera/v4l2_controls.cpp
@@ -136,7 +136,7 @@ V4L2ControlRange::V4L2ControlRange(const struct v4l2_query_ext_ctrl &ctrl)
 
 /**
  * \class V4L2ControlInfoMap
- * \brief A map of controlID to V4L2ControlRange
+ * \brief A map of controlID to ControlRange for V4L2 controls
  */
 
 /**
@@ -150,9 +150,9 @@ V4L2ControlRange::V4L2ControlRange(const struct v4l2_query_ext_ctrl &ctrl)
  *
  * \return The populated V4L2ControlInfoMap
  */
-V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, V4L2ControlRange> &&info)
+V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, ControlRange> &&info)
 {
-	std::map<const ControlId *, V4L2ControlRange>::operator=(std::move(info));
+	std::map<const ControlId *, ControlRange>::operator=(std::move(info));
 
 	idmap_.clear();
 	for (const auto &ctrl : *this)
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 133f8abc8f13..47999e70073c 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -342,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)
  */
 void V4L2Device::listControls()
 {
-	std::map<const ControlId *, V4L2ControlRange> ctrls;
+	std::map<const ControlId *, ControlRange> ctrls;
 	struct v4l2_query_ext_ctrl ctrl = {};
 
 	/* \todo Add support for menu and compound controls. */
@@ -380,9 +380,7 @@ void V4L2Device::listControls()
 		}
 
 		controlIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));
-		ctrls.emplace(std::piecewise_construct,
-			      std::forward_as_tuple(controlIds_.back().get()),
-			      std::forward_as_tuple(ctrl));
+		ctrls.emplace(controlIds_.back().get(), V4L2ControlRange(ctrl));
 	}
 
 	controls_ = std::move(ctrls);
diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp
index d4b7588eb362..182228f3a5b1 100644
--- a/test/v4l2_videodevice/controls.cpp
+++ b/test/v4l2_videodevice/controls.cpp
@@ -41,9 +41,9 @@ protected:
 			return TestFail;
 		}
 
-		const V4L2ControlRange &brightness = info.find(V4L2_CID_BRIGHTNESS)->second;
-		const V4L2ControlRange &contrast = info.find(V4L2_CID_CONTRAST)->second;
-		const V4L2ControlRange &saturation = info.find(V4L2_CID_SATURATION)->second;
+		const ControlRange &brightness = info.find(V4L2_CID_BRIGHTNESS)->second;
+		const ControlRange &contrast = info.find(V4L2_CID_CONTRAST)->second;
+		const ControlRange &saturation = info.find(V4L2_CID_SATURATION)->second;
 
 		/* Test getting controls. */
 		V4L2ControlList ctrls(info);
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list