[{"id":1952,"web_url":"https://patchwork.libcamera.org/comment/1952/","msgid":"<20190619200112.GM21753@pendragon.ideasonboard.com>","date":"2019-06-19T20:01:12","subject":"Re: [libcamera-devel] [PATCH v4 2/6] libcamera: v4l2_device: List\n\tcontrols at device open","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Jun 19, 2019 at 01:08:54PM +0200, Jacopo Mondi wrote:\n> Enumerate all the controls a device supports at open() time.\n> Store the control informations in a map inside the device to save\n> querying the control when setting or getting its value from the device.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/include/v4l2_device.h |  8 +++++++-\n>  src/libcamera/v4l2_device.cpp       | 30 +++++++++++++++++++++++++++++\n>  2 files changed, 37 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 2c26f3eae2b4..563be151c257 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -7,12 +7,15 @@\n>  #ifndef __LIBCAMERA_V4L2_DEVICE_H__\n>  #define __LIBCAMERA_V4L2_DEVICE_H__\n>  \n> +#include <map>\n>  #include <string>\n>  \n>  #include \"log.h\"\n>  \n>  namespace libcamera {\n>  \n> +class V4L2ControlInfo;\n> +\n>  class V4L2Device : protected Loggable\n>  {\n>  public:\n> @@ -22,7 +25,7 @@ public:\n>  \n>  protected:\n>  \tV4L2Device(const std::string &deviceNode, const std::string &logTag);\n> -\t~V4L2Device() {}\n> +\t~V4L2Device();\n>  \n>  \tint fd() { return fd_; }\n>  \n> @@ -33,6 +36,9 @@ protected:\n>  \tstd::string logPrefix() const { return \"'\" + logTag_ + \"'\"; }\n>  \n>  private:\n> +\tvoid listControls();\n> +\n> +\tstd::map<unsigned int, V4L2ControlInfo *> controls_;\n>  \tstd::string deviceNode_;\n>  \tstd::string logTag_;\n>  \tint fd_;\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index eeed0a70fb0e..58dd94836686 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -13,6 +13,7 @@\n>  #include <unistd.h>\n>  \n>  #include \"log.h\"\n> +#include \"v4l2_controls.h\"\n>  \n>  /**\n>   * \\file v4l2_device.h\n> @@ -82,6 +83,12 @@ V4L2Device::V4L2Device(const std::string &deviceNode, const std::string &logTag)\n>  {\n>  }\n>  \n> +V4L2Device::~V4L2Device()\n> +{\n> +\tfor (auto &pair : controls_)\n> +\t\tdelete pair.second;\n> +}\n> +\n>  /**\n>   * \\fn V4L2Device::fd()\n>   * \\brief Retrieve the V4L2 device file descriptor\n> @@ -114,6 +121,8 @@ int V4L2Device::open(unsigned int flags)\n>  \n>  \tfd_ = ret;\n>  \n> +\tlistControls();\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -141,4 +150,25 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n>   * \\return The tag to prefix log messages with\n>   */\n>  \n> +/*\n> + * \\brief List and store all controls supported by the V4L2 device\n\n\"List and store information about all controls supported by the V4L2\ndevice\"\n\n> + */\n> +void V4L2Device::listControls()\n> +{\n> +\tstruct v4l2_query_ext_ctrl ctrl = {};\n> +\n> +\t/* \\todo: add support for menu and compound controls. */\n\nNo need for a colon after any doxygen tag. \\todo Add support ...\n\n> +\tctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;\n> +\twhile (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl) == 0) {\n> +\t\tif (ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS ||\n> +\t\t    ctrl.flags & V4L2_CTRL_FLAG_DISABLED) {\n> +\t\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n> +\t\t\tcontinue;\n> +\t\t}\n> +\n> +\t\tcontrols_[ctrl.id] = new V4L2ControlInfo(ctrl);\n\nWould it be feasible to store a V4L2ControlInfo in the map instead of a\npointer ? That would simplify the destructor.\n\n> +\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n> +\t}\n> +}\n> +\n>  } /* namespace libcamera */","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BB0F460BC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Jun 2019 22:01:30 +0200 (CEST)","from pendragon.ideasonboard.com\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 2EE2B333;\n\tWed, 19 Jun 2019 22:01:30 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1560974490;\n\tbh=BrP3h6UKNZ3tkHNKJzPAgZ7+JWBHc9p9AxHlmfQQXHU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=p/MNlsmUqJjqvOPPmxM3sIa6HgnVN5aewe/JbRYtGHiIO4IJM0gpTyb/xb/KJ+AZB\n\tqWcZlyI+McsR4gmGMyWuwpOxIQKGBa/h5z45b6vueDD1uP2aRf/A5BWwDIonvXOf4y\n\tOCGlPOlptm/yfbmWtuK6rSf8jFA1Cv6jP11KKTVs=","Date":"Wed, 19 Jun 2019 23:01:12 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190619200112.GM21753@pendragon.ideasonboard.com>","References":"<20190619110858.20980-1-jacopo@jmondi.org>\n\t<20190619110858.20980-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190619110858.20980-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v4 2/6] libcamera: v4l2_device: List\n\tcontrols at device open","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":"Wed, 19 Jun 2019 20:01:30 -0000"}}]