[{"id":19015,"web_url":"https://patchwork.libcamera.org/comment/19015/","msgid":"<YSQj0pw3P1IpIsPZ@pendragon.ideasonboard.com>","date":"2021-08-23T22:40:18","subject":"Re: [libcamera-devel] [RFC PATCH v2 04/10] cam: file_sink: Use\n\toffset in mapping FrameBuffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Hiro,\n\nThank you for the patch.\n\nOn Mon, Aug 23, 2021 at 10:12:15PM +0900, Hirokazu Honda wrote:\n> This fixes the way of mapping FrameBuffer in FrameSink by\n> using offset.\n> \n> Signed-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(-)\n> \n> diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp\n> index 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\nTabs for indentation.\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\nYou can use fd instead of plane.fd.fd().\n\n>  \n\nAnd you can drop this blank line.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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)\n> diff --git a/src/cam/file_sink.h b/src/cam/file_sink.h\n> index 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__ */","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 8FC8EBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 22:40:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0048D688A3;\n\tTue, 24 Aug 2021 00:40:30 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DCCF568890\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Aug 2021 00:40:28 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 529CA2A5;\n\tTue, 24 Aug 2021 00:40:28 +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=\"WgWGwvRk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629758428;\n\tbh=knYrbWATphp52MDoYvfhF2JFGtXTDzLxlW7zxjLbMyY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=WgWGwvRkEAPbW9UJOFmUobvbR21KgrIPLeYSmQryb/TXMFJjdmWAD7T20pnvPlm7L\n\tqFciTrOT/qVq8EiuX3B2chg4yDEOAM8OH+tTBEN2ApMb1SY/Jg4m2CN5weLMdTULnh\n\tU4pPD22d1mT78kGJhFseSax+GPjgQhgJwyqd3HyI=","Date":"Tue, 24 Aug 2021 01:40:18 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YSQj0pw3P1IpIsPZ@pendragon.ideasonboard.com>","References":"<20210823131221.1034059-1-hiroh@chromium.org>\n\t<20210823131221.1034059-5-hiroh@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210823131221.1034059-5-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [RFC PATCH v2 04/10] cam: file_sink: Use\n\toffset in 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]