Video data is separated into logical video samples which will typically be one complete video frame. With compressed formats, a video sample may be one logical chunk and not one complete frame depending on the compression format. Video samples may be read from
/dev/video in one of several different modes.
In read mode, calls to
read(2) will return at most the data of one video sample. If the entire sample is not read, then subsequent reads will return at most the remaining data in that video sample.
Video samples may be mapped into memory with
mmap(2). The driver allocates internal buffers for a number of video samples which are mapped into memory. Initiating this mode requires several
ioctl(2) commands:
VIDIOC_REQBUFS to request the driver reserve buffers,
VIDIOC_QUERYBUF to query the details of each buffer,
mmap(2) to map each buffer into memory,
VIDIOC_QBUF to queue the buffers for receiving video data,
VIDIOC_STREAMON to begin streaming of video data, and
VIDIOC_DQBUF to remove a filled buffer from the queue. At this point the video data from the dequeued buffer is valid.