From patchwork Sun Apr 18 09:04:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11974 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 207DCBD812 for ; Sun, 18 Apr 2021 09:05:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D3C8A68818; Sun, 18 Apr 2021 11:05:07 +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="TgitGanK"; dkim-atps=neutral Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 86E46687F3 for ; Sun, 18 Apr 2021 11:05:05 +0200 (CEST) Received: by mail-ed1-x529.google.com with SMTP id w18so37209552edc.0 for ; Sun, 18 Apr 2021 02:05:05 -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=Jo8WkXMl8c5cRR6Ta7ynE+2nvwPxIi03CyEKeDa4jWM=; b=TgitGanKKA/DKYLvYo1DhDfma713OjA1IrGJx23PZAZc4aKlUDpAg8vW71im0err/b MCPhGvZieYw3Hq/WdUFVwhKRD2ReszHqVz5lly+Vi3b5Ir+/NGFfcjE0/S50eCbja5LF 8crTKJ6imC6bBcn7X5sREDqlUAq86nQcXXPUZDql0fEKiLh+1+1FKGox+6K2N7jSUZP8 gPS/c1F7niK/7zLP0I9552NqnFJnhFjMDxS3nIQktxRRJg+Er8Zj2fb2hlcSQyOlOZUG IpBBd+0h+r0Q6QNgxEHlZLrFgiecP+GQ1nkRh1rBNXvrf4faq5zyB+2GGcJwgLGg+CDn RGxQ== 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=Jo8WkXMl8c5cRR6Ta7ynE+2nvwPxIi03CyEKeDa4jWM=; b=moHOv5ulZoRR9CTZAiOqPZMvxaMukfDLTX3+abM+MWfUR/llx6ekrcImQTqa88MikB vWqxOHV2x+/2Dq3pjVdLmj0Ks1qCHs3uFc5qsDS4GOtW4+CBjhz9QlSZeKkIlbtzlV/n 5ARbuoT/uInnR+wcVV/i0MEtfJcVgj5y/yMOf19g6j8TLSiox5arjsPYLQ5SpHBXK3uq BFLg2lhyyQ0T1mFhqm7iJ1oCn8UujPmFQGbyrmrLt47hMtGX5T+itrTZzH0d4mAcV29J C429UiE3Uqn/5XRFuenBI4sExBNQ9aY9MPYtSyyJUuJ73F+36Corc68L1Yml+mEHAqpu w+qQ== X-Gm-Message-State: AOAM532LJhtXvMUwRBX6reJJ/6BKo34MY2Yf4iyQbqHrXCLxk6CiRWr5 C5vHThh8aOQY5j/qyvBbgz6cvyJx8uhrVQ== X-Google-Smtp-Source: ABdhPJwbc8Qfe7fr6Q+cV41dVmTuTvBeWAJYPfVp1+dOC8KaltGAWWY3TGL1aPMAafOFK9pQRvKEcw== X-Received: by 2002:a05:6402:26ca:: with SMTP id x10mr4833468edd.386.1618736704714; Sun, 18 Apr 2021 02:05:04 -0700 (PDT) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id z4sm9080679edb.97.2021.04.18.02.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 02:05:04 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 18 Apr 2021 10:04:56 +0100 Message-Id: <20210418090459.38506-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210418090459.38506-1-naush@raspberrypi.com> References: <20210418090459.38506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/4] 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 --- 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 b0f61d351e3a..f6d1ab16a290 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 Sun Apr 18 09:04:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11975 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 C6012BD812 for ; Sun, 18 Apr 2021 09:05:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5ED0968803; Sun, 18 Apr 2021 11:05: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="bA2Iim9s"; dkim-atps=neutral Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2B428602CD for ; Sun, 18 Apr 2021 11:05:06 +0200 (CEST) Received: by mail-ed1-x531.google.com with SMTP id j7so220519eds.8 for ; Sun, 18 Apr 2021 02:05: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=fW/hur3tefpJwBCdBS9ucikdtiTjIrz8a6UkMMoW9n0=; b=bA2Iim9s4Yb7uN7Ca+qtkQm3I9YqirW0xuD49Vmz7IsgGBClVowaUCx6aDSIqW5VyX KaKQ6LE8kMkeiLjuEk6J1dS4wk4KdA/EYmFRdgn+t8a/oD2tY4VYFaqLBnb4d26qswLr h9uIYtRR7Uz6EtATbHSxwG2J0Mq3pu2ClHMLtPrwQWGkpFWgW+m9VEIbps2HV8e3HRaA mzWscyHXaqY4a0H67TKsM/+1y4mFJ9ICsE9qv+B24toVSHN3lJVP5AFHtplsA0yhoO6B o3q0z5LcpDyyX59iUSG0sJ9VXq4DR+swPUyvOggtkWqZXfHgVQ6UrME94IXF2yCa9t66 VIYw== 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=fW/hur3tefpJwBCdBS9ucikdtiTjIrz8a6UkMMoW9n0=; b=jGmJg1URKJNHWb30JLTQrYr9jfWk9UjPxDXAkmf9Bxs3K18VLvzD+WA3XveTjCzBi/ AzRoPN5rbgcGBpj9ykbtdi58dNtZlxuRFAVLOA3xDp0LthiETt2ztkwG/A/TQiwzy/8X BmFTxLqkV0bmFSTcgHmI97AdgvTzLFymOW5iFiSl9llNyTzGtTqZOTPWGGBU7ulbAgPY IrHiQHtnF6rJ/fyROwq+Mtt0+V1SLR9KohjJHt0q/mGL77U73UIWoTgGEQb4IRmkc1+K cIpzdSy3a/cd7fVZhI0soTU5NxuGIbr2cNCJuT56bDMhjnGPapfW44+db3vMPKOvs9uG Nl7A== X-Gm-Message-State: AOAM530XZggQiePrFrsN8cVnXGTBN0kgVcC+j6xE1cFnE2yanNDNH7Bw H+VL9m1hgfy+IwGs/enrG404YXH9OVm3lg== X-Google-Smtp-Source: ABdhPJyb92kDm7+ciU2aoPFJs2W8m7d96CRVk7Zy9pmcANTRGbc1sUpe10xfK/BnyM59jSqUXeAF4g== X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr19384023edb.204.1618736705513; Sun, 18 Apr 2021 02:05:05 -0700 (PDT) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id z4sm9080679edb.97.2021.04.18.02.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 02:05:05 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 18 Apr 2021 10:04:57 +0100 Message-Id: <20210418090459.38506-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210418090459.38506-1-naush@raspberrypi.com> References: <20210418090459.38506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] 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 --- 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 Sun Apr 18 09:04:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11976 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 84860BD812 for ; Sun, 18 Apr 2021 09:05:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 99B8068816; Sun, 18 Apr 2021 11:05:09 +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="fMsGmWtI"; dkim-atps=neutral Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEB0068803 for ; Sun, 18 Apr 2021 11:05:06 +0200 (CEST) Received: by mail-ed1-x52d.google.com with SMTP id g17so36431839edm.6 for ; Sun, 18 Apr 2021 02:05: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=uule6aP/GbUVKt6rRXc2oaEhZT9hc7570Iq0GDDxCU0=; b=fMsGmWtIYkreFvpGOwnQsQaU5u+qXC7mqSrY6XSMTX/9lqc7anbItR10Ed7ao9vYyK iX+QoNDaXQAlZB2uOg/R7gO7cKRmHBcwPkUphrrH9LAnKUEflV1L7P3B9KvTbk97A6ht F4Jzg8cidHeI4TWgym0SJSzwi2yqM+GsSPXIyKc21QzeXvAR9ydA+WxjHDRab2AmYhN+ N7JxrWmSJRykk/8NWqzPEpoJCgA29WPmTBWNZw3TU1GM0wtiIl/8maotwglEQ9wcAaDM YgJddHkWkTRfhzIGzO7rOrnqR6mbdrZL3Vnz8Z6Z9Z6z5LXobQdchXs7wlX2r8FlWpXR AZGQ== 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=uule6aP/GbUVKt6rRXc2oaEhZT9hc7570Iq0GDDxCU0=; b=HLTMUlsUBQJVqqJqvZ2NyXGE6VaVBFtOx0d3BlqTa+oepn87u50Y3n/8/XzyfuPQgH TUBC5F96BOmpQAR+Zw0y3cOv+thIpMMQtUkfpmBrRzSYSmyw22vhXDsBRLyz2P62ZgKB WqPplmknJjzYlxXFacjzh0sSg81XzHfaf8iEbxfQRCZTAK6Flkbb7lUAbxTmjTnYPlk+ h23/GtdEqBJe2qLf0a+cK1H/LNdDETaebyZcr2JSGNl7h8N3jplYkEuhyU4KbY99Yf33 hgLR7+jhiqfxQPnr8aQQJEJYYkWYpzujVF+xGkKwp9uKhnLeUX6qaYKOPP2nARJ+LS/P 3eHw== X-Gm-Message-State: AOAM533OddoLX+WHa1/qhj1GyjJJ7pXPXMgMX0fYuhV0RlCM7ztWMGHP pE4iFRkRmTQ5FEsOJougHnVfumL2i97S4A== X-Google-Smtp-Source: ABdhPJz7bIrSlqvxl1DSz4K0AoH4bjS2PtC9oEDz9udF4D/B7DgAMRKZ9WkJnKCW73ZWa8L4nKpG2g== X-Received: by 2002:aa7:c7cc:: with SMTP id o12mr19683388eds.291.1618736706365; Sun, 18 Apr 2021 02:05:06 -0700 (PDT) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id z4sm9080679edb.97.2021.04.18.02.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 02:05:06 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 18 Apr 2021 10:04:58 +0100 Message-Id: <20210418090459.38506-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210418090459.38506-1-naush@raspberrypi.com> References: <20210418090459.38506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/4] 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 --- src/ipa/raspberrypi/controller/metadata.hpp | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 07dd28ed9e0a..319f2320fc70 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::lock_guard other_lock(other.mutex_); + data_ = other.data_; + } + + Metadata(Metadata &&other) + { + std::lock_guard other_lock(other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + } + template void Set(std::string const &tag, T const &value) { @@ -51,6 +66,15 @@ public: return *this; } + Metadata &operator=(Metadata &&other) + { + std::lock_guard lock(mutex_); + std::lock_guard other_lock(other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + return *this; + } + template T *GetLocked(std::string const &tag) { From patchwork Sun Apr 18 09:04:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11977 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 9A27BBD812 for ; Sun, 18 Apr 2021 09:05:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 553E86881E; Sun, 18 Apr 2021 11:05: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="NrHLbc5C"; dkim-atps=neutral Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 07DEF68819 for ; Sun, 18 Apr 2021 11:05:08 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id h10so37104895edt.13 for ; Sun, 18 Apr 2021 02:05: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=4RcEdwi1QWwOUa0feax3IKgOFFbXuYpYgXBgd3TfJCg=; b=NrHLbc5Cm4ekk026S9iQoP3F09BqwMtqr/BXSqJh9C00wpFwJhyMsi2AIRz5U9QvbT IohvKqF9azDeFuZ7dPa0nVXLZxveb6fSs4FlUm9LUBrlOYjeq8Gs0j4MFCzg0uGmCBHu TfD62ExqYUeRRTggcGPrvo8nR4gYbOSg3C+JxFDrAL0metNcXsQUPid9y0tvHyA4gAyU rpOuE6dIqPWlBqd4jPj5ayQ+VELUjOFelYHZUuCYlS0CX0DFzBqywLQIMR32YyzqrFto KlhqrHvKY2gwSQHL/m5VCg0lxMTgRZ2kpDzFpOCF93jigifRcEAlKGyy+qqQYoQdLuIi 629Q== 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=4RcEdwi1QWwOUa0feax3IKgOFFbXuYpYgXBgd3TfJCg=; b=fvKSWa61cA9vzwJ7Xqevh/x0eC1MQU4B9kDXVfMlqZi9OxNuXJ6GpYzZQmRN3fngA1 cIdxGrXCHT90VEXaMWbYJXYSdydBqvyhc/7qVSEF5AhBC0gIASgD0fCZd2ywInWTVldP HYeoSShc8NtfYWc0jgAhNKpTcf1L6dtgH7BEO0vLGP7ZRkZ8EHCllR8j9r/yqt6WxcCF ivNllIu2AHJOlgMpnvMHbi3edOrthM4El2+31REXIg9/fjnDFxjVjbjimOMkWcnHIOSB 9a2uVRz94zmju3Tbh8ZRYtiA7jDkoNcvF+sllDmDfzqAQvLbIcszIf72jgC6sVl+mFE0 HgNQ== X-Gm-Message-State: AOAM533PItv/4LmD5a8d6igYVOVvQHEhd0eUO7JXBVdpgnEyWHIV+tEd GsvPvOL1qcm5qCrkq7Tpk7o0+w+GVGqpaA== X-Google-Smtp-Source: ABdhPJxkGiFO1zu8svX4heIVSJNzngSRNSGHGwI4/rlYrA2eKC1WmYoFIvYSubdMuM12Jw1CvEP2Hg== X-Received: by 2002:aa7:c2c8:: with SMTP id m8mr5273522edp.86.1618736707361; Sun, 18 Apr 2021 02:05:07 -0700 (PDT) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id z4sm9080679edb.97.2021.04.18.02.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 02:05:07 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Sun, 18 Apr 2021 10:04:59 +0100 Message-Id: <20210418090459.38506-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210418090459.38506-1-naush@raspberrypi.com> References: <20210418090459.38506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/4] 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 --- src/ipa/raspberrypi/raspberrypi.cpp | 48 +++++++++++++++++-- .../pipeline/raspberrypi/raspberrypi.cpp | 5 ++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index f6d1ab16a290..a9b7bb1acb92 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::draft::SensorTimestamp); + RPiController::Metadata lastMetadata; Span embeddedBuffer; - rpiMetadata_.Clear(); - + lastMetadata = std::move(rpiMetadata_); fillDeviceStatus(data.controls); if (data.embeddedBufferPresent) { @@ -920,6 +936,30 @@ void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data) if (data.embeddedBufferPresent) returnEmbeddedBuffer(data.embeddedBufferId); + if (lastRunTimestamp_ && frameCount_ > dropFrameCount_ && + frameTimestamp - lastRunTimestamp_ < controllerMinFrameDuration * 1e3) { + /* + * Ensure we update the controller metadata with the new frame's + * exposure/gain values so that the correct values are returned + * out in libcamera metadata later on. All other metadata values + * must remain the same as the last frame. + */ + DeviceStatus currentDeviceStatus; + + rpiMetadata_.Get("device.status", currentDeviceStatus); + rpiMetadata_ = std::move(lastMetadata); + rpiMetadata_.Set("device.status", currentDeviceStatus); + processPending_ = false; + LOG(IPARPI, Debug) << "Rate-limiting the controller! inter-frame duration: " + << frameTimestamp - lastRunTimestamp_ + << ", min duration: " + << controllerMinFrameDuration * 1e3; + 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 2a917455500f..9cf9c8c6cebd 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1414,6 +1414,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::draft::SensorTimestamp, buffer->metadata().timestamp); bayerQueue_.push({ buffer, std::move(ctrl) }); } else { embeddedQueue_.push(buffer);