[1/2] libcamera: controls: Add array information to ControlId
diff mbox series

Message ID 20240911153523.1756554-2-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • Add array information to ControlId
Related show

Commit Message

Paul Elder Sept. 11, 2024, 3:35 p.m. UTC
Add to ControlId information on whether or not it is an array control,
and the size of the control if it is an array control.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 include/libcamera/controls.h | 17 ++++++++++++++++-
 src/libcamera/controls.cpp   | 16 ++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)

Comments

Kieran Bingham Sept. 11, 2024, 3:57 p.m. UTC | #1
Quoting Paul Elder (2024-09-11 16:35:22)
> Add to ControlId information on whether or not it is an array control,
> and the size of the control if it is an array control.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  include/libcamera/controls.h | 17 ++++++++++++++++-
>  src/libcamera/controls.cpp   | 16 ++++++++++++++--
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 8959dfcc2..b539159e1 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -46,50 +46,60 @@ struct control_type {
>  template<>
>  struct control_type<void> {
>         static constexpr ControlType value = ControlTypeNone;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<bool> {
>         static constexpr ControlType value = ControlTypeBool;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<uint8_t> {
>         static constexpr ControlType value = ControlTypeByte;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<int32_t> {
>         static constexpr ControlType value = ControlTypeInteger32;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<int64_t> {
>         static constexpr ControlType value = ControlTypeInteger64;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<float> {
>         static constexpr ControlType value = ControlTypeFloat;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<std::string> {
>         static constexpr ControlType value = ControlTypeString;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<Rectangle> {
>         static constexpr ControlType value = ControlTypeRectangle;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<>
>  struct control_type<Size> {
>         static constexpr ControlType value = ControlTypeSize;
> +       static constexpr std::size_t size = 0;
>  };
>  
>  template<typename T, std::size_t N>
>  struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
> +       static constexpr std::size_t size = N;
>  };
>  
>  } /* namespace details */
> @@ -215,11 +225,14 @@ class ControlId
>  {
>  public:
>         ControlId(unsigned int id, const std::string &name, ControlType type,
> +                 std::size_t size = 0,
>                   const std::map<std::string, int32_t> &enumStrMap = {});
>  
>         unsigned int id() const { return id_; }
>         const std::string &name() const { return name_; }
>         ControlType type() const { return type_; }
> +       bool isArray() const { return size_ > 0; }
> +       std::size_t size() const { return size_; }
>         const std::map<std::string, int32_t> &enumStrMap() const { return enumStrMap_; }
>         const std::string enumToString(int32_t value) const;
>  
> @@ -229,6 +242,7 @@ private:
>         unsigned int id_;
>         std::string name_;
>         ControlType type_;
> +       std::size_t size_;
>         std::map<std::string, int32_t> enumStrMap_;
>         std::map<int32_t, std::string> reverseMap_;
>  };
> @@ -260,7 +274,8 @@ public:
>         using type = T;
>  
>         Control(unsigned int id, const char *name, const std::map<std::string, int32_t> &enumStrMap = {})
> -               : ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, enumStrMap)
> +               : ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value,
> +                           details::control_type<std::remove_cv_t<T>>::size, enumStrMap)
>         {
>         }
>  
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 0f83139fb..1530bdb9c 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -394,8 +394,8 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen
>   * \param[in] enumStrMap The map from enum names to values (optional)
>   */
>  ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,
> -                    const std::map<std::string, int32_t> &enumStrMap)
> -       : id_(id), name_(name), type_(type), enumStrMap_(enumStrMap)
> +                    std::size_t size, const std::map<std::string, int32_t> &enumStrMap)
> +       : id_(id), name_(name), type_(type), size_(size), enumStrMap_(enumStrMap)
>  {
>         for (const auto &pair : enumStrMap_)
>                 reverseMap_[pair.second] = pair.first;
> @@ -419,6 +419,18 @@ ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,
>   * \return The control data type
>   */
>  
> +/**
> + * \fn bool isArray() const
> + * \brief Determine if the control is an array control
> + * \return True if the control is an array control, false otherwise
> + */
> +
> +/**
> + * \fn std::size_t size() const
> + * \brief Retrieve the size of the control if it is an array control
> + * \return The size of the array control, size_t::max for dynamic extend, or 0 for non-array
> + */
> +
>  /**
>   * \brief Retrieve the name of an enum value
>   * \return The name of the enum value
> -- 
> 2.39.2
>

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 8959dfcc2..b539159e1 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -46,50 +46,60 @@  struct control_type {
 template<>
 struct control_type<void> {
 	static constexpr ControlType value = ControlTypeNone;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<bool> {
 	static constexpr ControlType value = ControlTypeBool;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<uint8_t> {
 	static constexpr ControlType value = ControlTypeByte;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<int32_t> {
 	static constexpr ControlType value = ControlTypeInteger32;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<int64_t> {
 	static constexpr ControlType value = ControlTypeInteger64;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<float> {
 	static constexpr ControlType value = ControlTypeFloat;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<std::string> {
 	static constexpr ControlType value = ControlTypeString;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<Rectangle> {
 	static constexpr ControlType value = ControlTypeRectangle;
+	static constexpr std::size_t size = 0;
 };
 
 template<>
 struct control_type<Size> {
 	static constexpr ControlType value = ControlTypeSize;
+	static constexpr std::size_t size = 0;
 };
 
 template<typename T, std::size_t N>
 struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
+	static constexpr std::size_t size = N;
 };
 
 } /* namespace details */
@@ -215,11 +225,14 @@  class ControlId
 {
 public:
 	ControlId(unsigned int id, const std::string &name, ControlType type,
+		  std::size_t size = 0,
 		  const std::map<std::string, int32_t> &enumStrMap = {});
 
 	unsigned int id() const { return id_; }
 	const std::string &name() const { return name_; }
 	ControlType type() const { return type_; }
+	bool isArray() const { return size_ > 0; }
+	std::size_t size() const { return size_; }
 	const std::map<std::string, int32_t> &enumStrMap() const { return enumStrMap_; }
 	const std::string enumToString(int32_t value) const;
 
@@ -229,6 +242,7 @@  private:
 	unsigned int id_;
 	std::string name_;
 	ControlType type_;
+	std::size_t size_;
 	std::map<std::string, int32_t> enumStrMap_;
 	std::map<int32_t, std::string> reverseMap_;
 };
@@ -260,7 +274,8 @@  public:
 	using type = T;
 
 	Control(unsigned int id, const char *name, const std::map<std::string, int32_t> &enumStrMap = {})
-		: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, enumStrMap)
+		: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value,
+			    details::control_type<std::remove_cv_t<T>>::size, enumStrMap)
 	{
 	}
 
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 0f83139fb..1530bdb9c 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -394,8 +394,8 @@  void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen
  * \param[in] enumStrMap The map from enum names to values (optional)
  */
 ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,
-		     const std::map<std::string, int32_t> &enumStrMap)
-	: id_(id), name_(name), type_(type), enumStrMap_(enumStrMap)
+		     std::size_t size, const std::map<std::string, int32_t> &enumStrMap)
+	: id_(id), name_(name), type_(type), size_(size), enumStrMap_(enumStrMap)
 {
 	for (const auto &pair : enumStrMap_)
 		reverseMap_[pair.second] = pair.first;
@@ -419,6 +419,18 @@  ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,
  * \return The control data type
  */
 
+/**
+ * \fn bool isArray() const
+ * \brief Determine if the control is an array control
+ * \return True if the control is an array control, false otherwise
+ */
+
+/**
+ * \fn std::size_t size() const
+ * \brief Retrieve the size of the control if it is an array control
+ * \return The size of the array control, size_t::max for dynamic extend, or 0 for non-array
+ */
+
 /**
  * \brief Retrieve the name of an enum value
  * \return The name of the enum value