2020-08-26 07:03:09 +00:00
|
|
|
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
|
2020-09-24 12:04:26 +00:00
|
|
|
.. c:namespace:: V4L
|
2018-08-30 14:15:26 +00:00
|
|
|
|
2016-06-30 13:18:56 +00:00
|
|
|
.. _func-mmap:
|
|
|
|
|
|
|
|
***********
|
|
|
|
V4L2 mmap()
|
|
|
|
***********
|
|
|
|
|
2016-07-05 18:14:35 +00:00
|
|
|
Name
|
2016-07-05 10:58:48 +00:00
|
|
|
====
|
2016-06-30 13:18:56 +00:00
|
|
|
|
2016-07-05 10:58:48 +00:00
|
|
|
v4l2-mmap - Map device memory into application address space
|
2016-06-30 13:18:56 +00:00
|
|
|
|
2016-07-05 18:14:35 +00:00
|
|
|
Synopsis
|
2016-06-30 13:18:56 +00:00
|
|
|
========
|
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2016-08-19 15:00:43 +00:00
|
|
|
.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )
|
2016-07-05 10:58:48 +00:00
|
|
|
|
2016-07-05 18:14:35 +00:00
|
|
|
Arguments
|
2016-06-30 13:18:56 +00:00
|
|
|
=========
|
|
|
|
|
|
|
|
``start``
|
|
|
|
Map the buffer to this address in the application's address space.
|
|
|
|
When the ``MAP_FIXED`` flag is specified, ``start`` must be a
|
|
|
|
multiple of the pagesize and mmap will fail when the specified
|
|
|
|
address cannot be used. Use of this option is discouraged;
|
|
|
|
applications should just specify a ``NULL`` pointer here.
|
|
|
|
|
|
|
|
``length``
|
|
|
|
Length of the memory area to map. This must be the same value as
|
|
|
|
returned by the driver in the struct
|
2016-08-29 20:37:59 +00:00
|
|
|
:c:type:`v4l2_buffer` ``length`` field for the
|
2016-06-30 13:18:56 +00:00
|
|
|
single-planar API, and the same value as returned by the driver in
|
2016-08-29 20:37:59 +00:00
|
|
|
the struct :c:type:`v4l2_plane` ``length`` field for
|
2016-06-30 13:18:56 +00:00
|
|
|
the multi-planar API.
|
|
|
|
|
|
|
|
``prot``
|
|
|
|
The ``prot`` argument describes the desired memory protection.
|
|
|
|
Regardless of the device type and the direction of data exchange it
|
|
|
|
should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read
|
|
|
|
and write access to image buffers. Drivers should support at least
|
2016-07-10 14:57:43 +00:00
|
|
|
this combination of flags.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
#. The Linux ``videobuf`` kernel module, which is used by some
|
|
|
|
drivers supports only ``PROT_READ`` | ``PROT_WRITE``. When the
|
|
|
|
driver does not support the desired protection, the
|
2020-09-24 12:04:26 +00:00
|
|
|
:c:func:`mmap()` function fails.
|
2016-07-10 14:57:43 +00:00
|
|
|
|
|
|
|
#. Device memory accesses (e. g. the memory on a graphics card
|
|
|
|
with video capturing hardware) may incur a performance penalty
|
|
|
|
compared to main memory accesses, or reads may be significantly
|
|
|
|
slower than writes or vice versa. Other I/O methods may be more
|
|
|
|
efficient in such case.
|
2016-06-30 13:18:56 +00:00
|
|
|
|
|
|
|
``flags``
|
|
|
|
The ``flags`` parameter specifies the type of the mapped object,
|
|
|
|
mapping options and whether modifications made to the mapped copy of
|
|
|
|
the page are private to the process or are to be shared with other
|
|
|
|
references.
|
|
|
|
|
|
|
|
``MAP_FIXED`` requests that the driver selects no other address than
|
|
|
|
the one specified. If the specified address cannot be used,
|
2020-09-24 12:04:26 +00:00
|
|
|
:c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified,
|
2016-06-30 13:18:56 +00:00
|
|
|
``start`` must be a multiple of the pagesize. Use of this option is
|
|
|
|
discouraged.
|
|
|
|
|
|
|
|
One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set.
|
|
|
|
``MAP_SHARED`` allows applications to share the mapped memory with
|
2016-07-10 14:57:43 +00:00
|
|
|
other (e. g. child-) processes.
|
|
|
|
|
2016-08-15 20:49:50 +00:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The Linux ``videobuf`` module which is used by some
|
2016-07-10 14:57:43 +00:00
|
|
|
drivers supports only ``MAP_SHARED``. ``MAP_PRIVATE`` requests
|
|
|
|
copy-on-write semantics. V4L2 applications should not set the
|
|
|
|
``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON``
|
|
|
|
flags.
|
2016-06-30 13:18:56 +00:00
|
|
|
|
|
|
|
``fd``
|
2020-09-24 12:04:26 +00:00
|
|
|
File descriptor returned by :c:func:`open()`.
|
2016-06-30 13:18:56 +00:00
|
|
|
|
|
|
|
``offset``
|
|
|
|
Offset of the buffer in device memory. This must be the same value
|
|
|
|
as returned by the driver in the struct
|
2016-08-29 20:37:59 +00:00
|
|
|
:c:type:`v4l2_buffer` ``m`` union ``offset`` field for
|
2016-06-30 13:18:56 +00:00
|
|
|
the single-planar API, and the same value as returned by the driver
|
2016-08-29 20:37:59 +00:00
|
|
|
in the struct :c:type:`v4l2_plane` ``m`` union
|
2016-06-30 13:18:56 +00:00
|
|
|
``mem_offset`` field for the multi-planar API.
|
|
|
|
|
2016-07-05 18:14:35 +00:00
|
|
|
Description
|
2016-06-30 13:18:56 +00:00
|
|
|
===========
|
|
|
|
|
2020-09-24 12:04:26 +00:00
|
|
|
The :c:func:`mmap()` function asks to map ``length`` bytes starting at
|
2016-06-30 13:18:56 +00:00
|
|
|
``offset`` in the memory of the device specified by ``fd`` into the
|
|
|
|
application address space, preferably at address ``start``. This latter
|
|
|
|
address is a hint only, and is usually specified as 0.
|
|
|
|
|
|
|
|
Suitable length and offset parameters are queried with the
|
2016-07-01 16:58:44 +00:00
|
|
|
:ref:`VIDIOC_QUERYBUF` ioctl. Buffers must be
|
|
|
|
allocated with the :ref:`VIDIOC_REQBUFS` ioctl
|
2016-06-30 13:18:56 +00:00
|
|
|
before they can be queried.
|
|
|
|
|
2020-09-24 12:04:26 +00:00
|
|
|
To unmap buffers the :c:func:`munmap()` function is used.
|
2016-06-30 13:18:56 +00:00
|
|
|
|
2016-07-05 18:14:35 +00:00
|
|
|
Return Value
|
2016-06-30 13:18:56 +00:00
|
|
|
============
|
|
|
|
|
2020-09-24 12:04:26 +00:00
|
|
|
On success :c:func:`mmap()` returns a pointer to the mapped buffer. On
|
2016-06-30 13:18:56 +00:00
|
|
|
error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set
|
|
|
|
appropriately. Possible error codes are:
|
|
|
|
|
|
|
|
EBADF
|
|
|
|
``fd`` is not a valid file descriptor.
|
|
|
|
|
|
|
|
EACCES
|
|
|
|
``fd`` is not open for reading and writing.
|
|
|
|
|
|
|
|
EINVAL
|
|
|
|
The ``start`` or ``length`` or ``offset`` are not suitable. (E. g.
|
|
|
|
they are too large, or not aligned on a ``PAGESIZE`` boundary.)
|
|
|
|
|
|
|
|
The ``flags`` or ``prot`` value is not supported.
|
|
|
|
|
|
|
|
No buffers have been allocated with the
|
2016-07-01 16:58:44 +00:00
|
|
|
:ref:`VIDIOC_REQBUFS` ioctl.
|
2016-06-30 13:18:56 +00:00
|
|
|
|
|
|
|
ENOMEM
|
|
|
|
Not enough physical or virtual memory was available to complete the
|
|
|
|
request.
|