http://v4l2spec.bytesex.org/
for the official V4L2 specification.
The device file for video operation is
/dev/video
.
/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.
VIDIOC_QUERYCAP
(struct
v4l2_capabilities)
The capabilities field contains a number of flags indicating various features supported by the driver or hardware:
V4L2_CAP_VIDEO_CAPTURE
V4L2_CAP_READWRITE
V4L2_CAP_STREAMING
struct v4l2_capability {
uint8_t driver[16];
uint8_t card[32];
uint8_t bus_info[32];
uint32_t version;
uint32_t capabilities;
uint32_t reserved[4];
};
VIDIOC_REQBUFS
(struct
v4l2_requestbuffers)
V4L2_BUF_TYPE_VIDEO_CAPTURE
and
memory
to
V4L2_MEMORY_MMAP
.
The returned
count
represents the actual number of samples reserved which may be more
or fewer than requested.
struct v4l2_requestbuffers {
uint32_t count;
enum v4l2_buf_type type;
enum v4l2_memory memory;
uint32_t reserved[2];
};
VIDIOC_QUERYBUF
(struct
v4l2_buffer)
VIDIOC_QUERYBUF
.
The driver returns
m.offset
and
length.
struct v4l2_buffer {
uint32_t index;
enum v4l2_buf_type type;
uint32_t bytesused;
uint32_t flags;
enum v4l2_field field;
struct timeval timestamp;
struct v4l2_timecode timecode;
uint32_t sequence;
enum v4l2_memory memory;
union {
uint32_t offset;
unsigned long userptr;
} m;
uint32_t length;
uint32_t input;
uint32_t reserved;
};
PROT_READ|PROT_WRITE
and flags
MAP_SHARED
are recommended.
VIDIOC_QBUF
(struct
v4l2_buffer)
VIDIOC_STREAMON
(int)
VIDIOC_DQBUF
(struct
v4l2_buffer)
O_NONBLOCK
was specified to
open(2),
in which case it returns
EAGAIN
.
select(2),
or
poll(2)
prior to initiating any other mode will begin streaming of video for
reading with
read(2).
In this streaming mode
select(2)
or
poll(2)
indicate the availability of a video frame.
Calls to
read(2)
will return at most the video 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.
/dev/video