From patchwork Wed Feb 13 15:10:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 576 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 67BAB610BA for ; Wed, 13 Feb 2019 16:10:34 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B2825B6; Wed, 13 Feb 2019 16:10:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1550070634; bh=Ws+N0xCxnDs84aCFjzVjARruxTpC8rxo6wO4uCAtdwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRbucWtGE7PlzdHp/y0Aqa7ApBy90gc/Sre7vE/5xmr1xugTssrgR4bOpUMachbfK DWOzNFkCvLowjpj3qEZBt/dzzS2DU5SdvJaZFdh8o3yTqVHFW5merakGkWF1GCRVjA mVb/jb0TAqVGUdYiGF/CB7sOgA4AOFNVO4lDtqow= From: Kieran Bingham To: LibCamera Devel Date: Wed, 13 Feb 2019 15:10:26 +0000 Message-Id: <20190213151027.6376-8-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190213151027.6376-1-kieran.bingham@ideasonboard.com> References: <20190213151027.6376-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/8] libcamera: v4l2_device: importBuffers support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Feb 2019 15:10:35 -0000 Provide the ability to import a BufferPool into the V4L2Device allowing external dmabuf backed buffers to be queued. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_device.h | 1 + src/libcamera/v4l2_device.cpp | 45 ++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 5a536393a5b5..1d31d1b403bc 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -100,6 +100,7 @@ public: int setFormat(V4L2DeviceFormat *format); int exportBuffers(BufferPool *pool); + int importBuffers(BufferPool *pool); int releaseBuffers(); int queueBuffer(Buffer *buffer); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 152bd9930a70..2d0ce7011d8a 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -642,6 +642,36 @@ int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex, return 0; } +/** + * \brief Import the externally allocated \a pool of buffers + * \param[in] pool BufferPool of buffers to import + * \return 0 on success or a negative error code otherwise + */ +int V4L2Device::importBuffers(BufferPool *pool) +{ + unsigned int allocatedBuffers; + int ret; + + memoryType_ = V4L2_MEMORY_DMABUF; + + ret = requestBuffers(pool->count()); + if (ret < 0) + return ret; + + allocatedBuffers = ret; + if (allocatedBuffers < pool->count()) { + LOG(V4L2, Error) + << "Not enough buffers provided by V4L2Device"; + requestBuffers(0); + return -ENOMEM; + } + + LOG(V4L2, Debug) << "Device using an externally provided pool"; + bufferPool_ = pool; + + return 0; +} + /** * \brief Release all internally allocated buffers */ @@ -682,7 +712,20 @@ int V4L2Device::queueBuffer(Buffer *buffer) buf.memory = memoryType_; buf.field = V4L2_FIELD_NONE; - if (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) { + bool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type); + + if (buf.memory == V4L2_MEMORY_DMABUF) { + if (multiPlanar) { + for (unsigned int p = 0; + p < buffer->planes().size(); + p++) + planes[p].m.fd = buffer->planes()[p].dmabuf(); + } else { + buf.m.fd = buffer->planes()[0].dmabuf(); + } + } + + if (multiPlanar) { buf.length = buffer->planes().size(); buf.m.planes = planes; }