From patchwork Fri Apr 23 09:36: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: 12094 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 A10D0BDB15 for ; Fri, 23 Apr 2021 09:37:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EB8B6887C; Fri, 23 Apr 2021 11:37:56 +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="G7lxCbF+"; 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 2E3AB6886E for ; Fri, 23 Apr 2021 11:37:55 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id c3so14925171pfo.3 for ; Fri, 23 Apr 2021 02:37:55 -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=RSqDOLvLGFfx5si4xOZu5KKSSZfzCxjP22JVLy+D9C4=; b=G7lxCbF+777mSGRjyD7ykfbXQWVEkW6B/Zfh/+vcZI6dAKnIH/vflUBHJwzIG/jCzW 8UNbnWhUw8zqWqy8obI3vKfXGu4ilMGDktfmqCKtruQh+WOnSet+WL1Q5pt93zGtRQ6W DGQyt5wWnfVg1CklRNUxyWATZZjRWQE2sn0GQ= 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=RSqDOLvLGFfx5si4xOZu5KKSSZfzCxjP22JVLy+D9C4=; b=GtHbwRGV0y8Y+gvkSY5ZC7rL1E/cFRJxNVmMNibbPJ0MsVbAVJt+B1mo+2PxoaXl+A nxIXEmZYm3UtCuoKdrn2pOZKF65XhzCOzspMURGW6wcYlGkMIgF830My9/W/Cf10wS3O ykUMCpFhlvYrc9TEM9RP707oSNyRV+nb3Vz6dvWj2CQZH/kCTZgCiz+cTsFFUxk7/bfW B6SNbo5NirTZo8jtr0SyYvFMCotP8SJrFuN8ot63ScUBe+53fzlOac6MZQccofVVA2cB ZXDFF5LF64JKCLXLRMrmfRIRsGm91wdi3dgHDTPMmHOA9VbkM97IgP2E+YYpE8HvVlQh te6g== X-Gm-Message-State: AOAM531qcu+sdMBm85YcPftCHBOLTdTzuBtbYIaZgsLUAc2N/zsWc4Dq BWJAHKHVIyNcf7tyDNId4KXVfM11sF18bQ== X-Google-Smtp-Source: ABdhPJyyv6fZs+BKxOcSFWP+6T3hOWXLSEZkwDHuhqGZUGPQQRKeTpNHtuEJwx1rYPINwaUG7um6jA== X-Received: by 2002:a63:e206:: with SMTP id q6mr2871284pgh.225.1619170673037; Fri, 23 Apr 2021 02:37:53 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id z5sm4273660pff.191.2021.04.23.02.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 02:37:52 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 18:36:50 +0900 Message-Id: <20210423093653.1726488-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 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 | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index decd19ef..ce2860c4 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,14 @@ 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; + for (unsigned int i = 0; i < count; i++) { + const struct v4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i]; + 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: @@ -552,11 +541,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); } }