@@ -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);
Buffer *dequeueBuffer();
void bufferAvailable(EventNotifier *notifier);
@@ -901,31 +901,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().emplace_back(plane);
- ::close(expbuf.fd);
+ ::close(fd);
return 0;
}
@@ -951,6 +942,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
*/