vidioc-create-bufs.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _VIDIOC_CREATE_BUFS:
  4. ************************
  5. ioctl VIDIOC_CREATE_BUFS
  6. ************************
  7. Name
  8. ====
  9. VIDIOC_CREATE_BUFS - Create buffers for Memory Mapped or User Pointer or DMA Buffer I/O
  10. Synopsis
  11. ========
  12. .. c:macro:: VIDIOC_CREATE_BUFS
  13. ``int ioctl(int fd, VIDIOC_CREATE_BUFS, struct v4l2_create_buffers *argp)``
  14. Arguments
  15. =========
  16. ``fd``
  17. File descriptor returned by :c:func:`open()`.
  18. ``argp``
  19. Pointer to struct :c:type:`v4l2_create_buffers`.
  20. Description
  21. ===========
  22. This ioctl is used to create buffers for :ref:`memory mapped <mmap>`
  23. or :ref:`user pointer <userp>` or :ref:`DMA buffer <dmabuf>` I/O. It
  24. can be used as an alternative or in addition to the
  25. :ref:`VIDIOC_REQBUFS` ioctl, when a tighter control
  26. over buffers is required. This ioctl can be called multiple times to
  27. create buffers of different sizes.
  28. To allocate the device buffers applications must initialize the relevant
  29. fields of the struct :c:type:`v4l2_create_buffers` structure. The
  30. ``count`` field must be set to the number of requested buffers, the
  31. ``memory`` field specifies the requested I/O method and the ``reserved``
  32. array must be zeroed.
  33. The ``format`` field specifies the image format that the buffers must be
  34. able to handle. The application has to fill in this struct
  35. :c:type:`v4l2_format`. Usually this will be done using the
  36. :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` or
  37. :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctls to ensure that the
  38. requested format is supported by the driver. Based on the format's
  39. ``type`` field the requested buffer size (for single-planar) or plane
  40. sizes (for multi-planar formats) will be used for the allocated buffers.
  41. The driver may return an error if the size(s) are not supported by the
  42. hardware (usually because they are too small).
  43. The buffers created by this ioctl will have as minimum size the size
  44. defined by the ``format.pix.sizeimage`` field (or the corresponding
  45. fields for other format types). Usually if the ``format.pix.sizeimage``
  46. field is less than the minimum required for the given format, then an
  47. error will be returned since drivers will typically not allow this. If
  48. it is larger, then the value will be used as-is. In other words, the
  49. driver may reject the requested size, but if it is accepted the driver
  50. will use it unchanged.
  51. When the ioctl is called with a pointer to this structure the driver
  52. will attempt to allocate up to the requested number of buffers and store
  53. the actual number allocated and the starting index in the ``count`` and
  54. the ``index`` fields respectively. On return ``count`` can be smaller
  55. than the number requested.
  56. .. c:type:: v4l2_create_buffers
  57. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
  58. .. flat-table:: struct v4l2_create_buffers
  59. :header-rows: 0
  60. :stub-columns: 0
  61. :widths: 1 1 2
  62. * - __u32
  63. - ``index``
  64. - The starting buffer index, returned by the driver.
  65. * - __u32
  66. - ``count``
  67. - The number of buffers requested or granted. If count == 0, then
  68. :ref:`VIDIOC_CREATE_BUFS` will set ``index`` to the current number of
  69. created buffers, and it will check the validity of ``memory`` and
  70. ``format.type``. If those are invalid -1 is returned and errno is
  71. set to ``EINVAL`` error code, otherwise :ref:`VIDIOC_CREATE_BUFS` returns
  72. 0. It will never set errno to ``EBUSY`` error code in this particular
  73. case.
  74. * - __u32
  75. - ``memory``
  76. - Applications set this field to ``V4L2_MEMORY_MMAP``,
  77. ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See
  78. :c:type:`v4l2_memory`
  79. * - struct :c:type:`v4l2_format`
  80. - ``format``
  81. - Filled in by the application, preserved by the driver.
  82. * - __u32
  83. - ``capabilities``
  84. - Set by the driver. If 0, then the driver doesn't support
  85. capabilities. In that case all you know is that the driver is
  86. guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support
  87. other :c:type:`v4l2_memory` types. It will not support any other
  88. capabilities. See :ref:`here <v4l2-buf-capabilities>` for a list of the
  89. capabilities.
  90. If you want to just query the capabilities without making any
  91. other changes, then set ``count`` to 0, ``memory`` to
  92. ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type.
  93. * - __u32
  94. - ``flags``
  95. - Specifies additional buffer management attributes.
  96. See :ref:`memory-flags`.
  97. * - __u32
  98. - ``max_num_buffers``
  99. - If the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set
  100. this field indicates the maximum possible number of buffers
  101. for this queue.
  102. * - __u32
  103. - ``reserved``\ [5]
  104. - A place holder for future extensions. Drivers and applications
  105. must set the array to zero.
  106. Return Value
  107. ============
  108. On success 0 is returned, on error -1 and the ``errno`` variable is set
  109. appropriately. The generic error codes are described at the
  110. :ref:`Generic Error Codes <gen-errors>` chapter.
  111. ENOMEM
  112. No memory to allocate buffers for :ref:`memory mapped <mmap>` I/O.
  113. EINVAL
  114. The buffer type (``format.type`` field), requested I/O method
  115. (``memory``) or format (``format`` field) is not valid.