summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-05-24 01:24:39 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-05-24 01:26:38 +0300
commit3d6471013462f614bb14b3a775881b02c724df7a (patch)
treed9b18787d26e9e6377a4773eaa271b405d804835
parentb0be8eb957c6a54040a3a680d6549419dd885d27 (diff)
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 <laurent.pinchart@ideasonboard.com>
-rw-r--r--v4l2.c15
1 files changed, 14 insertions, 1 deletions
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",