[{"id":21129,"web_url":"https://patchwork.libcamera.org/comment/21129/","msgid":"<163767419585.3059017.8611573233763653702@Monstersaurus>","date":"2021-11-23T13:29:55","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v4] 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-23 12:39:01)\n> Apply auto focus and send lens controls to pipeline handler.\n> \n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\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..1a14556 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 lens movement and the\n\ns/ the//\n\nit reads as \"start of the lens movement and the that of the\" currently.\n                                            ^^^\n\nThat could easily be fixed while applying later though.\n\nIntegration held until we get the lens interface updated of course.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\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 932FBBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Nov 2021 13:29:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 47F696022F;\n\tTue, 23 Nov 2021 14:29:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 283C260121\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Nov 2021 14:29:58 +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 D35C1993;\n\tTue, 23 Nov 2021 14:29:57 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Lpk72BRQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637674197;\n\tbh=pDb4BkcOM4yGXlOOxhvF6gZlJFEeTBhLN297rpQXS2M=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=Lpk72BRQRPmk9hXIUZS042XMF+TWuVjZzqF6mayl/4/6hIITDLx2Zd3mnM9B/slXK\n\tBs9k3UhphPKoeBL2r3qKtU1fuS/jmt/bjxnEvA2cMEZ05Z7YKKNQEiQPfd9l+cT2+/\n\tf7832pSI6eFxoxfu0shT8I3yWnY587S/6i19vDb8=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211123123901.3199595-1-hanlinchen@chromium.org>","References":"<20211123123901.3199595-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":"Tue, 23 Nov 2021 13:29:55 +0000","Message-ID":"<163767419585.3059017.8611573233763653702@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v4] 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>"}},{"id":21131,"web_url":"https://patchwork.libcamera.org/comment/21131/","msgid":"<5ec350ec-73f2-2464-02a5-7bf1202716df@ideasonboard.com>","date":"2021-11-23T13:38:30","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v4] ipu3: Apply auto focus\n\tand send lens controls to pipeline handler","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hello,\n\nOn 11/23/21 6:09 PM, Han-Lin Chen wrote:\n> Apply auto focus and send lens controls to pipeline handler.\n\n\nfeels as if I have reviewed this patch before as part of bigger series\n\n>\n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\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> -\t       AiqResults &results)\n> +int AIQ::run2a(unsigned int frame, AiqInputParameters &params, AiqResults &results)\n>   {\n>   \t(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>   \tint setStatistics(unsigned int frame,\n>   \t\t\t  int64_t timestamp, AiqResults &results,\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> +\tint run2a(unsigned int frame, AiqInputParameters &params, AiqResults &results);\n>   \n>   private:\n>   \tstd::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>   \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 */\n> diff --git a/ipu3.cpp b/ipu3.cpp\n> index e2b5710..1a14556 100644\n> --- a/ipu3.cpp\n> +++ b/ipu3.cpp\n> @@ -78,6 +78,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> @@ -259,6 +263,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> @@ -370,11 +377,27 @@ void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame)\n>   \tresultsHistory_.extendOne();\n>   \taiq::AiqResults& latestResults = resultsHistory_.latest();\n>   \n> +\t/* Todo: Refactor AiqInputParameters interface to set following parameters. */\n\n\nYep, this should work for now, already can be made \\todo\n\n> +\taiqInputParams_.afParams.lens_position = lensPosition_;\n> +\taiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_;\n> +\n>   \taiq_.run2a(frame, aiqInputParams_, latestResults);\n>   \n>   \texposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time;\n>   \tgain_ = latestResults.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 * position should be produced.\n> +\t * Todo: Use the lens movement start time reported by the pipeline handler.\n\n\\todo here as well.. minors..\n\n> +\t */\n> +\tif (lensPosition_ != latestResults.af()->next_lens_position) {\n> +\t\tutils::time_point time = utils::clock::now();\n> +\t\tuint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();\n> +\t\tlensMovementStartTime_ = usecs;\n> +\t}\n> +\tlensPosition_ = 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>   \top.sensorControls = sensorCtrls;\n>   \n> +\top.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_);\n\n\nseems good to me,\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n\n> +\n>   \tqueueFrameAction.emit(frame, op);\n>   }\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 969FEBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Nov 2021 13:38:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 478EF60230;\n\tTue, 23 Nov 2021 14:38:37 +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 C377760121\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Nov 2021 14:38:35 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.81])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CA9E9A1B;\n\tTue, 23 Nov 2021 14:38:34 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"mPT4L8kx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637674715;\n\tbh=qHIPOIHGzeuLQcRgfzBJBAgpuMo2z6DsVfF/YLE5vwk=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=mPT4L8kxIpF2u/QBEIVF+HPYh1EpRHQp7jTg6AW6spNKpbaEgwv6WuhkTkArFywW3\n\tVNf/d11SIghHp1Nnzniic0MYmhuVuekspRUa6AwaBGubp+4is05hySVg5EIFwda+Og\n\tgC3+skI3P/IrE61+SVI4SDoMg9MzC9DYHWJTbKik=","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20211123123901.3199595-1-hanlinchen@chromium.org>","From":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<5ec350ec-73f2-2464-02a5-7bf1202716df@ideasonboard.com>","Date":"Tue, 23 Nov 2021 19:08:30 +0530","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.10.2","MIME-Version":"1.0","In-Reply-To":"<20211123123901.3199595-1-hanlinchen@chromium.org>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v4] 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>"}}]