From patchwork Wed Aug 11 12:40:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13303 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 2C13FBD87D for ; Wed, 11 Aug 2021 12:40:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DA2376888C; Wed, 11 Aug 2021 14:40:29 +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="AiagiqC1"; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0428468887 for ; Wed, 11 Aug 2021 14:40:28 +0200 (CEST) Received: by mail-pj1-x102a.google.com with SMTP id lw7-20020a17090b1807b029017881cc80b7so9297041pjb.3 for ; Wed, 11 Aug 2021 05:40:27 -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=loAwEKmkTZ2pc3VR3JLr5v3gT+NaKdhxObYxcW9rqlI=; b=AiagiqC1cHWqHXMRoHnNZLZ5DWn+wyhWZ7QH8wpa6OB+d2c+BHi3xs99z17f2VNLFf IokR3Tje0NFQXuOzpHxi7kjsGdcpCE8EX8ERjugE7zo5HyPzkgzvuMlqCAcfT3B/8icb 9e8d0dwG2Mhl/e8IaXmL6XQlOt6TzQw5RRjLA= 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=loAwEKmkTZ2pc3VR3JLr5v3gT+NaKdhxObYxcW9rqlI=; b=Xyp8VC44BBxfErYH9+U1x2k6SbB9mqNgKXwTXMH4KsTFfDH/nLZ/Df49tGoG2l9jzu cBPD6tsRKdF5o9wXd2L45GTMQIi0FsW4Z5XQAY4tilSuo4Yg0DhHvTlCK+wQ9GG0kHFJ VUMy9OdfLZogD6PniNuWkeSyp7uDZmVI2sUvC9mAiT9j4RdsH1lEcMH/OuFYJSi5hReW CecAsjSc8bg0Sp6sNUYypfFk64UEaeJkxXgv5/fV1V2X3CBFW/ExJw3/XowYeZSb1eP8 ZgYoKpvMhtJfUzqysAkfCJC6jFtSPj5NBSuwiZvekg3V93TlUOrH6FicieN6u4MePnFF YxDA== X-Gm-Message-State: AOAM531HDeiF/QvLZTTXgQNDy4B8HgV2ZoTjMbQ52dnKWBN8DueUTkK8 lR8BeiBe44t5VcE+dXV3KuQZraXp9uZ/sg== X-Google-Smtp-Source: ABdhPJwMetrLR6tN6wG3toFICjLlwaMgU8y1Z/J1srwMU1/aR8ON92Dy8ohqqDp1970qeDa8In3w+w== X-Received: by 2002:a17:90b:903:: with SMTP id bo3mr19232948pjb.103.1628685626304; Wed, 11 Aug 2021 05:40:26 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:ba11:c25e:242c:485d]) by smtp.gmail.com with ESMTPSA id p30sm15722876pfh.116.2021.08.11.05.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:40:25 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 11 Aug 2021 21:40:12 +0900 Message-Id: <20210811124015.2116188-3-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog In-Reply-To: <20210811124015.2116188-1-hiroh@chromium.org> References: <20210811124015.2116188-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/5] cam: file_sink: Fix wrong mapping planes 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" FileSink maps FrameBuffer in a wrong way that the mapped data points the address of a buffer, not plane. This fixes it. Signed-off-by: Hirokazu Honda --- src/cam/file_sink.cpp | 30 +++++++++++++++++++++++++----- src/cam/file_sink.h | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp index 2d30694a..267f7ea2 100644 --- a/src/cam/file_sink.cpp +++ b/src/cam/file_sink.cpp @@ -51,12 +51,32 @@ int FileSink::configure(const libcamera::CameraConfiguration &config) void FileSink::mapBuffer(FrameBuffer *buffer) { + /* \todo Use MappedFrameBuffer. */ + size_t offset = 0; + int prevFd = -1; 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 (prevFd != fd) { + const size_t length = lseek(fd, 0, SEEK_END); + void *address = mmap(nullptr, length, PROT_READ, + MAP_SHARED, fd, 0); + if (address == MAP_FAILED) { + std::cerr << "Failed to mmap plane: " + << strerror(errno) << std::endl; + return; + } + mappedBuffers_[fd] = std::make_pair(address, length); + prevFd = fd; + } - mappedBuffers_[plane.fd.fd()] = - std::make_pair(memory, plane.length); + uint8_t *buf = static_cast(mappedBuffers_[fd].first); + /* + * This offset calculation assumes planes are consecutive. + * \todo remove this assumption once offset is introduced to + * FrameBuffer::Plane. + */ + planeData_[fd] = static_cast(buf + offset); + offset += plane.length; } } @@ -102,7 +122,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; + void *data = planeData_[plane.fd.fd()]; 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..d236d6d8 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__ */