From patchwork Fri Oct 1 10:33:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 14018 X-Patchwork-Delegate: paul.elder@ideasonboard.com 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 D9A14BDC71 for ; Fri, 1 Oct 2021 10:33:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A513B691B8; Fri, 1 Oct 2021 12:33:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rcT5H5DO"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B337C691AA for ; Fri, 1 Oct 2021 12:33:42 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4C37F596; Fri, 1 Oct 2021 12:33:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1633084422; bh=FZZ3rKzhl/HjczljP766ilE3qTZbgXGbn4dkW1CfJuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rcT5H5DOhhTePLH16K5BQtlpfEiiDU1KcVPrUAyXZKlMlcWoCxinHIudxyWW6V1gd L9LMaWR7ReM7TMxTYtVQP6K0khPBWqAX33+Zj8MoMb2srsbKRSRNYbrBgDkMQsJJ27 hwPHTli46+S4EQml69FUozsHpHSnV1WY74SRaUmU= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 1 Oct 2021 19:33:21 +0900 Message-Id: <20211001103325.1077590-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211001103325.1077590-1-paul.elder@ideasonboard.com> References: <20211001103325.1077590-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/7] libcamera: pipeline: raspberrypi: Support the new AE controls 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 support for the new AE controls in the raspberrypi pipeline handler, and in the IPA. Bug: https://bugs.libcamera.org/show_bug.cgi?id=42 Bug: https://bugs.libcamera.org/show_bug.cgi?id=43 Signed-off-by: Paul Elder --- Changes in v2: - fix the rebase error where some uvc stuff was in rasberrypi - i haven't yet taken in the comments to move the new Pause/Resume functions Initial versoin: This is very hacky. I wasn't sure what the best way was to plumb it into the raspberrypi IPA as it was a bit hairy... --- include/libcamera/ipa/raspberrypi.h | 3 +- src/ipa/raspberrypi/controller/rpi/agc.cpp | 18 +++++++++- src/ipa/raspberrypi/controller/rpi/agc.hpp | 5 +++ src/ipa/raspberrypi/raspberrypi.cpp | 42 +++++++++++++++++----- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h index 521eaecd..363ea038 100644 --- a/include/libcamera/ipa/raspberrypi.h +++ b/include/libcamera/ipa/raspberrypi.h @@ -28,8 +28,9 @@ namespace RPi { * unsupported control is encountered. */ static const ControlInfoMap Controls({ - { &controls::AeEnable, ControlInfo(false, true) }, + { &controls::ExposureTimeMode, ControlInfo(controls::ExposureTimeModeValues) }, { &controls::ExposureTime, ControlInfo(0, 999999) }, + { &controls::AnalogueGainMode, ControlInfo(controls::AnalogueGainModeValues) }, { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) }, { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) }, { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 289c1fce..b45ea454 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -203,14 +203,30 @@ bool Agc::IsPaused() const } void Agc::Pause() +{ +} + +void Agc::Resume() +{ +} + +void Agc::PauseExposure() { fixed_shutter_ = status_.shutter_time; +} + +void Agc::PauseGain() +{ fixed_analogue_gain_ = status_.analogue_gain; } -void Agc::Resume() +void Agc::ResumeExposure() { fixed_shutter_ = 0s; +} + +void Agc::ResumeGain() +{ fixed_analogue_gain_ = 0; } diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp index 82063636..7ca3ca2f 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp @@ -92,6 +92,11 @@ public: void Prepare(Metadata *image_metadata) override; void Process(StatisticsPtr &stats, Metadata *image_metadata) override; + void PauseExposure(); + void PauseGain(); + void ResumeExposure(); + void ResumeGain(); + private: void updateLockStatus(DeviceStatus const &device_status); AgcConfig config_; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 047123ab..99935515 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -53,6 +53,8 @@ #include "sharpen_algorithm.hpp" #include "sharpen_status.h" +#include "controller/rpi/agc.hpp" + namespace libcamera { using namespace std::literals::chrono_literals; @@ -478,7 +480,10 @@ void IPARPi::reportMetadata() AgcStatus *agcStatus = rpiMetadata_.GetLocked("agc.status"); if (agcStatus) { - libcameraMetadata_.set(controls::AeLocked, agcStatus->locked); + libcameraMetadata_.set(controls::AeState, + agcStatus->locked ? + controls::AeStateConverged : + controls::AeStateSearching); libcameraMetadata_.set(controls::DigitalGain, agcStatus->digital_gain); } @@ -623,20 +628,22 @@ void IPARPi::queueRequest(const ControlList &controls) << " = " << ctrl.second.toString(); switch (ctrl.first) { - case controls::AE_ENABLE: { - RPiController::Algorithm *agc = controller_.GetAlgorithm("agc"); + case controls::EXPOSURE_TIME_MODE: { + RPiController::Algorithm *algo = controller_.GetAlgorithm("agc"); + RPiController::Agc *agc = reinterpret_cast(algo); if (!agc) { LOG(IPARPI, Warning) - << "Could not set AE_ENABLE - no AGC algorithm"; + << "Could not set EXPOSURE_TIME_MODE - no AGC algorithm"; break; } - if (ctrl.second.get() == false) - agc->Pause(); + if (ctrl.second.get() == controls::ExposureTimeModeDisabled) + agc->PauseExposure(); else - agc->Resume(); + agc->ResumeExposure(); - libcameraMetadata_.set(controls::AeEnable, ctrl.second.get()); + libcameraMetadata_.set(controls::ExposureTimeMode, + ctrl.second.get()); break; } @@ -656,6 +663,25 @@ void IPARPi::queueRequest(const ControlList &controls) break; } + case controls::ANALOGUE_GAIN_MODE: { + RPiController::Algorithm *algo = controller_.GetAlgorithm("agc"); + RPiController::Agc *agc = reinterpret_cast(algo); + if (!agc) { + LOG(IPARPI, Warning) + << "Could not set ANALOGUE_GAIN_MODE - no AGC algorithm"; + break; + } + + if (ctrl.second.get() == controls::AnalogueGainModeDisabled) + agc->PauseGain(); + else + agc->ResumeGain(); + + libcameraMetadata_.set(controls::AnalogueGainMode, + ctrl.second.get()); + break; + } + case controls::ANALOGUE_GAIN: { RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.GetAlgorithm("agc"));