From patchwork Thu Aug 26 11:25:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13504 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 C569CC3241 for ; Thu, 26 Aug 2021 11:25:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 74E8D68911; Thu, 26 Aug 2021 13:25:54 +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="WBphvbHn"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B77AB6888F for ; Thu, 26 Aug 2021 13:25:52 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id t42so2469815pfg.12 for ; Thu, 26 Aug 2021 04:25:52 -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=q/Zu6lDSYz71bUvfOG/40k/PmICM3E/IwpM3XH1WsjU=; b=WBphvbHnfI372IWs7vpZsRjGeiCg8YAK6X2ViDip3GdWYyx46HHuRot1c2Ada8gceX JNQz7cOCx/Z1p42w8shJHjkxfSKjjUm+daEB3rgYg6JqJMSb2anX0vILTBTiQ4U2D7rB Ufx6k2J63K2Y3I8dbOqag4YoHaVg6L6WsFHGs= 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=q/Zu6lDSYz71bUvfOG/40k/PmICM3E/IwpM3XH1WsjU=; b=BvFBGB4HoKjzdC8PGJ/lrT3IN34BP67OKuegVZIr2PrcQHQiya27nUb0wCXMIBiPqz 92kz08TiNgG1LWiiJP0LQUy7J40JLoBtapssgw+61W9SIPHLecmhCy26WrDynoE8Sd5o 3uYK5WYKAvhdes9vXBbeNzGBKSn3xBeD2hO+HFcVKK0s13UEleG6ySU3rqnrV5JOE31g AWFEToeHkbhGsAJwGikSooZ/P/JuDVFUHP5Ptd0lxydZUv6GjWQJ6XiNGWVJcpdNpSiD B1cfpzYymF+6mmBiMQacmTmbTLNlPt7mFxEFBWk1E/V/dsOKbfKAUvxsIj3u69RTfw8R E6KA== X-Gm-Message-State: AOAM532whiEyKoNW0UNjvbbbAtRc/HT4Ev3SwjUFPnrUokaQxALe5q2i fkLLHrVSWJI6dRGR+Hv4x8Ymrdsk0pXn6w== X-Google-Smtp-Source: ABdhPJzsK0Nko9nEck78hKdBCoqdfLRbNDu4QnifLpWoMFpp/k8usaWzbuTZULKJ64kjfLo1GkcWcQ== X-Received: by 2002:aa7:94ac:0:b0:3e0:f21a:e6ff with SMTP id a12-20020aa794ac000000b003e0f21ae6ffmr3283615pfl.76.1629977151036; Thu, 26 Aug 2021 04:25:51 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a5bc:b3dd:7208:bec1]) by smtp.gmail.com with ESMTPSA id s29sm3472057pgl.38.2021.08.26.04.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:50 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:33 +0900 Message-Id: <20210826112539.170694-4-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210826112539.170694-1-hiroh@chromium.org> References: <20210826112539.170694-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/9] 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 | 20 +++++++++++++++----- src/cam/file_sink.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp index 2d30694a..0b529e3e 100644 --- a/src/cam/file_sink.cpp +++ b/src/cam/file_sink.cpp @@ -51,12 +51,22 @@ 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, fd, 0); + mappedBuffers_[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 +112,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__ */