^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) .. _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) Opening and Closing Devices
^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) .. _v4l2_hardware_control:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) Controlling a hardware peripheral via V4L2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) ==========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) Hardware that is supported using the V4L2 uAPI often consists of multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) devices or peripherals, each of which have their own driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) The bridge driver exposes one or more V4L2 device nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) (see :ref:`v4l2_device_naming`).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) There are other drivers providing support for other components of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) the hardware, which may also expose device nodes, called V4L2 sub-devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) When such V4L2 sub-devices are exposed, they allow controlling those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) other hardware components - usually connected via a serial bus (like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) I²C, SMBus or SPI). Depending on the bridge driver, those sub-devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) can be controlled indirectly via the bridge driver or explicitly via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) the :ref:`Media Controller <media_controller>` and via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) :ref:`V4L2 sub-devices <subdev>`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) The devices that require the use of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) :ref:`Media Controller <media_controller>` are called **MC-centric**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) devices. The devices that are fully controlled via V4L2 device nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) are called **video-node-centric**.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) Userspace can check if a V4L2 hardware peripheral is MC-centric by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) calling :ref:`VIDIOC_QUERYCAP` and checking the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) :ref:`device_caps field <device-capabilities>`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) If the device returns ``V4L2_CAP_IO_MC`` flag at ``device_caps``,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) then it is MC-centric, otherwise, it is video-node-centric.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) It is required for MC-centric drivers to identify the V4L2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) sub-devices and to configure the pipelines via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) :ref:`media controller API <media_controller>` before using the peripheral.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) Also, the sub-devices' configuration shall be controlled via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) :ref:`sub-device API <subdev>`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) A video-node-centric may still provide media-controller and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) sub-device interfaces as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) However, in that case the media-controller and the sub-device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) interfaces are read-only and just provide information about the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) device. The actual configuration is done via the video nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .. _v4l2_device_naming:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) V4L2 Device Node Naming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) V4L2 drivers are implemented as kernel modules, loaded manually by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) system administrator or automatically when a device is first discovered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) The driver modules plug into the ``videodev`` kernel module. It provides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) helper functions and a common application interface specified in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) document.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) Each driver thus loaded registers one or more device nodes with major
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) number 81. Minor numbers are allocated dynamically unless the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) is compiled with the kernel option CONFIG_VIDEO_FIXED_MINOR_RANGES.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) In that case minor numbers are allocated in ranges depending on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) device node type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) The device nodes supported by the Video4Linux subsystem are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ======================== ====================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) Default device node name Usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ======================== ====================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ``/dev/videoX`` Video and metadata for capture/output devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ``/dev/vbiX`` Vertical blank data (i.e. closed captions, teletext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ``/dev/radioX`` Radio tuners and modulators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ``/dev/swradioX`` Software Defined Radio tuners and modulators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ``/dev/v4l-touchX`` Touch sensors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ``/dev/v4l-subdevX`` Video sub-devices (used by sensors and other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) components of the hardware peripheral)\ [#]_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ======================== ====================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) Where ``X`` is a non-negative integer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 1. The actual device node name is system-dependent, as udev rules may apply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 2. There is no guarantee that ``X`` will remain the same for the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) device, as the number depends on the device driver's probe order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) If you need an unique name, udev default rules produce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ``/dev/v4l/by-id/`` and ``/dev/v4l/by-path/`` directories containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) links that can be used uniquely to identify a V4L2 device node::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) $ tree /dev/v4l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /dev/v4l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ├── by-id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) │ └── usb-OmniVision._USB_Camera-B4.04.27.1-video-index0 -> ../../video0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) └── by-path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) └── pci-0000:00:14.0-usb-0:2:1.0-video-index0 -> ../../video0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .. [#] **V4L2 sub-device nodes** (e. g. ``/dev/v4l-subdevX``) use a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) set of system calls, as covered at :ref:`subdev`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) Many drivers support "video_nr", "radio_nr" or "vbi_nr" module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) options to select specific video/radio/vbi node numbers. This allows the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) user to request that the device node is named e.g. /dev/video5 instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) of leaving it to chance. When the driver supports multiple devices of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) the same type more than one device node number can be assigned,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) separated by commas:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .. code-block:: none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) # modprobe mydriver video_nr=0,1 radio_nr=0,1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) In ``/etc/modules.conf`` this may be written as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) options mydriver video_nr=0,1 radio_nr=0,1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) When no device node number is given as module option the driver supplies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) a default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) Normally udev will create the device nodes in /dev automatically for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) you. If udev is not installed, then you need to enable the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) CONFIG_VIDEO_FIXED_MINOR_RANGES kernel option in order to be able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) correctly relate a minor number to a device node number. I.e., you need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) to be certain that minor number 5 maps to device node name video5. With
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) this kernel option different device types have different minor number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ranges. These ranges are listed in :ref:`devices`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) The creation of character special files (with mknod) is a privileged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) operation and devices cannot be opened by major and minor number. That
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) means applications cannot *reliably* scan for loaded or installed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) drivers. The user must enter a device name, or the application can try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) the conventional device names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .. _related:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) Related Devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ===============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) Devices can support several functions. For example video capturing, VBI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) capturing and radio support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) The V4L2 API creates different V4L2 device nodes for each of these functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) The V4L2 API was designed with the idea that one device node could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) support all functions. However, in practice this never worked: this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 'feature' was never used by applications and many drivers did not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) support it and if they did it was certainly never tested. In addition,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) switching a device node between different functions only works when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) using the streaming I/O API, not with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) :c:func:`read()`/\ :c:func:`write()` API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) Today each V4L2 device node supports just one function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) Besides video input or output the hardware may also support audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) sampling or playback. If so, these functions are implemented as ALSA PCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) devices with optional ALSA audio mixer devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) One problem with all these devices is that the V4L2 API makes no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) provisions to find these related V4L2 device nodes. Some really complex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) hardware use the Media Controller (see :ref:`media_controller`) which can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) be used for this purpose. But several drivers do not use it, and while some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) code exists that uses sysfs to discover related V4L2 device nodes (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) libmedia_dev in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) `v4l-utils <http://git.linuxtv.org/cgit.cgi/v4l-utils.git/>`__ git
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) repository), there is no library yet that can provide a single API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) towards both Media Controller-based devices and devices that do not use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) the Media Controller. If you want to work on this please write to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) linux-media mailing list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) `https://linuxtv.org/lists.php <https://linuxtv.org/lists.php>`__.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) Multiple Opens
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) V4L2 devices can be opened more than once. [#f1]_ When this is supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) by the driver, users can for example start a "panel" application to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) change controls like brightness or audio volume, while another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) application captures video and audio. In other words, panel applications
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) are comparable to an ALSA audio mixer application. Just opening a V4L2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) device should not change the state of the device. [#f2]_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) Once an application has allocated the memory buffers needed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) streaming data (by calling the :ref:`VIDIOC_REQBUFS`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) or :ref:`VIDIOC_CREATE_BUFS` ioctls, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) implicitly by calling the :c:func:`read()` or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) :c:func:`write()` functions) that application (filehandle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) becomes the owner of the device. It is no longer allowed to make changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) that would affect the buffer sizes (e.g. by calling the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl) and other applications are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) no longer allowed to allocate buffers or start or stop streaming. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) EBUSY error code will be returned instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) Merely opening a V4L2 device does not grant exclusive access. [#f3]_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) Initiating data exchange however assigns the right to read or write the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) requested type of data, and to change related properties, to this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) descriptor. Applications can request additional access privileges using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) the priority mechanism described in :ref:`app-pri`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) Shared Data Streams
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ===================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) V4L2 drivers should not support multiple applications reading or writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) the same data stream on a device by copying buffers, time multiplexing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) or similar means. This is better handled by a proxy application in user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) Functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) To open and close V4L2 devices applications use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) :c:func:`open()` and :c:func:`close()` function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) respectively. Devices are programmed using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) :ref:`ioctl() <func-ioctl>` function as explained in the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) sections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .. [#f1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) There are still some old and obscure drivers that have not been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) updated to allow for multiple opens. This implies that for such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) drivers :c:func:`open()` can return an ``EBUSY`` error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) when the device is already in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .. [#f2]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) Unfortunately, opening a radio device often switches the state of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) device to radio mode in many drivers. This behavior should be fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) eventually as it violates the V4L2 specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .. [#f3]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) Drivers could recognize the ``O_EXCL`` open flag. Presently this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) not required, so applications cannot know if it really works.