v4l2-mmap - Map device memory into application address space
#include <unistd.h>
#include <sys/mman.h>
The prot argument describes the desired memory protection. Regardless of the device type and the direction of data exchange it should be set to PROT_READ | PROT_WRITE, permitting read and write access to image buffers. Drivers should support at least this combination of flags.
Note
The flags parameter specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references.
MAP_FIXED requests that the driver selects no other address than the one specified. If the specified address cannot be used, mmap() will fail. If MAP_FIXED is specified, start must be a multiple of the pagesize. Use of this option is discouraged.
One of the MAP_SHARED or MAP_PRIVATE flags must be set. MAP_SHARED allows applications to share the mapped memory with other (e. g. child-) processes.
Note
The Linux videobuf module which is used by some drivers supports only MAP_SHARED. MAP_PRIVATE requests copy-on-write semantics. V4L2 applications should not set the MAP_PRIVATE, MAP_DENYWRITE, MAP_EXECUTABLE or MAP_ANON flags.
The mmap() function asks to map length bytes starting at offset in the memory of the device specified by fd into the application address space, preferably at address start. This latter address is a hint only, and is usually specified as 0.
Suitable length and offset parameters are queried with the ioctl VIDIOC_QUERYBUF ioctl. Buffers must be allocated with the ioctl VIDIOC_REQBUFS ioctl before they can be queried.
To unmap buffers the munmap() function is used.
On success mmap() returns a pointer to the mapped buffer. On error MAP_FAILED (-1) is returned, and the errno variable is set appropriately. Possible error codes are:
The start or length or offset are not suitable. (E. g. they are too large, or not aligned on a PAGESIZE boundary.)
The flags or prot value is not supported.
No buffers have been allocated with the ioctl VIDIOC_REQBUFS ioctl.