[libcamera-devel] [PATCH v3 14/33] libcamera: v4l2_videodevice: Extract exportDmabufFd()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Jan 11 01:17:42 CET 2020


Hi Niklas,

Thank you for the patch.

On Fri, Jan 10, 2020 at 08:37:49PM +0100, Niklas Söderlund wrote:
> 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 <niklas.soderlund at ragnatech.se>
> Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
> Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
> * Changes since v1
> - Rename exportDmaBuffer() to exportDmabufFd()
> ---
>  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..1f52fe0120831fa3 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 exportDmabufFd(unsigned int index, unsigned int plane);

I think you can squash 28/33 with this patch.

>  
>  	Buffer *dequeueBuffer();
>  	void bufferAvailable(EventNotifier *notifier);
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 81d999e354a16bd0..7c9014af4ddea31a 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -902,31 +902,22 @@ 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 = exportDmabufFd(index, planeIndex);
> +	if (fd < 0)
> +		return fd;
>  
>  	FrameBuffer::Plane plane;
> -	plane.fd = FileDescriptor(expbuf.fd);
> +	plane.fd = FileDescriptor(fd);
>  	plane.length = length;
>  	buffer->planes().push_back(plane);
> -	::close(expbuf.fd);
> +	::close(fd);
>  
>  	return 0;
>  }
> @@ -952,6 +943,26 @@ int V4L2VideoDevice::importBuffers(BufferPool *pool)
>  	return 0;
>  }
>  
> +int 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 ret;
> +	}
> +
> +	return expbuf.fd;
> +}
> +
>  /**
>   * \brief Release all internally allocated buffers
>   */

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list