AnsweredAssumed Answered

With sensor in snapshot mode, V4L2 does not allow me to retrieve "fresh" frames

Question asked by Micha Ober on May 19, 2017

Camera:

Aptina MT9V024

 

BSP / OS:

root@phyboard-mira-imx6-3:~# lsb_release -a
Distributor ID: Yogurt
Description: Yogurt GNU/Linux i.MX6-PD15.3.0 (fido)
Release: i.MX6-PD15.3.0
Codename: fido
root@phyboard-mira-imx6-3:~# uname -a
Linux phyboard-mira-imx6-3 4.1.18-i.MX6-PD15.3.0 #1 SMP Thu Mar 31 19:45:37 CEST 2016 armv7l GNU/Linux

 

Setup:

I'm using the external Trigger input on the Sensor (snapshot mode), so it is not continuously capturing frames but only when requested to do. I'm using V4L2 to retrieve the frames (this is part of the code that is executed in a loop):

 

ret = select(video_fd + 1, &fds, NULL, NULL, &tv);

ret = xioctl(video_fd, VIDIOC_DQBUF, &v4l2buf);

img->imageData = buffers[v4l2buf.index].start;
cvSaveImage(filename, img, 0);

ret = xioctl(video_fd, VIDIOC_QBUF, &v4l2buf);

 

Problem:

I'm retrieving the frames with one frame delay. So triggering the camera at some point A, DQBUF gives me the buffer from the previous capture. But I would like to get it "instant", i.e. select() blocks until the camera is triggered and right then I receive the image data associated with that capture (not the previous one).

 

What I tried:

- I'm allocating 2 buffers during setup, because I cannot allocates less buffers (only more).

- Using buffers[(v4l2buf.index + 1) % 2].start instead of buffers[v4l2buf.index].start works but it does not look like a reliable solution.

- I found another question about the same topic[1], but the suggested method does not work for me. Everytime select() returns, I can only DQBUF a single buffer. Trying to DQ a second buffer results in an error.

 

 

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

Outcomes