From patchwork Thu May 27 05:28:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12434 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 78CEDC3203 for ; Thu, 27 May 2021 05:28:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DF1DE68924; Thu, 27 May 2021 07:28:52 +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="grj9HwcT"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 965106891F for ; Thu, 27 May 2021 07:28:51 +0200 (CEST) Received: by mail-pf1-x42d.google.com with SMTP id c12so2766135pfl.3 for ; Wed, 26 May 2021 22:28:51 -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=3RNOBCzj/WX3Lfoq/wSyxU1XdjGgeNyVTqIHwAxqQqk=; b=grj9HwcTjmB8LWJ/kNK5fBEhrlHaRwM7OCG70hOPmQANmsdI63PsK/2FHKK/63JN6s XsutEqHheyKeN3DeYEH5Q5+wnapwMVPgSPCizjxuCoyDmo+Q3JBkbNmZihZR59R1hXWA 9uMSwqj6Ha71o0JS0EThtXGsmh3UV/eCFyZEI= 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=3RNOBCzj/WX3Lfoq/wSyxU1XdjGgeNyVTqIHwAxqQqk=; b=JNkCInRHLZ79R5dkdZdIfQY+3eFBJdH4U1YV/J8EWEOuLq5U+Pdb64ecpYH0h5K95Z beICyXa8R+imepK/fg+2qy+9Yn/z0xQ/W6GvXs51akheMwydoW6UaMIk01EX8bo+trLu ltuOioFzItuo0HYo8QJ5FvV6P4WPS9D2fMb5F/iuXF5uZYQfVAa/RGCDz03BhENULkPI lMTXWP2mYGvemwUE+++yIqiuAokLZlATE0DaIiRlPCQvLXlS4LnfS+4GCI8TXq9pK6e9 PV9faXkuYfidfJ1o4OD1V0oDgwTgI2LqG5bDibgL3Eh8lwCStPE0IZ7xRfH7CDdf+oBN nr+Q== X-Gm-Message-State: AOAM533ucOzIF2dz38+CASbfrnqH3MWYWcmbZb4NMbZgysbkJVxyALtC KBK2MN0bS9LjAQj/8evuwcKqVwfFo8k17g== X-Google-Smtp-Source: ABdhPJwVH3r8WI/T72znypx0/cXBvL/+/W0bHUv73OMW51kNYiYB3ngD2I4CgJCxF4bh838ZlJ6qvQ== X-Received: by 2002:a62:2fc6:0:b029:28e:854b:20b3 with SMTP id v189-20020a622fc60000b029028e854b20b3mr2127093pfv.0.1622093329369; Wed, 26 May 2021 22:28:49 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:7911:c925:fd13:bd2d]) by smtp.gmail.com with ESMTPSA id 69sm793095pfx.115.2021.05.26.22.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 22:28:48 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 27 May 2021 14:28:43 +0900 Message-Id: <20210527052843.4186119-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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 | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index caafbc2d..b39c6266 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -244,12 +244,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()) { @@ -623,19 +617,17 @@ void V4L2Device::updateControlInfo() void V4L2Device::updateControls(ControlList *ctrls, Span v4l2Ctrls) { - unsigned int i = 0; - for (auto &ctrl : *ctrls) { - if (i == v4l2Ctrls.size()) - break; + for (const v4l2_ext_control &v4l2Ctrl : v4l2Ctrls) { + const unsigned int id = v4l2Ctrl.id; - const struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i]; - unsigned int id = ctrl.first; - ControlValue &value = ctrl.second; + ControlValue value = ctrls->get(id); const auto iter = controls_.find(id); + ASSERT(iter != controls_.end()); + switch (iter->first->type()) { case ControlTypeInteger64: - value.set(v4l2Ctrl->value64); + value.set(v4l2Ctrl.value64); break; case ControlTypeByte: @@ -650,11 +642,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); } }