{"id":19781,"url":"https://patchwork.libcamera.org/api/patches/19781/?format=json","web_url":"https://patchwork.libcamera.org/patch/19781/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240320101652.12873-2-jacopo.mondi@ideasonboard.com>","date":"2024-03-20T10:16:48","name":"[1/4] libcamera: Add 'required' property to controls","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4aea36765dfb3d49b102caa07e0b8843fd8b62a8","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19781/mbox/","series":[{"id":4234,"url":"https://patchwork.libcamera.org/api/series/4234/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4234","date":"2024-03-20T10:16:47","name":"apps: lc-compliance: Properties and multi-stream tests","version":1,"mbox":"https://patchwork.libcamera.org/series/4234/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19781/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19781/checks/","tags":{},"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 D3BD2C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Mar 2024 10:17:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A201462D2F;\n\tWed, 20 Mar 2024 11:17:07 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A093462CA4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Mar 2024 11:17:04 +0100 (CET)","from localhost.localdomain (unknown\n\t[IPv6:2001:b07:5d2e:52c9:cc1e:e404:491f:e6ea])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 320E03F1;\n\tWed, 20 Mar 2024 11:16:37 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YDXbfm78\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710929797;\n\tbh=Dr3Lm/VDL/TUI5SdwOAryBoZL/In+cKNvFijSofBUaM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=YDXbfm787eMEPwbVnkW08EUwTRGrYrxsbxgXLAlVb+mUxwn9o0dSRaYr89AcF6lTJ\n\tIGHJ7yt0zn8+xhOYZgkLpHrocH7rFXu10QYj8ayDp6ptvs8u8Ww4gvbLX4voWBEFvF\n\ti6wN56/eBRIsPssW0z1AHsM6XQgHwhfTDbJJd0GI=","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"[PATCH 1/4] libcamera: Add 'required' property to controls","Date":"Wed, 20 Mar 2024 11:16:48 +0100","Message-ID":"<20240320101652.12873-2-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.44.0","In-Reply-To":"<20240320101652.12873-1-jacopo.mondi@ideasonboard.com>","References":"<20240320101652.12873-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"Add to the ControlId class a 'required' boolean flag that determine\nif the control (or property) is mandatory to be supported by a Camera\nin order to comply with the libcamera API specification.\n\nAdd support for a 'required' field to the controls and properties yaml\nfile definition and control generation scripts.\n\nAlso plumb support for the flag in the control serializer component\nto allow pass the information across IPC borders.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n Documentation/guides/pipeline-handler.rst | 13 ++++++++----\n include/libcamera/controls.h              | 10 ++++++----\n include/libcamera/ipa/ipa_controls.h      |  3 ++-\n src/libcamera/control_serializer.cpp      |  4 +++-\n src/libcamera/controls.cpp                | 24 +++++++++++++++++------\n src/libcamera/ipa_controls.cpp            |  2 ++\n src/libcamera/v4l2_device.cpp             |  2 +-\n utils/gen-controls.py                     |  8 +++++++-\n 8 files changed, 48 insertions(+), 18 deletions(-)","diff":"diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst\nindex 728e9676b4a6..b0d77d795211 100644\n--- a/Documentation/guides/pipeline-handler.rst\n+++ b/Documentation/guides/pipeline-handler.rst\n@@ -610,10 +610,15 @@ information can be found in the `ControlInfoMap`_ class documentation.\n .. _ControlInfoMap: https://libcamera.org/api-html/classlibcamera_1_1ControlInfoMap.html\n \n Pipeline handlers register controls to expose the tunable device and IPA\n-parameters to applications. Our example pipeline handler only exposes trivial\n-controls of the video device, by registering a ``ControlId`` instance with\n-associated values for each supported V4L2 control but demonstrates the mapping\n-of V4L2 Controls to libcamera ControlIDs.\n+parameters to applications and register properties to expose the Camera\n+immutable characteristics. Controls and properties which have the ``required``\n+field specified in the YAML definition are mandatory to be supported by a Camera\n+in order for it to comply with the libcamera API specification.\n+\n+Our example pipeline handler only exposes trivial controls of the video device,\n+by registering a ``ControlId`` instance with associated values for each\n+supported V4L2 control but demonstrates the mapping of V4L2 Controls to\n+libcamera ControlIDs.\n \n Complete the initialization of the ``VividCameraData`` class by adding the\n following code to the ``VividCameraData::init()`` function to initialise the\ndiff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 82b955995380..0382a99de7fa 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -213,14 +213,15 @@ private:\n class ControlId\n {\n public:\n-\tControlId(unsigned int id, const std::string &name, ControlType type)\n-\t\t: id_(id), name_(name), type_(type)\n+\tControlId(unsigned int id, const std::string &name, ControlType type, bool required)\n+\t\t: id_(id), name_(name), type_(type), required_(required)\n \t{\n \t}\n \n \tunsigned int id() const { return id_; }\n \tconst std::string &name() const { return name_; }\n \tControlType type() const { return type_; }\n+\tbool required() const { return required_; }\n \n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(ControlId)\n@@ -228,6 +229,7 @@ private:\n \tunsigned int id_;\n \tstd::string name_;\n \tControlType type_;\n+\tbool required_;\n };\n \n static inline bool operator==(unsigned int lhs, const ControlId &rhs)\n@@ -256,8 +258,8 @@ class Control : public ControlId\n public:\n \tusing type = T;\n \n-\tControl(unsigned int id, const char *name)\n-\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)\n+\tControl(unsigned int id, const char *name, bool required)\n+\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, required)\n \t{\n \t}\n \ndiff --git a/include/libcamera/ipa/ipa_controls.h b/include/libcamera/ipa/ipa_controls.h\nindex e5da1946ce1d..5268b0a8f659 100644\n--- a/include/libcamera/ipa/ipa_controls.h\n+++ b/include/libcamera/ipa/ipa_controls.h\n@@ -46,7 +46,8 @@ struct ipa_control_info_entry {\n \tuint32_t id;\n \tuint32_t type;\n \tuint32_t offset;\n-\tuint32_t padding[1];\n+\tuint8_t required;\n+\tuint8_t padding[3];\n };\n \n #ifdef __cplusplus\ndiff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\nindex 0cf719bde798..b9ed1eea6552 100644\n--- a/src/libcamera/control_serializer.cpp\n+++ b/src/libcamera/control_serializer.cpp\n@@ -281,6 +281,7 @@ int ControlSerializer::serialize(const ControlInfoMap &infoMap,\n \t\tentry.id = id->id();\n \t\tentry.type = id->type();\n \t\tentry.offset = values.offset();\n+\t\tentry.required = id->required();\n \t\tentries.write(&entry);\n \n \t\tstore(info, values);\n@@ -498,7 +499,8 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t\t\t * debugging purpose.\n \t\t\t */\n \t\t\tcontrolIds_.emplace_back(std::make_unique<ControlId>(entry->id,\n-\t\t\t\t\t\t\t\t\t     \"\", type));\n+\t\t\t\t\t\t\t\t\t     \"\", type,\n+\t\t\t\t\t\t\t\t\t     entry->required));\n \t\t\t(*localIdMap)[entry->id] = controlIds_.back().get();\n \t\t}\n \ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 16d3547c8c07..2799d89869d7 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -378,18 +378,19 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n  * \\class ControlId\n  * \\brief Control static metadata\n  *\n- * The ControlId class stores a control ID, name and data type. It provides\n- * unique identification of a control, but without support for compile-time\n- * type deduction that the derived template Control class supports. See the\n- * Control class for more information.\n+ * The ControlId class stores a control ID, name, data type and a boolean\n+ * 'required' flag. It provides unique identification of a control, but without\n+ * support for compile-time type deduction that the derived template Control\n+ * class supports. See the Control class for more information.\n  */\n \n /**\n- * \\fn ControlId::ControlId(unsigned int id, const std::string &name, ControlType type)\n+ * \\fn ControlId::ControlId(unsigned int id, const std::string &name, ControlType type, bool required)\n  * \\brief Construct a ControlId instance\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] required Boolean flag that determine if the control is required\n  */\n \n /**\n@@ -410,6 +411,16 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n  * \\return The control data type\n  */\n \n+/**\n+ * \\fn bool ControlId::required() const\n+ * \\brief Determine if the control is required or not\n+ *\n+ * A control is 'required' if it is mandatory for a Camera to support it to\n+ * comply with the libcamera API specification.\n+ *\n+ * \\return True if the control is required, false otherwise\n+ */\n+\n /**\n  * \\fn bool operator==(unsigned int lhs, const ControlId &rhs)\n  * \\brief Compare a ControlId with a control numerical ID\n@@ -456,10 +467,11 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n  */\n \n /**\n- * \\fn Control::Control(unsigned int id, const char *name)\n+ * \\fn Control::Control(unsigned int id, const char *name, bool required)\n  * \\brief Construct a Control instance\n  * \\param[in] id The control numerical ID\n  * \\param[in] name The control name\n+ * \\param[in] required Boolean flag that determine if a control is required\n  *\n  * The control data type is automatically deduced from the template type T.\n  */\ndiff --git a/src/libcamera/ipa_controls.cpp b/src/libcamera/ipa_controls.cpp\nindex 870a443b0f38..2376cbd9df60 100644\n--- a/src/libcamera/ipa_controls.cpp\n+++ b/src/libcamera/ipa_controls.cpp\n@@ -220,6 +220,8 @@ static_assert(sizeof(ipa_control_value_entry) == 16,\n  * \\var ipa_control_info_entry::offset\n  * The offset in bytes from the beginning of the data section to the control\n  * info data (shall be a multiple of 8 bytes)\n+ * \\var ipa_control_info_entry::required\n+ * Boolean flag that determines if the controls is required or not\n  * \\var ipa_control_info_entry::padding\n  * Padding bytes (shall be set to 0)\n  */\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 24d208ef77dc..b055d14c2e51 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -522,7 +522,7 @@ std::unique_ptr<ControlId> V4L2Device::v4l2ControlId(const v4l2_query_ext_ctrl &\n \tconst std::string name(static_cast<const char *>(ctrl.name), len);\n \tconst ControlType type = v4l2CtrlType(ctrl.type);\n \n-\treturn std::make_unique<ControlId>(ctrl.id, name, type);\n+\treturn std::make_unique<ControlId>(ctrl.id, name, type, false);\n }\n \n /**\ndiff --git a/utils/gen-controls.py b/utils/gen-controls.py\nindex 6cd5e362c66f..1e997708b10d 100755\n--- a/utils/gen-controls.py\n+++ b/utils/gen-controls.py\n@@ -112,6 +112,11 @@ class Control(object):\n         else:\n             return f\"Span<const {typ}>\"\n \n+    @property\n+    def required(self):\n+        \"\"\"Is the control required\"\"\"\n+        return self.__data.get('required')\n+\n \n def snake_case(s):\n     return ''.join([c.isupper() and ('_' + c) or c for c in s]).strip('_')\n@@ -133,7 +138,7 @@ ${description}''')\n  * \\\\var ${name}\n ${description}\n  */''')\n-    def_template = string.Template('extern const Control<${type}> ${name}(${id_name}, \"${name}\");')\n+    def_template = string.Template('extern const Control<${type}> ${name}(${id_name}, \"${name}\", ${required});')\n     enum_values_doc = string.Template('''/**\n  * \\\\var ${name}Values\n  * \\\\brief List of all $name supported values\n@@ -158,6 +163,7 @@ ${description}\n             'type': ctrl.type,\n             'description': format_description(ctrl.description),\n             'id_name': id_name,\n+            'required': \"true\" if ctrl.required else \"false\"\n         }\n \n         target_doc = ctrls_doc[vendor]\n","prefixes":["1/4"]}