From patchwork Tue Nov 23 12:39:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14709 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 1F89EBF415 for ; Tue, 23 Nov 2021 12:39:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C972460230; Tue, 23 Nov 2021 13:39:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gy1wSt4b"; dkim-atps=neutral Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 58D4E60121 for ; Tue, 23 Nov 2021 13:39:08 +0100 (CET) Received: by mail-pg1-x52e.google.com with SMTP id l190so7644681pge.7 for ; Tue, 23 Nov 2021 04:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8v+u3e3qxxMvRsqtoHhaCV8i88G5oSYNJK31y0Kurts=; b=gy1wSt4bRvrSSw20XwwLvuOtyIEy55tC8NOtBSANWsKA4HyyfHW8vQLxpbCXWA46zd mOAbQnh4HheIqTv5QhN/XxCYwq3cx5cXrbTia9O5WLSp8Dy/8BgVOTTlTgM98o++lHrY 5Ln94Q5ug4k7rfr7YExCDBPx7SY3UAqjDjLHk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8v+u3e3qxxMvRsqtoHhaCV8i88G5oSYNJK31y0Kurts=; b=gb3+TpxbpjjfkLSvepbjDIouBsfJtrDhWsEK7A+fGpBDhplGAvz6atunw96rq5O0PY bTrp9U5BF97u95P0DayJeySyrXCQMdkXGGZrC07ZKr12H/RjMi0Boj5p6qs1Ce1H1f1l +UPTi/LmmkXzzHPG40NiEq0lEcFIUOA4d3BQwCRaAG4QCGGBV0zbWLu6pp11i/z7Oy71 yvktcXqvBA/r2hjQJ4nDNDlTjyKmZeOj6CnCz0T8o1dfHsmluuzWpE6hegAPwNQllQZx BVAvF5Qtn9tzyXEq4EIABVwUtEl1Wq0CIMyA9/T5tp7WLrZocCfsmdcQt20/c18dTq/e 9m+w== X-Gm-Message-State: AOAM533KOpc2tJZnxAUnmuqfzHIwNhYKTbVLEJCCPkWhG3R7XmOp7eFy IAhWbUKL0TCQGNDR0WaOIrSBzmQaA1ayog== X-Google-Smtp-Source: ABdhPJyZqpoXhhHFSyfXU6ViBsQZktedfW+MiQ3oOBfBbfdjC37NKjtMs6HBb4pAT4lZqeHHJw6wDQ== X-Received: by 2002:a05:6a00:216f:b0:49f:dcb7:2bf2 with SMTP id r15-20020a056a00216f00b0049fdcb72bf2mr4652228pff.19.1637671146507; Tue, 23 Nov 2021 04:39:06 -0800 (PST) Received: from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199]) by smtp.gmail.com with UTF8SMTPSA id ne7sm1129281pjb.36.2021.11.23.04.39.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:39:06 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 20:39:01 +0800 Message-Id: <20211123123901.3199595-1-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog MIME-Version: 1.0 Subject: [libcamera-devel] [IPU3-IPA PATCH v4] ipu3: Apply auto focus and send lens controls to pipeline handler 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" Apply auto focus and send lens controls to pipeline handler. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- aiq/aiq.cpp | 3 +-- aiq/aiq.h | 4 +--- aiq/aiq_input_parameters.cpp | 2 +- ipu3.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/aiq/aiq.cpp b/aiq/aiq.cpp index 24c61cb..52a9c07 100644 --- a/aiq/aiq.cpp +++ b/aiq/aiq.cpp @@ -138,8 +138,7 @@ int AIQ::setStatistics(unsigned int frame, * might run asycnronously, or after receipt of statistics, with the filling * of the parameter buffer being the only part handled when called for. */ -int AIQ::run2a(unsigned int frame, AiqInputParameters ¶ms, - AiqResults &results) +int AIQ::run2a(unsigned int frame, AiqInputParameters ¶ms, AiqResults &results) { (void)frame; diff --git a/aiq/aiq.h b/aiq/aiq.h index fcd02d2..49eee2d 100644 --- a/aiq/aiq.h +++ b/aiq/aiq.h @@ -39,9 +39,7 @@ public: int setStatistics(unsigned int frame, int64_t timestamp, AiqResults &results, const ipu3_uapi_stats_3a *stats); - - int run2a(unsigned int frame, AiqInputParameters ¶ms, - AiqResults &results); + int run2a(unsigned int frame, AiqInputParameters ¶ms, AiqResults &results); private: std::string decodeError(ia_err err); diff --git a/aiq/aiq_input_parameters.cpp b/aiq/aiq_input_parameters.cpp index 8f60d14..7a6a1fa 100644 --- a/aiq/aiq_input_parameters.cpp +++ b/aiq/aiq_input_parameters.cpp @@ -166,7 +166,7 @@ void AiqInputParameters::setAeAwbAfDefaults() ia_aiq_af_range_normal, ia_aiq_af_metering_mode_auto, ia_aiq_flash_mode_off, - NULL, NULL, false + &focusRect, &manualFocusParams, false }; /* GBCE Params */ diff --git a/ipu3.cpp b/ipu3.cpp index e2b5710..1a14556 100644 --- a/ipu3.cpp +++ b/ipu3.cpp @@ -78,6 +78,10 @@ private: uint32_t gain_; uint32_t minGain_; uint32_t maxGain_; + int32_t lensPosition_; + + /* Intel AF library relies on timestamp to wait for lens movement */ + uint64_t lensMovementStartTime_; /* Intel Library Instances. */ aiq::AIQ aiq_; @@ -259,6 +263,9 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, maxGain_ = itGain->second.max().get(); gain_ = maxGain_; + lensMovementStartTime_ = 0; + lensPosition_ = 0; + int ret; ret = aiq_.configure(); @@ -370,11 +377,27 @@ void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame) resultsHistory_.extendOne(); aiq::AiqResults& latestResults = resultsHistory_.latest(); + /* Todo: Refactor AiqInputParameters interface to set following parameters. */ + aiqInputParams_.afParams.lens_position = lensPosition_; + aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_; + aiq_.run2a(frame, aiqInputParams_, latestResults); exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time; gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global; + /* + * Af algorithm compares the timestamp of start of lens movement and the + * that of the statistics generated to estimate whether next lens + * position should be produced. + * Todo: Use the lens movement start time reported by the pipeline handler. + */ + if (lensPosition_ != latestResults.af()->next_lens_position) { + utils::time_point time = utils::clock::now(); + uint64_t usecs = std::chrono::duration_cast(time.time_since_epoch()).count(); + lensMovementStartTime_ = usecs; + } + lensPosition_ = latestResults.af()->next_lens_position; } void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) @@ -483,6 +506,8 @@ void IPAIPU3::setControls(unsigned int frame) op.sensorControls = sensorCtrls; + op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_); + queueFrameAction.emit(frame, op); }