From patchwork Fri May 7 08:40:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12222 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 4A19ABF831 for ; Fri, 7 May 2021 08:40:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EAA6068919; Fri, 7 May 2021 10:40:50 +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="j9KncL+U"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E0A86890C for ; Fri, 7 May 2021 10:40:49 +0200 (CEST) Received: by mail-wr1-x436.google.com with SMTP id l14so8319856wrx.5 for ; Fri, 07 May 2021 01:40:49 -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=gWJqV6+KMq4Cdqjn8VB0rZGm/jSwDPd5ZcJ2lMonb8E=; b=j9KncL+UNOwGCZ6bLH9bwOlmpFhoDC8zPaGAvMT5rfFJeNomHPimHlrZ/sAyeM0A1y 0WS5aLGzpF/MPh11s5jaDCGk6S+L3sAZnDkYz/6armdnIpumnbqtOcWdSCNQtM9KlduX LnCaT+kCjnqejI2gl3mVJbeo1m4HERt2gi4uUEM23QEn3eut+FZrrphAxMY8A93PjmQA Ps0r2SmxFbUooxQAmAOjDggY2/jO6lSgdmazDSkkm0ztEIVAuVDU2OqMr+5qAxlfNfkH 3zOzmECiI2Uo4VH+326bCxFjcBvho3hhXW+zHDtMIkNmNenuy2zQUt0r86mQITNr7MWj YbEg== 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=gWJqV6+KMq4Cdqjn8VB0rZGm/jSwDPd5ZcJ2lMonb8E=; b=AUtRCtvB6NdG4+5CUAyTAQZbOfBpTUBLFDqTdscyMpvzqSMTHYxQycXN/K8hrCpIfl v59CeszA9dL+cS9AEaQos3HprUjpTYcXPpYgAJh4EXqMkzOkBJ2tDT/yMN87/XssNs56 FwsY4En3gQgmWl/lmdXclfGf+MO2cQ+ed19f0HHXPdF32lCWzsDYnFjP7Bb8YSrdc+ke R33akSAbFodVXnp4gqspH3CZdQwjnTscnXNvuE1hfugUn74NMXTcpDWV0DW0upy/MmFy soPF5F3YHH9TZI6wDBIM5lssoPg5/Rl321FSlWNG0UzC/EicIs3QO1IU/3b6PBiQisgR Bjaw== X-Gm-Message-State: AOAM531EGzBdPy3fmmWSQ27BXf3KA1Cr51pEIXM947D970Rte0Y84ZTy DdtEJIuYeAx2H5XbGK776aKPdDNR8cg1pg== X-Google-Smtp-Source: ABdhPJyH27Y+ynH6eG5fj+bK0oeCRPGgiC4qcW8GLxXu+O24x4yvqKJO14JHuBs7e5+M7kX6hX2fYQ== X-Received: by 2002:a5d:400f:: with SMTP id n15mr6838475wrp.274.1620376849173; Fri, 07 May 2021 01:40:49 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:81ab:95ee:9715:e9fb]) by smtp.gmail.com with ESMTPSA id l12sm7604098wrm.76.2021.05.07.01.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 01:40:48 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 7 May 2021 09:40:38 +0100 Message-Id: <20210507084042.31879-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210507084042.31879-1-naush@raspberrypi.com> References: <20210507084042.31879-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/5] 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 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 Fri May 7 08:40:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12223 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 4D738BF831 for ; Fri, 7 May 2021 08:40:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B58FB6891D; Fri, 7 May 2021 10:40:52 +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="rGHQUzUF"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 696A86890C for ; Fri, 7 May 2021 10:40:50 +0200 (CEST) Received: by mail-wr1-x431.google.com with SMTP id v12so8306986wrq.6 for ; Fri, 07 May 2021 01:40:50 -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=rGHQUzUFwAhLsZi6vGsK2WOzNq75nNwVNrr8cL8i+UJLIQRhurDAYKjxTG+Vx3nApE LnFzE5T5oykDfVZ6tteNhU1/K7xmWQKVuk9tvUQGbEONnOs1kR9xxuQIBnJrNyh9HgFL HpxfCG3L8yzl7KOZYXUngRicWOljBlm89Ux7QKGy+grgM/y7RvmcY5zbOyYhUDzmSBeh ees3jOhN7/x5Cqwp0zalBS2MsiACPmtOgsnb8ri0M+hCprYu4qS8tJB7q6wF6Dy0cdtq nM6hv3wu31qk8QQDZDSFNJ9+0tKd+7yXlMhabPzvfuZwMSuxikVzzhoClpEHYmB0+h2/ nWZw== 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=gr+SvF53kuRY1IrF+wY+McNPwp4qpksesL/aCmwyRiroW+P9NQyu1l50PGsPVS+qaf GtM4QmNNFww622f99Clnh22HkP9buKr8I+VW5OgbcoSd6ZLGUdfDUxpw0VMoe4e52kKh 0lEhdB0iloMgQsu3szX/GxUm5AdbTBsBY+q2DgiOxqjBnlXtHXsJzQdpn2yuOTrItjQL XYJJPGqzN7UcLhtVmPNd2wvRdacpZtvA8BtrLymwwKLyuYmDSGDfLvk4W7r3gDq/x+GD xdWX44eUK35nfPv9K1cflls3S8uD2ltLe1fPDXbojza508nbBt4jXqFVJebGXdPCt/IE uzXw== X-Gm-Message-State: AOAM533g9q/3bKBmKvkhjEhStoUUU+0kV05ImA6v98wslbFC9uFCUCTK Ak8L6Dq2cLxzOoBOtxtyRptDH4VAsLw75A== X-Google-Smtp-Source: ABdhPJysKxiy52NTht5ROg8unjvM6fFaKj24u4lGDNOavoP9GCRKPt+2FcXQLBeLw5/jFato3q8eiQ== X-Received: by 2002:adf:ab1d:: with SMTP id q29mr10504127wrc.208.1620376849938; Fri, 07 May 2021 01:40:49 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:81ab:95ee:9715:e9fb]) by smtp.gmail.com with ESMTPSA id l12sm7604098wrm.76.2021.05.07.01.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 01:40:49 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 7 May 2021 09:40:39 +0100 Message-Id: <20210507084042.31879-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210507084042.31879-1-naush@raspberrypi.com> References: <20210507084042.31879-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/5] 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 Fri May 7 08:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12224 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 C585DBF835 for ; Fri, 7 May 2021 08:40:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B4F868922; Fri, 7 May 2021 10:40:53 +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="JoMOA0q+"; dkim-atps=neutral Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 530846890C for ; Fri, 7 May 2021 10:40:51 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id d11so8307286wrw.8 for ; Fri, 07 May 2021 01:40:51 -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=xuoCbVuKUIV66V4sgaGGY+s1zJ8EKg0r9sGPnJwPd7c=; b=JoMOA0q+PdyiE4YVl796UrAGS+2B2MCT6G659h5Y9JQllK7wwu50ZQ5LbBEA1MFUxI le3qVa72nNCbyn47DrqfuuMEIi+Mxq02ah1yabFJAjyAwAbVbdgW+KTFPNSJ8VyBv9tA XnnJE7TX/xYlsFtOzOxAMqtL51+m/cv1bLB+AccWyxeFKPlwgeypzLg/VJztHL/a6WQP NTmCDWOAnh2GrSXoTgTuNjh229oZtqFfk0yT/FMCClBeTf8YKsXtODq5Ppcekyl4U72F nbHA6FcNMf0S5pdpsQolVr6oH0IP7wwdFIMl4bYV5vUlnskEJ9P71RrBeufT4/Uuksia HNlA== 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=xuoCbVuKUIV66V4sgaGGY+s1zJ8EKg0r9sGPnJwPd7c=; b=D+5LUYZ5epSJ1wDdKCk7DJgK3/DiyMrGrSuvlbUBBQTOf/sEl4iNTdDe6z/xhOZGKP jOljqRZ3Q0KuAEhtRad468cM6k+nGAoMS9Yd4kSl9wA4RKlLdQO3Lav9yEvknKwovEel vkGIj95z41Yh6BZYg92BHU6dWob8LsS4NpYmEp0iJRQtm2loExKeHq4Ikz0pg5PkEiIT owXGQLcyIra13236/u5/YJ/YKVHBBLIZn1o3ZcxaDjZ/BsgnxiC6l3XN0tT0T5Knz2K5 IM84NBBM2mKaCAcP70orIG2DoPjJmvw/xasPpoP66U+KvTh7umzXFNmkRlAHp8QvrAHc WzXg== X-Gm-Message-State: AOAM531LtKZSQOIHQq9ZUoo4o/gcrzjS8irMfFy1u3o7NWFM4oSa0Aa9 5+3zYWt51j0OYAhRo+hxXHlrCCstOt71cA== X-Google-Smtp-Source: ABdhPJxF7gsr2QgV7o+ADEQAJDXCWQXpHMvJjxaghHunRJnLFYdb8p4KCUM1RjBFkLVPVBnEulJ0XA== X-Received: by 2002:adf:d084:: with SMTP id y4mr10946207wrh.0.1620376850628; Fri, 07 May 2021 01:40:50 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:81ab:95ee:9715:e9fb]) by smtp.gmail.com with ESMTPSA id l12sm7604098wrm.76.2021.05.07.01.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 01:40:50 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 7 May 2021 09:40:40 +0100 Message-Id: <20210507084042.31879-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210507084042.31879-1-naush@raspberrypi.com> References: <20210507084042.31879-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 3/5] 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 | 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 Fri May 7 08:40:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12225 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 9FF30BF831 for ; Fri, 7 May 2021 08:40:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 60DD968919; Fri, 7 May 2021 10:40:55 +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="F0/KH1h0"; dkim-atps=neutral Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B84EB6890E for ; Fri, 7 May 2021 10:40:51 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id x5so8297152wrv.13 for ; Fri, 07 May 2021 01:40:51 -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=ToAhjL9XFdxjjye6nKRusCeRANLcN15gZaOodjy4LOI=; b=F0/KH1h0po9NP/XRRJplLAtS8OXJmpfbGBtjJkaB8hq85vvGMwKwAnrVtiZIcuOFNh XcktEcDnQZzfI1Rcm8uQAXLeF7Uzpxi4ohaIE3JAKHUFott0QrDu6O7cbALBcVJ2QuKc 7zDMrfrEMoX28EeKwueHRlfXQokID1tydBWdaflbKLlL/azBKk1Ydp9kyRM0dvV43WHG s3P/lWg5kHqTJk6zkIZoqb/e/vI2lp4jXqDu70KtwZMyQuiwn3BGw1b5S1dcth2nlH/Z sPem+DZMGuTO2uXYugFw/0sXQHJTfndRRJmSGqxkaY0PT/9KuYhd4ZYwsJY92xnzvY5G 2kiw== 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=ToAhjL9XFdxjjye6nKRusCeRANLcN15gZaOodjy4LOI=; b=BaXSneB/a7D1zqibPLKmkrEhgdAOspAxFMxILhvrjObOPpe7BKLHJs8G4CuWcBYzo5 KMhDr7JiIhosuUDafPKzykWRpQbNkf9R84LCdIYANLpR9f2LEqgJFxJRC6Ny1wc68BA/ /IzBB6pSjsstpXl/YORE5gT7kbqOsWHp99OQVQf883vykyL2zq/Jg48k9J25atd3HHZJ M/luGlr+k5eoxDFyMtC2pbOhLw1MxPt60Cd6l0YnjuWewuGd3VoNLboMONox6uophLwm TPG/WQOXHfNLNcPl74BSxke2ya4FW4ALhZr2IE5pGYyR4JAaQ1Ra3PyvKwZdbJ5R136c baBQ== X-Gm-Message-State: AOAM532LTDCtaPXm5/KdQ7EwjgRkjMYFcFCzV2jz/XmZUh21Q9ct2TMf CwjQdl2eRUnU4IbLSzUhGufTZZC2pciv1Q== X-Google-Smtp-Source: ABdhPJw8hynxj6NuYoXAa7/TyWDXLDjE+nEg8ztapsVGSjwXP7pZ/WDmX6dILWYpYgAMXk974oCyhw== X-Received: by 2002:adf:fa06:: with SMTP id m6mr10847400wrr.387.1620376851299; Fri, 07 May 2021 01:40:51 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:81ab:95ee:9715:e9fb]) by smtp.gmail.com with ESMTPSA id l12sm7604098wrm.76.2021.05.07.01.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 01:40:50 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 7 May 2021 09:40:41 +0100 Message-Id: <20210507084042.31879-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210507084042.31879-1-naush@raspberrypi.com> References: <20210507084042.31879-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 4/5] ipa: raspberrypi: Add Overwrite 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 Overwrite method to the Metadata class. This will overwrite all key/value pairs in a destination object that have an identical key in the source metadata object. Once complete, the source Metadata object will be empty. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/metadata.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 319f2320fc70..ac64f17f617c 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -75,6 +75,26 @@ public: return *this; } + void Overwrite(Metadata &other) + { + std::lock_guard lock(mutex_); + std::lock_guard other_lock(other.mutex_); + + /* + * Overwrite any contents of data_ with identical keys from + * other.data_. Any keys from other.data_ that are not preset in + * data_ will simply be copied across. + * + * The reason for the seemingly illogical steps below is because + * std::map::merge() does not overwrite existing keys. + */ + other.data_.merge(data_); + std::swap(data_, other.data_); + + /* Render the other object as empty now! */ + other.data_.clear(); + } + template T *GetLocked(std::string const &tag) { From patchwork Fri May 7 08:40:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12226 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 0631ABF835 for ; Fri, 7 May 2021 08:40:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD98B6890C; Fri, 7 May 2021 10:40:55 +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="TfVgXges"; 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 C245668921 for ; Fri, 7 May 2021 10:40:52 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso6668371wmh.4 for ; Fri, 07 May 2021 01:40:52 -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=4S717ZsySRiN4h+aZW4nhYMwXVC+cgf8UZnjbQ6phO8=; b=TfVgXgesW084VhTrb1+XqCWAT9vl1OaSWlVcNYTp6Z2VfmLtUQGrHL5uEW+mPpm5lV xEz3yQObidj4IFM8C/PmZF4q0WZB6LO8qUukgXqyTrVD8bpk5UgsSu9w0GuDliuZF8uT bAHQS2HWagUJSUFogXo/UYAzw0kmRKdIxCP66Dwf2Qz9DOX2Go6tyqmapw15kJFfu5Ws ARHCR63JlsH8pIUaRF0Ies/QhCcTk2i5tznIYfsTJ3KFYb9jhx8GGBRXDk9WtywZohIm FB4J5ViPR6r/TxTzoyvDPtTYabC+/iZSpOMOtHwkOXDExHgMAQUGReh+XcmFcyRKF8OC 0Lig== 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=4S717ZsySRiN4h+aZW4nhYMwXVC+cgf8UZnjbQ6phO8=; b=mTll8zYt3/Gp3dozyZVMQ6XhXhpkbxUcT4eQiX5TQb9y8ZEfkPyu5D/Ue9RTIMtnl0 zv0ZIcexhJwGayX/dIA9Z808v3a4Aj+lisUI4R/mWuZzFkUTkg3bqrd0QyOQK2wDppF5 cbOvt5/1mcznYafAx4tMWNMgyng5UtMKEmV2sWx6+9ToFRu9/HBFZV4iMWKxnS2v88cT 3qq42vHfyFjM2zPrCDQ+ElNcpSac0QMpOB54AUnuAFiocwWLtyP/TrnONOMWTX+RxsIP Azj63VDTEQHz2CvkzMWDhH6GkusuDy5B3Yll8YvcNKnrc3Gy0QFddoRlhRkj112UlScV 81Ow== X-Gm-Message-State: AOAM531I2klwNxW11A83i5QoZlZ4ppo910l6rDN6ShCXidBxKmV1Mfe4 hu7FZJ3NOUWfnbOjVl51v/MreAqXz4nH9Q== X-Google-Smtp-Source: ABdhPJxeL3uesUMTy12RipniR9k9xi0PJmpYBu6vvZI2Xuzn1c8ZBeJEHz9TRSKB4gKmvDA22r5vnA== X-Received: by 2002:a7b:c74d:: with SMTP id w13mr8455645wmk.25.1620376852053; Fri, 07 May 2021 01:40:52 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:81ab:95ee:9715:e9fb]) by smtp.gmail.com with ESMTPSA id l12sm7604098wrm.76.2021.05.07.01.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 01:40:51 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 7 May 2021 09:40:42 +0100 Message-Id: <20210507084042.31879-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210507084042.31879-1-naush@raspberrypi.com> References: <20210507084042.31879-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 5/5] 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: Laurent Pinchart --- 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..57f5497a6e6b 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); + /* 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 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. Any other bits of metadata + * that were added in helper_->Prepare() will also be moved across. + * All other metadata values must remain the same as the last frame. + * + * We do this by overwriting the current frame's metadata into the + * previous frame's metadata object, and then swapping the latter + * with the former. + */ + lastMetadata.Overwrite(rpiMetadata_); + std::swap(rpiMetadata_, 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 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);