Patch Detail
Show a patch.
GET /api/1.1/patches/13689/?format=api
{ "id": 13689, "url": "https://patchwork.libcamera.org/api/1.1/patches/13689/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13689/", "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": "<20210906225636.14683-22-laurent.pinchart@ideasonboard.com>", "date": "2021-09-06T22:56:28", "name": "[libcamera-devel,v3,22/30] cam: file_sink: Use Image class to access pixel data", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "93956a5710cfdddaba20d85693319d7645427b36", "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/13689/mbox/", "series": [ { "id": 2482, "url": "https://patchwork.libcamera.org/api/1.1/series/2482/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2482", "date": "2021-09-06T22:54:20", "name": "libcamera: Handle fallout of FrameBuffer offset support", "version": 3, "mbox": "https://patchwork.libcamera.org/series/2482/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13689/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13689/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 2CC4EBE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 6 Sep 2021 22:57:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DE00569180;\n\tTue, 7 Sep 2021 00:57:47 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C435F6917D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 7 Sep 2021 00:57:07 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5A184B75;\n\tTue, 7 Sep 2021 00:57:07 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IcYJjze+\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969027;\n\tbh=9LYXnKijRFq02UZEC0V6piQFmCHLvjmAkL0qY8FYUGk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IcYJjze+hTZoJet9CodqqPDcIPJ3XNAitZ2ZzRE+5qgTqDn2mPYF7Jil6Wyz+ZbvF\n\tsDn+WZnckQoXw+w079VqsGNAoVeAE6+1tfWj2HNXmQ5IHgJiZeTvaltB4zSSNUjDE7\n\tYcPLjqdky96l4FDB3g39Pd6wTI5dN2ndumsTtvhU=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 7 Sep 2021 01:56:28 +0300", "Message-Id": "<20210906225636.14683-22-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>", "References": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 22/30] cam: file_sink: Use Image class\n\tto access pixel data", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Replace the manual implementation of frame buffer mapping with the Image\nclass to improve code sharing.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/cam/file_sink.cpp | 42 +++++++++++++-----------------------------\n src/cam/file_sink.h | 6 ++++--\n 2 files changed, 17 insertions(+), 31 deletions(-)", "diff": "diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp\nindex 0fc7d621f50b..3c2e565b27a2 100644\n--- a/src/cam/file_sink.cpp\n+++ b/src/cam/file_sink.cpp\n@@ -5,17 +5,18 @@\n * file_sink.cpp - File Sink\n */\n \n+#include <assert.h>\n #include <fcntl.h>\n #include <iomanip>\n #include <iostream>\n #include <sstream>\n #include <string.h>\n-#include <sys/mman.h>\n #include <unistd.h>\n \n #include <libcamera/camera.h>\n \n #include \"file_sink.h\"\n+#include \"image.h\"\n \n using namespace libcamera;\n \n@@ -26,12 +27,6 @@ FileSink::FileSink(const std::string &pattern)\n \n FileSink::~FileSink()\n {\n-\tfor (auto &iter : mappedBuffers_) {\n-\t\tvoid *memory = iter.second.first;\n-\t\tunsigned int length = iter.second.second;\n-\t\tmunmap(memory, length);\n-\t}\n-\tmappedBuffers_.clear();\n }\n \n int FileSink::configure(const libcamera::CameraConfiguration &config)\n@@ -51,23 +46,11 @@ int FileSink::configure(const libcamera::CameraConfiguration &config)\n \n void FileSink::mapBuffer(FrameBuffer *buffer)\n {\n-\t/* \\todo use MappedFrameBuffer. */\n-\tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n-\t\tconst int fd = plane.fd.fd();\n-\t\tif (mappedBuffers_.find(fd) == mappedBuffers_.end()) {\n-\t\t\t/**\n-\t\t\t * \\todo Should we try to only map the portions of the\n-\t\t\t * dmabuf that are used by planes ?\n-\t\t\t */\n-\t\t\tsize_t length = lseek(fd, 0, SEEK_END);\n-\t\t\tvoid *memory = mmap(NULL, plane.length, PROT_READ,\n-\t\t\t\t\t MAP_SHARED, fd, 0);\n-\t\t\tmappedBuffers_[fd] = std::make_pair(memory, length);\n-\t\t}\n+\tstd::unique_ptr<Image> image =\n+\t\tImage::fromFrameBuffer(buffer, Image::MapMode::ReadOnly);\n+\tassert(image != nullptr);\n \n-\t\tvoid *memory = mappedBuffers_[fd].first;\n-\t\tplaneData_[&plane] = static_cast<uint8_t *>(memory) + plane.offset;\n-\t}\n+\tmappedBuffers_[buffer] = std::move(image);\n }\n \n bool FileSink::processRequest(Request *request)\n@@ -108,19 +91,20 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)\n \t\treturn;\n \t}\n \n+\tImage *image = mappedBuffers_[buffer].get();\n+\n \tfor (unsigned int i = 0; i < buffer->planes().size(); ++i) {\n-\t\tconst FrameBuffer::Plane &plane = buffer->planes()[i];\n \t\tconst FrameMetadata::Plane &meta = buffer->metadata().planes()[i];\n \n-\t\tuint8_t *data = planeData_[&plane];\n-\t\tunsigned int length = std::min(meta.bytesused, plane.length);\n+\t\tSpan<uint8_t> data = image->data(i);\n+\t\tunsigned int length = std::min<unsigned int>(meta.bytesused, data.size());\n \n-\t\tif (meta.bytesused > plane.length)\n+\t\tif (meta.bytesused > data.size())\n \t\t\tstd::cerr << \"payload size \" << meta.bytesused\n-\t\t\t\t << \" larger than plane size \" << plane.length\n+\t\t\t\t << \" larger than plane size \" << data.size()\n \t\t\t\t << std::endl;\n \n-\t\tret = ::write(fd, data, length);\n+\t\tret = ::write(fd, data.data(), length);\n \t\tif (ret < 0) {\n \t\t\tret = -errno;\n \t\t\tstd::cerr << \"write error: \" << strerror(-ret)\ndiff --git a/src/cam/file_sink.h b/src/cam/file_sink.h\nindex c12325d955c5..335be93b8732 100644\n--- a/src/cam/file_sink.h\n+++ b/src/cam/file_sink.h\n@@ -8,12 +8,15 @@\n #define __CAM_FILE_SINK_H__\n \n #include <map>\n+#include <memory>\n #include <string>\n \n #include <libcamera/stream.h>\n \n #include \"frame_sink.h\"\n \n+class Image;\n+\n class FileSink : public FrameSink\n {\n public:\n@@ -32,8 +35,7 @@ private:\n \n \tstd::map<const libcamera::Stream *, std::string> streamNames_;\n \tstd::string pattern_;\n-\tstd::map<int, std::pair<void *, unsigned int>> mappedBuffers_;\n-\tstd::map<const libcamera::FrameBuffer::Plane *, uint8_t *> planeData_;\n+\tstd::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;\n };\n \n #endif /* __CAM_FILE_SINK_H__ */\n", "prefixes": [ "libcamera-devel", "v3", "22/30" ] }