From patchwork Mon Aug 21 13:10:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabrielle George X-Patchwork-Id: 18946 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 5077EC32B1 for ; Mon, 21 Aug 2023 13:10:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D79B8628C0; Mon, 21 Aug 2023 15:10:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1692623448; bh=x0m3Q6Zm5HNEYCWrPDKCa4gssb4L4IG3sXuRHUIlQiY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=IMix/AsxD5AZoeQ5jqN62BP4sh2PiEwjpJjQfm8Z5Gt/5ecm5N9Z+k48O8KmUXr+y VRhtgM5c4oTq1mdi35LiODTRSnuTpzHpDAI9voZFylsGvKAMgcRNfoYJ5DwPoop2rj iVKmGCaa9JgYPcHx7TxyIccdgj6dgl9tz0GJ/ewc5Zyk98C0zjZpfVZTTk/zZYvR3X wy/sh0BubSnCj8MubZgRojOGi0HpP8fLt8G+asY+WyG6FhT63zIAxO5Y1p7nW53ZD/ 5K9xO5kwjVu2rrIHABf9k1uLCRyPW3BWMmvHZfO0z2wKBoN/SfqhLvGLc0XNgD9Cc2 boavBcKnB44kw== Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B8FB627E1 for ; Mon, 21 Aug 2023 15:10:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GvwjXhmZ"; dkim-atps=neutral Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1c4dd644cf8so2202463fac.0 for ; Mon, 21 Aug 2023 06:10:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692623444; x=1693228244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=nS1565gi8HITXrBfkzEzaklAo8ZiCurdIwCfe5mRzKg=; b=GvwjXhmZnKwXgiHvvIBI7WFqCpCfIyKjbtkvDD73oz7XlGjJ4FU5rr4Exm31In2rDM RLJq6/xPRWav9LbZ9vxWePdU1XUds+Ij/KFLwF10ILCULdHUQBi0L0UWIsZ5n5i2Mv5H kCdp008rEa46aSjDLgLLFjgTsOW60efp6XSFZVYheR/FhFLQ48xWfzmYO4Vu57s3qd2R 7DT1WTwligYoXGpF0570uIiFT/hJpB655OurMUqQJwYRvUNNFV4aTI8JxxO5fmB/ReWT LqUQlR8UE6CpLOv2QIIaUdxm9aR5Idhbm8BqhIkrPk7SWm+oHMaNjFToTx9BnvuN5i+G DsUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692623444; x=1693228244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nS1565gi8HITXrBfkzEzaklAo8ZiCurdIwCfe5mRzKg=; b=aFkBcZLKsxFRO9D0uQS3hPUper1757TUHzWUN7MeJBq5FoarRRu5V3hZF0LtoYpbLG PEH872Y5EODIJeG6z1pKSAAorOzdNFd4byrU8lqXzh1N42TIyzwIpJy+o8VK7nveox14 yNTvOUuKi/cQ3vEPFHculCW1NpPKDd4+79aKYNCm+LRsjNEnn6kUOPG9CNP7/6AkWnXr ej9BXQezNzsRlscuB3eNdawRzaio+VLa7dpDf5SpBR2HkbZe/RMsBKyyudpQlyco/dmd CdU6dQ5sNgayi+Vm7Ao0r2JCcwLlOEbMlemuBkCDYtYhvAry4zWPS9fdZosE22C+ehOt p8QQ== X-Gm-Message-State: AOJu0Ywd/CTuos+Ohv0pSoq3tVuobRccvNkS8Jy4Y/FuqYJU8xU9e4hW ah0/O3JpVz+aSaq+0iK3YEyf1INTvlg= X-Google-Smtp-Source: AGHT+IEJmgsGy9aZkt9MLs2B85KK4lKLaxgd7vEqCTitMK+t+4iqvf7ZgM/61brhB9CqPgPEHh7tjw== X-Received: by 2002:a05:6870:470e:b0:1be:deef:748a with SMTP id b14-20020a056870470e00b001bedeef748amr9832354oaq.50.1692623444515; Mon, 21 Aug 2023 06:10:44 -0700 (PDT) Received: from localhost.localdomain (97-115-76-16.ptld.qwest.net. [97.115.76.16]) by smtp.gmail.com with ESMTPSA id ci1-20020a056871c48100b001bb51450d85sm4160283oac.4.2023.08.21.06.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 06:10:44 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, kieran.bingham@ideasonboard.com, vedantparanjape160201@gmail.com, gabbymg94@gmail.com Date: Mon, 21 Aug 2023 06:10:37 -0700 Message-Id: <20230821131039.127370-4-gabbymg94@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230821131039.127370-1-gabbymg94@gmail.com> References: <20230821131039.127370-1-gabbymg94@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 3/5] libcamera: v4l2 device: Store buffer info in 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: , X-Patchwork-Original-From: Gabby George via libcamera-devel From: Gabrielle George Reply-To: Gabby George Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To perform a memory mapping using mmap, the MappedFrameBuffer class needs the plane offset and file descriptor information of the frame buffer's plane(s). This information is provided in the response to REQBUF, which happens during buffer allocation. Store the plane offset and file descriptor information in the buffer's plane at the time of allocation. Currently, there is a metadata buffer type (metadata format UVCH) that does not support exporting buffers using EXPBUF, so this should only be done if the buffer type is metadata capture. Signed-off-by: Gabby George Reviewed-by: Vedant Paranjape --- src/libcamera/v4l2_videodevice.cpp | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index a72ef64d..e57cb131 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1402,18 +1402,27 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) std::vector planes; for (unsigned int nplane = 0; nplane < numPlanes; nplane++) { - UniqueFD fd = exportDmabufFd(buf.index, nplane); - if (!fd.isValid()) - return nullptr; - FrameBuffer::Plane plane; - plane.fd = SharedFD(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; + + if (buf.type == V4L2_BUF_TYPE_META_CAPTURE) { + /* + * Dmabuf fd is not exported for metadata, so store + * the offset from the querybuf call and this device's fd. + */ + plane.fd = SharedFD(this->fd()); + plane.offset = buf.m.offset; + } else { + UniqueFD fd = exportDmabufFd(buf.index, nplane); + if (!fd.isValid()) + return nullptr; + plane.fd = SharedFD(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; planes.push_back(std::move(plane));