[{"id":17296,"web_url":"https://patchwork.libcamera.org/comment/17296/","msgid":"<YK7bc6Cw4rLevdBb@pendragon.ideasonboard.com>","date":"2021-05-26T23:36:19","subject":"Re: [libcamera-devel] [PATCH] libcamera: V4L2Device: Remove the\n\tcontrols order assumption in updateControls()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Hiro,\n\nThank you for the patch.\n\nOn Wed, May 26, 2021 at 03:43:11PM +0900, Hirokazu Honda wrote:\n> The original updateControls() has the assumption that ctrls and\n> v4l2Ctrls lists are in the same order. It is dependent on the\n> caller implementation though. This changes updateControls()\n> implementation so that it works without the assumption.\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> ---\n>  src/libcamera/v4l2_device.cpp | 25 ++++++++-----------------\n>  1 file changed, 8 insertions(+), 17 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index caafbc2d..aaca7171 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -244,12 +244,6 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n>  \n>  \tControlList ctrls{ controls_ };\n>  \n> -\t/*\n> -\t * Start by filling the ControlList. This can't be combined with filling\n> -\t * v4l2Ctrls, as updateControls() relies on both containers having the\n> -\t * same order, and the control list is based on a map, which is not\n> -\t * sorted by insertion order.\n> -\t */\n>  \tfor (uint32_t id : ids) {\n>  \t\tconst auto iter = controls_.find(id);\n>  \t\tif (iter == controls_.end()) {\n> @@ -623,19 +617,16 @@ void V4L2Device::updateControlInfo()\n>  void V4L2Device::updateControls(ControlList *ctrls,\n>  \t\t\t\tSpan<const v4l2_ext_control> v4l2Ctrls)\n>  {\n> -\tunsigned int i = 0;\n> -\tfor (auto &ctrl : *ctrls) {\n> -\t\tif (i == v4l2Ctrls.size())\n> -\t\t\tbreak;\n> +\tfor (const v4l2_ext_control &v4l2Ctrl : v4l2Ctrls) {\n> +\t\tconst unsigned int id = v4l2Ctrl.id;\n>  \n> -\t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n> -\t\tunsigned int id = ctrl.first;\n> -\t\tControlValue &value = ctrl.second;\n> +\t\tControlValue value = ctrls->get(id);\n>  \n> -\t\tconst auto iter = controls_.find(id);\n> +\t\tconst auto &iter = controls_.find(id);\n\nfind() returns an iterator, not a reference to an iterator. Storing it\nin a reference here will work as the lifetime of rvalues is extended\nwhen a const lvalue reference is bound to them, but it's misleading, and\ndoesn't save any memory or CPU time. I think you should thus keep the\noriginal code.\n\n> +\t\tASSERT(iter != controls_.end());\n\nI'd add a blank line here.\n\nWith these changes,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \t\tswitch (iter->first->type()) {\n>  \t\tcase ControlTypeInteger64:\n> -\t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n> +\t\t\tvalue.set<int64_t>(v4l2Ctrl.value64);\n>  \t\t\tbreak;\n>  \n>  \t\tcase ControlTypeByte:\n> @@ -650,11 +641,11 @@ void V4L2Device::updateControls(ControlList *ctrls,\n>  \t\t\t * \\todo To be changed when support for string controls\n>  \t\t\t * will be added.\n>  \t\t\t */\n> -\t\t\tvalue.set<int32_t>(v4l2Ctrl->value);\n> +\t\t\tvalue.set<int32_t>(v4l2Ctrl.value);\n>  \t\t\tbreak;\n>  \t\t}\n>  \n> -\t\ti++;\n> +\t\tctrls->set(id, value);\n>  \t}\n>  }\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 39A01C3203\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 May 2021 23:36:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7056868923;\n\tThu, 27 May 2021 01:36:28 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B564E6050E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 May 2021 01:36:25 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3CC0C88D;\n\tThu, 27 May 2021 01:36:25 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"khtjRB8e\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1622072185;\n\tbh=4rVxb43qyymJSxnZfS9m55tbpbhe2C/k4IMV0+uA0q0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=khtjRB8ecinpApMy/R1Mz5+ULgxlJznLww+VjdpLJ5TBrni8G9LpVljS5Rju1ZOQu\n\toLLMCY6kM9jnwEYuKSL7QjGb7hEgry+r41xnRMVJKTATgXNhsqdPquhB8os0GA7F+9\n\tg2i+oYYw6cdLi5iA8D/oLSXzfE3R91nEJ6/6Bp+w=","Date":"Thu, 27 May 2021 02:36:19 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YK7bc6Cw4rLevdBb@pendragon.ideasonboard.com>","References":"<20210526064311.3767479-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210526064311.3767479-1-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: V4L2Device: Remove the\n\tcontrols order assumption in updateControls()","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]