From patchwork Thu Apr 22 02:18:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12055 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 9F247BDB15 for ; Thu, 22 Apr 2021 02:18:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 61E0268854; Thu, 22 Apr 2021 04:18:19 +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="Olj2K9RY"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 98DF468849 for ; Thu, 22 Apr 2021 04:18:17 +0200 (CEST) Received: by mail-pf1-x433.google.com with SMTP id y62so6812589pfg.4 for ; Wed, 21 Apr 2021 19:18:17 -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=Lu978gzqbTWIUvxflQvmctS/NAPkbdXXF8n35Kel5w8=; b=Olj2K9RYpewwcVglFIaiDq0Fys6aHxDjxq/RUBDbpLqPZLlxU6zK2koF9BBIKxEBvf 32k4ZxvB3v70UZPqCfjuEBnY4Z+sCA8XhaVIs6cKFnEkjIHlF+zwQAJj/JPAdDTatGvu OrSRkT4xGipBjGZKAUJC9rhCrNe+AisX1twJY= 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=Lu978gzqbTWIUvxflQvmctS/NAPkbdXXF8n35Kel5w8=; b=l3qNwJ8GMAn26UzfET6qwQIGc//0NJIsQIggOZS6nbfZpw/iAj8Z6EAO0uMhDxNYtO ESpU8TZtZCjMCe2MuoZ2FsGANb3IzJXvEBY6zI3NAMtftyHXJp1SPHPSuJeM0ATCWet9 R/sCLfea3pYbh7d7+xqkdGtcndIO1XD5hNyjnRTiV58P7aqFIZmiqMklHZhIAs3s0hL7 il+JRPj3i4zJPMT0emWH3Z/y4FSoQhfc5m6/vp6t42M1CwcI6zmQiUxy9zP8iFdoLJkJ QIruQzvTHtEIVf5QQQvUQxJlDZZQzDRCrAMUeRFbYZ/wfyxUfp3XerZzglididQF7Y4b Tgmw== X-Gm-Message-State: AOAM531Y94PobMVVUfn0MrIMLsCts/ezt6KH8QyBTHLfie7rcMwrxVAd A8n+WkAi2jxAIDvmV/LtsaWhD3kpl6nuGg== X-Google-Smtp-Source: ABdhPJzaGWGTKKsIueqm8sFYDerY/Kx8hygfQm4bOdcFfQ/Fdw3MBSuBwjuFtPGRwBGfoEv0cbzujw== X-Received: by 2002:a65:6184:: with SMTP id c4mr1160742pgv.200.1619057895755; Wed, 21 Apr 2021 19:18:15 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:f88:d5a0:ebc4:5b76]) by smtp.gmail.com with ESMTPSA id lt11sm3352480pjb.23.2021.04.21.19.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 19:18:15 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 22 Apr 2021 11:18:06 +0900 Message-Id: <20210422021809.520675-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210422021809.520675-1-hiroh@chromium.org> References: <20210422021809.520675-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 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 --- src/libcamera/v4l2_device.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..3c32d682 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,19 @@ 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; - - const struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i]; - unsigned int id = ctrl.first; - ControlValue &value = ctrl.second; + for (unsigned int i = 0; i < count; i++) { + const struct v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i]; + const unsigned int id = v4l2Ctrl.id; + if (!ctrls->contains(id)) { + LOG(V4L2, Error) << "ControlList doesn't contain id: " + << id; + return; + } - 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 +546,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 Thu Apr 22 02:18:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12056 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 406EFBDB15 for ; Thu, 22 Apr 2021 02:18:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4B0068853; Thu, 22 Apr 2021 04:18:21 +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="HITIMsHa"; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC7C468852 for ; Thu, 22 Apr 2021 04:18:18 +0200 (CEST) Received: by mail-pf1-x42e.google.com with SMTP id p67so25689583pfp.10 for ; Wed, 21 Apr 2021 19:18:18 -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=ntj34Oi7QZw5K7pg5QcWtTfZ8IzjTMaWd9YV8k6vys8=; b=HITIMsHa4c73RrwWdRLiP4h+ufi7IaByM1/S/+grXuV/0oEFJ2TyuJ006jAqVOf9rP J00P54OJSKkpQnpb5vQk2IY8fEhTbMNPIvx5u0QY7Ax0O/JeF5WsSPygtHrA7hWLGm+z jWXrErNj30Q/w5EYZmAGJ6Bv+FFb2+L0ujQ1s= 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=ntj34Oi7QZw5K7pg5QcWtTfZ8IzjTMaWd9YV8k6vys8=; b=q5PyekTNkSTqv3GoN1ZaGnwNP3xJp9QGgZtYd3DIdLEVZ7V8o4RTkhCz4ve6c3VYTq 52RLRV4kxRTe7dqhs1tHnVgIcSbn+ifDfzOXTIeUa8eRZTYC28X17a377ygluFGbP2TG npbhsDa0NSr7Jb3TlaDynuGvQCAUgSZuW0DVPyKjFAyeT98Sc4ASEyRJr81+8aiUFJVm Kp1AXu3qLGl1SNCgaw/3MjhpfMvkiJ1zjKLILuLuBjG8rrWJVQ0WQ7cTaIMXniPDIp6Y BEkdTllVkjfUskGFnq8pnWAiRKN4AzH+QFXQpWspJBpfHeb0KuZDtM6FfYL7IDV83ZXK q7Ng== X-Gm-Message-State: AOAM532hmM6YG7813dPNZB5ha3GaajSMg/AjOThzG+o2g1Xp25aiJELW 9cs64Vz0Ea9MISAScRRoujMOCVFqTwlgvA== X-Google-Smtp-Source: ABdhPJwrF+4PkDPvQavvJOwbK+THUTAr2xNg5vkxbm0dUZTVCktKldedXr8IK/8JskksXA0mE48OuA== X-Received: by 2002:a65:4986:: with SMTP id r6mr1171470pgs.392.1619057897139; Wed, 21 Apr 2021 19:18:17 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:f88:d5a0:ebc4:5b76]) by smtp.gmail.com with ESMTPSA id lt11sm3352480pjb.23.2021.04.21.19.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 19:18:16 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 22 Apr 2021 11:18:07 +0900 Message-Id: <20210422021809.520675-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210422021809.520675-1-hiroh@chromium.org> References: <20210422021809.520675-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 3c32d682..617e6ec9 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -173,8 +173,7 @@ 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_ }; @@ -190,22 +189,20 @@ ControlList V4L2Device::getControls(const std::vector &ids) ctrls.set(id, {}); } - 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 struct v4l2_query_ext_ctrl &info = controlInfo_[id]; + v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i]; if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) { ControlType type; - switch (info.type) { case V4L2_CTRL_TYPE_U8: type = ControlTypeByte; break; - default: LOG(V4L2, Error) << "Unsupported payload control type " @@ -213,7 +210,7 @@ ControlList V4L2Device::getControls(const std::vector &ids) return {}; } - ControlValue &value = ctrl.second; + ControlValue &value = ctrl->second; value.reserve(type, true, info.elems); Span data = value.data(); @@ -221,21 +218,20 @@ ControlList V4L2Device::getControls(const std::vector &ids) v4l2Ctrls[i].size = data.size(); } - v4l2Ctrls[i].id = id; - i++; + v4l2Ctrl.id = id; } 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 +240,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 Thu Apr 22 02:18:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12057 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 DCFF8BDB15 for ; Thu, 22 Apr 2021 02:18:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6FEA26885B; Thu, 22 Apr 2021 04:18:22 +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="NNZcFXY2"; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ACF4C68849 for ; Thu, 22 Apr 2021 04:18:20 +0200 (CEST) Received: by mail-pl1-x632.google.com with SMTP id v13so9137956ple.9 for ; Wed, 21 Apr 2021 19:18:20 -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=U3RImDmwzVIe880ArB4ZstBuCN+woBU2v98B5nJinbs=; b=NNZcFXY2fCesgiM0SnwpInVh5mwFS2gjHWxqrdkrj2H6qc+5j4GxlJujlEYNVgobvh qLjx+rzSTlmKJJ/Hl9D8MwvvU6BFsFiPXrdiAjGALLqkti1AKSXsKGlTft70KsVrq8bu KpYK4RDjaCbvwdQ5+swrGVnWiCS5O8W1G4s8o= 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=U3RImDmwzVIe880ArB4ZstBuCN+woBU2v98B5nJinbs=; b=R7ZPS5rLXsrliczxUQzpjOl1xVQWsDMCLj/gjZYo4TXSgKMWq+gnz9B/G3/dYn/Jyp p2CvC82J91gqXl/lFRvLdc0xNLR3eyQlIwehCgPaPpK81NzgrUr3HKqe7aGA9tBOtR5M RJ2iU3lUVryNHhWoBqwXP1aAD5eT42jfJ/VtpGcAef2yS/QfkSou3JOCnJyMeOIJPVid rUde3TcAak9/0jbKQu6UdPPoiLuE9R3mUqye1qi1bSlGzyL6GOk6C2ClKQjsOAQ+SlFF TTVhZ65Qn1G0wEQJsbrkh2y2KnujEJtBpYZPzXje2gs/rjTA87NQLpfnvg+sfOpxlhEW UvWg== X-Gm-Message-State: AOAM532gTeWAa38HUh4lvDne58QWBjgQphEUUt73e3BKSTbDWlammMf5 +je0Ge1LhhWKMGy1mms7vM0cglfoacDGuA== X-Google-Smtp-Source: ABdhPJzyYTJwNVR393mld/KHyAqPHPOT9ILArBBwSA1H7aZB1wuyH6ycwb9GX6NxONRJkvW1vRabKw== X-Received: by 2002:a17:90a:9511:: with SMTP id t17mr14928444pjo.235.1619057899008; Wed, 21 Apr 2021 19:18:19 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:f88:d5a0:ebc4:5b76]) by smtp.gmail.com with ESMTPSA id lt11sm3352480pjb.23.2021.04.21.19.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 19:18:18 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 22 Apr 2021 11:18:08 +0900 Message-Id: <20210422021809.520675-4-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210422021809.520675-1-hiroh@chromium.org> References: <20210422021809.520675-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 617e6ec9..9f71bf0e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -273,30 +273,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: { @@ -308,32 +306,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; @@ -342,11 +338,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 Thu Apr 22 02:18:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12058 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 15480BDB15 for ; Thu, 22 Apr 2021 02:18:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CAB7F68853; Thu, 22 Apr 2021 04:18:24 +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="GZ8r/yxS"; dkim-atps=neutral Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 393606885A for ; Thu, 22 Apr 2021 04:18:22 +0200 (CEST) Received: by mail-pj1-x1035.google.com with SMTP id lt13so11630440pjb.1 for ; Wed, 21 Apr 2021 19:18:22 -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=AvjxFuGHWuGy6en7PavGeDRuj1BiQI7LI6KxMvnz+GE=; b=GZ8r/yxStbs3y39HPFR+osHgaOoomiMGjphMPcwX3lchapG8cgI5OsXcILB8SrKTAc Rg+DrmdtHFCILTUyzHMg+0BqnIqwQKEIx/EaZsi3UcvM98kAJLPI2jZgtArJge/m3AOv kb5EvVCCg4KCp+ozWAgEj4u/JrGJnaatW1L1E= 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=AvjxFuGHWuGy6en7PavGeDRuj1BiQI7LI6KxMvnz+GE=; b=bLnZqHzHFBvS1Se99a4SJOKlHI+5dduCJSGJP7Liuon+eUrHvZUDVUwnAQDtQPpeOd a2iNcDv3nry3uvCs7woPT/jdl5Xsx4wPlNEQ4N/Ou6DG4QfffT9VM66cMS25REyTHsXX ANaWgBpuLCPGc6vG5c1f4Q+7ejlbPP3EMLUDUhocMW5VVIXjrJhdPjam+gl4cf0lhmsw vHkIHP1adN4FOY02PmFsYHhD8k/glP1A2L/+Cc1LiHJCKCYEbydgjVFiKda5CrvjGPGH oKXipZ2b54q0ald5RTNRv7N5pyCOeT1KUXoqlmMQxx4Lk+4P18fbt3GxpW61yLAtibut /4DQ== X-Gm-Message-State: AOAM530D8IrZ3YDsLX7Ocs/jiVsQ9lf+cKKjG1C8r2elefKFbGjpen7k kizX9Xtu4OnZjrAQ4acWz4WwJG5rM0HxJA== X-Google-Smtp-Source: ABdhPJyzbKnfwAU8Yp5ha2MWKsC1dNMYtzTryTsRZVfqaheq45+ZM+77WIeWZRGasNBhJ96kXNz0Sg== X-Received: by 2002:a17:90b:4a05:: with SMTP id kk5mr1324649pjb.202.1619057900672; Wed, 21 Apr 2021 19:18:20 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:f88:d5a0:ebc4:5b76]) by smtp.gmail.com with ESMTPSA id lt11sm3352480pjb.23.2021.04.21.19.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 19:18:20 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 22 Apr 2021 11:18:09 +0900 Message-Id: <20210422021809.520675-5-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210422021809.520675-1-hiroh@chromium.org> References: <20210422021809.520675-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 9f71bf0e..58516609 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -244,7 +244,7 @@ ControlList V4L2Device::getControls(const std::vector &ids) v4l2Ctrls.resize(errorIdx); } - updateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); + updateControls(&ctrls, v4l2Ctrls); return ctrls; } @@ -343,7 +343,7 @@ int V4L2Device::setControls(ControlList *ctrls) ret = errorIdx; } - updateControls(ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); + updateControls(ctrls, v4l2Ctrls); return ret; } @@ -507,14 +507,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; if (!ctrls->contains(id)) { LOG(V4L2, Error) << "ControlList doesn't contain id: "