[libcamera-devel] [PATCH v2 03/14] libcamera: control_ids: Generate map of all supported controls

Niklas Söderlund niklas.soderlund at ragnatech.se
Sun Oct 13 17:27:06 CEST 2019


Hi Laurent,

Thanks for your work.

On 2019-10-12 21:43:56 +0300, Laurent Pinchart wrote:
> In order to deserialise a ControlList, we will need to lookup ControlId
> instances based on their numerical ID. Generate a global map from the
> controls definitions to support such a lookup.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
> Changes since v1:
> 
> - Add ControlIdMap type
> ---
>  include/libcamera/control_ids.h.in | 2 ++
>  include/libcamera/controls.h       | 1 +
>  src/libcamera/control_ids.cpp.in   | 7 +++++++
>  src/libcamera/controls.cpp         | 9 +++++++++
>  src/libcamera/gen-controls.py      | 3 +++
>  5 files changed, 22 insertions(+)
> 
> diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in
> index 1d0bc791e559..6ff0e4186983 100644
> --- a/include/libcamera/control_ids.h.in
> +++ b/include/libcamera/control_ids.h.in
> @@ -24,6 +24,8 @@ ${ids}
>  
>  ${controls}
>  
> +extern const ControlIdMap controls;
> +
>  } /* namespace controls */
>  
>  } /* namespace libcamera */
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 90426753f40f..d8acd800b143 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -111,6 +111,7 @@ private:
>  	ControlValue max_;
>  };
>  
> +using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
>  using ControlInfoMap = std::unordered_map<const ControlId *, ControlRange>;
>  
>  class ControlList
> diff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in
> index dd5433820a8b..99c511d0e712 100644
> --- a/src/libcamera/control_ids.cpp.in
> +++ b/src/libcamera/control_ids.cpp.in
> @@ -31,6 +31,13 @@ ${controls_doc}
>  ${controls_def}
>  #endif
>  
> +/**
> + * \brief List of all supported libcamera controls
> + */
> +extern const ControlIdMap controls {
> +${controls_map}
> +};
> +
>  } /* namespace controls */
>  
>  } /* namespace libcamera */
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index f3260edce0bc..70c1af481af2 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -355,6 +355,15 @@ std::string ControlRange::toString() const
>  	return ss.str();
>  }
>  
> +/**
> + * \typedef ControlIdMap
> + * \brief A map of numerical control ID to ControlId
> + *
> + * The map is used by ControlList instances to access controls by numerical
> + * IDs. A global map of all libcamera controls is provided by
> + * controls::controls.
> + */
> +
>  /**
>   * \typedef ControlInfoMap
>   * \brief A map of ControlId to ControlRange
> diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
> index a3e52fb36f7a..940386cc68c8 100755
> --- a/src/libcamera/gen-controls.py
> +++ b/src/libcamera/gen-controls.py
> @@ -25,6 +25,7 @@ ${description}
>  
>      ctrls_doc = []
>      ctrls_def = []
> +    ctrls_map = []
>  
>      for ctrl in controls:
>          name, ctrl = ctrl.popitem()
> @@ -43,10 +44,12 @@ ${description}
>  
>          ctrls_doc.append(doc_template.substitute(info))
>          ctrls_def.append(def_template.substitute(info))
> +        ctrls_map.append('\t{ ' + id_name + ', &' + name + ' },')
>  
>      return {
>          'controls_doc': '\n\n'.join(ctrls_doc),
>          'controls_def': '\n'.join(ctrls_def),
> +        'controls_map': '\n'.join(ctrls_map),
>      }
>  
>  
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list