Patch Detail
Show a patch.
GET /api/1.1/patches/2941/?format=api
{ "id": 2941, "url": "https://patchwork.libcamera.org/api/1.1/patches/2941/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2941/", "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": "<20200229164254.23604-25-laurent.pinchart@ideasonboard.com>", "date": "2020-02-29T16:42:47", "name": "[libcamera-devel,24/31] libcamera: byte_stream_buffer: Add zero-copy read() variant", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "820bfb4ee63475421f0a3a899b423d0dbf7b88e4", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2941/mbox/", "series": [ { "id": 696, "url": "https://patchwork.libcamera.org/api/1.1/series/696/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=696", "date": "2020-02-29T16:42:23", "name": "libcamera: Add support for array controls", "version": 1, "mbox": "https://patchwork.libcamera.org/series/696/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2941/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2941/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C482F6279D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Feb 2020 17:43:30 +0100 (CET)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 61BFB33E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Feb 2020 17:43:30 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1582994610;\n\tbh=zhDNblkfSQLU1G/Vc9G29AQadAk7T5KBXLiuFTv8eOw=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=ArfzMrLUNbjW3j7LSunCEANX03X+MimCcLAPJ/Al3+ix/NXVgjdWpdfYED6fJMqAu\n\ti4yt/Jcd1j1gmMDdEucIaO3RAF4iMg7fknxUFeI5C0T+vPk8Z7641L5BZ89865HN4d\n\tJkNc5jLU9nXDlABTCS1ewGuEc+6nq/h7a2u53Qes=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 29 Feb 2020 18:42:47 +0200", "Message-Id": "<20200229164254.23604-25-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200229164254.23604-1-laurent.pinchart@ideasonboard.com>", "References": "<20200229164254.23604-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 24/31] libcamera: byte_stream_buffer: Add\n\tzero-copy read() variant", "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>", "X-List-Received-Date": "Sat, 29 Feb 2020 16:43:36 -0000" }, "content": "Add a read() function to ByteStreamBuffer that returns a pointer to the\ndata instead of copying it. Overflow check is still handled by the\nclass, but the caller must check the returned pointer explicitly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/byte_stream_buffer.cpp | 39 ++++++++++++++++++++++\n src/libcamera/include/byte_stream_buffer.h | 9 +++++\n 2 files changed, 48 insertions(+)", "diff": "diff --git a/src/libcamera/byte_stream_buffer.cpp b/src/libcamera/byte_stream_buffer.cpp\nindex 40380bf0434a..576f556f54a7 100644\n--- a/src/libcamera/byte_stream_buffer.cpp\n+++ b/src/libcamera/byte_stream_buffer.cpp\n@@ -241,6 +241,19 @@ int ByteStreamBuffer::skip(size_t size)\n * \\retval -ENOSPC no more space is available in the managed memory buffer\n */\n \n+/**\n+ * \\fn template<typename T> const T *ByteStreamBuffer::read(size_t count)\n+ * \\brief Read data from the managed memory buffer without copy\n+ * \\param[in] count Number of data items to read\n+ *\n+ * This function read \\a count elements of type \\a T from the buffer. Unlike\n+ * the other read variants, it doesn't copy the data but returns a pointer to\n+ * the first element. If data can't be read for any reason (usually due to\n+ * reading more data than available), the function returns nullptr.\n+ *\n+ * \\return A pointer to the data on success, or nullptr otherwise\n+ */\n+\n /**\n * \\fn template<typename T> int ByteStreamBuffer::write(const T *t)\n * \\brief Write \\a t to the managed memory buffer\n@@ -259,6 +272,32 @@ int ByteStreamBuffer::skip(size_t size)\n * \\retval -ENOSPC no more space is available in the managed memory buffer\n */\n \n+const uint8_t *ByteStreamBuffer::read(size_t size, size_t count)\n+{\n+\tif (!read_)\n+\t\treturn nullptr;\n+\n+\tif (overflow_)\n+\t\treturn nullptr;\n+\n+\tsize_t bytes;\n+\tif (__builtin_mul_overflow(size, count, &bytes)) {\n+\t\tsetOverflow();\n+\t\treturn nullptr;\n+\t}\n+\n+\tif (read_ + bytes > base_ + size_) {\n+\t\tLOG(Serialization, Error)\n+\t\t\t<< \"Unable to read \" << bytes << \" bytes: out of bounds\";\n+\t\tsetOverflow();\n+\t\treturn nullptr;\n+\t}\n+\n+\tconst uint8_t *data = read_;\n+\tread_ += bytes;\n+\treturn data;\n+}\n+\n int ByteStreamBuffer::read(uint8_t *data, size_t size)\n {\n \tif (!read_)\ndiff --git a/src/libcamera/include/byte_stream_buffer.h b/src/libcamera/include/byte_stream_buffer.h\nindex 17cb0146061e..b3aaa8b9fb28 100644\n--- a/src/libcamera/include/byte_stream_buffer.h\n+++ b/src/libcamera/include/byte_stream_buffer.h\n@@ -9,6 +9,7 @@\n \n #include <stddef.h>\n #include <stdint.h>\n+#include <type_traits>\n \n #include <libcamera/span.h>\n \n@@ -43,6 +44,13 @@ public:\n \t\t\t data.size_bytes());\n \t}\n \n+\ttemplate<typename T>\n+\tconst std::remove_reference_t<T> *read(size_t count = 1)\n+\t{\n+\t\tusing return_type = const std::remove_reference_t<T> *;\n+\t\treturn reinterpret_cast<return_type>(read(sizeof(T), count));\n+\t}\n+\n \ttemplate<typename T>\n \tint write(const T *t)\n \t{\n@@ -63,6 +71,7 @@ private:\n \tvoid setOverflow();\n \n \tint read(uint8_t *data, size_t size);\n+\tconst uint8_t *read(size_t size, size_t count);\n \tint write(const uint8_t *data, size_t size);\n \n \tByteStreamBuffer *parent_;\n", "prefixes": [ "libcamera-devel", "24/31" ] }