{"id":14392,"url":"https://patchwork.libcamera.org/api/patches/14392/?format=json","web_url":"https://patchwork.libcamera.org/patch/14392/","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":"<20211028100349.1098545-3-hanlinchen@chromium.org>","date":"2021-10-28T10:03:46","name":"[libcamera-devel,3/6] ipu3: Set statistics with the effective AE AiqResults","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"487f5efd72bfbdebf3aea9b8a1037d834c8ac173","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/14392/mbox/","series":[{"id":2673,"url":"https://patchwork.libcamera.org/api/series/2673/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2673","date":"2021-10-28T10:03:44","name":"[libcamera-devel,1/6] ipu3: Use ia_aiq_frame_use_preview as default mode for AIQ","version":1,"mbox":"https://patchwork.libcamera.org/series/2673/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14392/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14392/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 C57E6BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 28 Oct 2021 10:03:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 79BED600C4;\n\tThu, 28 Oct 2021 12:03:58 +0200 (CEST)","from mail-pg1-x541.google.com (mail-pg1-x541.google.com\n\t[IPv6:2607:f8b0:4864:20::541])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 85099600B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Oct 2021 12:03:57 +0200 (CEST)","by mail-pg1-x541.google.com with SMTP id h193so5930243pgc.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Oct 2021 03:03:57 -0700 (PDT)","from localhost ([2401:fa00:1:10:1bc:52e7:6df5:c7cf])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\tb10sm2780427pfi.122.2021.10.28.03.03.55\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tThu, 28 Oct 2021 03:03:55 -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=\"T0CPjW0N\"; 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=lTSTK7FwG3T04+revACHrdm6IhgZuUILZhymSQGcEl8=;\n\tb=T0CPjW0Nfww4D7MpTbYCCUf5LVUnhIdCUJJFPHProfRHlAZ6+B7o1M6JR9HWBeeTTO\n\tLqXyVZLWq9SjeVjqD9VLsd1HMO1XC6ZYlwLHaxu6HRHoCgh5uY6GOZSWJHYitQ9W7X9d\n\tgNYfY3RczquvNOglgx8U3PQU/TllFGqJbtmFQ=","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=lTSTK7FwG3T04+revACHrdm6IhgZuUILZhymSQGcEl8=;\n\tb=bsl/cR9nznqcq3e/yDdfPjfbQ5qCwTDRA2mkfsJBX/nUHvL/Mwd4hat7/bYkThb9C8\n\tOu+m326bBpmrmfJr4E0uRXllN9GMyUrfejuTyQUBxg3dNP8yNUdGw1x8kvVth+sb+85T\n\ttwSxKvi2Quj12XdImQR1HC9+J39iACm+/ZhlQLOhWNHJ0FMxX90ke+kCnjCRa+brN9f9\n\tDNl40IAKUU8kegpaidP7QTjSP3x+3mGcazZhm8ipbLXTLTq9KTEbPfUUYRvXu9u2RUm6\n\tP8Re5RANW+ZpzMCjMiGf2N9nhhylhjXm6okArqzUTWMCQ/7qJ4bqru3JaAlwi/a+cLWb\n\twNOQ==","X-Gm-Message-State":"AOAM533K9u7UWsOg9mbt3B3uqjWgAz82mRzIm+y7b4y91doZkb6F9Qw9\n\t+OXkoaz/y/Wzzm13n3LEK4hCHUxOXrOdquCu","X-Google-Smtp-Source":"ABdhPJwQ+T0RBy2+0iiwhcUCz7MxW53C4qiYj8pKgE7nGKQ8HVmUtpxBXNt7tVK4CDfyK251RCgLGQ==","X-Received":"by 2002:a63:8f5a:: with SMTP id r26mr2487035pgn.50.1635415435956;\n\tThu, 28 Oct 2021 03:03:55 -0700 (PDT)","From":"Han-Lin Chen <hanlinchen@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 28 Oct 2021 18:03:46 +0800","Message-Id":"<20211028100349.1098545-3-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 3/6] ipu3: Set statistics with the\n\teffective AE AiqResults","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":"Han-Lin Chen <hanlinchen@chromium.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Set the statistics with the latest AE AiqResults which has the same\nexposure time and analog gain. The patch reduces the AE haunting during\nthe converging process.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.com>\n---\n aiq/aiq_input_parameters.cpp |  4 +--\n ipu3.cpp                     | 66 ++++++++++++++++++++++++++++++------\n 2 files changed, 57 insertions(+), 13 deletions(-)","diff":"diff --git a/aiq/aiq_input_parameters.cpp b/aiq/aiq_input_parameters.cpp\nindex bc87b31..5dd2f6c 100644\n--- a/aiq/aiq_input_parameters.cpp\n+++ b/aiq/aiq_input_parameters.cpp\n@@ -130,7 +130,7 @@ AiqInputParameters &AiqInputParameters::operator=(const AiqInputParameters &othe\n \n void AiqInputParameters::setAeAwbAfDefaults()\n {\n-\t/*Ae Params */\n+\t/* Ae Params */\n \taeInputParams.num_exposures = NUM_EXPOSURES;\n \taeInputParams.frame_use = ia_aiq_frame_use_preview;\n \taeInputParams.flash_mode = ia_aiq_flash_mode_off;\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 8126e9d..b7de901 100644\n--- a/ipu3.cpp\n+++ b/ipu3.cpp\n@@ -59,7 +59,8 @@ private:\n \tvoid fillParams(unsigned int frame, ipu3_uapi_params *params);\n \tvoid parseStatistics(unsigned int frame,\n \t\t\t     int64_t frameTimestamp,\n-\t\t\t     const ipu3_uapi_stats_3a *stats);\n+\t\t\t     const ipu3_uapi_stats_3a *stats,\n+\t\t\t     const ControlList& sensorCtrls);\n \n \tvoid setControls(unsigned int frame);\n \n@@ -84,6 +85,7 @@ private:\n \t/* Temporary storage until we have a FrameContext object / struct */\n \taiq::AiqInputParameters aiqInputParams_;\n \taiq::AiqResults results_;\n+\taiq::AiqResultsRingBuffer resultsHistory_;\n \n \tBinaryData aiqb_;\n \tBinaryData nvm_;\n@@ -282,6 +284,8 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \t/* Upate the camera controls using the new sensor settings. */\n \tupdateControls(sensorInfo_, ctrls_, ipaControls);\n \n+\tresultsHistory_.Reset();\n+\n \treturn 0;\n }\n \n@@ -327,7 +331,10 @@ void IPAIPU3::processEvent(const IPU3Event &event)\n \t\tconst ipu3_uapi_stats_3a *stats =\n \t\t\treinterpret_cast<ipu3_uapi_stats_3a *>(mem.data());\n \n-\t\tparseStatistics(event.frame, event.frameTimestamp, stats);\n+\t\tparseStatistics(event.frame,\n+\t\t\t\t\t\t\t\t\t\tevent.frameTimestamp,\n+\t\t\t\t\t\t\t\t\t\tstats,\n+\t\t\t\t\t\t\t\t\t\tevent.sensorControls);\n \t\tbreak;\n \t}\n \tcase EventFillParams: {\n@@ -374,14 +381,16 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n \t*/\n \n \t/* Run algorithms into/using this context structure */\n-\tif (frame % 10 == 0)\n-\t\taiq_.run2a(frame, aiqInputParams_, results_);\n+\taiq_.run2a(frame, aiqInputParams_, results_);\n \n \taic_.updateRuntimeParams(results_);\n \taic_.run(params);\n \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+\tresultsHistory_.Push(results_);\n+\n \tsetControls(frame);\n \n \tIPU3Action op;\n@@ -392,7 +401,8 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n \n void IPAIPU3::parseStatistics(unsigned int frame,\n \t\t\t      int64_t frameTimestamp,\n-\t\t\t      const ipu3_uapi_stats_3a *stats)\n+\t\t\t      const ipu3_uapi_stats_3a *stats,\n+\t\t\t      const ControlList& sensorCtrls)\n {\n \tControlList ctrls(controls::controls);\n \n@@ -403,10 +413,43 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n \t */\n \n \tASSERT (frameTimestamp > 0);\n-\taiq_.setStatistics(frame, frameTimestamp, results_, stats);\n+\n+\t/* Ae algorithm expects the statistics to be set with it's corresponding Ae\n+\t * result, i.e., the Ae result should match the exposure time/analog gain\n+\t * with the the effective sensor controls of the statistics.\n+\t * Search the required Ae result in the result history and combine it with\n+\t * the latest result as the input to AIQ::setStatistics().\n+\t */\n+\n+\tint32_t effectiveExpo = 0;\n+\tint32_t effectiveGain = 0;\n+\tControlValue ctrlValue;\n+\n+\tctrlValue = sensorCtrls.get(V4L2_CID_EXPOSURE);\n+\tif (!ctrlValue.isNone())\n+\t\teffectiveExpo = ctrlValue.get<int32_t>();\n+\n+\tctrlValue = sensorCtrls.get(V4L2_CID_ANALOGUE_GAIN);\n+\tif (!ctrlValue.isNone())\n+\t\teffectiveGain = ctrlValue.get<int32_t>();\n+\n+\tauto pred = [effectiveExpo, effectiveGain] (aiq::AiqResults& result) {\n+\t\tia_aiq_exposure_sensor_parameters* sensorExposure =\n+\t\t\tresult.ae()->exposures[0].sensor_exposure;\n+\n+\t\treturn (effectiveExpo == sensorExposure->coarse_integration_time ||\n+\t\t\teffectiveGain == sensorExposure->analog_gain_code_global);\n+\t};\n+\taiq::AiqResults& aeMatchedResults = resultsHistory_.searchBackward(pred, results_);\n+\n+\taiq::AiqResults combinedResults = results_;\n+\tcombinedResults.setAe(aeMatchedResults.ae());\n+\n+\t/* Aiq library expects timestamp in microseconds */\n+\taiq_.setStatistics(frame, (frameTimestamp / 1000), combinedResults, stats);\n \n \t/* Set frame durations from exposure results */\n-\tia_aiq_exposure_sensor_parameters *sensorExposure = results_.ae()->exposures->sensor_exposure;\n+\tia_aiq_exposure_sensor_parameters *sensorExposure = combinedResults.ae()->exposures->sensor_exposure;\n \tint64_t frameDuration = (sensorExposure->line_length_pixels * sensorExposure->frame_length_lines) /\n \t\t\t\t(sensorInfo_.pixelRate / 1e6);\n \tctrls.set(controls::FrameDuration, frameDuration);\n@@ -423,10 +466,11 @@ void IPAIPU3::setControls(unsigned int frame)\n \tIPU3Action op;\n \top.op = ActionSetSensorControls;\n \n-\tControlList ctrls(ctrls_);\n-\tctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure_));\n-\tctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain_));\n-\top.controls = ctrls;\n+\tControlList sensorCtrls(ctrls_);\n+\tsensorCtrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure_));\n+\tsensorCtrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain_));\n+\n+\top.sensorControls = sensorCtrls;\n \n \tqueueFrameAction.emit(frame, op);\n }\n","prefixes":["libcamera-devel","3/6"]}