From patchwork Sun Jan 12 01:01:54 2020 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: 2596 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CEFC7606D6 for ; Sun, 12 Jan 2020 02:03:09 +0100 (CET) X-Halon-ID: 4a600745-34d7-11ea-b6d8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac5d7b.dip0.t-ipconnect.de [84.172.93.123]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 4a600745-34d7-11ea-b6d8-005056917f90; Sun, 12 Jan 2020 02:03:06 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 12 Jan 2020 02:01:54 +0100 Message-Id: <20200112010212.2609025-15-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200112010212.2609025-1-niklas.soderlund@ragnatech.se> References: <20200112010212.2609025-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 14/32] libcamera: v4l2_videodevice: Extract exportDmabufFd() 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: Sun, 12 Jan 2020 01:03:10 -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 separate function. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v3 - Make exportDmabufFd() return a FileDescriptor * Changes since v1 - Rename exportDmaBuffer() to exportDmabufFd() --- src/libcamera/include/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_videodevice.cpp | 42 +++++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index fdf11b3a6ec9b702..27ec77cdcc3c07ff 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -26,6 +26,7 @@ class Buffer; class BufferMemory; class BufferPool; class EventNotifier; +class FileDescriptor; class MediaDevice; class MediaEntity; @@ -179,6 +180,7 @@ private: int requestBuffers(unsigned int count); int createPlane(BufferMemory *buffer, unsigned int index, unsigned int plane, unsigned int length); + FileDescriptor exportDmabufFd(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 81d999e354a16bd0..4551484cfbf8c6ef 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "log.h" #include "media_device.h" @@ -902,31 +903,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; - 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; - } + FileDescriptor fd = exportDmabufFd(index, planeIndex); + if (!fd.isValid()) + return -EINVAL; FrameBuffer::Plane plane; - plane.fd = FileDescriptor(expbuf.fd); + plane.fd = fd; plane.length = length; buffer->planes().push_back(plane); - ::close(expbuf.fd); return 0; } @@ -952,6 +941,27 @@ int V4L2VideoDevice::importBuffers(BufferPool *pool) return 0; } +FileDescriptor V4L2VideoDevice::exportDmabufFd(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 FileDescriptor(); + } + + return FileDescriptor(expbuf.fd); +} + /** * \brief Release all internally allocated buffers */