From patchwork Tue Apr 27 01:21:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12116 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 DD140BDCA4 for ; Tue, 27 Apr 2021 01:22:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1513568880; Tue, 27 Apr 2021 03:22:00 +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="hpUK8O2R"; 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 1B642605BD for ; Tue, 27 Apr 2021 03:21:58 +0200 (CEST) Received: by mail-pj1-x1035.google.com with SMTP id kb13-20020a17090ae7cdb02901503d67f0beso513920pjb.0 for ; Mon, 26 Apr 2021 18:21:58 -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=bT/Pe1z2AFRQwP+7vmDRt+Pxfy/0+BHzUjvqrSL0yF8=; b=hpUK8O2RGfjGVBdG1pm/1Usf11EME837M7YuP6Gj6ur6kOH/6Jsf+maWL5WxZ/iru8 YupeoeUMXwr/lATbG6dIoQmin5Z7BNw1CWnm5EJD9ybLy6viTV8u0M5ZITmsICg7iFO1 GOhmQjvaT56T3Z2g4zgZT1T+Fm6tZugNpJdWA= 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=bT/Pe1z2AFRQwP+7vmDRt+Pxfy/0+BHzUjvqrSL0yF8=; b=LKAs4p/K6b9uxCD1iq0iFu2YF1Y9r40RDVaw7u2coxlOyxMaeBzlvUz47Yr6j3Oicq iNHb1TQjalL1X4VQh0b2/mL6nxuGQIxc5dQebH5SmndfKOoiP98yyVgF91cpyRBsHjB6 XoxBVGXzLoxKac84nbibh8XS2dzBAo/LHgefqKZD74AUwETA/fCJbWjXncuyspUVMIDI ysNoUpxzcfVG2dDnuY3nOqRPooInWqYdI3ldqpRzDcgML7usffhhqzhKlhA6RlE87QuX ePoUdtHJYB4fdnaT7mV3Ae4WqC/t5pGNGphJ801s+hPlLRFlv5Oa/2TDlxJCfu+BXat9 62FQ== X-Gm-Message-State: AOAM533eK/8TjYlKGalTbgf1oI8sGn7YGdnm9LXy1CioXp9psfcDJmnD BwMDDZN7Cyr7HgYEf7MXlH0DUEaCoY+piQ== X-Google-Smtp-Source: ABdhPJwbHjn6lUPvwCEkmO51f5T4Whu8v2p8bF22IMfsbr13yIkwT/8RO78mft7uEUbiNN/JH0xa8A== X-Received: by 2002:a17:902:6a88:b029:eb:3ea5:58c3 with SMTP id n8-20020a1709026a88b02900eb3ea558c3mr21794650plk.55.1619486516193; Mon, 26 Apr 2021 18:21:56 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:12bd:9107:566c:4682]) by smtp.gmail.com with ESMTPSA id p10sm715901pfo.210.2021.04.26.18.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 18:21:55 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 27 Apr 2021 10:21:50 +0900 Message-Id: <20210427012150.5338-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-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 | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 397029ac..64501523 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -178,12 +178,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()) { @@ -520,19 +514,13 @@ void V4L2Device::listControls() 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; - - 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: @@ -547,11 +535,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); } }