Commit 87fc8d5a authored by André Almeida's avatar André Almeida

Refactor reqbuf and add comments

parent 858b92a1
......@@ -62,11 +62,13 @@ static void xioctl(int fh, int request, void *arg)
}
}
/* query que capabilities of the driver */
void v4l2_querycap(int fd){
struct v4l2_capability caps;
xioctl(fd, VIDIOC_QUERYCAP, &caps);
/* check if the driver can operate with this app */
if(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE == 0){
perror("Device can't make a multi-planar video capture");
exit(EXIT_FAILURE);
......@@ -77,6 +79,7 @@ void v4l2_querycap(int fd){
}
}
/* negotiates a format with the driver */
void v4l2_s_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
......@@ -96,6 +99,7 @@ void v4l2_s_fmt(int fd, struct context ctx){
}
/* just try to set a format, but don't actually change the driver */
void v4l2_try_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
......@@ -106,7 +110,6 @@ void v4l2_try_fmt(int fd, struct context ctx){
fmt.fmt.pix_mp.pixelformat = ctx.pix_format;
fmt.fmt.pix_mp.num_planes = ctx.num_planes;
/* doesn't make difference, driver overwrite this data */
fmt.fmt.pix_mp.plane_fmt[0].sizeimage = 230400;
fmt.fmt.pix_mp.plane_fmt[1].sizeimage = 57600;
fmt.fmt.pix_mp.plane_fmt[2].sizeimage = 57600;
......@@ -121,6 +124,7 @@ void v4l2_try_fmt(int fd, struct context ctx){
}
/* get actual driver format */
void v4l2_g_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
......@@ -144,7 +148,8 @@ void v4l2_g_fmt(int fd, struct context ctx){
fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
}
void v4l2_reqbuf(int fd, struct context ctx){
/* require buffers for the driver and return the number of allocated bufs */
int v4l2_reqbuf(int fd, struct context ctx){
struct v4l2_requestbuffers req;
CLEAR(req);
......@@ -153,12 +158,13 @@ void v4l2_reqbuf(int fd, struct context ctx){
req.memory = ctx.mem_type;
xioctl(fd, VIDIOC_REQBUFS, &req);
if (req.count < ctx.num_buffers){
if (req.count < ctx.num_buffers)
printf("Warning: couldn't allocate all requested buffers");
ctx.num_buffers = req.count;
}
return req.count;
}
/* query and get info of a buffer by the index */
void v4l2_querybuf(int fd, struct context ctx, int index, struct v4l2_plane *planes, struct v4l2_buffer *buf){
CLEAR(*buf);
......@@ -181,7 +187,7 @@ void v4l2_querybuf(int fd, struct context ctx, int index, struct v4l2_plane *pla
}
/* enqueue buffer of index i */
/* enqueue buffer by it index */
void v4l2_qbuf(int fd, struct context ctx, int index, struct v4l2_plane *planes, struct v4l2_buffer *buf){
CLEAR(*buf);
......@@ -261,7 +267,7 @@ int main(int argc, char **argv)
#endif
/* Requiring buffers */
v4l2_reqbuf(fd, ctx);
ctx.num_buffers = v4l2_reqbuf(fd, ctx);
/* Buffer memory allocation */
buffers = calloc(ctx.num_planes * ctx.num_buffers, sizeof(*buffers));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment