V4L2 problems arising

In a data out when I am using the following code:

struct v4l2_buffer buf;
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;

if(ioctl(fd, VIDIOC_DQBUF, &buf) == -1)
{
printf("VIDIOC_DQBUF failed\n");
return -10;
}
printf("VIDIOC_DQBUF success\n");

 

The results have been running the ioctl return -1, we have been unable to solve the problem

But when I step before adding select for testing in this, to solve this problem

fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = 2;
tv.tv_usec = 0;
int ret;
ret = select(fd+1, &fds, NULL, NULL, &tv);

 

This time delay is set in the above code to detect whether there is data fd, fd when there is data, select will return, otherwise select will be blocked there, waiting;

Like this solves the previous problems, the problem is before the camera started when acquiring data, using the ioctl immediately obtain data of one frame, but the message queue has not at this time, so ioctl returns -1, issue the command fails

When using select, and when there is data fd before returning, so we remove a child to have the data we get, the error does not occur

Guess you like

Origin www.cnblogs.com/yangjiquan/p/11369472.html