Patch Detail
Show a patch.
GET /api/patches/10975/?format=api
{ "id": 10975, "url": "https://patchwork.libcamera.org/api/patches/10975/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10975/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210124140506.786503-2-naush@raspberrypi.com>", "date": "2021-01-24T14:05:04", "name": "[libcamera-devel,v2,2/4] ipa: raspberrypi: Limit the calculated vblank based on the sensor mode", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "527cb5b30e8df9c80237342b8b384f8fd2631da4", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/10975/mbox/", "series": [ { "id": 1602, "url": "https://patchwork.libcamera.org/api/series/1602/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1602", "date": "2021-01-24T14:05:03", "name": "[libcamera-devel,v2,1/4] raspberrypi: Add the correct integer const postfix for FrameDurations", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1602/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10975/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10975/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 12FD6BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 24 Jan 2021 14:05:16 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9B382682A3;\n\tSun, 24 Jan 2021 15:05:14 +0100 (CET)", "from mail-wm1-x329.google.com (mail-wm1-x329.google.com\n\t[IPv6:2a00:1450:4864:20::329])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 938646829E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 24 Jan 2021 15:05:13 +0100 (CET)", "by mail-wm1-x329.google.com with SMTP id c128so8462774wme.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 24 Jan 2021 06:05:13 -0800 (PST)", "from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tu16sm19311053wrn.68.2021.01.24.06.05.11\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 24 Jan 2021 06:05:12 -0800 (PST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"juKR9ZkP\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=Iv2RfYLpcer8K9hi7RY1wi3KewqGhT3EI6OJHgoarH8=;\n\tb=juKR9ZkPWshgNscqXhbTtuWv3EEeEZ84kubPmpxkBt2M9/yaLR+B2cAKuBwmQrq7Xo\n\tYUSioQv22w5nbNUhuntk/+yOeWev//5KI4l5CEO+nIf8kgbrUJcRTxrYFsGCn8KI5Wm+\n\t4Y//SNf9BTsk67dw1PypnrDUOtLT2y3ADA4tMHR1gbqBcROZJzjAjC8GxtNzlKFkxs7m\n\t9/IBrzQ4215RmrApvjckC+U+oRg9mK6foeXw60JcvDHp2fp65R1DVU+10ngiB7ItPh2I\n\tlLlJX0eV4vkJgDULwLH8XKArvsBH4yx167h1+IDNQS110t26Nh4qTkK21lUnKvoAga7J\n\tFcCg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=Iv2RfYLpcer8K9hi7RY1wi3KewqGhT3EI6OJHgoarH8=;\n\tb=G9h4FJREYJsKZlqW4Xh9/2Q5oD1ERswJV1gb3q7aPt7LbKECbmYciBVMg2zX98Rhpc\n\tu9dPRm0ZGDYTpSChnlKWuduWj6auKakJbNbpqGnd9/2yTFegA4nJxWGwOLt1w1fIQPb8\n\t18DGw1hcoffexSSgFMFFNR2lMizYA2fNWyD1LboeG4HSSLsktYiUs+ydobWv3sKfmzDg\n\tMVRnKvVJ4e131TtOUljb7etmmkW9211jCUFWNm10Bq2E4QaUM9MMbRYS00sx6Tiv1TMm\n\tVZ4+bxyp2+6Fi05AIKoG6unry5VgfSOAKUc5eX2rYHlNW/Yy3xZgnRi5Y2/ttHxSqW0u\n\tzWFA==", "X-Gm-Message-State": "AOAM530504QOENUMb7WVxBAOPOglf8UzRYTGvpR5DxK5ZwPZaWbjda1l\n\tPwAhkfoAUXc2H3067FEVwX2ZmriG7/j6WBzM", "X-Google-Smtp-Source": "ABdhPJyMCfG87nmPA8ZKKxdx6C+wMoySbNjllbbqd9pQpzLCUUBzZidKSUYOXNfTPMbEOEok+lXWqg==", "X-Received": "by 2002:a7b:c115:: with SMTP id\n\tw21mr1193163wmi.114.1611497112883; \n\tSun, 24 Jan 2021 06:05:12 -0800 (PST)", "From": "Naushir Patuck <naush@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 24 Jan 2021 14:05:04 +0000", "Message-Id": "<20210124140506.786503-2-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20210124140506.786503-1-naush@raspberrypi.com>", "References": "<20210124140506.786503-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v2 2/4] ipa: raspberrypi: Limit the\n\tcalculated vblank based on the sensor mode", "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>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The existing framerate/vblank calculations did not account for the\nsensor mode limits. This commit extracts vblank limits from the sensor\nv4l2 controls, and stores it in the camera modes structure.\n\nExposure and vblank value calculations now use values clamped to the\nsensor mode limits. The libcamera::controls::FrameDurations metadata\nreturn values now reflect the minimum and maximum after clamping.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/cam_helper.cpp | 16 +++---\n src/ipa/raspberrypi/cam_helper.hpp | 5 +-\n src/ipa/raspberrypi/cam_helper_imx219.cpp | 6 +--\n src/ipa/raspberrypi/cam_helper_imx477.cpp | 4 +-\n src/ipa/raspberrypi/cam_helper_ov5647.cpp | 4 +-\n src/ipa/raspberrypi/controller/camera_mode.h | 2 +\n src/ipa/raspberrypi/raspberrypi.cpp | 51 ++++++++++++++------\n 7 files changed, 49 insertions(+), 39 deletions(-)", "diff": "diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp\nindex b7b8faf09c69..3e17255737b2 100644\n--- a/src/ipa/raspberrypi/cam_helper.cpp\n+++ b/src/ipa/raspberrypi/cam_helper.cpp\n@@ -34,9 +34,8 @@ CamHelper *CamHelper::Create(std::string const &cam_name)\n \treturn nullptr;\n }\n \n-CamHelper::CamHelper(MdParser *parser, unsigned int maxFrameLength,\n-\t\t unsigned int frameIntegrationDiff)\n-\t: parser_(parser), initialized_(false), maxFrameLength_(maxFrameLength),\n+CamHelper::CamHelper(MdParser *parser, unsigned int frameIntegrationDiff)\n+\t: parser_(parser), initialized_(false),\n \t frameIntegrationDiff_(frameIntegrationDiff)\n {\n }\n@@ -67,13 +66,12 @@ uint32_t CamHelper::GetVBlanking(double &exposure, double minFrameDuration,\n \tassert(initialized_);\n \n \t/*\n-\t * Clamp frame length by the frame duration range and the maximum allowable\n-\t * value in the sensor, given by maxFrameLength_.\n+\t * minFrameDuration and maxFrameDuration will have been clamped to the\n+\t * maximum allowable values in the sensor for this mode.\n \t */\n-\tframeLengthMin = std::clamp<uint32_t>(1e3 * minFrameDuration / mode_.line_length,\n-\t\t\t\t\t mode_.height, maxFrameLength_);\n-\tframeLengthMax = std::clamp<uint32_t>(1e3 * maxFrameDuration / mode_.line_length,\n-\t\t\t\t\t mode_.height, maxFrameLength_);\n+\tframeLengthMin = 1e3 * minFrameDuration / mode_.line_length;\n+\tframeLengthMax = 1e3 * maxFrameDuration / mode_.line_length;\n+\n \t/*\n \t * Limit the exposure to the maximum frame duration requested, and\n \t * re-calculate if it has been clipped.\ndiff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp\nindex b1739a57e342..14d70112cb62 100644\n--- a/src/ipa/raspberrypi/cam_helper.hpp\n+++ b/src/ipa/raspberrypi/cam_helper.hpp\n@@ -62,8 +62,7 @@ class CamHelper\n {\n public:\n \tstatic CamHelper *Create(std::string const &cam_name);\n-\tCamHelper(MdParser *parser, unsigned int maxFrameLength,\n-\t\t unsigned int frameIntegrationDiff);\n+\tCamHelper(MdParser *parser, unsigned int frameIntegrationDiff);\n \tvirtual ~CamHelper();\n \tvoid SetCameraMode(const CameraMode &mode);\n \tMdParser &Parser() const { return *parser_; }\n@@ -86,8 +85,6 @@ protected:\n \n private:\n \tbool initialized_;\n-\t/* Largest possible frame length, in units of lines. */\n-\tunsigned int maxFrameLength_;\n \t/*\n \t * Smallest difference between the frame length and integration time,\n \t * in units of lines.\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp\nindex 8688ec091c44..95b8e698fe3b 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx219.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp\n@@ -56,15 +56,13 @@ private:\n \t * in units of lines.\n \t */\n \tstatic constexpr int frameIntegrationDiff = 4;\n-\t/* Largest possible frame length, in units of lines. */\n-\tstatic constexpr int maxFrameLength = 0xffff;\n };\n \n CamHelperImx219::CamHelperImx219()\n #if ENABLE_EMBEDDED_DATA\n-\t: CamHelper(new MdParserImx219(), maxFrameLength, frameIntegrationDiff)\n+\t: CamHelper(new MdParserImx219(), frameIntegrationDiff)\n #else\n-\t: CamHelper(new MdParserRPi(), maxFrameLength, frameIntegrationDiff)\n+\t: CamHelper(new MdParserRPi(), frameIntegrationDiff)\n #endif\n {\n }\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp\nindex 5396131003f1..eaa7be16d20e 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx477.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp\n@@ -45,12 +45,10 @@ private:\n \t * in units of lines.\n \t */\n \tstatic constexpr int frameIntegrationDiff = 22;\n-\t/* Largest possible frame length, in units of lines. */\n-\tstatic constexpr int maxFrameLength = 0xffdc;\n };\n \n CamHelperImx477::CamHelperImx477()\n-\t: CamHelper(new MdParserImx477(), maxFrameLength, frameIntegrationDiff)\n+\t: CamHelper(new MdParserImx477(), frameIntegrationDiff)\n {\n }\n \ndiff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp\nindex 2bd8a754f133..a7f417324048 100644\n--- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp\n@@ -30,8 +30,6 @@ private:\n \t * in units of lines.\n \t */\n \tstatic constexpr int frameIntegrationDiff = 4;\n-\t/* Largest possible frame length, in units of lines. */\n-\tstatic constexpr int maxFrameLength = 0xffff;\n };\n \n /*\n@@ -40,7 +38,7 @@ private:\n */\n \n CamHelperOv5647::CamHelperOv5647()\n-\t: CamHelper(new MdParserRPi(), maxFrameLength, frameIntegrationDiff)\n+\t: CamHelper(new MdParserRPi(), frameIntegrationDiff)\n {\n }\n \ndiff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h\nindex 920f11beb0b0..3baeadaca076 100644\n--- a/src/ipa/raspberrypi/controller/camera_mode.h\n+++ b/src/ipa/raspberrypi/controller/camera_mode.h\n@@ -37,6 +37,8 @@ struct CameraMode {\n \tdouble line_length;\n \t// any camera transform *not* reflected already in the camera tuning\n \tlibcamera::Transform transform;\n+\t// minimum and maximum vblanking limits for this mode\n+\tuint32_t vblank_min, vblank_max;\n };\n \n #ifdef __cplusplus\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 5ccc7a6551f5..30ba9aef9d97 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -102,6 +102,7 @@ private:\n \tvoid reportMetadata();\n \tbool parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus);\n \tvoid processStats(unsigned int bufferId);\n+\tvoid applyFrameDurations(double minFrameDuration, double maxFrameDuration);\n \tvoid applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls);\n \tvoid applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls);\n \tvoid applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls);\n@@ -279,6 +280,14 @@ void IPARPi::setMode(const CameraSensorInfo &sensorInfo)\n \t * the line length in pixels and the pixel rate.\n \t */\n \tmode_.line_length = 1e9 * sensorInfo.lineLength / sensorInfo.pixelRate;\n+\n+\t/*\n+\t * Set the vertical blanking (frame duration) limits for the mode to\n+\t * ensure exposure and framerate calculations are clipped appropriately.\n+\t */\n+\tconst auto itVblank = sensorCtrls_.find(V4L2_CID_VBLANK);\n+\tmode_.vblank_min = itVblank->second.min().get<int32_t>();\n+\tmode_.vblank_max = itVblank->second.max().get<int32_t>();\n }\n \n void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n@@ -384,8 +393,8 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n \t\tcontroller_.Initialise();\n \t\tcontrollerInit_ = true;\n \n-\t\tminFrameDuration_ = defaultMinFrameDuration;\n-\t\tmaxFrameDuration_ = defaultMaxFrameDuration;\n+\t\t/* Supply initial values for frame durations. */\n+\t\tapplyFrameDurations(defaultMinFrameDuration, defaultMaxFrameDuration);\n \n \t\t/* Supply initial values for gain and exposure. */\n \t\tControlList ctrls(sensorCtrls_);\n@@ -819,20 +828,7 @@ void IPARPi::queueRequest(const ControlList &controls)\n \n \t\tcase controls::FRAME_DURATIONS: {\n \t\t\tauto frameDurations = ctrl.second.get<Span<const int64_t>>();\n-\n-\t\t\t/* This will be applied once AGC recalculations occur. */\n-\t\t\tminFrameDuration_ = frameDurations[0] ? frameDurations[0] : defaultMinFrameDuration;\n-\t\t\tmaxFrameDuration_ = frameDurations[1] ? frameDurations[1] : defaultMaxFrameDuration;\n-\t\t\tmaxFrameDuration_ = std::max(maxFrameDuration_, minFrameDuration_);\n-\n-\t\t\t/*\n-\t\t\t * \\todo The values returned in the metadata below must be\n-\t\t\t * correctly clipped by what the sensor mode supports and\n-\t\t\t * what the AGC exposure mode or manual shutter speed limits\n-\t\t\t */\n-\t\t\tlibcameraMetadata_.set(controls::FrameDurations,\n-\t\t\t\t\t { static_cast<int64_t>(minFrameDuration_),\n-\t\t\t\t\t\t static_cast<int64_t>(maxFrameDuration_) });\n+\t\t\tapplyFrameDurations(frameDurations[0], frameDurations[1]);\n \t\t\tbreak;\n \t\t}\n \n@@ -991,6 +987,29 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n \t\t static_cast<int32_t>(awbStatus->gain_b * 1000));\n }\n \n+void IPARPi::applyFrameDurations(double minFrameDuration, double maxFrameDuration)\n+{\n+\tconst double minSensorFrameDuration = 1e-3 * (mode_.vblank_min + mode_.height) *\n+\t\t\t\t\t mode_.line_length;\n+\tconst double maxSensorFrameDuration = 1e-3 * (mode_.vblank_max + mode_.height) *\n+\t\t\t\t\t mode_.line_length;\n+\t/*\n+\t * This will only be applied once AGC recalculations occur.\n+\t * The values may be clamped based on the sensor mode capabilities as well.\n+\t */\n+\tminFrameDuration_ = minFrameDuration ? minFrameDuration : defaultMaxFrameDuration;\n+\tmaxFrameDuration_ = maxFrameDuration ? maxFrameDuration : defaultMinFrameDuration;\n+\tminFrameDuration_ = std::clamp(minFrameDuration_,\n+\t\t\t\t minSensorFrameDuration, maxSensorFrameDuration);\n+\tmaxFrameDuration_ = std::clamp(maxFrameDuration_,\n+\t\t\t\t minSensorFrameDuration, maxSensorFrameDuration);\n+\n+\t/* Return the validated limits out though metadata. */\n+\tlibcameraMetadata_.set(controls::FrameDurations,\n+\t\t\t { static_cast<int64_t>(minFrameDuration_),\n+\t\t\t\t static_cast<int64_t>(maxFrameDuration_) });\n+}\n+\n void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)\n {\n \tint32_t gainCode = helper_->GainCode(agcStatus->analogue_gain);\n", "prefixes": [ "libcamera-devel", "v2", "2/4" ] }