Show a patch.

GET /api/1.1/patches/12229/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 12229,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/12229/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/12229/",
    "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": "<20210507113728.14037-2-david.plowman@raspberrypi.com>",
    "date": "2021-05-07T11:37:27",
    "name": "[libcamera-devel,v4,1/2] ipa: raspberrypi: Make sensor embedded data parser use Span class",
    "commit_ref": "df36fb4abb37c216d1eaf60a1772047b5205d0b7",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "59530c5055b81156fcab87bd8a12cb7dc96b2d46",
    "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/12229/mbox/",
    "series": [
        {
            "id": 2012,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2012/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2012",
            "date": "2021-05-07T11:37:26",
            "name": "Raspberry Pi generalised sensor metadata parsing",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/2012/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/12229/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/12229/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 A5E30BF831\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  7 May 2021 11:37:35 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4CF606891E;\n\tFri,  7 May 2021 13:37:35 +0200 (CEST)",
            "from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 93D53602BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  7 May 2021 13:37:32 +0200 (CEST)",
            "by mail-wr1-x435.google.com with SMTP id a4so8888261wrr.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 07 May 2021 04:37:32 -0700 (PDT)",
            "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tw22sm13739009wmc.13.2021.05.07.04.37.31\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 07 May 2021 04:37:31 -0700 (PDT)"
        ],
        "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=\"E7lgAUHB\"; 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=OK8QXok1w8+H9bvA1Y5X2DEO0Zo2BqKFQiJ4Rdn9HkI=;\n\tb=E7lgAUHBvKZBRC5ZOAj7o+LKqLWoj4SAwGJma4tsrggUZb/kKS0lF+ikxOcSeWAKLi\n\tnpQmoBouKlBv/4c+BpyZ9wQIYMROSstC67Zp6b5e9APBwA4/N+1921eAeU1kmSHdfGiZ\n\tHT91T4BnJhWkm+2CWGrx9wdeGF4mTk8ihpY/7pP6pOyNy2xiGKKROzxz7lt19iglBZ3c\n\tnPOsKPDRLWs7aGBYf/D9cq3VfYwfRs9+Iyro65dWyha28wrhjma9qWTQteHn4aqjxgFE\n\t0//1jG6LtsOvfG691gGR3iE5GetDp/UnR7eHB3qMtcQwb8JyyQpadpS4SJ3KnYYUyh1z\n\tzazg==",
        "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=OK8QXok1w8+H9bvA1Y5X2DEO0Zo2BqKFQiJ4Rdn9HkI=;\n\tb=RiQXe0eDKj8YgruogXGRPNX5Fe2eUqsOLC43M7DEbcLyF16fP4gqfg+zM2Rdxs+2SV\n\tPjCh4rlymoeSPu7z2xfspA1e+OUYDUnHezc+xXlxxvj0/JS2rrli1Uo69CDaUTWOQ2xx\n\t38sSTtnGlpLSRrY/CzPh9nRW/fPNhgsQko8+9idqVyrC5QZJiU9KKdTd/Jyl10ktvMDl\n\tBzjnUZEzSaLlr8oOLXi2fiRAfcYTRvnX/lbXueXVLyOUfnf718w+55PGZsERNztQfwJG\n\tZDVxhQxA9fffZYrf6a/dDzp5nkjw/hCov5bubVaNcHnjB4AQAhinQHuBG64JdLNYrOx6\n\t/MbQ==",
        "X-Gm-Message-State": "AOAM532TyxF4/q1CRgJGJkm4aCB/8mqiiFS/39z+MbLPgJfUDmAFeWKG\n\tUlo143bsDKKC/PtX42EPTbIbzM5TkzrJuA==",
        "X-Google-Smtp-Source": "ABdhPJxc5AUwz0YOnI5LieWa3O8ShnKcrfveiZ4WW7cjn7x1pRKmwfkDytfVEzjHDIHsq0kM25FXVw==",
        "X-Received": "by 2002:a05:6000:18a:: with SMTP id\n\tp10mr11909263wrx.345.1620387452051; \n\tFri, 07 May 2021 04:37:32 -0700 (PDT)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  7 May 2021 12:37:27 +0100",
        "Message-Id": "<20210507113728.14037-2-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20210507113728.14037-1-david.plowman@raspberrypi.com>",
        "References": "<20210507113728.14037-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v4 1/2] ipa: raspberrypi: Make sensor\n\tembedded data parser use Span class",
        "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": "Improve MdParser::Parse() by taking a Span, pointing to const data\nthat it should not change, as its input buffer.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/cam_helper_imx219.cpp |  8 ++++----\n src/ipa/raspberrypi/cam_helper_imx477.cpp |  8 ++++----\n src/ipa/raspberrypi/md_parser.cpp         | 23 ++++++++++++-----------\n src/ipa/raspberrypi/md_parser.hpp         | 20 ++++++++------------\n 4 files changed, 28 insertions(+), 31 deletions(-)",
    "diff": "diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp\nindex 566ecbca..e550fba6 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx219.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp\n@@ -29,7 +29,7 @@ class MdParserImx219 : public MdParserSmia\n {\n public:\n \tMdParserImx219();\n-\tStatus Parse(void *data) override;\n+\tStatus Parse(libcamera::Span<const uint8_t> buffer) override;\n \tStatus GetExposureLines(unsigned int &lines) override;\n \tStatus GetGainCode(unsigned int &gain_code) override;\n private:\n@@ -118,7 +118,7 @@ MdParserImx219::MdParserImx219()\n \treg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = -1;\n }\n \n-MdParser::Status MdParserImx219::Parse(void *data)\n+MdParser::Status MdParserImx219::Parse(libcamera::Span<const uint8_t> buffer)\n {\n \tbool try_again = false;\n \n@@ -132,7 +132,7 @@ MdParser::Status MdParserImx219::Parse(void *data)\n \t\t/* Need to be ordered */\n \t\tuint32_t regs[3] = { GAIN_REG, EXPHI_REG, EXPLO_REG };\n \t\treg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = -1;\n-\t\tint ret = static_cast<int>(findRegs(static_cast<uint8_t *>(data),\n+\t\tint ret = static_cast<int>(findRegs(buffer,\n \t\t\t\t\t\t    regs, reg_offsets_, 3));\n \t\t/*\n \t\t * > 0 means \"worked partially but parse again next time\",\n@@ -148,7 +148,7 @@ MdParser::Status MdParserImx219::Parse(void *data)\n \t\tif (reg_offsets_[i] == -1)\n \t\t\tcontinue;\n \n-\t\treg_values_[i] = static_cast<uint8_t *>(data)[reg_offsets_[i]];\n+\t\treg_values_[i] = buffer[reg_offsets_[i]];\n \t}\n \n \t/* Re-parse next time if we were unhappy in some way. */\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp\nindex 73a5ca7d..a4a58c15 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx477.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp\n@@ -21,7 +21,7 @@ class MdParserImx477 : public MdParserSmia\n {\n public:\n \tMdParserImx477();\n-\tStatus Parse(void *data) override;\n+\tStatus Parse(libcamera::Span<const uint8_t> buffer) override;\n \tStatus GetExposureLines(unsigned int &lines) override;\n \tStatus GetGainCode(unsigned int &gain_code) override;\n private:\n@@ -107,7 +107,7 @@ MdParserImx477::MdParserImx477()\n \treg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = reg_offsets_[3] = -1;\n }\n \n-MdParser::Status MdParserImx477::Parse(void *data)\n+MdParser::Status MdParserImx477::Parse(libcamera::Span<const uint8_t> buffer)\n {\n \tbool try_again = false;\n \n@@ -126,7 +126,7 @@ MdParser::Status MdParserImx477::Parse(void *data)\n \t\t\tGAINLO_REG\n \t\t};\n \t\treg_offsets_[0] = reg_offsets_[1] = reg_offsets_[2] = reg_offsets_[3] = -1;\n-\t\tint ret = static_cast<int>(findRegs(static_cast<uint8_t *>(data),\n+\t\tint ret = static_cast<int>(findRegs(buffer,\n \t\t\t\t\t\t    regs, reg_offsets_, 4));\n \t\t/*\n \t\t * > 0 means \"worked partially but parse again next time\",\n@@ -142,7 +142,7 @@ MdParser::Status MdParserImx477::Parse(void *data)\n \t\tif (reg_offsets_[i] == -1)\n \t\t\tcontinue;\n \n-\t\treg_values_[i] = static_cast<uint8_t *>(data)[reg_offsets_[i]];\n+\t\treg_values_[i] = buffer[reg_offsets_[i]];\n \t}\n \n \t/* Re-parse next time if we were unhappy in some way. */\ndiff --git a/src/ipa/raspberrypi/md_parser.cpp b/src/ipa/raspberrypi/md_parser.cpp\nindex d82c102c..852a1d34 100644\n--- a/src/ipa/raspberrypi/md_parser.cpp\n+++ b/src/ipa/raspberrypi/md_parser.cpp\n@@ -27,12 +27,13 @@ using namespace RPiController;\n #define REG_VALUE 0x5a\n #define REG_SKIP 0x55\n \n-MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data,\n+MdParserSmia::ParseStatus MdParserSmia::findRegs(libcamera::Span<const uint8_t> buffer,\n \t\t\t\t\t\t uint32_t regs[], int offsets[],\n \t\t\t\t\t\t unsigned int num_regs)\n {\n \tassert(num_regs > 0);\n-\tif (data[0] != LINE_START)\n+\n+\tif (buffer[0] != LINE_START)\n \t\treturn NO_LINE_START;\n \n \tunsigned int current_offset = 1; // after the LINE_START\n@@ -40,15 +41,15 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data,\n \tunsigned int reg_num = 0, first_reg = 0;\n \tParseStatus retcode = PARSE_OK;\n \twhile (1) {\n-\t\tint tag = data[current_offset++];\n+\t\tint tag = buffer[current_offset++];\n \t\tif ((bits_per_pixel_ == 10 &&\n \t\t     (current_offset + 1 - current_line_start) % 5 == 0) ||\n \t\t    (bits_per_pixel_ == 12 &&\n \t\t     (current_offset + 1 - current_line_start) % 3 == 0)) {\n-\t\t\tif (data[current_offset++] != REG_SKIP)\n+\t\t\tif (buffer[current_offset++] != REG_SKIP)\n \t\t\t\treturn BAD_DUMMY;\n \t\t}\n-\t\tint data_byte = data[current_offset++];\n+\t\tint data_byte = buffer[current_offset++];\n \t\t//printf(\"Offset %u, tag 0x%02x data_byte 0x%02x\\n\", current_offset-1, tag, data_byte);\n \t\tif (tag == LINE_END_TAG) {\n \t\t\tif (data_byte != LINE_END_TAG)\n@@ -59,18 +60,18 @@ MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data,\n \t\t\t\tcurrent_offset =\n \t\t\t\t\tcurrent_line_start + line_length_bytes_;\n \t\t\t\t// Require whole line to be in the buffer (if buffer size set).\n-\t\t\t\tif (buffer_size_bytes_ &&\n+\t\t\t\tif (buffer.size() &&\n \t\t\t\t    current_offset + line_length_bytes_ >\n-\t\t\t\t\t    buffer_size_bytes_)\n+\t\t\t\t\t    buffer.size())\n \t\t\t\t\treturn MISSING_REGS;\n-\t\t\t\tif (data[current_offset] != LINE_START)\n+\t\t\t\tif (buffer[current_offset] != LINE_START)\n \t\t\t\t\treturn NO_LINE_START;\n \t\t\t} else {\n \t\t\t\t// allow a zero line length to mean \"hunt for the next line\"\n-\t\t\t\twhile (data[current_offset] != LINE_START &&\n-\t\t\t\t       current_offset < buffer_size_bytes_)\n+\t\t\t\twhile (buffer[current_offset] != LINE_START &&\n+\t\t\t\t       current_offset < buffer.size())\n \t\t\t\t\tcurrent_offset++;\n-\t\t\t\tif (current_offset == buffer_size_bytes_)\n+\t\t\t\tif (current_offset == buffer.size())\n \t\t\t\t\treturn NO_LINE_START;\n \t\t\t}\n \t\t\t// inc current_offset to after LINE_START\ndiff --git a/src/ipa/raspberrypi/md_parser.hpp b/src/ipa/raspberrypi/md_parser.hpp\nindex 926f676e..8e22b1d7 100644\n--- a/src/ipa/raspberrypi/md_parser.hpp\n+++ b/src/ipa/raspberrypi/md_parser.hpp\n@@ -8,6 +8,8 @@\n \n #include <stdint.h>\n \n+#include <libcamera/span.h>\n+\n /* Camera metadata parser class. Usage as shown below.\n \n Setup:\n@@ -21,17 +23,15 @@ parser->SetBitsPerPixel(bpp);\n parser->SetLineLengthBytes(pitch);\n parser->SetNumLines(2);\n \n-Note 1: if you don't know how many lines there are, you can use SetBufferSize\n-instead to limit the total buffer size.\n+Note 1: if you don't know how many lines there are, the size of the input\n+buffer is used as a limit instead.\n \n Note 2: if you don't know the line length, you can leave the line length unset\n-(or set to zero) and the parser will hunt for the line start instead. In this\n-case SetBufferSize *must* be used so that the parser won't run off the end of\n-the buffer.\n+(or set to zero) and the parser will hunt for the line start instead.\n \n Then on every frame:\n \n-if (parser->Parse(data) != MdParser::OK)\n+if (parser->Parse(buffer) != MdParser::OK)\n     much badness;\n unsigned int exposure_lines, gain_code\n if (parser->GetExposureLines(exposure_lines) != MdParser::OK)\n@@ -75,11 +75,7 @@ public:\n \t{\n \t\tline_length_bytes_ = num_bytes;\n \t}\n-\tvoid SetBufferSize(unsigned int num_bytes)\n-\t{\n-\t\tbuffer_size_bytes_ = num_bytes;\n-\t}\n-\tvirtual Status Parse(void *data) = 0;\n+\tvirtual Status Parse(libcamera::Span<const uint8_t> buffer) = 0;\n \tvirtual Status GetExposureLines(unsigned int &lines) = 0;\n \tvirtual Status GetGainCode(unsigned int &gain_code) = 0;\n \n@@ -116,7 +112,7 @@ protected:\n \t\tBAD_LINE_END  = -4,\n \t\tBAD_PADDING   = -5\n \t};\n-\tParseStatus findRegs(unsigned char *data, uint32_t regs[],\n+\tParseStatus findRegs(libcamera::Span<const uint8_t> buffer, uint32_t regs[],\n \t\t\t     int offsets[], unsigned int num_regs);\n };\n \n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "1/2"
    ]
}