From 3d6471013462f614bb14b3a775881b02c724df7a Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 24 May 2018 01:24:39 +0300 Subject: v4l2: Query buffer sizes when exporting buffers In order to properly import buffers, the size of each buffer to be imported must be known. The size is queried when the buffers are mmap()ed, but mapping them isn't mandatory. Query the size when exporting buffers to ensure that we always have a valid size for import. Signed-off-by: Laurent Pinchart --- v4l2.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/v4l2.c b/v4l2.c index 25c8fb4..6b1c753 100644 --- a/v4l2.c +++ b/v4l2.c @@ -631,13 +631,26 @@ int v4l2_export_buffers(struct v4l2_device *dev) .type = dev->type, .index = i, }; + struct v4l2_buffer buf = { + .index = i, + .type = dev->type, + .memory = dev->memtype, + }; + + ret = ioctl(dev->fd, VIDIOC_QUERYBUF, &buf); + if (ret < 0) { + printf("%s: unable to query buffer %u (%d).\n", + dev->name, i, errno); + return -errno; + } ret = ioctl(dev->fd, VIDIOC_EXPBUF, &expbuf); if (ret < 0) { printf("Failed to export buffer %u.\n", i); - return ret; + return -errno; } + dev->buffers[i].size = buf.length; dev->buffers[i].dmabuf = expbuf.fd; printf("%s: buffer %u exported with fd %u.\n", -- cgit v1.2.3