{"id":12095,"url":"https://patchwork.libcamera.org/api/1.1/patches/12095/?format=json","web_url":"https://patchwork.libcamera.org/patch/12095/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210423093653.1726488-2-hiroh@chromium.org>","date":"2021-04-23T09:36:51","name":"[libcamera-devel,v5,2/4] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in getControls()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"0a15512a0af2cf152b3d880a167b1eefbe33c706","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12095/mbox/","series":[{"id":1970,"url":"https://patchwork.libcamera.org/api/1.1/series/1970/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1970","date":"2021-04-23T09:36:50","name":"[libcamera-devel,v5,1/4] libcamera: V4L2Device: Remove the controls order assumption in updateControls()","version":5,"mbox":"https://patchwork.libcamera.org/series/1970/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12095/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12095/checks/","tags":{},"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 A6A95BDB15\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 23 Apr 2021 09:37:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 668B668881;\n\tFri, 23 Apr 2021 11:37:58 +0200 (CEST)","from mail-pl1-x631.google.com (mail-pl1-x631.google.com\n\t[IPv6:2607:f8b0:4864:20::631])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 06F6F6887B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Apr 2021 11:37:56 +0200 (CEST)","by mail-pl1-x631.google.com with SMTP id p16so21002207plf.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Apr 2021 02:37:55 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:8537:2d4f:8d35:5777])\n\tby smtp.gmail.com with ESMTPSA id\n\tz5sm4273660pff.191.2021.04.23.02.37.53\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 23 Apr 2021 02:37:54 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"b0yrrMWF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=3JRIL9VD0+XeiN5ymASkeohbruAVE54kRat/uXu6Ma0=;\n\tb=b0yrrMWFsT735Fou+G2CUYKL3A7YCzh+/RFFXfMFrvEIDca4czcmk+IMfDVyHBjTwB\n\tHalWh59NmMAl8cotWe8S5oLtxGur4baoVjIe9T7CA4+HwoZSoTIE3GV3Oar9iO1V0eT6\n\t/mlSEFgdBF1R0o/IQJbzHIW+XjB73euc6Mc74=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=3JRIL9VD0+XeiN5ymASkeohbruAVE54kRat/uXu6Ma0=;\n\tb=q6BUegWLWcTWSTK0LGKW2h1N3/7R8bXTPWUzYaC/UEIqpdAagas7qhRZXJCaQOWRUX\n\tAFRADNlDfkJ0QtTiDf4nB36/eTc+gxRNsz67Y8Nw3qmSBPKYzRqZBLeLPN6ZgDmQDJc+\n\t/MxiFJt71/ElPAwuqepq2OvOrXjLxK39eHVfenZao+lMviGmdwcao5OR1Ar1KkmKNWux\n\tSPba0ZYdWU4cAGgg9czfaln2WDoiYgi+A3yiys2JCF6y2hygjXyqR1tVd66sB6YTKucs\n\t3S4XCvAYd2yRfze5gwSWyix4DNnJDedm9gplqdzER98BGO6MJMsIYXOxitDJxOMgjopI\n\t/06w==","X-Gm-Message-State":"AOAM532cTK6By0edN51IComCnnqKb+ajTwjfnGP03S3BEodcf16sszlc\n\t7pnXbNK004wTMvZtr6eBME8ivuXSFecKvg==","X-Google-Smtp-Source":"ABdhPJz06yh+wzXrqKULClS8l6g0/4VMQn25YQXAEurdP57CYqxVRbYmQ6oxwrDomijeOJrI/PxZVg==","X-Received":"by 2002:a17:902:c183:b029:ea:c15a:c6e9 with SMTP id\n\td3-20020a170902c183b02900eac15ac6e9mr2967590pld.14.1619170674463; \n\tFri, 23 Apr 2021 02:37:54 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 23 Apr 2021 18:36:51 +0900","Message-Id":"<20210423093653.1726488-2-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.498.g6c1eba8ee3d-goog","In-Reply-To":"<20210423093653.1726488-1-hiroh@chromium.org>","References":"<20210423093653.1726488-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v5 2/4] libcamera: V4L2Device: Use\n\tstd::vector for v4l2_ext_control in getControls()","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>","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>"},"content":"The original code uses Variable-Length-Array, which is not\nofficially supported in C++. This replaces the array with\nstd::vector.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/libcamera/v4l2_device.cpp | 41 +++++++++++++++++------------------\n 1 file changed, 20 insertions(+), 21 deletions(-)","diff":"diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex ce2860c4..bbe8f154 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -173,13 +173,18 @@ void V4L2Device::close()\n  */\n ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n {\n-\tunsigned int count = ids.size();\n-\tif (count == 0)\n+\tif (ids.empty())\n \t\treturn {};\n \n \tControlList ctrls{ controls_ };\n+\tstd::vector<v4l2_ext_control> v4l2Ctrls(ids.size());\n+\tmemset(v4l2Ctrls.data(), 0, sizeof(v4l2_ext_control) * ctrls.size());\n+\n+\tfor (size_t i = 0, j = 0; j < ids.size(); ++j) {\n+\t\tconst unsigned int id = ids[j];\n+\t\tif (ctrls.contains(id))\n+\t\t\tcontinue;\n \n-\tfor (uint32_t id : ids) {\n \t\tconst auto iter = controls_.find(id);\n \t\tif (iter == controls_.end()) {\n \t\t\tLOG(V4L2, Error)\n@@ -187,20 +192,12 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t\treturn {};\n \t\t}\n \n-\t\tctrls.set(id, {});\n-\t}\n-\n-\tstruct v4l2_ext_control v4l2Ctrls[count];\n-\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n-\n-\tunsigned int i = 0;\n-\tfor (auto &ctrl : ctrls) {\n-\t\tunsigned int id = ctrl.first;\n+\t\tv4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i++];\n \t\tconst struct v4l2_query_ext_ctrl &info = controlInfo_[id];\n+\t\tControlValue value{};\n \n \t\tif (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {\n \t\t\tControlType type;\n-\n \t\t\tswitch (info.type) {\n \t\t\tcase V4L2_CTRL_TYPE_U8:\n \t\t\t\ttype = ControlTypeByte;\n@@ -213,7 +210,6 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t\t\treturn {};\n \t\t\t}\n \n-\t\t\tControlValue &value = ctrl.second;\n \t\t\tvalue.reserve(type, true, info.elems);\n \t\t\tSpan<uint8_t> data = value.data();\n \n@@ -221,21 +217,23 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t\tv4l2Ctrls[i].size = data.size();\n \t\t}\n \n-\t\tv4l2Ctrls[i].id = id;\n-\t\ti++;\n+\t\tv4l2Ctrl.id = id;\n+\t\tctrls.set(id, std::move(value));\n \t}\n \n+\tv4l2Ctrls.resize(ctrls.size());\n+\n \tstruct v4l2_ext_controls v4l2ExtCtrls = {};\n \tv4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL;\n-\tv4l2ExtCtrls.controls = v4l2Ctrls;\n-\tv4l2ExtCtrls.count = count;\n+\tv4l2ExtCtrls.controls = v4l2Ctrls.data();\n+\tv4l2ExtCtrls.count = v4l2Ctrls.size();\n \n \tint ret = ioctl(VIDIOC_G_EXT_CTRLS, &v4l2ExtCtrls);\n \tif (ret) {\n \t\tunsigned int errorIdx = v4l2ExtCtrls.error_idx;\n \n \t\t/* Generic validation error. */\n-\t\tif (errorIdx == 0 || errorIdx >= count) {\n+\t\tif (errorIdx == 0 || errorIdx >= v4l2Ctrls.size()) {\n \t\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n \t\t\t\t\t << strerror(-ret);\n \t\t\treturn {};\n@@ -244,10 +242,11 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t/* A specific control failed. */\n \t\tLOG(V4L2, Error) << \"Unable to read control \" << errorIdx\n \t\t\t\t << \": \" << strerror(-ret);\n-\t\tcount = errorIdx - 1;\n+\n+\t\tv4l2Ctrls.resize(errorIdx);\n \t}\n \n-\tupdateControls(&ctrls, v4l2Ctrls, count);\n+\tupdateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size());\n \n \treturn ctrls;\n }\n","prefixes":["libcamera-devel","v5","2/4"]}