From patchwork Fri Oct 29 11:59:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14423 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 D4655BDB1C for ; Fri, 29 Oct 2021 12:00:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E063600BD; Fri, 29 Oct 2021 14:00:21 +0200 (CEST) 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="ScBQg3df"; dkim-atps=neutral Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 35DB1600B8 for ; Fri, 29 Oct 2021 14:00:18 +0200 (CEST) Received: by mail-pj1-x102e.google.com with SMTP id gn3so7095581pjb.0 for ; Fri, 29 Oct 2021 05:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=imlPZU3kTuDJRGvSnEYlWRRbrPPnlI4LZdlpVSqGL0I=; b=ScBQg3df1GtW6nvWBbwVvrjUI5qESaZd1Im3/MxhYCzMccZjEZ1FxiKRgUorx5uBVt JuciAnNPv6UvRAl5ytopQoVnN8vosT+zP6ym7C6JRuNJJ5zTAiRmZ3K0UGJtl3p8dFkD GT4QBBPqgZKHI1lZSiUswpjGXi8N4Pd8A7cmI= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=imlPZU3kTuDJRGvSnEYlWRRbrPPnlI4LZdlpVSqGL0I=; b=4QOsnleylTyzdKzY53bW1urLu0k7ebOZt9b+6Xs1Tj8Tv0uts2Y9e28xmGOZ4P2Jo8 FFo2iCMEU9HfAc66H8PvMEseexoIbGpiNMXEdEpYBWUQMgJIejwCjsjMPCW+Y16NiM6e /9TSjgCF/5stVJHgOq9BiRuBrHn97VjMe3bzZsX17rWjXgr8UoyXBXM0ZWmCDZfFHNOp pkDvnVIGIAunrFKaMXkR8/uD3MRrdevBHL4EZXqwKJc3lUL8nPwe7aBXiPfq5GyTQ2pE dPHqvIWMhNcfERKkni2685aRUP/qi60R1Dsl87DR1hF7CR7IYOyXu7YA5wrCVig78hnY +Luw== X-Gm-Message-State: AOAM532zxODO0vZuf2ePziyEjrBDFhd65ypfG50VOoMmZEcGSwVY3+Nq RoC244jQCS3C5t/R60lnCW5mnDxfC/1C58Ve X-Google-Smtp-Source: ABdhPJzSv7T97Vpr0qcjZL/cIQ1XR3uOfQIf2Iy8csRAtcUcbGZuGZLuwzCO8A0gp37LgUazAQAi5g== X-Received: by 2002:a17:90a:5992:: with SMTP id l18mr19035730pji.127.1635508811314; Fri, 29 Oct 2021 05:00:11 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:35fe:d53b:684:b538]) by smtp.gmail.com with UTF8SMTPSA id k5sm5839262pjd.46.2021.10.29.05.00.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Oct 2021 05:00:11 -0700 (PDT) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 29 Oct 2021 19:59:59 +0800 Message-Id: <20211029120001.2469018-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211029120001.2469018-1-hanlinchen@chromium.org> References: <20211029120001.2469018-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/6] 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 --- aiq/aiq.cpp | 5 ++++- aiq/aiq.h | 2 +- aiq/aiq_input_parameters.cpp | 2 +- ipu3.cpp | 27 ++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/aiq/aiq.cpp b/aiq/aiq.cpp index 24c61cb..9c7f9d6 100644 --- a/aiq/aiq.cpp +++ b/aiq/aiq.cpp @@ -139,7 +139,7 @@ int AIQ::setStatistics(unsigned int frame, * of the parameter buffer being the only part handled when called for. */ int AIQ::run2a(unsigned int frame, AiqInputParameters ¶ms, - AiqResults &results) + AiqResults &results, int lensPosition, int64_t lensMovementStartTime) { (void)frame; @@ -157,6 +157,9 @@ int AIQ::run2a(unsigned int frame, AiqInputParameters ¶ms, params.saParams.awb_results = results.awb(); shadingAdapterRun(params.saParams, results); + params.afParams.lens_position = lensPosition; + params.afParams.lens_movement_start_timestamp = lensMovementStartTime; + afRun(params.afParams, results); return 0; diff --git a/aiq/aiq.h b/aiq/aiq.h index fcd02d2..4f5f868 100644 --- a/aiq/aiq.h +++ b/aiq/aiq.h @@ -41,7 +41,7 @@ public: const ipu3_uapi_stats_3a *stats); int run2a(unsigned int frame, AiqInputParameters ¶ms, - AiqResults &results); + AiqResults &results, int lensPosition, int64_t lensMovementStartTime); private: std::string decodeError(ia_err err); diff --git a/aiq/aiq_input_parameters.cpp b/aiq/aiq_input_parameters.cpp index 46553a6..5dd2f6c 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 f463805..c2dc754 100644 --- a/ipu3.cpp +++ b/ipu3.cpp @@ -77,6 +77,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_; @@ -258,6 +262,9 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, maxGain_ = itGain->second.max().get(); gain_ = maxGain_; + lensMovementStartTime_ = 0; + lensPosition_ = 0; + int ret; ret = aiq_.configure(); @@ -381,7 +388,7 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) */ /* Run algorithms into/using this context structure */ - aiq_.run2a(frame, aiqInputParams_, results_); + aiq_.run2a(frame, aiqInputParams_, results_, lensPosition_, lensMovementStartTime_); aic_.updateRuntimeParams(results_); aic_.run(params); @@ -389,6 +396,19 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) exposure_ = results_.ae()->exposures[0].sensor_exposure->coarse_integration_time; gain_ = results_.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 + * positon should be produced. + * Todo: Use the lens movement start time reported by the pipeline handler. + */ + if (lensPosition_ != results_.af()->next_lens_position) { + utils::time_point time = utils::clock::now(); + uint64_t msecs = std::chrono::duration_cast(time.time_since_epoch()).count(); + lensMovementStartTime_ = msecs; + } + lensPosition_ = results_.af()->next_lens_position; + resultsHistory_.Push(results_); setControls(frame); @@ -472,6 +492,11 @@ void IPAIPU3::setControls(unsigned int frame) op.sensorControls = sensorCtrls; + ControlList lensCtrls; + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_); + + op.lensControls = lensCtrls; + queueFrameAction.emit(frame, op); }