[{"id":31176,"web_url":"https://patchwork.libcamera.org/comment/31176/","msgid":"<20240911162808.GG4470@pendragon.ideasonboard.com>","date":"2024-09-11T16:28:08","subject":"Re: [PATCH v2 1/2] libcamera: controls: Add array information to\n\tControlId","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Sep 11, 2024 at 06:23:59PM +0200, Paul Elder wrote:\n> Add to ControlId information on whether or not it is an array control,\n> and the size of the control if it is an array control.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> Changes in v2:\n> - fix documentation\n> ---\n>  include/libcamera/controls.h | 17 ++++++++++++++++-\n>  src/libcamera/controls.cpp   | 17 +++++++++++++++--\n>  2 files changed, 31 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\n> index 8959dfcc2..b539159e1 100644\n> --- a/include/libcamera/controls.h\n> +++ b/include/libcamera/controls.h\n> @@ -46,50 +46,60 @@ struct control_type {\n>  template<>\n>  struct control_type<void> {\n>  \tstatic constexpr ControlType value = ControlTypeNone;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<bool> {\n>  \tstatic constexpr ControlType value = ControlTypeBool;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<uint8_t> {\n>  \tstatic constexpr ControlType value = ControlTypeByte;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<int32_t> {\n>  \tstatic constexpr ControlType value = ControlTypeInteger32;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<int64_t> {\n>  \tstatic constexpr ControlType value = ControlTypeInteger64;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<float> {\n>  \tstatic constexpr ControlType value = ControlTypeFloat;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<std::string> {\n>  \tstatic constexpr ControlType value = ControlTypeString;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<Rectangle> {\n>  \tstatic constexpr ControlType value = ControlTypeRectangle;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<>\n>  struct control_type<Size> {\n>  \tstatic constexpr ControlType value = ControlTypeSize;\n> +\tstatic constexpr std::size_t size = 0;\n>  };\n>  \n>  template<typename T, std::size_t N>\n>  struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {\n> +\tstatic constexpr std::size_t size = N;\n>  };\n>  \n>  } /* namespace details */\n> @@ -215,11 +225,14 @@ class ControlId\n>  {\n>  public:\n>  \tControlId(unsigned int id, const std::string &name, ControlType type,\n> +\t\t  std::size_t size = 0,\n>  \t\t  const std::map<std::string, int32_t> &enumStrMap = {});\n>  \n>  \tunsigned int id() const { return id_; }\n>  \tconst std::string &name() const { return name_; }\n>  \tControlType type() const { return type_; }\n> +\tbool isArray() const { return size_ > 0; }\n> +\tstd::size_t size() const { return size_; }\n>  \tconst std::map<std::string, int32_t> &enumStrMap() const { return enumStrMap_; }\n>  \tconst std::string enumToString(int32_t value) const;\n>  \n> @@ -229,6 +242,7 @@ private:\n>  \tunsigned int id_;\n>  \tstd::string name_;\n>  \tControlType type_;\n> +\tstd::size_t size_;\n>  \tstd::map<std::string, int32_t> enumStrMap_;\n>  \tstd::map<int32_t, std::string> reverseMap_;\n>  };\n> @@ -260,7 +274,8 @@ public:\n>  \tusing type = T;\n>  \n>  \tControl(unsigned int id, const char *name, const std::map<std::string, int32_t> &enumStrMap = {})\n> -\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, enumStrMap)\n> +\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value,\n> +\t\t\t    details::control_type<std::remove_cv_t<T>>::size, enumStrMap)\n>  \t{\n>  \t}\n>  \n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 0f83139fb..217769396 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -391,11 +391,12 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n>   * \\param[in] id The control numerical ID\n>   * \\param[in] name The control name\n>   * \\param[in] type The control data type\n> + * \\param[in] size The size of the array control, or 0 if scalar control\n>   * \\param[in] enumStrMap The map from enum names to values (optional)\n>   */\n>  ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,\n> -\t\t     const std::map<std::string, int32_t> &enumStrMap)\n> -\t: id_(id), name_(name), type_(type), enumStrMap_(enumStrMap)\n> +\t\t     std::size_t size, const std::map<std::string, int32_t> &enumStrMap)\n> +\t: id_(id), name_(name), type_(type), size_(size), enumStrMap_(enumStrMap)\n>  {\n>  \tfor (const auto &pair : enumStrMap_)\n>  \t\treverseMap_[pair.second] = pair.first;\n> @@ -419,6 +420,18 @@ ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,\n>   * \\return The control data type\n>   */\n>  \n> +/**\n> + * \\fn bool ControlId::isArray() const\n> + * \\brief Determine if the control is an array control\n> + * \\return True if the control is an array control, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn std::size_t ControlId::size() const\n> + * \\brief Retrieve the size of the control if it is an array control\n> + * \\return The size of the array control, size_t::max for dynamic extend, or 0 for non-array\n\nLine wrap.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> + */\n> +\n>  /**\n>   * \\brief Retrieve the name of an enum value\n>   * \\return The name of the enum value","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 04AD9C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Sep 2024 16:28:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF4DD634FC;\n\tWed, 11 Sep 2024 18:28:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8023F618F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Sep 2024 18:28:43 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(213-229-8-243.static.upcbusiness.at [213.229.8.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 92199BEB;\n\tWed, 11 Sep 2024 18:27:25 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"OyO7wko6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726072045;\n\tbh=z+KlVoIZUC6/zC8EGbcSsls1xYGUWxeBzDj4/qHgR74=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OyO7wko6QDhWty5JFnZhaNZmJ+pjMiKaqlVjshvpnch8f1eMwb1+auKseUL8VBcgL\n\tSm/7PGgGgxpF3pqt8URH1tRF96fi1ZHk3zdHR/LC9BXFeuNuZ3HZWWt1QtEkR67tEu\n\tL0awKDx4CempRfy015R4m+Af1fN6Si3DfImpOSnE=","Date":"Wed, 11 Sep 2024 19:28:08 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v2 1/2] libcamera: controls: Add array information to\n\tControlId","Message-ID":"<20240911162808.GG4470@pendragon.ideasonboard.com>","References":"<20240911162400.1906661-1-paul.elder@ideasonboard.com>\n\t<20240911162400.1906661-2-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240911162400.1906661-2-paul.elder@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]