{"id":13303,"url":"https://patchwork.libcamera.org/api/patches/13303/?format=json","web_url":"https://patchwork.libcamera.org/patch/13303/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20210811124015.2116188-3-hiroh@chromium.org>","date":"2021-08-11T12:40:12","name":"[libcamera-devel,RFC,2/5] cam: file_sink: Fix wrong mapping planes","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"b52c2f319785231dade94c7d7ee4d5f760ba2938","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13303/mbox/","series":[{"id":2339,"url":"https://patchwork.libcamera.org/api/series/2339/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2339","date":"2021-08-11T12:40:10","name":"MappedFrameBuffer::maps() returns the plane address","version":1,"mbox":"https://patchwork.libcamera.org/series/2339/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13303/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13303/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 2C13FBD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Aug 2021 12:40:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA2376888C;\n\tWed, 11 Aug 2021 14:40:29 +0200 (CEST)","from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com\n\t[IPv6:2607:f8b0:4864:20::102a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0428468887\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Aug 2021 14:40:28 +0200 (CEST)","by mail-pj1-x102a.google.com with SMTP id\n\tlw7-20020a17090b1807b029017881cc80b7so9297041pjb.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Aug 2021 05:40:27 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:ba11:c25e:242c:485d])\n\tby smtp.gmail.com with ESMTPSA id\n\tp30sm15722876pfh.116.2021.08.11.05.40.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 11 Aug 2021 05:40:25 -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=\"AiagiqC1\"; 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=loAwEKmkTZ2pc3VR3JLr5v3gT+NaKdhxObYxcW9rqlI=;\n\tb=AiagiqC1cHWqHXMRoHnNZLZ5DWn+wyhWZ7QH8wpa6OB+d2c+BHi3xs99z17f2VNLFf\n\tIokR3Tje0NFQXuOzpHxi7kjsGdcpCE8EX8ERjugE7zo5HyPzkgzvuMlqCAcfT3B/8icb\n\t9e8d0dwG2Mhl/e8IaXmL6XQlOt6TzQw5RRjLA=","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=loAwEKmkTZ2pc3VR3JLr5v3gT+NaKdhxObYxcW9rqlI=;\n\tb=Xyp8VC44BBxfErYH9+U1x2k6SbB9mqNgKXwTXMH4KsTFfDH/nLZ/Df49tGoG2l9jzu\n\tcBPD6tsRKdF5o9wXd2L45GTMQIi0FsW4Z5XQAY4tilSuo4Yg0DhHvTlCK+wQ9GG0kHFJ\n\tVUMy9OdfLZogD6PniNuWkeSyp7uDZmVI2sUvC9mAiT9j4RdsH1lEcMH/OuFYJSi5hReW\n\tCecAsjSc8bg0Sp6sNUYypfFk64UEaeJkxXgv5/fV1V2X3CBFW/ExJw3/XowYeZSb1eP8\n\tZgYoKpvMhtJfUzqysAkfCJC6jFtSPj5NBSuwiZvekg3V93TlUOrH6FicieN6u4MePnFF\n\tYxDA==","X-Gm-Message-State":"AOAM531HDeiF/QvLZTTXgQNDy4B8HgV2ZoTjMbQ52dnKWBN8DueUTkK8\n\tlR8BeiBe44t5VcE+dXV3KuQZraXp9uZ/sg==","X-Google-Smtp-Source":"ABdhPJwMetrLR6tN6wG3toFICjLlwaMgU8y1Z/J1srwMU1/aR8ON92Dy8ohqqDp1970qeDa8In3w+w==","X-Received":"by 2002:a17:90b:903:: with SMTP id\n\tbo3mr19232948pjb.103.1628685626304; \n\tWed, 11 Aug 2021 05:40:26 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH 2/5] cam: file_sink: Fix wrong mapping\n\tplanes","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":"FileSink maps FrameBuffer in a wrong way that the mapped data points\nthe address of a buffer, not plane. This fixes it.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/cam/file_sink.cpp | 30 +++++++++++++++++++++++++-----\n src/cam/file_sink.h   |  1 +\n 2 files changed, 26 insertions(+), 5 deletions(-)","diff":"diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp\nindex 2d30694a..267f7ea2 100644\n--- a/src/cam/file_sink.cpp\n+++ b/src/cam/file_sink.cpp\n@@ -51,12 +51,32 @@ int FileSink::configure(const libcamera::CameraConfiguration &config)\n \n void FileSink::mapBuffer(FrameBuffer *buffer)\n {\n+\t/* \\todo Use MappedFrameBuffer. */\n+\tsize_t offset = 0;\n+\tint prevFd = -1;\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 (prevFd != fd) {\n+\t\t\tconst size_t length = lseek(fd, 0, SEEK_END);\n+\t\t\tvoid *address = mmap(nullptr, length, PROT_READ,\n+\t\t\t\t\t     MAP_SHARED, fd, 0);\n+\t\t\tif (address == MAP_FAILED) {\n+\t\t\t\tstd::cerr << \"Failed to mmap plane: \"\n+\t\t\t\t\t  << strerror(errno) << std::endl;\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t\tmappedBuffers_[fd] = std::make_pair(address, length);\n+\t\t\tprevFd = fd;\n+\t\t}\n \n-\t\tmappedBuffers_[plane.fd.fd()] =\n-\t\t\tstd::make_pair(memory, plane.length);\n+\t\tuint8_t *buf = static_cast<uint8_t *>(mappedBuffers_[fd].first);\n+\t\t/*\n+\t\t * This offset calculation assumes planes are consecutive.\n+\t\t * \\todo remove this assumption once offset is introduced to\n+\t\t * FrameBuffer::Plane.\n+\t\t */\n+\t\tplaneData_[fd] = static_cast<void *>(buf + offset);\n+\t\toffset += plane.length;\n \t}\n }\n \n@@ -102,7 +122,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\tvoid *data = planeData_[plane.fd.fd()];\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..d236d6d8 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<int, void *> planeData_;\n };\n \n #endif /* __CAM_FILE_SINK_H__ */\n","prefixes":["libcamera-devel","RFC","2/5"]}