ioctl VIDIOC_REQBUFS
Name #
VIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O
Synopsis #
int ioctl(int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp)
Arguments #
-
fdFile descriptor returned by
open(). -
argpPointer to struct
v4l2_requestbuffers.
Description #
This ioctl is used to initiate memory mapped, user pointer or DMABUF based I/O. Memory mapped buffers are located in device memory and must be allocated with this ioctl before they can be mapped into the application's address space. User buffers are allocated by applications themselves, and this ioctl is merely used to switch the driver into user pointer I/O mode and to setup some internal structures. Similarly, DMABUF buffers are allocated by applications through a device driver, and this ioctl only configures the driver into DMABUF I/O mode without performing any direct allocation.
To allocate device buffers applications initialize all fields of the struct v4l2_requestbuffers structure. They set the type field to the respective stream or buffer type, the count field to the desired number of buffers, memory must be set to the requested I/O method and the reserved array must be zeroed. When the ioctl is called with a pointer to this structure the driver will attempt to allocate the requested number of buffers and it stores the actual number allocated in the count field. It can be smaller than the number requested, even zero, when the driver runs out of free memory. A larger number is also possible when the driver requires more buffers to function correctly. For example video output requires at least two buffers, one displayed and one filled by the application.
When the I/O method is not supported the ioctl returns an EINVAL error code.
Applications can call ioctl VIDIOC_REQBUFS again to change the number of buffers. Note that if any buffers are still mapped or exported via DMABUF, then ioctl VIDIOC_REQBUFS can only succeed if the V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS capability is set. Otherwise ioctl VIDIOC_REQBUFS will return the EBUSY error code. If V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS is set, then these buffers are orphaned and will be freed when they are unmapped or when the exported DMABUF fds are closed. A count value of zero frees or orphans all buffers, after aborting or finishing any DMA in progress, an implicit VIDIOC_STREAMOFF.
v4l2_requestbuffers
|
__u32 |
|
The number of buffers requested or granted. |
|
__u32 |
|
Type of the stream or buffers, this is the same as the struct |
|
__u32 |
|
Applications set this field to |
|
__u32 |
|
Set by the driver. If 0, then the driver doesn't support capabilities. In that case all you know is that the driver is guaranteed to support If you want to query the capabilities with a minimum of side-effects, then this can be called with |
|
__u8 |
|
Specifies additional buffer management attributes. See memory-flags. |
|
__u8 |
|
Reserved for future extensions. |
|
|
0x00000001 |
This buffer type supports the |
|
|
0x00000002 |
This buffer type supports the |
|
|
0x00000004 |
This buffer type supports the |
|
|
0x00000008 |
This buffer type supports requests. |
|
|
0x00000010 |
The kernel allows calling ioctl VIDIOC_REQBUFS while buffers are still mapped or exported via DMABUF. These orphaned buffers will be freed when they are unmapped or when the exported DMABUF fds are closed. |
|
|
0x00000020 |
Only valid for stateless decoders. If set, then userspace can set the |
|
|
0x00000040 |
This capability is set by the driver to indicate that the queue supports cache and memory management hints. However, it's only valid when the queue is used for memory mapping streaming I/O. See V4L2_BUF_FLAG_NO_CACHE_INVALIDATE, V4L2_BUF_FLAG_NO_CACHE_CLEAN and V4L2_MEMORY_FLAG_NON_COHERENT. |
|
|
0x00000080 |
If set, then the |
|
|
0x00000100 |
If set, then |
|
|
0x00000001 |
A buffer is allocated either in coherent (it will be automatically coherent between the CPU and the bus) or non-coherent memory. The latter can provide performance gains, for instance the CPU cache sync/flush operations can be avoided if the buffer is accessed by the corresponding device only and the CPU does not read/write to/from that buffer. However, this requires extra care from the driver -- it must guarantee memory consistency by issuing a cache flush/sync when consistency is needed. If this flag is set V4L2 will attempt to allocate the buffer in non-coherent memory. The flag takes effect only if the buffer is used for memory mapping I/O and the queue reports the V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability. |
Return Value #
On success 0 is returned, on error -1 and the errno variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.
-
EINVAL
The buffer type (
typefield) or the requested I/O method (memory) is not supported.