From patchwork Mon Jun 13 14:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 16217 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 B25E1BD161 for ; Mon, 13 Jun 2022 14:29:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7C22865651; Mon, 13 Jun 2022 16:29:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655130550; bh=4gOouZ4scIBgUXuj6+zedJHsGvyIrkic8SgL+Nkiv2w=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=C0B4AEnhoBjyu5BjZH4BzRB3mQn1//DG4uPNMJssOiLXg06n9a0sIkG10shVbo8dr /wl66k6aqXr/KJI08pkfas7+7uBkA54E89py1jku7yk2uf+CcSQE3XtwQfF9rz+0Nv 6f4koITEue0aI7gd43m2FjYQKNAL+zOTp7Lkv5qvhvoNwPnxemKJTDJVTljfSJG3/u hzs4OPOi4BkA6iqSl9eUPzz8iCDgJA+oIifYvkf5BuJRxLByXCI4QnzHnEZn/UCmOy BCwBQR9Ip97/TPPORcw9Gr3gupCvfiXhZJrU7TqT4Jw+h3Y2j0tB89U4xDMgPipbNJ umTiNFbVxgtyw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F0166563D for ; Mon, 13 Jun 2022 16:29:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="V0GZrOMW"; dkim-atps=neutral Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:a1c7:c28c:7720:9b30]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A99E305; Mon, 13 Jun 2022 16:29:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655130541; bh=4gOouZ4scIBgUXuj6+zedJHsGvyIrkic8SgL+Nkiv2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V0GZrOMW0Gu0MWTRVK7LRb1rma7z0vbTcidnSR6qOYeZb0jS41BDvcLWQGXQkevwH cHFrYWjxjeFYKI6isZCtFxkJkGBQN2nOUk9vtvcA41HB2xx3AbHQKaEnVCAdjArbUz EBTRBSdsb9O3q80XDxUUyE6DMHnyfz3EkeNkYAY4= To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jun 2022 16:28:50 +0200 Message-Id: <20220613142853.98484-8-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220613142853.98484-1-jeanmichel.hautbois@ideasonboard.com> References: <20220613142853.98484-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/10] ipa: raspberrypi: Introduce AfPause and AfPauseState 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: , X-Patchwork-Original-From: Jean-Michel Hautbois via libcamera-devel From: Jean-Michel Hautbois Reply-To: Jean-Michel Hautbois Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In the continuous mode, the algorithm can be paused and resumed by the user using the AfPause control. Introduce the state machine associated with this call, and populate a specific pause state which will populate the AfPauseState control. Signed-off-by: Jean-Michel Hautbois --- include/libcamera/ipa/raspberrypi.h | 2 ++ src/ipa/raspberrypi/controller/af_algorithm.hpp | 2 ++ src/ipa/raspberrypi/controller/af_status.h | 1 + src/ipa/raspberrypi/controller/iob/af.cpp | 14 +++++++++++++- src/ipa/raspberrypi/controller/iob/af.h | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 15 +++++++++++++++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index 5bc14f4e..a7a15904 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -48,6 +48,8 @@ static const ControlInfoMap Controls({ { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, { &controls::AfMode, ControlInfo(controls::AfModeValues) }, { &controls::AfState, ControlInfo(controls::AfStateValues) }, + { &controls::AfPause, ControlInfo(controls::AfPauseValues) }, + { &controls::AfPauseState, ControlInfo(controls::AfPauseStateValues) }, }, controls::controls); } /* namespace RPi */ diff --git a/src/ipa/raspberrypi/controller/af_algorithm.hpp b/src/ipa/raspberrypi/controller/af_algorithm.hpp index 1e7aaa45..ac34e3b6 100644 --- a/src/ipa/raspberrypi/controller/af_algorithm.hpp +++ b/src/ipa/raspberrypi/controller/af_algorithm.hpp @@ -22,6 +22,8 @@ public: virtual void Trigger() = 0; // cancel a cycle (in auto mode) virtual void Cancel() = 0; + // pause the continuous mode + virtual void Pause(const uint32_t &pause) = 0; // set AF windows virtual void SetWindows(const libcamera::Rectangle &afWindows) = 0; // set AF range diff --git a/src/ipa/raspberrypi/controller/af_status.h b/src/ipa/raspberrypi/controller/af_status.h index 3428d032..aa412ef6 100644 --- a/src/ipa/raspberrypi/controller/af_status.h +++ b/src/ipa/raspberrypi/controller/af_status.h @@ -18,5 +18,6 @@ struct AfStatus { uint32_t lensPosition; libcamera::controls::AfStateEnum state; + libcamera::controls::AfPauseStateEnum pauseState; libcamera::Rectangle windows; }; diff --git a/src/ipa/raspberrypi/controller/iob/af.cpp b/src/ipa/raspberrypi/controller/iob/af.cpp index e09514c4..2efc12f5 100644 --- a/src/ipa/raspberrypi/controller/iob/af.cpp +++ b/src/ipa/raspberrypi/controller/iob/af.cpp @@ -54,6 +54,7 @@ void Af::SetMode(const uint32_t &mode) if (mode != mode_) { LOG(IoBAf, Debug) << "Switched AF mode from " << mode_ << " to " << mode; + status_.pauseState = libcamera::controls::AfPauseStateRunning; mode_ = mode; } } @@ -62,8 +63,15 @@ void Af::Trigger() { } -void Af::Cancel() +void Af::Pause(const uint32_t &pause) { + /* \todo: add the AfPauseDeferred mode */ + if (mode_ == libcamera::controls::AfModeContinuous) { + if (pause == libcamera::controls::AfPauseImmediate) + status_.pauseState = libcamera::controls::AfPauseStatePaused; + else if (pause == libcamera::controls::AfPauseResume) + status_.pauseState = libcamera::controls::AfPauseStateRunning; + } } void Af::SetWindows([[maybe_unused]] const libcamera::Rectangle &afWindows) @@ -199,6 +207,10 @@ void Af::Process(StatisticsPtr &stats, [[maybe_unused]] Metadata *image_metadata currentContrast_ += stats->focus_stats[i].contrast_val[1][1] / stats->focus_stats[i].contrast_val_num[1][1]; + /* If we are in a paused state, we won't process the stats */ + if (status_.pauseState == libcamera::controls::AfPauseStatePaused) + return; + /* Depending on the mode, we may or may not process the stats */ if (status_.state == libcamera::controls::AfStateIdle) return; diff --git a/src/ipa/raspberrypi/controller/iob/af.h b/src/ipa/raspberrypi/controller/iob/af.h index 4ed50cfb..c4ab3574 100644 --- a/src/ipa/raspberrypi/controller/iob/af.h +++ b/src/ipa/raspberrypi/controller/iob/af.h @@ -26,6 +26,7 @@ public: void SetMode(const uint32_t &mode) override; void Trigger() override; void Cancel() override; + void Pause(const uint32_t &pause) override; void SetWindows(const libcamera::Rectangle &afWindows) override; void SetRange(const uint32_t &range) override; void setSpeed(const uint32_t &speed) override; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 226388a7..8c6f213f 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -552,6 +552,7 @@ void IPARPi::reportMetadata() AfStatus *afStatus = rpiMetadata_.GetLocked("af.status"); if (afStatus) { libcameraMetadata_.set(controls::AfState, afStatus->state); + libcameraMetadata_.set(controls::AfPauseState, afStatus->pauseState); } } @@ -971,6 +972,20 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::AF_PAUSE: { + RPiController::AfAlgorithm *af = dynamic_cast( + controller_.GetAlgorithm("iob.af")); + if (!af) { + LOG(IPARPI, Warning) + << "Could not set AF_MODE - no AF algorithm"; + break; + } + + af->Pause(ctrl.second.get()); + + break; + } + default: LOG(IPARPI, Warning) << "Ctrl " << controls::controls.at(ctrl.first)->name()