[{"id":2009,"web_url":"https://patchwork.libcamera.org/comment/2009/","msgid":"<20190624160158.GN5737@pendragon.ideasonboard.com>","date":"2019-06-24T16:01:58","subject":"Re: [libcamera-devel] [PATCH v6 2/6] libcamera: v4l2_device: List\n\tvalid controls at 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 Mon, Jun 24, 2019 at 04:28:55PM +0200, Jacopo Mondi wrote:\n> Enumerate all the valid controls a device supports at open() time.\n> A control is valid only if its type is supported.\n> \n> Store the control information in a map inside the device to save\n> querying the control when setting or getting its value from the device\n> and provide an operation to retrieve information by control ID.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/libcamera/include/v4l2_device.h |  8 ++++\n>  src/libcamera/v4l2_device.cpp       | 57 +++++++++++++++++++++++++++++\n>  2 files changed, 65 insertions(+)\n> \n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 75f23a05b903..556960467e10 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -7,18 +7,23 @@\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>  \tvoid close();\n>  \tbool isOpen() const { return fd_ != -1; }\n>  \n> +\tconst V4L2ControlInfo *getControlInfo(unsigned int id) const;\n> +\n>  \tconst std::string &deviceNode() const { return deviceNode_; }\n>  \n>  protected:\n> @@ -32,6 +37,9 @@ protected:\n>  \tint fd() { return fd_; }\n>  \n>  private:\n> +\tvoid listControls();\n> +\n> +\tstd::map<unsigned int, V4L2ControlInfo> controls_;\n>  \tstd::string deviceNode_;\n>  \tint fd_;\n>  };\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 99621a724b96..51764b441f92 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,8 @@ int V4L2Device::open(unsigned int flags)\n>  \n>  \tfd_ = ret;\n>  \n> +\tlistControls();\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -107,6 +110,21 @@ void V4L2Device::close()\n>   * \\return True if the V4L2 device node is open, false otherwise\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> + */\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 Perform an IOCTL system call on the device node\n>   * \\param[in] request The IOCTL request code\n> @@ -137,4 +155,43 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n>   * \\return The V4L2 device file descriptor, -1 if the device node is not open\n>   */\n>  \n> +/*\n> + * \\brief List and store information about all controls supported by the\n> + * V4L2 device\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> +\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\tV4L2ControlInfo info(ctrl);\n> +\t\tswitch (info.type()) {\n> +\t\tcase V4L2_CTRL_TYPE_INTEGER:\n> +\t\tcase V4L2_CTRL_TYPE_BOOLEAN:\n> +\t\tcase V4L2_CTRL_TYPE_MENU:\n> +\t\tcase V4L2_CTRL_TYPE_BUTTON:\n> +\t\tcase V4L2_CTRL_TYPE_INTEGER64:\n> +\t\tcase V4L2_CTRL_TYPE_BITMASK:\n> +\t\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n> +\t\t\tbreak;\n> +\t\t/* \\todo Support compound controls. */\n> +\t\tdefault:\n> +\t\t\tLOG(V4L2, Error) << \"Control type '\" << info.type()\n> +\t\t\t\t\t << \"' not supported\";\n> +\t\t\tcontinue;\n> +\t\t}\n> +\n> +\t\tcontrols_.emplace(ctrl.id, info);\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 7F84F61580\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Jun 2019 18:04:26 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1C4FE52F;\n\tMon, 24 Jun 2019 18:04:26 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1561392266;\n\tbh=7l8oc1/0AauiB2EEO34oShVNG7ZTGJV1eJHl/DlAH/Q=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LFciPAxP4Wzfqum8nniiLrCuLPUrM5CXtaYhY5RfkbzHOG7FjqMyXFd2ZF3eqTpvZ\n\tW2NbcjaSd6U6DDFNlq/sWYPWQO6N/5WEVJp86pp/en93DE8NoNojwtc2upidYZHH6D\n\tGr60nUJu7mx/aP1+fdkqbrklwaG3B3F1Wyng82I0=","Date":"Mon, 24 Jun 2019 19:01:58 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190624160158.GN5737@pendragon.ideasonboard.com>","References":"<20190624142859.19313-1-jacopo@jmondi.org>\n\t<20190624142859.19313-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190624142859.19313-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v6 2/6] libcamera: v4l2_device: List\n\tvalid controls at 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":"Mon, 24 Jun 2019 16:04:26 -0000"}}]