[libcamera-devel,06/11] libcamera: v4l2_controls: Cache query control information

Message ID 20200309162414.720306-7-jacopo@jmondi.org
State Accepted
Headers show
Series
  • Adda support for V4L2 array control and strings
Related show

Commit Message

Jacopo Mondi March 9, 2020, 4:24 p.m. UTC
Cache the V4L2 control info retrieved with VIDIOC_QUERY_EXT_CTRL
at control listing time for later use.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/include/v4l2_device.h | 1 +
 src/libcamera/v4l2_device.cpp       | 1 +
 2 files changed, 2 insertions(+)

Comments

Laurent Pinchart March 20, 2020, 9:14 p.m. UTC | #1
Hi Jacopo,

On Mon, Mar 09, 2020 at 05:24:09PM +0100, Jacopo Mondi wrote:
> Cache the V4L2 control info retrieved with VIDIOC_QUERY_EXT_CTRL
> at control listing time for later use.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/libcamera/include/v4l2_device.h | 1 +
>  src/libcamera/v4l2_device.cpp       | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
> index 6bfddefe336c..e1fd048cc85a 100644
> --- a/src/libcamera/include/v4l2_device.h
> +++ b/src/libcamera/include/v4l2_device.h
> @@ -48,6 +48,7 @@ private:
>  			    const struct v4l2_ext_control *v4l2Ctrls,
>  			    unsigned int count);
>  
> +	std::map<unsigned int, struct v4l2_query_ext_ctrl> ctrlsInfo_;

To match the next field, I would call this controlInfo_ (controlInfos_
would have been better, but that would be an English error as
information is uncountable).

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  	std::vector<std::unique_ptr<V4L2ControlId>> controlIds_;
>  	ControlInfoMap controls_;
>  	std::string deviceNode_;
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 179476e9afad..65e97f92b01f 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -382,6 +382,7 @@ void V4L2Device::listControls()
>  
>  		controlIds_.emplace_back(std::make_unique<V4L2ControlId>(ctrl));
>  		ctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl));
> +		ctrlsInfo_[ctrl.id] = ctrl;
>  	}
>  
>  	controls_ = std::move(ctrls);

Patch

diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index 6bfddefe336c..e1fd048cc85a 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -48,6 +48,7 @@  private:
 			    const struct v4l2_ext_control *v4l2Ctrls,
 			    unsigned int count);
 
+	std::map<unsigned int, struct v4l2_query_ext_ctrl> ctrlsInfo_;
 	std::vector<std::unique_ptr<V4L2ControlId>> controlIds_;
 	ControlInfoMap controls_;
 	std::string deviceNode_;
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 179476e9afad..65e97f92b01f 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -382,6 +382,7 @@  void V4L2Device::listControls()
 
 		controlIds_.emplace_back(std::make_unique<V4L2ControlId>(ctrl));
 		ctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl));
+		ctrlsInfo_[ctrl.id] = ctrl;
 	}
 
 	controls_ = std::move(ctrls);