summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <paul.kocialkowski@bootlin.com>2018-07-19 15:03:47 +0200
committerPaul Kocialkowski <paul.kocialkowski@bootlin.com>2018-07-20 13:47:48 +0200
commit72c22a3bcea891bfe7947bbd96108ff418b6464d (patch)
tree316a7b535eba2dde06b752c11482609b84d5a89c
parentd2357862f836570e8c9d350ec88f83894c2e68ca (diff)
downloadlibva-v4l2-request-72c22a3bcea891bfe7947bbd96108ff418b6464d.tar.gz
libva-v4l2-request-72c22a3bcea891bfe7947bbd96108ff418b6464d.tar.bz2
libva-v4l2-request-72c22a3bcea891bfe7947bbd96108ff418b6464d.zip
v4l2: Introduce helper to request buffers
Although this is not needed when using the combination of CREATE_BUFS and QUERYBUF V4L2 ioctls (as currently done) to allocate and prepare buffers, the REQBUF ioctl is useful to liberate the buffers after use. This introduces a helper for this purpose. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
-rw-r--r--src/v4l2.c20
-rw-r--r--src/v4l2.h2
2 files changed, 22 insertions, 0 deletions
diff --git a/src/v4l2.c b/src/v4l2.c
index 429e158..64635fa 100644
--- a/src/v4l2.c
+++ b/src/v4l2.c
@@ -188,6 +188,26 @@ int v4l2_query_buffer(int video_fd, unsigned int type, unsigned int index,
return 0;
}
+int v4l2_request_buffers(int video_fd, unsigned int type,
+ unsigned int buffers_count)
+{
+ struct v4l2_requestbuffers buffers;
+ int rc;
+
+ memset(&buffers, 0, sizeof(buffers));
+ buffers.type = type;
+ buffers.memory = V4L2_MEMORY_MMAP;
+ buffers.count = buffers_count;
+
+ rc = ioctl(video_fd, VIDIOC_REQBUFS, &buffers);
+ if (rc < 0) {
+ request_log("Unable to request buffers: %s\n", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
int v4l2_queue_buffer(int video_fd, int request_fd, unsigned int type,
unsigned int index, unsigned int size,
unsigned int buffers_count)
diff --git a/src/v4l2.h b/src/v4l2.h
index 83523a5..6265ece 100644
--- a/src/v4l2.h
+++ b/src/v4l2.h
@@ -41,6 +41,8 @@ int v4l2_create_buffers(int video_fd, unsigned int type,
int v4l2_query_buffer(int video_fd, unsigned int type, unsigned int index,
unsigned int *lengths, unsigned int *offsets,
unsigned int buffers_count);
+int v4l2_request_buffers(int video_fd, unsigned int type,
+ unsigned int buffers_count);
int v4l2_queue_buffer(int video_fd, int request_fd, unsigned int type,
unsigned int index, unsigned int size,
unsigned int buffers_count);