[{"id":23641,"web_url":"https://patchwork.libcamera.org/comment/23641/","msgid":"<CAHW6GYJSYo9AcqB66-_F1G7savVQRWcXQy+ZYTNjHO3Ss5BXWA@mail.gmail.com>","date":"2022-06-28T08:46:09","subject":"Re: [libcamera-devel] [PATCH v3 2/3] pipeline: ipa: raspberrypi:\n\tCorrectly report available control limits","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"HI Naush\n\nThanks for the patch. LGTM.\n\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nDavid\n\nOn Wed, 22 Jun 2022 at 11:21, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> The ipa currently advertises a static ControlInfoMap to specify the available\n> controls and their limits. Fix this limitation by having the IPA populate a new\n> ControlInfoMap with updated limits for ExposureTime, AnalogueGain, and\n> FrameDurationLimits controls based on the current sensor mode. This new\n> ControlInfoMap is then returned back to the pipeline handler and available to\n> the application after a successful Camera::configure() call.\n>\n> Before the first call to Camera::configure(), this ControlInfoMap provides some\n> reasonable default limits for ExposureTime, AnalogueGain, and\n> FrameDurationLimits. However, applications must not rely on these values, but\n> obtain the correct limits after the call to Camera::configure().\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  include/libcamera/ipa/raspberrypi.mojom       |  1 +\n>  src/ipa/raspberrypi/raspberrypi.cpp           | 33 +++++++++++++++++--\n>  .../pipeline/raspberrypi/raspberrypi.cpp      |  3 ++\n>  3 files changed, 34 insertions(+), 3 deletions(-)\n>\n> diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom\n> index 77f52c282b0f..c0de435b7b33 100644\n> --- a/include/libcamera/ipa/raspberrypi.mojom\n> +++ b/include/libcamera/ipa/raspberrypi.mojom\n> @@ -45,6 +45,7 @@ struct IPAConfig {\n>\n>  struct IPAConfigResult {\n>         float modeSensitivity;\n> +       libcamera.ControlInfoMap controlInfo;\n>  };\n>\n>  struct StartConfig {\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 089528f5e126..8f57350878cf 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -74,8 +74,8 @@ constexpr Duration controllerMinFrameDuration = 1.0s / 30.0;\n>  /* List of controls handled by the Raspberry Pi IPA */\n>  static const ControlInfoMap::Map ipaControls{\n>         { &controls::AeEnable, ControlInfo(false, true) },\n> -       { &controls::ExposureTime, ControlInfo(0, 999999) },\n> -       { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) },\n> +       { &controls::ExposureTime, ControlInfo(0, 66666) },\n> +       { &controls::AnalogueGain, ControlInfo(1.0f, 16.0f) },\n>         { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) },\n>         { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) },\n>         { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) },\n> @@ -89,7 +89,7 @@ static const ControlInfoMap::Map ipaControls{\n>         { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) },\n>         { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) },\n>         { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) },\n> -       { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) },\n> +       { &controls::FrameDurationLimits, ControlInfo(INT64_C(33333), INT64_C(120000)) },\n>         { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }\n>  };\n>\n> @@ -446,6 +446,33 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n>         ASSERT(controls);\n>         *controls = std::move(ctrls);\n>\n> +       /*\n> +        * Apply the correct limits to the exposure, gain and frame duration controls\n> +        * based on the current sensor mode.\n> +        */\n> +       ControlInfoMap::Map ctrlMap = ipaControls;\n> +       const Duration minSensorFrameDuration = mode_.min_frame_length * mode_.line_length;\n> +       const Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length;\n> +       ctrlMap[&controls::FrameDurationLimits] =\n> +               ControlInfo(static_cast<int64_t>(minSensorFrameDuration.get<std::micro>()),\n> +                           static_cast<int64_t>(maxSensorFrameDuration.get<std::micro>()));\n> +\n> +       ctrlMap[&controls::AnalogueGain] =\n> +               ControlInfo(1.0f, static_cast<float>(helper_->Gain(maxSensorGainCode_)));\n> +\n> +       /*\n> +        * Calculate the max exposure limit from the frame duration limit as V4L2\n> +        * will limit the maximum control value based on the current VBLANK value.\n> +        */\n> +       Duration maxShutter = Duration::max();\n> +       helper_->GetVBlanking(maxShutter, minSensorFrameDuration, maxSensorFrameDuration);\n> +       const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get<int32_t>();\n> +\n> +       ctrlMap[&controls::ExposureTime] =\n> +               ControlInfo(static_cast<int32_t>(helper_->Exposure(exposureMin).get<std::micro>()),\n> +                           static_cast<int32_t>(maxShutter.get<std::micro>()));\n> +\n> +       result->controlInfo = ControlInfoMap(std::move(ctrlMap), controls::controls);\n>         return 0;\n>  }\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index d980c1a71dd8..4596f2babcea 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -940,6 +940,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>         /* Store the mode sensitivity for the application. */\n>         data->properties_.set(properties::SensorSensitivity, result.modeSensitivity);\n>\n> +       /* Update the controls that the Raspberry Pi IPA can handle. */\n> +       data->controlInfo_ = result.controlInfo;\n> +\n>         /* Setup the Video Mux/Bridge entities. */\n>         for (auto &[device, link] : data->bridgeDevices_) {\n>                 /*\n> --\n> 2.25.1\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 2BF54BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Jun 2022 08:46:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D648365635;\n\tTue, 28 Jun 2022 10:46:21 +0200 (CEST)","from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com\n\t[IPv6:2a00:1450:4864:20::62a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 180266559A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Jun 2022 10:46:21 +0200 (CEST)","by mail-ej1-x62a.google.com with SMTP id pk21so24307372ejb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Jun 2022 01:46:21 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656405981;\n\tbh=xPQolKemeP9j4O1wjMIwnu4hPv2pNJ5/0GNbyGHl+TI=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=EwOf50sLNemXz3pNTIazFEORxG9mQSpg+7PIMHAn93SGk2NX28rA5u1H0EFpMIQG0\n\tA+qRMn2ZlK9N9yqmw3rI6MYdrwFuqydVyRa/agrVOWZdHTdpCXXv8AIDeJFtQUIs1N\n\tX0ZnWk61HYqr0axpK4M4Hgm4hcKw95lrIN6yvS4qH48ckaHJ96LL0kfJpGsOyZe/Jl\n\te6zYmpfxsqaEc0z8jhTgbyq4Pq/UaKCtRCPJV+hLWAV46Z+dyPCs+0DNmdCCTlMrIS\n\tcx3MLU4B07QvtmaHry3eiFCFo1nlnFSdS8T/4M+hAL20qgzzI2LX99DxrDWKQQJNjz\n\tFSRrAGVUteYPg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=un7N8USw5R3vIUr4Rcxwegu6AbZaCoFSrJiBp1Lx0FY=;\n\tb=W3kNi/eZFCLr/xOOfpRMEYbNy0oTs1b3ZpxagI6A7ly+xeOKmVPOhQb+7/MggfX00E\n\tCKZP8Z3P2Bh813u7MG/0QxrtspJdvw3xM6ecBxyDPxEqZa7FQJKGSWcGnqmBf1xRYgSm\n\tiLC0gvzYifAbqM+xyJXY1z5N+M0yQ6Rsca03OHxBSAYdnWPiFEvFYyKCjFdGbjaOkcu2\n\tOXCvKNE2F3wrNcvzmoipCFKsLtL1pMVLr8rnjsjKJJJ/BtsWGyRZwMn/SvwY09oAcWYV\n\tHK+KNCGz+QSFU+hS2ekrnxTfVmhPRyX7GjoAXZZZxbOQDeeX9AeHEeNsNieQjyCiGU8p\n\tPfVg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"W3kNi/eZ\"; dkim-atps=neutral","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=un7N8USw5R3vIUr4Rcxwegu6AbZaCoFSrJiBp1Lx0FY=;\n\tb=BB8/D7mDA7uOZ7y3TCUZc4t+JF6U2FYXYFugMcHcZlvAoYl0ZRO2N8MI508zK5iFBo\n\ty2mbFOsyQ8ZGfoOmEKYtyc3Zu+PYJCpxbQvOzf4a+kRBnRmZSrhym/5difGaCN0prUKE\n\tUfhNFR+6hDGASpzKIBZ7IraGVDtyD5/83sraKkeXqgFRfnZmvvbT5x6bRZfWJEwTwpJ2\n\tRp5sZwcupb9IZOkdPim+oT1MzRNlyoPwEIhabgO7OP9sk4RmbpxnmsFiWxcTyry0U63K\n\t19QglkBBXUkzo5zLaja0RxCL5VHSAtH9VRTlTZdKUD/qGOA+GMaPCKeo27Zmylm8p2mH\n\trLFg==","X-Gm-Message-State":"AJIora/KyYYWAzsN7hun6zk1a2yyBdL/jRiRGc15Qm5V9ATwgfThtlJs\n\tZTYgf6mS9plmN12WDRhhsWUwqTVULdNPTc3RNTw1Ow==","X-Google-Smtp-Source":"AGRyM1uPuYseNFFqw+ixRcheG9YqdDhdiadwLXr9m8LR3r5ojt6YKq9CiG3mixDAF1+dOj7Hi3ugNZAgr7NatlZWO+o=","X-Received":"by 2002:a17:906:478e:b0:722:fc31:aa13 with SMTP id\n\tcw14-20020a170906478e00b00722fc31aa13mr16897948ejc.84.1656405980690;\n\tTue, 28 Jun 2022 01:46:20 -0700 (PDT)","MIME-Version":"1.0","References":"<20220622102047.22492-1-naush@raspberrypi.com>\n\t<20220622102047.22492-3-naush@raspberrypi.com>","In-Reply-To":"<20220622102047.22492-3-naush@raspberrypi.com>","Date":"Tue, 28 Jun 2022 09:46:09 +0100","Message-ID":"<CAHW6GYJSYo9AcqB66-_F1G7savVQRWcXQy+ZYTNjHO3Ss5BXWA@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v3 2/3] pipeline: ipa: raspberrypi:\n\tCorrectly report available control limits","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>","From":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]