From patchwork Tue Apr 13 06:19:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11896 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 A5E1FBD224 for ; Tue, 13 Apr 2021 06:19:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1AEFF687F3; Tue, 13 Apr 2021 08:19:36 +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="jNgQRpoF"; 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 DF5A0605AE for ; Tue, 13 Apr 2021 08:19:33 +0200 (CEST) Received: by mail-pj1-x1035.google.com with SMTP id i4so7924957pjk.1 for ; Mon, 12 Apr 2021 23:19:33 -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=Q1hC5n4D2ruo8tDDXvz3jBM31g3+DuH4sNeW+LjMqkY=; b=jNgQRpoF7FWgfOf+HbNqMdgzfcdpO1kElBtMSEWqrtQz9aGZ0WbXCIFS8cxENQI5IA mPBJpSPYfCoq6bRhMjZGmmkkT8NTdpVW44kifvLKJMXDCWoMwvs5JhVKbH5pTk2Dv0Sz fMGtOLxKPhbDJSv5WMsDvIMzp23+B8ayBJ0Js= 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=Q1hC5n4D2ruo8tDDXvz3jBM31g3+DuH4sNeW+LjMqkY=; b=HdVmr1LfKCmA+HQDszV+xrGZFZUhRABXtZWsZreEB1N/Fj72GZBxDuRqsHNQqqF59N RUzctILscwengB+/RwMN5hup6oItyS43uDfL22ylacic+WqhNThiRE2frqYBktkS14pv qknn1dhYug1dtFf2/+melem4KyPdrfB9f99v40EY7Ba1yQO7CWQL7LANBc8EhiLDKGqO oX9ruNRUeruxCKr+otqQwokfJBAcP+6c+AXJhaJsY0W2g4at8aFN15R0mP/G2M8y3/Qp nyE7C1SutpNdUn3EOb04JI4Me4RDHF+Y+pvSlneouLtl/5Lx4aOOppmNmlvR+zK9h5ad T8bQ== X-Gm-Message-State: AOAM530DMXwZ72+M4Da+PsZNZhB/C+lbc/CFDmk0TM+QryHwHpXCf/QT 3fadoNTmwiervgZ1hmjl4YJLdbhPS3obTw== X-Google-Smtp-Source: ABdhPJwzumDc5JDpYF58fPRm4dfKdLuyTRLnX4RqbxhH4FAqFevZlTOjai3qyjTEVe72/HFw+6jWyw== X-Received: by 2002:a17:90b:300c:: with SMTP id hg12mr3027914pjb.165.1618294771934; Mon, 12 Apr 2021 23:19:31 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n4sm11666063pfu.45.2021.04.12.23.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 23:19:31 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 15:19:23 +0900 Message-Id: <20210413061925.3054927-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..78c289c2 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,21 +195,26 @@ ControlList V4L2Device::getControls(const std::vector &ids) ctrls.set(id, {}); } - struct v4l2_ext_control v4l2Ctrls[count]; - memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); - - unsigned int i = 0; + std::vector v4l2Ctrls; + v4l2Ctrls.reserve(ctrls.size()); for (auto &ctrl : ctrls) { unsigned int id = ctrl.first; const struct v4l2_query_ext_ctrl &info = controlInfo_[id]; + v4l2_ext_control v4l2Ctrl; + memset(&v4l2Ctrl, 0, sizeof(v4l2Ctrl)); if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) { - ControlType type; - switch (info.type) { - case V4L2_CTRL_TYPE_U8: + case V4L2_CTRL_TYPE_U8: { + ControlType type; type = ControlTypeByte; + ControlValue &value = ctrl.second; + value.reserve(type, true, info.elems); + Span data = value.data(); + v4l2Ctrl.p_u8 = data.data(); + v4l2Ctrl.size = data.size(); break; + } default: LOG(V4L2, Error) @@ -218,30 +222,23 @@ ControlList V4L2Device::getControls(const std::vector &ids) << info.type; return {}; } - - ControlValue &value = ctrl.second; - value.reserve(type, true, info.elems); - Span data = value.data(); - - v4l2Ctrls[i].p_u8 = data.data(); - v4l2Ctrls[i].size = data.size(); } - v4l2Ctrls[i].id = id; - i++; + v4l2Ctrl.id = id; + v4l2Ctrls.push_back(std::move(v4l2Ctrl)); } 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 +247,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 Tue Apr 13 06:19:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11897 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 BFAB1BD224 for ; Tue, 13 Apr 2021 06:19:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7985A68805; Tue, 13 Apr 2021 08:19:36 +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="GtG7BlvA"; 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 F1A4F605AE for ; Tue, 13 Apr 2021 08:19:34 +0200 (CEST) Received: by mail-pj1-x1035.google.com with SMTP id cu16so5920025pjb.4 for ; Mon, 12 Apr 2021 23:19:34 -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=Ox+C7Af69yIOx2a+58sLdnlGiHUk+GH4jLb5Jk/KAYI=; b=GtG7BlvASClndtlgXEPc4ucS1Wi/A2uaDWInLDLgcmcDqer0kIaYN3pvb+q17XRr/j s+tsN9qwQFFYQub7elWukqPkfCC4bUp6GJDRtnAr58w2ffQ98XLhBdq/VhOUb5JcAk4m UETZl6+wDKuHZbqTj7k0r2lxOeyErXuwp3trg= 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=Ox+C7Af69yIOx2a+58sLdnlGiHUk+GH4jLb5Jk/KAYI=; b=dRA696e4lCrYZA7psSW0AYMMSyhM/IKoLq9Cpih8hBxg2A1ulMSMUjrTysXPoEaikL Fco2DaKVLoSMAsE72d6US7tJDv/BAgfilpbEftOiZ2RbJ4KeIyd42va8qXHIBG1Nnd1t ZhqRHi+dHLK7cuW1sGUaDSPQsOzoF15iZVf0yIsCV0UToDNWJU8GO6+juEeDddJQTLKK u04ReyzP6XJVnYzO7AunQ6NLhIWGeEc5AnLrNRL1IvlZ8yJQUx1O0wQGQR8ZySuenP8u J6a4fd9kEvLiBiyB8QcjkDl1cmF5VtvM/4j0TOJ2ZcDBjyABVTQ8AhFhjhstZFkCcTe3 Fh/w== X-Gm-Message-State: AOAM533sdSpTvM3LtR9BmPkCmb6/8t9GhaOGN7ztePlbTO0oNWfbzgnn Ba4Sxmf9nLn7WSM/9UOIoewaX6NP/6BQYQ== X-Google-Smtp-Source: ABdhPJy6ef7aLY7cGsGPiXsA7eZpUH2Q8GEoh+zKbOzN4SPhiFy76kKrOajnNZG3vrNifz2bSlQ9eA== X-Received: by 2002:a17:902:708b:b029:e6:77ca:3cb6 with SMTP id z11-20020a170902708bb02900e677ca3cb6mr30759437plk.84.1618294773434; Mon, 12 Apr 2021 23:19:33 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n4sm11666063pfu.45.2021.04.12.23.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 23:19:32 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 15:19:24 +0900 Message-Id: <20210413061925.3054927-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413061925.3054927-1-hiroh@chromium.org> References: <20210413061925.3054927-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] 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. Reviewed-by: Kieran Bingham --- src/libcamera/v4l2_device.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 78c289c2..8625dde8 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -280,12 +280,11 @@ 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, v4l2Ctrls.size()); unsigned int i = 0; for (auto &ctrl : *ctrls) { @@ -332,15 +331,15 @@ int V4L2Device::setControls(ControlList *ctrls) 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; @@ -349,11 +348,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 Tue Apr 13 06:19:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11898 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 165F8BD224 for ; Tue, 13 Apr 2021 06:19:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CCA90687FF; Tue, 13 Apr 2021 08:19:38 +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="gJqxOICr"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E0A468807 for ; Tue, 13 Apr 2021 08:19:36 +0200 (CEST) Received: by mail-pl1-x62a.google.com with SMTP id j7so7647550plx.2 for ; Mon, 12 Apr 2021 23:19:36 -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=slwRzF9Gj9xvox8fzWKnDmBEEvj0hcU17A7XH1OMBAA=; b=gJqxOICrCMlHggPPocmFgdJt4OWfxH36rAmTwoIlN8mtOLBC43DHwjTMPJTpjdUfjd SJJdB+3+fSXStdbc2DI72jlD1LfaFkrVlxHtlS10nVNRbpKkaKsw+ElC0KQB8xKKByqZ Ml6ySSf6LI7sGI5/PHIztsOymWt3MoFuhz7IU= 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=slwRzF9Gj9xvox8fzWKnDmBEEvj0hcU17A7XH1OMBAA=; b=C9wzGu/6sm/arOgQ4cEP4ne8e9+BkSz7lH7OBRYjFbPs6roD7db4dBOeNpyMslTjoY dAm7/lo7IC+T/IhZoehX8gRfYCobebU9+8f7hvi8jLo4jTz+nM2xGgCU+KjPBj79BdZm EhsZ4ElMcvor86i4PEDNgESlhSDQlA8Q+2ZQwmDOUwqtm2qoRzyA0fTrGpOMDX/HTiWZ e8YmxXdBlJRLONpeGfziukdBq0/cle76nu63eITENdyxyBe+bCEPVgKLU071pWPX5hDy retdteA23l4cRzeaQz7XKDF5iYN+pV8Mu5k2pl903awFTqHRHrj7YOxMGZvj0/clEdaO XD9g== X-Gm-Message-State: AOAM5326P9AgVoNpv0OiSZc/lR69tISLLRu7eRtyFvN5WjlcZ6yioyMC +04M6cTI39jYdFJIddoQ3XSA4hGGVpFwIg== X-Google-Smtp-Source: ABdhPJycFZeX3DqwNbkTwcnB8RL64OKpuhTAiTwtGGmdsgkyOpeA/xXWiqr0d7ZefnGLAzDQAK40+Q== X-Received: by 2002:a17:902:e884:b029:e5:fece:3bb0 with SMTP id w4-20020a170902e884b02900e5fece3bb0mr31075309plg.61.1618294774860; Mon, 12 Apr 2021 23:19:34 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n4sm11666063pfu.45.2021.04.12.23.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 23:19:34 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 15:19:25 +0900 Message-Id: <20210413061925.3054927-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413061925.3054927-1-hiroh@chromium.org> References: <20210413061925.3054927-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: V4L2Device: Use std::vector 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 std::vector. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/v4l2_device.h | 3 +- src/libcamera/v4l2_device.cpp | 36 +++++++++++++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index d006bf68..4cce3840 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -55,8 +55,7 @@ protected: private: void listControls(); void updateControls(ControlList *ctrls, - const struct v4l2_ext_control *v4l2Ctrls, - unsigned int count); + const std::vector &v4l2Ctrls); void eventAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 8625dde8..8f29cd7f 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -251,7 +251,7 @@ ControlList V4L2Device::getControls(const std::vector &ids) v4l2Ctrls.resize(errorIdx); } - updateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); + updateControls(&ctrls, v4l2Ctrls); return ctrls; } @@ -353,7 +353,7 @@ int V4L2Device::setControls(ControlList *ctrls) ret = errorIdx; } - updateControls(ctrls, v4l2Ctrls.data(), v4l2Ctrls.size()); + updateControls(ctrls, v4l2Ctrls); return ret; } @@ -517,25 +517,27 @@ 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) + const std::vector &v4l2Ctrls) { - unsigned int i = 0; - for (auto &ctrl : *ctrls) { - if (i == count) - break; + for (const v4l2_ext_control &v4l2Ctrl : v4l2Ctrls) { + if (!ctrls->contains(v4l2Ctrl.id)) { + LOG(V4L2, Error) << "Unknown id: " << v4l2Ctrl.id; + continue; + } - const struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i]; - unsigned int id = ctrl.first; - ControlValue &value = ctrl.second; + const auto it = controls_.find(v4l2Ctrl.id); + if (it == controls_.end()) { + LOG(V4L2, Error) << "Unknown id: " << v4l2Ctrl.id; + continue; + } - const auto iter = controls_.find(id); - switch (iter->first->type()) { + const ControlValue &value = ctrls->get(v4l2Ctrl.id); + ControlValue newValue = value; + switch (it->first->type()) { case ControlTypeInteger64: - value.set(v4l2Ctrl->value64); + newValue.set(v4l2Ctrl.value64); break; case ControlTypeByte: @@ -550,11 +552,11 @@ void V4L2Device::updateControls(ControlList *ctrls, * \todo To be changed when support for string controls * will be added. */ - value.set(v4l2Ctrl->value); + newValue.set(v4l2Ctrl.value); break; } - i++; + ctrls->set(v4l2Ctrl.id, newValue); } }