From patchwork Mon Aug 21 13:10:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabrielle George X-Patchwork-Id: 18945 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 9532AC32B0 for ; Mon, 21 Aug 2023 13:10:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 28305627E2; 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=DMCXw05gQo2OpLrAzcVL4l/cyzLBkRuuVkgP6P5OnJs=; 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=R6ET98cO75JqwbCkjIefTgi6VnWjRvU+g3bNPpzFb7qBxmSqoe+9nAXXd08M34C/B McZUl6CtrafHJL9Xpn7yYzQMuovMiwRUiAoZdUXvfnw7oraLGPp7FDvuqYcdf9D4G0 /uP76GFrrmROWD/WVVO/Me1hyG0pfUZ9E522ucIBYI+hoHTMvh0gtgM5lfZ7d09YNC lujzGF2TY+0tQKTBdBZ/c1+UZAqjA6JeyOwJDBxhAEZN2l8LPKYTbtMgHlwo1azDz+ xnVD57mhXbKVdHOi9gE1ml4ZQaGQFRFM2wf/oUmGjlTS91ib9agrgbmVglEobWMuF4 FXLVEQa1l/WMQ== Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 064B561E09 for ; Mon, 21 Aug 2023 15:10:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hqBJSkqa"; dkim-atps=neutral Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1cca0a1b3c7so18548fac.2 for ; Mon, 21 Aug 2023 06:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692623443; x=1693228243; 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=gLWaKmx/cdcNVCylxEJWFcipivTebMrGpD7wATBJy5o=; b=hqBJSkqa8Ng97Vz8RDYeQtRC/UYBC+PcpnOSFjDCGPLC3b4/lIe1rTyf45eeTYedPO 6kqW2qFshq42FcAosQaF2seOXkkLwwMDfNnDBlxJbzhl0p+bh5MJv5DtXpvlwqtbcxq1 uZsz6rbUXzSIKJ8asSJbPY8Tioy+MO15u0BdPIK/zfk7pJ7SOAhHIY1inRIsh8+nS+8J uzQLm7LDeEXwbJYcmSzgEJ7sdMleTmt+cSZB5ipwxsUunxzAzscWnDQoMDWzjMr+R+aa 360999vvFvYMVSS9sqtxRFhJnsshKb+UUVIr/DlUdWFb9xOifI+rLyKqym8pmOpyrfhi WqHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692623443; x=1693228243; 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=gLWaKmx/cdcNVCylxEJWFcipivTebMrGpD7wATBJy5o=; b=EGg+SLEEqeQfxLNTDKotmc1c3GPLBcaKbmY6Lc+7NALZgrhusNOw9OS6Qh3MkOZZAv WNnUdv++5VpevVB8jnkVYdWHnKyPirrIIjXHwrvMLU1QbxdnIfOD+A6ExaVQRl/7aSYI OVtrDF/bFyXPaOXM9tDXwRGfQWewIzLFajBZgwb8XJkUO4pFtbp310ytP66WPaIcoaej akVRIhT2dNkTtjejALgHThpgQYj5dNqfna6Z7T7kbGuc0WNzCRATT7six2+IgzDU+bV3 w1lzSmM6xDt0+YA9q8lLBYOEUzRQTTJT+E6wh2mYv8tBLekMAKT8NC117/Z1T2EgVpkw SIDw== X-Gm-Message-State: AOJu0Yz6V6zLBhVkb6+jCCYTWkrRygq7MOJJxtMIPRnSYhQyDvkJ7ssD lKogWalcpVdVSQwBJuocWmLpUDUT4xY= X-Google-Smtp-Source: AGHT+IFe737xihYZsVt677Rbiqp7a+FY84GHAlVGiU7VbU5CLiDUo6Rn9c9HDbqDe9RzwV6+uP+u/w== X-Received: by 2002:a05:6870:40ca:b0:1bc:3f6:579b with SMTP id l10-20020a05687040ca00b001bc03f6579bmr10132146oal.22.1692623443533; Mon, 21 Aug 2023 06:10:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 06:10:43 -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:36 -0700 Message-Id: <20230821131039.127370-3-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 2/5] libcamera: MappedFrameBuffer: Use stored plane offset 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" As it is written, the MappedFrameBuffer causes a failure in mmap when attempting to map UVC metadata planes. UVC metadata (four character code UVCH) does not support exporting buffers as file descriptors, so mmap can be used to give libcamera access to the metadata buffer planes. It is convenient to use the already-existing MappedFrameBuffers class, but the class must be modified to support mapping using file descriptors of the video node itself. To do this, mmap needs information obtained through a call to QUERYBUF, namely, the plane offset for buffer planes. Modify the constructor of a MappedFrameBuffer to use the plane offset directly in the call to mmap, rather than the hard-coded 0 value. The current version does not work when a buffer cannot be exported as a dma buf fd. The fd argument to mmap must be the one obtained on a call to open() for the video node (ie, /dev/videoX). This method of mapping buffer planes requires the arguments to mmap to be exactly the length and offset QUERYBUF provides. Mmap will return a -EINVAL if this is not the case. Signed-off-by: Gabby George --- .../libcamera/internal/mapped_framebuffer.h | 3 ++- src/libcamera/mapped_framebuffer.cpp | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index fb39adbf..04096d1b 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -54,7 +54,8 @@ public: using MapFlags = Flags; - MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags); + MappedFrameBuffer(const FrameBuffer *buffer, + MapFlags flags, bool usePlaneOffset = false); }; LIBCAMERA_FLAGS_ENABLE_OPERATORS(MappedFrameBuffer::MapFlag) diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp index 6860069b..3d2cc332 100644 --- a/src/libcamera/mapped_framebuffer.cpp +++ b/src/libcamera/mapped_framebuffer.cpp @@ -172,12 +172,13 @@ MappedBuffer::~MappedBuffer() * \brief Map all planes of a FrameBuffer * \param[in] buffer FrameBuffer to be mapped * \param[in] flags Protection flags to apply to map + * \param[in] usePlaneOffset Use offset stored in buffer's plane; default false * * Construct an object to map a frame buffer for CPU access. The mapping can be * made as Read only, Write only or support Read and Write operations by setting * the MapFlag flags accordingly. */ -MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) +MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags, bool usePlaneOffset) { ASSERT(!buffer->planes().empty()); planes_.reserve(buffer->planes().size()); @@ -223,8 +224,14 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) const int fd = plane.fd.get(); auto &info = mappedBuffers[fd]; if (!info.address) { - void *address = mmap(nullptr, info.mapLength, mmapFlags, - MAP_SHARED, fd, 0); + void *address; + if (usePlaneOffset) { + address = mmap(nullptr, plane.length, mmapFlags, + MAP_SHARED, fd, plane.offset); + } else { + address = mmap(nullptr, info.mapLength, mmapFlags, + MAP_SHARED, fd, 0); + } if (address == MAP_FAILED) { error_ = -errno; LOG(Buffer, Error) << "Failed to mmap plane: " @@ -233,10 +240,13 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) } info.address = static_cast(address); - maps_.emplace_back(info.address, info.mapLength); + maps_.emplace_back(info.address, usePlaneOffset ? plane.length : + info.mapLength); } - planes_.emplace_back(info.address + plane.offset, plane.length); + uint8_t *storedAddress = usePlaneOffset ? info.address : + info.address + plane.offset; + planes_.emplace_back(storedAddress, plane.length); } }