[libcamera-devel] [PATCH 01/11] libcamera: controls: Name all ControlInfoMap instance variables infoMap

Jacopo Mondi jacopo at jmondi.org
Fri Mar 20 12:50:44 CET 2020


Hi Laurent,

On Mon, Mar 09, 2020 at 05:24:04PM +0100, Jacopo Mondi wrote:
> From: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>
> To prepare for the rename of ControlRange to ControlInfo, rename all the
> ControlInfoMap instance variables currently named info to infoMap. This
> will help avoiding namespace clashes.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Sorry, submitted but forgot to add my tag
Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>

Thanks
  j

> ---
>  include/libcamera/controls.h                  |  2 +-
>  src/libcamera/control_serializer.cpp          | 29 ++++++++++---------
>  src/libcamera/controls.cpp                    |  6 ++--
>  src/libcamera/include/control_serializer.h    |  4 +--
>  ...{control_info.cpp => control_info_map.cpp} | 18 ++++++------
>  test/controls/meson.build                     |  8 ++---
>  test/v4l2_videodevice/controls.cpp            | 18 ++++++------
>  7 files changed, 43 insertions(+), 42 deletions(-)
>  rename test/controls/{control_info.cpp => control_info_map.cpp} (74%)
>
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 0e111ab72bce..3d2250f43f3c 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -313,7 +313,7 @@ private:
>  public:
>  	ControlList();
>  	ControlList(const ControlIdMap &idmap, ControlValidator *validator = nullptr);
> -	ControlList(const ControlInfoMap &info, ControlValidator *validator = nullptr);
> +	ControlList(const ControlInfoMap &infoMap, ControlValidator *validator = nullptr);
>
>  	using iterator = ControlListMap::iterator;
>  	using const_iterator = ControlListMap::const_iterator;
> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> index 004735fb2aa0..dcc63d20c06c 100644
> --- a/src/libcamera/control_serializer.cpp
> +++ b/src/libcamera/control_serializer.cpp
> @@ -106,19 +106,19 @@ size_t ControlSerializer::binarySize(const ControlRange &range)
>
>  /**
>   * \brief Retrieve the size in bytes required to serialize a ControlInfoMap
> - * \param[in] info The control info map
> + * \param[in] infoMap The control info map
>   *
>   * Compute and return the size in bytes required to store the serialized
>   * ControlInfoMap.
>   *
>   * \return The size in bytes required to store the serialized ControlInfoMap
>   */
> -size_t ControlSerializer::binarySize(const ControlInfoMap &info)
> +size_t ControlSerializer::binarySize(const ControlInfoMap &infoMap)
>  {
>  	size_t size = sizeof(struct ipa_controls_header)
> -		    + info.size() * sizeof(struct ipa_control_range_entry);
> +		    + infoMap.size() * sizeof(struct ipa_control_range_entry);
>
> -	for (const auto &ctrl : info)
> +	for (const auto &ctrl : infoMap)
>  		size += binarySize(ctrl.second);
>
>  	return size;
> @@ -159,32 +159,33 @@ void ControlSerializer::store(const ControlRange &range,
>
>  /**
>   * \brief Serialize a ControlInfoMap in a buffer
> - * \param[in] info The control info map to serialize
> + * \param[in] infoMap The control info map to serialize
>   * \param[in] buffer The memory buffer where to serialize the ControlInfoMap
>   *
> - * Serialize the \a info map into the \a buffer using the serialization format
> + * Serialize the \a infoMap into the \a buffer using the serialization format
>   * defined by the IPA context interface in ipa_controls.h.
>   *
> - * The serializer stores a reference to the \a info internally. The caller
> - * shall ensure that \a info stays valid until the serializer is reset().
> + * The serializer stores a reference to the \a infoMap internally. The caller
> + * shall ensure that \a infoMap stays valid until the serializer is reset().
>   *
>   * \return 0 on success, a negative error code otherwise
>   * \retval -ENOSPC Not enough space is available in the buffer
>   */
> -int ControlSerializer::serialize(const ControlInfoMap &info,
> +int ControlSerializer::serialize(const ControlInfoMap &infoMap,
>  				 ByteStreamBuffer &buffer)
>  {
>  	/* Compute entries and data required sizes. */
> -	size_t entriesSize = info.size() * sizeof(struct ipa_control_range_entry);
> +	size_t entriesSize = infoMap.size()
> +			   * sizeof(struct ipa_control_range_entry);
>  	size_t valuesSize = 0;
> -	for (const auto &ctrl : info)
> +	for (const auto &ctrl : infoMap)
>  		valuesSize += binarySize(ctrl.second);
>
>  	/* Prepare the packet header, assign a handle to the ControlInfoMap. */
>  	struct ipa_controls_header hdr;
>  	hdr.version = IPA_CONTROLS_FORMAT_VERSION;
>  	hdr.handle = ++serial_;
> -	hdr.entries = info.size();
> +	hdr.entries = infoMap.size();
>  	hdr.size = sizeof(hdr) + entriesSize + valuesSize;
>  	hdr.data_offset = sizeof(hdr) + entriesSize;
>
> @@ -197,7 +198,7 @@ int ControlSerializer::serialize(const ControlInfoMap &info,
>  	ByteStreamBuffer entries = buffer.carveOut(entriesSize);
>  	ByteStreamBuffer values = buffer.carveOut(valuesSize);
>
> -	for (const auto &ctrl : info) {
> +	for (const auto &ctrl : infoMap) {
>  		const ControlId *id = ctrl.first;
>  		const ControlRange &range = ctrl.second;
>
> @@ -217,7 +218,7 @@ int ControlSerializer::serialize(const ControlInfoMap &info,
>  	 * Store the map to handle association, to be used to serialize and
>  	 * deserialize control lists.
>  	 */
> -	infoMapHandles_[&info] = hdr.handle;
> +	infoMapHandles_[&infoMap] = hdr.handle;
>
>  	return 0;
>  }
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 4326174adf86..833a436c64df 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -706,11 +706,11 @@ ControlList::ControlList(const ControlIdMap &idmap, ControlValidator *validator)
>
>  /**
>   * \brief Construct a ControlList with the idmap of a control info map
> - * \param[in] info The ControlInfoMap for the control list target object
> + * \param[in] infoMap The ControlInfoMap for the control list target object
>   * \param[in] validator The validator (may be null)
>   */
> -ControlList::ControlList(const ControlInfoMap &info, ControlValidator *validator)
> -	: validator_(validator), idmap_(&info.idmap()), infoMap_(&info)
> +ControlList::ControlList(const ControlInfoMap &infoMap, ControlValidator *validator)
> +	: validator_(validator), idmap_(&infoMap.idmap()), infoMap_(&infoMap)
>  {
>  }
>
> diff --git a/src/libcamera/include/control_serializer.h b/src/libcamera/include/control_serializer.h
> index b91d13155f5e..026e62340328 100644
> --- a/src/libcamera/include/control_serializer.h
> +++ b/src/libcamera/include/control_serializer.h
> @@ -24,10 +24,10 @@ public:
>
>  	void reset();
>
> -	static size_t binarySize(const ControlInfoMap &info);
> +	static size_t binarySize(const ControlInfoMap &infoMap);
>  	static size_t binarySize(const ControlList &list);
>
> -	int serialize(const ControlInfoMap &info, ByteStreamBuffer &buffer);
> +	int serialize(const ControlInfoMap &infoMap, ByteStreamBuffer &buffer);
>  	int serialize(const ControlList &list, ByteStreamBuffer &buffer);
>
>  	template<typename T>
> diff --git a/test/controls/control_info.cpp b/test/controls/control_info_map.cpp
> similarity index 74%
> rename from test/controls/control_info.cpp
> rename to test/controls/control_info_map.cpp
> index fa9d7bae97d0..eeb702db095b 100644
> --- a/test/controls/control_info.cpp
> +++ b/test/controls/control_info_map.cpp
> @@ -36,41 +36,41 @@ protected:
>
>  	int run() override
>  	{
> -		const ControlInfoMap &info = camera_->controls();
> +		const ControlInfoMap &infoMap = camera_->controls();
>
>  		/* Test looking up a valid control by ControlId. */
> -		if (info.count(&controls::Brightness) != 1) {
> +		if (infoMap.count(&controls::Brightness) != 1) {
>  			cerr << "count() on valid control failed" << endl;
>  			return TestFail;
>  		}
>
> -		if (info.find(&controls::Brightness) == info.end()) {
> +		if (infoMap.find(&controls::Brightness) == infoMap.end()) {
>  			cerr << "find() on valid control failed" << endl;
>  			return TestFail;
>  		}
>
> -		info.at(&controls::Brightness);
> +		infoMap.at(&controls::Brightness);
>
>  		/* Test looking up a valid control by numerical ID. */
> -		if (info.count(controls::Brightness.id()) != 1) {
> +		if (infoMap.count(controls::Brightness.id()) != 1) {
>  			cerr << "count() on valid ID failed" << endl;
>  			return TestFail;
>  		}
>
> -		if (info.find(controls::Brightness.id()) == info.end()) {
> +		if (infoMap.find(controls::Brightness.id()) == infoMap.end()) {
>  			cerr << "find() on valid ID failed" << endl;
>  			return TestFail;
>  		}
>
> -		info.at(controls::Brightness.id());
> +		infoMap.at(controls::Brightness.id());
>
>  		/* Test looking up an invalid control by numerical ID. */
> -		if (info.count(12345) != 0) {
> +		if (infoMap.count(12345) != 0) {
>  			cerr << "count() on invalid ID failed" << endl;
>  			return TestFail;
>  		}
>
> -		if (info.find(12345) != info.end()) {
> +		if (infoMap.find(12345) != infoMap.end()) {
>  			cerr << "find() on invalid ID failed" << endl;
>  			return TestFail;
>  		}
> diff --git a/test/controls/meson.build b/test/controls/meson.build
> index f0850df28c8a..16a7f33fdcc6 100644
> --- a/test/controls/meson.build
> +++ b/test/controls/meson.build
> @@ -1,8 +1,8 @@
>  control_tests = [
> -    [ 'control_info',   'control_info.cpp' ],
> -    [ 'control_list',   'control_list.cpp' ],
> -    [ 'control_range',  'control_range.cpp' ],
> -    [ 'control_value',  'control_value.cpp' ],
> +    [ 'control_info_map',           'control_info_map.cpp' ],
> +    [ 'control_list',               'control_list.cpp' ],
> +    [ 'control_range',              'control_range.cpp' ],
> +    [ 'control_value',              'control_value.cpp' ],
>  ]
>
>  foreach t : control_tests
> diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp
> index 42c653d4435a..1b71bf0633b4 100644
> --- a/test/v4l2_videodevice/controls.cpp
> +++ b/test/v4l2_videodevice/controls.cpp
> @@ -26,27 +26,27 @@ public:
>  protected:
>  	int run()
>  	{
> -		const ControlInfoMap &info = capture_->controls();
> +		const ControlInfoMap &infoMap = capture_->controls();
>
>  		/* Test control enumeration. */
> -		if (info.empty()) {
> +		if (infoMap.empty()) {
>  			cerr << "Failed to enumerate controls" << endl;
>  			return TestFail;
>  		}
>
> -		if (info.find(V4L2_CID_BRIGHTNESS) == info.end() ||
> -		    info.find(V4L2_CID_CONTRAST) == info.end() ||
> -		    info.find(V4L2_CID_SATURATION) == info.end()) {
> +		if (infoMap.find(V4L2_CID_BRIGHTNESS) == infoMap.end() ||
> +		    infoMap.find(V4L2_CID_CONTRAST) == infoMap.end() ||
> +		    infoMap.find(V4L2_CID_SATURATION) == infoMap.end()) {
>  			cerr << "Missing controls" << endl;
>  			return TestFail;
>  		}
>
> -		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;
> +		const ControlRange &brightness = infoMap.find(V4L2_CID_BRIGHTNESS)->second;
> +		const ControlRange &contrast = infoMap.find(V4L2_CID_CONTRAST)->second;
> +		const ControlRange &saturation = infoMap.find(V4L2_CID_SATURATION)->second;
>
>  		/* Test getting controls. */
> -		ControlList ctrls(info);
> +		ControlList ctrls(infoMap);
>  		ctrls.set(V4L2_CID_BRIGHTNESS, -1);
>  		ctrls.set(V4L2_CID_CONTRAST, -1);
>  		ctrls.set(V4L2_CID_SATURATION, -1);
> --
> 2.25.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel


More information about the libcamera-devel mailing list