[{"id":2101,"web_url":"https://patchwork.libcamera.org/comment/2101/","msgid":"<20190701234233.GD9228@bigcity.dyn.berto.se>","date":"2019-07-01T23:42:33","subject":"Re: [libcamera-devel] [PATCH v4 02/13] libcamera: v4l2_device: Add\n\tmethod to retrieve all supported controls","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2019-07-01 23:14:53 +0300, Laurent Pinchart wrote:\n> Add a new controls() method to the V4L2Device class to retrieve the map\n> of all supported controls. This is needed in order to dynamically query\n> the supported controls, for instance for drivers that support different\n> sets of controls depending on the device model.\n> \n> To make the API easier to use, create a type alias for the control ID to\n> ControlInfo and use it.\n> \n> Remove the getControlInfo() method that is not used externally, as it\n> can now be replaced by accessing the full list of controls.\n> \n> Update the CameraSensor API accordingly.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\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(-)\n> \n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 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>  /**\n> diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> index 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>  \n> diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\n> index 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:\n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 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>  };\n> diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\n> index 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\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 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> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x144.google.com (mail-lf1-x144.google.com\n\t[IPv6:2a00:1450:4864:20::144])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C29A60BF8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Jul 2019 01:42:35 +0200 (CEST)","by mail-lf1-x144.google.com with SMTP id x144so9962464lfa.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 01 Jul 2019 16:42:35 -0700 (PDT)","from localhost (customer-145-14-112-32.stosn.net. [145.14.112.32])\n\tby smtp.gmail.com with ESMTPSA id\n\tr17sm3486890ljc.85.2019.07.01.16.42.33\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tMon, 01 Jul 2019 16:42:34 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=HMdpoIJH4APfrPr5ObWWhwhqedjAkcSj8SCjQZHSM5w=;\n\tb=Jow5opicXnShmdiN5igEpaIbhzJH1Gc2t02Mxx0UL0gR5hYhSVj0IlvXHIVVSJZe1V\n\tY4N8fSAnOGWsX1VFcZunrK02Nkpnxlu78IUYp85Wn4RtIUfMcJQNEGQz/gmyOFcIn+EP\n\txScaeMSKYnUeem81UXXeBqZfphjM5Oi3sUP6GG0TFQ0wONKC8+oQWKGinHOKE12ksltl\n\tqTXjUG5mhyT2uqs0ljM87f0iG1M0f5qUDfBMgGZ0GGQ9z6iWwg3kvJiWYuF4V0p2FvZq\n\t5ZR1ctynC87DnhWsH9AonxK4EZNEBrJWzrlx8tjDqUjxzIDpbnjjoKp+zFCdzhTL2Oj/\n\tJ/HQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=HMdpoIJH4APfrPr5ObWWhwhqedjAkcSj8SCjQZHSM5w=;\n\tb=s0AvPrxY7H6n5170w4zhsFLRG5n/o2rDUblWbZrMfUpikZwMkJWOUXM3Zrui6vFmjO\n\tuKSui68FuwYMLVoT5rWnmXTR4+l03KDK2EyKWfqOZVhIZMi/7Qfj5V6dSvC0K7fuIBU5\n\tvwm00UWCGElMBNSbH7imBPqItahd0M5cjdGpmN9XVG4vV4AT+H3AK6Ii/DdAGqBz18Dv\n\tVReQeNP39Qm8hbH9il/ir68S6tOM8+uUQrOnLDqOQYTO49sAahlheXR07gNqTLEYLbt6\n\tsL+oKdq7UuMqZhkwfr0NxzzCBhe2f/HuoO7amTrNC8IbzbxOSK3MJkdyNOuB+3N0+RGD\n\t9YKQ==","X-Gm-Message-State":"APjAAAUEgNRPHtc05Ad3Kx3eY4trWHRXBExX2Mjpg9ky23visEr22nfk\n\tCIj0e0LNYa7lzvMg+a4At+uLzhYg6lU=","X-Google-Smtp-Source":"APXvYqznKp2VVCs+QR5K2+HU0CCi0E+58uWaz9+fWsHhPZ1N4Lj+HBRAP4iXMtmzvMDwP4E/Wac7Qw==","X-Received":"by 2002:ac2:5382:: with SMTP id g2mr12390525lfh.92.1562024554584;\n\tMon, 01 Jul 2019 16:42:34 -0700 (PDT)","Date":"Tue, 2 Jul 2019 01:42:33 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190701234233.GD9228@bigcity.dyn.berto.se>","References":"<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>\n\t<20190701201504.28487-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190701201504.28487-3-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [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 23:42:35 -0000"}}]