From patchwork Mon Apr 19 13:17: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: 11997 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 C458EBD812 for ; Mon, 19 Apr 2021 13:17:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 708C668835; Mon, 19 Apr 2021 15:17:28 +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="nnqfLFO4"; 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 756EB602CD for ; Mon, 19 Apr 2021 15:17:27 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id a4so34021901wrr.2 for ; Mon, 19 Apr 2021 06:17:27 -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=nnqfLFO4CanlAnfby2OO53IS4oy8LHMuHV0KuoyM+qsw8kt2/7PCogJexNoZG1UJ/S e131S2qvyM242rJfoqDHf3Li7UusHy5yhXN+5JKMlMI5zOmzOB6e86t4Ov71gzYq/IV9 4AVuvOq5/s8HoEE9JufuvyH1WIRTdOuVawS/tprbSfzuJeYqUKyqpB0RrjhK3eaaxuL7 H9omSE4avIlvzFvdejf0QEz0xDQe7+yFPrVPegSh7vvBmQ439V2kme2eGkt95hmcNnxX 3XPzqlKI6VNLYQ3hd8cWTz/+M7n7eW9QxLPUklaxkcuRCoWXYa6SVz5vx+qo4kW2YHMo SBhA== 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=ElILAxcDXubHXi+cbklVlV2bPdYfZtSknPmwPIUmtdmcsKefqYeAZD4rmNQ/RUzuei b4JKFca3aQhq6gs99TJqMADQBMcPQpxzcIvEOb0p1g/NcugigfszqI0sQnu3aW/fyZQi aJ+nv6WnrXXnE8yVi+r4UjpygJex79jT0UMfq4JM0MuUR20gIyLRZR9ndCOouYGK9VKR /Ywgw+Bl7c8tapP7L1yTrq8RSrUZN+fuVHHMtmdVvg2LzdhOw7K9UaDpSOprNsjFJhB9 dx47yNf2eHY4OihyNkB6uBRnVLq4B/yCu3WS9HErxKIsnYhELSBP2YUhgOzgIWwSabAM L02A== X-Gm-Message-State: AOAM533cTs/HatNEKRbxENdcb5CHIzBLyrGcYz1AoU70mhuyG+BqwaG0 m+3AL9MktLffgAKjUsIw9RCFiZqdfdI1CQ== X-Google-Smtp-Source: ABdhPJxzUWyUfxq2BtVkx+BMOFZ8UN8rP1fxWrCb5hLDDf8o6B6aCpMaAbzSBuuGIDkQEPAmJhUQYg== X-Received: by 2002:adf:e58f:: with SMTP id l15mr14215503wrm.175.1618838246972; Mon, 19 Apr 2021 06:17:26 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:15:5363:8f56:4f84:754]) by smtp.gmail.com with ESMTPSA id t6sm22335428wrx.38.2021.04.19.06.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 06:17:26 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 19 Apr 2021 14:17:12 +0100 Message-Id: <20210419131715.256802-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210419131715.256802-1-naush@raspberrypi.com> References: <20210419131715.256802-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/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 Mon Apr 19 13:17: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: 11998 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 28442BD812 for ; Mon, 19 Apr 2021 13:17:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D8FDA6883A; Mon, 19 Apr 2021 15:17:30 +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="pXhytwhM"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 64E7A68832 for ; Mon, 19 Apr 2021 15:17:28 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so18036300wmj.2 for ; Mon, 19 Apr 2021 06:17:28 -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=pXhytwhMwyQIX3nWdamPkvoIqD0AbWoGpvXKKLSV/DxJwpA1dRlxMw5MrTIBibxC00 /s+IFEvSnKJLrAaL8epKrRr17kA7DovWiiUWj+6YpCKFUcT2B9fuiBX0u3H5ctX9C7vI GzLQjjD5IDeeFSWmzNYgh8tYpL7wOnTFznuXw50TKN5KZveAXFJyJ3AlvKYFvxYiqWFQ rNuZcWpZjjx2Zp32DfPehfrhQ39xjaV+19wVx/8AzcUqCuvgT2n9hKMRdotJYLp3PbwJ eh59dxyjm5qh+uWQoBrAfXfp0NjYJAEj/L0ikdJqiIWLpERVsKbQ7EZkQ+MLjEgpK8OB nG1g== 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=IEF+bo5ogvTlRw9YV+07H3ky1Btp4+swsNV+kLCI5KJdm4b8nUuxRgBdILD5gkK9Cq MNMJ/+xDQ3OI6/AMcEndX/l0cErhFkFGAlnX9TWj2A9Z7IMuqJFJDKswMUnOrqG2E1J0 cKrbxmLc0/8B/tepSlwYyIxIzFaKKDKS1OcaMOZAMBtQrYDiZm2Zknuu7OS10EIloYGW jBiNIFk/9/tRNYiWKCeQTtny0GxRf4YGtta90GGC66edYRpd5LDw/7fvDgOoEN1ML5tK nsmH2FSMuxI5QNaYJAwqDKh1uw8C/FFnofvLWeK2dP4sAZ3E1OJfA0W7VnoErGmTSrg5 5TEg== X-Gm-Message-State: AOAM531NQn0lm7OIyQWPpn1PqCiFU0hQ4gyAjtu/IN6lHpxO8HH0/bhv oFSKlmiz2a4iK6C10kENS7rVaqsTV5OK0g== X-Google-Smtp-Source: ABdhPJw4Htvh4BmJIiVVLDFnHD1FqJY+0W3OTKM4HQ6JfyjoT7eSFMavDxokI8x0LXa+FCrRsulAcg== X-Received: by 2002:a1c:770a:: with SMTP id t10mr21872473wmi.49.1618838247855; Mon, 19 Apr 2021 06:17:27 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:15:5363:8f56:4f84:754]) by smtp.gmail.com with ESMTPSA id t6sm22335428wrx.38.2021.04.19.06.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 06:17:27 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 19 Apr 2021 14:17:13 +0100 Message-Id: <20210419131715.256802-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210419131715.256802-1-naush@raspberrypi.com> References: <20210419131715.256802-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/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 Mon Apr 19 13:17: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: 11999 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 814DDBD812 for ; Mon, 19 Apr 2021 13:17:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DDD768839; Mon, 19 Apr 2021 15:17:32 +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="VFx/h1cN"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EE9068830 for ; Mon, 19 Apr 2021 15:17:29 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id n4-20020a05600c4f84b029013151278decso6834273wmq.4 for ; Mon, 19 Apr 2021 06:17:29 -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=ByDL9nYy7x4L3Tto/bzy+16JVkmrBlZp1522yVKSnPo=; b=VFx/h1cNXTdgknnNOD7+mHakOezi1fCrmb+jpNd2QwzbsLVvdYXQYRASmr2bm0SaHA zzXQLe+XS+mJjz7ZJgr8D3AG7J7X358q8PsD54fxWwoTi4XaF//RXQLgUr2B0x7CtkEV 7pMIYVdIb6YyUI7Fvbi0/7xpTNsvcx9pZNUcHqStPMUw3idwW8OqWbAivnisW5elUrHl w8reMyqXpx/+B4Fkc11iW6pDQq2cNWpgZpP6RL9nXdCyvAOBb7y1C2geq8V1HNi5N1Nt L5z3QkPpzWlyQ7lejSM7AMsPSo4wmMhSPIrNwIgMLuStOVi9WrX0ETILBX0xopOWBnPV EaQg== 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=ByDL9nYy7x4L3Tto/bzy+16JVkmrBlZp1522yVKSnPo=; b=kQSoGTdkjIJqalWem1Yxw4Mgl9skZyow/CcRj9AJ3kM81I4cXrUI81IBsklxuKBpD0 8jA1kNxHOutJxDNppo7JMS0XcARuPatv0fQuMgGn0vwHyp2oYD0roCgbfEpgCnqCZt/L fGPaRutlB3ncn5Oo30FSCCnGBdgXLYA4cDL2YKjHr8WnBQnU0pEN3hqFPRZyBNbB11x0 Wo1m6RqFI5y8mdRUFakHLMXwj4/NYqGS1xqy24kjh6BdrlIdCWC9Ggv7uryvMMUMn8xh kAA/YY6SNCM8jk8wIEuPAUQjVYE9xVHC07+s4ysWbL7WfG/9o2kHbsP3BKmUdkHTFa/X 6ERA== X-Gm-Message-State: AOAM533q8qD2ZFYogXUhJwmsZ0yLZReR1NO9XCU9mBqqk3+UPizDd6j7 4+7rhFt5eRiA2T2eMx0MuHwaaEL0KwB/2A== X-Google-Smtp-Source: ABdhPJx4sd5L0cvzuIVSb7627iCBgoDeyHtUFqg0IqySkbmRO7aYmSXCkC6/RXGsH5e6WS+ThgATiw== X-Received: by 2002:a1c:4b19:: with SMTP id y25mr21641864wma.91.1618838248772; Mon, 19 Apr 2021 06:17:28 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:15:5363:8f56:4f84:754]) by smtp.gmail.com with ESMTPSA id t6sm22335428wrx.38.2021.04.19.06.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 06:17:28 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 19 Apr 2021 14:17:14 +0100 Message-Id: <20210419131715.256802-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210419131715.256802-1-naush@raspberrypi.com> References: <20210419131715.256802-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/4] ipa: raspberrypi: Add 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 move all key/value pairs between a source and destination metadata object. Once complete, the source Metadata object will be empty. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/controller/metadata.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 319f2320fc70..1d3e941b3e52 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -75,6 +75,18 @@ public: return *this; } + void Merge(Metadata &other) + { + std::lock_guard lock(mutex_); + std::lock_guard other_lock(other.mutex_); + + for (auto const &kv: other.data_) + data_[kv.first] = std::move(kv.second); + + /* Render the other object as empty now! */ + other.data_.clear(); + } + template T *GetLocked(std::string const &tag) { From patchwork Mon Apr 19 13:17: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: 12000 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 2CE58BD812 for ; Mon, 19 Apr 2021 13:17:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C95CE68840; Mon, 19 Apr 2021 15:17:32 +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="cbwyswM8"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C5E868830 for ; Mon, 19 Apr 2021 15:17:30 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id f195-20020a1c1fcc0000b029012eb88126d7so8070359wmf.3 for ; Mon, 19 Apr 2021 06:17:30 -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=uhakufSYimFzXE2ktJnS7KEDy6j7582V8I7AiynSico=; b=cbwyswM8jU+xVUbqNU5W0VoCEBViuubX0Tjl/HZBd+mxsEfJulIGGI1hCJenYLezLO fNaXWcC2aLScOulKV+NRnpaKXgUv+uQUIc5NAnoE0i/BEuQ0xl1mMQGVmeSmK5xb7Smv o6dz5+CugVOv1TY20X25b2BqefKWbgx1y2iugXtD5SckHhZ8GtNThcPXU9IAiA0R2R+0 Ys8s4vULSvIsyR+8ti2VAikiNT79qwRtO4a72okWuYNVajYVs72uGteTEuyAj/kCIpyx lN8IkY1CWxOZrO1DE9NX/mP35EHXT98ei0oVLhC1NNS4t6ePG5lP+F25d6tziK+1UixE WP6g== 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=uhakufSYimFzXE2ktJnS7KEDy6j7582V8I7AiynSico=; b=aJkcuEHr40waIiCUcZFr8zTvZ9qnpqQVuv6EWvzAL7jvq4aCZih1g5C2xNzX08lv7g CtTwmv8i4yjacDG4NqwxO1E9ua3mbk1WeRzQ258jc09hjsPYstJS+dfWxLQEISk6R5pF LMEakzgzGDlSn0HHim8XxGLmrs8svc4txWJZ09jJfVaHuOW7uhzeclNLNKa8UWk0nIzO eoGj4ls7LUz3c2NqZkzOempBABVJkaMK9rJxuVsHkeoma0sQnYLL2UxdlwcFJAAtmF0j siFBIgK2zZARdEA8qMWnSFp44icoksTHgJN8+AxaRKai93PSs1yotYyWVzvMQvnNSVXg RMmw== X-Gm-Message-State: AOAM531NnVjZ9ViVI/uFStxW+koJZgJ+fcv1IwHKms6lSKQ9A/gZcSfx +c4Rpz8zuO1zlrQIMGhYxOX6PZ9np9GXag== X-Google-Smtp-Source: ABdhPJzr32JVK95455kG6YIuSmy68FxPvP5xi3VmyRb/iOKRWFmhTIZy0w/RTS/1P1+sqex7iaaqwg== X-Received: by 2002:a1c:80cd:: with SMTP id b196mr21733366wmd.30.1618838249707; Mon, 19 Apr 2021 06:17:29 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:15:5363:8f56:4f84:754]) by smtp.gmail.com with ESMTPSA id t6sm22335428wrx.38.2021.04.19.06.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 06:17:29 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 19 Apr 2021 14:17:15 +0100 Message-Id: <20210419131715.256802-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210419131715.256802-1-naush@raspberrypi.com> References: <20210419131715.256802-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 | 50 +++++++++++++++++-- .../pipeline/raspberrypi/raspberrypi.cpp | 5 ++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index f6d1ab16a290..eac1cf8cfe44 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,32 @@ 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. 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 merging the current frame's metadata into the + * previous frame's metadata object, and then moving the latter + * into the former. + */ + lastMetadata.Merge(rpiMetadata_); + rpiMetadata_ = std::move(lastMetadata); + 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);