From patchwork Thu Aug 26 11:25:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13502 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 BB120BD87C for ; Thu, 26 Aug 2021 11:25:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 848D368911; Thu, 26 Aug 2021 13:25:51 +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="n7J7aybe"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A84C6890C for ; Thu, 26 Aug 2021 13:25:48 +0200 (CEST) Received: by mail-pj1-x102b.google.com with SMTP id z24-20020a17090acb1800b0018e87a24300so2152968pjt.0 for ; Thu, 26 Aug 2021 04:25:48 -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=wG9z/g9FQd1O8kxRzBe7Lxs5OeUPvX5W5GJCjSV3vmk=; b=n7J7aybelzfalJnBm0WRp5fldoAN8CG7vh/jDS8PQRB5pfu7yHzUCPbGyfJpgWsUGf rl256/cGVw9tl19J/rpdDLaI8m0TKQNoU9VoR5TCnEqtrKWKdtRH/94wbB8jNjIHZVu0 qtZJMpEtCVwx2W81Cl9egxfK+b75TPyKYt148= 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=wG9z/g9FQd1O8kxRzBe7Lxs5OeUPvX5W5GJCjSV3vmk=; b=WojU+9udjdEhE9LWA8/pPJkeryT1AXDSokHwo/AkOAQVTvKWpOLs31z/zAofKsaHsJ 0GQFL0kIR1E9eSekGzb0Szc7joVJadkS6B4gEOU5OdHVJLZkEOrrUxnoBWjmVv28LXss Iux1lm/7sJ1bKgN7uE4RTvJKnKscugtc5F0pZFlZYc3Fd7rBe+aiybm/2NUq3Wat0vuN 1kxuzPS9GsybcdxIfDAYzGliSu3MEM+F21ytyEAnpPG+RrTd0JxuJwioYaWTqk1N9i1U pfgw8hHJWWEhDXMZdyJZU5KubKxgAPyJNz4xB0n/2pqWjo7wNHfeVm3GcjgV3frmyWgD 0dhg== X-Gm-Message-State: AOAM533QwLt4ipjBRgv4PWWfV9YL+2ymAFKZsMfQajh1Q+ryRwWFUz4g TzsTGGlWHp5cNsJ19F3VNQGxcriFnGZaMw== X-Google-Smtp-Source: ABdhPJx+N+Sxgm8LOJ59FvlLXDK/VbLfTQjn+KwR/2upevWedWwhBsZHriKaAjRrD7QP50bjNwyRZQ== X-Received: by 2002:a17:902:c406:b0:12d:d0ff:fb7 with SMTP id k6-20020a170902c40600b0012dd0ff0fb7mr3184398plk.70.1629977147126; Thu, 26 Aug 2021 04:25:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:46 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:31 +0900 Message-Id: <20210826112539.170694-2-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 1/9] libcamera: framebuffer: Add offset to FrameBuffer::Plane 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 adds offset to FrameBuffer::Plane. It enables representing frame buffers that store planes in the same dmabuf at different offsets, as for instance required by the V4L2 NV12 pixel format. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/framebuffer.h | 1 + src/libcamera/framebuffer.cpp | 24 +++++++++++++++++------- src/libcamera/ipa_data_serializer.cpp | 5 ++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index 28307890..5de3c744 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -42,6 +42,7 @@ class FrameBuffer final : public Extensible public: struct Plane { FileDescriptor fd; + unsigned int offset; unsigned int length; }; diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index b401c50e..bf7a52ad 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -131,7 +131,7 @@ FrameBuffer::Private::Private() * * The static information describes the memory planes that make a frame. The * planes are specified when creating the FrameBuffer and are expressed as a set - * of dmabuf file descriptors and length. + * of dmabuf file descriptors, offset and length. * * The dynamic information is grouped in a FrameMetadata instance. It is updated * during the processing of a queued capture request, and is valid from the @@ -151,18 +151,23 @@ FrameBuffer::Private::Private() * * Planar pixel formats use multiple memory regions to store the different * colour components of a frame. The Plane structure describes such a memory - * region by a dmabuf file descriptor and a length. A FrameBuffer then - * contains one or multiple planes, depending on the pixel format of the - * frames it is meant to store. + * region by a dmabuf file descriptor, an offset within the dmabuf and a length. + * A FrameBuffer then contains one or multiple planes, depending on the pixel + * format of the frames it is meant to store. + * + * The offset identifies the location of the plane data from the start of the + * memory referenced by the dmabuf file descriptor. Multiple planes may be + * stored in the same dmabuf, in which case they will reference the same dmabuf + * and different offsets. No two planes may overlap, as specified by their + * offset and length. * * To support DMA access, planes are associated with dmabuf objects represented * by FileDescriptor handles. The Plane class doesn't handle mapping of the * memory to the CPU, but applications and IPAs may use the dmabuf file * descriptors to map the plane memory with mmap() and access its contents. * - * \todo Once we have a Kernel API which can express offsets within a plane - * this structure shall be extended to contain this information. See commit - * 83148ce8be55e for initial documentation of this feature. + * \todo Specify how an application shall decide whether to use a single or + * multiple dmabufs, based on the camera requirements. */ /** @@ -170,6 +175,11 @@ FrameBuffer::Private::Private() * \brief The dmabuf file descriptor */ +/** + * \var FrameBuffer::Plane::offset + * \brief The plane offset in bytes +*/ + /** * \var FrameBuffer::Plane::length * \brief The plane length in bytes diff --git a/src/libcamera/ipa_data_serializer.cpp b/src/libcamera/ipa_data_serializer.cpp index 5b183c70..82ec9b20 100644 --- a/src/libcamera/ipa_data_serializer.cpp +++ b/src/libcamera/ipa_data_serializer.cpp @@ -569,6 +569,7 @@ FileDescriptor IPADataSerializer::deserialize(const std::vector< * FrameBuffer::Plane is serialized as: * * 4 byte - FileDescriptor + * 4 bytes - uint32_t Offset * 4 bytes - uint32_t Length */ template<> @@ -586,6 +587,7 @@ IPADataSerializer::serialize(const FrameBuffer::Plane &data, dataVec.insert(dataVec.end(), fdBuf.begin(), fdBuf.end()); fdsVec.insert(fdsVec.end(), fdFds.begin(), fdFds.end()); + appendPOD(dataVec, data.offset); appendPOD(dataVec, data.length); return { dataVec, fdsVec }; @@ -603,7 +605,8 @@ IPADataSerializer::deserialize(std::vector::const_i ret.fd = IPADataSerializer::deserialize(dataBegin, dataBegin + 4, fdsBegin, fdsBegin + 1); - ret.length = readPOD(dataBegin, 4, dataEnd); + ret.offset = readPOD(dataBegin, 4, dataEnd); + ret.length = readPOD(dataBegin, 8, dataEnd); return ret; } From patchwork Thu Aug 26 11:25:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13503 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 2E019BD87C 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 E8C4D688E5; Thu, 26 Aug 2021 13:25:53 +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="ilKQd1gz"; dkim-atps=neutral Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 007316888F for ; Thu, 26 Aug 2021 13:25:51 +0200 (CEST) Received: by mail-pg1-x536.google.com with SMTP id s11so2767524pgr.11 for ; Thu, 26 Aug 2021 04:25:50 -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=cIFc40HtWtIL1OXXk5WK2FVqnWkKAedNtYJqkR0Jv9o=; b=ilKQd1gzKKrqtL2RB0XR0+1LuddO+uRvU6Yi2Cg6ol34AMpW4VYzlSkZe4Xm7Ommas 3xJruwhmBZdwxALFlVgQIPPiq7scVO7LYNu7i0zMDBRVoBkhiT6vKTE6F1ii6kqi1l5V LhWhWlmrui9V/8WWHxY6Nhv3Sw2fm/pErh2cY= 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=cIFc40HtWtIL1OXXk5WK2FVqnWkKAedNtYJqkR0Jv9o=; b=OMZnRlXK3T7L7UUbR1vH3Ia66GY2o7GufTAxpsB8JzOCKZlpx3aMNqc0/v3ZUlHB6S 7jBJ6wTh1H4BkpVBMDbU1OlcsrpuHXi20DaeTaF9p/iVm9x3vpkw0nNTGO7vrpqPwFK0 WD0mIKK4r62jPr4MtixMCGfLHiVgl11Bwba4KcT3mlicJNJX2l2dmSKcvEeL22Ppo5iZ MjwXYV253sp+Svvkm/SiB3JRPlP6rkqoESsuX7tOLJgADlC5ESn6t1YlsW/dEWqnuy2t wyhB/nPWK19heKddLLFUp6zRBL50pZdEm/pv8bOcSls+tmfWT1ZaEyVGuBILaQF/UlVj hvbQ== X-Gm-Message-State: AOAM5323YI/828tmg0CKKSG0vc3WxWAfEk8tmaEXEq6pz6uMCseUWyIh G/rkndAFVieW1w6Zwc86JQMQHGhBEJP5gQ== X-Google-Smtp-Source: ABdhPJwQBxs+c58Adv7oOLpc6yXiCMztbBLJCZBzymldjl3+aYTeGaXhDKZJqe0fE20ZGuj+qPb/ig== X-Received: by 2002:a62:58c2:0:b0:3eb:31ee:cfb9 with SMTP id m185-20020a6258c2000000b003eb31eecfb9mr3412374pfb.31.1629977149163; Thu, 26 Aug 2021 04:25:49 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:48 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:32 +0900 Message-Id: <20210826112539.170694-3-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 2/9] libcamera: mapped_framebuffer: Return plane begin address by MappedBuffer::maps() 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" MappedBuffer::maps() returns std::vector. Plane has the address, but the address points the beginning of the buffer containing the plane. This makes the Plane point the beginning of the plane. So MappedBuffer::maps()[i].data() returns the address of i-th plane. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- .../libcamera/internal/mapped_framebuffer.h | 4 +- src/android/mm/generic_camera_buffer.cpp | 2 - src/libcamera/mapped_framebuffer.cpp | 71 ++++++++++++++++--- src/libcamera/v4l2_videodevice.cpp | 6 ++ 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index 3401a9fc..42479541 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -30,12 +30,14 @@ public: bool isValid() const { return error_ == 0; } int error() const { return error_; } - const std::vector &maps() const { return maps_; } + /* \todo rename to planes(). */ + const std::vector &maps() const { return planes_; } protected: MappedBuffer(); int error_; + std::vector planes_; std::vector maps_; private: diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index d4f3f22b..299a5496 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -53,8 +53,6 @@ private: int flags_; off_t bufferLength_; std::vector planeInfo_; - /* \todo Remove planes_ when it will be added to MappedBuffer */ - std::vector> planes_; }; CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer, diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp index 2ebe9fdb..1dc88647 100644 --- a/src/libcamera/mapped_framebuffer.cpp +++ b/src/libcamera/mapped_framebuffer.cpp @@ -7,8 +7,11 @@ #include "libcamera/internal/mapped_framebuffer.h" +#include #include +#include #include +#include #include @@ -79,6 +82,7 @@ MappedBuffer::MappedBuffer(MappedBuffer &&other) MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other) { error_ = other.error_; + planes_ = std::move(other.planes_); maps_ = std::move(other.maps_); other.error_ = -ENOENT; @@ -127,10 +131,18 @@ MappedBuffer::~MappedBuffer() */ /** - * \var MappedBuffer::maps_ + * \var MappedBuffer::planes_ * \brief Stores the internal mapped planes * * MappedBuffer derived classes shall store the mappings they create in this + * vector which points the beginning of mapped plane addresses. + */ + +/** + * \var MappedBuffer::maps_ + * \brief Stores the mapped buffer + * + * MappedBuffer derived classes shall store the mappings they create in this * vector which is parsed during destruct to unmap any memory mappings which * completed successfully. */ @@ -167,7 +179,8 @@ MappedBuffer::~MappedBuffer() */ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) { - maps_.reserve(buffer->planes().size()); + ASSERT(!buffer->planes().empty()); + planes_.reserve(buffer->planes().size()); int mmapFlags = 0; @@ -177,17 +190,55 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) if (flags & MapFlag::Write) mmapFlags |= PROT_WRITE; + struct MappedBufferInfo { + uint8_t *address = nullptr; + size_t mapLength = 0; + size_t dmabufLength = 0; + }; + std::map mappedBuffers; + + for (const FrameBuffer::Plane &plane : buffer->planes()) { + const int fd = plane.fd.fd(); + if (mappedBuffers.find(fd) == mappedBuffers.end()) { + const size_t length = lseek(fd, 0, SEEK_END); + mappedBuffers[fd] = MappedBufferInfo{ nullptr, 0, length }; + } + + const size_t length = mappedBuffers[fd].dmabufLength; + + if (plane.offset > length || + plane.offset + plane.length > length) { + LOG(Buffer, Fatal) << "plane is out of buffer: " + << "buffer length=" << length + << ", plane offset=" << plane.offset + << ", plane length=" << plane.length; + return; + } + size_t &mapLength = mappedBuffers[fd].mapLength; + mapLength = std::max(mapLength, + static_cast(plane.offset + plane.length)); + } + for (const FrameBuffer::Plane &plane : buffer->planes()) { - void *address = mmap(nullptr, plane.length, mmapFlags, - MAP_SHARED, plane.fd.fd(), 0); - if (address == MAP_FAILED) { - error_ = -errno; - LOG(Buffer, Error) << "Failed to mmap plane: " - << strerror(-error_); - break; + const int fd = plane.fd.fd(); + auto &info = mappedBuffers[fd]; + if (!info.address) { + void *address = + static_cast( + mmap(nullptr, info.mapLength, mmapFlags, + MAP_SHARED, fd, 0)); + if (address == MAP_FAILED) { + error_ = -errno; + LOG(Buffer, Error) << "Failed to mmap plane: " + << strerror(-error_); + return; + } + + info.address = static_cast(address); + maps_.emplace_back(info.address, info.mapLength); } - maps_.emplace_back(static_cast(address), plane.length); + planes_.emplace_back(info.address + plane.offset, plane.length); } } diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ce60dff6..2ff25af2 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1283,6 +1283,12 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) FrameBuffer::Plane plane; plane.fd = std::move(fd); + /* + * V4L2 API doesn't provide dmabuf offset information of plane. + * Set 0 as a placeholder offset. + * \todo Set the right offset once V4L2 API provides a way. + */ + plane.offset = 0; plane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length; 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__ */ From patchwork Thu Aug 26 11:25:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13505 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 62040BD87C for ; Thu, 26 Aug 2021 11:25:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14FC2688E5; Thu, 26 Aug 2021 13:25:57 +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="dDT5kqFK"; dkim-atps=neutral Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E0A268919 for ; Thu, 26 Aug 2021 13:25:54 +0200 (CEST) Received: by mail-pg1-x52a.google.com with SMTP id x4so2823140pgh.1 for ; Thu, 26 Aug 2021 04:25:54 -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=7WvogKrN3bFtWOlOa6LHh6IQxO3Sjs4Hr9+xtUUr+hI=; b=dDT5kqFKNx271UQC7hby897M1T4YQEDUUrEX0Liz3Lp7Pwg7TE34bDxcwgADFSNror 5YAkHfcft890/ksNF+8kbej6sI6yYVuQC0ju5a7+esw3Q9/rJaemYb+Vt6n60xuAn5pX iy3yJr9v7GFjHGUA9XIAzjFkCpww0js7XJ9zs= 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=7WvogKrN3bFtWOlOa6LHh6IQxO3Sjs4Hr9+xtUUr+hI=; b=KFbRYcuj9eqaSOn2qaiVBchCgK9iVzkhjqL9poanx7AKgdmUAfa3MafeDe6Lh+PkBV OUNgdUYvEW7jbUcNUCXQfRTu8mtmhavobon9Jbl2OF3motwEULvVt5XSve9T5/aACXKc H+NJIcYY+rJFa79B+//pJ40fXcZKA+Cr03EKZHRAQjs7lFESOt9LdovtKU39e6CPx/o8 TfqTvj8kSqnrcoygmtKM1wLMtzv1dtRpJtoO5+bhwrvplDx4d7ryTUvJ9LEDjuTBb/Yw /1PF/Jc32no0MHP9GlL4NInIpbm2SDIVhit12NsemF/4I9FxeRVD9m0+EpxwHr3JLIDC flrg== X-Gm-Message-State: AOAM5335wH+qiizTWJnsOsKn+TCC2vFW3hfr97a3qoL831fL4gBmtjvj t9107rL544ZLQyMQCEWG8u4th9oQib889w== X-Google-Smtp-Source: ABdhPJxnp/20qjd+05zyuyDFVWalGUnU4fTB2Yu/sdqa/ipd9sTJfPU/9haaYuY25Bn96bHoq3s+xQ== X-Received: by 2002:a62:7b50:0:b029:3cd:e227:3486 with SMTP id w77-20020a627b500000b02903cde2273486mr3372294pfc.74.1629977152810; Thu, 26 Aug 2021 04:25:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:52 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:34 +0900 Message-Id: <20210826112539.170694-5-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 4/9] ipa: rkisp1: Use offset in mapping IPABuffer 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" IPABuffer is represented by FrameBuffer. FrameBuffer::Plane has now an offset. This uses the offset variable to map the IPABuffer. The mapped IPABuffer is represented and managed as MappedFrameBuffer. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/ipa/rkisp1/rkisp1.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 06fb9640..046816e0 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -24,6 +23,8 @@ #include #include +#include + namespace libcamera { LOG_DEFINE_CATEGORY(IPARkISP1) @@ -54,7 +55,7 @@ private: void metadataReady(unsigned int frame, unsigned int aeState); std::map buffers_; - std::map buffersMemory_; + std::map mappedBuffers_; ControlInfoMap ctrls_; @@ -160,22 +161,13 @@ void IPARkISP1::mapBuffers(const std::vector &buffers) std::forward_as_tuple(buffer.planes)); const FrameBuffer &fb = elem.first->second; - /* - * \todo Provide a helper to mmap() buffers (possibly exposed - * to applications). - */ - buffersMemory_[buffer.id] = mmap(NULL, - fb.planes()[0].length, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fb.planes()[0].fd.fd(), - 0); - - if (buffersMemory_[buffer.id] == MAP_FAILED) { - int ret = -errno; + MappedFrameBuffer mappedBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite); + if (!mappedBuffer.isValid()) { LOG(IPARkISP1, Fatal) << "Failed to mmap buffer: " - << strerror(-ret); + << strerror(mappedBuffer.error()); } + + mappedBuffers_.emplace(buffer.id, std::move(mappedBuffer)); } } @@ -186,8 +178,7 @@ void IPARkISP1::unmapBuffers(const std::vector &ids) if (fb == buffers_.end()) continue; - munmap(buffersMemory_[id], fb->second.planes()[0].length); - buffersMemory_.erase(id); + mappedBuffers_.erase(id); buffers_.erase(id); } } @@ -200,7 +191,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event) unsigned int bufferId = event.bufferId; const rkisp1_stat_buffer *stats = - static_cast(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_.at(bufferId).maps()[0].data()); updateStatistics(frame, stats); break; @@ -210,7 +202,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event) unsigned int bufferId = event.bufferId; rkisp1_params_cfg *params = - static_cast(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_.at(bufferId).maps()[0].data()); queueRequest(frame, params, event.controls); break; From patchwork Thu Aug 26 11:25:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13506 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 429A2C3242 for ; Thu, 26 Aug 2021 11:26:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D0F3168918; Thu, 26 Aug 2021 13:25:59 +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="XcNJu1pc"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C2726891B for ; Thu, 26 Aug 2021 13:25:58 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id mq3so1972271pjb.5 for ; Thu, 26 Aug 2021 04:25:58 -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=w3io4ICj3+SqN8WinyGtF95ZiA98f5dYRzFd6Imr/mY=; b=XcNJu1pcFv4ezLL3mn6zO2tEPAhoBiJZzbNU6ITJQfzd/LzI9DaazqSVyAjb20gzV5 E4ZLh+EGnZHcU0aSDSBcgJKcTIHqQKi/tAfrrgQvampUbSngF/qZHReVH3sNaceE1VvJ Wre+kDLqCAxLmOmXpyqYDJzfOIpv0EltO07Xo= 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=w3io4ICj3+SqN8WinyGtF95ZiA98f5dYRzFd6Imr/mY=; b=eTvDnwCBKyp8CX+UMbodFzxE4bZMSAZA15JPMzKpIxdmcD5nuPc6DS6JhpYWYihAar 6f9GzcZWBMFZ1eaieW6tM7kpIds9dxpWRS3HyKTY5P8tZXQedygOEa/L3mPVKCrJFqdH KBaIYSOYri7Csev7rKW+23UhylQ+JoGFRnDvaK1yDmrvyR2sYrz4PmtAucvjhHQ+Xxo3 /y5V1r1V74Nv+h+4Q9yij0oglbahlZDqxUc69twAN+DD9BAnOkMFkGnoMONrWcRdL4uo zZrtGKMXYhTNNvhNt0Myq0WmDeKh9ZVlw5A0kuwq5Lai3vOjhqfhdbY4jjBux8SEhKIL 9/oA== X-Gm-Message-State: AOAM532AtRieKr0I0qJEbEle4dG/y+ipMEBz08jQFaTDFsaDvGdHrRtg czlT77z8vKugHxiIeT4frG+b8/jCy1OKtw== X-Google-Smtp-Source: ABdhPJwJudQ0T46wu5edtVH3PyDj57kM3dlctnvBBMCA8u9ge5/W+Yj3T/Kn2pwoZDykikRjNEZfQA== X-Received: by 2002:a17:902:dac6:b0:138:85a7:ef80 with SMTP id q6-20020a170902dac600b0013885a7ef80mr1470898plx.45.1629977156410; Thu, 26 Aug 2021 04:25:56 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:55 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:36 +0900 Message-Id: <20210826112539.170694-7-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 6/9] gstreamer: gstlibcameraallocator: Use offset in creating a buffer 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: , Cc: Nicolas Dufresne Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The plane length is the length of the plane size. The buffer length to be allocated for a plane is the offset and the length of FrameBuffer::Plane. Signed-off-by: Hirokazu Honda Reviewed-by: Nicolas Dufresne Reviewed-by: Laurent Pinchart --- src/gstreamer/gstlibcameraallocator.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp index 7bd8ba2d..60ead273 100644 --- a/src/gstreamer/gstlibcameraallocator.cpp +++ b/src/gstreamer/gstlibcameraallocator.cpp @@ -52,8 +52,10 @@ FrameWrap::FrameWrap(GstAllocator *allocator, FrameBuffer *buffer, outstandingPlanes_(0) { for (const FrameBuffer::Plane &plane : buffer->planes()) { - GstMemory *mem = gst_fd_allocator_alloc(allocator, plane.fd.fd(), plane.length, + GstMemory *mem = gst_fd_allocator_alloc(allocator, plane.fd.fd(), + plane.offset + plane.length, GST_FD_MEMORY_FLAG_DONT_CLOSE); + gst_memory_resize(mem, plane.offset, plane.length); gst_mini_object_set_qdata(GST_MINI_OBJECT(mem), getQuark(), this, nullptr); GST_MINI_OBJECT(mem)->dispose = gst_libcamera_allocator_release; g_object_unref(mem->allocator); From patchwork Thu Aug 26 11:25:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13507 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 85DADC3243 for ; Thu, 26 Aug 2021 11:26:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3F4876891B; Thu, 26 Aug 2021 13:26:02 +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="NAomP8cE"; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF6FD6891B for ; Thu, 26 Aug 2021 13:25:59 +0200 (CEST) Received: by mail-pl1-x636.google.com with SMTP id m4so1633017pll.0 for ; Thu, 26 Aug 2021 04:25:59 -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=RKGsxDXeIpUrZGD7PC/qMrhFninvZF/n+M+4dHhZyu8=; b=NAomP8cEGvvsXLbkdDFJlrWyryxfoGYJ9IKGalcxCkkrJPNU/9YhUOWki5/rwZyvoM PltQ7p8lC03qrlacnSVu/LTPpFBAZYUb+RMAiIJp8p06tejOICu8QFLg2hkCAkevF6HF PZU1Lpji1Gvdjf7S7RARihGYgR5EOHu5NuoQc= 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=RKGsxDXeIpUrZGD7PC/qMrhFninvZF/n+M+4dHhZyu8=; b=Pai30Chpt2/JJ//ZGHkbRyQm29b0WlcIcD5NEAXLmOStQpkryrsDt8xsJXR5dNPWD5 Lz0f3CJSSdSsEhnJ1rHmuO/e3clAVMZ7oyz1BRDwkb3MInia6YXAvq2HHMxVliB69/3E DFd9xJfORvZathHhjiXYHhgZ1F7eAGWHOprBO9U13AXV1hhjYYFle9q8fhwQgiiwI346 H8x8A5ztLkRi//rbnp9U1oj0K5O237ElCHj1C+SC/4uXcYqm4+1R4BPjK1CS5rhM6WXH IWchPG52bvcSjC8J+QZ6oJPA+pMm2zO1rp7pdCmw0744nFXnkwxpTBtNloQo5bW2XyKm SbYw== X-Gm-Message-State: AOAM531jGJaRfk7JoSG6mJyb0hOXpQpT+5f2NtBw+6s8RNM9aVeVT6ug ghTY/pbK2OUrZU3apiBsmXAgT/4QfuRXMg== X-Google-Smtp-Source: ABdhPJwXU7p2z3HT9a3DLxWOlPUWX3VUZCDAaB7HDdWzQOWN03BODRn2cs3sbuAuratVetVfhx1+lg== X-Received: by 2002:a17:90a:680a:: with SMTP id p10mr3760726pjj.179.1629977158131; Thu, 26 Aug 2021 04:25:58 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:57 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:37 +0900 Message-Id: <20210826112539.170694-8-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 7/9] V4L2VideDevice::createBuffer() creates the same number of FrameBuffer::Planes as V4L2 format planes. Therefore, if the v4l2 format single is single-planar format, the created number of FrameBuffer::Planes is 1. It should rather create the same number of FrameBuffer::Planes as the color format 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" Signed-off-by: Hirokazu Honda --- include/libcamera/internal/v4l2_videodevice.h | 10 +- src/libcamera/v4l2_videodevice.cpp | 141 ++++++++++++++---- test/v4l2_videodevice/buffer_cache.cpp | 6 +- 3 files changed, 123 insertions(+), 34 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index e767ec84..bfda6726 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -114,8 +114,9 @@ struct V4L2Capability final : v4l2_capability { class V4L2BufferCache { public: - V4L2BufferCache(unsigned int numEntries); - V4L2BufferCache(const std::vector> &buffers); + V4L2BufferCache(unsigned int numEntries, unsigned int numPlanes); + V4L2BufferCache(const std::vector> &buffers, + unsigned int numPlanes); ~V4L2BufferCache(); int get(const FrameBuffer &buffer); @@ -126,7 +127,8 @@ private: { public: Entry(); - Entry(bool free, uint64_t lastUsed, const FrameBuffer &buffer); + Entry(bool free, uint64_t lastUsed, unsigned int numPlanes, + const FrameBuffer &buffer); bool operator==(const FrameBuffer &buffer) const; @@ -149,6 +151,7 @@ private: std::atomic lastUsedCounter_; std::vector cache_; + unsigned int numPlanes_; /* \todo Expose the miss counter through an instrumentation API. */ unsigned int missCounter_; }; @@ -242,6 +245,7 @@ private: FrameBuffer *dequeueBuffer(); V4L2Capability caps_; + V4L2DeviceFormat format_; enum v4l2_buf_type bufferType_; enum v4l2_memory memoryType_; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 2ff25af2..f5f8741a 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -25,6 +25,7 @@ #include +#include "libcamera/internal/formats.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/media_object.h" @@ -157,13 +158,15 @@ LOG_DECLARE_CATEGORY(V4L2) /** * \brief Create an empty cache with \a numEntries entries * \param[in] numEntries Number of entries to reserve in the cache + * \param[in] numPlanes Number of V4L2 buffer planes * - * Create a cache with \a numEntries entries all marked as unused. The entries - * will be populated as the cache is used. This is typically used to implement - * buffer import, with buffers added to the cache as they are queued. + * Create a cache with \a numEntries entries all marked as unused. The entry is + * for \a numPlanes planes V4L2 buffer. The entries will be populated as the + * cache is used. This is typically used to implement buffer import, with + * buffers added to the cache as they are queued. */ -V4L2BufferCache::V4L2BufferCache(unsigned int numEntries) - : lastUsedCounter_(1), missCounter_(0) +V4L2BufferCache::V4L2BufferCache(unsigned int numEntries, unsigned int numPlanes) + : lastUsedCounter_(1), numPlanes_(numPlanes), missCounter_(0) { cache_.resize(numEntries); } @@ -171,17 +174,20 @@ V4L2BufferCache::V4L2BufferCache(unsigned int numEntries) /** * \brief Create a pre-populated cache * \param[in] buffers Array of buffers to pre-populated with + * \param[in] numPlanes Number of V4L2 buffer planes * - * Create a cache pre-populated with \a buffers. This is typically used to - * implement buffer export, with all buffers added to the cache when they are - * allocated. + * Create a cache pre-populated with \a buffers. The entry is for \a numPlanes + * planes V4L2 buffer. This is typically used to implement buffer export, with + * all buffers added to the cache when they are allocated. */ -V4L2BufferCache::V4L2BufferCache(const std::vector> &buffers) - : lastUsedCounter_(1), missCounter_(0) +V4L2BufferCache::V4L2BufferCache(const std::vector> &buffers, + unsigned int numPlanes) + : lastUsedCounter_(1), numPlanes_(numPlanes), missCounter_(0) { for (const std::unique_ptr &buffer : buffers) cache_.emplace_back(true, lastUsedCounter_.fetch_add(1, std::memory_order_acq_rel), + numPlanes_, *buffer.get()); } @@ -237,6 +243,7 @@ int V4L2BufferCache::get(const FrameBuffer &buffer) cache_[use] = Entry(false, lastUsedCounter_.fetch_add(1, std::memory_order_acq_rel), + numPlanes_, buffer); return use; @@ -257,24 +264,53 @@ V4L2BufferCache::Entry::Entry() { } -V4L2BufferCache::Entry::Entry(bool free, uint64_t lastUsed, const FrameBuffer &buffer) +V4L2BufferCache::Entry::Entry(bool free, uint64_t lastUsed, + unsigned int numPlanes, const FrameBuffer &buffer) : free_(free), lastUsed_(lastUsed) { - for (const FrameBuffer::Plane &plane : buffer.planes()) - planes_.emplace_back(plane); + ASSERT(numPlanes <= buffer.planes().size()); + unsigned int length = 0; + for (const FrameBuffer::Plane &plane : buffer.planes()) { + ASSERT(plane.offset == length); + length += plane.length; + + if (planes_.size() < numPlanes) + planes_.emplace_back(plane); + } + + if (numPlanes == 1) + planes_[0].length = length; } bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const { const std::vector &planes = buffer.planes(); - if (planes_.size() != planes.size()) + if (planes_.size() != planes.size() || planes_.size() == 1) return false; - for (unsigned int i = 0; i < planes.size(); i++) - if (planes_[i].fd != planes[i].fd.fd() || - planes_[i].length != planes[i].length) + if (planes_.size() == 1) { + /* + * planes_ is V4L2 single-planar format buffer. fds of + * FrameBuffer::Plane must be identical and the sum of plane + * size is the V4L2 buffer length. + */ + unsigned int length = 0; + for (unsigned int i = 0; i < planes.size(); i++) { + if (planes_[0].fd != planes[i].fd.fd()) + return false; + length += planes[i].length; + } + if (length != planes_[0].length) return false; + } else { + /* planes_ is V4L2 multi-planar format buffer. */ + for (unsigned int i = 0; i < planes.size(); i++) + if (planes_[i].fd != planes[i].fd.fd() || + planes_[i].length != planes[i].length) + return false; + } + return true; } @@ -579,6 +615,12 @@ int V4L2VideoDevice::open() << "Opened device " << caps_.bus_info() << ": " << caps_.driver() << ": " << caps_.card(); + ret = getFormat(&format_); + if (ret) { + LOG(V4L2, Error) << "Failed to get format"; + return ret; + } + return 0; } @@ -668,6 +710,12 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type) << "Opened device " << caps_.bus_info() << ": " << caps_.driver() << ": " << caps_.card(); + ret = getFormat(&format_); + if (ret) { + LOG(V4L2, Error) << "Failed to get format"; + return ret; + } + return 0; } @@ -761,12 +809,19 @@ int V4L2VideoDevice::tryFormat(V4L2DeviceFormat *format) */ int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format) { + int ret = 0; if (caps_.isMeta()) - return trySetFormatMeta(format, true); + ret = trySetFormatMeta(format, true); else if (caps_.isMultiplanar()) - return trySetFormatMultiplane(format, true); + ret = trySetFormatMultiplane(format, true); else - return trySetFormatSingleplane(format, true); + ret = trySetFormatSingleplane(format, true); + + /* Cache the set format on success. */ + if (ret == 0) + format_ = *format; + + return ret; } int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format) @@ -1152,8 +1207,13 @@ int V4L2VideoDevice::requestBuffers(unsigned int count, * successful return the driver's internal buffer management is initialized in * MMAP mode, and the video device is ready to accept queueBuffer() calls. * - * The number of planes and the plane sizes for the allocation are determined - * by the currently active format on the device as set by setFormat(). + * The number of planes and their offsets and sizes are determined by the + * currently active format on the device as set by setFormat(). They do not map + * to the V4L2 buffer planes, but to colour planes of the pixel format. For + * instance, if the active format is formats::NV12, the allocated FrameBuffer + * instances will have two planes, for the luma and chroma components, + * regardless of whether the device uses V4L2_PIX_FMT_NV12 or + * V4L2_PIX_FMT_NV12M. * * Buffers allocated with this function shall later be free with * releaseBuffers(). If buffers have already been allocated with @@ -1171,7 +1231,7 @@ int V4L2VideoDevice::allocateBuffers(unsigned int count, if (ret < 0) return ret; - cache_ = new V4L2BufferCache(*buffers); + cache_ = new V4L2BufferCache(*buffers, format_.planesCount); memoryType_ = V4L2_MEMORY_MMAP; return ret; @@ -1190,8 +1250,13 @@ int V4L2VideoDevice::allocateBuffers(unsigned int count, * usable with any V4L2 video device in DMABUF mode, or with other dmabuf * importers. * - * The number of planes and the plane sizes for the allocation are determined - * by the currently active format on the device as set by setFormat(). + * The number of planes and their offsets and sizes are determined by the + * currently active format on the device as set by setFormat(). They do not map + * to the V4L2 buffer planes, but to colour planes of the pixel format. For + * instance, if the active format is formats::NV12, the allocated FrameBuffer + * instances will have two planes, for the luma and chroma components, + * regardless of whether the device uses V4L2_PIX_FMT_NV12 or + * V4L2_PIX_FMT_NV12M. * * Multiple independent sets of buffers can be allocated with multiple calls to * this function. Device-specific limitations may apply regarding the minimum @@ -1289,12 +1354,32 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) * \todo Set the right offset once V4L2 API provides a way. */ plane.offset = 0; - plane.length = multiPlanar ? - buf.m.planes[nplane].length : buf.length; + plane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length; planes.push_back(std::move(plane)); } + const auto &info = PixelFormatInfo::info(format_.fourcc); + if (info.isValid() && info.numPlanes() != numPlanes) { + ASSERT(numPlanes == 1u); + const size_t numColorPlanes = info.numPlanes(); + planes.resize(numColorPlanes); + const FileDescriptor &fd = planes[0].fd; + size_t offset = 0; + for (size_t i = 0; i < numColorPlanes; ++i) { + planes[i].fd = fd; + planes[i].offset = offset; + + /* \todo Take the V4L2 stride into account */ + const unsigned int vertSubSample = + info.planes[i].verticalSubSampling; + planes[i].length = + info.stride(format_.size.width, i, 1u) * + ((format_.size.height + vertSubSample - 1) / vertSubSample); + offset += planes[i].length; + } + } + return std::make_unique(std::move(planes)); } @@ -1352,7 +1437,7 @@ int V4L2VideoDevice::importBuffers(unsigned int count) if (ret) return ret; - cache_ = new V4L2BufferCache(count); + cache_ = new V4L2BufferCache(count, format_.planesCount); LOG(V4L2, Debug) << "Prepared to import " << count << " buffers"; diff --git a/test/v4l2_videodevice/buffer_cache.cpp b/test/v4l2_videodevice/buffer_cache.cpp index b3f2bec1..48f748bc 100644 --- a/test/v4l2_videodevice/buffer_cache.cpp +++ b/test/v4l2_videodevice/buffer_cache.cpp @@ -166,7 +166,7 @@ public: * Test cache of same size as there are buffers, the cache is * created from a list of buffers and will be pre-populated. */ - V4L2BufferCache cacheFromBuffers(buffers); + V4L2BufferCache cacheFromBuffers(buffers, 1u); if (testSequential(&cacheFromBuffers, buffers) != TestPass) return TestFail; @@ -181,7 +181,7 @@ public: * Test cache of same size as there are buffers, the cache is * not pre-populated. */ - V4L2BufferCache cacheFromNumbers(numBuffers); + V4L2BufferCache cacheFromNumbers(numBuffers, 1u); if (testSequential(&cacheFromNumbers, buffers) != TestPass) return TestFail; @@ -196,7 +196,7 @@ public: * Test cache half the size of number of buffers used, the cache * is not pre-populated. */ - V4L2BufferCache cacheHalf(numBuffers / 2); + V4L2BufferCache cacheHalf(numBuffers / 2, 1u); if (testRandom(&cacheHalf, buffers) != TestPass) return TestFail; From patchwork Thu Aug 26 11:25:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13509 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 2D3ADC3244 for ; Thu, 26 Aug 2021 11:26:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9152F6891F; Thu, 26 Aug 2021 13:26:03 +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="KiN1JA4v"; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69D1068918 for ; Thu, 26 Aug 2021 13:26:02 +0200 (CEST) Received: by mail-pg1-x52b.google.com with SMTP id x4so2823468pgh.1 for ; Thu, 26 Aug 2021 04:26:02 -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=qkKOSitCpgh3F4llbfu8xUquAFol7q5mSSq6mfDvLZ0=; b=KiN1JA4vNgSFS/GFeWQ117CSQ0pZw/0sE5i9Ifls8OLYAM6DkAFz4JkGkcOCI59/OU wTUInstE/0lXXIIY9MCMeWoUSFNQexW2hwgeH6+WjZLocZMxx73vyyqH4VLbF1FWWVgW j//9c2HDauX+Pt9NKC/CX4JdR15IcEWxF/fAE= 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=qkKOSitCpgh3F4llbfu8xUquAFol7q5mSSq6mfDvLZ0=; b=M6jhEXHUF4xHxMR7j6Aytuw4QvXsLNNJ3Wql2vLHuKT9ODjE7L045iciRcpw2i7oWm KpbADWMRG5SmPpqXnprCaXvwfM+khzLs5Bbpf2uHaqqt9Gzw8KwqfSSPzrGXT9BB6GyJ VRxK4LA+5LdC1XoBNFBVdu7YMOuCtNKcWb3iODglh0/8r7aCp0y3mMDgnOHK0eDxEFvq pYNn7x1u5kL1Epso3kmpGyQy+feiVocXAli9RggpoNMC0WKnC3tY5hfINX+4YRLVSvhV 2+bID+p4EwpMoYQYL/b8LkX7PwBKhLTwzbIcjd05cmTKlYErPVuigXpwCUqyg3Pw9z56 0NtA== X-Gm-Message-State: AOAM532xGmgxQXM3/t5gmtlAzoWbiujuHozUvf3hqnjN6R691J5R6yPs VKejy7MCYc6AM8U7mqULJMRz6XiMFwV2hw== X-Google-Smtp-Source: ABdhPJzdTPg7K9W9ptJi36NcIqoCr1SSQDX5BlGK97BN/ZTBsX/GXMquTAbs2a8GZ7KT3pXTYDHxrQ== X-Received: by 2002:a63:2f04:: with SMTP id v4mr2916530pgv.380.1629977160653; Thu, 26 Aug 2021 04:26:00 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:59 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:38 +0900 Message-Id: <20210826112539.170694-9-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 8/9] android: camera_device: Fill offset and right length in CreateFrameBuffer() 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" CameraDevice::CreateFrameBuffer() fills the length of the buffer to each FrameBuffer::Plane::length. It should rather be the length of plane. This also changes CreateFrameBuffer() to fill offset of FrameBuffer::Plane. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 52 +++++++++++++++++++++-------------- src/android/camera_device.h | 6 +++- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a69b687a..4702b332 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -744,31 +745,40 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) +FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, + libcamera::PixelFormat pixelFormat, + const libcamera::Size &size) { - std::vector planes; + FileDescriptor fd; + /* + * This assumes all the planes are in the same dmabuf. + * + * \todo Verify that this assumption holds, fstat() can be used to check + * if two fds refer to the same dmabuf. + */ for (int i = 0; i < camera3buffer->numFds; i++) { - /* Skip unused planes. */ - if (camera3buffer->data[i] == -1) + if (camera3buffer->data[i] != -1) { + fd = FileDescriptor(camera3buffer->data[i]); break; - - FrameBuffer::Plane plane; - plane.fd = FileDescriptor(camera3buffer->data[i]); - if (!plane.fd.isValid()) { - LOG(HAL, Error) << "Failed to obtain FileDescriptor (" - << camera3buffer->data[i] << ") " - << " on plane " << i; - return nullptr; } + } - off_t length = lseek(plane.fd.fd(), 0, SEEK_END); - if (length == -1) { - LOG(HAL, Error) << "Failed to query plane length"; - return nullptr; - } + if (!fd.isValid()) { + LOG(HAL, Fatal) << "No valid fd"; + return nullptr; + } + + CameraBuffer buf(camera3buffer, pixelFormat, size, PROT_READ); + if (!buf.isValid()) { + LOG(HAL, Fatal) << "Failed to create CameraBuffer"; + return nullptr; + } - plane.length = length; - planes.push_back(std::move(plane)); + std::vector planes(buf.numPlanes()); + for (size_t i = 0; i < buf.numPlanes(); ++i) { + planes[i].fd = fd; + planes[i].offset = buf.offset(i); + planes[i].length = buf.size(i); } return new FrameBuffer(std::move(planes)); @@ -976,7 +986,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * associate it with the Camera3RequestDescriptor for * lifetime management only. */ - buffer = createFrameBuffer(*camera3Buffer.buffer); + buffer = createFrameBuffer(*camera3Buffer.buffer, + cameraStream->configuration().pixelFormat, + cameraStream->configuration().size); descriptor.frameBuffers_.emplace_back(buffer); LOG(HAL, Debug) << ss.str() << " (direct)"; break; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index dd9aebba..a5576927 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include @@ -91,7 +93,9 @@ private: void stop(); - libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); + libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer, + libcamera::PixelFormat pixelFormat, + const libcamera::Size &size); void abortRequest(camera3_capture_request_t *request); bool isValidRequest(camera3_capture_request_t *request) const; void notifyShutter(uint32_t frameNumber, uint64_t timestamp); From patchwork Thu Aug 26 11:25:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13508 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 87683C3245 for ; Thu, 26 Aug 2021 11:26:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 31D3B688A6; Thu, 26 Aug 2021 13:26:06 +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="cgnYyoLO"; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 256A868921 for ; Thu, 26 Aug 2021 13:26:04 +0200 (CEST) Received: by mail-pf1-x430.google.com with SMTP id e16so2065587pfc.6 for ; Thu, 26 Aug 2021 04:26:04 -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=sdvZj+O5ZkY80gq4NQVCkYqBtQlsOOMwEm2QRiBE960=; b=cgnYyoLObtc085VnCPEwb+lmNyUJnzIkEUMWmhJ2YO84fxbVuFWU72vOoqMZ2/hpXl AMOVHrlzxpo3ne3PmSkVH4mtuE49ljA6Aj5J0iKr7qrY7vrVQh5D2PIYH4RNfIsjME0B 3+VZJEmnSS0/K+Dt2y0ruQAcBt9DqL5vW9dZc= 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=sdvZj+O5ZkY80gq4NQVCkYqBtQlsOOMwEm2QRiBE960=; b=o+91DBFfk9QQ6Os/yybUxM8qU54sKJ4SxQBvGqjeVCHwGpLjgyBtXasBvYzdNXduDu sF8qowVFGnazzjRbHnhleA6SRUOcpnYyhCCPCKRgsDZi9Ecr/XEmhA7C9wzbiOBpR7+v JPGH7gTzpt57kfvQKhjNBrK7O4xdayjWVfFwQ4SVZhHHrdBcs4xBLgFxhbTTgltmEgZx IKxBAFmpHLCeVhuTotOQBkYqzf+L0EsoKxOYVrnc7WIXrRX9Fda3ejIDdrK2q2dVXiHJ k4G2CziHx0hXn9GH9wwiiSsuIADN4R4vhFpd8uMF8y2sD0+3lIpgEBSErDw8hWge0SpV FCLQ== X-Gm-Message-State: AOAM531okg3nT9qLmSseJ6jp/CpkVPJKM8JzPuVPf+IgTtqQhc+MoUpC CyNGprmOuqfH130NdGeqDSPtAkelToLwXw== X-Google-Smtp-Source: ABdhPJxU9steJFMtAaJUKs0h0THz0NMBkm0+TgtqRfyhNc3+yRFsrd0CA9xxt/o6XWpcpEb+mFOCpg== X-Received: by 2002:a63:d250:: with SMTP id t16mr2975281pgi.95.1629977162480; Thu, 26 Aug 2021 04:26:02 -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.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:26:02 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:39 +0900 Message-Id: <20210826112539.170694-10-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 9/9] libcamera: framebuffer: Add assertion to detect offset is unfilled 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" The offset variable is introduced to FrameBuffer::Plane. In order to detect that the plane is used while the offset is not set, this adds the assertion to FrameBuffer::planes(). It should be removed in the future. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/framebuffer.h | 13 +++++++++++-- src/libcamera/framebuffer.cpp | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index 5de3c744..d5aeff00 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -7,6 +7,8 @@ #ifndef __LIBCAMERA_FRAMEBUFFER_H__ #define __LIBCAMERA_FRAMEBUFFER_H__ +#include +#include #include #include @@ -41,14 +43,21 @@ class FrameBuffer final : public Extensible public: struct Plane { + static constexpr unsigned int kInvalidOffset = std::numeric_limits::max(); FileDescriptor fd; - unsigned int offset; + unsigned int offset = kInvalidOffset; unsigned int length; }; FrameBuffer(const std::vector &planes, unsigned int cookie = 0); - const std::vector &planes() const { return planes_; } + const std::vector &planes() const + { + /* \todo Remove the assertions after sufficient testing */ + for (const auto &plane : planes_) + assert(plane.offset != Plane::kInvalidOffset); + return planes_; + } Request *request() const; const FrameMetadata &metadata() const { return metadata_; } diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index bf7a52ad..c99f5b15 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -170,6 +170,11 @@ FrameBuffer::Private::Private() * multiple dmabufs, based on the camera requirements. */ +/** + * \var FrameBuffer::Plane::kInvalidOffset + * \brief Invalid offset value, to identify uninitialized planes + */ + /** * \var FrameBuffer::Plane::fd * \brief The dmabuf file descriptor