Commit fbe8e367 authored by André Almeida's avatar André Almeida

Add try fmt and refactor g fmt

parent cb7e45b8
......@@ -89,6 +89,38 @@ void v4l2_s_fmt(int fd, struct context ctx){
xioctl(fd, VIDIOC_S_FMT, &fmt);
}
void v4l2_try_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
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;
/* 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;
xioctl(fd, VIDIOC_TRY_FMT, &fmt);
__u8 num_planes = fmt.fmt.pix_mp.num_planes;
printf("Number of planes: %d\n", num_planes);
for(int i = 0; i < num_planes; i++)
printf("plane[%d].sizeimage = %u\n", i,
fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
}
void v4l2_g_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
xioctl(fd, VIDIOC_G_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",
......@@ -99,19 +131,12 @@ void v4l2_s_fmt(int fd, struct context ctx){
printf("Warning: driver is sending image at %dx%d\n",
fmt.fmt.pix.width, fmt.fmt.pix.height);
}
void v4l2_g_fmt(int fd, struct context ctx){
struct v4l2_format fmt;
//fmt.type = ctx.buf_type;
xioctl(fd, VIDIOC_G_FMT, &fmt);
__u8 num_planes = fmt.fmt.pix_mp.num_planes;
printf("Number of planes: %d\n", num_planes);
for(int i = 0; i < num_planes; i++){
__u32 b = fmt.fmt.pix_mp.plane_fmt[i].sizeimage;
printf("Plane[%d].sizeimage = %u\n", i, b);
}
for(int i = 0; i < num_planes; i++)
printf("plane[%d].sizeimage = %u\n", i,
fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
}
void v4l2_reqbuf(int fd, struct context ctx){
......@@ -215,9 +240,12 @@ int main(int argc, char **argv)
/* Setting image format */
v4l2_s_fmt(fd, ctx);
/* Getting image format */
#ifdef DBG_PRINT
/* Getting image format */
v4l2_g_fmt(fd, ctx);
/* Trying to set a image format */
v4l2_try_fmt(fd, ctx);
#endif
/* Requiring buffers */
......@@ -254,7 +282,7 @@ int main(int argc, char **argv)
/* enqueue the buffers */
for (i = 0; i < ctx.num_buffers; i++)
v4l2_qbuf(fd, ctx, i, planes, &buf);
/* start the streaming */
type = ctx.buf_type;
xioctl(fd, VIDIOC_STREAMON, &type);
......
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