From patchwork Thu Apr 15 04:36: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: 11934 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 F2409BD224 for ; Thu, 15 Apr 2021 04:36:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E5F56880A; Thu, 15 Apr 2021 06:36:34 +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="cBq1E+Dz"; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E368602C7 for ; Thu, 15 Apr 2021 06:36:32 +0200 (CEST) Received: by mail-pf1-x434.google.com with SMTP id b26so10084807pfr.3 for ; Wed, 14 Apr 2021 21:36:32 -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=zFtD9rQf8Iv6NHghLu1cUepALcYmYwlxAOla1nag0lQ=; b=cBq1E+DzNv3MTzTcf01WrjNLpSyT3/feaz0PxubN9pbdYEuh+bhaStTRaCEDMukb5P umERmO91krxiSxWi1tIBg1FRSrUrMCKuwindafmsvTktWunVHrinyobHWgca2noEKIsM ZlW7bE3K8RXfeWXSlMI7kdC9URdtBuCuVJhY4= 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=zFtD9rQf8Iv6NHghLu1cUepALcYmYwlxAOla1nag0lQ=; b=Geu4MFJkiHF3r4KCAn8moEButcDNsVClkBrsrTsqCH5OjMY34hPbKRr6FlTaygT3t0 Oq5ImKt8H6u32F+jJJ5jhSrpOehVrizmimkVBcJx/sneKlEq5cK74uylliYYCn5d90Ax tGtgtfGvZXfeZqX9GPWyit0LezrQQdzy+Ma97QP2LjPANuC6JUi1uRIIY3I/5DVwNjon wF3R4EumT3HqxZeWtYs4ngX1W+1AF5rgl4f2xGwBpRzNB59Z0xYifX+PLSTmfyZa4C/A QbRShn6SrOvkFNCaCxjpHI9rEIvIZELmgA+1P6gnjKl6+9m+Ak2kXRInPQTbPYmIMHiQ 666A== X-Gm-Message-State: AOAM532Xv9QaKwh2IZOjjfiPA41BE3UjY71yRqYI8oarn8A+EAeGu/Bl g4UhszcWfiOxa6Td9soM9N7gqotIrKo/pA== X-Google-Smtp-Source: ABdhPJw97WyWjJGZf55okuon5U2fV6kX367UgACLbnrpNx5S5M/heOb0vV05ZpRC2EZVZPwfWg96BA== X-Received: by 2002:a62:8f4a:0:b029:20a:448e:7018 with SMTP id n71-20020a628f4a0000b029020a448e7018mr1419543pfd.62.1618461390633; Wed, 14 Apr 2021 21:36:30 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id 1sm343824pjx.46.2021.04.14.21.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Apr 2021 21:36:30 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 15 Apr 2021 13:36:25 +0900 Message-Id: <20210415043625.3346627-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index d4a9bb75..8fd79934 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -525,19 +525,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 +552,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); } }