{"id":14423,"url":"https://patchwork.libcamera.org/api/patches/14423/?format=json","web_url":"https://patchwork.libcamera.org/patch/14423/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211029120001.2469018-4-hanlinchen@chromium.org>","date":"2021-10-29T11:59:59","name":"[libcamera-devel,v2,4/6] ipu3: Apply auto focus and send lens controls to pipeline handler","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"5966235189f50a3585c4affeaefd81aa1d126e84","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/people/98/?format=json","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14423/mbox/","series":[{"id":2681,"url":"https://patchwork.libcamera.org/api/series/2681/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2681","date":"2021-10-29T11:59:56","name":"[libcamera-devel,v2,1/6] ipu3: Use ia_aiq_frame_use_preview as default mode for AIQ","version":2,"mbox":"https://patchwork.libcamera.org/series/2681/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14423/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14423/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D4655BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Oct 2021 12:00:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8E063600BD;\n\tFri, 29 Oct 2021 14:00:21 +0200 (CEST)","from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com\n\t[IPv6:2607:f8b0:4864:20::102e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 35DB1600B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Oct 2021 14:00:18 +0200 (CEST)","by mail-pj1-x102e.google.com with SMTP id gn3so7095581pjb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Oct 2021 05:00:18 -0700 (PDT)","from localhost ([2401:fa00:1:10:35fe:d53b:684:b538])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\tk5sm5839262pjd.46.2021.10.29.05.00.10\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 29 Oct 2021 05:00:11 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"ScBQg3df\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=imlPZU3kTuDJRGvSnEYlWRRbrPPnlI4LZdlpVSqGL0I=;\n\tb=ScBQg3df1GtW6nvWBbwVvrjUI5qESaZd1Im3/MxhYCzMccZjEZ1FxiKRgUorx5uBVt\n\tJuciAnNPv6UvRAl5ytopQoVnN8vosT+zP6ym7C6JRuNJJ5zTAiRmZ3K0UGJtl3p8dFkD\n\tGT4QBBPqgZKHI1lZSiUswpjGXi8N4Pd8A7cmI=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=imlPZU3kTuDJRGvSnEYlWRRbrPPnlI4LZdlpVSqGL0I=;\n\tb=4QOsnleylTyzdKzY53bW1urLu0k7ebOZt9b+6Xs1Tj8Tv0uts2Y9e28xmGOZ4P2Jo8\n\tFFo2iCMEU9HfAc66H8PvMEseexoIbGpiNMXEdEpYBWUQMgJIejwCjsjMPCW+Y16NiM6e\n\t/9TSjgCF/5stVJHgOq9BiRuBrHn97VjMe3bzZsX17rWjXgr8UoyXBXM0ZWmCDZfFHNOp\n\tpkDvnVIGIAunrFKaMXkR8/uD3MRrdevBHL4EZXqwKJc3lUL8nPwe7aBXiPfq5GyTQ2pE\n\tdPHqvIWMhNcfERKkni2685aRUP/qi60R1Dsl87DR1hF7CR7IYOyXu7YA5wrCVig78hnY\n\t+Luw==","X-Gm-Message-State":"AOAM532zxODO0vZuf2ePziyEjrBDFhd65ypfG50VOoMmZEcGSwVY3+Nq\n\tRoC244jQCS3C5t/R60lnCW5mnDxfC/1C58Ve","X-Google-Smtp-Source":"ABdhPJzSv7T97Vpr0qcjZL/cIQ1XR3uOfQIf2Iy8csRAtcUcbGZuGZLuwzCO8A0gp37LgUazAQAi5g==","X-Received":"by 2002:a17:90a:5992:: with SMTP id\n\tl18mr19035730pji.127.1635508811314; \n\tFri, 29 Oct 2021 05:00:11 -0700 (PDT)","From":"Han-Lin Chen <hanlinchen@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 4/6] ipu3: Apply auto focus and send\n\tlens controls to pipeline handler","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Apply auto focus and send lens controls to pipeline handler.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n---\n aiq/aiq.cpp                  |  5 ++++-\n aiq/aiq.h                    |  2 +-\n aiq/aiq_input_parameters.cpp |  2 +-\n ipu3.cpp                     | 27 ++++++++++++++++++++++++++-\n 4 files changed, 32 insertions(+), 4 deletions(-)","diff":"diff --git a/aiq/aiq.cpp b/aiq/aiq.cpp\nindex 24c61cb..9c7f9d6 100644\n--- a/aiq/aiq.cpp\n+++ b/aiq/aiq.cpp\n@@ -139,7 +139,7 @@ int AIQ::setStatistics(unsigned int frame,\n  * of the parameter buffer being the only part handled when called for.\n  */\n int AIQ::run2a(unsigned int frame, AiqInputParameters &params,\n-\t       AiqResults &results)\n+\t             AiqResults &results, int lensPosition, int64_t lensMovementStartTime)\n {\n \t(void)frame;\n \n@@ -157,6 +157,9 @@ int AIQ::run2a(unsigned int frame, AiqInputParameters &params,\n \tparams.saParams.awb_results = results.awb();\n \tshadingAdapterRun(params.saParams, results);\n \n+\tparams.afParams.lens_position = lensPosition;\n+\tparams.afParams.lens_movement_start_timestamp = lensMovementStartTime;\n+\n \tafRun(params.afParams, results);\n \n \treturn 0;\ndiff --git a/aiq/aiq.h b/aiq/aiq.h\nindex fcd02d2..4f5f868 100644\n--- a/aiq/aiq.h\n+++ b/aiq/aiq.h\n@@ -41,7 +41,7 @@ public:\n \t\t\t  const ipu3_uapi_stats_3a *stats);\n \n \tint run2a(unsigned int frame, AiqInputParameters &params,\n-\t\t  AiqResults &results);\n+\t          AiqResults &results, int lensPosition, int64_t lensMovementStartTime);\n \n private:\n \tstd::string decodeError(ia_err err);\ndiff --git a/aiq/aiq_input_parameters.cpp b/aiq/aiq_input_parameters.cpp\nindex 46553a6..5dd2f6c 100644\n--- a/aiq/aiq_input_parameters.cpp\n+++ b/aiq/aiq_input_parameters.cpp\n@@ -166,7 +166,7 @@ void AiqInputParameters::setAeAwbAfDefaults()\n \t\tia_aiq_af_range_normal,\n \t\tia_aiq_af_metering_mode_auto,\n \t\tia_aiq_flash_mode_off,\n-\t\tNULL, NULL, false\n+\t\t&focusRect, &manualFocusParams, false\n \t};\n \n \t/* GBCE Params */\ndiff --git a/ipu3.cpp b/ipu3.cpp\nindex f463805..c2dc754 100644\n--- a/ipu3.cpp\n+++ b/ipu3.cpp\n@@ -77,6 +77,10 @@ private:\n \tuint32_t gain_;\n \tuint32_t minGain_;\n \tuint32_t maxGain_;\n+\tint32_t lensPosition_;\n+\n+\t/* Intel AF library relies on timestamp to wait for lens movement */\n+\tuint64_t lensMovementStartTime_;\n \n \t/* Intel Library Instances. */\n \taiq::AIQ aiq_;\n@@ -258,6 +262,9 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \tmaxGain_ = itGain->second.max().get<int32_t>();\n \tgain_ = maxGain_;\n \n+\tlensMovementStartTime_ = 0;\n+\tlensPosition_ = 0;\n+\n \tint ret;\n \n \tret = aiq_.configure();\n@@ -381,7 +388,7 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n \t*/\n \n \t/* Run algorithms into/using this context structure */\n-\taiq_.run2a(frame, aiqInputParams_, results_);\n+\taiq_.run2a(frame, aiqInputParams_, results_, lensPosition_, lensMovementStartTime_);\n \n \taic_.updateRuntimeParams(results_);\n \taic_.run(params);\n@@ -389,6 +396,19 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n \texposure_ = results_.ae()->exposures[0].sensor_exposure->coarse_integration_time;\n \tgain_ = results_.ae()->exposures[0].sensor_exposure->analog_gain_code_global;\n \n+\t/*\n+\t * Af algorithm compares the timestamp of start of lens movement and the\n+\t * that of the statistics generated to estimate whether next lens\n+\t * positon should be produced.\n+\t * Todo: Use the lens movement start time reported by the pipeline handler.\n+\t */\n+\tif (lensPosition_ != results_.af()->next_lens_position) {\n+\t\tutils::time_point time = utils::clock::now();\n+\t\tuint64_t msecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();\n+\t\tlensMovementStartTime_ = msecs;\n+\t}\n+\tlensPosition_ = results_.af()->next_lens_position;\n+\n \tresultsHistory_.Push(results_);\n \n \tsetControls(frame);\n@@ -472,6 +492,11 @@ void IPAIPU3::setControls(unsigned int frame)\n \n \top.sensorControls = sensorCtrls;\n \n+\tControlList lensCtrls;\n+\tlensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_);\n+\n+\top.lensControls = lensCtrls;\n+\n \tqueueFrameAction.emit(frame, op);\n }\n \n","prefixes":["libcamera-devel","v2","4/6"]}