Patch Detail
Show a patch.
GET /api/1.1/patches/11546/?format=api
{ "id": 11546, "url": "https://patchwork.libcamera.org/api/1.1/patches/11546/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11546/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20210310172348.4312-2-david.plowman@raspberrypi.com>", "date": "2021-03-10T17:23:48", "name": "[libcamera-devel,RFC,1/1] ipa: raspberrypi: Use CamHelpers to generalise embedded data parsing", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f72e81cf5db485435303595b70515c8a435aea58", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/1.1/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11546/mbox/", "series": [ { "id": 1782, "url": "https://patchwork.libcamera.org/api/1.1/series/1782/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1782", "date": "2021-03-10T17:23:47", "name": "Raspberry Pi generalised embedded data parsing", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1782/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11546/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11546/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 2C3EDBD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Mar 2021 17:23:56 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F17C468AA7;\n\tWed, 10 Mar 2021 18:23:54 +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 3186F602E5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Mar 2021 18:23:53 +0100 (CET)", "by mail-wm1-x329.google.com with SMTP id l22so7615588wme.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Mar 2021 09:23:53 -0800 (PST)", "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\ti17sm18701599wrp.77.2021.03.10.09.23.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 10 Mar 2021 09:23:52 -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=\"ivpKtaf9\"; 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=BX+KOMNqKVDvcOli4HMSqDwkdxigcXC2R2RWuWY/8TU=;\n\tb=ivpKtaf9MjDfX3HzWDSYtq1sKEjO8lRz5EVy5uXCqoBtx7HTsUT4MWP0iAsP/kwrpd\n\trCfuu/+KnA6vr5EYOahhLAqcvVHSr4htK9ysKrpUYDO938p7RTGIzdMiJKBDu7pzMjJC\n\tbI5ClLsiOeHOxEtsrfjYSu82+jNJtf88lJKJq4OXcESHjc0Fuzv9RiMTPepXlLJG99JI\n\t3T209gXAlInEaS5HTYUhQ3aoVcV6dplhB52ra/69+cSFHmCj2tSp3xmqgfXX5UhalOLi\n\t34EPRw/wmfsWSV1PeIfBMfkiQE82tn8B5M2v4uvAqWhtLK5YVnzIKJdUbVzniX9iS3oX\n\t/fkA==", "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=BX+KOMNqKVDvcOli4HMSqDwkdxigcXC2R2RWuWY/8TU=;\n\tb=BcRXExdbWRb3JbnbXYmumI8zyMAdhBfCcC4acfVAYxbOM7CWt6XXFw+TIUfEFZ76co\n\tlr351R7jmi6WbyxOxnlfKzowcDcpIJalttklCczgUdHjj5gqfBZDQh2gCvtCdVqhxvnP\n\tTadcoQujq1rNZS1b7CuxFlYl3ueb1obUIJRsYTv6sA4TudaAgpJbXFSzsJD98OJlJ9Sn\n\tkMOcjksv63xtk5yXqglDjmII43Sz04+FSjAhtFAfvhOpETD56ZClTfP65FPzkQ5wla50\n\tn88QMQ/8jJ2PEbuO4B2Mo9zlFn3+HtefemRpe7lEl29bxjgeDmR4OnyIYlwbmFGY8KZZ\n\tV7+Q==", "X-Gm-Message-State": "AOAM532S6XrFU/wYZ2oNdEupWZvnAJsCU+s+RrYD28zbWj6Tja9WL9sb\n\t5OeyXJ8DU52DVAB5iFoxcaVNOBwcBRoZxw==", "X-Google-Smtp-Source": "ABdhPJwzwKMswcn/VySvM6twS0ZmXGei/v/tUXqhM/39u1ntNQginMBfakXCPFGE0RhEC65Az/uX7A==", "X-Received": "by 2002:a05:600c:4ca9:: with SMTP id\n\tg41mr4440953wmp.150.1615397032663; \n\tWed, 10 Mar 2021 09:23:52 -0800 (PST)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 10 Mar 2021 17:23:48 +0000", "Message-Id": "<20210310172348.4312-2-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20210310172348.4312-1-david.plowman@raspberrypi.com>", "References": "<20210310172348.4312-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [RFC PATCH 1/1] ipa: raspberrypi: Use CamHelpers\n\tto generalise embedded data parsing", "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": "CamHelpers get virtual Prepare() and Process() methods, running just\nbefore and just after the ISP, just like Raspberry Pi Algorithms.\n\nThe Prepare() method is able to parse the register dumps in embedded\ndata buffers, and can be specialised to perform custom processing when\nnecessary.\n\nThe IPA itself no longer performs this register parsing, it just has\nto call the new Prepare() and Process() methods.\n---\n src/ipa/raspberrypi/cam_helper.cpp | 49 ++++++++++++++++\n src/ipa/raspberrypi/cam_helper.hpp | 14 ++++-\n src/ipa/raspberrypi/raspberrypi.cpp | 88 ++++++++---------------------\n 3 files changed, 84 insertions(+), 67 deletions(-)", "diff": "diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp\nindex 0ae0baa0..fc69f4cb 100644\n--- a/src/ipa/raspberrypi/cam_helper.cpp\n+++ b/src/ipa/raspberrypi/cam_helper.cpp\n@@ -17,6 +17,11 @@\n #include \"md_parser.hpp\"\n \n using namespace RPiController;\n+using namespace libcamera;\n+\n+namespace libcamera {\n+LOG_DECLARE_CATEGORY(IPARPI)\n+}\n \n static std::map<std::string, CamHelperCreateFunc> cam_helpers;\n \n@@ -45,6 +50,17 @@ CamHelper::~CamHelper()\n \tdelete parser_;\n }\n \n+void CamHelper::Prepare(const Span<uint8_t> &buffer,\n+\t\t\tconst ControlList &controls, Metadata &metadata)\n+{\n+\tparseRegisters(buffer, controls, metadata);\n+}\n+\n+void CamHelper::Process([[maybe_unused]] StatisticsPtr &stats,\n+\t\t\t[[maybe_unused]] Metadata &metadata)\n+{\n+}\n+\n uint32_t CamHelper::ExposureLines(double exposure_us) const\n {\n \tassert(initialized_);\n@@ -139,6 +155,39 @@ unsigned int CamHelper::MistrustFramesModeSwitch() const\n \treturn 0;\n }\n \n+void CamHelper::parseRegisters(const Span<uint8_t> &buffer,\n+\t\t\t const ControlList &controls, Metadata &metadata)\n+{\n+\tstruct DeviceStatus deviceStatus = {};\n+\tbool success = false;\n+\tuint32_t exposureLines, gainCode;\n+\n+\tif (buffer.size()) {\n+\t\tparser_->SetBufferSize(buffer.size());\n+\t\tsuccess = parser_->Parse(buffer.data()) == MdParser::Status::OK &&\n+\t\t\t parser_->GetExposureLines(exposureLines) == MdParser::Status::OK &&\n+\t\t\t parser_->GetGainCode(gainCode) == MdParser::Status::OK;\n+\n+\t\tif (!success)\n+\t\t\tLOG(IPARPI, Error) << \"Embedded buffer parsing failed\";\n+\t}\n+\n+\tif (!success) {\n+\t\texposureLines = controls.get(V4L2_CID_EXPOSURE).get<int32_t>();\n+\t\tgainCode = controls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n+\t}\n+\n+\tdeviceStatus.shutter_speed = Exposure(exposureLines);\n+\tdeviceStatus.analogue_gain = Gain(gainCode);\n+\n+\tLOG(IPARPI, Debug) << \"Metadata - Exposure : \"\n+\t\t\t << deviceStatus.shutter_speed\n+\t\t\t << \" Gain : \"\n+\t\t\t << deviceStatus.analogue_gain;\n+\n+\tmetadata.Set(\"device.status\", deviceStatus);\n+}\n+\n RegisterCamHelper::RegisterCamHelper(char const *cam_name,\n \t\t\t\t CamHelperCreateFunc create_func)\n {\ndiff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp\nindex 1b2d6eec..ce5b82d2 100644\n--- a/src/ipa/raspberrypi/cam_helper.hpp\n+++ b/src/ipa/raspberrypi/cam_helper.hpp\n@@ -8,8 +8,13 @@\n \n #include <string>\n \n+#include <libcamera/controls.h>\n+#include <libcamera/span.h>\n+\n #include \"camera_mode.h\"\n+#include \"controller/controller.hpp\"\n #include \"md_parser.hpp\"\n+#include \"controller/metadata.hpp\"\n \n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n@@ -65,7 +70,10 @@ public:\n \tCamHelper(MdParser *parser, unsigned int frameIntegrationDiff);\n \tvirtual ~CamHelper();\n \tvoid SetCameraMode(const CameraMode &mode);\n-\tMdParser &Parser() const { return *parser_; }\n+\tvirtual void Prepare(const libcamera::Span<uint8_t> &buffer,\n+\t\t\t const libcamera::ControlList &controls,\n+\t\t\t Metadata &metadata);\n+\tvirtual void Process(StatisticsPtr &stats, Metadata &metadata);\n \tuint32_t ExposureLines(double exposure_us) const;\n \tdouble Exposure(uint32_t exposure_lines) const; // in us\n \tvirtual uint32_t GetVBlanking(double &exposure_us, double minFrameDuration,\n@@ -81,6 +89,10 @@ public:\n \tvirtual unsigned int MistrustFramesModeSwitch() const;\n \n protected:\n+\tvoid parseRegisters(const libcamera::Span<uint8_t> &buffer,\n+\t\t\t const libcamera::ControlList &controls,\n+\t\t\t Metadata &metadata);\n+\n \tMdParser *parser_;\n \tCameraMode mode_;\n \ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 7904225a..d699540a 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -103,9 +103,6 @@ private:\n \tvoid returnEmbeddedBuffer(unsigned int bufferId);\n \tvoid prepareISP(const ipa::RPi::ISPConfig &data);\n \tvoid reportMetadata();\n-\tbool parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus);\n-\tvoid fillDeviceStatus(uint32_t exposureLines, uint32_t gainCode,\n-\t\t\t 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@@ -913,35 +910,37 @@ void IPARPi::returnEmbeddedBuffer(unsigned int bufferId)\n \n void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data)\n {\n-\tstruct DeviceStatus deviceStatus = {};\n-\tbool success = false;\n+\tSpan<uint8_t> embeddedBuffer;\n+\tbool returnEmbedded = false;\n+\n+\trpiMetadata_.Clear();\n \n \tif (data.embeddedBufferPresent) {\n \t\t/*\n \t\t * Pipeline handler has supplied us with an embedded data buffer,\n-\t\t * so parse it and extract the exposure and gain.\n+\t\t * we must pass it to the CamHelper for parsing.\n \t\t */\n-\t\tsuccess = parseEmbeddedData(data.embeddedBufferId, deviceStatus);\n-\n-\t\t/* Done with embedded data now, return to pipeline handler asap. */\n-\t\treturnEmbeddedBuffer(data.embeddedBufferId);\n+\t\tauto it = buffers_.find(data.embeddedBufferId);\n+\t\tif (it == buffers_.end())\n+\t\t\tLOG(IPARPI, Error) << \"Could not find embedded buffer!\";\n+\t\telse {\n+\t\t\tembeddedBuffer = it->second.maps()[0];\n+\t\t\treturnEmbedded = true;\n+\t\t}\n \t}\n \n-\tif (!success) {\n-\t\t/*\n-\t\t * Pipeline handler has not supplied an embedded data buffer,\n-\t\t * or embedded data buffer parsing has failed for some reason,\n-\t\t * so pull the exposure and gain values from the control list.\n-\t\t */\n-\t\tint32_t exposureLines = data.controls.get(V4L2_CID_EXPOSURE).get<int32_t>();\n-\t\tint32_t gainCode = data.controls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n-\t\tfillDeviceStatus(exposureLines, gainCode, deviceStatus);\n-\t}\n+\t/*\n+\t * This will add the DeviceStatus to the metadata, and depending on the\n+\t * sensor, may do additional custom processing.\n+\t */\n+\thelper_->Prepare(embeddedBuffer, data.controls, rpiMetadata_);\n+\n+\t/* Done with embedded data now, return to pipeline handler asap. */\n+\tif (returnEmbedded)\n+\t\treturnEmbeddedBuffer(data.embeddedBufferId);\n \n \tControlList ctrls(ispCtrls_);\n \n-\trpiMetadata_.Clear();\n-\trpiMetadata_.Set(\"device.status\", deviceStatus);\n \tcontroller_.Prepare(&rpiMetadata_);\n \n \t/* Lock the metadata buffer to avoid constant locks/unlocks. */\n@@ -991,50 +990,6 @@ void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data)\n \t\tsetIspControls.emit(ctrls);\n }\n \n-bool IPARPi::parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus)\n-{\n-\tauto it = buffers_.find(bufferId);\n-\tif (it == buffers_.end()) {\n-\t\tLOG(IPARPI, Error) << \"Could not find embedded buffer!\";\n-\t\treturn false;\n-\t}\n-\n-\tSpan<uint8_t> mem = it->second.maps()[0];\n-\thelper_->Parser().SetBufferSize(mem.size());\n-\tRPiController::MdParser::Status status = helper_->Parser().Parse(mem.data());\n-\tif (status != RPiController::MdParser::Status::OK) {\n-\t\tLOG(IPARPI, Error) << \"Embedded Buffer parsing failed, error \" << status;\n-\t\treturn false;\n-\t} else {\n-\t\tuint32_t exposureLines, gainCode;\n-\t\tif (helper_->Parser().GetExposureLines(exposureLines) != RPiController::MdParser::Status::OK) {\n-\t\t\tLOG(IPARPI, Error) << \"Exposure time failed\";\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tif (helper_->Parser().GetGainCode(gainCode) != RPiController::MdParser::Status::OK) {\n-\t\t\tLOG(IPARPI, Error) << \"Gain failed\";\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tfillDeviceStatus(exposureLines, gainCode, deviceStatus);\n-\t}\n-\n-\treturn true;\n-}\n-\n-void IPARPi::fillDeviceStatus(uint32_t exposureLines, uint32_t gainCode,\n-\t\t\t struct DeviceStatus &deviceStatus)\n-{\n-\tdeviceStatus.shutter_speed = helper_->Exposure(exposureLines);\n-\tdeviceStatus.analogue_gain = helper_->Gain(gainCode);\n-\n-\tLOG(IPARPI, Debug) << \"Metadata - Exposure : \"\n-\t\t\t << deviceStatus.shutter_speed\n-\t\t\t << \" Gain : \"\n-\t\t\t << deviceStatus.analogue_gain;\n-}\n-\n void IPARPi::processStats(unsigned int bufferId)\n {\n \tauto it = buffers_.find(bufferId);\n@@ -1046,6 +1001,7 @@ void IPARPi::processStats(unsigned int bufferId)\n \tSpan<uint8_t> mem = it->second.maps()[0];\n \tbcm2835_isp_stats *stats = reinterpret_cast<bcm2835_isp_stats *>(mem.data());\n \tRPiController::StatisticsPtr statistics = std::make_shared<bcm2835_isp_stats>(*stats);\n+\thelper_->Process(statistics, rpiMetadata_);\n \tcontroller_.Process(statistics, &rpiMetadata_);\n \n \tstruct AgcStatus agcStatus;\n", "prefixes": [ "libcamera-devel", "RFC", "1/1" ] }