1 .. -*- coding: utf-8; mode: rst -*-
3 .. _VIDIOC_CREATE_BUFS:
5 ************************
6 ioctl VIDIOC_CREATE_BUFS
7 ************************
12 VIDIOC_CREATE_BUFS - Create buffers for Memory Mapped or User Pointer or DMA Buffer I/O
18 .. c:function:: int ioctl( int fd, VIDIOC_CREATE_BUFS, struct v4l2_create_buffers *argp )
19 :name: VIDIOC_CREATE_BUFS
26 File descriptor returned by :ref:`open() <func-open>`.
29 Pointer to struct :c:type:`v4l2_create_buffers`.
35 This ioctl is used to create buffers for :ref:`memory mapped <mmap>`
36 or :ref:`user pointer <userp>` or :ref:`DMA buffer <dmabuf>` I/O. It
37 can be used as an alternative or in addition to the
38 :ref:`VIDIOC_REQBUFS` ioctl, when a tighter control
39 over buffers is required. This ioctl can be called multiple times to
40 create buffers of different sizes.
42 To allocate the device buffers applications must initialize the relevant
43 fields of the struct :c:type:`v4l2_create_buffers` structure. The
44 ``count`` field must be set to the number of requested buffers, the
45 ``memory`` field specifies the requested I/O method and the ``reserved``
48 The ``format`` field specifies the image format that the buffers must be
49 able to handle. The application has to fill in this struct
50 :c:type:`v4l2_format`. Usually this will be done using the
51 :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` or
52 :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctls to ensure that the
53 requested format is supported by the driver. Based on the format's
54 ``type`` field the requested buffer size (for single-planar) or plane
55 sizes (for multi-planar formats) will be used for the allocated buffers.
56 The driver may return an error if the size(s) are not supported by the
57 hardware (usually because they are too small).
59 The buffers created by this ioctl will have as minimum size the size
60 defined by the ``format.pix.sizeimage`` field (or the corresponding
61 fields for other format types). Usually if the ``format.pix.sizeimage``
62 field is less than the minimum required for the given format, then an
63 error will be returned since drivers will typically not allow this. If
64 it is larger, then the value will be used as-is. In other words, the
65 driver may reject the requested size, but if it is accepted the driver
66 will use it unchanged.
68 When the ioctl is called with a pointer to this structure the driver
69 will attempt to allocate up to the requested number of buffers and store
70 the actual number allocated and the starting index in the ``count`` and
71 the ``index`` fields respectively. On return ``count`` can be smaller
72 than the number requested.
75 .. c:type:: v4l2_create_buffers
77 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
79 .. flat-table:: struct v4l2_create_buffers
86 - The starting buffer index, returned by the driver.
89 - The number of buffers requested or granted. If count == 0, then
90 :ref:`VIDIOC_CREATE_BUFS` will set ``index`` to the current number of
91 created buffers, and it will check the validity of ``memory`` and
92 ``format.type``. If those are invalid -1 is returned and errno is
93 set to ``EINVAL`` error code, otherwise :ref:`VIDIOC_CREATE_BUFS` returns
94 0. It will never set errno to ``EBUSY`` error code in this particular
98 - Applications set this field to ``V4L2_MEMORY_MMAP``,
99 ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See
100 :c:type:`v4l2_memory`
101 * - struct :c:type:`v4l2_format`
103 - Filled in by the application, preserved by the driver.
106 - A place holder for future extensions. Drivers and applications
107 must set the array to zero.
113 On success 0 is returned, on error -1 and the ``errno`` variable is set
114 appropriately. The generic error codes are described at the
115 :ref:`Generic Error Codes <gen-errors>` chapter.
118 No memory to allocate buffers for :ref:`memory mapped <mmap>` I/O.
121 The buffer type (``format.type`` field), requested I/O method
122 (``memory``) or format (``format`` field) is not valid.