From patchwork Mon Aug 23 13:12:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13447 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D8CACBD87C for ; Mon, 23 Aug 2021 13:12:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 832EF688A6; Mon, 23 Aug 2021 15:12:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EqhpK8Lh"; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A1B83688D2 for ; Mon, 23 Aug 2021 15:12:41 +0200 (CEST) Received: by mail-pf1-x42e.google.com with SMTP id x16so15329511pfh.2 for ; Mon, 23 Aug 2021 06:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ub6vFbEA76Qz1icj8AASyaVTq9tX0ZQYDwgHf6xWUDM=; b=EqhpK8LhfNmZi6ZAzIpD1MvHBeyLaqLnjX9TFBfxmBcZq7UBKcErFWptbh4fA1tSq1 3vS+qN3g/9EkSpTlkM0XeIUTk5wDvDBzZS8qsGTDdP/Uqmub6aJOQszHUeqqmSiR2f6E v1zMHlsLXBQk+WFqWC23EnZtwC1Cx1BTXtl2A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ub6vFbEA76Qz1icj8AASyaVTq9tX0ZQYDwgHf6xWUDM=; b=JPK5qN7nfKML7/OI73DxTPEcqea1JJ89JQHM0iH6JRbsMTuYUQNocgqxPHQfrbK52w fYeOIGgMSxs1vyNFrUL5R4g12TdUmIWlZeSp0yFkCKaTPFk0m8yocYDTjn7kHNGRQq95 fPWqbDGVxrJnQUEf5UGQqtqrXm5gJ7YxyQuEiXclkqSNKYMZQaPVUQNsivleFjIyyZ9W YQ11UO+nqnBNot3BcTaOhJhjRsMM4G7TbjSeLXKSaj1nNtQO6E33BPydy4zUzs2jkXkU HZbElHmK8noKwnCaFTTQDdNlVUL/87+n69vu3bMAlh9uz9Fu+deZmKj/fsLjKkyMsjUA MV8Q== X-Gm-Message-State: AOAM532bxQGRZkw8kE6sa8Gd25V2OH8p3uolKDKEIGyB72QoAlHOoh+g +15/9fJwJMX7IE3+e6d/eW3Zt35BM6u2fQ== X-Google-Smtp-Source: ABdhPJxY6yyNkTLgPD6xGJlIziq4Cs9IxQSM4sQNBDJZzikgUcYRBrL9QWRKRK65wJilwzg31/zfXg== X-Received: by 2002:a62:3301:0:b0:3eb:2fee:87cc with SMTP id z1-20020a623301000000b003eb2fee87ccmr5217633pfz.62.1629724359970; Mon, 23 Aug 2021 06:12:39 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:184e:5d20:8fcb:dfcd]) by smtp.gmail.com with ESMTPSA id j4sm18596891pgi.6.2021.08.23.06.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 06:12:39 -0700 (PDT) From: Hirokazu Honda 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 Subject: [libcamera-devel] [RFC PATCH v2 04/10] cam: file_sink: Use offset in mapping FrameBuffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This fixes the way of mapping FrameBuffer in FrameSink by using offset. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/cam/file_sink.cpp | 22 +++++++++++++++++----- src/cam/file_sink.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp index 2d30694a..26a60058 100644 --- a/src/cam/file_sink.cpp +++ b/src/cam/file_sink.cpp @@ -51,12 +51,24 @@ int FileSink::configure(const libcamera::CameraConfiguration &config) void FileSink::mapBuffer(FrameBuffer *buffer) { + /* \todo use MappedFrameBuffer. */ for (const FrameBuffer::Plane &plane : buffer->planes()) { - void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED, - plane.fd.fd(), 0); + const int fd = plane.fd.fd(); + if (mappedBuffers_.find(fd) == mappedBuffers_.end()) { + /** + * \todo Should we try to only map the portions of the + * dmabuf that are used by planes ? + */ + size_t length = lseek(fd, 0, SEEK_END); + void *memory = mmap(NULL, plane.length, PROT_READ, + MAP_SHARED, plane.fd.fd(), 0); + mappedBuffers_[plane.fd.fd()] = + std::make_pair(memory, length); - mappedBuffers_[plane.fd.fd()] = - std::make_pair(memory, plane.length); + } + + void *memory = mappedBuffers_[fd].first; + planeData_[&plane] = static_cast(memory) + plane.offset; } } @@ -102,7 +114,7 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer) const FrameBuffer::Plane &plane = buffer->planes()[i]; const FrameMetadata::Plane &meta = buffer->metadata().planes[i]; - void *data = mappedBuffers_[plane.fd.fd()].first; + uint8_t *data = planeData_[&plane]; unsigned int length = std::min(meta.bytesused, plane.length); if (meta.bytesused > plane.length) diff --git a/src/cam/file_sink.h b/src/cam/file_sink.h index c3eb230a..c12325d9 100644 --- a/src/cam/file_sink.h +++ b/src/cam/file_sink.h @@ -33,6 +33,7 @@ private: std::map streamNames_; std::string pattern_; std::map> mappedBuffers_; + std::map planeData_; }; #endif /* __CAM_FILE_SINK_H__ */