{"id":2301,"url":"https://patchwork.libcamera.org/api/1.1/patches/2301/?format=json","web_url":"https://patchwork.libcamera.org/patch/2301/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20191108205409.18845-6-laurent.pinchart@ideasonboard.com>","date":"2019-11-08T20:53:50","name":"[libcamera-devel,v2,05/24] libcamera: controls: Index ControlList by unsigned int","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"76f72af85822822782b29c3ef0fd871002eb42f1","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2301/mbox/","series":[{"id":568,"url":"https://patchwork.libcamera.org/api/1.1/series/568/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=568","date":"2019-11-08T20:53:45","name":"Control serialization and IPA C API","version":2,"mbox":"https://patchwork.libcamera.org/series/568/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2301/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2301/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2355161518\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Nov 2019 21:54:24 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B34EE31D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Nov 2019 21:54:23 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1573246463;\n\tbh=H6M8NSZF6jSyz1p/+mvTTR2Qq5ZmYJYZRMI1+csblmg=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=o9PLxABGMqywmoM+H86TL+A4Nhh8i7pwYSnmHif5+Y+vpxWbqC/6e6rbH7dCjuqM5\n\tj9Xfq3NTqZLXI74IL277chN35D+xC9qaG6IZteBB4yFRJWRjGC3i+vwfNVHKAWl3on\n\tLxbowFQ6Ro4uZpP8gltvdmx1Xl6CDTiPJq8bPiD0=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  8 Nov 2019 22:53:50 +0200","Message-Id":"<20191108205409.18845-6-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.23.0","In-Reply-To":"<20191108205409.18845-1-laurent.pinchart@ideasonboard.com>","References":"<20191108205409.18845-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 05/24] libcamera: controls: Index\n\tControlList by unsigned int","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>","X-List-Received-Date":"Fri, 08 Nov 2019 20:54:25 -0000"},"content":"In preparation for serialization, index the ControlList by unsigned int.\nThis will allow deserializing a ControlList without requiring external\ninformation.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/controls.h              | 26 +++++++---\n src/libcamera/camera_controls.cpp         |  4 +-\n src/libcamera/controls.cpp                | 59 +++++++++--------------\n src/libcamera/include/camera_controls.h   |  2 +-\n src/libcamera/include/control_validator.h |  2 +-\n src/libcamera/pipeline/uvcvideo.cpp       |  4 +-\n src/libcamera/pipeline/vimc.cpp           |  4 +-\n src/libcamera/v4l2_device.cpp             | 23 ++++-----\n 8 files changed, 60 insertions(+), 64 deletions(-)","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 19075858fbba..f9979a466eaa 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -78,12 +78,22 @@ private:\n \tControlType type_;\n };\n \n-static inline bool operator==(const ControlId &lhs, const ControlId &rhs)\n+static inline bool operator==(unsigned int lhs, const ControlId &rhs)\n {\n-\treturn lhs.id() == rhs.id();\n+\treturn lhs == rhs.id();\n }\n \n-static inline bool operator!=(const ControlId &lhs, const ControlId &rhs)\n+static inline bool operator!=(unsigned int lhs, const ControlId &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n+static inline bool operator==(const ControlId &lhs, unsigned int rhs)\n+{\n+\treturn lhs.id() == rhs;\n+}\n+\n+static inline bool operator!=(const ControlId &lhs, unsigned int rhs)\n {\n \treturn !(lhs == rhs);\n }\n@@ -175,7 +185,7 @@ private:\n class ControlList\n {\n private:\n-\tusing ControlListMap = std::unordered_map<const ControlId *, ControlValue>;\n+\tusing ControlListMap = std::unordered_map<unsigned int, ControlValue>;\n \n public:\n \tControlList(const ControlIdMap &idmap, ControlValidator *validator = nullptr);\n@@ -199,7 +209,7 @@ public:\n \ttemplate<typename T>\n \tconst T &get(const Control<T> &ctrl) const\n \t{\n-\t\tconst ControlValue *val = find(ctrl);\n+\t\tconst ControlValue *val = find(ctrl.id());\n \t\tif (!val) {\n \t\t\tstatic T t(0);\n \t\t\treturn t;\n@@ -211,7 +221,7 @@ public:\n \ttemplate<typename T>\n \tvoid set(const Control<T> &ctrl, const T &value)\n \t{\n-\t\tControlValue *val = find(ctrl);\n+\t\tControlValue *val = find(ctrl.id());\n \t\tif (!val)\n \t\t\treturn;\n \n@@ -222,8 +232,8 @@ public:\n \tvoid set(unsigned int id, const ControlValue &value);\n \n private:\n-\tconst ControlValue *find(const ControlId &id) const;\n-\tControlValue *find(const ControlId &id);\n+\tconst ControlValue *find(unsigned int id) const;\n+\tControlValue *find(unsigned int id);\n \n \tControlValidator *validator_;\n \tconst ControlIdMap *idmap_;\ndiff --git a/src/libcamera/camera_controls.cpp b/src/libcamera/camera_controls.cpp\nindex 341da56019f7..59dcede2ca36 100644\n--- a/src/libcamera/camera_controls.cpp\n+++ b/src/libcamera/camera_controls.cpp\n@@ -44,10 +44,10 @@ const std::string &CameraControlValidator::name() const\n  * \\param[in] id The control ID\n  * \\return True if the control is valid, false otherwise\n  */\n-bool CameraControlValidator::validate(const ControlId &id) const\n+bool CameraControlValidator::validate(unsigned int id) const\n {\n \tconst ControlInfoMap &controls = camera_->controls();\n-\treturn controls.find(&id) != controls.end();\n+\treturn controls.find(id) != controls.end();\n }\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 2c5c98633585..021d5f0990e0 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -259,16 +259,21 @@ bool ControlValue::operator==(const ControlValue &other) const\n  */\n \n /**\n- * \\fn bool operator==(const ControlId &lhs, const ControlId &rhs)\n- * \\brief Compare two ControlId instances for equality\n- * \\param[in] lhs Left-hand side ControlId\n+ * \\fn bool operator==(unsigned int lhs, const ControlId &rhs)\n+ * \\brief Compare a ControlId with a control numerical ID\n+ * \\param[in] lhs Left-hand side numerical ID\n  * \\param[in] rhs Right-hand side ControlId\n  *\n- * ControlId instances are compared based on the numerical ControlId::id()\n- * only, as an object may not have two separate controls with the same\n- * numerical ID.\n+ * \\return True if \\a lhs is equal to \\a rhs.id(), false otherwise\n+ */\n+\n+/**\n+ * \\fn bool operator==(const ControlId &lhs, unsigned int rhs)\n+ * \\brief Compare a ControlId with a control numerical ID\n+ * \\param[in] lhs Left-hand side ControlId\n+ * \\param[in] rhs Right-hand side numerical ID\n  *\n- * \\return True if \\a lhs and \\a rhs have equal control IDs, false otherwise\n+ * \\return True if \\a lhs.id() is equal to \\a rhs, false otherwise\n  */\n \n /**\n@@ -655,7 +660,7 @@ ControlList::ControlList(const ControlInfoMap &info, ControlValidator *validator\n  */\n bool ControlList::contains(const ControlId &id) const\n {\n-\treturn controls_.find(&id) != controls_.end();\n+\treturn controls_.find(id.id()) != controls_.end();\n }\n \n /**\n@@ -666,11 +671,7 @@ bool ControlList::contains(const ControlId &id) const\n  */\n bool ControlList::contains(unsigned int id) const\n {\n-\tconst auto iter = idmap_->find(id);\n-\tif (iter == idmap_->end())\n-\t\treturn false;\n-\n-\treturn contains(*iter->second);\n+\treturn controls_.find(id) != controls_.end();\n }\n \n /**\n@@ -716,15 +717,7 @@ const ControlValue &ControlList::get(unsigned int id) const\n {\n \tstatic ControlValue zero;\n \n-\tconst auto ctrl = idmap_->find(id);\n-\tif (ctrl == idmap_->end()) {\n-\t\tLOG(Controls, Error)\n-\t\t\t<< \"Control \" << utils::hex(id)\n-\t\t\t<< \" is not supported\";\n-\t\treturn zero;\n-\t}\n-\n-\tconst ControlValue *val = find(*ctrl->second);\n+\tconst ControlValue *val = find(id);\n \tif (!val)\n \t\treturn zero;\n \n@@ -745,27 +738,19 @@ const ControlValue &ControlList::get(unsigned int id) const\n  */\n void ControlList::set(unsigned int id, const ControlValue &value)\n {\n-\tconst auto ctrl = idmap_->find(id);\n-\tif (ctrl == idmap_->end()) {\n-\t\tLOG(Controls, Error)\n-\t\t\t<< \"Control 0x\" << utils::hex(id)\n-\t\t\t<< \" is not supported\";\n-\t\treturn;\n-\t}\n-\n-\tControlValue *val = find(*ctrl->second);\n+\tControlValue *val = find(id);\n \tif (!val)\n \t\treturn;\n \n \t*val = value;\n }\n \n-const ControlValue *ControlList::find(const ControlId &id) const\n+const ControlValue *ControlList::find(unsigned int id) const\n {\n-\tconst auto iter = controls_.find(&id);\n+\tconst auto iter = controls_.find(id);\n \tif (iter == controls_.end()) {\n \t\tLOG(Controls, Error)\n-\t\t\t<< \"Control \" << id.name() << \" not found\";\n+\t\t\t<< \"Control \" << utils::hex(id) << \" not found\";\n \n \t\treturn nullptr;\n \t}\n@@ -773,16 +758,16 @@ const ControlValue *ControlList::find(const ControlId &id) const\n \treturn &iter->second;\n }\n \n-ControlValue *ControlList::find(const ControlId &id)\n+ControlValue *ControlList::find(unsigned int id)\n {\n \tif (validator_ && !validator_->validate(id)) {\n \t\tLOG(Controls, Error)\n-\t\t\t<< \"Control \" << id.name()\n+\t\t\t<< \"Control \" << utils::hex(id)\n \t\t\t<< \" is not valid for \" << validator_->name();\n \t\treturn nullptr;\n \t}\n \n-\treturn &controls_[&id];\n+\treturn &controls_[id];\n }\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/camera_controls.h b/src/libcamera/include/camera_controls.h\nindex 998a2d155a44..265c1fe379db 100644\n--- a/src/libcamera/include/camera_controls.h\n+++ b/src/libcamera/include/camera_controls.h\n@@ -19,7 +19,7 @@ public:\n \tCameraControlValidator(Camera *camera);\n \n \tconst std::string &name() const override;\n-\tbool validate(const ControlId &id) const override;\n+\tbool validate(unsigned int id) const override;\n \n private:\n \tCamera *camera_;\ndiff --git a/src/libcamera/include/control_validator.h b/src/libcamera/include/control_validator.h\nindex 3598b18f2f26..f1c9110b158f 100644\n--- a/src/libcamera/include/control_validator.h\n+++ b/src/libcamera/include/control_validator.h\n@@ -19,7 +19,7 @@ public:\n \tvirtual ~ControlValidator() {}\n \n \tvirtual const std::string &name() const = 0;\n-\tvirtual bool validate(const ControlId &id) const = 0;\n+\tvirtual bool validate(unsigned int id) const = 0;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex 45448d6f8c05..522229241ffb 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -231,7 +231,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \tControlList controls(data->video_->controls());\n \n \tfor (auto it : request->controls()) {\n-\t\tconst ControlId &id = *it.first;\n+\t\tunsigned int id = it.first;\n \t\tControlValue &value = it.second;\n \n \t\tif (id == controls::Brightness) {\n@@ -250,7 +250,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \n \tfor (const auto &ctrl : controls)\n \t\tLOG(UVC, Debug)\n-\t\t\t<< \"Setting control \" << ctrl.first->name()\n+\t\t\t<< \"Setting control \" << utils::hex(ctrl.first)\n \t\t\t<< \" to \" << ctrl.second.toString();\n \n \tint ret = data->video_->setControls(&controls);\ndiff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex e6ab6a085824..06664fed42e7 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -298,7 +298,7 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n \tControlList controls(data->sensor_->controls());\n \n \tfor (auto it : request->controls()) {\n-\t\tconst ControlId &id = *it.first;\n+\t\tunsigned int id = it.first;\n \t\tControlValue &value = it.second;\n \n \t\tif (id == controls::Brightness)\n@@ -311,7 +311,7 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n \n \tfor (const auto &ctrl : controls)\n \t\tLOG(VIMC, Debug)\n-\t\t\t<< \"Setting control \" << ctrl.first->name()\n+\t\t\t<< \"Setting control \" << utils::hex(ctrl.first)\n \t\t\t<< \" to \" << ctrl.second.toString();\n \n \tint ret = data->sensor_->setControls(&controls);\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex a2b0d891b12f..0452f801029c 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -176,15 +176,15 @@ int V4L2Device::getControls(ControlList *ctrls)\n \n \tunsigned int i = 0;\n \tfor (const auto &ctrl : *ctrls) {\n-\t\tconst ControlId *id = ctrl.first;\n-\t\tconst auto iter = controls_.find(id->id());\n+\t\tunsigned int id = ctrl.first;\n+\t\tconst auto iter = controls_.find(id);\n \t\tif (iter == controls_.end()) {\n \t\t\tLOG(V4L2, Error)\n-\t\t\t\t<< \"Control '\" << id->name() << \"' not found\";\n+\t\t\t\t<< \"Control \" << utils::hex(id) << \" not found\";\n \t\t\treturn -EINVAL;\n \t\t}\n \n-\t\tv4l2Ctrls[i].id = id->id();\n+\t\tv4l2Ctrls[i].id = id;\n \t\ti++;\n \t}\n \n@@ -250,19 +250,19 @@ int V4L2Device::setControls(ControlList *ctrls)\n \n \tunsigned int i = 0;\n \tfor (const auto &ctrl : *ctrls) {\n-\t\tconst ControlId *id = ctrl.first;\n-\t\tconst auto iter = controls_.find(id->id());\n+\t\tunsigned int id = ctrl.first;\n+\t\tconst auto iter = controls_.find(id);\n \t\tif (iter == controls_.end()) {\n \t\t\tLOG(V4L2, Error)\n-\t\t\t\t<< \"Control '\" << id->name() << \"' not found\";\n+\t\t\t\t<< \"Control \" << utils::hex(id) << \" not found\";\n \t\t\treturn -EINVAL;\n \t\t}\n \n-\t\tv4l2Ctrls[i].id = id->id();\n+\t\tv4l2Ctrls[i].id = id;\n \n \t\t/* Set the v4l2_ext_control value for the write operation. */\n \t\tconst ControlValue &value = ctrl.second;\n-\t\tswitch (id->type()) {\n+\t\tswitch (iter->first->type()) {\n \t\tcase ControlTypeInteger64:\n \t\t\tv4l2Ctrls[i].value64 = value.get<int64_t>();\n \t\t\tbreak;\n@@ -403,10 +403,11 @@ void V4L2Device::updateControls(ControlList *ctrls,\n \t\t\tbreak;\n \n \t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n-\t\tconst ControlId *id = ctrl.first;\n+\t\tunsigned int id = ctrl.first;\n \t\tControlValue &value = ctrl.second;\n \n-\t\tswitch (id->type()) {\n+\t\tconst auto iter = controls_.find(id);\n+\t\tswitch (iter->first->type()) {\n \t\tcase ControlTypeInteger64:\n \t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n \t\t\tbreak;\n","prefixes":["libcamera-devel","v2","05/24"]}