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; }