[{"id":21576,"web_url":"https://patchwork.libcamera.org/comment/21576/","msgid":"<163853910091.3059017.7261445630924535889@Monstersaurus>","date":"2021-12-03T13:45:00","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v5] ipu3: Apply auto focus\n\tand send lens controls to pipeline handler","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Han-Lin,\n\nQuoting Han-Lin Chen (2021-11-26 11:30:27)\n> Apply auto focus and send lens controls to pipeline handler.\n> \n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\nWith the corresponding interface changes now merged in libcamera, I've\nmerged this patch too.\n\n--\nKieran\n\n\n> ---\n>  aiq/aiq.cpp                  |  3 +--\n>  aiq/aiq.h                    |  4 +---\n>  aiq/aiq_input_parameters.cpp |  2 +-\n>  ipu3.cpp                     | 25 +++++++++++++++++++++++++\n>  4 files changed, 28 insertions(+), 6 deletions(-)\n> \n> diff --git a/aiq/aiq.cpp b/aiq/aiq.cpp\n> index 24c61cb..52a9c07 100644\n> --- a/aiq/aiq.cpp\n> +++ b/aiq/aiq.cpp\n> @@ -138,8 +138,7 @@ int AIQ::setStatistics(unsigned int frame,\n>   * might run asycnronously, or after receipt of statistics, with the filling\n>   * of the parameter buffer being the only part handled when called for.\n>   */\n> -int AIQ::run2a(unsigned int frame, AiqInputParameters &params,\n> -              AiqResults &results)\n> +int AIQ::run2a(unsigned int frame, AiqInputParameters &params, AiqResults &results)\n>  {\n>         (void)frame;\n>  \n> diff --git a/aiq/aiq.h b/aiq/aiq.h\n> index fcd02d2..49eee2d 100644\n> --- a/aiq/aiq.h\n> +++ b/aiq/aiq.h\n> @@ -39,9 +39,7 @@ public:\n>         int setStatistics(unsigned int frame,\n>                           int64_t timestamp, AiqResults &results,\n>                           const ipu3_uapi_stats_3a *stats);\n> -\n> -       int run2a(unsigned int frame, AiqInputParameters &params,\n> -                 AiqResults &results);\n> +       int run2a(unsigned int frame, AiqInputParameters &params, AiqResults &results);\n>  \n>  private:\n>         std::string decodeError(ia_err err);\n> diff --git a/aiq/aiq_input_parameters.cpp b/aiq/aiq_input_parameters.cpp\n> index 8f60d14..7a6a1fa 100644\n> --- a/aiq/aiq_input_parameters.cpp\n> +++ b/aiq/aiq_input_parameters.cpp\n> @@ -166,7 +166,7 @@ void AiqInputParameters::setAeAwbAfDefaults()\n>                 ia_aiq_af_range_normal,\n>                 ia_aiq_af_metering_mode_auto,\n>                 ia_aiq_flash_mode_off,\n> -               NULL, NULL, false\n> +               &focusRect, &manualFocusParams, false\n>         };\n>  \n>         /* GBCE Params */\n> diff --git a/ipu3.cpp b/ipu3.cpp\n> index e2b5710..6ab86e0 100644\n> --- a/ipu3.cpp\n> +++ b/ipu3.cpp\n> @@ -78,6 +78,10 @@ private:\n>         uint32_t gain_;\n>         uint32_t minGain_;\n>         uint32_t maxGain_;\n> +       int32_t lensPosition_;\n> +\n> +       /* Intel AF library relies on timestamp to wait for lens movement */\n> +       uint64_t lensMovementStartTime_;\n>  \n>         /* Intel Library Instances. */\n>         aiq::AIQ aiq_;\n> @@ -259,6 +263,9 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>         maxGain_ = itGain->second.max().get<int32_t>();\n>         gain_ = maxGain_;\n>  \n> +       lensMovementStartTime_ = 0;\n> +       lensPosition_ = 0;\n> +\n>         int ret;\n>  \n>         ret = aiq_.configure();\n> @@ -370,11 +377,27 @@ void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)\n>         resultsHistory_.extendOne();\n>         aiq::AiqResults& latestResults = resultsHistory_.latest();\n>  \n> +       /* Todo: Refactor AiqInputParameters interface to set following parameters. */\n> +       aiqInputParams_.afParams.lens_position = lensPosition_;\n> +       aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;\n> +\n>         aiq_.run2a(frame, aiqInputParams_, latestResults);\n>  \n>         exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;\n>         gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global;\n>  \n> +       /*\n> +        * Af algorithm compares the timestamp of start of the lens movement and\n> +        * that of the statistics generated to estimate whether next lens\n> +        * position should be produced.\n> +        * \\todo use the lens movement start time reported by the pipeline handler.\n> +        */\n> +       if (lensPosition_ != latestResults.af()->next_lens_position) {\n> +               utils::time_point time = utils::clock::now();\n> +               uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();\n> +               lensMovementStartTime_ = usecs;\n> +       }\n> +       lensPosition_ = latestResults.af()->next_lens_position;\n>  }\n>  \n>  void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n> @@ -483,6 +506,8 @@ void IPAIPU3::setControls(unsigned int frame)\n>  \n>         op.sensorControls = sensorCtrls;\n>  \n> +       op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_);\n> +\n>         queueFrameAction.emit(frame, op);\n>  }\n>  \n> -- \n> 2.34.0.rc2.393.gf8c9666880-goog\n>","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 975C1BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 13:45:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C2F8B60832;\n\tFri,  3 Dec 2021 14:45:05 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C61460725\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 14:45:04 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 05217A59;\n\tFri,  3 Dec 2021 14:45:03 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KviiYMhO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638539104;\n\tbh=IbXcauYPoqxL92HC9k/z+T19pZb3MJBUPUbde0+56HY=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=KviiYMhOrKU+iQ/sBlNDKXumCL3q0mYMYS1e/3XKaBR7G2JblAZ/lkVlzqd4C4yLe\n\tJ26p5L8XbqdDHsTC8t4+G9GnU4SVA+/Gz/UQHVhnyhuVtYDt2Ej4iJEXhtRmG5MGWZ\n\tT1oVk3z1s4VbxfQ99T88NXi/8B1+pLHwS7bg/naY=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211126113027.3280009-1-hanlinchen@chromium.org>","References":"<20211126113027.3280009-1-hanlinchen@chromium.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 03 Dec 2021 13:45:00 +0000","Message-ID":"<163853910091.3059017.7261445630924535889@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v5] ipu3: Apply auto focus\n\tand send lens 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>"}}]