From 03fcc154eb0599e02276c9f64fce46b643104e20 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Thu, 7 Feb 2019 20:56:08 +0000 Subject: libcamera: v4l2_device: Simplify exportBuffers() exportBuffers() can only operate on an existing BufferPool allocation. The pool identifies its size through its .count() method. Passing a count in to the exportBuffers() call is redundant and can be incorrect if the value is not the same as the BufferPool size. Simplify the function and remove the unnecessary argument, correcting all uses throughout the code base. While we're here, remove the createBuffers() helper from the V4L2DeviceTest which only served to obfuscate which pool the buffers were being allocated for. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/libcamera/v4l2_device.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/libcamera/v4l2_device.cpp') diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 207ba933..ca6bb4ee 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -538,13 +538,12 @@ int V4L2Device::requestBuffers(unsigned int count) } /** - * \brief Request \a count buffers to be allocated from the device and stored in - * the buffer pool provided. - * \param[in] count Number of buffers to allocate + * \brief Request buffers to be allocated from the device and stored in the + * buffer pool provided. * \param[out] pool BufferPool to populate with buffers * \return 0 on success or a negative error code otherwise */ -int V4L2Device::exportBuffers(unsigned int count, BufferPool *pool) +int V4L2Device::exportBuffers(BufferPool *pool) { unsigned int allocatedBuffers; unsigned int i; @@ -552,21 +551,19 @@ int V4L2Device::exportBuffers(unsigned int count, BufferPool *pool) memoryType_ = V4L2_MEMORY_MMAP; - ret = requestBuffers(count); + ret = requestBuffers(pool->count()); if (ret < 0) return ret; allocatedBuffers = ret; - if (allocatedBuffers < count) { + if (allocatedBuffers < pool->count()) { LOG(V4L2, Error) << "Not enough buffers provided by V4L2Device"; requestBuffers(0); return -ENOMEM; } - count = ret; - /* Map the buffers. */ - for (i = 0; i < count; ++i) { + for (i = 0; i < pool->count(); ++i) { struct v4l2_plane planes[VIDEO_MAX_PLANES] = {}; struct v4l2_buffer buf = {}; struct Buffer &buffer = pool->buffers()[i]; -- cgit v1.2.1