^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) .. c:namespace:: V4L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) .. _func-open:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ***********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) V4L2 open()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) ***********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) v4l2-open - Open a V4L2 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) Synopsis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .. code-block:: c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .. c:function:: int open( const char *device_name, int flags )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ``device_name``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) Device to be opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ``flags``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Open flags. Access mode must be ``O_RDWR``. This is just a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) technicality, input devices still support only reading and output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) devices only writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) When the ``O_NONBLOCK`` flag is given, the :c:func:`read()`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) function and the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return the ``EAGAIN`` error code when no data is available or no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) buffer is in the driver outgoing queue, otherwise these functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) block until data becomes available. All V4L2 drivers exchanging data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) with applications must support the ``O_NONBLOCK`` flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) Other flags have no effect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) To open a V4L2 device applications call :c:func:`open()` with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) desired device name. This function has no side effects; all data format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) parameters, current input or output, control values or other properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) remain unchanged. At the first :c:func:`open()` call after loading the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) driver they will be reset to default values, drivers are never in an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) undefined state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) Return Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) On success :c:func:`open()` returns the new file descriptor. On error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) -1 is returned, and the ``errno`` variable is set appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) Possible error codes are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) EACCES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) The caller has no permission to access the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) EBUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) The driver does not support multiple opens and the device is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ENXIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) No device corresponding to this device special file exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ENOMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) Not enough kernel memory was available to complete the request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) EMFILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) The process already has the maximum number of files open.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ENFILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) The limit on the total number of files open on the system has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) reached.