dmx-expbuf.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: DTV.dmx
  3. .. _DMX_EXPBUF:
  4. ****************
  5. ioctl DMX_EXPBUF
  6. ****************
  7. Name
  8. ====
  9. DMX_EXPBUF - Export a buffer as a DMABUF file descriptor.
  10. .. warning:: this API is still experimental
  11. Synopsis
  12. ========
  13. .. c:macro:: DMX_EXPBUF
  14. ``int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)``
  15. Arguments
  16. =========
  17. ``fd``
  18. File descriptor returned by :c:func:`open()`.
  19. ``argp``
  20. Pointer to struct :c:type:`dmx_exportbuffer`.
  21. Description
  22. ===========
  23. This ioctl is an extension to the memory mapping I/O method.
  24. It can be used to export a buffer as a DMABUF file at any time after
  25. buffers have been allocated with the :ref:`DMX_REQBUFS` ioctl.
  26. To export a buffer, applications fill struct :c:type:`dmx_exportbuffer`.
  27. Applications must set the ``index`` field. Valid index numbers
  28. range from zero to the number of buffers allocated with :ref:`DMX_REQBUFS`
  29. (struct :c:type:`dmx_requestbuffers` ``count``) minus one.
  30. Additional flags may be posted in the ``flags`` field. Refer to a manual
  31. for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
  32. and O_RDWR are supported.
  33. All other fields must be set to zero. In the
  34. case of multi-planar API, every plane is exported separately using
  35. multiple :ref:`DMX_EXPBUF` calls.
  36. After calling :ref:`DMX_EXPBUF` the ``fd`` field will be set by a
  37. driver, on success. This is a DMABUF file descriptor. The application may
  38. pass it to other DMABUF-aware devices. It is recommended to close a DMABUF
  39. file when it is no longer used to allow the associated memory to be reclaimed.
  40. Examples
  41. ========
  42. .. code-block:: c
  43. int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
  44. {
  45. struct dmx_exportbuffer expbuf;
  46. memset(&expbuf, 0, sizeof(expbuf));
  47. expbuf.type = bt;
  48. expbuf.index = index;
  49. if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
  50. perror("DMX_EXPBUF");
  51. return -1;
  52. }
  53. *dmafd = expbuf.fd;
  54. return 0;
  55. }
  56. Return Value
  57. ============
  58. On success 0 is returned, on error -1 and the ``errno`` variable is set
  59. appropriately. The generic error codes are described at the
  60. :ref:`Generic Error Codes <gen-errors>` chapter.
  61. EINVAL
  62. A queue is not in MMAP mode or DMABUF exporting is not supported or
  63. ``flags`` or ``index`` fields are invalid.