From patchwork Wed Apr 21 09:38:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12028 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 CD197BDB16 for ; Wed, 21 Apr 2021 09:39:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8CA8568847; Wed, 21 Apr 2021 11:39:05 +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="b7pI52M8"; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EB3468806 for ; Wed, 21 Apr 2021 11:39:04 +0200 (CEST) Received: by mail-pl1-x635.google.com with SMTP id u7so19505735plr.6 for ; Wed, 21 Apr 2021 02:39:04 -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=aL6F25+hayUMfwdqm82sea9jwpijub9/hGWor4Bf3R0=; b=b7pI52M8KvlUUpt9nppi7upF8RnsozaK53ubV49evvU4TaWMNhO/XtlV4cQs/CJ9u4 yfDr0Mc80afqgiVpHdxpxhnjuBIErlah8oMpbRvOVpF1noV251aF8xwtoTO4AiWZLMf8 LR5g3fb29Gt95JF9u10sFejt2K3ufleM3q92g= 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=aL6F25+hayUMfwdqm82sea9jwpijub9/hGWor4Bf3R0=; b=ZrEe1PAyrWmjtMDuv2iMlQFv5+7q2lS9dI2gJkdKtOSqZwIY4p99jsBilBbrENpASr Pkw2dm+WwXIbIXiteJFHz2ACGuH5OjsXyVVwP0L+i8D08lp+OldlKWRQqLzhyb94Mv90 PbnSxy2vE0pK1EPCHFZ5+XHk1Lkf7ySl3c5o8EXssKGomR6ZOeu4lmNkj+T01q/TDBGd bEO+1uw4GbnuTnedl1qXX6gK8aHuBzgl0a+JvZJq3wqT7MmFAGfLYor9mHrVwPMDMzDy a5wWG8UTtwHXlxoI8X1/peW+2tC5WdX9tnfy4raUCB0vmjzRIMMN6criaEU/nLhaJzQD fJqQ== X-Gm-Message-State: AOAM532x6eCOxlQELcByjVQORxnwtMX7wLGM/okWLGbyzSSQfNWz65UR AJrVcqSbBUAoxv1RXjpPvzeTTDu8HkD9qQ== X-Google-Smtp-Source: ABdhPJzlP9rKZSS38OzFYpzUceRwdSmlrv37DbGANtGNNdSrDOFqBKFUrb0Z4Om0ENnvmBFBc0999A== X-Received: by 2002:a17:902:7043:b029:ec:939f:c9e5 with SMTP id h3-20020a1709027043b02900ec939fc9e5mr20231485plt.64.1618997942429; Wed, 21 Apr 2021 02:39:02 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:7aaa:cbeb:5d87:4ab6]) by smtp.gmail.com with ESMTPSA id o11sm1305939pfu.188.2021.04.21.02.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 02:39:01 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 21 Apr 2021 18:38:55 +0900 Message-Id: <20210421093857.391409-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] 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 aad442de..c95c5e2a 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_ }; @@ -196,22 +195,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 " @@ -219,7 +216,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(); @@ -227,21 +224,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 {}; @@ -250,10 +246,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; }