[libcamera-devel,07/21] libcamera: v4l2_controls: Make V4L2Control a DataValue

Message ID 20190924172503.30864-8-jacopo@jmondi.org
State Superseded
Headers show
Series
  • Implement control serialization
Related show

Commit Message

Jacopo Mondi Sept. 24, 2019, 5:24 p.m. UTC
In order to be able to easily serialize a V4L2ControlList which contains
controls, make the V4L2Control class a DataValue.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/include/v4l2_controls.h | 11 ++++------
 src/libcamera/pipeline/uvcvideo.cpp   |  2 +-
 src/libcamera/pipeline/vimc.cpp       |  2 +-
 src/libcamera/v4l2_controls.cpp       | 29 +--------------------------
 src/libcamera/v4l2_device.cpp         |  8 ++++----
 5 files changed, 11 insertions(+), 41 deletions(-)

Patch

diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h
index 27b855f3407f..8b1a23f37204 100644
--- a/src/libcamera/include/v4l2_controls.h
+++ b/src/libcamera/include/v4l2_controls.h
@@ -32,21 +32,18 @@  private:
 
 using V4L2ControlInfoMap = std::map<unsigned int, V4L2ControlInfo>;
 
-class V4L2Control
+class V4L2Control : public DataValue
 {
 public:
 	V4L2Control(unsigned int id, int value = 0)
-		: id_(id), value_(value) {}
-
-	DataType type() const { return value_.type(); }
-	int64_t value() const { return value_.getInt64(); }
-	void setValue(int64_t value) { value_ = value; }
+		: DataValue(value), id_(id)
+	{
+	}
 
 	unsigned int id() const { return id_; }
 
 private:
 	unsigned int id_;
-	DataValue value_;
 };
 
 class V4L2ControlList
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 02455d1ac675..6c7238e8a245 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -264,7 +264,7 @@  int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)
 		LOG(UVC, Debug)
 			<< "Setting control 0x"
 			<< std::hex << std::setw(8) << ctrl.id() << std::dec
-			<< " to " << ctrl.value();
+			<< " to " << ctrl.getInt();
 
 	int ret = data->video_->setControls(&controls);
 	if (ret) {
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index 5515704df14c..80a71f7cd5fd 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -308,7 +308,7 @@  int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)
 		LOG(VIMC, Debug)
 			<< "Setting control 0x"
 			<< std::hex << std::setw(8) << ctrl.id() << std::dec
-			<< " to " << ctrl.value();
+			<< " to " << ctrl.getInt();
 
 	int ret = data->sensor_->setControls(&controls);
 	if (ret) {
diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp
index 9bc4929cbd76..864b0be1e96f 100644
--- a/src/libcamera/v4l2_controls.cpp
+++ b/src/libcamera/v4l2_controls.cpp
@@ -103,8 +103,7 @@  V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)
  * V4L2Device::setControls() and V4L2Device::getControls() operations.
  *
  * \todo Currently all V4L2Controls are integers. For the sake of keeping the
- * implementation as simpler as possible treat all values as int64. The value()
- * and setValue() operations use that single data type for now.
+ * implementation as simpler as possible treat all values as int64.
  */
 
 /**
@@ -114,32 +113,6 @@  V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)
  * \param value The control value
  */
 
-/**
- * \fn V4L2Control::type()
- * \brief Retrieve the type of the control
- * \return The control type
- */
-
-/**
- * \fn V4L2Control::value()
- * \brief Retrieve the value of the control
- *
- * This method returns the cached control value, initially set by
- * V4L2ControlList::add() and then updated when the controls are read or
- * written with V4L2Device::getControls() and V4L2Device::setControls().
- *
- * \return The V4L2 control value
- */
-
-/**
- * \fn V4L2Control::setValue()
- * \brief Set the value of the control
- * \param value The new V4L2 control value
- *
- * This method stores the control value, which will be applied to the
- * device when calling V4L2Device::setControls().
- */
-
 /**
  * \fn V4L2Control::id()
  * \brief Retrieve the control ID this instance refers to
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index e87863af6a66..e1a715edec13 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -260,14 +260,14 @@  int V4L2Device::setControls(V4L2ControlList *ctrls)
 		/* Set the v4l2_ext_control value for the write operation. */
 		switch (ctrl->type()) {
 		case DataTypeInteger64:
-			v4l2Ctrls[i].value64 = ctrl->value();
+			v4l2Ctrls[i].value64 = ctrl->getInt();
 			break;
 		default:
 			/*
 			 * \todo To be changed when support for string and
 			 * compound controls will be added.
 			 */
-			v4l2Ctrls[i].value = ctrl->value();
+			v4l2Ctrls[i].value = ctrl->getInt64();
 			break;
 		}
 	}
@@ -386,14 +386,14 @@  void V4L2Device::updateControls(V4L2ControlList *ctrls,
 
 		switch (ctrl->type()) {
 		case DataTypeInteger64:
-			ctrl->setValue(v4l2Ctrls[i].value64);
+			ctrl->set(static_cast<int64_t>(v4l2Ctrls[i].value64));
 			break;
 		default:
 			/*
 			 * \todo To be changed when support for string and
 			 * compound controls will be added.
 			 */
-			ctrl->setValue(v4l2Ctrls[i].value);
+			ctrl->set(static_cast<int>(v4l2Ctrls[i].value));
 			break;
 		}
 	}