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 <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Kieran Bingham 2019-02-07 20:56:08 +00:00
parent 3e354b00b4
commit 03fcc154eb
9 changed files with 16 additions and 22 deletions

View file

@ -99,7 +99,7 @@ public:
int getFormat(V4L2DeviceFormat *format); int getFormat(V4L2DeviceFormat *format);
int setFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format);
int exportBuffers(unsigned int count, BufferPool *pool); int exportBuffers(BufferPool *pool);
int releaseBuffers(); int releaseBuffers();
int queueBuffer(Buffer *buffer); int queueBuffer(Buffer *buffer);

View file

@ -191,8 +191,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream)
if (!cfg.bufferCount) if (!cfg.bufferCount)
return -EINVAL; return -EINVAL;
int ret = data->cio2_->exportBuffers(cfg.bufferCount, int ret = data->cio2_->exportBuffers(&stream->bufferPool());
&stream->bufferPool());
if (ret) { if (ret) {
LOG(IPU3, Error) << "Failed to request memory"; LOG(IPU3, Error) << "Failed to request memory";
return ret; return ret;

View file

@ -102,7 +102,7 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera, Stream *stream)
LOG(UVC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; LOG(UVC, Debug) << "Requesting " << cfg.bufferCount << " buffers";
return video_->exportBuffers(cfg.bufferCount, &stream->bufferPool()); return video_->exportBuffers(&stream->bufferPool());
} }
int PipelineHandlerUVC::freeBuffers(Camera *camera, Stream *stream) int PipelineHandlerUVC::freeBuffers(Camera *camera, Stream *stream)

View file

@ -101,7 +101,7 @@ int PipelineHandlerVimc::allocateBuffers(Camera *camera, Stream *stream)
LOG(VIMC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; LOG(VIMC, Debug) << "Requesting " << cfg.bufferCount << " buffers";
return video_->exportBuffers(cfg.bufferCount, &stream->bufferPool()); return video_->exportBuffers(&stream->bufferPool());
} }
int PipelineHandlerVimc::freeBuffers(Camera *camera, Stream *stream) int PipelineHandlerVimc::freeBuffers(Camera *camera, Stream *stream)

View file

@ -538,13 +538,12 @@ int V4L2Device::requestBuffers(unsigned int count)
} }
/** /**
* \brief Request \a count buffers to be allocated from the device and stored in * \brief Request buffers to be allocated from the device and stored in the
* the buffer pool provided. * buffer pool provided.
* \param[in] count Number of buffers to allocate
* \param[out] pool BufferPool to populate with buffers * \param[out] pool BufferPool to populate with buffers
* \return 0 on success or a negative error code otherwise * \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 allocatedBuffers;
unsigned int i; unsigned int i;
@ -552,21 +551,19 @@ int V4L2Device::exportBuffers(unsigned int count, BufferPool *pool)
memoryType_ = V4L2_MEMORY_MMAP; memoryType_ = V4L2_MEMORY_MMAP;
ret = requestBuffers(count); ret = requestBuffers(pool->count());
if (ret < 0) if (ret < 0)
return ret; return ret;
allocatedBuffers = ret; allocatedBuffers = ret;
if (allocatedBuffers < count) { if (allocatedBuffers < pool->count()) {
LOG(V4L2, Error) << "Not enough buffers provided by V4L2Device"; LOG(V4L2, Error) << "Not enough buffers provided by V4L2Device";
requestBuffers(0); requestBuffers(0);
return -ENOMEM; return -ENOMEM;
} }
count = ret;
/* Map the buffers. */ /* 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_plane planes[VIDEO_MAX_PLANES] = {};
struct v4l2_buffer buf = {}; struct v4l2_buffer buf = {};
struct Buffer &buffer = pool->buffers()[i]; struct Buffer &buffer = pool->buffers()[i];

View file

@ -38,9 +38,9 @@ protected:
Timer timeout; Timer timeout;
int ret; int ret;
createBuffers(bufferCount); pool_.createBuffers(bufferCount);
ret = dev_->exportBuffers(bufferCount, &pool_); ret = dev_->exportBuffers(&pool_);
if (ret) if (ret)
return TestFail; return TestFail;

View file

@ -19,9 +19,9 @@ protected:
*/ */
const unsigned int bufferCount = 8; const unsigned int bufferCount = 8;
createBuffers(bufferCount); pool_.createBuffers(bufferCount);
int ret = dev_->exportBuffers(bufferCount, &pool_); int ret = dev_->exportBuffers(&pool_);
if (ret) if (ret)
return TestFail; return TestFail;

View file

@ -14,9 +14,9 @@ protected:
{ {
const unsigned int bufferCount = 8; const unsigned int bufferCount = 8;
createBuffers(bufferCount); pool_.createBuffers(bufferCount);
int ret = dev_->exportBuffers(bufferCount, &pool_); int ret = dev_->exportBuffers(&pool_);
if (ret) if (ret)
return TestFail; return TestFail;

View file

@ -24,8 +24,6 @@ class V4L2DeviceTest : public Test
public: public:
V4L2DeviceTest() : dev_(nullptr){}; V4L2DeviceTest() : dev_(nullptr){};
void createBuffers(unsigned int qty) { pool_.createBuffers(qty); }
protected: protected:
int init(); int init();
void cleanup(); void cleanup();