{"id":17550,"url":"https://patchwork.libcamera.org/api/1.1/patches/17550/?format=json","web_url":"https://patchwork.libcamera.org/patch/17550/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221006131744.5179-10-naush@raspberrypi.com>","date":"2022-10-06T13:17:43","name":"[libcamera-devel,v2,09/10] ipa: raspberrypi: Allow full line length control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"1a1afcd301d3dc6edc6f050a5d9a9936f4400fd8","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17550/mbox/","series":[{"id":3537,"url":"https://patchwork.libcamera.org/api/1.1/series/3537/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3537","date":"2022-10-06T13:17:34","name":"Raspberry Pi: Horizontal blanking control","version":2,"mbox":"https://patchwork.libcamera.org/series/3537/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17550/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17550/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 14F46C3285\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  6 Oct 2022 13:18:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BC3B762D1D;\n\tThu,  6 Oct 2022 15:18:04 +0200 (CEST)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B1F2562D01\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Oct 2022 15:18:01 +0200 (CEST)","by mail-wr1-x436.google.com with SMTP id n12so2660416wrp.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 06 Oct 2022 06:18:01 -0700 (PDT)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tq18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.18.00\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 06 Oct 2022 06:18:00 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1665062284;\n\tbh=RaIKxvybGoMB6uAP+wjjb5iTqt8PQwKcl9SA0mP5u3c=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=QhGlIONnrTV2R6Y1pU8TYXT/Lz/bDx3zayfXilgCvEnW+dzfsXPXm2m5a8vsvlA2i\n\t1YEkGz3i83ps9OiDN+knjUwReqEOkCqAzziwmnxOwulc+apuD8LEsf3ktiWAdzVrp3\n\txS4qpb5CCpH7x556ii2Qu6VMMc5o8wyxMNqE1ZTCeUoOCFJSjkJQ5YHeGCdgUAKfzy\n\t8N7anukn2UUV2XshDvyEMPOxmcBEbAMZW8SMkohabL8nKhB2y84aSuduQKVknfeDtm\n\tIsjrZ9vqDFfQPpJ0L4Q9l0JKAT/pKsUcNJ0G2cJbI0WONI9knnJexmShcJ+ftSd7DH\n\t89q7m8k1cvkIg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date;\n\tbh=pxt6/tficOHsXFhXoILdAkU3b46HFC2Yc7SPtUOfGUU=;\n\tb=DA/9McNzdysz9ndqo/752Q2lKXybKiWHqVlG4PlwXUv/0Cv3lEZYcs64RiX3zAUyki\n\tcQLEVDjw0cN3Ajs7UFychTFwUhRf2tkjlTd+SPBU1fS12RT5I4zCIIVMkqI9MWEAd9e5\n\txCpFar8HBy+ZuGwQ2pqQTBtS4gpJ06Be2vuXoKod6WM7z5+xhMWIkPYizkKa4EPp/sAZ\n\tE8A7uKa10FM2gCxvdWwbH1e5Ioj/G024IB6b1+hrrrWPQXyRgiGhvX1lnRSoSFODxmrw\n\tEGOK+wFH4/VEMOvGibuE7ORwNT5uQ8IUwiGD5As/2WJhPefzacCL3qaV8ksIn7TwN72H\n\tXMiA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"DA/9McNz\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date;\n\tbh=pxt6/tficOHsXFhXoILdAkU3b46HFC2Yc7SPtUOfGUU=;\n\tb=YNWS5cGRDjtUcQw3XxCzMyfb7B2pqoNEmJSEVR2EB+cu5y+/HB+N7qI7K/fzWJhChf\n\t0kiQK9k1mnM9kb604MD5RlchfwPbsp+Zl9H09TErO1Ym+n0O5Mk40bOej0OB2INf8CP3\n\tNsqVXglFSztN3d5vhLWP/PT6pit+O8ZSY6IchNc45nKG+c2syUbGubiQWbrg41mdUoXN\n\th0o7Sfm5XWohMp872J5Bo/904rULTBw3gL1NuoDr6KIY/X8JTt16nM+a7GCunz/R6Vgy\n\tN7nZDUOcGib0ROIMyYjePrpD1EDqRarb74uphncVgJUIoLqoAiKQj6EQZyTASV7g3HEj\n\tNWvw==","X-Gm-Message-State":"ACrzQf2GKqeXCt+9Zo6qHs/T45vjJYepkPeHlGnsjwzaWGFhW27EbBNr\n\t+4eCidrwevJ7mXujxCHKxgwcz62bTVyT1w==","X-Google-Smtp-Source":"AMsMyM4GT4jgw3FdTxV5hZQF3BAuB4piT3dHmSFWnchmj8ERKYH41sW+tFVDkovhdb/Z5bgwcgVB3g==","X-Received":"by 2002:a5d:688f:0:b0:22c:df1c:92cd with SMTP id\n\th15-20020a5d688f000000b0022cdf1c92cdmr3314057wru.52.1665062280747; \n\tThu, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 09/10] ipa: raspberrypi: Allow full\n\tline length control","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Rename CamHelper::getVBlanking to CamHelper::getBlanking, and update the\ncalculations in that function to return both horizontal and vertical blanking\nvalues for a given exposure time and frame duration limits. The calculations\nare setup such that vertical blanking is extended to the maximum allowable\nvalue, and any remainder gets put into horizontal blanking.\n\nThe calculated horizontal blanking value is now returned to the pipeline handler\nto pass into DelayedControls to program into the sensor.\n\nUpdate the IPA to now specify the maximum frame duration from the maximum\nhorizontal + vertical blanking values provided by the sensor mode. Additionally,\nthe IPA now uses the frame specific horizontal blanking value (as returned by\nDelayedControls) in all instances.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nTested-by: Dave Stevenson <dave.stevenson@raspberrypi.com>\n---\n src/ipa/raspberrypi/cam_helper.cpp        | 48 +++++++++++++++++------\n src/ipa/raspberrypi/cam_helper.h          |  7 ++--\n src/ipa/raspberrypi/cam_helper_imx477.cpp | 24 +++++++-----\n src/ipa/raspberrypi/cam_helper_imx519.cpp | 24 +++++++-----\n src/ipa/raspberrypi/raspberrypi.cpp       | 43 ++++++++++++--------\n 5 files changed, 95 insertions(+), 51 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp\nindex bc3f66a51254..afbc03d36b02 100644\n--- a/src/ipa/raspberrypi/cam_helper.cpp\n+++ b/src/ipa/raspberrypi/cam_helper.cpp\n@@ -7,6 +7,7 @@\n \n #include <linux/videodev2.h>\n \n+#include <limits>\n #include <map>\n #include <string.h>\n \n@@ -70,31 +71,56 @@ Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength)\n \treturn exposureLines * lineLength;\n }\n \n-uint32_t CamHelper::getVBlanking(Duration &exposure,\n-\t\t\t\t Duration minFrameDuration,\n-\t\t\t\t Duration maxFrameDuration) const\n+std::pair<uint32_t, uint32_t> CamHelper::getBlanking(Duration &exposure,\n+\t\t\t\t\t\t     Duration minFrameDuration,\n+\t\t\t\t\t\t     Duration maxFrameDuration) const\n {\n-\tuint32_t frameLengthMin, frameLengthMax, vblank;\n-\tuint32_t exposureLines = CamHelper::exposureLines(exposure, mode_.minLineLength);\n+\tuint32_t frameLengthMin, frameLengthMax, vblank, hblank;\n+\tDuration lineLength = mode_.minLineLength;\n \n \t/*\n \t * minFrameDuration and maxFrameDuration are clamped by the caller\n \t * based on the limits for the active sensor mode.\n+\t *\n+\t * frameLengthMax gets calculated on the smallest line length as we do\n+\t * not want to extend that unless absolutely necessary.\n \t */\n \tframeLengthMin = minFrameDuration / mode_.minLineLength;\n \tframeLengthMax = maxFrameDuration / mode_.minLineLength;\n \n+\t/*\n+\t * Watch out for (exposureLines + frameIntegrationDiff_) overflowing a\n+\t * uint32_t in the std::clamp() below when the exposure time is\n+\t * extremely (extremely!) long - as happens when the IPA calculates the\n+\t * maximum possible exposure time.\n+\t */\n+\tuint32_t exposureLines = std::min(CamHelper::exposureLines(exposure, lineLength),\n+\t\t\t\t\t  std::numeric_limits<uint32_t>::max() - frameIntegrationDiff_);\n+\tuint32_t frameLengthLines = std::clamp(exposureLines + frameIntegrationDiff_,\n+\t\t\t\t\t       frameLengthMin, frameLengthMax);\n+\n+\t/*\n+\t * If our frame length lines is above the maximum allowed, see if we can\n+\t * extend the line length to accommodate the requested frame length.\n+\t */\n+\tif (frameLengthLines > mode_.maxFrameLength) {\n+\t\tDuration lineLengthAdjusted = lineLength * frameLengthLines / mode_.maxFrameLength;\n+\t\tlineLength = std::min(mode_.maxLineLength, lineLengthAdjusted);\n+\t\tframeLengthLines = mode_.maxFrameLength;\n+\t}\n+\n+\thblank = lineLengthToHblank(lineLength);\n+\tvblank = frameLengthLines - mode_.height;\n+\n \t/*\n \t * Limit the exposure to the maximum frame duration requested, and\n \t * re-calculate if it has been clipped.\n \t */\n-\texposureLines = std::min(frameLengthMax - frameIntegrationDiff_, exposureLines);\n-\texposure = CamHelper::exposure(exposureLines, mode_.minLineLength);\n+\texposureLines = std::min(frameLengthLines - frameIntegrationDiff_,\n+\t\t\t\t CamHelper::exposureLines(exposure, lineLength));\n+\texposure = CamHelper::exposure(exposureLines, lineLength);\n \n-\t/* Limit the vblank to the range allowed by the frame length limits. */\n-\tvblank = std::clamp(exposureLines + frameIntegrationDiff_,\n-\t\t\t    frameLengthMin, frameLengthMax) - mode_.height;\n-\treturn vblank;\n+\treturn { vblank, hblank };\n }\n \n Duration CamHelper::hblankToLineLength(uint32_t hblank) const\ndiff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h\nindex 6cd1dd397b91..b3f8c9803094 100644\n--- a/src/ipa/raspberrypi/cam_helper.h\n+++ b/src/ipa/raspberrypi/cam_helper.h\n@@ -8,6 +8,7 @@\n \n #include <memory>\n #include <string>\n+#include <utility>\n \n #include <libcamera/base/span.h>\n #include <libcamera/base/utils.h>\n@@ -82,9 +83,9 @@ public:\n \t\t\t\t       const libcamera::utils::Duration lineLength) const;\n \tvirtual libcamera::utils::Duration exposure(uint32_t exposureLines,\n \t\t\t\t\t\t    const libcamera::utils::Duration lineLength) const;\n-\tvirtual uint32_t getVBlanking(libcamera::utils::Duration &exposure,\n-\t\t\t\t      libcamera::utils::Duration minFrameDuration,\n-\t\t\t\t      libcamera::utils::Duration maxFrameDuration) const;\n+\tvirtual std::pair<uint32_t, uint32_t> getBlanking(libcamera::utils::Duration &exposure,\n+\t\t\t\t\t\t\t  libcamera::utils::Duration minFrameDuration,\n+\t\t\t\t\t\t\t  libcamera::utils::Duration maxFrameDuration) const;\n \tlibcamera::utils::Duration hblankToLineLength(uint32_t hblank) const;\n \tuint32_t lineLengthToHblank(const libcamera::utils::Duration &duration) const;\n \tlibcamera::utils::Duration lineLengthPckToDuration(uint32_t lineLengthPck) const;\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp\nindex 76a82cc51378..19a5e471c27e 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx477.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp\n@@ -46,8 +46,8 @@ public:\n \tuint32_t gainCode(double gain) const override;\n \tdouble gain(uint32_t gainCode) const override;\n \tvoid prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n-\tuint32_t getVBlanking(Duration &exposure, Duration minFrameDuration,\n-\t\t\t      Duration maxFrameDuration) const override;\n+\tstd::pair<uint32_t, uint32_t> getBlanking(Duration &exposure, Duration minFrameDuration,\n+\t\t\t\t\t\t  Duration maxFrameDuration) const override;\n \tvoid getDelays(int &exposureDelay, int &gainDelay,\n \t\t       int &vblankDelay, int &hblankDelay) const override;\n \tbool sensorEmbeddedDataPresent() const override;\n@@ -118,15 +118,19 @@ void CamHelperImx477::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n \t}\n }\n \n-uint32_t CamHelperImx477::getVBlanking(Duration &exposure,\n-\t\t\t\t       Duration minFrameDuration,\n-\t\t\t\t       Duration maxFrameDuration) const\n+std::pair<uint32_t, uint32_t> CamHelperImx477::getBlanking(Duration &exposure,\n+\t\t\t\t\t\t\t   Duration minFrameDuration,\n+\t\t\t\t\t\t\t   Duration maxFrameDuration) const\n {\n \tuint32_t frameLength, exposureLines;\n \tunsigned int shift = 0;\n \n-\tframeLength = mode_.height + CamHelper::getVBlanking(exposure, minFrameDuration,\n-\t\t\t\t\t\t\t     maxFrameDuration);\n+\tauto [vblank, hblank] = CamHelper::getBlanking(exposure, minFrameDuration,\n+\t\t\t\t\t\t       maxFrameDuration);\n+\n+\tframeLength = mode_.height + vblank;\n+\tDuration lineLength = hblankToLineLength(hblank);\n+\n \t/*\n \t * Check if the frame length calculated needs to be setup for long\n \t * exposure mode. This will require us to use a long exposure scale\n@@ -144,12 +148,12 @@ uint32_t CamHelperImx477::getVBlanking(Duration &exposure,\n \tif (shift) {\n \t\t/* Account for any rounding in the scaled frame length value. */\n \t\tframeLength <<= shift;\n-\t\texposureLines = CamHelperImx477::exposureLines(exposure, mode_.minLineLength);\n+\t\texposureLines = CamHelperImx477::exposureLines(exposure, lineLength);\n \t\texposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff);\n-\t\texposure = CamHelperImx477::exposure(exposureLines, mode_.minLineLength);\n+\t\texposure = CamHelperImx477::exposure(exposureLines, lineLength);\n \t}\n \n-\treturn frameLength - mode_.height;\n+\treturn { frameLength - mode_.height, hblank };\n }\n \n void CamHelperImx477::getDelays(int &exposureDelay, int &gainDelay,\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp\nindex 9dff1eeb899f..d2eb171912da 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx519.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp\n@@ -46,8 +46,8 @@ public:\n \tuint32_t gainCode(double gain) const override;\n \tdouble gain(uint32_t gainCode) const override;\n \tvoid prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n-\tuint32_t getVBlanking(Duration &exposure, Duration minFrameDuration,\n-\t\t\t      Duration maxFrameDuration) const override;\n+\tstd::pair<uint32_t, uint32_t> getBlanking(Duration &exposure, Duration minFrameDuration,\n+\t\t\t\t\t\t  Duration maxFrameDuration) const override;\n \tvoid getDelays(int &exposureDelay, int &gainDelay,\n \t\t       int &vblankDelay, int &hblankDelay) const override;\n \tbool sensorEmbeddedDataPresent() const override;\n@@ -118,15 +118,19 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n \t}\n }\n \n-uint32_t CamHelperImx519::getVBlanking(Duration &exposure,\n-\t\t\t\t       Duration minFrameDuration,\n-\t\t\t\t       Duration maxFrameDuration) const\n+std::pair<uint32_t, uint32_t> CamHelperImx519::getBlanking(Duration &exposure,\n+\t\t\t\t\t\t\t   Duration minFrameDuration,\n+\t\t\t\t\t\t\t   Duration maxFrameDuration) const\n {\n \tuint32_t frameLength, exposureLines;\n \tunsigned int shift = 0;\n \n-\tframeLength = mode_.height + CamHelper::getVBlanking(exposure, minFrameDuration,\n-\t\t\t\t\t\t\t     maxFrameDuration);\n+\tauto [vblank, hblank] = CamHelper::getBlanking(exposure, minFrameDuration,\n+\t\t\t\t\t\t       maxFrameDuration);\n+\n+\tframeLength = mode_.height + vblank;\n+\tDuration lineLength = hblankToLineLength(hblank);\n+\n \t/*\n \t * Check if the frame length calculated needs to be setup for long\n \t * exposure mode. This will require us to use a long exposure scale\n@@ -144,12 +148,12 @@ uint32_t CamHelperImx519::getVBlanking(Duration &exposure,\n \tif (shift) {\n \t\t/* Account for any rounding in the scaled frame length value. */\n \t\tframeLength <<= shift;\n-\t\texposureLines = CamHelperImx519::exposureLines(exposure, mode_.minLineLength);\n+\t\texposureLines = CamHelperImx519::exposureLines(exposure, lineLength);\n \t\texposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff);\n-\t\texposure = CamHelperImx519::exposure(exposureLines, mode_.minLineLength);\n+\t\texposure = CamHelperImx519::exposure(exposureLines, lineLength);\n \t}\n \n-\treturn frameLength - mode_.height;\n+\treturn { frameLength - mode_.height, hblank };\n }\n \n void CamHelperImx519::getDelays(int &exposureDelay, int &gainDelay,\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex c8e15f2b04d1..497a83939ae6 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -315,7 +315,7 @@ void IPARPi::start(const ControlList &controls, StartConfig *startConfig)\n \t}\n \n \tstartConfig->dropFrameCount = dropFrameCount_;\n-\tconst Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength;\n+\tconst Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength;\n \tstartConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get<std::milli>();\n \n \tfirstStart_ = false;\n@@ -462,7 +462,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n \t */\n \tControlInfoMap::Map ctrlMap = ipaControls;\n \tconst Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength;\n-\tconst Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength;\n+\tconst Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength;\n \tctrlMap[&controls::FrameDurationLimits] =\n \t\tControlInfo(static_cast<int64_t>(minSensorFrameDuration.get<std::micro>()),\n \t\t\t    static_cast<int64_t>(maxSensorFrameDuration.get<std::micro>()));\n@@ -475,7 +475,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,\n \t * will limit the maximum control value based on the current VBLANK value.\n \t */\n \tDuration maxShutter = Duration::max();\n-\thelper_->getVBlanking(maxShutter, minSensorFrameDuration, maxSensorFrameDuration);\n+\thelper_->getBlanking(maxShutter, minSensorFrameDuration, maxSensorFrameDuration);\n \tconst uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get<int32_t>();\n \n \tctrlMap[&controls::ExposureTime] =\n@@ -552,7 +552,7 @@ void IPARPi::reportMetadata()\n \t\t\t\t       deviceStatus->shutterSpeed.get<std::micro>());\n \t\tlibcameraMetadata_.set(controls::AnalogueGain, deviceStatus->analogueGain);\n \t\tlibcameraMetadata_.set(controls::FrameDuration,\n-\t\t\t\t       helper_->exposure(deviceStatus->frameLength, mode_.minLineLength).get<std::micro>());\n+\t\t\t\t       helper_->exposure(deviceStatus->frameLength, deviceStatus->lineLength).get<std::micro>());\n \t\tif (deviceStatus->sensorTemperature)\n \t\t\tlibcameraMetadata_.set(controls::SensorTemperature, *deviceStatus->sensorTemperature);\n \t}\n@@ -1111,7 +1111,7 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls)\n \tint32_t hblank = sensorControls.get(V4L2_CID_HBLANK).get<int32_t>();\n \n \tdeviceStatus.lineLength = helper_->hblankToLineLength(hblank);\n-\tdeviceStatus.shutterSpeed = helper_->exposure(exposureLines, mode_.minLineLength);\n+\tdeviceStatus.shutterSpeed = helper_->exposure(exposureLines, deviceStatus.lineLength);\n \tdeviceStatus.analogueGain = helper_->gain(gainCode);\n \tdeviceStatus.frameLength = mode_.height + vblank;\n \n@@ -1157,7 +1157,7 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDuration)\n {\n \tconst Duration minSensorFrameDuration = mode_.minFrameLength * mode_.minLineLength;\n-\tconst Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.minLineLength;\n+\tconst Duration maxSensorFrameDuration = mode_.maxFrameLength * mode_.maxLineLength;\n \n \t/*\n \t * This will only be applied once AGC recalculations occur.\n@@ -1178,11 +1178,11 @@ void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur\n \n \t/*\n \t * Calculate the maximum exposure time possible for the AGC to use.\n-\t * getVBlanking() will update maxShutter with the largest exposure\n+\t * getBlanking() will update maxShutter with the largest exposure\n \t * value possible.\n \t */\n \tDuration maxShutter = Duration::max();\n-\thelper_->getVBlanking(maxShutter, minFrameDuration_, maxFrameDuration_);\n+\thelper_->getBlanking(maxShutter, minFrameDuration_, maxFrameDuration_);\n \n \tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n \t\tcontroller_.getAlgorithm(\"agc\"));\n@@ -1200,10 +1200,11 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)\n \t */\n \tgainCode = std::min<int32_t>(gainCode, maxSensorGainCode_);\n \n-\t/* getVBlanking might clip exposure time to the fps limits. */\n+\t/* getBlanking might clip exposure time to the fps limits. */\n \tDuration exposure = agcStatus->shutterTime;\n-\tint32_t vblanking = helper_->getVBlanking(exposure, minFrameDuration_, maxFrameDuration_);\n-\tint32_t exposureLines = helper_->exposureLines(exposure, mode_.minLineLength);\n+\tauto [vblank, hblank] = helper_->getBlanking(exposure, minFrameDuration_, maxFrameDuration_);\n+\tint32_t exposureLines = helper_->exposureLines(exposure,\n+\t\t\t\t\t\t       helper_->hblankToLineLength(hblank));\n \n \tLOG(IPARPI, Debug) << \"Applying AGC Exposure: \" << exposure\n \t\t\t   << \" (Shutter lines: \" << exposureLines << \", AGC requested \"\n@@ -1211,14 +1212,22 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)\n \t\t\t   << agcStatus->analogueGain << \" (Gain Code: \"\n \t\t\t   << gainCode << \")\";\n \n-\t/*\n-\t * Due to the behavior of V4L2, the current value of VBLANK could clip the\n-\t * exposure time without us knowing. The next time though this function should\n-\t * clip exposure correctly.\n-\t */\n-\tctrls.set(V4L2_CID_VBLANK, vblanking);\n+\tctrls.set(V4L2_CID_VBLANK, static_cast<int32_t>(vblank));\n \tctrls.set(V4L2_CID_EXPOSURE, exposureLines);\n \tctrls.set(V4L2_CID_ANALOGUE_GAIN, gainCode);\n+\n+\t/*\n+\t * At present, there is no way of knowing if a control is read-only.\n+\t * As a workaround, assume that if the minimum and maximum values of\n+\t * the V4L2_CID_HBLANK control are the same, it implies the control\n+\t * is read-only. This seems to be the case for all the cameras our IPA\n+\t * works with.\n+\t *\n+\t * \\todo The control API ought to have a flag to specify if a control\n+\t * is read-only which could be used below.\n+\t */\n+\tif (mode_.minLineLength != mode_.maxLineLength)\n+\t\tctrls.set(V4L2_CID_HBLANK, static_cast<int32_t>(hblank));\n }\n \n void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls)\n","prefixes":["libcamera-devel","v2","09/10"]}