{"id":1561,"url":"https://patchwork.libcamera.org/api/patches/1561/?format=json","web_url":"https://patchwork.libcamera.org/patch/1561/","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":"<20190701201504.28487-3-laurent.pinchart@ideasonboard.com>","date":"2019-07-01T20:14:53","name":"[libcamera-devel,v4,02/13] libcamera: v4l2_device: Add method to retrieve all supported controls","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"7bc65438464e1927ea3e18106b0d610ab97df5c0","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1561/mbox/","series":[{"id":386,"url":"https://patchwork.libcamera.org/api/series/386/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=386","date":"2019-07-01T20:14:51","name":"libcamera Controls","version":4,"mbox":"https://patchwork.libcamera.org/series/386/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1561/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1561/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 0EE236157D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 22:15:29 +0200 (CEST)","from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B2E8B120A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 22:15:28 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562012128;\n\tbh=r4GlBeFbCtEwZuFYOy++W3PzOUZo4tKOrRSt+OvtyX4=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=BtCYWTZPMt9i1pIR8+OY7sI+6kWoK4y6KBFvwjZIgdwROAZpkIV+DKK/ayPRe5KmW\n\t6D57b1HUso5kEfs3/HAuQYbyUgu4r64ZjNXW3tFU49OowiTSdaRT94TvSIw/qM/gWe\n\t5+RvGTKoD/vTYzozxQyQ6I7T42Yd87GPJixNdAF8=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  1 Jul 2019 23:14:53 +0300","Message-Id":"<20190701201504.28487-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>","References":"<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 02/13] libcamera: v4l2_device: Add\n\tmethod to retrieve all supported controls","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Mon, 01 Jul 2019 20:15:29 -0000"},"content":"Add a new controls() method to the V4L2Device class to retrieve the map\nof all supported controls. This is needed in order to dynamically query\nthe supported controls, for instance for drivers that support different\nsets of controls depending on the device model.\n\nTo make the API easier to use, create a type alias for the control ID to\nControlInfo and use it.\n\nRemove the getControlInfo() method that is not used externally, as it\ncan now be replaced by accessing the full list of controls.\n\nUpdate the CameraSensor API accordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/camera_sensor.cpp       | 10 ++++------\n src/libcamera/include/camera_sensor.h |  5 ++---\n src/libcamera/include/v4l2_controls.h |  6 ++++--\n src/libcamera/include/v4l2_device.h   |  9 ++++-----\n src/libcamera/v4l2_controls.cpp       |  5 +++++\n src/libcamera/v4l2_device.cpp         | 25 +++++++++----------------\n 6 files changed, 28 insertions(+), 32 deletions(-)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 471c3e2e6e47..a7670b449b31 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -248,14 +248,12 @@ int CameraSensor::setFormat(V4L2SubdeviceFormat *format)\n }\n \n /**\n- * \\brief Retrieve information about a control\n- * \\param[in] id The control ID\n- * \\return A pointer to the V4L2ControlInfo for control \\a id, or nullptr\n- * if the sensor doesn't have such a control\n+ * \\brief Retrieve the supported V4L2 controls and their information\n+ * \\return A map of the V4L2 controls supported by the sensor\n  */\n-const V4L2ControlInfo *CameraSensor::getControlInfo(unsigned int id) const\n+const V4L2ControlInfoMap &CameraSensor::controls() const\n {\n-\treturn subdev_->getControlInfo(id);\n+\treturn subdev_->controls();\n }\n \n /**\ndiff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\nindex b42e7b8e1343..fe033fb374c1 100644\n--- a/src/libcamera/include/camera_sensor.h\n+++ b/src/libcamera/include/camera_sensor.h\n@@ -13,12 +13,11 @@\n #include <libcamera/geometry.h>\n \n #include \"log.h\"\n+#include \"v4l2_controls.h\"\n \n namespace libcamera {\n \n class MediaEntity;\n-class V4L2ControlInfo;\n-class V4L2ControlList;\n class V4L2Subdevice;\n \n struct V4L2SubdeviceFormat;\n@@ -43,7 +42,7 @@ public:\n \t\t\t\t      const Size &size) const;\n \tint setFormat(V4L2SubdeviceFormat *format);\n \n-\tconst V4L2ControlInfo *getControlInfo(unsigned int id) const;\n+\tconst V4L2ControlInfoMap &controls() const;\n \tint getControls(V4L2ControlList *ctrls);\n \tint setControls(V4L2ControlList *ctrls);\n \ndiff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\nindex 0047efab11fa..10b726504951 100644\n--- a/src/libcamera/include/v4l2_controls.h\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -8,11 +8,11 @@\n #ifndef __LIBCAMERA_V4L2_CONTROLS_H__\n #define __LIBCAMERA_V4L2_CONTROLS_H__\n \n+#include <map>\n+#include <stdint.h>\n #include <string>\n #include <vector>\n \n-#include <stdint.h>\n-\n #include <linux/v4l2-controls.h>\n #include <linux/videodev2.h>\n \n@@ -41,6 +41,8 @@ private:\n \tint64_t max_;\n };\n \n+using V4L2ControlInfoMap = std::map<unsigned int, V4L2ControlInfo>;\n+\n class V4L2Control\n {\n public:\ndiff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 24a0134a2cba..e7e9829cb05f 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -13,19 +13,18 @@\n #include <linux/videodev2.h>\n \n #include \"log.h\"\n+#include \"v4l2_controls.h\"\n \n namespace libcamera {\n \n-class V4L2ControlInfo;\n-class V4L2ControlList;\n-\n class V4L2Device : protected Loggable\n {\n public:\n \tvoid close();\n \tbool isOpen() const { return fd_ != -1; }\n \n-\tconst V4L2ControlInfo *getControlInfo(unsigned int id) const;\n+\tconst V4L2ControlInfoMap &controls() const { return controls_; }\n+\n \tint getControls(V4L2ControlList *ctrls);\n \tint setControls(V4L2ControlList *ctrls);\n \n@@ -48,7 +47,7 @@ private:\n \t\t\t    const struct v4l2_ext_control *v4l2Ctrls,\n \t\t\t    unsigned int count);\n \n-\tstd::map<unsigned int, V4L2ControlInfo> controls_;\n+\tV4L2ControlInfoMap controls_;\n \tstd::string deviceNode_;\n \tint fd_;\n };\ndiff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\nindex af017bce48ba..84258d9954d0 100644\n--- a/src/libcamera/v4l2_controls.cpp\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -114,6 +114,11 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n  * \\return The V4L2 control maximum value\n  */\n \n+/**\n+ * \\typedef V4L2ControlInfoMap\n+ * \\brief A map of control ID to V4L2ControlInfo\n+ */\n+\n /**\n  * \\class V4L2Control\n  * \\brief A V4L2 control value\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 06939dead705..e3ec44a7f156 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -111,19 +111,10 @@ void V4L2Device::close()\n  */\n \n /**\n- * \\brief Retrieve information about a control\n- * \\param[in] id The control ID\n- * \\return A pointer to the V4L2ControlInfo for control \\a id, or nullptr\n- * if the device doesn't have such a control\n+ * \\fn V4L2Device::controls()\n+ * \\brief Retrieve the supported V4L2 controls and their information\n+ * \\return A map of the V4L2 controls supported by the device\n  */\n-const V4L2ControlInfo *V4L2Device::getControlInfo(unsigned int id) const\n-{\n-\tauto it = controls_.find(id);\n-\tif (it == controls_.end())\n-\t\treturn nullptr;\n-\n-\treturn &it->second;\n-}\n \n /**\n  * \\brief Read controls from the device\n@@ -158,13 +149,14 @@ int V4L2Device::getControls(V4L2ControlList *ctrls)\n \n \tfor (unsigned int i = 0; i < count; ++i) {\n \t\tconst V4L2Control *ctrl = ctrls->getByIndex(i);\n-\t\tconst V4L2ControlInfo *info = getControlInfo(ctrl->id());\n-\t\tif (!info) {\n+\t\tconst auto iter = controls_.find(ctrl->id());\n+\t\tif (iter == controls_.end()) {\n \t\t\tLOG(V4L2, Error)\n \t\t\t\t<< \"Control '\" << ctrl->id() << \"' not found\";\n \t\t\treturn -EINVAL;\n \t\t}\n \n+\t\tconst V4L2ControlInfo *info = &iter->second;\n \t\tcontrolInfo[i] = info;\n \t\tv4l2Ctrls[i].id = info->id();\n \t}\n@@ -232,13 +224,14 @@ int V4L2Device::setControls(V4L2ControlList *ctrls)\n \n \tfor (unsigned int i = 0; i < count; ++i) {\n \t\tconst V4L2Control *ctrl = ctrls->getByIndex(i);\n-\t\tconst V4L2ControlInfo *info = getControlInfo(ctrl->id());\n-\t\tif (!info) {\n+\t\tconst auto iter = controls_.find(ctrl->id());\n+\t\tif (iter == controls_.end()) {\n \t\t\tLOG(V4L2, Error)\n \t\t\t\t<< \"Control '\" << ctrl->id() << \"' not found\";\n \t\t\treturn -EINVAL;\n \t\t}\n \n+\t\tconst V4L2ControlInfo *info = &iter->second;\n \t\tcontrolInfo[i] = info;\n \t\tv4l2Ctrls[i].id = info->id();\n \n","prefixes":["libcamera-devel","v4","02/13"]}