I'm using an Aptina MT9V024 sensor connected via LVDS to the CSI interface of an i.MX6 Quad. I'm running the sensor in snapshot mode, i.e. using an external signal to trigger/start the image capture.
On software side, I'm running Yocto Linux and an application written in C which should retrieve the captured image data.
It works like this (part of the code, run in a loop):
// wait until camers is triggered
ret = select(video_fd + 1, &fds, NULL, NULL, &tv);
// dq buffer / read image data and save to disk
ret = xioctl(video_fd, VIDIOC_DQBUF, &v4l2buf);
img->imageData = buffers[v4l2buf.index].start;
cvSaveImage(filename, img, 0);
// enqueue another buffer to capture next frame
ret = xioctl(video_fd, VIDIOC_QBUF, &v4l2buf);
The call to select(...)
blocks until a new frame is available, i.e. the camera was triggered.
My problem: The image retrieved is the one from the previous capture. During init, I'm requesting two buffers, because the sensor does not start with less. But I cannot DQBUF more than one buffer after select(...) returns. So, I'm always stuck with an old frame.
What works is accessing not the buffer which I get returned by DQBUF, but "the other" buffer, i.e. use buffers[(v4l2buf.index + 1) % 2]
instead of buffers[v4l2buf.index]
in the third line in the code above. But I suppose that this is not a very reliable way, as I'm accessing a buffer which is, according to the v4l2 API, not ready to be read (but in reality it contains the data which I want).