From patchwork Thu Apr 22 02:18:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12055 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 9F247BDB15 for ; Thu, 22 Apr 2021 02:18:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 61E0268854; Thu, 22 Apr 2021 04:18:19 +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="Olj2K9RY"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 98DF468849 for ; Thu, 22 Apr 2021 04:18:17 +0200 (CEST) Received: by mail-pf1-x433.google.com with SMTP id y62so6812589pfg.4 for ; Wed, 21 Apr 2021 19:18:17 -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=Lu978gzqbTWIUvxflQvmctS/NAPkbdXXF8n35Kel5w8=; b=Olj2K9RYpewwcVglFIaiDq0Fys6aHxDjxq/RUBDbpLqPZLlxU6zK2koF9BBIKxEBvf 32k4ZxvB3v70UZPqCfjuEBnY4Z+sCA8XhaVIs6cKFnEkjIHlF+zwQAJj/JPAdDTatGvu OrSRkT4xGipBjGZKAUJC9rhCrNe+AisX1twJY= 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=Lu978gzqbTWIUvxflQvmctS/NAPkbdXXF8n35Kel5w8=; b=l3qNwJ8GMAn26UzfET6qwQIGc//0NJIsQIggOZS6nbfZpw/iAj8Z6EAO0uMhDxNYtO ESpU8TZtZCjMCe2MuoZ2FsGANb3IzJXvEBY6zI3NAMtftyHXJp1SPHPSuJeM0ATCWet9 R/sCLfea3pYbh7d7+xqkdGtcndIO1XD5hNyjnRTiV58P7aqFIZmiqMklHZhIAs3s0hL7 il+JRPj3i4zJPMT0emWH3Z/y4FSoQhfc5m6/vp6t42M1CwcI6zmQiUxy9zP8iFdoLJkJ QIruQzvTHtEIVf5QQQvUQxJlDZZQzDRCrAMUeRFbYZ/wfyxUfp3XerZzglididQF7Y4b Tgmw== X-Gm-Message-State: AOAM531Y94PobMVVUfn0MrIMLsCts/ezt6KH8QyBTHLfie7rcMwrxVAd A8n+WkAi2jxAIDvmV/LtsaWhD3kpl6nuGg== X-Google-Smtp-Source: ABdhPJzaGWGTKKsIueqm8sFYDerY/Kx8hygfQm4bOdcFfQ/Fdw3MBSuBwjuFtPGRwBGfoEv0cbzujw== X-Received: by 2002:a65:6184:: with SMTP id c4mr1160742pgv.200.1619057895755; Wed, 21 Apr 2021 19:18:15 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:f88:d5a0:ebc4:5b76]) by smtp.gmail.com with ESMTPSA id lt11sm3352480pjb.23.2021.04.21.19.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 19:18:15 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 22 Apr 2021 11:18:06 +0900 Message-Id: <20210422021809.520675-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210422021809.520675-1-hiroh@chromium.org> References: <20210422021809.520675-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/4] 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 | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..3c32d682 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -179,12 +179,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()) { @@ -525,19 +519,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 +546,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); } }