From patchwork Thu Oct 28 10:03:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14393 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 28197BF415 for ; Thu, 28 Oct 2021 10:04:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D32E3600F9; Thu, 28 Oct 2021 12:04:00 +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="DawF9SR1"; dkim-atps=neutral Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C60C600B5 for ; Thu, 28 Oct 2021 12:03:59 +0200 (CEST) Received: by mail-pf1-x42a.google.com with SMTP id b1so1952581pfm.6 for ; Thu, 28 Oct 2021 03:03:59 -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=fhWHJGT3GiHqLhE5ItshH8KqbE/k12uuErESYkJGWwE=; b=DawF9SR1Kv+BOseHJDO6haf90BJE/FdLX7dR9kBtcK3i1Oi2PSi9ouSbTI84yh1MQo mNtq5gPwluaTT2Z7bldvWrrZqMoedU/h06BaV6UVQXdDrcdoGdCAFEyqrizNmSnEVPVS xBpDC7VBmskPc+WbUZuiCxCQ4yopjTN8wNtX8= 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=fhWHJGT3GiHqLhE5ItshH8KqbE/k12uuErESYkJGWwE=; b=cqBKt0bMJ2uvKxi0R2QIIe+C3l3cpUVTqXg5J0Oik1m/I7ViTLESRWbGJBhLxkdvvj QyrQENvJqK9attkyYK4QYj7J2KEbpjL32CCmfEmal8AEX34aAis5SCJ7bUKORcI7I3U/ MZoOuFcaafyICnX5DXv12GR8r0wOpmNt2yqWdHRlwqpBf7DB2oe/tjwwYWj24fErvatW kQs1UomDg+dwwdYJBYFTHE6D0ZhD7icRzmzUNWMwKidwYSK86YErHenCNCqmyMfmOsOj /TmE5uHLf7s2j3IayWk80karbbg2GBnoJpE05zuLavd2M/wA2CeIozHUPqt6HZujrQDG nmtg== X-Gm-Message-State: AOAM533i6hUvchZE3E9tvXTgeILZE8vJFOYUqW5jyKQBWz8trvhQXbJD THtGR5bR678qkPQN0I/B068nfBZleDQCWleU X-Google-Smtp-Source: ABdhPJyp5qEJIh5nARascfiR0RaeU66nsXtfcKsywe2gtwI5pb7PpSJO0JuKxS5p/YMIy5FFxuFWCA== X-Received: by 2002:a05:6a00:2181:b0:44d:c18d:7af9 with SMTP id h1-20020a056a00218100b0044dc18d7af9mr3225357pfi.16.1635415437984; Thu, 28 Oct 2021 03:03:57 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:1bc:52e7:6df5:c7cf]) by smtp.gmail.com with UTF8SMTPSA id n29sm2828130pfv.77.2021.10.28.03.03.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Oct 2021 03:03:57 -0700 (PDT) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 18:03:47 +0800 Message-Id: <20211028100349.1098545-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211028100349.1098545-1-hanlinchen@chromium.org> References: <20211028100349.1098545-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: , Cc: Han-Lin Chen 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 +- ipu3.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 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/ipu3.cpp b/ipu3.cpp index b7de901..45330ca 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 start and the + * that of the statistics generated to estimate whether next lens positon + * should be produced. + * Todo: Uses 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); }