vidioc-reqbufs.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _VIDIOC_REQBUFS:
  3. ********************
  4. ioctl VIDIOC_REQBUFS
  5. ********************
  6. Name
  7. ====
  8. VIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O
  9. Synopsis
  10. ========
  11. .. c:function:: int ioctl( int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp )
  12. :name: VIDIOC_REQBUFS
  13. Arguments
  14. =========
  15. ``fd``
  16. File descriptor returned by :ref:`open() <func-open>`.
  17. ``argp``
  18. Description
  19. ===========
  20. This ioctl is used to initiate :ref:`memory mapped <mmap>`,
  21. :ref:`user pointer <userp>` or :ref:`DMABUF <dmabuf>` based I/O.
  22. Memory mapped buffers are located in device memory and must be allocated
  23. with this ioctl before they can be mapped into the application's address
  24. space. User buffers are allocated by applications themselves, and this
  25. ioctl is merely used to switch the driver into user pointer I/O mode and
  26. to setup some internal structures. Similarly, DMABUF buffers are
  27. allocated by applications through a device driver, and this ioctl only
  28. configures the driver into DMABUF I/O mode without performing any direct
  29. allocation.
  30. To allocate device buffers applications initialize all fields of the
  31. struct :c:type:`v4l2_requestbuffers` structure. They set the ``type``
  32. field to the respective stream or buffer type, the ``count`` field to
  33. the desired number of buffers, ``memory`` must be set to the requested
  34. I/O method and the ``reserved`` array must be zeroed. When the ioctl is
  35. called with a pointer to this structure the driver will attempt to
  36. allocate the requested number of buffers and it stores the actual number
  37. allocated in the ``count`` field. It can be smaller than the number
  38. requested, even zero, when the driver runs out of free memory. A larger
  39. number is also possible when the driver requires more buffers to
  40. function correctly. For example video output requires at least two
  41. buffers, one displayed and one filled by the application.
  42. When the I/O method is not supported the ioctl returns an ``EINVAL`` error
  43. code.
  44. Applications can call :ref:`VIDIOC_REQBUFS` again to change the number of
  45. buffers, however this cannot succeed when any buffers are still mapped.
  46. A ``count`` value of zero frees all buffers, after aborting or finishing
  47. any DMA in progress, an implicit
  48. :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`.
  49. .. c:type:: v4l2_requestbuffers
  50. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
  51. .. flat-table:: struct v4l2_requestbuffers
  52. :header-rows: 0
  53. :stub-columns: 0
  54. :widths: 1 1 2
  55. * - __u32
  56. - ``count``
  57. - The number of buffers requested or granted.
  58. * - __u32
  59. - ``type``
  60. - Type of the stream or buffers, this is the same as the struct
  61. :c:type:`v4l2_format` ``type`` field. See
  62. :c:type:`v4l2_buf_type` for valid values.
  63. * - __u32
  64. - ``memory``
  65. - Applications set this field to ``V4L2_MEMORY_MMAP``,
  66. ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See
  67. :c:type:`v4l2_memory`.
  68. * - __u32
  69. - ``reserved``\ [2]
  70. - A place holder for future extensions. Drivers and applications
  71. must set the array to zero.
  72. Return Value
  73. ============
  74. On success 0 is returned, on error -1 and the ``errno`` variable is set
  75. appropriately. The generic error codes are described at the
  76. :ref:`Generic Error Codes <gen-errors>` chapter.
  77. EINVAL
  78. The buffer type (``type`` field) or the requested I/O method
  79. (``memory``) is not supported.