Commit 5ae7decd authored by André Almeida's avatar André Almeida

Incapsulate get caps and set format

parent 44e65d4f
......@@ -63,18 +63,36 @@ static void xioctl(int fh, int request, void *arg)
}
void v4l2_querycap(int fd){
struct v4l2_capability caps;
xioctl(fd, VIDIOC_QUERYCAP, &caps);
if(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE == 0){
perror("Device can't make a multi-planar video capture");
exit(EXIT_FAILURE);
}
}
void v4l2_s_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
}
void v4l2_streamon(int fd, enum v4l2_buf_type type){
CLEAR(fmt);
fmt.type = ctx.buf_type;
fmt.fmt.pix_mp.width = ctx.img_width;
fmt.fmt.pix_mp.height = ctx.img_height;
fmt.fmt.pix_mp.pixelformat = ctx.pix_format;
fmt.fmt.pix_mp.num_planes = ctx.num_planes;
}
xioctl(fd, VIDIOC_S_FMT, &fmt);
void v4l2_streamoff(int fd, enum v4l2_buf_type type){
/* Comparing fmt accepted by the driver */
if (fmt.fmt.pix.pixelformat != ctx.pix_format) {
printf("Device didn't accept YUV420M format (got %x). Can't proceed.\n",
fmt.fmt.pix.pixelformat);
exit(EXIT_FAILURE);
}
if ((fmt.fmt.pix.width != ctx.img_width) || (fmt.fmt.pix.height != ctx.img_height))
printf("Warning: driver is sending image at %dx%d\n",
fmt.fmt.pix.width, fmt.fmt.pix.height);
}
......@@ -112,7 +130,6 @@ int main(int argc, char **argv)
struct v4l2_buffer buf;
struct v4l2_requestbuffers req;
struct v4l2_plane planes[ctx.num_planes];
struct v4l2_capability caps;
enum v4l2_buf_type type;
fd_set fds;
struct timeval tv;
......@@ -131,32 +148,11 @@ int main(int argc, char **argv)
}
/* Querying device capabilities */
xioctl(fd, VIDIOC_QUERYCAP, &caps);
if(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE == 0){
perror("Device can't make a multi-planar video capture");
exit(EXIT_FAILURE);
}
v4l2_querycap(fd);
/* Setting image format */
CLEAR(fmt);
fmt.type = ctx.buf_type;
fmt.fmt.pix_mp.width = ctx.img_width;
fmt.fmt.pix_mp.height = ctx.img_height;
fmt.fmt.pix_mp.pixelformat = ctx.pix_format;
fmt.fmt.pix_mp.num_planes = ctx.num_planes;
v4l2_s_fmt(fd, ctx);
xioctl(fd, VIDIOC_S_FMT, &fmt);
/* Comparing fmt accepted by the driver */
if (fmt.fmt.pix.pixelformat != ctx.pix_format) {
printf("Device didn't accept YUV420M format (got %x). Can't proceed.\n",
fmt.fmt.pix.pixelformat);
exit(EXIT_FAILURE);
}
if ((fmt.fmt.pix.width != ctx.img_width) || (fmt.fmt.pix.height != ctx.img_height))
printf("Warning: driver is sending image at %dx%d\n",
fmt.fmt.pix.width, fmt.fmt.pix.height);
/* Requiring buffers */
CLEAR(req);
req.count = ctx.num_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