[{"id":20988,"web_url":"https://patchwork.libcamera.org/comment/20988/","msgid":"<163717188046.420308.4146489398405243137@Monstersaurus>","date":"2021-11-17T17:58:00","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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":"Quoting Han-Lin Chen (2021-11-11 10:49:06)\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                     | 26 ++++++++++++++++++++++++++\n>  4 files changed, 29 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 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>                 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 9d07268..f38440d 100644\n> --- a/ipu3.cpp\n> +++ b/ipu3.cpp\n> @@ -77,6 +77,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> @@ -257,6 +261,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> @@ -383,6 +390,10 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\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>         aic_.updateRuntimeParams(latestResults);\n>         aic_.run(params);\n> @@ -390,6 +401,19 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\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> +        * that of the statistics generated to estimate whether next lens\n> +        * positon should be produced.\n\n/positon/position/\n\n> +        * Todo: Use the lens movement start time reported by the pipeline handler.\n\nIs this the time the control is set? or something that's expected to be\nidentified from the VCM?\n\n> +        */\n> +       if (lensPosition_ != latestResults.af()->next_lens_position) {\n> +               utils::time_point time = utils::clock::now();\n> +               uint64_t msecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();\n> +               lensMovementStartTime_ = msecs;\n> +       }\n> +       lensPosition_ = latestResults.af()->next_lens_position;\n> +\n>         setControls(frame);\n>  \n>         IPU3Action op;\n> @@ -473,6 +497,8 @@ void IPAIPU3::setControls(unsigned int frame)\n>  \n>         op.sensorControls = sensorCtrls;\n>  \n> +       op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_);\n> +\n\nThis one is going to need the corresponding update in libcamera of\ncourse.\n\nPerhaps merging the interface change is possible before/while we sort\nout the other parts, as that's distinct and could unblock this patch.\n\nBut when this can compile:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>         queueFrameAction.emit(frame, op);\n>  }\n>  \n> -- \n> 2.34.0.rc1.387.gb447b232ab-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 5A64BBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 17 Nov 2021 17:58:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AE91260376;\n\tWed, 17 Nov 2021 18:58:05 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 12A1160121\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Nov 2021 18:58: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 9DB622CF;\n\tWed, 17 Nov 2021 18:58:03 +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=\"g38TJdMs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637171883;\n\tbh=u93K0jtCWxep4WLesvPMRFWBpvVVSI+2f7LdMdo3qUM=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=g38TJdMsYoA/F3SsPQV4HiLQbVftrnvJaRKRshhbZKARDn6uC65x2Z92P7Nly/3RG\n\tRkVOkR7w/tDs6/H7chYIzqv7gw7o/jLCZxP6eTcbD802xaBqdWz88Rwic2Zbad9N4X\n\tzG4NDvKRJNCb2qXTr2ZEfEMSbOYvR/f0HjRnflCU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211111104908.295992-5-hanlinchen@chromium.org>","References":"<20211111104908.295992-1-hanlinchen@chromium.org>\n\t<20211111104908.295992-5-hanlinchen@chromium.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 17 Nov 2021 17:58:00 +0000","Message-ID":"<163717188046.420308.4146489398405243137@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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":21060,"web_url":"https://patchwork.libcamera.org/comment/21060/","msgid":"<163733977155.1089182.3471272794352498024@Monstersaurus>","date":"2021-11-19T16:36:11","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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":"Quoting Kieran Bingham (2021-11-17 17:58:00)\n> Quoting Han-Lin Chen (2021-11-11 10:49:06)\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                     | 26 ++++++++++++++++++++++++++\n> >  4 files changed, 29 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 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> >                 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 9d07268..f38440d 100644\n> > --- a/ipu3.cpp\n> > +++ b/ipu3.cpp\n> > @@ -77,6 +77,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> > @@ -257,6 +261,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> > @@ -383,6 +390,10 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\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> >         aic_.updateRuntimeParams(latestResults);\n> >         aic_.run(params);\n> > @@ -390,6 +401,19 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\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> > +        * that of the statistics generated to estimate whether next lens\n> > +        * positon should be produced.\n> \n> /positon/position/\n> \n> > +        * Todo: Use the lens movement start time reported by the pipeline handler.\n> \n> Is this the time the control is set? or something that's expected to be\n> identified from the VCM?\n> \n> > +        */\n> > +       if (lensPosition_ != latestResults.af()->next_lens_position) {\n> > +               utils::time_point time = utils::clock::now();\n> > +               uint64_t msecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();\n> > +               lensMovementStartTime_ = msecs;\n\nSmall note here. microseconds is usually referred to as us, (usecs?) ...\nmsecs to me would imply milli-seconds...?\n\nThe defintiion and use are closely grouped here, so it's clear\neitherway, but thought it was worth mentioning here.\n\n\n\n> > +       }\n> > +       lensPosition_ = latestResults.af()->next_lens_position;\n> > +\n> >         setControls(frame);\n> >  \n> >         IPU3Action op;\n> > @@ -473,6 +497,8 @@ void IPAIPU3::setControls(unsigned int frame)\n> >  \n> >         op.sensorControls = sensorCtrls;\n> >  \n> > +       op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_);\n> > +\n> \n> This one is going to need the corresponding update in libcamera of\n> course.\n> \n> Perhaps merging the interface change is possible before/while we sort\n> out the other parts, as that's distinct and could unblock this patch.\n> \n> But when this can compile:\n\nI'll merge this series with the exception of these two commits:\n\n ipu3: Apply auto focus and send lens controls to pipeline handler\n ipu3: Run AIQ for the first frame to avoid blanking\n\nAs they require the lens updates on the libcamera side.  \"Run AIQ...\"\ndoesn't, but it seems to need to be on top of the other patch, and I\ncan't cherry-pick it cleanly, (which I was able to do with ipu3: Use\ngbce and tone mapping from the tuning files) so I'll leave it out for\nnow.\n\nYour patch queue should be easier to handle with those down anyway.\n\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> >         queueFrameAction.emit(frame, op);\n> >  }\n> >  \n> > -- \n> > 2.34.0.rc1.387.gb447b232ab-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 15C52BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Nov 2021 16:36:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E23D60371;\n\tFri, 19 Nov 2021 17:36:16 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E3FBD600B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 17:36:14 +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 779BD1C19;\n\tFri, 19 Nov 2021 17:36:14 +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=\"Pv5LLbte\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637339774;\n\tbh=nC1pJZvptCYdPYB+qrbKp7UA6tBiR04f5toPqqqaIHw=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=Pv5LLbteWbqmwSLJPw4tMjRFh+hKVoFd9SR7WvKfgCgW5/EKB8PWMyYXzMM9g3lEh\n\th/kZVuzeLAg2/+BWF2DquOGFF2Jrb5+frRbo+Ff23HmB+7Sm0B6vNa+uNEE33Zai38\n\t6ujFvaaiaxWqQx/ujA04g6t97PNrmizb7f61XYw4=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<163717188046.420308.4146489398405243137@Monstersaurus>","References":"<20211111104908.295992-1-hanlinchen@chromium.org>\n\t<20211111104908.295992-5-hanlinchen@chromium.org>\n\t<163717188046.420308.4146489398405243137@Monstersaurus>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 19 Nov 2021 16:36:11 +0000","Message-ID":"<163733977155.1089182.3471272794352498024@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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":21095,"web_url":"https://patchwork.libcamera.org/comment/21095/","msgid":"<163757934510.1089182.16118917808259105642@Monstersaurus>","date":"2021-11-22T11:09:05","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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 Kieran Bingham (2021-11-19 16:36:11)\n> Quoting Kieran Bingham (2021-11-17 17:58:00)\n> > Quoting Han-Lin Chen (2021-11-11 10:49:06)\n> > > Apply auto focus and send lens controls to pipeline handler.\n> > > \n> \n> I'll merge this series with the exception of these two commits:\n> \n>  ipu3: Apply auto focus and send lens controls to pipeline handler\n>  ipu3: Run AIQ for the first frame to avoid blanking\n> \n> As they require the lens updates on the libcamera side.  \"Run AIQ...\"\n> doesn't, but it seems to need to be on top of the other patch, and I\n> can't cherry-pick it cleanly, (which I was able to do with ipu3: Use\n> gbce and tone mapping from the tuning files) so I'll leave it out for\n> now.\n> \n> Your patch queue should be easier to handle with those down anyway.\n\nI've merged this series with the exception of:\n  ipu3: Apply auto focus and send lens controls to pipeline handler\n\nThat needs the corresponding updates in libcamera to be accepted first.\nThe AIQ was easy to fix the conflicts when cherry-picking, and has been\ntested on the Soraka with the latest libcamera master branch.\n\n--\nKieran","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 85490BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Nov 2021 11:09:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9BE3F6036F;\n\tMon, 22 Nov 2021 12:09:10 +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 7985660230\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Nov 2021 12:09:08 +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 161F114C3;\n\tMon, 22 Nov 2021 12:09:08 +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=\"TPC3sW/g\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637579348;\n\tbh=OVac8QbKKahQvfQFMoOJ3ba2HzCTeAWPOkNdNapQJNc=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=TPC3sW/giOZY6pMrtqThQ8Elrnn964qXAuQ9d6xfymBEcFXeV9ETWqwPVxv3N7/q4\n\t6q5+ZB7iyPfh4DnWZ/RR9hGJW/T+30R8uDaFs18Ay4mksjoKiRLkaIbHQM3fkOKnHq\n\tmFnIsN23k32DKcC7nr5hwglkNT9RvMg9aTxkwaZw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<163733977155.1089182.3471272794352498024@Monstersaurus>","References":"<20211111104908.295992-1-hanlinchen@chromium.org>\n\t<20211111104908.295992-5-hanlinchen@chromium.org>\n\t<163717188046.420308.4146489398405243137@Monstersaurus>\n\t<163733977155.1089182.3471272794352498024@Monstersaurus>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 22 Nov 2021 11:09:05 +0000","Message-ID":"<163757934510.1089182.16118917808259105642@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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":21127,"web_url":"https://patchwork.libcamera.org/comment/21127/","msgid":"<CAJAuwMkdO9zHXKDTWZ6Yn1GjHZJHHsZJB1s+jkcB6Vt98Y8jdA@mail.gmail.com>","date":"2021-11-23T12:50:34","subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and send lens controls to pipeline handler","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/people/98/","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"content":"Hi Kieran,\nMany thanks for the help.\n\nOn Sat, Nov 20, 2021 at 12:36 AM Kieran Bingham\n<kieran.bingham@ideasonboard.com> wrote:\n>\n> Quoting Kieran Bingham (2021-11-17 17:58:00)\n> > Quoting Han-Lin Chen (2021-11-11 10:49:06)\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                     | 26 ++++++++++++++++++++++++++\n> > >  4 files changed, 29 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 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> > >                 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 9d07268..f38440d 100644\n> > > --- a/ipu3.cpp\n> > > +++ b/ipu3.cpp\n> > > @@ -77,6 +77,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> > > @@ -257,6 +261,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> > > @@ -383,6 +390,10 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\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> > >         aic_.updateRuntimeParams(latestResults);\n> > >         aic_.run(params);\n> > > @@ -390,6 +401,19 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\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> > > +        * that of the statistics generated to estimate whether next lens\n> > > +        * positon should be produced.\n> >\n> > /positon/position/\n> >\n> > > +        * Todo: Use the lens movement start time reported by the pipeline handler.\n> >\n> > Is this the time the control is set? or something that's expected to be\n> > identified from the VCM?\nIt's the time the control is set into the device. I cannot find\nextension of the V4L2 which reports it from the VCM.\n> >\n> > > +        */\n> > > +       if (lensPosition_ != latestResults.af()->next_lens_position) {\n> > > +               utils::time_point time = utils::clock::now();\n> > > +               uint64_t msecs = std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();\n> > > +               lensMovementStartTime_ = msecs;\n>\n> Small note here. microseconds is usually referred to as us, (usecs?) ...\n> msecs to me would imply milli-seconds...?\nYou're right. I was always confused with the time abbreviations. :-|\n>\n> The defintiion and use are closely grouped here, so it's clear\n> eitherway, but thought it was worth mentioning here.\n>\n>\n>\n> > > +       }\n> > > +       lensPosition_ = latestResults.af()->next_lens_position;\n> > > +\n> > >         setControls(frame);\n> > >\n> > >         IPU3Action op;\n> > > @@ -473,6 +497,8 @@ void IPAIPU3::setControls(unsigned int frame)\n> > >\n> > >         op.sensorControls = sensorCtrls;\n> > >\n> > > +       op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_);\n> > > +\n> >\n> > This one is going to need the corresponding update in libcamera of\n> > course.\n> >\n> > Perhaps merging the interface change is possible before/while we sort\n> > out the other parts, as that's distinct and could unblock this patch.\n> >\n> > But when this can compile:\n>\n> I'll merge this series with the exception of these two commits:\n>\n>  ipu3: Apply auto focus and send lens controls to pipeline handler\n>  ipu3: Run AIQ for the first frame to avoid blanking\n>\n> As they require the lens updates on the libcamera side.  \"Run AIQ...\"\n> doesn't, but it seems to need to be on top of the other patch, and I\n> can't cherry-pick it cleanly, (which I was able to do with ipu3: Use\n> gbce and tone mapping from the tuning files) so I'll leave it out for\n> now.\n>\n> Your patch queue should be easier to handle with those down anyway.\n>\n>\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > >         queueFrameAction.emit(frame, op);\n> > >  }\n> > >\n> > > --\n> > > 2.34.0.rc1.387.gb447b232ab-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 8FA4BBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Nov 2021 12:50:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B72456033C;\n\tTue, 23 Nov 2021 13:50:47 +0100 (CET)","from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com\n\t[IPv6:2607:f8b0:4864:20::c34])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A53E560121\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Nov 2021 13:50:46 +0100 (CET)","by mail-oo1-xc34.google.com with SMTP id\n\tr18-20020a4a7252000000b002c5f52d1834so7459759ooe.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Nov 2021 04:50:46 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"O5riaHT1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=oc7LRdinNNazmC1MjcOFg4u5CfqLwipLG+RsbOaqTvE=;\n\tb=O5riaHT1/Oz5sUOV35fUmMj1Hg3mgoRUcnWdt8l9mi8Fl/snia08UEynRdeve3UgZc\n\t6fc2ufyv49yZ3VJ4Kxced1DZR7f8FRoh91owtcZ1a1MwuAShQcsG8Gw15GWGU8fLwRAM\n\tjBcCexXCi3zvrc1XMGpgmeZB8WxjZErMH76u0=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=oc7LRdinNNazmC1MjcOFg4u5CfqLwipLG+RsbOaqTvE=;\n\tb=VmwYtf+ygZECEk2Tav7LTGCJK6P5fq+TOJA+pihTyXuYmYfZHfSl3+s56s4/bLumhU\n\tG+z8zVub9ye2gx2W4/3BJcpURS6AJjcd7drTQgpQjGWWWPGwZsjZmplzmdEFnXF9frzO\n\tz932eRAruNfvMsNCTQuAhQ18SBUXznm3dCz9Z25dLngl5owkZXfMRvKSc2ckaYnpbBdI\n\twDoDkqL4JT9c5TI+OYgma/IG1QwlQuJdBPwa5sfyRoL17KU4S6ss/r+5AVR5b75YyQ1d\n\t1GEzi7pQ1Sl00qgHHtOoLB+r9NUdz8kpudaR6PhbOQrm6GgkWGOwmvVitAVRo2QAnBvP\n\tfwVw==","X-Gm-Message-State":"AOAM532FL105TQchYsjRxGkifYHpiDT0EeTTiyYmGihj7lrauvO5gMpP\n\t/U3o9Iign+bea/aSs0TXEZoH2Ew0KCoAqI380S/ybA==","X-Google-Smtp-Source":"ABdhPJwsx8EXzUeCx9royRE+d4BWcapE4SAQJVKsTEew0uK2pgVSRUjkg7rX6TMo2M/EtG/KWd2dKFm0lpiyjs9bb/0=","X-Received":"by 2002:a4a:9406:: with SMTP id h6mr2836834ooi.80.1637671845108; \n\tTue, 23 Nov 2021 04:50:45 -0800 (PST)","MIME-Version":"1.0","References":"<20211111104908.295992-1-hanlinchen@chromium.org>\n\t<20211111104908.295992-5-hanlinchen@chromium.org>\n\t<163717188046.420308.4146489398405243137@Monstersaurus>\n\t<163733977155.1089182.3471272794352498024@Monstersaurus>","In-Reply-To":"<163733977155.1089182.3471272794352498024@Monstersaurus>","From":"Hanlin Chen <hanlinchen@chromium.org>","Date":"Tue, 23 Nov 2021 20:50:34 +0800","Message-ID":"<CAJAuwMkdO9zHXKDTWZ6Yn1GjHZJHHsZJB1s+jkcB6Vt98Y8jdA@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [IPU3-IPA PATCH v3 4/6] ipu3: Apply auto\n\tfocus and 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]