summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2019-01-30 12:52:00 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2019-02-13 15:58:06 +0000
commit819eb422b39afbfb618ed3b1618cf03bebec1abd (patch)
treecd356a0291ab8b36c3dda3ecbba27c96508f9712
parent03fcc154eb0599e02276c9f64fce46b643104e20 (diff)
libcamera: v4l2_device: importBuffers support
Provide the ability to import a BufferPool into the V4L2Device allowing external dmabuf backed buffers to be queued. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--src/libcamera/include/v4l2_device.h1
-rw-r--r--src/libcamera/v4l2_device.cpp45
2 files changed, 45 insertions, 1 deletions
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index 5a536393..1d31d1b4 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -100,6 +100,7 @@ public:
int setFormat(V4L2DeviceFormat *format);
int exportBuffers(BufferPool *pool);
+ int importBuffers(BufferPool *pool);
int releaseBuffers();
int queueBuffer(Buffer *buffer);
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index ca6bb4ee..24e11555 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -643,6 +643,36 @@ int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex,
}
/**
+ * \brief Import the externally allocated \a pool of buffers
+ * \param[in] pool BufferPool of buffers to import
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2Device::importBuffers(BufferPool *pool)
+{
+ unsigned int allocatedBuffers;
+ int ret;
+
+ memoryType_ = V4L2_MEMORY_DMABUF;
+
+ ret = requestBuffers(pool->count());
+ if (ret < 0)
+ return ret;
+
+ allocatedBuffers = ret;
+ if (allocatedBuffers < pool->count()) {
+ LOG(V4L2, Error)
+ << "Not enough buffers provided by V4L2Device";
+ requestBuffers(0);
+ return -ENOMEM;
+ }
+
+ LOG(V4L2, Debug) << "provided pool of " << pool->count() << "buffers";
+ bufferPool_ = pool;
+
+ return 0;
+}
+
+/**
* \brief Release all internally allocated buffers
*/
int V4L2Device::releaseBuffers()
@@ -680,7 +710,20 @@ int V4L2Device::queueBuffer(Buffer *buffer)
buf.memory = memoryType_;
buf.field = V4L2_FIELD_NONE;
- if (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {
+ bool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);
+
+ if (buf.memory == V4L2_MEMORY_DMABUF) {
+ if (multiPlanar) {
+ for (unsigned int p = 0;
+ p < buffer->planes().size();
+ p++)
+ planes[p].m.fd = buffer->planes()[p].dmabuf();
+ } else {
+ buf.m.fd = buffer->planes()[0].dmabuf();
+ }
+ }
+
+ if (multiPlanar) {
buf.length = buffer->planes().size();
buf.m.planes = planes;
}