From patchwork Fri Apr 23 09:36:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12094 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A10D0BDB15 for ; Fri, 23 Apr 2021 09:37:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EB8B6887C; Fri, 23 Apr 2021 11:37:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="G7lxCbF+"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E3AB6886E for ; Fri, 23 Apr 2021 11:37:55 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id c3so14925171pfo.3 for ; Fri, 23 Apr 2021 02:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RSqDOLvLGFfx5si4xOZu5KKSSZfzCxjP22JVLy+D9C4=; b=G7lxCbF+777mSGRjyD7ykfbXQWVEkW6B/Zfh/+vcZI6dAKnIH/vflUBHJwzIG/jCzW 8UNbnWhUw8zqWqy8obI3vKfXGu4ilMGDktfmqCKtruQh+WOnSet+WL1Q5pt93zGtRQ6W DGQyt5wWnfVg1CklRNUxyWATZZjRWQE2sn0GQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RSqDOLvLGFfx5si4xOZu5KKSSZfzCxjP22JVLy+D9C4=; b=GtHbwRGV0y8Y+gvkSY5ZC7rL1E/cFRJxNVmMNibbPJ0MsVbAVJt+B1mo+2PxoaXl+A nxIXEmZYm3UtCuoKdrn2pOZKF65XhzCOzspMURGW6wcYlGkMIgF830My9/W/Cf10wS3O ykUMCpFhlvYrc9TEM9RP707oSNyRV+nb3Vz6dvWj2CQZH/kCTZgCiz+cTsFFUxk7/bfW B6SNbo5NirTZo8jtr0SyYvFMCotP8SJrFuN8ot63ScUBe+53fzlOac6MZQccofVVA2cB ZXDFF5LF64JKCLXLRMrmfRIRsGm91wdi3dgHDTPMmHOA9VbkM97IgP2E+YYpE8HvVlQh te6g== X-Gm-Message-State: AOAM531qcu+sdMBm85YcPftCHBOLTdTzuBtbYIaZgsLUAc2N/zsWc4Dq BWJAHKHVIyNcf7tyDNId4KXVfM11sF18bQ== X-Google-Smtp-Source: ABdhPJyyv6fZs+BKxOcSFWP+6T3hOWXLSEZkwDHuhqGZUGPQQRKeTpNHtuEJwx1rYPINwaUG7um6jA== X-Received: by 2002:a63:e206:: with SMTP id q6mr2871284pgh.225.1619170673037; Fri, 23 Apr 2021 02:37:53 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id z5sm4273660pff.191.2021.04.23.02.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 02:37:52 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 18:36:50 +0900 Message-Id: <20210423093653.1726488-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 1/4] libcamera: V4L2Device: Remove the controls order assumption in updateControls() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The original updateControls() has the assumption that ctrls and v4l2Ctrls lists are in the same order. It is dependent on the caller implementation though. This changes updateControls() implementation so that it works without the assumption. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..ce2860c4 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -179,12 +179,6 @@ ControlList V4L2Device::getControls(const std::vector &ids) ControlList ctrls{ controls_ }; - /* - * Start by filling the ControlList. This can't be combined with filling - * v4l2Ctrls, as updateControls() relies on both containers having the - * same order, and the control list is based on a map, which is not - * sorted by insertion order. - */ for (uint32_t id : ids) { const auto iter = controls_.find(id); if (iter == controls_.end()) { @@ -525,19 +519,14 @@ void V4L2Device::updateControls(ControlList *ctrls, const struct v4l2_ext_control *v4l2Ctrls, unsigned int count) { - unsigned int i = 0; - for (auto &ctrl : *ctrls) { - if (i == count) - break; + for (unsigned int i = 0; i < count; i++) { + const struct v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i]; + const unsigned int id = v4l2Ctrl.id; - const struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i]; - unsigned int id = ctrl.first; - ControlValue &value = ctrl.second; - - const auto iter = controls_.find(id); - switch (iter->first->type()) { + ControlValue value = ctrls->get(id); + switch (value.type()) { case ControlTypeInteger64: - value.set(v4l2Ctrl->value64); + value.set(v4l2Ctrl.value64); break; case ControlTypeByte: @@ -552,11 +541,11 @@ void V4L2Device::updateControls(ControlList *ctrls, * \todo To be changed when support for string controls * will be added. */ - value.set(v4l2Ctrl->value); + value.set(v4l2Ctrl.value); break; } - i++; + ctrls->set(id, value); } } From patchwork Fri Apr 23 09:36:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12095 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A6A95BDB15 for ; Fri, 23 Apr 2021 09:37:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 668B668881; Fri, 23 Apr 2021 11:37:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="b0yrrMWF"; dkim-atps=neutral Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06F6F6887B for ; Fri, 23 Apr 2021 11:37:56 +0200 (CEST) Received: by mail-pl1-x631.google.com with SMTP id p16so21002207plf.12 for ; Fri, 23 Apr 2021 02:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3JRIL9VD0+XeiN5ymASkeohbruAVE54kRat/uXu6Ma0=; b=b0yrrMWFsT735Fou+G2CUYKL3A7YCzh+/RFFXfMFrvEIDca4czcmk+IMfDVyHBjTwB HalWh59NmMAl8cotWe8S5oLtxGur4baoVjIe9T7CA4+HwoZSoTIE3GV3Oar9iO1V0eT6 /mlSEFgdBF1R0o/IQJbzHIW+XjB73euc6Mc74= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3JRIL9VD0+XeiN5ymASkeohbruAVE54kRat/uXu6Ma0=; b=q6BUegWLWcTWSTK0LGKW2h1N3/7R8bXTPWUzYaC/UEIqpdAagas7qhRZXJCaQOWRUX AFRADNlDfkJ0QtTiDf4nB36/eTc+gxRNsz67Y8Nw3qmSBPKYzRqZBLeLPN6ZgDmQDJc+ /MxiFJt71/ElPAwuqepq2OvOrXjLxK39eHVfenZao+lMviGmdwcao5OR1Ar1KkmKNWux SPba0ZYdWU4cAGgg9czfaln2WDoiYgi+A3yiys2JCF6y2hygjXyqR1tVd66sB6YTKucs 3S4XCvAYd2yRfze5gwSWyix4DNnJDedm9gplqdzER98BGO6MJMsIYXOxitDJxOMgjopI /06w== X-Gm-Message-State: AOAM532cTK6By0edN51IComCnnqKb+ajTwjfnGP03S3BEodcf16sszlc 7pnXbNK004wTMvZtr6eBME8ivuXSFecKvg== X-Google-Smtp-Source: ABdhPJz06yh+wzXrqKULClS8l6g0/4VMQn25YQXAEurdP57CYqxVRbYmQ6oxwrDomijeOJrI/PxZVg== X-Received: by 2002:a17:902:c183:b029:ea:c15a:c6e9 with SMTP id d3-20020a170902c183b02900eac15ac6e9mr2967590pld.14.1619170674463; Fri, 23 Apr 2021 02:37:54 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id z5sm4273660pff.191.2021.04.23.02.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 02:37:54 -0700 (PDT) From: Hirokazu Honda 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 std::vector for v4l2_ext_control in getControls() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The original code uses Variable-Length-Array, which is not officially supported in C++. This replaces the array with std::vector. Signed-off-by: Hirokazu Honda --- src/libcamera/v4l2_device.cpp | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index ce2860c4..bbe8f154 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -173,13 +173,18 @@ void V4L2Device::close() */ ControlList V4L2Device::getControls(const std::vector &ids) { - unsigned int count = ids.size(); - if (count == 0) + if (ids.empty()) return {}; ControlList ctrls{ controls_ }; + std::vector v4l2Ctrls(ids.size()); + memset(v4l2Ctrls.data(), 0, sizeof(v4l2_ext_control) * ctrls.size()); + + for (size_t i = 0, j = 0; j < ids.size(); ++j) { + const unsigned int id = ids[j]; + if (ctrls.contains(id)) + continue; - for (uint32_t id : ids) { const auto iter = controls_.find(id); if (iter == controls_.end()) { LOG(V4L2, Error) @@ -187,20 +192,12 @@ ControlList V4L2Device::getControls(const std::vector &ids) return {}; } - ctrls.set(id, {}); - } - - struct v4l2_ext_control v4l2Ctrls[count]; - memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); - - unsigned int i = 0; - for (auto &ctrl : ctrls) { - unsigned int id = ctrl.first; + v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i++]; const struct v4l2_query_ext_ctrl &info = controlInfo_[id]; + ControlValue value{}; if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) { ControlType type; - switch (info.type) { case V4L2_CTRL_TYPE_U8: type = ControlTypeByte; @@ -213,7 +210,6 @@ ControlList V4L2Device::getControls(const std::vector &ids) return {}; } - ControlValue &value = ctrl.second; value.reserve(type, true, info.elems); Span data = value.data(); @@ -221,21 +217,23 @@ ControlList V4L2Device::getControls(const std::vector &ids) v4l2Ctrls[i].size = data.size(); } - v4l2Ctrls[i].id = id; - i++; + v4l2Ctrl.id = id; + ctrls.set(id, std::move(value)); } + v4l2Ctrls.resize(ctrls.size()); + struct v4l2_ext_controls v4l2ExtCtrls = {}; v4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL; - v4l2ExtCtrls.controls = v4l2Ctrls; - v4l2ExtCtrls.count = count; + v4l2ExtCtrls.controls = v4l2Ctrls.data(); + v4l2ExtCtrls.count = v4l2Ctrls.size(); int ret = ioctl(VIDIOC_G_EXT_CTRLS, &v4l2ExtCtrls); if (ret) { unsigned int errorIdx = v4l2ExtCtrls.error_idx; /* Generic validation error. */ - if (errorIdx == 0 || errorIdx >= count) { + if (errorIdx == 0 || errorIdx >= v4l2Ctrls.size()) { LOG(V4L2, Error) << "Unable to read controls: " << strerror(-ret); return {}; @@ -244,10 +242,11 @@ ControlList V4L2Device::getControls(const std::vector &ids) /* A specific control failed. */ LOG(V4L2, Error) << "Unable to read control " << errorIdx << ": " << strerror(-ret); - count = errorIdx - 1; + + v4l2Ctrls.resize(errorIdx); } - updateControls(&ctrls, v4l2Ctrls, count); + updateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); return ctrls; } From patchwork Fri Apr 23 09:36:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12096 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8BA23BDB15 for ; Fri, 23 Apr 2021 09:38:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CAA868877; Fri, 23 Apr 2021 11:38:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lXlRvfwq"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D6FB96886E for ; Fri, 23 Apr 2021 11:37:57 +0200 (CEST) Received: by mail-pf1-x42f.google.com with SMTP id i190so33705946pfc.12 for ; Fri, 23 Apr 2021 02:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vqhxNImrRFwrCGgwRCpGCR59ScBeqsxKt3tq2DT/EAI=; b=lXlRvfwq7hvmWlO21LWiYWUv585UnVMEl0S4vw52YJKmfXhpDO71BTecWyuNVe2icZ lVgUd8VzLk/4V2uNX4CQ3BtLg9sT+Gm+FZupDtEHneKfWvUxCbg5xR11Qah9d92p3qwg /nmJlKESasoXZjMjdidKmYd2hEa6k1vEyUw34= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vqhxNImrRFwrCGgwRCpGCR59ScBeqsxKt3tq2DT/EAI=; b=LoVdvKmCKKGm267PeMYhAMwYix9mjOpSFn7NVdSosigjzpdWxbBodsTxiy/m2WOtvi UkoPGCdYx6S+E/BlfMXhGxhTGEjUqSWG36xxHoEVB1iD8yNDo5LXx6iNo7Y+yys95hij 7ZQ5qhgoZ/G/PKpvDj6dQRhp0gkiZsg814yMxz+8Rd1GhR+QU3BPDcgfXzi3ZvsD5gyW 4dk9w3WgORKfpBrxL9QoIatduoYct0UbDw/LHSOMiN/kSeqULd5nMUi8IOxlVOfLKq0W +9ckIlYzfnHW4yT2qLxlo4w/eTJhMTUj5aQAfNBEnQl315/qzdZxPqJ+6VWAZ9Da5YHb jesg== X-Gm-Message-State: AOAM532LzaWvwHogjRx/guvaIHnR5eTbeUzShyPVM/oLi2aNr1CST+Q0 QYcfT6fv5QpckDMBKKdd0xAHSHcD9X/PDg== X-Google-Smtp-Source: ABdhPJx6vqiiDQ0zowsnRCrujvgvjJOyrLsA8diVJg+OkgAIe/ydrMSnZPWzrOwcTi4YLugJEz65Bw== X-Received: by 2002:a63:3c5e:: with SMTP id i30mr2875208pgn.331.1619170676231; Fri, 23 Apr 2021 02:37:56 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id z5sm4273660pff.191.2021.04.23.02.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 02:37:55 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 18:36:52 +0900 Message-Id: <20210423093653.1726488-3-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 3/4] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in setControls() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The original code uses Variable-Length-Array, which is not officially supported in C++. This replaces the array with std::vector. Signed-off-by: Hirokazu Honda Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 39 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index bbe8f154..4522268d 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -275,30 +275,28 @@ ControlList V4L2Device::getControls(const std::vector &ids) */ int V4L2Device::setControls(ControlList *ctrls) { - unsigned int count = ctrls->size(); - if (count == 0) + if (ctrls->empty()) return 0; - struct v4l2_ext_control v4l2Ctrls[count]; - memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); + std::vector v4l2Ctrls(ctrls->size()); + memset(v4l2Ctrls.data(), 0, sizeof(v4l2_ext_control) * ctrls->size()); - unsigned int i = 0; - for (auto &ctrl : *ctrls) { - unsigned int id = ctrl.first; + for (auto [ctrl, i] = std::pair(ctrls->begin(), 0u); i < ctrls->size(); ctrl++, i++) { + const unsigned int id = ctrl->first; const auto iter = controls_.find(id); if (iter == controls_.end()) { LOG(V4L2, Error) << "Control " << utils::hex(id) << " not found"; return -EINVAL; } - - v4l2Ctrls[i].id = id; + v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i]; + v4l2Ctrl.id = id; /* Set the v4l2_ext_control value for the write operation. */ - ControlValue &value = ctrl.second; + ControlValue &value = ctrl->second; switch (iter->first->type()) { case ControlTypeInteger64: - v4l2Ctrls[i].value64 = value.get(); + v4l2Ctrl.value64 = value.get(); break; case ControlTypeByte: { @@ -310,32 +308,30 @@ int V4L2Device::setControls(ControlList *ctrls) } Span data = value.data(); - v4l2Ctrls[i].p_u8 = data.data(); - v4l2Ctrls[i].size = data.size(); + v4l2Ctrl.p_u8 = data.data(); + v4l2Ctrl.size = data.size(); break; } default: /* \todo To be changed to support strings. */ - v4l2Ctrls[i].value = value.get(); + v4l2Ctrl.value = value.get(); break; } - - i++; } struct v4l2_ext_controls v4l2ExtCtrls = {}; v4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL; - v4l2ExtCtrls.controls = v4l2Ctrls; - v4l2ExtCtrls.count = count; + v4l2ExtCtrls.controls = v4l2Ctrls.data(); + v4l2ExtCtrls.count = v4l2Ctrls.size(); int ret = ioctl(VIDIOC_S_EXT_CTRLS, &v4l2ExtCtrls); if (ret) { unsigned int errorIdx = v4l2ExtCtrls.error_idx; /* Generic validation error. */ - if (errorIdx == 0 || errorIdx >= count) { + if (errorIdx == 0 || errorIdx >= v4l2Ctrls.size()) { LOG(V4L2, Error) << "Unable to set controls: " << strerror(-ret); return -EINVAL; @@ -344,11 +340,12 @@ int V4L2Device::setControls(ControlList *ctrls) /* A specific control failed. */ LOG(V4L2, Error) << "Unable to set control " << errorIdx << ": " << strerror(-ret); - count = errorIdx - 1; + + v4l2Ctrls.resize(errorIdx); ret = errorIdx; } - updateControls(ctrls, v4l2Ctrls, count); + updateControls(ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); return ret; } From patchwork Fri Apr 23 09:36:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12097 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3A408BDB15 for ; Fri, 23 Apr 2021 09:38:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1B246887B; Fri, 23 Apr 2021 11:38:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IFuCvSzl"; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B5A6068877 for ; Fri, 23 Apr 2021 11:37:59 +0200 (CEST) Received: by mail-pg1-x533.google.com with SMTP id b17so34824854pgh.7 for ; Fri, 23 Apr 2021 02:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o3KaVkmOW7yQ2PRBDDrr/MSJU0RRor10z7001foGA3U=; b=IFuCvSzlSuzLcs6YD/wJBmO+WDKcMpyGxubv7rWat5YrTb/eqdpVIzylU0fSTxJoYU mfIawNaX7NlvnCZDSkArTusE6qcogixNpFNYUkgc0yMUX6AfLjs80o63hjYokh4js8QI UBA85Jd7tLHtK4igxjwVjTdfUFsNVv63RXtCI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o3KaVkmOW7yQ2PRBDDrr/MSJU0RRor10z7001foGA3U=; b=T3xI+iwfWgG7noheOlJSScqis2G4C+759y3x4DBhHgCVQ7SnYmpK8/tgnZn+zeEx+a nrp9kEgpDUb8Svlm8srlqCCSha/9S1jj/AUXVW6OpGu6EZIChuotpFiuIXI4jLi4lJU7 Kozl3UugD2ADKHclfA+s6/GJuKYEFErnia/VYkcWlzhACsXQXDlnMm13Qp7rMp/abND2 g6Y9q+UArZ2Kzy1j9w/jAA0D7Ku/EQIyJItZ6WwgliSquLTPeriAa6Alc7InW8txA6B1 tNMxXcY2qzIxljRkwWphEzgy+aag77lezF8u1V2z2iT9nfFDJpD6RYsnstADNgBeeeHS F8bw== X-Gm-Message-State: AOAM530Dqf5f7h1D1GWxJ3Mi5mZOWXN8GODS5A/jdLOMGtYALbbr7HEY VtTLp7Vz6/5+0ikCtDsIQqToyNqotnGqeg== X-Google-Smtp-Source: ABdhPJwn4QFpBQQGCsblpYKZ7NPwve/iehWsWcTAv6E5kaEqBRzl0ZMTKaaa+IOWcGjcIHVZ0xGlTA== X-Received: by 2002:a62:8485:0:b029:1fc:d912:67d6 with SMTP id k127-20020a6284850000b02901fcd91267d6mr2961376pfd.80.1619170678186; Fri, 23 Apr 2021 02:37:58 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id z5sm4273660pff.191.2021.04.23.02.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 02:37:57 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 18:36:53 +0900 Message-Id: <20210423093653.1726488-4-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 4/4] libcamera: V4L2Device: Use Span in updateControls() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" V4L2Device::updateControls() takes two arguments, raw array and its size, for the v4l2_ext_control values. This replaces it with libcamera::Span. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/internal/v4l2_device.h | 4 ++-- src/libcamera/v4l2_device.cpp | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index d006bf68..087f07e7 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -14,6 +14,7 @@ #include #include +#include #include "libcamera/internal/log.h" #include "libcamera/internal/v4l2_controls.h" @@ -55,8 +56,7 @@ protected: private: void listControls(); void updateControls(ControlList *ctrls, - const struct v4l2_ext_control *v4l2Ctrls, - unsigned int count); + Span v4l2Ctrls); void eventAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 4522268d..954060f4 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -246,7 +246,7 @@ ControlList V4L2Device::getControls(const std::vector &ids) v4l2Ctrls.resize(errorIdx); } - updateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); + updateControls(&ctrls, v4l2Ctrls); return ctrls; } @@ -345,7 +345,7 @@ int V4L2Device::setControls(ControlList *ctrls) ret = errorIdx; } - updateControls(ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); + updateControls(ctrls, v4l2Ctrls); return ret; } @@ -509,14 +509,11 @@ void V4L2Device::listControls() * values in \a v4l2Ctrls * \param[inout] ctrls List of V4L2 controls to update * \param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver - * \param[in] count The number of controls to update */ void V4L2Device::updateControls(ControlList *ctrls, - const struct v4l2_ext_control *v4l2Ctrls, - unsigned int count) + Span v4l2Ctrls) { - for (unsigned int i = 0; i < count; i++) { - const struct v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i]; + for (const v4l2_ext_control &v4l2Ctrl : v4l2Ctrls) { const unsigned int id = v4l2Ctrl.id; ControlValue value = ctrls->get(id);