V4L2 How to capture fresh frame? (i.MX mxc capture , select() with timeout = 0)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

V4L2 How to capture fresh frame? (i.MX mxc capture , select() with timeout = 0)

Jump to solution
4,305 Views
ilyakosharov
Contributor II

Hi!

I'm working with board based on Nitrogen6x using v4l2 for capturing mt9v131 Aptina sensor through mxc capture drivers.

Sensor is connected through csi and ipu and works with mxc_v4l2_capture.c subsystem.

As it has FRAME_NUM = 10 buffer frames i have a video stream with delay of 10 frames. One of solutions i have found to have fresh frame is to dequeue and queue buffers as long as it possible with timeout = 0 while select returns something with Read descriptor. When select returns an error you have a latest frame or, as it could be, have to wait for timeout != 0 (corresponding with your FPS).

So, the problem is that select with timeout = 0

res = select(handlePrivate->devHandle + 1, &readFDSet, NULL, NULL, 0);

everytime returns 1, means that something is to be readed. It happens even in endless loop with select request only.

The questions are:

- Is the camera filedescriptor has something to read? What could it be? Not only frames?

- Maybe there is a more elegant way to get latest frame with v4l2?

Thanx for suggestions!

P.S. I've tried this solution with USB webcam and it worked fine.

Labels (1)
0 Kudos
1 Solution
2,222 Views
ilyakosharov
Contributor II

I've found that poll() and select() works correct with timeout == 0 when device is opened with O_NONBLOCK flag.

That's all.

View solution in original post

0 Kudos
3 Replies
2,223 Views
ilyakosharov
Contributor II

I've found that poll() and select() works correct with timeout == 0 when device is opened with O_NONBLOCK flag.

That's all.

0 Kudos
2,222 Views
EricNelson
Senior Contributor II

Hello Ilya,

If you're using mfw_v4l2_capture.c, this is the right approach (poll() with zero timeout and ioctl(DQBUF)).

I wouldn't use select(), since it's pretty clunky. poll() is much easier to use.

2,222 Views
ilyakosharov
Contributor II

EricNelsonThank you for your answer! poll() is really easier to use.

Using this I've found mxc_poll(...) function in mxc_v4l2_capture.c that performs poll():

static unsigned int mxc_poll(struct file *file, struct poll_table_struct *wait)

{

struct video_device *dev = video_devdata(file);

cam_data *cam = video_get_drvdata(dev);

wait_queue_head_t *queue = NULL;

int res = POLLIN | POLLRDNORM;

pr_debug("In MVC:mxc_poll\n");

if (down_interruptible(&cam->busy_lock))

return -EINTR;

queue = &cam->enc_queue;

poll_wait(file, queue, wait);

up(&cam->busy_lock);

return res;

}

As I understand, poll_wait(...) waits for something in queue. So it just waits for new frame and returns POLLIN | POLLRDNORM everytime.

So, we are not able to reach the condition then all buffers are red out and we wait for fresh one, as mxc_poll returns only POLLIN | POLLRDNORM.

So, how to skip all buffers but last? =)

0 Kudos