From patchwork Thu Oct 6 13:17:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17542 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 456A3C327C for ; Thu, 6 Oct 2022 13:17:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BA04C62CEC; Thu, 6 Oct 2022 15:17:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062275; bh=w2S4d6v1gYSnFkQxkmqriKMoaRZOOgpuTDPY4i3E45Q=; 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=iboEPCyd0ZfKu2Fi3s9CS8+Nkhm/X+386CHXTOCiht3TaVTScZeXhvmGXFHqW0CYj m0WozV29k5WkvCYsAhwba1e6aEkJTnJPG1aoU82YKP9lJVC6N6NtnQyx6S91srwoc0 pKyAMhYj3EZB1rMNxEd6ijPAeBLeXvMEF1IMnPojRCZaH8EQsSd3vJstotbXbVQcUM CudLDmKU40yBD/+MbQMMqmA3EEYwpdGsB6uClc4biA8StEdHvSzcBxHy4hfhblv6tI KfhxEUnWAi5dNgBbRIbA2q+mRWKcT/2CdWxWoooXiBiQ/R15eVv/yGqv7o8GrwwUyh RXutg1XJNMZwA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 11CA062CEC for ; Thu, 6 Oct 2022 15:17:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="k9DtKtBB"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id a3so2732276wrt.0 for ; Thu, 06 Oct 2022 06:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=63HV8gWPDPKpyvSeClm2tYYD+NWm1ekUi/dYqoq+cHU=; b=k9DtKtBBfaoGfunaN0lvccv9C9VMGcHM+ARTFsuIsG1YQjH+ddFeo8WqrTa5eCahVM EDwve+tN2IITJeHDhK/qNfFmizF+ffWaE0YR3sZsqtLg+3b3ayWzjuNc22wTn13TfxaY /GbErVdXZKBuDYaqz5UbvDzKfk0sIIsGANrQsbNoyUTj8yAIXAkLRBNPWDSfvGf3PAK6 G1pa5EANDvv7QtT4WDav6KXYqOY7W10zUgaj4XMEFoYmPUTtwGZDUyiWRy0OhXvtl2GT FVfNV2iDPSjBxtB0Wf0Q6IS1r01CYWVDITL3Q3Fki9Mc551ChmHYmchnjagmy29mm/06 V5eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=63HV8gWPDPKpyvSeClm2tYYD+NWm1ekUi/dYqoq+cHU=; b=Ua0QxSDCQCLRe19lT5zJhVQ+uQl83u/8I2zJISlLO6tihF6d1+K15HToSRChHuckVa O0sO/WzkaEiyuuIFQk6MITtn+WoHxuKn3vX4UNv3LOnPvyh2z8DA0Q6mdOV7b5tOYIKh tr+0vVWyF+gqlH9U+GM2EXhrjRCnZqGy2cy+YqCuB02es03JQr8QRBm+dLzGs3wRmyD8 YHNr+FIifN+AKMM+HqiBD8Q4zY69+/2I/u67lJC+K0U75L3VGM+QXxyUhyNxYSr9lvx6 9YcwbIf5Mn4PTt5dxc1FBryfIo9uIWwAMYZmRrXANzwZjTysQ+Sp1PLkxHzN1EI4wzo8 bTew== X-Gm-Message-State: ACrzQf1sk5uIH3gk62pCJVGBdcVxKVfvoIfplYQ4wmTacVKAsMO0kzn8 7C9zj3qBGjUoLoAItPXnD9lm9DmTS9+Pjw== X-Google-Smtp-Source: AMsMyM6swrIA9Y0OEkUQjIbf5mjOcMNg8P/GHOJHQMnNZMTYlvG87NN2nNo3d5qJ4mWBccrdwLAahA== X-Received: by 2002:a5d:414c:0:b0:22c:de8a:d233 with SMTP id c12-20020a5d414c000000b0022cde8ad233mr3370151wrq.194.1665062273353; Thu, 06 Oct 2022 06:17:53 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:52 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:35 +0100 Message-Id: <20221006131744.5179-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/10] camera_sensor: Add minimum and maximum line length to IPACameraSensorInfo 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" Add fields for minimum and maximum line length (in units of pixels) to the IPACameraSensorInfo structure. This replaces the existing lineLength field. Update the ipu3, raspberrypi and rkisp1 IPAs to use IPACameraSensorInfo::minLineLength instead of IPACameraSensorInfo::lineLength, as logically we will always want to use the fastest sensor readout by default. Since the IPAs now use minLineLength for their calculations, set the starting value of the V4L2_CID_HBLANK control to its minimum in CameraSensor::init(). Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- include/libcamera/ipa/core.mojom | 21 +++++++++++++++------ src/ipa/ipu3/ipu3.cpp | 6 ++++-- src/ipa/raspberrypi/raspberrypi.cpp | 2 +- src/ipa/rkisp1/rkisp1.cpp | 2 +- src/libcamera/camera_sensor.cpp | 15 +++++++++++++-- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/include/libcamera/ipa/core.mojom b/include/libcamera/ipa/core.mojom index 74f3339e56f2..2bc3028c22d6 100644 --- a/include/libcamera/ipa/core.mojom +++ b/include/libcamera/ipa/core.mojom @@ -172,10 +172,17 @@ module libcamera; */ /** - * \var IPACameraSensorInfo::lineLength - * \brief Total line length in pixels + * \var IPACameraSensorInfo::minLineLength + * \brief The minimum line length in pixels * - * The total line length in pixel clock periods, including blanking. + * The minimum allowable line length in pixel clock periods, including blanking. + */ + +/** + * \var IPACameraSensorInfo::maxLineLength + * \brief The maximum line length in pixels + * + * The maximum allowable line length in pixel clock periods, including blanking. */ /** @@ -189,7 +196,7 @@ module libcamera; * To obtain the minimum frame duration: * * \verbatim - frameDuration(s) = minFrameLength(lines) * lineLength(pixels) / pixelRate(pixels per second) + frameDuration(s) = minFrameLength(lines) * minLineLength(pixels) / pixelRate(pixels per second) \endverbatim */ @@ -204,7 +211,7 @@ module libcamera; * To obtain the maximum frame duration: * * \verbatim - frameDuration(s) = maxFrameLength(lines) * lineLength(pixels) / pixelRate(pixels per second) + frameDuration(s) = maxFrameLength(lines) * maxLineLength(pixels) / pixelRate(pixels per second) \endverbatim */ struct IPACameraSensorInfo { @@ -217,7 +224,9 @@ struct IPACameraSensorInfo { Size outputSize; uint64 pixelRate; - uint32 lineLength; + + uint32 minLineLength; + uint32 maxLineLength; uint32 minFrameLength; uint32 maxFrameLength; diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index b93a09d40c39..7e26fc5639c2 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -336,7 +336,8 @@ int IPAIPU3::init(const IPASettings &settings, /* Clean context */ context_.configuration = {}; - context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate; + context_.configuration.sensor.lineDuration = sensorInfo.minLineLength + * 1.0s / sensorInfo.pixelRate; /* Load the tuning data file. */ File file(settings.configurationFile); @@ -499,7 +500,8 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, context_.frameContexts.clear(); /* Initialise the sensor configuration. */ - context_.configuration.sensor.lineDuration = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate; + context_.configuration.sensor.lineDuration = sensorInfo_.minLineLength + * 1.0s / sensorInfo_.pixelRate; /* * Compute the sensor V4L2 controls to be used by the algorithms and diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 8d731435764e..358a119da222 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -356,7 +356,7 @@ void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo) * Calculate the line length as the ratio between the line length in * pixels and the pixel rate. */ - mode_.lineLength = sensorInfo.lineLength * (1.0s / sensorInfo.pixelRate); + mode_.lineLength = sensorInfo.minLineLength * (1.0s / sensorInfo.pixelRate); /* * Set the frame length limits for the mode to ensure exposure and diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 32feb1682749..ddb22d98eb41 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -246,7 +246,7 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info, context_.configuration.hw.revision = hwRevision_; context_.configuration.sensor.size = info.outputSize; - context_.configuration.sensor.lineDuration = info.lineLength * 1.0s / info.pixelRate; + context_.configuration.sensor.lineDuration = info.minLineLength * 1.0s / info.pixelRate; /* * When the AGC computes the new exposure values for a frame, it needs diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 911fd0beae4e..83f81d655395 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -176,6 +176,15 @@ int CameraSensor::init() if (ret) return ret; + /* Set HBLANK to the minimum as a starting value. */ + const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); + ControlList ctrl(subdev_->controls()); + + ctrl.set(V4L2_CID_HBLANK, hblank.min().get()); + ret = subdev_->setControls(&ctrl); + if (ret) + return ret; + return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } @@ -883,10 +892,12 @@ int CameraSensor::sensorInfo(IPACameraSensorInfo *info) const return -EINVAL; } - int32_t hblank = ctrls.get(V4L2_CID_HBLANK).get(); - info->lineLength = info->outputSize.width + hblank; info->pixelRate = ctrls.get(V4L2_CID_PIXEL_RATE).get(); + const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); + info->minLineLength = info->outputSize.width + hblank.min().get(); + info->maxLineLength = info->outputSize.width + hblank.max().get(); + const ControlInfo vblank = ctrls.infoMap()->at(V4L2_CID_VBLANK); info->minFrameLength = info->outputSize.height + vblank.min().get(); info->maxFrameLength = info->outputSize.height + vblank.max().get(); From patchwork Thu Oct 6 13:17:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17543 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 E906FBD16B for ; Thu, 6 Oct 2022 13:17:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9121562D05; Thu, 6 Oct 2022 15:17:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062278; bh=DfzHQ0bZZY8QgmiGOX9cjtXd5ci7YtVJOuyas16zy9A=; 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=OfGA84Tqm1hRjLoKxzmNv87R4UK2BULjEhOwKqx8VyPv2RrqqlJYvBAs6V6aRUjNI gy3twsvvFFfQSBYysrpT4qKp0nGpaf2azRMd8sDtIejrwwPnR/wRqgOhy/IHVFZwXr bmxcVGkOrxZAc5rSaV740As17vbZq/+SzZhj6hv+ZqEbXocPamqeYFb0opTqLmSw7E MddrH5hIAt9zPIKkgpQ6FBbVJLsX5NPo21rXmt5PHmtVPH4TL+Dcvn1yUbxpIrzeWa 70K+0ZwXATHYT3fKH5tYdJ8E191pXM1GoVsYLG08/o7JCnUMz6LhHPBINp1wxuCpmZ 3NtXGWqeyhFPA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F123062CF1 for ; Thu, 6 Oct 2022 15:17:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Lc93DDfi"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id bq9so2690640wrb.4 for ; Thu, 06 Oct 2022 06:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=tM2HZQgNPT7c6W3h2GI86+7wXtUs/IeSla0L7MdHmWA=; b=Lc93DDfiM925gVVxX9JXBk+WI2vnXLKZfPMMl6633tfvypS87nxrP9yMeEmBJnQEPr aU0gXmBIFoKlMQ0YF0IoXiImN2Eb0dlwy4DLUJQtLlVtmiodoQ/WRflmVCu8Fwktlf2f sotMJFElMkS2v0KHWbS/SiMduFQWRFDEnW/AWFkU6QC8x0SEgZflibXXyw5KwvT6yEBY rMqM/RT5Ef7C4e0UCJBsqcHrgMDCo9+O1Vg7o5P56jWsFkAKlhbB7wX2l8pANsJfIs5g tQ7NoHdJEiffWEdwVcI0DJrWoj83qUHp7sWrzGA+rxSerO9yEb1JJzPAEePIeuVQCiB0 qLGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=tM2HZQgNPT7c6W3h2GI86+7wXtUs/IeSla0L7MdHmWA=; b=IJhkT7akgX04Bs0RqZXuUzk9jKmG2yyz8iwk9oKoGdWIAr6T6FmHKV9kzbybHXIDLY zX39MncNzTIgL9HEx6KfTij0HZH1jC2cwrii5MxnXPNm4GirgkH4NuzSHbhMz71QVHIC 1JpQRgclQstte0NhQVF2CrilXCZhFA641Fnw0upEzII/pPXSGkhS1DOg9BfXVvn66s0S yYSt+f4fQYJaCGx8P+YOFu/PxxVeV8cvShCoN4Qf05viQ4V/lb3rsarNNl9peyganYkz Hd1j6I8I0WsADqYwSqs5YgEkmeKWJMSYnAX4e0xUjvbvSh2TJvLLFWP8R/HG6HtpWs+U JehQ== X-Gm-Message-State: ACrzQf0ZTpbfUHcC9xXDRlt4mrgU3XSp63xwqSdnkfSusrKOQqIyQz3K zv+lSUKznkKbuxrn0Xfx8lBj21kE/EP0LA== X-Google-Smtp-Source: AMsMyM4qRDSm+NqxlMztrl3P2/eP0dej/8Qve8A0wT30Ee8x615ALYdm4X5xzmRe34kSBN3Bpr+mqQ== X-Received: by 2002:a05:6000:154e:b0:22a:3177:1985 with SMTP id 14-20020a056000154e00b0022a31771985mr3212296wry.117.1665062274479; Thu, 06 Oct 2022 06:17:54 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:53 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:36 +0100 Message-Id: <20221006131744.5179-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/10] ipa: raspberrypi: Add minimum and maximum line length fields to 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" Add fields for minimum and maximum line length duration to the CameraMode structure. This replaces the existing lineLength field. Any use of the existing lineLength field is replaced by the new minLineLength field, as logically we always want to use the fastest sensor readout by default. As a drive-by cosmetic change, split all fields in the CameraMode structure into separate lines. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 8 +++---- src/ipa/raspberrypi/controller/camera_mode.h | 23 +++++++++++++------- src/ipa/raspberrypi/raspberrypi.cpp | 13 ++++++----- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index cac8f39ee763..42251ba29682 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -64,13 +64,13 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats, uint32_t CamHelper::exposureLines(const Duration exposure) const { assert(initialized_); - return exposure / mode_.lineLength; + return exposure / mode_.minLineLength; } Duration CamHelper::exposure(uint32_t exposureLines) const { assert(initialized_); - return exposureLines * mode_.lineLength; + return exposureLines * mode_.minLineLength; } uint32_t CamHelper::getVBlanking(Duration &exposure, @@ -86,8 +86,8 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, * minFrameDuration and maxFrameDuration are clamped by the caller * based on the limits for the active sensor mode. */ - frameLengthMin = minFrameDuration / mode_.lineLength; - frameLengthMax = maxFrameDuration / mode_.lineLength; + frameLengthMin = minFrameDuration / mode_.minLineLength; + frameLengthMax = maxFrameDuration / mode_.minLineLength; /* * Limit the exposure to the maximum frame duration requested, and diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h index a6ccf8c1c600..6bc35b771946 100644 --- a/src/ipa/raspberrypi/controller/camera_mode.h +++ b/src/ipa/raspberrypi/controller/camera_mode.h @@ -20,23 +20,30 @@ struct CameraMode { /* bit depth of the raw camera output */ uint32_t bitdepth; /* size in pixels of frames in this mode */ - uint16_t width, height; + uint16_t width; + uint16_t height; /* size of full resolution uncropped frame ("sensor frame") */ - uint16_t sensorWidth, sensorHeight; + uint16_t sensorWidth; + uint16_t sensorHeight; /* binning factor (1 = no binning, 2 = 2-pixel binning etc.) */ - uint8_t binX, binY; + uint8_t binX; + uint8_t binY; /* location of top left pixel in the sensor frame */ - uint16_t cropX, cropY; + uint16_t cropX; + uint16_t cropY; /* scaling factor (so if uncropped, width*scaleX is sensorWidth) */ - double scaleX, scaleY; + double scaleX; + double scaleY; /* scaling of the noise compared to the native sensor mode */ double noiseFactor; - /* line time */ - libcamera::utils::Duration lineLength; + /* minimum and maximum line time */ + libcamera::utils::Duration minLineLength; + libcamera::utils::Duration maxLineLength; /* any camera transform *not* reflected already in the camera tuning */ libcamera::Transform transform; /* minimum and maximum fame lengths in units of lines */ - uint32_t minFrameLength, maxFrameLength; + uint32_t minFrameLength; + uint32_t maxFrameLength; /* sensitivity of this mode */ double sensitivity; }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 358a119da222..67326bcf4a14 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -314,7 +314,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) } startConfig->dropFrameCount = dropFrameCount_; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.lineLength; + const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength; startConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get(); firstStart_ = false; @@ -356,7 +356,8 @@ void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo) * Calculate the line length as the ratio between the line length in * pixels and the pixel rate. */ - mode_.lineLength = sensorInfo.minLineLength * (1.0s / sensorInfo.pixelRate); + mode_.minLineLength = sensorInfo.minLineLength * (1.0s / sensorInfo.pixelRate); + mode_.maxLineLength = sensorInfo.maxLineLength * (1.0s / sensorInfo.pixelRate); /* * Set the frame length limits for the mode to ensure exposure and @@ -458,8 +459,8 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, * based on the current sensor mode. */ ControlInfoMap::Map ctrlMap = ipaControls; - const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.lineLength; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.lineLength; + const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength; + const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength; ctrlMap[&controls::FrameDurationLimits] = ControlInfo(static_cast(minSensorFrameDuration.get()), static_cast(maxSensorFrameDuration.get())); @@ -1150,8 +1151,8 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDuration) { - const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.lineLength; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.lineLength; + const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength; + const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength; /* * This will only be applied once AGC recalculations occur. From patchwork Thu Oct 6 13:17:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17544 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 63F64C327C for ; Thu, 6 Oct 2022 13:17:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1297C62CFD; Thu, 6 Oct 2022 15:17:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062279; bh=J8lJ6PGCLvUfkjHvaRUY8NgDNAIkJP7WBkY+MQMcq8I=; 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=Jv+sKHNCnl/+nx+fuPdfxPLkye5KB8MK4wcNS8FLDrPAq/fSrtE/wrcXXLxUuZnho RYMsqqPjCe/BcBM+0WsYJ3ZurXYAdr2ce7GxtMRluwsejFHe4P1oITs1y34vvIcMDB Fbe9fEet3Kh9SqC4yDYVwkqBCIx+UK92Jxva+L+8lr117xkp56GYC3W5Wpp8H7EVlA 1YyiAYFT8FdG3TwxkmtqgepSf1/lNpGg3V/MQIe21pZ/JVjOUp8mKLuZeJSqvF7yqA Yss5kMymwwx0ANzGz7o7G5l25RlC+RLC+JNIGe/rr9Krozr1q2SzYu4ICNU++WO0Sl EZATOedYdNZpg== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 655C062CFC for ; Thu, 6 Oct 2022 15:17:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="IoBqAW78"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id b4so2706252wrs.1 for ; Thu, 06 Oct 2022 06:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=PPWqyUmpb6N+I4R6BCY7bFIr1oMEW/5912qbXTEqvGA=; b=IoBqAW78xokAioPc5hwwNIlFvNHhBidEGUcahce9LWhZPeFyrHp+f2idyxjARGjqqy CKGTWohS+0Qr07oCM5e34TUc8HZeBKn/25UJNnGkj1A4uc+eGUqeqETDljCbbjRlD5B2 YE0jXxwkJ58Fa1b9hG69jdugXAfzW7pYxk+QbCKz50BLecOp7+q8s80R9LOpz0jgfA7Q UrHZhQuqwyXmlFvwR47JlAFa1Mp5Mf7yRzwukraUU+bZ/3PVLna6JYFDWmQFrYF7oGIC fC1F8SvikrjlRsV7xLqDkpQch1hrWfwvKdQhqPqhY+FMLonm8l3q7MezD3Zl/6cv1x4a fOJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=PPWqyUmpb6N+I4R6BCY7bFIr1oMEW/5912qbXTEqvGA=; b=VL7QKSHhHcn2PhFSTposLOK7lQYAFdF6A6h/+LH36JtuG0dlot83c3go/oEQNjcvOU tRDa/fGhTyiNkigI4wq2GQRCKwzXa+vbRDslBimmL57wRUxkMZAuFRsSxoN8/SO2s9dp bi7oayV9B8gtdToW+XTyO2jpW8W78e5EqwjXc0GGV35EVRg1fDxR0fOLfIyOzwD1yTrO 5bGEDiLOBVtw2wAyP2v0FrSMS0o6WzmAuyMWyShEuqAjU008vXDb+VY1ddVjy/tH/ltR 3SzmUCWdryVylKyh9kk0aAVZl2xJeEOCwaEP2CwMj9BxJA0gPg2QSysErB86G/N5NP7Q PBSQ== X-Gm-Message-State: ACrzQf3pEeEW5PNz1uXxVIe/FxkCxG2J8/VN8dows75CHw1u9Ztn58V6 eJXZ//EmlJNwglFBD7yTiW+kxI+954WEFw== X-Google-Smtp-Source: AMsMyM7sNUP2xsCd793PCCqrBYv2qOz2w95uLca9Ulf/o5qtWStsbcNt7KQSFokolkpaykR0usVWAw== X-Received: by 2002:a5d:4a01:0:b0:21d:8ce1:8b6d with SMTP id m1-20020a5d4a01000000b0021d8ce18b6dmr3180226wrq.718.1665062275548; Thu, 06 Oct 2022 06:17:55 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:37 +0100 Message-Id: <20221006131744.5179-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/10] ipa: raspberrypi: Pass lineLength into the CamHelper API 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" Update CamHelper::exposureLines() and CamHelper::exposure() to take a line length duration parameter for use in the exposure calculations. For now, only use the minimum line length for all the calculations to match the existing IPA behavior. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 12 ++++++------ src/ipa/raspberrypi/cam_helper.h | 6 ++++-- src/ipa/raspberrypi/cam_helper_imx219.cpp | 3 ++- src/ipa/raspberrypi/cam_helper_imx296.cpp | 10 ++++++---- src/ipa/raspberrypi/cam_helper_imx477.cpp | 7 ++++--- src/ipa/raspberrypi/cam_helper_imx519.cpp | 7 ++++--- src/ipa/raspberrypi/raspberrypi.cpp | 8 ++++---- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index 42251ba29682..fd3527b94501 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -61,16 +61,16 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats, { } -uint32_t CamHelper::exposureLines(const Duration exposure) const +uint32_t CamHelper::exposureLines(const Duration exposure, const Duration lineLength) const { assert(initialized_); - return exposure / mode_.minLineLength; + return exposure / lineLength; } -Duration CamHelper::exposure(uint32_t exposureLines) const +Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) const { assert(initialized_); - return exposureLines * mode_.minLineLength; + return exposureLines * lineLength; } uint32_t CamHelper::getVBlanking(Duration &exposure, @@ -78,7 +78,7 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, Duration maxFrameDuration) const { uint32_t frameLengthMin, frameLengthMax, vblank; - uint32_t exposureLines = CamHelper::exposureLines(exposure); + uint32_t exposureLines = CamHelper::exposureLines(exposure, mode_.minLineLength); assert(initialized_); @@ -94,7 +94,7 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, * re-calculate if it has been clipped. */ exposureLines = std::min(frameLengthMax - frameIntegrationDiff_, exposureLines); - exposure = CamHelper::exposure(exposureLines); + exposure = CamHelper::exposure(exposureLines, mode_.minLineLength); /* Limit the vblank to the range allowed by the frame length limits. */ vblank = std::clamp(exposureLines + frameIntegrationDiff_, diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h index 70d62719da86..9b5e602689f3 100644 --- a/src/ipa/raspberrypi/cam_helper.h +++ b/src/ipa/raspberrypi/cam_helper.h @@ -78,8 +78,10 @@ public: virtual void prepare(libcamera::Span buffer, Metadata &metadata); virtual void process(StatisticsPtr &stats, Metadata &metadata); - virtual uint32_t exposureLines(libcamera::utils::Duration exposure) const; - virtual libcamera::utils::Duration exposure(uint32_t exposureLines) const; + virtual uint32_t exposureLines(const libcamera::utils::Duration exposure, + const libcamera::utils::Duration lineLength) const; + virtual libcamera::utils::Duration exposure(uint32_t exposureLines, + const libcamera::utils::Duration lineLength) const; virtual uint32_t getVBlanking(libcamera::utils::Duration &exposure, libcamera::utils::Duration minFrameDuration, libcamera::utils::Duration maxFrameDuration) const; diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index 7ded07a213cd..98a3b31956ec 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -94,7 +94,8 @@ void CamHelperImx219::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; - deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg)); + deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), + mode_.minLineLength); deviceStatus.analogueGain = gain(registers.at(gainReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); diff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp index 66d21e36ecd0..d86ff3878983 100644 --- a/src/ipa/raspberrypi/cam_helper_imx296.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp @@ -21,8 +21,8 @@ public: CamHelperImx296(); uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; - uint32_t exposureLines(Duration exposure) const override; - Duration exposure(uint32_t exposureLines) const override; + uint32_t exposureLines(const Duration exposure, const Duration lineLength) const override; + Duration exposure(uint32_t exposureLines, const Duration lineLength) const override; void getDelays(int &exposureDelay, int &gainDelay, int &vblankDelay) const override; private: @@ -53,12 +53,14 @@ double CamHelperImx296::gain(uint32_t gainCode) const return std::pow(10.0, gainCode / 200.0); } -uint32_t CamHelperImx296::exposureLines(Duration exposure) const +uint32_t CamHelperImx296::exposureLines(const Duration exposure, + [[maybe_unused]] const Duration lineLength) const { return std::max(minExposureLines, (exposure - 14.26us) / timePerLine); } -Duration CamHelperImx296::exposure(uint32_t exposureLines) const +Duration CamHelperImx296::exposure(uint32_t exposureLines, + [[maybe_unused]] const Duration lineLength) const { return std::max(minExposureLines, exposureLines) * timePerLine + 14.26us; } diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index aa306d6661c6..71529bdd3034 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -144,9 +144,9 @@ uint32_t CamHelperImx477::getVBlanking(Duration &exposure, if (shift) { /* Account for any rounding in the scaled frame length value. */ frameLength <<= shift; - exposureLines = CamHelperImx477::exposureLines(exposure); + exposureLines = CamHelperImx477::exposureLines(exposure, mode_.minLineLength); exposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff); - exposure = CamHelperImx477::exposure(exposureLines); + exposure = CamHelperImx477::exposure(exposureLines, mode_.minLineLength); } return frameLength - mode_.height; @@ -170,7 +170,8 @@ void CamHelperImx477::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; - deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg)); + deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), + mode_.minLineLength); deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); deviceStatus.sensorTemperature = std::clamp(registers.at(temperatureReg), -20, 80); diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp index 54e104e7659a..2c120dad1680 100644 --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp @@ -144,9 +144,9 @@ uint32_t CamHelperImx519::getVBlanking(Duration &exposure, if (shift) { /* Account for any rounding in the scaled frame length value. */ frameLength <<= shift; - exposureLines = CamHelperImx519::exposureLines(exposure); + exposureLines = CamHelperImx519::exposureLines(exposure, mode_.minLineLength); exposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff); - exposure = CamHelperImx519::exposure(exposureLines); + exposure = CamHelperImx519::exposure(exposureLines, mode_.minLineLength); } return frameLength - mode_.height; @@ -170,7 +170,8 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; - deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg)); + deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), + mode_.minLineLength); deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 67326bcf4a14..13807f4d47f7 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -477,7 +477,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get(); ctrlMap[&controls::ExposureTime] = - ControlInfo(static_cast(helper_->exposure(exposureMin).get()), + ControlInfo(static_cast(helper_->exposure(exposureMin, mode_.minLineLength).get()), static_cast(maxShutter.get())); result->controlInfo = ControlInfoMap(std::move(ctrlMap), controls::controls); @@ -550,7 +550,7 @@ void IPARPi::reportMetadata() deviceStatus->shutterSpeed.get()); libcameraMetadata_.set(controls::AnalogueGain, deviceStatus->analogueGain); libcameraMetadata_.set(controls::FrameDuration, - helper_->exposure(deviceStatus->frameLength).get()); + helper_->exposure(deviceStatus->frameLength, mode_.minLineLength).get()); if (deviceStatus->sensorTemperature) libcameraMetadata_.set(controls::SensorTemperature, *deviceStatus->sensorTemperature); } @@ -1106,7 +1106,7 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls) int32_t gainCode = sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get(); int32_t vblank = sensorControls.get(V4L2_CID_VBLANK).get(); - deviceStatus.shutterSpeed = helper_->exposure(exposureLines); + deviceStatus.shutterSpeed = helper_->exposure(exposureLines, mode_.minLineLength); deviceStatus.analogueGain = helper_->gain(gainCode); deviceStatus.frameLength = mode_.height + vblank; @@ -1198,7 +1198,7 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) /* getVBlanking might clip exposure time to the fps limits. */ Duration exposure = agcStatus->shutterTime; int32_t vblanking = helper_->getVBlanking(exposure, minFrameDuration_, maxFrameDuration_); - int32_t exposureLines = helper_->exposureLines(exposure); + int32_t exposureLines = helper_->exposureLines(exposure, mode_.minLineLength); LOG(IPARPI, Debug) << "Applying AGC Exposure: " << exposure << " (Shutter lines: " << exposureLines << ", AGC requested " From patchwork Thu Oct 6 13:17:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17545 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 C3A92BD16B for ; Thu, 6 Oct 2022 13:18:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8423162D0F; Thu, 6 Oct 2022 15:18:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062280; bh=9uSlBADtPmusFJSy/vPdN6s/sj96SrHKwSF9ge2O8co=; 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=NQ5Zxb0sK7mzVy3PNzU9JXGX+DaGSPzNStIXBOQSiYWuE8ENf1oCRLPFn+Vi8Qw+O GHk7DglZWJqKE7XDkqeKnskI89ZKGVXgNN/PjvsuOr2MeeUODFYVkM90/I+N6m3uFs E1IdUgcMefNDzcPjcwIwylLmtmk/sXnryiaDwvoSyR2RY10hFkyo+sMe9mvIlcu+cQ UQQfW9L5nF00DCp2MrcJGHMcgImk5k+esiYSjXpehqJw013fqEv5onTC4pWE10wum4 O9g/PSB8sYUgQiMSFhiNYDJp3MHhn6Fngm1nIjFRm+nj8KPgNbg1fHoVFzhc20q8JQ DFbuaheJ1r/RQ== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E13762CF1 for ; Thu, 6 Oct 2022 15:17:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="I7y4TiKt"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id a3so2732506wrt.0 for ; Thu, 06 Oct 2022 06:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=+XBEmVpKujqmMA3AqvvSLE7pPeInV6i9gV1hkCZ8g6I=; b=I7y4TiKtk8ZX88umR8aYHoOF36OLjwP7+wPnn5k63FKfRRAv6PATulAKEm4dTgVmM4 FaFqbq9ran1s0jaQLow4TOi2uW5d9RYwGCJJRqe2yMwRNnVIq/Wr5Xkrx1Q4JXRgpE5m StLE3PUpSZlgXEArD8hjTUeBOUL1VBbalEnjucJi5VgQwWfn74KfB0Ym9rEqPeNAHU5v x1pJSknVhL9s5jtQn5099gPVgiadswVliTTq/2Eacoq4EE7+8QJV+TvfTNeyt8LTWgHC Tyb+kSTwOOJvK2YjsmSWgwlhFa1I7912rL5MEdVljq2sCDPsek1HBtpNr16u/5fuFPWe zaiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=+XBEmVpKujqmMA3AqvvSLE7pPeInV6i9gV1hkCZ8g6I=; b=JJnYXOU6lsbou/mWZB9B2KMUzN7LSw10op/Dku1TTfJlwrcgyhT4VLIrnlyEYcM0Qz 9g0HYMsf6utmHg0Sb5/L+gir4dsnPot7t+p7YrBCSytqgVx5nvgUBtwCc5jMi8QLeUEm AScPYaRNvV2PpSuihSK6w+OggN24M/78HLq1MlyZr+x2Tn+nKVLeO+Jsbj/RyH1pZCQX KY9tgunbFZlitzZE5A5pLND+aqGMvs5GrcyUDR1iYDsiqo8qBPeELZBNq1GsY8HNTGQa TaX0bJyigCCZBBIHcn0OIo70InITKgAvSiolJejxa8dBE2N08l1hbIfbSUAbAYAzl4Oh G0yA== X-Gm-Message-State: ACrzQf0KTIlGpwdFvBf9+JlvWUiPdJ7qx8aGPdq1q4eFVx2uqpMm8uit EO9EoOA1VL+npgr8JnSH4/2txRjMPEIRNg== X-Google-Smtp-Source: AMsMyM5F04OaSMiEvjdTtxxjLXCkaqnGIR9EoG6QR6XS8jl8dYZVYlGl9SRFkaUwI/Kfs7eiJenKyQ== X-Received: by 2002:adf:b646:0:b0:221:76eb:b3ba with SMTP id i6-20020adfb646000000b0022176ebb3bamr3082713wre.237.1665062276505; Thu, 06 Oct 2022 06:17:56 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:38 +0100 Message-Id: <20221006131744.5179-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/10] ipa: raspberrypi: Remove initialized_ field from CamHelper 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" Given that the single user of the CamHelper is the Raspberry Pi IPA, the initialized_ field check is unnecessary. Remove the check and the field. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 9 +-------- src/ipa/raspberrypi/cam_helper.h | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index fd3527b94501..45214531626e 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -7,7 +7,6 @@ #include -#include #include #include @@ -41,8 +40,7 @@ CamHelper *CamHelper::create(std::string const &camName) } CamHelper::CamHelper(std::unique_ptr parser, unsigned int frameIntegrationDiff) - : parser_(std::move(parser)), initialized_(false), - frameIntegrationDiff_(frameIntegrationDiff) + : parser_(std::move(parser)), frameIntegrationDiff_(frameIntegrationDiff) { } @@ -63,13 +61,11 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats, uint32_t CamHelper::exposureLines(const Duration exposure, const Duration lineLength) const { - assert(initialized_); return exposure / lineLength; } Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) const { - assert(initialized_); return exposureLines * lineLength; } @@ -80,8 +76,6 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, uint32_t frameLengthMin, frameLengthMax, vblank; uint32_t exposureLines = CamHelper::exposureLines(exposure, mode_.minLineLength); - assert(initialized_); - /* * minFrameDuration and maxFrameDuration are clamped by the caller * based on the limits for the active sensor mode. @@ -110,7 +104,6 @@ void CamHelper::setCameraMode(const CameraMode &mode) parser_->setBitsPerPixel(mode.bitdepth); parser_->setLineLengthBytes(0); /* We use SetBufferSize. */ } - initialized_ = true; } void CamHelper::getDelays(int &exposureDelay, int &gainDelay, diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h index 9b5e602689f3..6771829a56da 100644 --- a/src/ipa/raspberrypi/cam_helper.h +++ b/src/ipa/raspberrypi/cam_helper.h @@ -106,7 +106,6 @@ protected: CameraMode mode_; private: - bool initialized_; /* * Smallest difference between the frame length and integration time, * in units of lines. From patchwork Thu Oct 6 13:17:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17546 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 C390FC3285 for ; Thu, 6 Oct 2022 13:18:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67A9962D12; Thu, 6 Oct 2022 15:18:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062281; bh=LiJykRHySPwMITHpitnktWgOfZ/SebcLk52NJaiBcf4=; 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=O57b42VunBALK7mcc7U1fm/6oDYrjq6se3PIYDqwsCjgalbtILj49xD6c5z4ewk2Q Rd1KArh6iP4hXiNNx8JkQ+a1As59Yr8chFnv7q+suJOZeEp8I2KdfODKBjHRoC2Ty4 nqFhXWKG9tPNxPSXrYvYwaprb3fCG4URZbLkVmWtJa1J2kNAOo5g4BQerfn+RTKu2a kqOOdFDzAjspr/QJn+xPePKVn35mJhfiD6Gg++vEcF99qkSOqYgfbaEpfV9gRaWUJY JJPA/Oxl1DOeZ3uuSkZBn0jJhGN+ZcmjXd/mYUtf4tL//bQlYHh7JLeysIdjShOJi7 f9GF0dFi8IIgw== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF74A62CF1 for ; Thu, 6 Oct 2022 15:17:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="B2ewzxDV"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id j7so2695203wrr.3 for ; Thu, 06 Oct 2022 06:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=3A80b1nsNT2hQAo3ttEhnCdEVBVLiw4c2Pt97Cf+Zds=; b=B2ewzxDVtVP/tfhkO2vOO4/HcCPCU5BloHFnti2+5oUefgfBVb4WZz5neqpitKZV8h xHqDM8KOdWzJkpNyd21fFXL/PIEIL710vk0YJewuxQjTh1RWjoSNCIhwbAhghPDzCYDW S/i7tQudc6pDkTd/1mJzdblmDbIC8cL+C+SKA2DIjllIgkUlfjoZP1/gkTV7iHp2PZq3 3LwHFiSqr3D2vAs0I/7dfL5i23WJbxMy91/P2JezCM5kYIas7lhhKcFLPbiZGs+PlatI bU7H1hzFT/SNoXMQ87oHIgZ/Z6ZpPu0DnEpIIt2Hapd3tTVakqECOEr7MYoFbIAWDsAa M/2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=3A80b1nsNT2hQAo3ttEhnCdEVBVLiw4c2Pt97Cf+Zds=; b=odwIpT7woJOdcG3trAsY/do8TkW3Sn2qLsz6MQ1asPZE1V0bOcX5q/w7Qh/5SE1/lP E+zsdacKrOzBmTle5u7mQtr/CM1d1eshPLo0+SqRkfNLdzWdDBcFW3Po/4u3oKeAh4Jg XQk4uF/ugOb2qsdUA+4DA8tCmmw0GbwyfrxFCyatm2ZrspJH2iEueq1Cxmd5dRHlFaeL BRQuPYyg+HkTzX/NvpJ1jF+XLEnSicCU5IJbx/t5tkLXBtxLtZQZAXmQKWBtjDUa0DSS 6X0Z+x7UhLiEN5BGgnQ7HBLPJ+WN8SKzyV6wnf/RSpOivdPcevsY+4JvLz36vEynUKOW 1yoA== X-Gm-Message-State: ACrzQf1VsOkqGwFTVK6a8zQUr6bn6cY99fTNc57nUh9KNZ/xu4JpmAbw sPFhQdCgiLwEWQObvkqPzSklJSi0Qf9cLQ== X-Google-Smtp-Source: AMsMyM7n8MDXVQefyKPdgaZajwWIzILh1oOg1jou6jVKz0Pa6yxpbAjdBJk3HZY7WE5/MiR9jcZQyw== X-Received: by 2002:a5d:65c4:0:b0:22c:dbdd:7177 with SMTP id e4-20020a5d65c4000000b0022cdbdd7177mr3053983wrw.470.1665062277356; Thu, 06 Oct 2022 06:17:57 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:56 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:39 +0100 Message-Id: <20221006131744.5179-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/10] pipeline: ipa: raspberrypi: Add HBLANK control to DelayedControls 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" Update CamHelper::getDelays() to return the sensor HBLANK delay. The HBLANK delay is set to the same value as VBLANK delay for all sensors in the Raspberry Pi IPA. Return the HBLANK gain delay from the IPA to the pipeline handler, and initialise DelayedControls to handle V4L2_CID_HBLANK with this delay value. As a drive-by, check that the V4L2_CID_HBLANK control is available when calling IPARPi::configure(). Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- include/libcamera/ipa/raspberrypi.mojom | 1 + src/ipa/raspberrypi/cam_helper.cpp | 3 ++- src/ipa/raspberrypi/cam_helper.h | 2 +- src/ipa/raspberrypi/cam_helper_imx290.cpp | 5 +++-- src/ipa/raspberrypi/cam_helper_imx296.cpp | 6 ++++-- src/ipa/raspberrypi/cam_helper_imx477.cpp | 5 +++-- src/ipa/raspberrypi/cam_helper_imx519.cpp | 5 +++-- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 5 +++-- src/ipa/raspberrypi/cam_helper_ov9281.cpp | 5 +++-- src/ipa/raspberrypi/raspberrypi.cpp | 6 ++++-- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 1 + 11 files changed, 28 insertions(+), 16 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index c0de435b7b33..40f78d9e3b3f 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -23,6 +23,7 @@ struct SensorConfig { uint32 gainDelay; uint32 exposureDelay; uint32 vblankDelay; + uint32 hblankDelay; uint32 sensorMetadata; }; diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index 45214531626e..dd7236f1b693 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -107,7 +107,7 @@ void CamHelper::setCameraMode(const CameraMode &mode) } void CamHelper::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { /* * These values are correct for many sensors. Other sensors will @@ -116,6 +116,7 @@ void CamHelper::getDelays(int &exposureDelay, int &gainDelay, exposureDelay = 2; gainDelay = 1; vblankDelay = 2; + hblankDelay = 2; } bool CamHelper::sensorEmbeddedDataPresent() const diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h index 6771829a56da..db2387afc993 100644 --- a/src/ipa/raspberrypi/cam_helper.h +++ b/src/ipa/raspberrypi/cam_helper.h @@ -88,7 +88,7 @@ public: virtual uint32_t gainCode(double gain) const = 0; virtual double gain(uint32_t gainCode) const = 0; virtual void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const; + int &vblankDelay, int &hblankDelay) const; virtual bool sensorEmbeddedDataPresent() const; virtual double getModeSensitivity(const CameraMode &mode) const; virtual unsigned int hideFramesStartup() const; diff --git a/src/ipa/raspberrypi/cam_helper_imx290.cpp b/src/ipa/raspberrypi/cam_helper_imx290.cpp index 25f23d531c72..7d6f5b549a73 100644 --- a/src/ipa/raspberrypi/cam_helper_imx290.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx290.cpp @@ -18,7 +18,7 @@ public: uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const override; + int &vblankDelay, int &hblankDelay) const override; unsigned int hideFramesModeSwitch() const override; private: @@ -46,11 +46,12 @@ double CamHelperImx290::gain(uint32_t gainCode) const } void CamHelperImx290::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { exposureDelay = 2; gainDelay = 2; vblankDelay = 2; + hblankDelay = 2; } unsigned int CamHelperImx290::hideFramesModeSwitch() const diff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp index d86ff3878983..ecb845e76e12 100644 --- a/src/ipa/raspberrypi/cam_helper_imx296.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp @@ -23,7 +23,8 @@ public: double gain(uint32_t gainCode) const override; uint32_t exposureLines(const Duration exposure, const Duration lineLength) const override; Duration exposure(uint32_t exposureLines, const Duration lineLength) const override; - void getDelays(int &exposureDelay, int &gainDelay, int &vblankDelay) const override; + void getDelays(int &exposureDelay, int &gainDelay, + int &vblankDelay, int &hblankDelay) const override; private: static constexpr uint32_t minExposureLines = 1; @@ -66,11 +67,12 @@ Duration CamHelperImx296::exposure(uint32_t exposureLines, } void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { exposureDelay = 2; gainDelay = 2; vblankDelay = 2; + hblankDelay = 2; } static CamHelper *create() diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 71529bdd3034..76a82cc51378 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -49,7 +49,7 @@ public: uint32_t getVBlanking(Duration &exposure, Duration minFrameDuration, Duration maxFrameDuration) const override; void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const override; + int &vblankDelay, int &hblankDelay) const override; bool sensorEmbeddedDataPresent() const override; private: @@ -153,11 +153,12 @@ uint32_t CamHelperImx477::getVBlanking(Duration &exposure, } void CamHelperImx477::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { exposureDelay = 2; gainDelay = 2; vblankDelay = 3; + hblankDelay = 3; } bool CamHelperImx477::sensorEmbeddedDataPresent() const diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp index 2c120dad1680..9dff1eeb899f 100644 --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp @@ -49,7 +49,7 @@ public: uint32_t getVBlanking(Duration &exposure, Duration minFrameDuration, Duration maxFrameDuration) const override; void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const override; + int &vblankDelay, int &hblankDelay) const override; bool sensorEmbeddedDataPresent() const override; private: @@ -153,11 +153,12 @@ uint32_t CamHelperImx519::getVBlanking(Duration &exposure, } void CamHelperImx519::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { exposureDelay = 2; gainDelay = 2; vblankDelay = 3; + hblankDelay = 3; } bool CamHelperImx519::sensorEmbeddedDataPresent() const diff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp index 04fb725d42db..5a99083dee78 100644 --- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp @@ -18,7 +18,7 @@ public: uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const override; + int &vblankDelay, int &hblankDelay) const override; unsigned int hideFramesStartup() const override; unsigned int hideFramesModeSwitch() const override; unsigned int mistrustFramesStartup() const override; @@ -53,7 +53,7 @@ double CamHelperOv5647::gain(uint32_t gainCode) const } void CamHelperOv5647::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { /* * We run this sensor in a mode where the gain delay is bumped up to @@ -62,6 +62,7 @@ void CamHelperOv5647::getDelays(int &exposureDelay, int &gainDelay, exposureDelay = 2; gainDelay = 2; vblankDelay = 2; + hblankDelay = 2; } unsigned int CamHelperOv5647::hideFramesStartup() const diff --git a/src/ipa/raspberrypi/cam_helper_ov9281.cpp b/src/ipa/raspberrypi/cam_helper_ov9281.cpp index 66f56a31e1b8..86c5bc4c8fda 100644 --- a/src/ipa/raspberrypi/cam_helper_ov9281.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov9281.cpp @@ -18,7 +18,7 @@ public: uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const override; + int &vblankDelay, int &hblankDelay) const override; private: /* @@ -49,12 +49,13 @@ double CamHelperOv9281::gain(uint32_t gainCode) const } void CamHelperOv9281::getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const + int &vblankDelay, int &hblankDelay) const { /* The driver appears to behave as follows: */ exposureDelay = 2; gainDelay = 2; vblankDelay = 2; + hblankDelay = 2; } static CamHelper *create() diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 13807f4d47f7..9b0ad4361c97 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -219,13 +219,14 @@ int IPARPi::init(const IPASettings &settings, IPAInitResult *result) * Pass out the sensor config to the pipeline handler in order * to setup the staggered writer class. */ - int gainDelay, exposureDelay, vblankDelay, sensorMetadata; - helper_->getDelays(exposureDelay, gainDelay, vblankDelay); + int gainDelay, exposureDelay, vblankDelay, hblankDelay, sensorMetadata; + helper_->getDelays(exposureDelay, gainDelay, vblankDelay, hblankDelay); sensorMetadata = helper_->sensorEmbeddedDataPresent(); result->sensorConfig.gainDelay = gainDelay; result->sensorConfig.exposureDelay = exposureDelay; result->sensorConfig.vblankDelay = vblankDelay; + result->sensorConfig.hblankDelay = hblankDelay; result->sensorConfig.sensorMetadata = sensorMetadata; /* Load the tuning file for this sensor. */ @@ -607,6 +608,7 @@ bool IPARPi::validateSensorControls() V4L2_CID_ANALOGUE_GAIN, V4L2_CID_EXPOSURE, V4L2_CID_VBLANK, + V4L2_CID_HBLANK, }; for (auto c : ctrls) { diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index bcb5bb8a1e73..61997326f7f9 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1289,6 +1289,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me std::unordered_map params = { { V4L2_CID_ANALOGUE_GAIN, { result.sensorConfig.gainDelay, false } }, { V4L2_CID_EXPOSURE, { result.sensorConfig.exposureDelay, false } }, + { V4L2_CID_HBLANK, { result.sensorConfig.hblankDelay, false } }, { V4L2_CID_VBLANK, { result.sensorConfig.vblankDelay, true } } }; data->delayedCtrls_ = std::make_unique(data->sensor_->device(), params); From patchwork Thu Oct 6 13:17:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17547 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 4F175C327C for ; Thu, 6 Oct 2022 13:18:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F0FD362D0C; Thu, 6 Oct 2022 15:18:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062282; bh=croap5DWWumQWm5xG/4E66jcarVh+wYhdqBHyVroOeg=; 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=xrKW8tAgrM8w53uGbyHyOmH44LnjJyFU48/Eg0vRCJiZyopuDTGgej608vWIIfUer prW6TlN3JZGieYM8/fgiUIP1lB6RLaG/V4bYzkz3Ot41PispvuaiQFX5JBglw4o2re PXRRDUSmLU+/aavbVTITtKob0r+7Q4+2cfHz6Z/BpvnOiN+Ab6ji7mW6SJvFiPQFwc KvFU5SJ/FTXIDtZbpyMAzcZPaTn1K82P+1XIeR3wlZlWge8asYMZsBYvEkMv3gSq2g H0lh8uJd0NF9+4Vrv3hhmGmmzByElL8AK4H+qlotakyobh/iJmwmnbYRFHYrlqvfWe ZE5mgObtz5MqQ== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B6A9B62D07 for ; Thu, 6 Oct 2022 15:17:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="L5arwjAL"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id bq9so2690912wrb.4 for ; Thu, 06 Oct 2022 06:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=JOQILjSzgUd1k716q1AvO/aSMegCkdXz5al8107hheU=; b=L5arwjAL3FYL/qNzxLS7rntNBHYlyy1kKIL35bobR9+Uai76O4fPbybFU6ZO/KlnRo kJr8qEpPSwL47smbvQc+DTRSWQS8oIYG+uqR9/j0/pfBBcGlj/OSNTADoLhvnEMO4zTF mU4m7Q1XVB3WW22dVYAONNcyRenm1kTgrD5m9nXuM/7QbaQlsiZpA/n+ktmfXf7bonfP tzS/PU7tMHdHYC+ba3AA1Ze6Jy6r1wvOW1KNSal7dmpKoJddhcwaRqh9UeKMFINlLDnc ZWPVGfRMM80bwMnI3joJ/PNJqvWeG8GYWFu6ALWy0pyEcr1GJiimsZFShOWdIhG5OIX7 HXPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=JOQILjSzgUd1k716q1AvO/aSMegCkdXz5al8107hheU=; b=FSonuhZAXKw8du+twO6mbp+8vL7k+7RiXMCzV3c64GqS6hpyzs+TmzkRoEDbJHw82D v99rPvpR5IeyvJ/UMGDXW+66M6zXL72yd+npayHRZT6XrhOVwLb23qmaVKRkuVNUIOdY xXdmFm3shUbWa3RgKelhAlzd9jn9Dl5rLXoxEcDqvo6FC3Usq7a0qSJ+3ecHpQFg4i/F VWNj7fnGHJEEVoa/AmLTJ+yZFjPgExmG27P4KfAdAUIs2HHDVrD9TR9LoRFeVjD25FwY xDKYMc3wzNb33WRwlWAx7y92BqFNGF9gIc6UzFbqLr+AAEwb2zFQV31gE3xjywZGEqnc DcaQ== X-Gm-Message-State: ACrzQf3l25iBFoZikM04zFN8UDRZxAcpM/YrA6k9xJqCVb0bGATb+bKd we46g1HW0ZtYVx0TOVtegfVYXeGfXmKizA== X-Google-Smtp-Source: AMsMyM4LHbxeGgBE/WXpQJJlNvR3KmP3UVN26n5uWByA9AsvjeONDxMkLO7KaTBNyzReSMXW5HgGBQ== X-Received: by 2002:adf:ebc6:0:b0:22a:c5ee:b057 with SMTP id v6-20020adfebc6000000b0022ac5eeb057mr3235042wrn.317.1665062278330; Thu, 06 Oct 2022 06:17:58 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:40 +0100 Message-Id: <20221006131744.5179-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/10] ipa: raspberrypi: Add pixel clock rate to the CameraMode structure 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" The pixel clock rate will be used in subsequent commits to calculate line length durations. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/camera_mode.h | 2 ++ src/ipa/raspberrypi/raspberrypi.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h index 6bc35b771946..4cd9712e8c19 100644 --- a/src/ipa/raspberrypi/controller/camera_mode.h +++ b/src/ipa/raspberrypi/controller/camera_mode.h @@ -46,4 +46,6 @@ struct CameraMode { uint32_t maxFrameLength; /* sensitivity of this mode */ double sensitivity; + /* pixel clock rate */ + uint64_t pixelRate; }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 9b0ad4361c97..b6289f151677 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -331,6 +331,7 @@ void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo) mode_.sensorHeight = sensorInfo.activeAreaSize.height; mode_.cropX = sensorInfo.analogCrop.x; mode_.cropY = sensorInfo.analogCrop.y; + mode_.pixelRate = sensorInfo.pixelRate; /* * Calculate scaling parameters. The scale_[xy] factors are determined From patchwork Thu Oct 6 13:17:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17548 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 EBDA2C3286 for ; Thu, 6 Oct 2022 13:18:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8751B62D19; Thu, 6 Oct 2022 15:18:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062282; bh=oIfN2bhrPLhi8sqa1hMKCz/V8u/e6tzLk1rhkG5IU8A=; 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=NilKDrt8PzOgewSn25n9Z94x8UyyrYDI+pUfUpGYyE1Ti2BsdHXL+0RviRGuIfkME LLcrGcUvt6/SGMIlGBPzfs4noth+8JYoLEkj3QpJQz5WkViSJUFupWAf9ljvJsFl4M RZkAfLKLJKEmFBps9iFXdkZEME6ocivv6bam1rsCiKmk7cQ79TINOFQ2dD/pL/m4o1 ItspwwwMJyTs/2RHpyO5hUCQvnC+gGbbRoChV5EqVKimUzdpihes+F5MeKaaCnAUaV jHPfIrckwo0WR7c0IiJiJElF8jW5/esv1WEmk0HU1JG1aGrR3CuvKb/MDyTz0Ftzhw UZ2z9eL9srR3w== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ABF5162CFE for ; Thu, 6 Oct 2022 15:17:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qSEQP85D"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id ay36so1036626wmb.0 for ; Thu, 06 Oct 2022 06:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=0Gqu8R6R2OicBQ0UOmq1eJlfI5JuYCILNc7IuRsY9DU=; b=qSEQP85D9R08Pc9h7eXgjuwRWW4NEpyKtjOP0NkdbrNi/3JUtSKZvQ4W1FEq2LUy7k dHd5ggvslsLq+yf3OK8FAEYFqWIRcOGouQoWIkG8JTqYJFoVwmLc+40DSunAVhAtp03u mdBePH89NxpKHVqFJdYkzkacZPK+HGfcmyRG6t166s6OMo1odszbjtbwZJk7N3lJL9H0 p4YwFyMHyleK4X7rXBMDi8ssxVg1J7LbUvSUpuT/uulvKb7wODKscjmorMV2bKEzHSf9 hEPWJoCCO9OGjdcpON+7WZdGN2gN7USQEw2yLR0IPI/q0aWhS3hTU2D7J6IuGsQ2ksmK Ge4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=0Gqu8R6R2OicBQ0UOmq1eJlfI5JuYCILNc7IuRsY9DU=; b=Eer5X9Um0S2F1aQcTvLaFCiVJRJ218dVKe6ex6QWVQ57NT2G9Mc7rEob65kPb/g30j WyhLmixP7HiU/mJ37s6mWfipbNNzcOzFv4Z9TImtZiWzusD5K99boGHj9C2FOlAVg9+Q 9WX9QIU/qkKsp6b5sTFVA7TpArp39Mnc+7NzEduvThJBZWDn3GhUCVppkc0h9u27jS+h 1TDbwsCGknri69zmsi2Hk2j/QDHBjRBOfOodxY/WY1HgKG1sH3YrSIMaPJF3w3Md0Ih4 bBdIV7FHzkJ41yr0WVlV0IwrQf55SKRSYBc1boLTCQeSLVOxHTtkr2T2EHF4y3cFsCzE 3V1g== X-Gm-Message-State: ACrzQf0lH/m+7Fkf7fVcZS8wFtPVxrErGDXM6s23DbxfW1v/u5T2iUH7 pyo0ojHM1HHhR15CwmBm+L5qDxh6vYJcig== X-Google-Smtp-Source: AMsMyM6FNtWm2EmWPbKqs1q0SSGP+qneP6mxBf/7CzIB+AfT72MvyhzXYmNckUxcJ3OXmZhLHTky4Q== X-Received: by 2002:a05:600c:4109:b0:3c1:b50e:b5ea with SMTP id j9-20020a05600c410900b003c1b50eb5eamr2216117wmi.71.1665062279154; Thu, 06 Oct 2022 06:17:59 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:41 +0100 Message-Id: <20221006131744.5179-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/10] ipa: raspberrypi: Add line length calculations helper functions 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" Add CamHelper::hblankToLineLength() to calculate the line length duration from the horizontal blanking (in pixels) value. Add CamHelper::lineLengthToHblank() to calculate the horizontal blanking (in pixels) value from the line length duration. Add CamHelper::lineLengthPckToDuration() to calculate the line length duration from the line length in pixels. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 16 ++++++++++++++++ src/ipa/raspberrypi/cam_helper.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index dd7236f1b693..bc3f66a51254 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -18,6 +18,7 @@ using namespace RPiController; using namespace libcamera; using libcamera::utils::Duration; +using namespace std::literals::chrono_literals; namespace libcamera { LOG_DECLARE_CATEGORY(IPARPI) @@ -96,6 +97,21 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, return vblank; } +Duration CamHelper::hblankToLineLength(uint32_t hblank) const +{ + return (mode_.width + hblank) * (1.0s / mode_.pixelRate); +} + +uint32_t CamHelper::lineLengthToHblank(const Duration &lineLength) const +{ + return (lineLength * mode_.pixelRate / 1.0s) - mode_.width; +} + +Duration CamHelper::lineLengthPckToDuration(uint32_t lineLengthPck) const +{ + return lineLengthPck * (1.0s / mode_.pixelRate); +} + void CamHelper::setCameraMode(const CameraMode &mode) { mode_ = mode; diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h index db2387afc993..6cd1dd397b91 100644 --- a/src/ipa/raspberrypi/cam_helper.h +++ b/src/ipa/raspberrypi/cam_helper.h @@ -85,6 +85,9 @@ public: virtual uint32_t getVBlanking(libcamera::utils::Duration &exposure, libcamera::utils::Duration minFrameDuration, libcamera::utils::Duration maxFrameDuration) const; + libcamera::utils::Duration hblankToLineLength(uint32_t hblank) const; + uint32_t lineLengthToHblank(const libcamera::utils::Duration &duration) const; + libcamera::utils::Duration lineLengthPckToDuration(uint32_t lineLengthPck) const; virtual uint32_t gainCode(double gain) const = 0; virtual double gain(uint32_t gainCode) const = 0; virtual void getDelays(int &exposureDelay, int &gainDelay, From patchwork Thu Oct 6 13:17:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17549 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 A8A7FBD16B for ; Thu, 6 Oct 2022 13:18:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 619E362D17; Thu, 6 Oct 2022 15:18:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062283; bh=xNTg8MgDbCgc7QoFbf3h9gdIw6XzNr2e/f8yNDHlKGY=; 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=cDedvTxq2jtnO6+49Pay0Fir1W4/W7yDVCmMBy0MgnqxhLrw/LZeUtSS2CcqNPvi0 lPNQrgz2Z90Ek4ceBWC8IuiS9x6YDXKlqUAt2QPOvLGMCr8T8zHu4DzLbXn2z+g93r iVSDArY2jgjFcZouGf18u0LWFS5PchYwAbPlyY96qazIr82Xd3+SJr6vneYGODLcEo iZjjxeikkdWqzv1o043tk7YlIUeWdXvhpPYtlY5bRfi226sR7rMyfeOYBf/Y7fX/hr 75J3eN4lm4d+Yya/mEbzDGnCkp1DGP0gaPeGDBfs32kioL2BxlosXYJ5sCuse9ERKV Ct4UxvoUzuhuw== Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7525A62D0E for ; Thu, 6 Oct 2022 15:18:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="NdoEIFPy"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id bk15so2645600wrb.13 for ; Thu, 06 Oct 2022 06:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=EYXhUS5A+XqtUQmt61JKtz8Dby+AR9H2er9xdgsAi7Y=; b=NdoEIFPyLUZXHL9ZUGBg0SLLDunCZtHB1i3C1vRGincHYKNaNTXMI2QN+eBURFiDWX VLgcXmQQsU69Vc70cdZlpMoQGK9NDSR6uNkQQbVJd79ZJa7ddX4drXFB2lKOjJ29/VYO CW2lCib7RDUDv5as/xd1oBZZYcJfTb7sejHWc2hSzvhSLjdCzZHiirGxuXjOeMtFP0qT BZIh6GWzqdut82mHj2NKco3UkHv6g+gWevjWzvMqdDU8Knw+QfddPBt+X2nauPFbX1VV kZ4Kozq7y7exM5haCu+r9LI1Chy1ox245ErK+ll4yTxPyk41GQcmsiBp3h8LIyhfxcR7 2RNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=EYXhUS5A+XqtUQmt61JKtz8Dby+AR9H2er9xdgsAi7Y=; b=YcZwjcJsqrlUbWKDPK3eQUsMCPP+vm6X2n4L+ZqeiwKXh1eIV6QlDkRThBymsxT9O5 0PlewRdG/HDKgHzFV0BCbRllnQewkNdGAXHXxfxIAKplcMhJJbW6Md/Fb5u3wA3lmoD5 HTgo5hcKZQT+Q4ENrPWQ+WQeAdbwjTF9O9HEpMzHLv6gjHOE/qRoCXLexsW7lyjW58ns ucOTzJyh40wlFDE6r+/vEwZWrl2Q8hu2V7Rws0dWURveinY7Ht2jSakE2ooVK7sYvG6E 2xOwMfDYPOoXW6GTrtsvqKvfATf/jdZ5VqmnAxUhhKLBpEI5/y1Oyj08twtpzB0HkZM/ j6fw== X-Gm-Message-State: ACrzQf3gKcbv/GY1aN/jMrl4uuChIunuOcvsiy7izPFqH3ZT9ylpUMru cfAXf2/cSFCUp007tFK7ME8gPxL7puALyw== X-Google-Smtp-Source: AMsMyM4qxrv9oyeyPFk05yg59KneACuA8rpS6HGZzt89m3ROiQ8EGwcx946CgZ/dpzWaua6Osyxt/Q== X-Received: by 2002:a05:6000:10cc:b0:22e:39a:efe4 with SMTP id b12-20020a05600010cc00b0022e039aefe4mr3287997wrx.256.1665062279903; Thu, 06 Oct 2022 06:17:59 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:42 +0100 Message-Id: <20221006131744.5179-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/10] ipa: raspberrypi: Add line length to DeviceStatus 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" Add a lineLength field to the DeviceStatus structure to store the line length used for a particular frame. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/device_status.cpp | 1 + src/ipa/raspberrypi/controller/device_status.h | 4 +++- src/ipa/raspberrypi/raspberrypi.cpp | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/controller/device_status.cpp b/src/ipa/raspberrypi/controller/device_status.cpp index 2360a77bf1ea..c907efdd7511 100644 --- a/src/ipa/raspberrypi/controller/device_status.cpp +++ b/src/ipa/raspberrypi/controller/device_status.cpp @@ -12,6 +12,7 @@ std::ostream &operator<<(std::ostream &out, const DeviceStatus &d) { out << "Exposure: " << d.shutterSpeed << " Frame length: " << d.frameLength + << " Line length: " << d.lineLength << " Gain: " << d.analogueGain; if (d.aperture) diff --git a/src/ipa/raspberrypi/controller/device_status.h b/src/ipa/raspberrypi/controller/device_status.h index 8f74e21b0c6e..4384c2149589 100644 --- a/src/ipa/raspberrypi/controller/device_status.h +++ b/src/ipa/raspberrypi/controller/device_status.h @@ -19,7 +19,7 @@ struct DeviceStatus { DeviceStatus() : shutterSpeed(std::chrono::seconds(0)), frameLength(0), - analogueGain(0.0) + lineLength(std::chrono::seconds(0)), analogueGain(0.0) { } @@ -29,6 +29,8 @@ struct DeviceStatus { libcamera::utils::Duration shutterSpeed; /* frame length given in number of lines */ uint32_t frameLength; + /* line length for the current frame */ + libcamera::utils::Duration lineLength; double analogueGain; /* 1.0/distance-in-metres, or 0 if unknown */ std::optional lensPosition; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index b6289f151677..c8e15f2b04d1 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1108,7 +1108,9 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls) int32_t exposureLines = sensorControls.get(V4L2_CID_EXPOSURE).get(); int32_t gainCode = sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get(); int32_t vblank = sensorControls.get(V4L2_CID_VBLANK).get(); + int32_t hblank = sensorControls.get(V4L2_CID_HBLANK).get(); + deviceStatus.lineLength = helper_->hblankToLineLength(hblank); deviceStatus.shutterSpeed = helper_->exposure(exposureLines, mode_.minLineLength); deviceStatus.analogueGain = helper_->gain(gainCode); deviceStatus.frameLength = mode_.height + vblank; From patchwork Thu Oct 6 13:17:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17550 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 14F46C3285 for ; Thu, 6 Oct 2022 13:18:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC3B762D1D; Thu, 6 Oct 2022 15:18:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062284; bh=RaIKxvybGoMB6uAP+wjjb5iTqt8PQwKcl9SA0mP5u3c=; 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=QhGlIONnrTV2R6Y1pU8TYXT/Lz/bDx3zayfXilgCvEnW+dzfsXPXm2m5a8vsvlA2i 1YEkGz3i83ps9OiDN+knjUwReqEOkCqAzziwmnxOwulc+apuD8LEsf3ktiWAdzVrp3 xS4qpb5CCpH7x556ii2Qu6VMMc5o8wyxMNqE1ZTCeUoOCFJSjkJQ5YHeGCdgUAKfzy 8N7anukn2UUV2XshDvyEMPOxmcBEbAMZW8SMkohabL8nKhB2y84aSuduQKVknfeDtm IsjrZ9vqDFfQPpJ0L4Q9l0JKAT/pKsUcNJ0G2cJbI0WONI9knnJexmShcJ+ftSd7DH 89q7m8k1cvkIg== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B1F2562D01 for ; Thu, 6 Oct 2022 15:18:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="DA/9McNz"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id n12so2660416wrp.10 for ; Thu, 06 Oct 2022 06:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=pxt6/tficOHsXFhXoILdAkU3b46HFC2Yc7SPtUOfGUU=; b=DA/9McNzdysz9ndqo/752Q2lKXybKiWHqVlG4PlwXUv/0Cv3lEZYcs64RiX3zAUyki cQLEVDjw0cN3Ajs7UFychTFwUhRf2tkjlTd+SPBU1fS12RT5I4zCIIVMkqI9MWEAd9e5 xCpFar8HBy+ZuGwQ2pqQTBtS4gpJ06Be2vuXoKod6WM7z5+xhMWIkPYizkKa4EPp/sAZ E8A7uKa10FM2gCxvdWwbH1e5Ioj/G024IB6b1+hrrrWPQXyRgiGhvX1lnRSoSFODxmrw EGOK+wFH4/VEMOvGibuE7ORwNT5uQ8IUwiGD5As/2WJhPefzacCL3qaV8ksIn7TwN72H XMiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=pxt6/tficOHsXFhXoILdAkU3b46HFC2Yc7SPtUOfGUU=; b=YNWS5cGRDjtUcQw3XxCzMyfb7B2pqoNEmJSEVR2EB+cu5y+/HB+N7qI7K/fzWJhChf 0kiQK9k1mnM9kb604MD5RlchfwPbsp+Zl9H09TErO1Ym+n0O5Mk40bOej0OB2INf8CP3 NsqVXglFSztN3d5vhLWP/PT6pit+O8ZSY6IchNc45nKG+c2syUbGubiQWbrg41mdUoXN h0o7Sfm5XWohMp872J5Bo/904rULTBw3gL1NuoDr6KIY/X8JTt16nM+a7GCunz/R6Vgy N7nZDUOcGib0ROIMyYjePrpD1EDqRarb74uphncVgJUIoLqoAiKQj6EQZyTASV7g3HEj NWvw== X-Gm-Message-State: ACrzQf2GKqeXCt+9Zo6qHs/T45vjJYepkPeHlGnsjwzaWGFhW27EbBNr +4eCidrwevJ7mXujxCHKxgwcz62bTVyT1w== X-Google-Smtp-Source: AMsMyM4GT4jgw3FdTxV5hZQF3BAuB4piT3dHmSFWnchmj8ERKYH41sW+tFVDkovhdb/Z5bgwcgVB3g== X-Received: by 2002:a5d:688f:0:b0:22c:df1c:92cd with SMTP id h15-20020a5d688f000000b0022cdf1c92cdmr3314057wru.52.1665062280747; Thu, 06 Oct 2022 06:18:00 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:18:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:43 +0100 Message-Id: <20221006131744.5179-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/10] ipa: raspberrypi: Allow full line length control 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" Rename CamHelper::getVBlanking to CamHelper::getBlanking, and update the calculations in that function to return both horizontal and vertical blanking values for a given exposure time and frame duration limits. The calculations are setup such that vertical blanking is extended to the maximum allowable value, and any remainder gets put into horizontal blanking. The calculated horizontal blanking value is now returned to the pipeline handler to pass into DelayedControls to program into the sensor. Update the IPA to now specify the maximum frame duration from the maximum horizontal + vertical blanking values provided by the sensor mode. Additionally, the IPA now uses the frame specific horizontal blanking value (as returned by DelayedControls) in all instances. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 48 +++++++++++++++++------ src/ipa/raspberrypi/cam_helper.h | 7 ++-- src/ipa/raspberrypi/cam_helper_imx477.cpp | 24 +++++++----- src/ipa/raspberrypi/cam_helper_imx519.cpp | 24 +++++++----- src/ipa/raspberrypi/raspberrypi.cpp | 43 ++++++++++++-------- 5 files changed, 95 insertions(+), 51 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index bc3f66a51254..afbc03d36b02 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -7,6 +7,7 @@ #include +#include #include #include @@ -70,31 +71,56 @@ Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) return exposureLines * lineLength; } -uint32_t CamHelper::getVBlanking(Duration &exposure, - Duration minFrameDuration, - Duration maxFrameDuration) const +std::pair CamHelper::getBlanking(Duration &exposure, + Duration minFrameDuration, + Duration maxFrameDuration) const { - uint32_t frameLengthMin, frameLengthMax, vblank; - uint32_t exposureLines = CamHelper::exposureLines(exposure, mode_.minLineLength); + uint32_t frameLengthMin, frameLengthMax, vblank, hblank; + Duration lineLength = mode_.minLineLength; /* * minFrameDuration and maxFrameDuration are clamped by the caller * based on the limits for the active sensor mode. + * + * frameLengthMax gets calculated on the smallest line length as we do + * not want to extend that unless absolutely necessary. */ frameLengthMin = minFrameDuration / mode_.minLineLength; frameLengthMax = maxFrameDuration / mode_.minLineLength; + /* + * Watch out for (exposureLines + frameIntegrationDiff_) overflowing a + * uint32_t in the std::clamp() below when the exposure time is + * extremely (extremely!) long - as happens when the IPA calculates the + * maximum possible exposure time. + */ + uint32_t exposureLines = std::min(CamHelper::exposureLines(exposure, lineLength), + std::numeric_limits::max() - frameIntegrationDiff_); + uint32_t frameLengthLines = std::clamp(exposureLines + frameIntegrationDiff_, + frameLengthMin, frameLengthMax); + + /* + * If our frame length lines is above the maximum allowed, see if we can + * extend the line length to accommodate the requested frame length. + */ + if (frameLengthLines > mode_.maxFrameLength) { + Duration lineLengthAdjusted = lineLength * frameLengthLines / mode_.maxFrameLength; + lineLength = std::min(mode_.maxLineLength, lineLengthAdjusted); + frameLengthLines = mode_.maxFrameLength; + } + + hblank = lineLengthToHblank(lineLength); + vblank = frameLengthLines - mode_.height; + /* * Limit the exposure to the maximum frame duration requested, and * re-calculate if it has been clipped. */ - exposureLines = std::min(frameLengthMax - frameIntegrationDiff_, exposureLines); - exposure = CamHelper::exposure(exposureLines, mode_.minLineLength); + exposureLines = std::min(frameLengthLines - frameIntegrationDiff_, + CamHelper::exposureLines(exposure, lineLength)); + exposure = CamHelper::exposure(exposureLines, lineLength); - /* Limit the vblank to the range allowed by the frame length limits. */ - vblank = std::clamp(exposureLines + frameIntegrationDiff_, - frameLengthMin, frameLengthMax) - mode_.height; - return vblank; + return { vblank, hblank }; } Duration CamHelper::hblankToLineLength(uint32_t hblank) const diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h index 6cd1dd397b91..b3f8c9803094 100644 --- a/src/ipa/raspberrypi/cam_helper.h +++ b/src/ipa/raspberrypi/cam_helper.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -82,9 +83,9 @@ public: const libcamera::utils::Duration lineLength) const; virtual libcamera::utils::Duration exposure(uint32_t exposureLines, const libcamera::utils::Duration lineLength) const; - virtual uint32_t getVBlanking(libcamera::utils::Duration &exposure, - libcamera::utils::Duration minFrameDuration, - libcamera::utils::Duration maxFrameDuration) const; + virtual std::pair getBlanking(libcamera::utils::Duration &exposure, + libcamera::utils::Duration minFrameDuration, + libcamera::utils::Duration maxFrameDuration) const; libcamera::utils::Duration hblankToLineLength(uint32_t hblank) const; uint32_t lineLengthToHblank(const libcamera::utils::Duration &duration) const; libcamera::utils::Duration lineLengthPckToDuration(uint32_t lineLengthPck) const; diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 76a82cc51378..19a5e471c27e 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -46,8 +46,8 @@ public: uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; void prepare(libcamera::Span buffer, Metadata &metadata) override; - uint32_t getVBlanking(Duration &exposure, Duration minFrameDuration, - Duration maxFrameDuration) const override; + std::pair getBlanking(Duration &exposure, Duration minFrameDuration, + Duration maxFrameDuration) const override; void getDelays(int &exposureDelay, int &gainDelay, int &vblankDelay, int &hblankDelay) const override; bool sensorEmbeddedDataPresent() const override; @@ -118,15 +118,19 @@ void CamHelperImx477::prepare(libcamera::Span buffer, Metadata &m } } -uint32_t CamHelperImx477::getVBlanking(Duration &exposure, - Duration minFrameDuration, - Duration maxFrameDuration) const +std::pair CamHelperImx477::getBlanking(Duration &exposure, + Duration minFrameDuration, + Duration maxFrameDuration) const { uint32_t frameLength, exposureLines; unsigned int shift = 0; - frameLength = mode_.height + CamHelper::getVBlanking(exposure, minFrameDuration, - maxFrameDuration); + auto [vblank, hblank] = CamHelper::getBlanking(exposure, minFrameDuration, + maxFrameDuration); + + frameLength = mode_.height + vblank; + Duration lineLength = hblankToLineLength(hblank); + /* * Check if the frame length calculated needs to be setup for long * exposure mode. This will require us to use a long exposure scale @@ -144,12 +148,12 @@ uint32_t CamHelperImx477::getVBlanking(Duration &exposure, if (shift) { /* Account for any rounding in the scaled frame length value. */ frameLength <<= shift; - exposureLines = CamHelperImx477::exposureLines(exposure, mode_.minLineLength); + exposureLines = CamHelperImx477::exposureLines(exposure, lineLength); exposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff); - exposure = CamHelperImx477::exposure(exposureLines, mode_.minLineLength); + exposure = CamHelperImx477::exposure(exposureLines, lineLength); } - return frameLength - mode_.height; + return { frameLength - mode_.height, hblank }; } void CamHelperImx477::getDelays(int &exposureDelay, int &gainDelay, diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp index 9dff1eeb899f..d2eb171912da 100644 --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp @@ -46,8 +46,8 @@ public: uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; void prepare(libcamera::Span buffer, Metadata &metadata) override; - uint32_t getVBlanking(Duration &exposure, Duration minFrameDuration, - Duration maxFrameDuration) const override; + std::pair getBlanking(Duration &exposure, Duration minFrameDuration, + Duration maxFrameDuration) const override; void getDelays(int &exposureDelay, int &gainDelay, int &vblankDelay, int &hblankDelay) const override; bool sensorEmbeddedDataPresent() const override; @@ -118,15 +118,19 @@ void CamHelperImx519::prepare(libcamera::Span buffer, Metadata &m } } -uint32_t CamHelperImx519::getVBlanking(Duration &exposure, - Duration minFrameDuration, - Duration maxFrameDuration) const +std::pair CamHelperImx519::getBlanking(Duration &exposure, + Duration minFrameDuration, + Duration maxFrameDuration) const { uint32_t frameLength, exposureLines; unsigned int shift = 0; - frameLength = mode_.height + CamHelper::getVBlanking(exposure, minFrameDuration, - maxFrameDuration); + auto [vblank, hblank] = CamHelper::getBlanking(exposure, minFrameDuration, + maxFrameDuration); + + frameLength = mode_.height + vblank; + Duration lineLength = hblankToLineLength(hblank); + /* * Check if the frame length calculated needs to be setup for long * exposure mode. This will require us to use a long exposure scale @@ -144,12 +148,12 @@ uint32_t CamHelperImx519::getVBlanking(Duration &exposure, if (shift) { /* Account for any rounding in the scaled frame length value. */ frameLength <<= shift; - exposureLines = CamHelperImx519::exposureLines(exposure, mode_.minLineLength); + exposureLines = CamHelperImx519::exposureLines(exposure, lineLength); exposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff); - exposure = CamHelperImx519::exposure(exposureLines, mode_.minLineLength); + exposure = CamHelperImx519::exposure(exposureLines, lineLength); } - return frameLength - mode_.height; + return { frameLength - mode_.height, hblank }; } void CamHelperImx519::getDelays(int &exposureDelay, int &gainDelay, diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index c8e15f2b04d1..497a83939ae6 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -315,7 +315,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig) } startConfig->dropFrameCount = dropFrameCount_; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength; + const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; startConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get(); firstStart_ = false; @@ -462,7 +462,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, */ ControlInfoMap::Map ctrlMap = ipaControls; const Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength; - const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength; + const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; ctrlMap[&controls::FrameDurationLimits] = ControlInfo(static_cast(minSensorFrameDuration.get()), static_cast(maxSensorFrameDuration.get())); @@ -475,7 +475,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, * will limit the maximum control value based on the current VBLANK value. */ Duration maxShutter = Duration::max(); - helper_->getVBlanking(maxShutter, minSensorFrameDuration, maxSensorFrameDuration); + helper_->getBlanking(maxShutter, minSensorFrameDuration, maxSensorFrameDuration); const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get(); ctrlMap[&controls::ExposureTime] = @@ -552,7 +552,7 @@ void IPARPi::reportMetadata() deviceStatus->shutterSpeed.get()); libcameraMetadata_.set(controls::AnalogueGain, deviceStatus->analogueGain); libcameraMetadata_.set(controls::FrameDuration, - helper_->exposure(deviceStatus->frameLength, mode_.minLineLength).get()); + helper_->exposure(deviceStatus->frameLength, deviceStatus->lineLength).get()); if (deviceStatus->sensorTemperature) libcameraMetadata_.set(controls::SensorTemperature, *deviceStatus->sensorTemperature); } @@ -1111,7 +1111,7 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls) int32_t hblank = sensorControls.get(V4L2_CID_HBLANK).get(); deviceStatus.lineLength = helper_->hblankToLineLength(hblank); - deviceStatus.shutterSpeed = helper_->exposure(exposureLines, mode_.minLineLength); + deviceStatus.shutterSpeed = helper_->exposure(exposureLines, deviceStatus.lineLength); deviceStatus.analogueGain = helper_->gain(gainCode); deviceStatus.frameLength = mode_.height + vblank; @@ -1157,7 +1157,7 @@ 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_.minLineLength; + const Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength; /* * This will only be applied once AGC recalculations occur. @@ -1178,11 +1178,11 @@ void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur /* * Calculate the maximum exposure time possible for the AGC to use. - * getVBlanking() will update maxShutter with the largest exposure + * getBlanking() will update maxShutter with the largest exposure * value possible. */ Duration maxShutter = Duration::max(); - helper_->getVBlanking(maxShutter, minFrameDuration_, maxFrameDuration_); + helper_->getBlanking(maxShutter, minFrameDuration_, maxFrameDuration_); RPiController::AgcAlgorithm *agc = dynamic_cast( controller_.getAlgorithm("agc")); @@ -1200,10 +1200,11 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) */ gainCode = std::min(gainCode, maxSensorGainCode_); - /* getVBlanking might clip exposure time to the fps limits. */ + /* getBlanking might clip exposure time to the fps limits. */ Duration exposure = agcStatus->shutterTime; - int32_t vblanking = helper_->getVBlanking(exposure, minFrameDuration_, maxFrameDuration_); - int32_t exposureLines = helper_->exposureLines(exposure, mode_.minLineLength); + auto [vblank, hblank] = helper_->getBlanking(exposure, minFrameDuration_, maxFrameDuration_); + int32_t exposureLines = helper_->exposureLines(exposure, + helper_->hblankToLineLength(hblank)); LOG(IPARPI, Debug) << "Applying AGC Exposure: " << exposure << " (Shutter lines: " << exposureLines << ", AGC requested " @@ -1211,14 +1212,22 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) << agcStatus->analogueGain << " (Gain Code: " << gainCode << ")"; - /* - * Due to the behavior of V4L2, the current value of VBLANK could clip the - * exposure time without us knowing. The next time though this function should - * clip exposure correctly. - */ - ctrls.set(V4L2_CID_VBLANK, vblanking); + ctrls.set(V4L2_CID_VBLANK, static_cast(vblank)); ctrls.set(V4L2_CID_EXPOSURE, exposureLines); ctrls.set(V4L2_CID_ANALOGUE_GAIN, gainCode); + + /* + * At present, there is no way of knowing if a control is read-only. + * As a workaround, assume that if the minimum and maximum values of + * the V4L2_CID_HBLANK control are the same, it implies the control + * is read-only. This seems to be the case for all the cameras our IPA + * works with. + * + * \todo The control API ought to have a flag to specify if a control + * is read-only which could be used below. + */ + if (mode_.minLineLength != mode_.maxLineLength) + ctrls.set(V4L2_CID_HBLANK, static_cast(hblank)); } void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls) From patchwork Thu Oct 6 13:17:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17551 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 AF71BC3287 for ; Thu, 6 Oct 2022 13:18:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3BED962D18; Thu, 6 Oct 2022 15:18:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062285; bh=hV19k6+5ZyQUG7rvYzMq3gDrTHgp05W10hHjsFaKaPk=; 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=PceIWNvQp01vKF51ufM+9x9KncaYm6a6GdW2iYFZeKuPOrpEHWYlxqEH50ynCMmnr /bdSJU6+99LgKWYnd/zkDWxdJjeE4NC4uYuDQb4UjHl17dje74GxZL3rM5A3DzRkrz 0F/am0rv9OR/w/bIKnS5mY/EM9Jx2yQ8UnjrfevTPdg/ul703RI3eYfpKapVb/3mGw StrqfDNC10H3Y1uHjQONcIk/nRtqjNIFK6+qfN01Kzdt7Qqiavza2n601UUa141AU0 PDiJYJm2VihvU1bk0U+Vv3zezCcvHdk87wFxAl1wmYvc4jARj0SaF4F9it4wuLUSnO XrJxv/lKRJmZw== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60C3962D0B for ; Thu, 6 Oct 2022 15:18:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Az05FNQw"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id b4so2706728wrs.1 for ; Thu, 06 Oct 2022 06:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=/spMsGEdXBbA5Mp/XA3rOFmIjFUaZnuuSdKv/kJBWeQ=; b=Az05FNQwwnuD9doSxwBNp3eREGiHlkHLohaeLzt+5J3joWv+CKomaYSDM86BP5HRYx A7PlDGCgv6rUjqrmnl6gK+e4C27mfnKzzEbMd9SV/DZBDxwhqF1nIdNjQnKmuSz9tCVt U15wbogC9Sbse86lXaA3cxybv/OfAwXtXAkdXJo8/l4SP3U2NiZ5SPtcb9vlF0Ky0kCz 076OGSe6cacbG82kYnOxhnj5rYskk4KAGO50ts9BHXLGzSx5tVkFHwlvP60qKL1EObRd DaS6d8ywv7/+uvPGFy/EsKmJsOFYGrduMu/J+V3NafMKPf956qV6zvs1yxZX7zuLx5Fb I/kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=/spMsGEdXBbA5Mp/XA3rOFmIjFUaZnuuSdKv/kJBWeQ=; b=dkPkPaLSkpVKf3kCL9GuPAv0yGPXq9O9PqYz2YxFHH57TZp5jichhPkGzGdXresW6H 9nXIdUc+EsSNiGQ9J+1hmwVqwP0ZYGrl1ynHrY/19pOFRTqYP1oJdfgtOMkPn+2qG0gS +lWYtEy7XsFKAl0EnqoLv7F61L3g55JTryXG3H9qATrRhKM+T521yK88Zqr6/2ueofOs rP1JoTGkmWNEAenGJK+S/hAal1cfvFlL2IeYax7tFdWPOqIyKTFWUx5YVKeKJBGyGKdV w2V3ortB9btZi+8HnjzkEoW/o9LPYwDAVcnINvKJJl5WYC0inoMkrtw3f2X7XnYwHLIa A7WQ== X-Gm-Message-State: ACrzQf1g2NgzpUmH6gZKggoC/hxjyCvvvJ9igtfjltiNCvSrkfuG3cmQ s2vMeDvI1OZCpSWDPT0pkvatpYgmf28BLg== X-Google-Smtp-Source: AMsMyM5BbKtFj+3FVEyJAkL5BdIq6SMt3UWWOaf7iHg2yi0kSbhhFSfADdLNndaSnO4aiXei2T59UA== X-Received: by 2002:a5d:6c6b:0:b0:225:dde:ab40 with SMTP id r11-20020a5d6c6b000000b002250ddeab40mr3230686wrz.690.1665062281943; Thu, 06 Oct 2022 06:18:01 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:18:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:44 +0100 Message-Id: <20221006131744.5179-11-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/10] ipa: raspberrypi: Extract line length from the embedded data parser 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" Update the imx219, imx477 and imx519 parsers to extract the line length values from the embedded data stream and use these values in the deviceStatus metadata, replacing the DelayedControls provided values. Signed-off-by: Naushir Patuck Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 3 ++- src/ipa/raspberrypi/cam_helper_imx219.cpp | 9 +++++++-- src/ipa/raspberrypi/cam_helper_imx477.cpp | 9 +++++++-- src/ipa/raspberrypi/cam_helper_imx519.cpp | 9 +++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index afbc03d36b02..d90ac1deda47 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -222,7 +222,7 @@ void CamHelper::parseEmbeddedData(Span buffer, metadata.merge(parsedMetadata); /* - * Overwrite the exposure/gain, frame length and sensor temperature values + * Overwrite the exposure/gain, line/frame length and sensor temperature values * in the existing DeviceStatus with values from the parsed embedded buffer. * Fetch it first in case any other fields were set meaningfully. */ @@ -236,6 +236,7 @@ void CamHelper::parseEmbeddedData(Span buffer, deviceStatus.shutterSpeed = parsedDeviceStatus.shutterSpeed; deviceStatus.analogueGain = parsedDeviceStatus.analogueGain; deviceStatus.frameLength = parsedDeviceStatus.frameLength; + deviceStatus.lineLength = parsedDeviceStatus.lineLength; if (parsedDeviceStatus.sensorTemperature) deviceStatus.sensorTemperature = parsedDeviceStatus.sensorTemperature; diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index 98a3b31956ec..c3337ed08466 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -32,8 +32,11 @@ constexpr uint32_t expHiReg = 0x15a; constexpr uint32_t expLoReg = 0x15b; constexpr uint32_t frameLengthHiReg = 0x160; constexpr uint32_t frameLengthLoReg = 0x161; +constexpr uint32_t lineLengthHiReg = 0x162; +constexpr uint32_t lineLengthLoReg = 0x163; constexpr std::initializer_list registerList [[maybe_unused]] - = { expHiReg, expLoReg, gainReg, frameLengthHiReg, frameLengthLoReg }; + = { expHiReg, expLoReg, gainReg, frameLengthHiReg, frameLengthLoReg, + lineLengthHiReg, lineLengthLoReg }; class CamHelperImx219 : public CamHelper { @@ -94,8 +97,10 @@ void CamHelperImx219::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; + deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 + + registers.at(lineLengthLoReg)); deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), - mode_.minLineLength); + deviceStatus.lineLength); deviceStatus.analogueGain = gain(registers.at(gainReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 19a5e471c27e..bc769ca75baa 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -35,9 +35,12 @@ constexpr uint32_t gainHiReg = 0x0204; constexpr uint32_t gainLoReg = 0x0205; constexpr uint32_t frameLengthHiReg = 0x0340; constexpr uint32_t frameLengthLoReg = 0x0341; +constexpr uint32_t lineLengthHiReg = 0x0342; +constexpr uint32_t lineLengthLoReg = 0x0343; constexpr uint32_t temperatureReg = 0x013a; constexpr std::initializer_list registerList = - { expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg, temperatureReg }; + { expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg, + lineLengthHiReg, lineLengthLoReg, temperatureReg }; class CamHelperImx477 : public CamHelper { @@ -175,8 +178,10 @@ void CamHelperImx477::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; + deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 + + registers.at(lineLengthLoReg)); deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), - mode_.minLineLength); + deviceStatus.lineLength); deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); deviceStatus.sensorTemperature = std::clamp(registers.at(temperatureReg), -20, 80); diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp index d2eb171912da..c7262aa0b6e6 100644 --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp @@ -36,8 +36,11 @@ constexpr uint32_t gainHiReg = 0x0204; constexpr uint32_t gainLoReg = 0x0205; constexpr uint32_t frameLengthHiReg = 0x0340; constexpr uint32_t frameLengthLoReg = 0x0341; +constexpr uint32_t lineLengthHiReg = 0x0342; +constexpr uint32_t lineLengthLoReg = 0x0343; constexpr std::initializer_list registerList = - { expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg }; + { expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg, + lineLengthHiReg, lineLengthLoReg }; class CamHelperImx519 : public CamHelper { @@ -175,8 +178,10 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; + deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 + + registers.at(lineLengthLoReg)); deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), - mode_.minLineLength); + deviceStatus.lineLength); deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);