From patchwork Mon May 10 09:58:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12234 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 0D297BF829 for ; Mon, 10 May 2021 09:59:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8DA576891E; Mon, 10 May 2021 11:59:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mSWWRfId"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B022C6890C for ; Mon, 10 May 2021 11:59:06 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id p14-20020a05600c358eb029015c01f207d7so2798583wmq.5 for ; Mon, 10 May 2021 02:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KgKpcksnv6s1nkIaPgdoTr/RRRZK1ZRchgD3iCqTLKU=; b=mSWWRfIdSJryyUxVmYJoZP40YEPqCNi2ifzIDxwu9O5b809jnofovvIdWV0x9uW7mE 75YCI4aajYVaEw5mvSgx2+3j2yw3WDHs/Lbaw0/wKjCGBG5RClGAzcn8Bal8lULTrQmk XGYGUUmY+sBegtjjK9iRDYextjcyds2Wz383XOqyEZ3IoFm9/pCi2pV1ayQQL86NbZtO 92ONp3C71n1nMHQdXEvcOgjtZ4zlXwf+sbMhYKvQVGbJNXM+C0zr5oYC9vQkzt9joHJi 9/1hMvLDgk1tJ8n+vqo+RbXSKXMbarmfPyQBZMbIeQxDlcNqu70/UrcvNY/HgKV9AXa7 LhQg== 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=KgKpcksnv6s1nkIaPgdoTr/RRRZK1ZRchgD3iCqTLKU=; b=V94LzWdQgrJlbO0pBLJPH3mn/CgO3o4xfVJYFvPssUhDPVG8GWcl8O+Fz8o2GtI01H 7i30XkkR+qLZucYHQM5tRUd+vkrYbvmdns+sTDqdDfXzuK11plIUs/ZonBs8g1NcmS3c ScYhPgqh0osMAj2hJIQWBBb2AoeM7UOV9neg7NF81tNPZBew5VzUFUKZxPxbPuWV5Cl6 pah6A4/BhjqvuK4h7mi6fMye/TRJE3/L+VazNIsXMKw1Jy2ZVcwqgvTGz9Yq+H7b2GOk 72jfq4nhH1sNdmobahhXJvOJkuIWkTVNZIvzl6Jmd4LdmSsAxdFJoQ68FhyWYrnyXMy0 PG4w== X-Gm-Message-State: AOAM5309ud21hQIPzE5TIM49Wh7vfjUahgFBRJ3QMTny2ks/GApW8gJw /6en6KEZ5ROiM1BcPyxfvcUzjrppFRU87Q== X-Google-Smtp-Source: ABdhPJyJb0TWul5TdK/ukZ9ubh6EBEhDyQG9/W7GFR+p0iIPAKJYjGA1At967AI+b9rtP5ekX3ozCg== X-Received: by 2002:a7b:c0cf:: with SMTP id s15mr36205446wmh.110.1620640746185; Mon, 10 May 2021 02:59:06 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e710:3ec:6dad:dc2]) by smtp.gmail.com with ESMTPSA id y17sm24767917wrw.90.2021.05.10.02.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 02:59:05 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 10:58:10 +0100 Message-Id: <20210510095814.3732400-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510095814.3732400-1-naush@raspberrypi.com> References: <20210510095814.3732400-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/6] ipa: raspberrypi: Store dropped frame count in a member variable 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" Store the number of dropped frames on startup in a member variable. This will be used in a subsequent change for rate limiting the controller algorithms. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/raspberrypi.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index bb55f9317788..07409621a03a 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -143,6 +143,9 @@ private: /* How many frames we should avoid running control algos on. */ unsigned int mistrustCount_; + /* Number of frames that need to be dropped on startup. */ + unsigned int dropFrameCount_; + /* LS table allocation passed in from the pipeline handler. */ FileDescriptor lsTableHandle_; void *lsTable_; @@ -220,9 +223,8 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf */ frameCount_ = 0; checkCount_ = 0; - unsigned int dropFrame = 0; if (firstStart_) { - dropFrame = helper_->HideFramesStartup(); + dropFrameCount_ = helper_->HideFramesStartup(); mistrustCount_ = helper_->MistrustFramesStartup(); /* @@ -250,14 +252,14 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf awbConvergenceFrames += mistrustCount_; } - dropFrame = std::max({ dropFrame, agcConvergenceFrames, awbConvergenceFrames }); - LOG(IPARPI, Debug) << "Drop " << dropFrame << " frames on startup"; + dropFrameCount_ = std::max({ dropFrameCount_, agcConvergenceFrames, awbConvergenceFrames }); + LOG(IPARPI, Debug) << "Drop " << dropFrameCount_ << " frames on startup"; } else { - dropFrame = helper_->HideFramesModeSwitch(); + dropFrameCount_ = helper_->HideFramesModeSwitch(); mistrustCount_ = helper_->MistrustFramesModeSwitch(); } - startConfig->dropFrameCount = dropFrame; + startConfig->dropFrameCount = dropFrameCount_; firstStart_ = false; } From patchwork Mon May 10 09:58:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12235 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 34BC4BF829 for ; Mon, 10 May 2021 09:59:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB68A6891D; Mon, 10 May 2021 11:59:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pU5bzADc"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7DAEC6891A for ; Mon, 10 May 2021 11:59:07 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso9362436wmc.1 for ; Mon, 10 May 2021 02:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+GT3G4sPCrq9a5bQt/xmz9z6Jx7t87Z5yxPlBQqFaZM=; b=pU5bzADcJMPLNrBVQ07r1tDtIXwyVlPYDEWKokZedo0ouvLGZ3bTmsb3YVO11QoDY3 X58wwRE/r9MgA9Wr3BAd5NK+qg/3sV//9PliyK1hYOPDT8q1ARgCpK1YI8wlrkJrAZ29 gLzicwCYmOHt/Hk2C1xmGIdykjtHI9brjWCXwnq52r9YK7JfpMotoyeS5Rrz35JOGVoZ v1fPpYc7gFT6kUqezUF3/AyDaBv8ZFKwbgQMS3G4Umzb0nOA5+qJnSYit+wo11dVdb0Q kQBvZ1rSdutY9sKZDqAGtftzBQiKxyFVcTaslBxpuZNJnBVX/IkWkuuUu01pET2NKagn 3JEA== 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=+GT3G4sPCrq9a5bQt/xmz9z6Jx7t87Z5yxPlBQqFaZM=; b=Ub6LGCJr17gq9kp2Pis7VfbQbnhcipaaBXTlB6spe96z992ODTjKvmb/j9jqp0xZYu ozCXt7VdZFL1bgEiE90gDkQmDr3vtp3jKr9HjvG1VZ4QSB80xjRXGkF2/fgJeZM5P+Ra 3V5EmLf+9iroqnimxYzkwtpZDJEoBSWwuXfAt07WewPd5V7FxE7wjIlJwaLbmmyAAMPN KntzgvUuS87870s/3zo7jNHdrdw8PO3ENYfdS3BOMKS4RszYBq/7snDtlz/ijMSodNmN FUibnbydjoZFEWM7+FLJovBBSttYLJrYtf1ejzbcyjUzbngC28ZyWQPsalYTXm+Jmnii YjIg== X-Gm-Message-State: AOAM533PFEoYcu/48axWqJONQY56qPej7dM1MAIl9sBftmoOd2CbrTK3 iy2C1ETJ22eNygYwHI3nFdy9etMPgLnKLw== X-Google-Smtp-Source: ABdhPJza/+EbCU2q1b2BJALltEDucDymYtxq9wpHsHgsJ8fA1zgIpYYyz3FQbS1tNWEgyomKlLlqjQ== X-Received: by 2002:a05:600c:4105:: with SMTP id j5mr36197475wmi.141.1620640746976; Mon, 10 May 2021 02:59:06 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e710:3ec:6dad:dc2]) by smtp.gmail.com with ESMTPSA id y17sm24767917wrw.90.2021.05.10.02.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 02:59:06 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 10:58:11 +0100 Message-Id: <20210510095814.3732400-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510095814.3732400-1-naush@raspberrypi.com> References: <20210510095814.3732400-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/6] ipa: raspberrypi: Reformat RPiController::Metadata class header 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" Rearrange header includes to be in alphabetical order. Add whitespace to class definition to match libcamera coding guidelines. Fix a typo in the comment showing an example of scoped locks. There are no functional changes in this commit. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/metadata.hpp | 23 ++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 4f44ffc6771c..07dd28ed9e0a 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited * * metadata.hpp - general metadata class */ @@ -9,22 +9,25 @@ // A simple class for carrying arbitrary metadata, for example about an image. #include -#include -#include #include #include +#include +#include namespace RPiController { class Metadata { public: - template void Set(std::string const &tag, T const &value) + template + void Set(std::string const &tag, T const &value) { std::lock_guard lock(mutex_); data_[tag] = value; } - template int Get(std::string const &tag, T &value) const + + template + int Get(std::string const &tag, T &value) const { std::lock_guard lock(mutex_); auto it = data_.find(tag); @@ -33,11 +36,13 @@ public: value = std::any_cast(it->second); return 0; } + void Clear() { std::lock_guard lock(mutex_); data_.clear(); } + Metadata &operator=(Metadata const &other) { std::lock_guard lock(mutex_); @@ -45,7 +50,9 @@ public: data_ = other.data_; return *this; } - template T *GetLocked(std::string const &tag) + + template + T *GetLocked(std::string const &tag) { // This allows in-place access to the Metadata contents, // for which you should be holding the lock. @@ -54,15 +61,17 @@ public: return nullptr; return std::any_cast(&it->second); } + template void SetLocked(std::string const &tag, T const &value) { // Use this only if you're holding the lock yourself. data_[tag] = value; } + // Note: use of (lowercase) lock and unlock means you can create scoped // locks with the standard lock classes. - // e.g. std::lock_guard lock(metadata) + // e.g. std::lock_guard lock(metadata) void lock() { mutex_.lock(); } void unlock() { mutex_.unlock(); } From patchwork Mon May 10 09:58:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12236 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 AAE47BF835 for ; Mon, 10 May 2021 09:59:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 50C1468928; Mon, 10 May 2021 11:59:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SOoguaPp"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45B9F68911 for ; Mon, 10 May 2021 11:59:08 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id t18so15948121wry.1 for ; Mon, 10 May 2021 02:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JYjTBu6eoLSl1bTSIjACjku/fhdeNHUKB7hMNg3Gq8A=; b=SOoguaPpdeHGHgAFaSltmqHLRMuoKGv39YPbmhbv1bpjdWmxIbzMD/4g7BQReNX/Ch LQvZQ07zfMP2RYuLePrSpCult2n1ERRio8d6CWB8Vkoa4MBfX4BPMHbg8C0JpKnj8/zX dyeYb/j433+gZ6IhdiCkOETeQmB2cjol9Eri4Q+hMz+40bV8lneMRDSM0yaRS1BwjG9W xdz2lP6BcQ+B0G4Dw8S2HZC1dytRCYx+zzoc2K0aX6IR03raBq4zYlu/YMwYbMdV0mIM 3Vpo8r5CtLHSDnnqI0RHESClGIFtIAAwLJ74JmGvAjn3qj7LDVanH37mWu+m3TDS1Fll 2vTQ== 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=JYjTBu6eoLSl1bTSIjACjku/fhdeNHUKB7hMNg3Gq8A=; b=W1KiXISlWVSWiXM/5gQwpZCxli8a79c0W6uW41w7H6atnnq1/1TXZ/BaAfgRntaHbD jP4giXbvGRaXEZas6HGv88DCjy4VAg1Ex8T4CrWGa+IU6jBLu2ih9phbW1VqVKNx+BlP a9VrQZ4UF87f3Hq2atCa1yJPeFvMH1vZshsakuQkdhoBQEo6twgJJbyxP+k9zvhqTO+O xwKkcofm/WA0jLU+9oncd7i+QCNJrLNwlTk2NNZnE+iRRDJO7FqVBB61sk68H2GgYNP7 PW+lcXisEWZiC52lg6YD4hOQpgYKD940L8Zfm7ypkE1CpmRLt9PhvVCly+kJFmpXF9Qa 4VkQ== X-Gm-Message-State: AOAM5323nBep6qYxY7FPJhiLpIg9wORQbXLhS5DkOucmqoqUoNJ8GdYM xJIat7+IIX/6zKNIy3hnJbvY6+whGYbTsw== X-Google-Smtp-Source: ABdhPJyoE2sO1LqG50SLncLmtLjPC2u0Qt+iwuOU1jw4QcrVFgpYIR6PrdqwCDNydnENZhfhaMJIUQ== X-Received: by 2002:adf:ffc4:: with SMTP id x4mr28644272wrs.415.1620640747685; Mon, 10 May 2021 02:59:07 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e710:3ec:6dad:dc2]) by smtp.gmail.com with ESMTPSA id y17sm24767917wrw.90.2021.05.10.02.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 02:59:07 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 10:58:12 +0100 Message-Id: <20210510095814.3732400-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510095814.3732400-1-naush@raspberrypi.com> References: <20210510095814.3732400-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 3/6] ipa: raspberrypi: Switch to std::scoped_lock in the Metadata class 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" Replace std::lock_guard with std::scoped_lock. When locking a single mutex, both are functionally the same. When locking two mutexes in the operator= overload, the scoped_lock uses a deadlock avoidance algorithm to avoid deadlock. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/metadata.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 07dd28ed9e0a..e735cfbe0480 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -22,14 +22,14 @@ public: template void Set(std::string const &tag, T const &value) { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); data_[tag] = value; } template int Get(std::string const &tag, T &value) const { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); auto it = data_.find(tag); if (it == data_.end()) return -1; @@ -39,14 +39,13 @@ public: void Clear() { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); data_.clear(); } Metadata &operator=(Metadata const &other) { - std::lock_guard lock(mutex_); - std::lock_guard other_lock(other.mutex_); + std::scoped_lock lock(mutex_, other.mutex_); data_ = other.data_; return *this; } From patchwork Mon May 10 09:58:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12237 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 4E350BF829 for ; Mon, 10 May 2021 09:59:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA4426892A; Mon, 10 May 2021 11:59:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SKFO0IHu"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13EF76890C for ; Mon, 10 May 2021 11:59:09 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id o26-20020a1c4d1a0000b0290146e1feccdaso9386547wmh.0 for ; Mon, 10 May 2021 02:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6nvwrdwFQFfVWryhozrzfX48ubzoceWz0iZ+FUQS5OE=; b=SKFO0IHuND9o7ofr1KZo3H8T7S3MskA+meZeU+XjcJgt99ePzN3UyDczWF/DTP5SBX MDpt/1+a6zcXS6JrfO8k3cdnD//AN8JAqIcp91N3WVb+awDjIcSqTkl3IfJ0G7RLfwx3 57mJtxx6h2t6XoJqux9NUy8i9a7j0mtjRTN6Z0Ds9hXMbdft6PovmCIBc6WIpUpCD24C 8CALAKUu5cVb6I9n4yXDqSmEwh/ECe6mRcNIyDP6OcfowacxuNSU9X8GsaYBomdIMylD q/G29vAvIkEFRGx85sFpIvF8M5Wh1onmxVYhMtpgzq+imwN2u5mBAHdhJAyyVYr5NTys hL/g== 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=6nvwrdwFQFfVWryhozrzfX48ubzoceWz0iZ+FUQS5OE=; b=SFEWJ7Puy2fB3DYojDzpud450NNPrHsf/PZkzskY5LyETxN/MFhXmsEHRDFPPEeoHg d35sFIVu5IpMfr7VpvSshBk8k4lNzBgcpW0fmsy1z6FWpiJefgWsBavdc4JXUAJxrSU/ aNWsjkLCqAYZYNGPIPO2RPr9y+ffWZcExMv07ek07Rha8Y/CwmQnaCiCBcVxj0SrXaIB d67Ykc4A6nZ0hLaMITWv2AxfgI0hRO0SLTwM+LIsMC/4CSxYuPt6a40QA5OZHGWfN1K4 yXvBk0U0qNTgq4eAwmM+YkwwRA1g5oGhvQhl9PFyqE3hQPFLkNMlthFgPXkjdYQfCZ5r SZNg== X-Gm-Message-State: AOAM530poYVYn7aM4jdjo6VPC5Yr/CIqKrCmHrgrytZmfWhjzovybck+ TN0ctkOgi4FJP++DwigZCBSNQNRmspa99g== X-Google-Smtp-Source: ABdhPJyvaUPXez0HtgFCAFd84L5FKGUl0mOLk3ApdiGP7egdp7DV5zdDRoJ18H0P+7eb9eU+szDKAQ== X-Received: by 2002:a7b:c191:: with SMTP id y17mr35920580wmi.19.1620640748581; Mon, 10 May 2021 02:59:08 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e710:3ec:6dad:dc2]) by smtp.gmail.com with ESMTPSA id y17sm24767917wrw.90.2021.05.10.02.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 02:59:08 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 10:58:13 +0100 Message-Id: <20210510095814.3732400-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510095814.3732400-1-naush@raspberrypi.com> References: <20210510095814.3732400-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 4/6] ipa: raspberrypi: Add move/copy ctors and operators to Metadata class 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" Add a default, move and copy constructor as well as a move operator implementation RPiController::Metadata class. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/metadata.hpp | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index e735cfbe0480..3a97a5f5c502 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -19,6 +19,21 @@ namespace RPiController { class Metadata { public: + Metadata() = default; + + Metadata(Metadata const &other) + { + std::scoped_lock other_lock(other.mutex_); + data_ = other.data_; + } + + Metadata(Metadata &&other) + { + std::scoped_lock other_lock(other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + } + template void Set(std::string const &tag, T const &value) { @@ -50,6 +65,14 @@ public: return *this; } + Metadata &operator=(Metadata &&other) + { + std::scoped_lock lock(mutex_, other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + return *this; + } + template T *GetLocked(std::string const &tag) { From patchwork Mon May 10 09:58:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12238 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 B0A89BF829 for ; Mon, 10 May 2021 09:59:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 384B86892C; Mon, 10 May 2021 11:59:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SWNr9P/Y"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3B046891D for ; Mon, 10 May 2021 11:59:09 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id l2so15934191wrm.9 for ; Mon, 10 May 2021 02:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FEqthfD1opOlgUQvReBRoIm1vl+hGBwXG6rHSbk0IFg=; b=SWNr9P/YXuB8jE68PEZuscFw1BmuUJ8jKD3Ss64BBlJEWXoVTpg3KQvy97T7R6CNaK D1/PKx5PtnZyd1Jh6WKphZhummuXlQiDJVEx8A3J4VAYF540xV42RAW9jOkE9HC07E8o YYoH/NM9BagcEuaC0fBJkEI0tZKcWyoOZrozqHTneUYzWdm09PYzgzeuDNS3FmWmtGkA 7v37ISwN8/SufaI2J8djevgg/L7iOwEZ0ERyK0w7tlUPxnpgxSYRz5lQY3dAptkphS0W gqB54fWeYAvOjIgK4YOp7eurBid1d6yuG4VAJ/ZX4ZGYFwq+05+t7YUoQnojmvMxu/oW aBLQ== 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=FEqthfD1opOlgUQvReBRoIm1vl+hGBwXG6rHSbk0IFg=; b=mYAIX3jrCA4GZwPj/nVxgCajuravVM5FENNuRtRF/O+KY2PEO9FRZTaymVw+zrIpfp 8cOoJSRT+Q6Mqh83nbf+zpu2uZsG1hjK+4KoALUd6L3ucyxokLfyKKoF+bRSdJFO+W0R kaxAeEy3kTkoA8C0RrBLlkwQLI7vYGwkfP1dsqFMKUYcVSsA1yJJccUmoIjONQ0PUraj yBCfUoqiGcxkXA2vn/rjIOvqDoYlWBBNhVDjFuFRPJJR1yaWIgr91lqs0zeIeq99QnOm ugxBumIzPHqXpaGS2/UQjyOt+WoooZBtVdhz0ocVtkCZQ011wacB7+/8i2qAsPKC5XBs XCSA== X-Gm-Message-State: AOAM532Kx0aRZGhRLS1/hLF1US07P8UTzqAVFrzfCrY6tRtkcrfUVRCi koSZDlpLQ5hCg+5ALWMEG3M3C43IjqapgQ== X-Google-Smtp-Source: ABdhPJwnXSZnIYD8rj4ZkZ3f7VT7gMti1lplX2dyhn3WrLtc+AuPMhH9t9pCQ4zP9l1zVkRsB0CGKg== X-Received: by 2002:adf:e9d0:: with SMTP id l16mr29531308wrn.191.1620640749275; Mon, 10 May 2021 02:59:09 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e710:3ec:6dad:dc2]) by smtp.gmail.com with ESMTPSA id y17sm24767917wrw.90.2021.05.10.02.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 02:59:08 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 10:58:14 +0100 Message-Id: <20210510095814.3732400-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510095814.3732400-1-naush@raspberrypi.com> References: <20210510095814.3732400-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 5/6] ipa: raspberrypi: Add a Merge method to RPiController::Metadata 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" Add a new Merge method to the Metadata class. This will merge all unique key/value pairs from a source metadata map to the destination map. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/metadata.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 3a97a5f5c502..fd6aac880bad 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -73,6 +73,12 @@ public: return *this; } + void Merge(Metadata &other) + { + std::scoped_lock lock(mutex_, other.mutex_); + data_.merge(other.data_); + } + template T *GetLocked(std::string const &tag) { From patchwork Mon May 10 09:58:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12239 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 2382DBF829 for ; Mon, 10 May 2021 09:59:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B47C668926; Mon, 10 May 2021 11:59:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="inIbQJsR"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC90D6890C for ; Mon, 10 May 2021 11:59:10 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id y124-20020a1c32820000b029010c93864955so10787448wmy.5 for ; Mon, 10 May 2021 02:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fmFRyvKG40VFNgvY7s5IVKLxkKqN5DwxSDI/eMitC4I=; b=inIbQJsRbdaz3bZNW+8Ay47vaaALuQDwvMCvX5cjzMjE9KpQAdCD7//rVc7AfQy7vJ AySjpD4vnMdoTLuHz7bRVxhbCrCThtjCcJ7LN8xzA/dKYlq7DuD6Rq9nor9+EL4u1jbO oDx8ytdcZZIqq6fVEMGj5gacP6QT0+oAEv/4hmOgLkEnI4XfhDFE6p25toqQjv75WNJ7 RmOMEVNZ7oFYY2V9FAkkCVaxYfS0ts9UZ8kzTLUft//HbR+Wu6Hx17WyXyIFaxhOcA5D j0vh/PJ+EgqN2bX1WEfMnsCBvWCjVLDIjwqSvvC7mmTE0HE09WM8CozxwW5sepCoO5fS bQIg== 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=fmFRyvKG40VFNgvY7s5IVKLxkKqN5DwxSDI/eMitC4I=; b=nNqx2JH/7NwB4AIFhIXNNG7TsQr5vzTa3j2e2nb49FRbf/ET66x/EEM0pFt7EdRhJd eW0z8zVie3QGBxVazc644x+/RZe1fLCFRjFMzeXBYSRfZhNN79Tlw+2GN++wQqYmck3G X1ccXJdOqIcvQC8JaNnTco0WiSmyFOnMBE2//1GWRdjkmGBpV7AT7JADo5UCPwa6zoEk BauG2Z0/Vlk9l4fkk/wNsaKQyl53tLuAXmcJMMgbIT341qUErY6RrYc8jwX/5lOyT63Y oH9QPvhN75TZFBxXmg9I+jfmjLrHi1NxK5Pm+sWNv+zGXd7TGz4z8cu0sT+RwFPJzXYz bkdw== X-Gm-Message-State: AOAM531+Ih6HC3dk1/wSO4DwvO5Dvk/pf22U1+T65VNf0Jh6kGUSeFgi ms2Tx5+PTCFgAgBH5UM7+j/Xt9ekx/whJw== X-Google-Smtp-Source: ABdhPJzoCHHfMCK6qULSshNl970toyxie62p6nni30TannPChpFWn/k1JouwmEUB1+al+ftJyaTzXQ== X-Received: by 2002:a1c:7402:: with SMTP id p2mr35839969wmc.88.1620640750116; Mon, 10 May 2021 02:59:10 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e710:3ec:6dad:dc2]) by smtp.gmail.com with ESMTPSA id y17sm24767917wrw.90.2021.05.10.02.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 02:59:09 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 10:58:15 +0100 Message-Id: <20210510095814.3732400-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510095814.3732400-1-naush@raspberrypi.com> References: <20210510095814.3732400-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 6/6] ipa: raspberrypi: Rate-limit the controller algorithms 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 controller algorithms currently run on every frame provided to the IPA by the pipeline handler. This may be undesirable for very fast fps operating modes where it could significantly increase the computation cycles (per unit time) without providing any significant changes to the IQ parameters. The added latencies could also cause dropped frames. Pass the FrameBuffer timestamp to the IPA through the controls. This timestamp will be used to rate-limit the controller algorithms to run with a minimum inter-frame time given by a compile time constant, currently set to 16.66ms. On startup, we don't rate-limit the algorithms until after the number of frames required for convergence. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/raspberrypi.cpp | 42 +++++++++++++++++-- .../pipeline/raspberrypi/raspberrypi.cpp | 5 +++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 07409621a03a..52d91db282ea 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -61,6 +61,14 @@ constexpr unsigned int DefaultExposureTime = 20000; constexpr double defaultMinFrameDuration = 1e6 / 30.0; constexpr double defaultMaxFrameDuration = 1e6 / 0.01; +/* + * Determine the minimum allowable inter-frame duration (in us) to run the + * controller algorithms. If the pipeline handler provider frames at a rate + * higher than this, we rate-limit the controller Prepare() and Process() calls + * to lower than or equal to this rate. + */ +constexpr double controllerMinFrameDuration = 1e6 / 60.0; + LOG_DEFINE_CATEGORY(IPARPI) class IPARPi : public ipa::RPi::IPARPiInterface @@ -68,7 +76,7 @@ class IPARPi : public ipa::RPi::IPARPiInterface public: IPARPi() : controller_(), frameCount_(0), checkCount_(0), mistrustCount_(0), - lsTable_(nullptr), firstStart_(true) + lastRunTimestamp_(0), lsTable_(nullptr), firstStart_(true) { } @@ -146,6 +154,12 @@ private: /* Number of frames that need to be dropped on startup. */ unsigned int dropFrameCount_; + /* Frame timestamp for the last run of the controller. */ + uint64_t lastRunTimestamp_; + + /* Do we run a Controller::process() for this frame? */ + bool processPending_; + /* LS table allocation passed in from the pipeline handler. */ FileDescriptor lsTableHandle_; void *lsTable_; @@ -262,6 +276,7 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf startConfig->dropFrameCount = dropFrameCount_; firstStart_ = false; + lastRunTimestamp_ = 0; } void IPARPi::setMode(const CameraSensorInfo &sensorInfo) @@ -406,7 +421,7 @@ void IPARPi::signalStatReady(uint32_t bufferId) { if (++checkCount_ != frameCount_) /* assert here? */ LOG(IPARPI, Error) << "WARNING: Prepare/Process mismatch!!!"; - if (frameCount_ > mistrustCount_) + if (processPending_ && frameCount_ > mistrustCount_) processStats(bufferId); reportMetadata(); @@ -894,10 +909,11 @@ void IPARPi::returnEmbeddedBuffer(unsigned int bufferId) void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data) { + int64_t frameTimestamp = data.controls.get(controls::SensorTimestamp); + RPiController::Metadata lastMetadata; Span embeddedBuffer; - rpiMetadata_.Clear(); - + lastMetadata = std::move(rpiMetadata_); fillDeviceStatus(data.controls); if (data.embeddedBufferPresent) { @@ -920,6 +936,24 @@ void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data) if (data.embeddedBufferPresent) returnEmbeddedBuffer(data.embeddedBufferId); + /* Allow a 10% margin on the comparison below. */ + constexpr double eps = controllerMinFrameDuration * 1e3 * 0.1; + if (lastRunTimestamp_ && frameCount_ > dropFrameCount_ && + frameTimestamp - lastRunTimestamp_ + eps < controllerMinFrameDuration * 1e3) { + /* + * Ensure we merge the previous frame's metadata with the current + * frame. This will not overwrite exposure/gain values for the + * current frame, or any other bits of metadata that were added + * in helper_->Prepare(). + */ + rpiMetadata_.Merge(lastMetadata); + processPending_ = false; + return; + } + + lastRunTimestamp_ = frameTimestamp; + processPending_ = true; + ControlList ctrls(ispCtrls_); controller_.Prepare(&rpiMetadata_); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index b22564938cdc..d26ae2a9772a 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1426,6 +1426,11 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) * DelayedControl and queue them along with the frame buffer. */ ControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence); + /* + * Add the frame timestamp to the ControlList for the IPA to use + * as it does not receive the FrameBuffer object. + */ + ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp); bayerQueue_.push({ buffer, std::move(ctrl) }); } else { embeddedQueue_.push(buffer);