forked from marfrit/libva-v4l2-request-fourier
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>
This commit is contained in:
+20
@@ -188,6 +188,26 @@ int v4l2_query_buffer(int video_fd, unsigned int type, unsigned int index,
|
|||||||
return 0;
|
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,
|
int v4l2_queue_buffer(int video_fd, int request_fd, unsigned int type,
|
||||||
unsigned int index, unsigned int size,
|
unsigned int index, unsigned int size,
|
||||||
unsigned int buffers_count)
|
unsigned int buffers_count)
|
||||||
|
|||||||
@@ -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,
|
int v4l2_query_buffer(int video_fd, unsigned int type, unsigned int index,
|
||||||
unsigned int *lengths, unsigned int *offsets,
|
unsigned int *lengths, unsigned int *offsets,
|
||||||
unsigned int buffers_count);
|
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,
|
int v4l2_queue_buffer(int video_fd, int request_fd, unsigned int type,
|
||||||
unsigned int index, unsigned int size,
|
unsigned int index, unsigned int size,
|
||||||
unsigned int buffers_count);
|
unsigned int buffers_count);
|
||||||
|
|||||||
Reference in New Issue
Block a user