From patchwork Mon Mar 27 09:34:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18466 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EC0F9C329C for ; Mon, 27 Mar 2023 09:34:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 467D462747; Mon, 27 Mar 2023 11:34:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679909687; bh=JVdfbSnT6OCQKMajmp+DwoRSSQ66yxco/CpyDTl3f1U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QNtOy+oCB13c8ePw6MtmJyYLn59JaE3b4XJ63bTxggU/QIBSB3oJBnKsGXLe+bC4u dUe4q9/mVf30esZ/9m99udNjBu6OAKhFSHtfkg318wu83YWAwcH7CNv9ngFgnSuGKZ XhrVUZS7F18k6x1IcZSvjdc3z62UzfkLrgWz0exeolX35Ohl3IE1oUFvgul86dj07F T0PzANBpdQej7NCsskYu3/ut4l1xpbIZK2epXrY3MmBMkMNP561cXWlNVS2/nfk9KV 7V9rnrMiC8WRfuBz1v/hQlZD6NtbaYeAeSkvij6V8wVuG+kFrVLp5xLQ3cIDzZDkoJ dwXs5IGA+F9yg== Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A9FF26271E for ; Mon, 27 Mar 2023 11:34:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="IPuUjmRo"; dkim-atps=neutral Received: by mail-io1-xd29.google.com with SMTP id z1so3596778iot.11 for ; Mon, 27 Mar 2023 02:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679909683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m0q0eJhd3Kapv18ykdi9paPfoedIk4GLldhtnmYKlLw=; b=IPuUjmRoiPK11b780NesBgK1nNJ62RWuJse1+FgJDTpcTw49tiw3Kd3SZYc2ocFu81 aEQ16y242OeVACxsOVaO6zon6mt/ogvlAzeCZuo6xjpHRxNSH7fToVCxzflk864gpT9I G3pTPzKtWR3d2oFUnYJNXd/70Gss9x/LisWf5KRgtExZuSe+it4OEvvqPzjlPHky1Mpi 9//3EFpPjKzps9gZATxVET8Cs8kiTR1gagrpp3GlWRsrVIxry7SIhKGyfCq3T0WmziyC ZwFcXEY01rPunlBbQioyD+RI6bTNvAsLBMrVmSMEfX0Q/LkZByf4l0/1HUrLF4yJz7cW uTaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679909683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m0q0eJhd3Kapv18ykdi9paPfoedIk4GLldhtnmYKlLw=; b=5XSrJ43s0HuTJhOGQ8d8Ijpg8U5ca12L2RkIr61jBoYV3K+J5YMVkkCPYPLtoURVgm 1GhVOnX8Zw9itinC5WE8nDhBG8v2wDl2Ha6TApZGHhQAWO8skiyWa7RR9BkNbMalFjG+ fUzAX/BPkPdHBM99ImB4E4k6jNwm1krSbslCvphGLENHQOSFM6zcc17T2bcpnnlp8PfC sMnrzVVTk8Arl4jrbHG0e9PIflRxdxv1V5wwmQXdiEPs48EKKuwrrTbv6s63d4egjHW2 wKDHLroDpak1b1WPdrNHujfwNGwrD3WCg+nZt1SWT9MzIM7c/pcZXaZk8Xcwqw94IIOY CK0g== X-Gm-Message-State: AO0yUKU2YnQaw3aW8UlttJlex6N7ORA2vx7naXR5kae1A54x0C5BviYv RDe67O7NEMe4SV0HN5kWLt1/ptuh4X9+lA3RO/VDcg== X-Google-Smtp-Source: AK7set9NMaC5KydlQZa0CUJAZnCKfwMwhiTxfXnMRwrLyvAFQvPgV7MWUoVFIMaUMl0S5RLXVPFxZw== X-Received: by 2002:a6b:d310:0:b0:74c:9cc4:ac0 with SMTP id s16-20020a6bd310000000b0074c9cc40ac0mr7854459iob.14.1679909683140; Mon, 27 Mar 2023 02:34:43 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id d12-20020a056602328c00b0075464a69c10sm7658345ioz.10.2023.03.27.02.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 02:34:42 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Mar 2023 10:34:37 +0100 Message-Id: <20230327093439.24670-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327093439.24670-1-naush@raspberrypi.com> References: <20230327093439.24670-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] ipa: raspberrypi: Use the new sensor limits fields in CameraMode X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the new analogue gain and shutter speed limit fields in the ipa code when reporting back the control value limits and calculating the analogue gain code to use. This also replaces the now unused (and removed) maxSensorGainCode_ field. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/raspberrypi/raspberrypi.cpp | 37 +++++++++-------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 3f1afb846420..c10e57e07ab0 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -224,9 +224,6 @@ private: Duration minFrameDuration_; Duration maxFrameDuration_; - /* Maximum gain code for the sensor. */ - uint32_t maxSensorGainCode_; - /* Track the frame length times over FrameLengthsQueueSize frames. */ std::deque frameLengths_; Duration lastTimeout_; @@ -455,8 +452,6 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const IPAConfig &ip } } - maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get(); - /* Setup a metadata ControlList to output metadata. */ libcameraMetadata_ = ControlList(controls::controls); @@ -517,26 +512,17 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const IPAConfig &ip * based on the current sensor mode. */ ControlInfoMap::Map ctrlMap = ipaControls; - const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; ctrlMap[&controls::FrameDurationLimits] = - ControlInfo(static_cast(minSensorFrameDuration.get()), - static_cast(maxSensorFrameDuration.get())); + ControlInfo(static_cast(mode_.minFrameDuration.get()), + static_cast(mode_.maxFrameDuration.get())); ctrlMap[&controls::AnalogueGain] = - ControlInfo(1.0f, static_cast(helper_->gain(maxSensorGainCode_))); - - /* - * Calculate the max exposure limit from the frame duration limit as V4L2 - * will limit the maximum control value based on the current VBLANK value. - */ - Duration maxShutter = Duration::max(); - helper_->getBlanking(maxShutter, minSensorFrameDuration, maxSensorFrameDuration); - const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get(); + ControlInfo(static_cast(mode_.minAnalogueGain), + static_cast(mode_.maxAnalogueGain)); ctrlMap[&controls::ExposureTime] = - ControlInfo(static_cast(helper_->exposure(exposureMin, mode_.minLineLength).get()), - static_cast(maxShutter.get())); + ControlInfo(static_cast(mode_.minShutter.get()), + static_cast(mode_.maxShutter.get())); /* Declare Autofocus controls, only if we have a controllable lens */ if (lensPresent_) @@ -1496,9 +1482,6 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDuration) { - const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; - /* * This will only be applied once AGC recalculations occur. * The values may be clamped based on the sensor mode capabilities as well. @@ -1506,9 +1489,9 @@ void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur minFrameDuration_ = minFrameDuration ? minFrameDuration : defaultMaxFrameDuration; maxFrameDuration_ = maxFrameDuration ? maxFrameDuration : defaultMinFrameDuration; minFrameDuration_ = std::clamp(minFrameDuration_, - minSensorFrameDuration, maxSensorFrameDuration); + mode_.minFrameDuration, mode_.maxFrameDuration); maxFrameDuration_ = std::clamp(maxFrameDuration_, - minSensorFrameDuration, maxSensorFrameDuration); + mode_.minFrameDuration, mode_.maxFrameDuration); maxFrameDuration_ = std::max(maxFrameDuration_, minFrameDuration_); /* Return the validated limits via metadata. */ @@ -1531,6 +1514,8 @@ void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) { + const int32_t minGainCode = helper_->gainCode(mode_.minAnalogueGain); + const int32_t maxGainCode = helper_->gainCode(mode_.maxAnalogueGain); int32_t gainCode = helper_->gainCode(agcStatus->analogueGain); /* @@ -1538,7 +1523,7 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) * DelayedControls. The AGC will correctly handle a lower gain returned * by the sensor, provided it knows the actual gain used. */ - gainCode = std::min(gainCode, maxSensorGainCode_); + gainCode = std::clamp(gainCode, minGainCode, maxGainCode); /* getBlanking might clip exposure time to the fps limits. */ Duration exposure = agcStatus->shutterTime;