{"id":13447,"url":"https://patchwork.libcamera.org/api/1.1/patches/13447/?format=json","web_url":"https://patchwork.libcamera.org/patch/13447/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210823131221.1034059-5-hiroh@chromium.org>","date":"2021-08-23T13:12:15","name":"[libcamera-devel,RFC,v2,04/10] cam: file_sink: Use offset in mapping FrameBuffer","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ba993644e6abdd736c3b199a1e605f5aa6718ffa","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13447/mbox/","series":[{"id":2386,"url":"https://patchwork.libcamera.org/api/1.1/series/2386/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2386","date":"2021-08-23T13:12:11","name":"Add offset to FrameBuffer::Plane","version":2,"mbox":"https://patchwork.libcamera.org/series/2386/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13447/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13447/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 D8CACBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 13:12:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 832EF688A6;\n\tMon, 23 Aug 2021 15:12:43 +0200 (CEST)","from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com\n\t[IPv6:2607:f8b0:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A1B83688D2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 15:12:41 +0200 (CEST)","by mail-pf1-x42e.google.com with SMTP id x16so15329511pfh.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 06:12:41 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:184e:5d20:8fcb:dfcd])\n\tby smtp.gmail.com with ESMTPSA id\n\tj4sm18596891pgi.6.2021.08.23.06.12.38\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Aug 2021 06:12:39 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"EqhpK8Lh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=ub6vFbEA76Qz1icj8AASyaVTq9tX0ZQYDwgHf6xWUDM=;\n\tb=EqhpK8LhfNmZi6ZAzIpD1MvHBeyLaqLnjX9TFBfxmBcZq7UBKcErFWptbh4fA1tSq1\n\t3vS+qN3g/9EkSpTlkM0XeIUTk5wDvDBzZS8qsGTDdP/Uqmub6aJOQszHUeqqmSiR2f6E\n\tv1zMHlsLXBQk+WFqWC23EnZtwC1Cx1BTXtl2A=","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=ub6vFbEA76Qz1icj8AASyaVTq9tX0ZQYDwgHf6xWUDM=;\n\tb=JPK5qN7nfKML7/OI73DxTPEcqea1JJ89JQHM0iH6JRbsMTuYUQNocgqxPHQfrbK52w\n\tfYeOIGgMSxs1vyNFrUL5R4g12TdUmIWlZeSp0yFkCKaTPFk0m8yocYDTjn7kHNGRQq95\n\tfPWqbDGVxrJnQUEf5UGQqtqrXm5gJ7YxyQuEiXclkqSNKYMZQaPVUQNsivleFjIyyZ9W\n\tYQ11UO+nqnBNot3BcTaOhJhjRsMM4G7TbjSeLXKSaj1nNtQO6E33BPydy4zUzs2jkXkU\n\tHZbElHmK8noKwnCaFTTQDdNlVUL/87+n69vu3bMAlh9uz9Fu+deZmKj/fsLjKkyMsjUA\n\tMV8Q==","X-Gm-Message-State":"AOAM532bxQGRZkw8kE6sa8Gd25V2OH8p3uolKDKEIGyB72QoAlHOoh+g\n\t+15/9fJwJMX7IE3+e6d/eW3Zt35BM6u2fQ==","X-Google-Smtp-Source":"ABdhPJxY6yyNkTLgPD6xGJlIziq4Cs9IxQSM4sQNBDJZzikgUcYRBrL9QWRKRK65wJilwzg31/zfXg==","X-Received":"by 2002:a62:3301:0:b0:3eb:2fee:87cc with SMTP id\n\tz1-20020a623301000000b003eb2fee87ccmr5217633pfz.62.1629724359970; \n\tMon, 23 Aug 2021 06:12:39 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 23 Aug 2021 22:12:15 +0900","Message-Id":"<20210823131221.1034059-5-hiroh@chromium.org>","X-Mailer":"git-send-email 2.33.0.rc2.250.ged5fa647cd-goog","In-Reply-To":"<20210823131221.1034059-1-hiroh@chromium.org>","References":"<20210823131221.1034059-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH v2 04/10] cam: file_sink: Use offset\n\tin mapping FrameBuffer","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":"This fixes the way of mapping FrameBuffer in FrameSink by\nusing offset.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/cam/file_sink.cpp | 22 +++++++++++++++++-----\n src/cam/file_sink.h   |  1 +\n 2 files changed, 18 insertions(+), 5 deletions(-)","diff":"diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp\nindex 2d30694a..26a60058 100644\n--- a/src/cam/file_sink.cpp\n+++ b/src/cam/file_sink.cpp\n@@ -51,12 +51,24 @@ 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\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n-\t\t\t\t    plane.fd.fd(), 0);\n+\t\tconst int fd = plane.fd.fd();\n+\t\tif (mappedBuffers_.find(fd) == mappedBuffers_.end()) {\n+\t\t\t/**\n+                         * \\todo Should we try to only map the portions of the\n+                         * dmabuf that are used by planes ?\n+                         */\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, plane.fd.fd(), 0);\n+\t\t\tmappedBuffers_[plane.fd.fd()] =\n+\t\t\t\tstd::make_pair(memory, length);\n \n-\t\tmappedBuffers_[plane.fd.fd()] =\n-\t\t\tstd::make_pair(memory, plane.length);\n+\t\t}\n+\n+\t\tvoid *memory = mappedBuffers_[fd].first;\n+\t\tplaneData_[&plane] = static_cast<uint8_t *>(memory) + plane.offset;\n \t}\n }\n \n@@ -102,7 +114,7 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)\n \t\tconst FrameBuffer::Plane &plane = buffer->planes()[i];\n \t\tconst FrameMetadata::Plane &meta = buffer->metadata().planes[i];\n \n-\t\tvoid *data = mappedBuffers_[plane.fd.fd()].first;\n+\t\tuint8_t *data = planeData_[&plane];\n \t\tunsigned int length = std::min(meta.bytesused, plane.length);\n \n \t\tif (meta.bytesused > plane.length)\ndiff --git a/src/cam/file_sink.h b/src/cam/file_sink.h\nindex c3eb230a..c12325d9 100644\n--- a/src/cam/file_sink.h\n+++ b/src/cam/file_sink.h\n@@ -33,6 +33,7 @@ private:\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 };\n \n #endif /* __CAM_FILE_SINK_H__ */\n","prefixes":["libcamera-devel","RFC","v2","04/10"]}