From patchwork Mon Aug 14 11:28:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabrielle George X-Patchwork-Id: 18940 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 D6AE7C32B0 for ; Mon, 14 Aug 2023 11:29:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7C255628E4; Mon, 14 Aug 2023 13:29:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1692012540; bh=267zk0bj+HNkmSZr/ZXjLE2OK+LNcaCshBj12zeX6rY=; 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=uMrkP/3mq+ET60L50/Bg1o0T1wDt1G0iFaogUtLAO4bk/21JQ7rg8uOlgnPHtyxfU QmbhhKNlH5vkAilO7xRayzoBX+M7oxYAZTBQZSUFRnRHVIRUmAdD8OTCO6qGyqibe5 JWGaf+wQkXGsSJkGMa9RA77ZN62egRUuQzKGfOO5x1xTj+/1Q6QWhIXCsvoEE1NbvX BEJZ5LgFAPjZwvg5RI3/niG4h/t2krjnlRddp+Q99/jAFvg5yjm7lN42EcAQAjQQVJ 49Kangqg8y5IZo7wi/s2Z331fPYUUHsNwhOq4QRVJgU2L+MWzdCv1TEsC4jO8Z+shp k/gICcieAo9mg== Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 76E2C61E0B for ; Mon, 14 Aug 2023 13:28:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QVT6zUUq"; dkim-atps=neutral Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1c4d67f493bso826148fac.2 for ; Mon, 14 Aug 2023 04:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692012535; x=1692617335; 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=6tSJ7JOO2z+X4Zmaf/GuvpJdVyVmlcb8Z4R8sdhfdp0=; b=QVT6zUUqZwnTsMh30wZpvk+vfMd6edwdSTgs/oYPitNFB1+0gM/xLRgudF0+L5foMT cEWmnnbURBgwjUTfBE3XSNhV4405xPAUH46CSKy+Q/g9tn137MJw5CgWeg71ng6ZiW9h uS/r2haaN21xB+FpjFZwXVTm874z8cCG5AhbEJfKFctqqF41lrGX5YPIoMJFRhMcs3y5 TnBVnr6l5VLInEs6Zi8tv1N6RaPnidGjNKCErBbhSwsNz9gTK/fee06/puQUNCthJ0f2 BZpYtk3ehte+vnD6mbK4C7NbG1dZI/NubZrwLTnDTkxuiOJFWr6D93bAZ7ZPILeJ8HHL kn9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692012535; x=1692617335; 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=6tSJ7JOO2z+X4Zmaf/GuvpJdVyVmlcb8Z4R8sdhfdp0=; b=ipUkByu9k0JsO1o4wqYp7ksIxKuLWmUtRWLrtJ6oynmHiozgkMHkZdPiUERXXuwh4s 7pzY/a5Hj7i4A1umqdmuGbosjVyJCuKJDFO/rWh0sUH86+SIJaffSJjhHh+9+YAUXjYI XIdnWahQtJSwOp5iAZ1JhTIhK5BUhyhGgzXtd7oxF9g4mR05mTTN2OAlyC7iqAKE15Hh JIIgNht39tgGs5Qy01KkfmQ7shXxWv89Gk1k0YCULcdH4vIgNKVFtr/sCK3QLH8wop9e jUeOmMZatjKuwIspkRx2EUPAxiroD+GDY8kkAukKt7udnYTNz2eOfywxyrbpDi0wBOaR HkLA== X-Gm-Message-State: AOJu0YwtKxY4c6Aj/S/JyuSMg2xsLSd7RQFir7bPseT8uZhgGXVav6Be 9qo10qtJRy9KoiJENfgBuzWw7RZN34L7FQ== X-Google-Smtp-Source: AGHT+IGe7Gn43V1JUUIxPdiMSegfVqXn6us7yfiXzI4QExjH9pwI0ateCkZPZaMcR6EqEa4qqQcc6w== X-Received: by 2002:a05:6871:886:b0:1c4:ee87:d3ea with SMTP id r6-20020a056871088600b001c4ee87d3eamr3424797oaq.36.1692012534860; Mon, 14 Aug 2023 04:28:54 -0700 (PDT) Received: from localhost.localdomain (97-115-76-16.ptld.qwest.net. [97.115.76.16]) by smtp.gmail.com with ESMTPSA id c3-20020a9d6c83000000b006b92509e76esm4163817otr.32.2023.08.14.04.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 04:28:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, kieran.bingham@ideasonboard.com, vedantparanjape160201@gmail.com, gabbymg94@gmail.com Date: Mon, 14 Aug 2023 04:28:47 -0700 Message-Id: <20230814112849.176943-4-gabbymg94@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230814112849.176943-1-gabbymg94@gmail.com> References: <20230814112849.176943-1-gabbymg94@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 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 --- src/libcamera/v4l2_videodevice.cpp | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index a72ef64d..8cf427c0 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1402,18 +1402,28 @@ 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) { + 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; + } else { + /* Dmabuf fd is not exported for metadata, so store + * the offset from the querybuf call and this device's fd. + */ + SharedFD tmp(this->fd()); + plane.fd = tmp; + plane.offset = buf.m.offset; + } plane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length; planes.push_back(std::move(plane));