0001 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
0002 .. c:namespace:: DTV.dmx
0003
0004 .. _DMX_EXPBUF:
0005
0006 ****************
0007 ioctl DMX_EXPBUF
0008 ****************
0009
0010 Name
0011 ====
0012
0013 DMX_EXPBUF - Export a buffer as a DMABUF file descriptor.
0014
0015 .. warning:: this API is still experimental
0016
0017 Synopsis
0018 ========
0019
0020 .. c:macro:: DMX_EXPBUF
0021
0022 ``int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)``
0023
0024 Arguments
0025 =========
0026
0027 ``fd``
0028 File descriptor returned by :c:func:`open()`.
0029
0030 ``argp``
0031 Pointer to struct :c:type:`dmx_exportbuffer`.
0032
0033 Description
0034 ===========
0035
0036 This ioctl is an extension to the memory mapping I/O method.
0037 It can be used to export a buffer as a DMABUF file at any time after
0038 buffers have been allocated with the :ref:`DMX_REQBUFS` ioctl.
0039
0040 To export a buffer, applications fill struct :c:type:`dmx_exportbuffer`.
0041 Applications must set the ``index`` field. Valid index numbers
0042 range from zero to the number of buffers allocated with :ref:`DMX_REQBUFS`
0043 (struct :c:type:`dmx_requestbuffers` ``count``) minus one.
0044 Additional flags may be posted in the ``flags`` field. Refer to a manual
0045 for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
0046 and O_RDWR are supported.
0047 All other fields must be set to zero. In the
0048 case of multi-planar API, every plane is exported separately using
0049 multiple :ref:`DMX_EXPBUF` calls.
0050
0051 After calling :ref:`DMX_EXPBUF` the ``fd`` field will be set by a
0052 driver, on success. This is a DMABUF file descriptor. The application may
0053 pass it to other DMABUF-aware devices. It is recommended to close a DMABUF
0054 file when it is no longer used to allow the associated memory to be reclaimed.
0055
0056 Examples
0057 ========
0058
0059 .. code-block:: c
0060
0061 int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
0062 {
0063 struct dmx_exportbuffer expbuf;
0064
0065 memset(&expbuf, 0, sizeof(expbuf));
0066 expbuf.type = bt;
0067 expbuf.index = index;
0068 if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
0069 perror("DMX_EXPBUF");
0070 return -1;
0071 }
0072
0073 *dmafd = expbuf.fd;
0074
0075 return 0;
0076 }
0077
0078 Return Value
0079 ============
0080
0081 On success 0 is returned, on error -1 and the ``errno`` variable is set
0082 appropriately. The generic error codes are described at the
0083 :ref:`Generic Error Codes <gen-errors>` chapter.
0084
0085 EINVAL
0086 A queue is not in MMAP mode or DMABUF exporting is not supported or
0087 ``flags`` or ``index`` fields are invalid.