From patchwork Tue Nov 26 23:36:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 2361 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 16C6461CAA for ; Wed, 27 Nov 2019 00:39:34 +0100 (CET) X-Halon-ID: ff16ac83-10a5-11ea-a0b9-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de [84.172.88.101]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id ff16ac83-10a5-11ea-a0b9-005056917f90; Wed, 27 Nov 2019 00:39:32 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Nov 2019 00:36:03 +0100 Message-Id: <20191126233620.1695316-14-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191126233620.1695316-1-niklas.soderlund@ragnatech.se> References: <20191126233620.1695316-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 13/30] libcamera: v4l2_videodevice: Extract exportDmaBuffer() to export DMA buffer 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-List-Received-Date: Tue, 26 Nov 2019 23:39:35 -0000 The part in createPlane() that exports a dma buffer from a video device will be used directly by the FrameBuffer interface. Break it out to a own function. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 41 +++++++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index fdf11b3a6ec9b702..34bbff41760753bd 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -179,6 +179,7 @@ private: int requestBuffers(unsigned int count); int createPlane(BufferMemory *buffer, unsigned int index, unsigned int plane, unsigned int length); + int exportDmaBuffer(unsigned int index, unsigned int plane); Buffer *dequeueBuffer(); void bufferAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 644e4545a2f33b2e..cc0a1c9382a2b1ed 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -901,28 +901,19 @@ int V4L2VideoDevice::exportBuffers(BufferPool *pool) int V4L2VideoDevice::createPlane(BufferMemory *buffer, unsigned int index, unsigned int planeIndex, unsigned int length) { - struct v4l2_exportbuffer expbuf = {}; - int ret; + int fd; LOG(V4L2, Debug) << "Buffer " << index << " plane " << planeIndex << ": length=" << length; - expbuf.type = bufferType_; - expbuf.index = index; - expbuf.plane = planeIndex; - expbuf.flags = O_RDWR; - - ret = ioctl(VIDIOC_EXPBUF, &expbuf); - if (ret < 0) { - LOG(V4L2, Error) - << "Failed to export buffer: " << strerror(-ret); - return ret; - } + fd = exportDmaBuffer(index, planeIndex); + if (fd < 0) + return fd; - buffer->planes().emplace_back(expbuf.fd, length); - ::close(expbuf.fd); + buffer->planes().emplace_back(fd, length); + ::close(fd); return 0; } @@ -948,6 +939,26 @@ int V4L2VideoDevice::importBuffers(BufferPool *pool) return 0; } +int V4L2VideoDevice::exportDmaBuffer(unsigned int index, unsigned int plane) +{ + struct v4l2_exportbuffer expbuf = {}; + int ret; + + expbuf.type = bufferType_; + expbuf.index = index; + expbuf.plane = plane; + expbuf.flags = O_RDWR; + + ret = ioctl(VIDIOC_EXPBUF, &expbuf); + if (ret < 0) { + LOG(V4L2, Error) + << "Failed to export buffer: " << strerror(-ret); + return ret; + } + + return expbuf.fd; +} + /** * \brief Release all internally allocated buffers */