[{"id":16535,"web_url":"https://patchwork.libcamera.org/comment/16535/","msgid":"<YIXr9EwpQkA9gKdX@pendragon.ideasonboard.com>","date":"2021-04-25T22:23:48","subject":"Re: [libcamera-devel] [PATCH v5 1/4] libcamera: V4L2Device: Remove\n\tthe controls 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 Fri, Apr 23, 2021 at 06:36:50PM +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 | 27 ++++++++-------------------\n>  1 file changed, 8 insertions(+), 19 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index decd19ef..ce2860c4 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -179,12 +179,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> @@ -525,19 +519,14 @@ void V4L2Device::updateControls(ControlList *ctrls,\n>  \t\t\t\tconst struct v4l2_ext_control *v4l2Ctrls,\n>  \t\t\t\tunsigned int count)\n>  {\n> -\tunsigned int i = 0;\n> -\tfor (auto &ctrl : *ctrls) {\n> -\t\tif (i == count)\n> -\t\t\tbreak;\n> +\tfor (unsigned int i = 0; i < count; i++) {\n> +\t\tconst struct v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i];\n> +\t\tconst unsigned int id = v4l2Ctrl.id;\n\nThe main reason why we had a local id variable is because using\nctrl.first is not very readable. With this patch, we could use\nv4l2Ctrl.id to replace id below. No need to change this though, a local\nvariable is fine.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\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> -\n> -\t\tconst auto iter = controls_.find(id);\n> -\t\tswitch (iter->first->type()) {\n> +\t\tControlValue value = ctrls->get(id);\n> +\t\tswitch (value.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> @@ -552,11 +541,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 E01C2BDB97\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 25 Apr 2021 22:23:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 556F86887C;\n\tMon, 26 Apr 2021 00:23:55 +0200 (CEST)","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 9279D602D1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Apr 2021 00:23:53 +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 ED92F4FB;\n\tMon, 26 Apr 2021 00:23:52 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"SY3tCznd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1619389433;\n\tbh=oysZSoWOPz/BjiUUHWWHDeKJKb1CRbAr1QYBSvClWBI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=SY3tCznda7XLWVfFw6k11mfgrd83xAgSkvAfX5XJwiTmQWiQ3JIipADq3NhpcREPr\n\tFVHzdejndpZynVC/lLSrfN7oJUT45SOJWLQoWJ7K1mzde/V5wttpZ2HEptJxjDgVUl\n\tGl11S1YBZTV8FJKTRjBVV/2FfXoBo8EDFssZ0E5E=","Date":"Mon, 26 Apr 2021 01:23:48 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YIXr9EwpQkA9gKdX@pendragon.ideasonboard.com>","References":"<20210423093653.1726488-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210423093653.1726488-1-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH v5 1/4] libcamera: V4L2Device: Remove\n\tthe controls 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","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]