From patchwork Wed May 26 06:43:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12421 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 CEBE8C3203 for ; Wed, 26 May 2021 06:43:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 322B668922; Wed, 26 May 2021 08:43:20 +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="bg40dJpW"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2814D6891B for ; Wed, 26 May 2021 08:43:19 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id d78so206869pfd.10 for ; Tue, 25 May 2021 23:43:19 -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=umurDYwZpbLqTAmXYIB3IUlN7PC3nJKh/nRuCeVfO24=; b=bg40dJpW5koKuR2llvr7L41XQ0xUrQLT3XzngzLlQ1N46WLlQqgKCxuxn0sfe8DoCJ +ic7p/hw5VFAzK8Di+Jvm4IAch+9RaXaGDJTenlTdxpj43+5XBF/JiVwEJKoVTbrWejQ mnrzg9Kt+3p0FYKWaEb6sHc8QkXJr9rmDVxVk= 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=umurDYwZpbLqTAmXYIB3IUlN7PC3nJKh/nRuCeVfO24=; b=lQZnSBeiI5fJS8NJGupbWSHFuNe7eH/vlvS6LsXqSQa8xkKeVTH2yrVAi2zGJxWRNh gVXm/r3oRwWFauQ/E8Mp5C9Zcv+BAWZLxryn3Q/7YG7e79v7snjfkxAnHt3d+SdAjEi6 v/A/jvqA1gyc+tgrUxxTizdERtk2m125EM+IUQjXu8pxfVB1AipkASgucl+YYOwsuTLB I6htZYrouFqdUMVjEGHcy0UPBwnTeGz9p6KbrZ+8PkcQNVGdfLLYrbY23xGd4kAyvMVe a2tAi4/RTqP+MLAo0nhZZg2S1gBD+u4ZeY2G3T8xVzIzEYSA4ZoazWPPY3hkKKzI61j7 dgvA== X-Gm-Message-State: AOAM530vWUmzUWnQ5kX2mySNPP9atAzwYwIEXjTn3odAYve6UPSmUXRy xzLg2ItVHX+j/4TqN7Wc6tHgLo5c27ySwQ== X-Google-Smtp-Source: ABdhPJzh+09MDnkyi/sF2P5/botfEA18va5RrnqQ2WXgTdtwjSJ6m/SEI4uYbxQpSU3NP11vAAsoRA== X-Received: by 2002:a63:ad0f:: with SMTP id g15mr23244708pgf.415.1622011397416; Tue, 25 May 2021 23:43:17 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:e36c:ae58:48e5:2f8e]) by smtp.gmail.com with ESMTPSA id o9sm16372349pfh.217.2021.05.25.23.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 23:43:16 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 26 May 2021 15:43:11 +0900 Message-Id: <20210526064311.3767479-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-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 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 | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index caafbc2d..aaca7171 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,16 @@ 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); + 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 +641,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); } }