Buffer management
You should consider that in V4L2, two buffer queues are maintained: one for the driver (referred to as the INPUT queue) and one for the user (referred to as the OUTPUT queue). Buffers are queued into the driver's queue by the user space application in order to be filled with data (the application uses the VIDIOC_QBUF
ioctl for this). Buffers are filled by the driver in the order they have been enqueued. Once filled, each buffer is moved off the INPUT queue and put into the OUTPUT queue, which is the user queue.
Whenever the user application calls VIDIOC_DQBUF
in order to dequeue a buffer, this buffer is looked for in the OUTPUT queue. If it's in there, the buffer will be dequeued and pushed to the user application; otherwise, the application will wait until a filled buffer is there. After the user finishes using the buffer, it must call VIDIOC_QBUF
on this buffer in order to enqueue it back in the INPUT queue so that it can be filled again.
After...