18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _diff-v4l:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci********************************
78c2ecf20Sopenharmony_ciDifferences between V4L and V4L2
88c2ecf20Sopenharmony_ci********************************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciThe Video For Linux API was first introduced in Linux 2.1 to unify and
118c2ecf20Sopenharmony_cireplace various TV and radio device related interfaces, developed
128c2ecf20Sopenharmony_ciindependently by driver writers in prior years. Starting with Linux 2.5
138c2ecf20Sopenharmony_cithe much improved V4L2 API replaces the V4L API. The support for the old
148c2ecf20Sopenharmony_ciV4L calls were removed from Kernel, but the library :ref:`libv4l`
158c2ecf20Sopenharmony_cisupports the conversion of a V4L API system call into a V4L2 one.
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ciOpening and Closing Devices
188c2ecf20Sopenharmony_ci===========================
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciFor compatibility reasons the character device file names recommended
218c2ecf20Sopenharmony_cifor V4L2 video capture, overlay, radio and raw vbi capture devices did
228c2ecf20Sopenharmony_cinot change from those used by V4L. They are listed in :ref:`devices`
238c2ecf20Sopenharmony_ciand below in :ref:`v4l-dev`.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciThe teletext devices (minor range 192-223) have been removed in V4L2 and
268c2ecf20Sopenharmony_cino longer exist. There is no hardware available anymore for handling
278c2ecf20Sopenharmony_cipure teletext. Instead raw or sliced VBI is used.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciThe V4L ``videodev`` module automatically assigns minor numbers to
308c2ecf20Sopenharmony_cidrivers in load order, depending on the registered device type. We
318c2ecf20Sopenharmony_cirecommend that V4L2 drivers by default register devices with the same
328c2ecf20Sopenharmony_cinumbers, but the system administrator can assign arbitrary minor numbers
338c2ecf20Sopenharmony_ciusing driver module options. The major device number remains 81.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci.. _v4l-dev:
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci.. flat-table:: V4L Device Types, Names and Numbers
388c2ecf20Sopenharmony_ci    :header-rows:  1
398c2ecf20Sopenharmony_ci    :stub-columns: 0
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci    * - Device Type
428c2ecf20Sopenharmony_ci      - File Name
438c2ecf20Sopenharmony_ci      - Minor Numbers
448c2ecf20Sopenharmony_ci    * - Video capture and overlay
458c2ecf20Sopenharmony_ci      - ``/dev/video`` and ``/dev/bttv0``\  [#f1]_, ``/dev/video0`` to
468c2ecf20Sopenharmony_ci	``/dev/video63``
478c2ecf20Sopenharmony_ci      - 0-63
488c2ecf20Sopenharmony_ci    * - Radio receiver
498c2ecf20Sopenharmony_ci      - ``/dev/radio``\  [#f2]_, ``/dev/radio0`` to ``/dev/radio63``
508c2ecf20Sopenharmony_ci      - 64-127
518c2ecf20Sopenharmony_ci    * - Raw VBI capture
528c2ecf20Sopenharmony_ci      - ``/dev/vbi``, ``/dev/vbi0`` to ``/dev/vbi31``
538c2ecf20Sopenharmony_ci      - 224-255
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciV4L prohibits (or used to prohibit) multiple opens of a device file.
568c2ecf20Sopenharmony_ciV4L2 drivers *may* support multiple opens, see :ref:`open` for details
578c2ecf20Sopenharmony_ciand consequences.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciV4L drivers respond to V4L2 ioctls with an ``EINVAL`` error code.
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciQuerying Capabilities
628c2ecf20Sopenharmony_ci=====================
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciThe V4L ``VIDIOCGCAP`` ioctl is equivalent to V4L2's
658c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCAP`.
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciThe ``name`` field in struct ``video_capability`` became
688c2ecf20Sopenharmony_ci``card`` in struct :c:type:`v4l2_capability`, ``type``
698c2ecf20Sopenharmony_ciwas replaced by ``capabilities``. Note V4L2 does not distinguish between
708c2ecf20Sopenharmony_cidevice types like this, better think of basic video input, video output
718c2ecf20Sopenharmony_ciand radio devices supporting a set of related functions like video
728c2ecf20Sopenharmony_cicapturing, video overlay and VBI capturing. See :ref:`open` for an
738c2ecf20Sopenharmony_ciintroduction.
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{5.5cm}|p{6.5cm}|p{5.5cm}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci.. cssclass:: longtable
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci.. flat-table::
808c2ecf20Sopenharmony_ci    :header-rows:  1
818c2ecf20Sopenharmony_ci    :stub-columns: 0
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci    * - ``struct video_capability`` ``type``
848c2ecf20Sopenharmony_ci      - struct :c:type:`v4l2_capability`
858c2ecf20Sopenharmony_ci	``capabilities`` flags
868c2ecf20Sopenharmony_ci      - Purpose
878c2ecf20Sopenharmony_ci    * - ``VID_TYPE_CAPTURE``
888c2ecf20Sopenharmony_ci      - ``V4L2_CAP_VIDEO_CAPTURE``
898c2ecf20Sopenharmony_ci      - The :ref:`video capture <capture>` interface is supported.
908c2ecf20Sopenharmony_ci    * - ``VID_TYPE_TUNER``
918c2ecf20Sopenharmony_ci      - ``V4L2_CAP_TUNER``
928c2ecf20Sopenharmony_ci      - The device has a :ref:`tuner or modulator <tuner>`.
938c2ecf20Sopenharmony_ci    * - ``VID_TYPE_TELETEXT``
948c2ecf20Sopenharmony_ci      - ``V4L2_CAP_VBI_CAPTURE``
958c2ecf20Sopenharmony_ci      - The :ref:`raw VBI capture <raw-vbi>` interface is supported.
968c2ecf20Sopenharmony_ci    * - ``VID_TYPE_OVERLAY``
978c2ecf20Sopenharmony_ci      - ``V4L2_CAP_VIDEO_OVERLAY``
988c2ecf20Sopenharmony_ci      - The :ref:`video overlay <overlay>` interface is supported.
998c2ecf20Sopenharmony_ci    * - ``VID_TYPE_CHROMAKEY``
1008c2ecf20Sopenharmony_ci      - ``V4L2_FBUF_CAP_CHROMAKEY`` in field ``capability`` of struct
1018c2ecf20Sopenharmony_ci	:c:type:`v4l2_framebuffer`
1028c2ecf20Sopenharmony_ci      - Whether chromakey overlay is supported. For more information on
1038c2ecf20Sopenharmony_ci	overlay see :ref:`overlay`.
1048c2ecf20Sopenharmony_ci    * - ``VID_TYPE_CLIPPING``
1058c2ecf20Sopenharmony_ci      - ``V4L2_FBUF_CAP_LIST_CLIPPING`` and
1068c2ecf20Sopenharmony_ci	``V4L2_FBUF_CAP_BITMAP_CLIPPING`` in field ``capability`` of
1078c2ecf20Sopenharmony_ci	struct :c:type:`v4l2_framebuffer`
1088c2ecf20Sopenharmony_ci      - Whether clipping the overlaid image is supported, see
1098c2ecf20Sopenharmony_ci	:ref:`overlay`.
1108c2ecf20Sopenharmony_ci    * - ``VID_TYPE_FRAMERAM``
1118c2ecf20Sopenharmony_ci      - ``V4L2_FBUF_CAP_EXTERNOVERLAY`` *not set* in field ``capability``
1128c2ecf20Sopenharmony_ci	of struct :c:type:`v4l2_framebuffer`
1138c2ecf20Sopenharmony_ci      - Whether overlay overwrites frame buffer memory, see
1148c2ecf20Sopenharmony_ci	:ref:`overlay`.
1158c2ecf20Sopenharmony_ci    * - ``VID_TYPE_SCALES``
1168c2ecf20Sopenharmony_ci      - ``-``
1178c2ecf20Sopenharmony_ci      - This flag indicates if the hardware can scale images. The V4L2 API
1188c2ecf20Sopenharmony_ci	implies the scale factor by setting the cropping dimensions and
1198c2ecf20Sopenharmony_ci	image size with the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` and
1208c2ecf20Sopenharmony_ci	:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, respectively. The
1218c2ecf20Sopenharmony_ci	driver returns the closest sizes possible. For more information on
1228c2ecf20Sopenharmony_ci	cropping and scaling see :ref:`crop`.
1238c2ecf20Sopenharmony_ci    * - ``VID_TYPE_MONOCHROME``
1248c2ecf20Sopenharmony_ci      - ``-``
1258c2ecf20Sopenharmony_ci      - Applications can enumerate the supported image formats with the
1268c2ecf20Sopenharmony_ci	:ref:`VIDIOC_ENUM_FMT` ioctl to determine if
1278c2ecf20Sopenharmony_ci	the device supports grey scale capturing only. For more
1288c2ecf20Sopenharmony_ci	information on image formats see :ref:`pixfmt`.
1298c2ecf20Sopenharmony_ci    * - ``VID_TYPE_SUBCAPTURE``
1308c2ecf20Sopenharmony_ci      - ``-``
1318c2ecf20Sopenharmony_ci      - Applications can call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>`
1328c2ecf20Sopenharmony_ci	ioctl to determine if the device supports capturing a subsection
1338c2ecf20Sopenharmony_ci	of the full picture ("cropping" in V4L2). If not, the ioctl
1348c2ecf20Sopenharmony_ci	returns the ``EINVAL`` error code. For more information on cropping
1358c2ecf20Sopenharmony_ci	and scaling see :ref:`crop`.
1368c2ecf20Sopenharmony_ci    * - ``VID_TYPE_MPEG_DECODER``
1378c2ecf20Sopenharmony_ci      - ``-``
1388c2ecf20Sopenharmony_ci      - Applications can enumerate the supported image formats with the
1398c2ecf20Sopenharmony_ci	:ref:`VIDIOC_ENUM_FMT` ioctl to determine if
1408c2ecf20Sopenharmony_ci	the device supports MPEG streams.
1418c2ecf20Sopenharmony_ci    * - ``VID_TYPE_MPEG_ENCODER``
1428c2ecf20Sopenharmony_ci      - ``-``
1438c2ecf20Sopenharmony_ci      - See above.
1448c2ecf20Sopenharmony_ci    * - ``VID_TYPE_MJPEG_DECODER``
1458c2ecf20Sopenharmony_ci      - ``-``
1468c2ecf20Sopenharmony_ci      - See above.
1478c2ecf20Sopenharmony_ci    * - ``VID_TYPE_MJPEG_ENCODER``
1488c2ecf20Sopenharmony_ci      - ``-``
1498c2ecf20Sopenharmony_ci      - See above.
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ciThe ``audios`` field was replaced by ``capabilities`` flag
1528c2ecf20Sopenharmony_ci``V4L2_CAP_AUDIO``, indicating *if* the device has any audio inputs or
1538c2ecf20Sopenharmony_cioutputs. To determine their number applications can enumerate audio
1548c2ecf20Sopenharmony_ciinputs with the :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` ioctl. The
1558c2ecf20Sopenharmony_ciaudio ioctls are described in :ref:`audio`.
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ciThe ``maxwidth``, ``maxheight``, ``minwidth`` and ``minheight`` fields
1588c2ecf20Sopenharmony_ciwere removed. Calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
1598c2ecf20Sopenharmony_ci:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl with the desired
1608c2ecf20Sopenharmony_cidimensions returns the closest size possible, taking into account the
1618c2ecf20Sopenharmony_cicurrent video standard, cropping and scaling limitations.
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciVideo Sources
1648c2ecf20Sopenharmony_ci=============
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciV4L provides the ``VIDIOCGCHAN`` and ``VIDIOCSCHAN`` ioctl using struct
1678c2ecf20Sopenharmony_ci``video_channel`` to enumerate the video inputs of a V4L
1688c2ecf20Sopenharmony_cidevice. The equivalent V4L2 ioctls are
1698c2ecf20Sopenharmony_ci:ref:`VIDIOC_ENUMINPUT`,
1708c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
1718c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` using struct
1728c2ecf20Sopenharmony_ci:c:type:`v4l2_input` as discussed in :ref:`video`.
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ciThe ``channel`` field counting inputs was renamed to ``index``, the
1758c2ecf20Sopenharmony_civideo input types were renamed as follows:
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci.. flat-table::
1798c2ecf20Sopenharmony_ci    :header-rows:  1
1808c2ecf20Sopenharmony_ci    :stub-columns: 0
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci    * - struct ``video_channel`` ``type``
1838c2ecf20Sopenharmony_ci      - struct :c:type:`v4l2_input` ``type``
1848c2ecf20Sopenharmony_ci    * - ``VIDEO_TYPE_TV``
1858c2ecf20Sopenharmony_ci      - ``V4L2_INPUT_TYPE_TUNER``
1868c2ecf20Sopenharmony_ci    * - ``VIDEO_TYPE_CAMERA``
1878c2ecf20Sopenharmony_ci      - ``V4L2_INPUT_TYPE_CAMERA``
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ciUnlike the ``tuners`` field expressing the number of tuners of this
1908c2ecf20Sopenharmony_ciinput, V4L2 assumes each video input is connected to at most one tuner.
1918c2ecf20Sopenharmony_ciHowever a tuner can have more than one input, i. e. RF connectors, and a
1928c2ecf20Sopenharmony_cidevice can have multiple tuners. The index number of the tuner
1938c2ecf20Sopenharmony_ciassociated with the input, if any, is stored in field ``tuner`` of
1948c2ecf20Sopenharmony_cistruct :c:type:`v4l2_input`. Enumeration of tuners is
1958c2ecf20Sopenharmony_cidiscussed in :ref:`tuner`.
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ciThe redundant ``VIDEO_VC_TUNER`` flag was dropped. Video inputs
1988c2ecf20Sopenharmony_ciassociated with a tuner are of type ``V4L2_INPUT_TYPE_TUNER``. The
1998c2ecf20Sopenharmony_ci``VIDEO_VC_AUDIO`` flag was replaced by the ``audioset`` field. V4L2
2008c2ecf20Sopenharmony_ciconsiders devices with up to 32 audio inputs. Each set bit in the
2018c2ecf20Sopenharmony_ci``audioset`` field represents one audio input this video input combines
2028c2ecf20Sopenharmony_ciwith. For information about audio inputs and how to switch between them
2038c2ecf20Sopenharmony_cisee :ref:`audio`.
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ciThe ``norm`` field describing the supported video standards was replaced
2068c2ecf20Sopenharmony_ciby ``std``. The V4L specification mentions a flag ``VIDEO_VC_NORM``
2078c2ecf20Sopenharmony_ciindicating whether the standard can be changed. This flag was a later
2088c2ecf20Sopenharmony_ciaddition together with the ``norm`` field and has been removed in the
2098c2ecf20Sopenharmony_cimeantime. V4L2 has a similar, albeit more comprehensive approach to
2108c2ecf20Sopenharmony_civideo standards, see :ref:`standard` for more information.
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ciTuning
2138c2ecf20Sopenharmony_ci======
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ciThe V4L ``VIDIOCGTUNER`` and ``VIDIOCSTUNER`` ioctl and struct
2168c2ecf20Sopenharmony_ci``video_tuner`` can be used to enumerate the tuners of a
2178c2ecf20Sopenharmony_ciV4L TV or radio device. The equivalent V4L2 ioctls are
2188c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_TUNER <VIDIOC_G_TUNER>` and
2198c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_TUNER <VIDIOC_G_TUNER>` using struct
2208c2ecf20Sopenharmony_ci:c:type:`v4l2_tuner`. Tuners are covered in :ref:`tuner`.
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ciThe ``tuner`` field counting tuners was renamed to ``index``. The fields
2238c2ecf20Sopenharmony_ci``name``, ``rangelow`` and ``rangehigh`` remained unchanged.
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ciThe ``VIDEO_TUNER_PAL``, ``VIDEO_TUNER_NTSC`` and ``VIDEO_TUNER_SECAM``
2268c2ecf20Sopenharmony_ciflags indicating the supported video standards were dropped. This
2278c2ecf20Sopenharmony_ciinformation is now contained in the associated struct
2288c2ecf20Sopenharmony_ci:c:type:`v4l2_input`. No replacement exists for the
2298c2ecf20Sopenharmony_ci``VIDEO_TUNER_NORM`` flag indicating whether the video standard can be
2308c2ecf20Sopenharmony_ciswitched. The ``mode`` field to select a different video standard was
2318c2ecf20Sopenharmony_cireplaced by a whole new set of ioctls and structures described in
2328c2ecf20Sopenharmony_ci:ref:`standard`. Due to its ubiquity it should be mentioned the BTTV
2338c2ecf20Sopenharmony_cidriver supports several standards in addition to the regular
2348c2ecf20Sopenharmony_ci``VIDEO_MODE_PAL`` (0), ``VIDEO_MODE_NTSC``, ``VIDEO_MODE_SECAM`` and
2358c2ecf20Sopenharmony_ci``VIDEO_MODE_AUTO`` (3). Namely N/PAL Argentina, M/PAL, N/PAL, and NTSC
2368c2ecf20Sopenharmony_ciJapan with numbers 3-6 (sic).
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ciThe ``VIDEO_TUNER_STEREO_ON`` flag indicating stereo reception became
2398c2ecf20Sopenharmony_ci``V4L2_TUNER_SUB_STEREO`` in field ``rxsubchans``. This field also
2408c2ecf20Sopenharmony_cipermits the detection of monaural and bilingual audio, see the
2418c2ecf20Sopenharmony_cidefinition of struct :c:type:`v4l2_tuner` for details.
2428c2ecf20Sopenharmony_ciPresently no replacement exists for the ``VIDEO_TUNER_RDS_ON`` and
2438c2ecf20Sopenharmony_ci``VIDEO_TUNER_MBS_ON`` flags.
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ciThe ``VIDEO_TUNER_LOW`` flag was renamed to ``V4L2_TUNER_CAP_LOW`` in
2468c2ecf20Sopenharmony_cithe struct :c:type:`v4l2_tuner` ``capability`` field.
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ciThe ``VIDIOCGFREQ`` and ``VIDIOCSFREQ`` ioctl to change the tuner
2498c2ecf20Sopenharmony_cifrequency where renamed to
2508c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FREQUENCY <VIDIOC_G_FREQUENCY>` and
2518c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FREQUENCY <VIDIOC_G_FREQUENCY>`. They take a pointer
2528c2ecf20Sopenharmony_cito a struct :c:type:`v4l2_frequency` instead of an
2538c2ecf20Sopenharmony_ciunsigned long integer.
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci.. _v4l-image-properties:
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ciImage Properties
2588c2ecf20Sopenharmony_ci================
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ciV4L2 has no equivalent of the ``VIDIOCGPICT`` and ``VIDIOCSPICT`` ioctl
2618c2ecf20Sopenharmony_ciand struct ``video_picture``. The following fields where
2628c2ecf20Sopenharmony_cireplaced by V4L2 controls accessible with the
2638c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCTRL`,
2648c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` and
2658c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` ioctls:
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci.. flat-table::
2698c2ecf20Sopenharmony_ci    :header-rows:  1
2708c2ecf20Sopenharmony_ci    :stub-columns: 0
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci    * - struct ``video_picture``
2738c2ecf20Sopenharmony_ci      - V4L2 Control ID
2748c2ecf20Sopenharmony_ci    * - ``brightness``
2758c2ecf20Sopenharmony_ci      - ``V4L2_CID_BRIGHTNESS``
2768c2ecf20Sopenharmony_ci    * - ``hue``
2778c2ecf20Sopenharmony_ci      - ``V4L2_CID_HUE``
2788c2ecf20Sopenharmony_ci    * - ``colour``
2798c2ecf20Sopenharmony_ci      - ``V4L2_CID_SATURATION``
2808c2ecf20Sopenharmony_ci    * - ``contrast``
2818c2ecf20Sopenharmony_ci      - ``V4L2_CID_CONTRAST``
2828c2ecf20Sopenharmony_ci    * - ``whiteness``
2838c2ecf20Sopenharmony_ci      - ``V4L2_CID_WHITENESS``
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ciThe V4L picture controls are assumed to range from 0 to 65535 with no
2868c2ecf20Sopenharmony_ciparticular reset value. The V4L2 API permits arbitrary limits and
2878c2ecf20Sopenharmony_cidefaults which can be queried with the
2888c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCTRL` ioctl. For general
2898c2ecf20Sopenharmony_ciinformation about controls see :ref:`control`.
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ciThe ``depth`` (average number of bits per pixel) of a video image is
2928c2ecf20Sopenharmony_ciimplied by the selected image format. V4L2 does not explicitly provide
2938c2ecf20Sopenharmony_cisuch information assuming applications recognizing the format are aware
2948c2ecf20Sopenharmony_ciof the image depth and others need not know. The ``palette`` field moved
2958c2ecf20Sopenharmony_ciinto the struct :c:type:`v4l2_pix_format`:
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci.. flat-table::
2998c2ecf20Sopenharmony_ci    :header-rows:  1
3008c2ecf20Sopenharmony_ci    :stub-columns: 0
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci    * - struct ``video_picture`` ``palette``
3038c2ecf20Sopenharmony_ci      - struct :c:type:`v4l2_pix_format` ``pixfmt``
3048c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_GREY``
3058c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_GREY <V4L2-PIX-FMT-GREY>`
3068c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_HI240``
3078c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_HI240 <pixfmt-reserved>` [#f3]_
3088c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_RGB565``
3098c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_RGB565 <pixfmt-rgb>`
3108c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_RGB555``
3118c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_RGB555 <pixfmt-rgb>`
3128c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_RGB24``
3138c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_BGR24 <pixfmt-rgb>`
3148c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_RGB32``
3158c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_BGR32 <pixfmt-rgb>` [#f4]_
3168c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV422``
3178c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_YUYV <V4L2-PIX-FMT-YUYV>`
3188c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUYV``\  [#f5]_
3198c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_YUYV <V4L2-PIX-FMT-YUYV>`
3208c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_UYVY``
3218c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_UYVY <V4L2-PIX-FMT-UYVY>`
3228c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV420``
3238c2ecf20Sopenharmony_ci      - None
3248c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV411``
3258c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_Y41P <V4L2-PIX-FMT-Y41P>` [#f6]_
3268c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_RAW``
3278c2ecf20Sopenharmony_ci      - None [#f7]_
3288c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV422P``
3298c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_YUV422P <V4L2-PIX-FMT-YUV422P>`
3308c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV411P``
3318c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_YUV411P <V4L2-PIX-FMT-YUV411P>` [#f8]_
3328c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV420P``
3338c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_YVU420 <V4L2-PIX-FMT-YVU420>`
3348c2ecf20Sopenharmony_ci    * - ``VIDEO_PALETTE_YUV410P``
3358c2ecf20Sopenharmony_ci      - :ref:`V4L2_PIX_FMT_YVU410 <V4L2-PIX-FMT-YVU410>`
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ciV4L2 image formats are defined in :ref:`pixfmt`. The image format can
3388c2ecf20Sopenharmony_cibe selected with the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ciAudio
3418c2ecf20Sopenharmony_ci=====
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ciThe ``VIDIOCGAUDIO`` and ``VIDIOCSAUDIO`` ioctl and struct
3448c2ecf20Sopenharmony_ci``video_audio`` are used to enumerate the audio inputs
3458c2ecf20Sopenharmony_ciof a V4L device. The equivalent V4L2 ioctls are
3468c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
3478c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` using struct
3488c2ecf20Sopenharmony_ci:c:type:`v4l2_audio` as discussed in :ref:`audio`.
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ciThe ``audio`` "channel number" field counting audio inputs was renamed
3518c2ecf20Sopenharmony_cito ``index``.
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ciOn ``VIDIOCSAUDIO`` the ``mode`` field selects *one* of the
3548c2ecf20Sopenharmony_ci``VIDEO_SOUND_MONO``, ``VIDEO_SOUND_STEREO``, ``VIDEO_SOUND_LANG1`` or
3558c2ecf20Sopenharmony_ci``VIDEO_SOUND_LANG2`` audio demodulation modes. When the current audio
3568c2ecf20Sopenharmony_cistandard is BTSC ``VIDEO_SOUND_LANG2`` refers to SAP and
3578c2ecf20Sopenharmony_ci``VIDEO_SOUND_LANG1`` is meaningless. Also undocumented in the V4L
3588c2ecf20Sopenharmony_cispecification, there is no way to query the selected mode. On
3598c2ecf20Sopenharmony_ci``VIDIOCGAUDIO`` the driver returns the *actually received* audio
3608c2ecf20Sopenharmony_ciprogrammes in this field. In the V4L2 API this information is stored in
3618c2ecf20Sopenharmony_cithe struct :c:type:`v4l2_tuner` ``rxsubchans`` and
3628c2ecf20Sopenharmony_ci``audmode`` fields, respectively. See :ref:`tuner` for more
3638c2ecf20Sopenharmony_ciinformation on tuners. Related to audio modes struct
3648c2ecf20Sopenharmony_ci:c:type:`v4l2_audio` also reports if this is a mono or
3658c2ecf20Sopenharmony_cistereo input, regardless if the source is a tuner.
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ciThe following fields where replaced by V4L2 controls accessible with the
3688c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCTRL`,
3698c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` and
3708c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` ioctls:
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci.. flat-table::
3748c2ecf20Sopenharmony_ci    :header-rows:  1
3758c2ecf20Sopenharmony_ci    :stub-columns: 0
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci    * - struct ``video_audio``
3788c2ecf20Sopenharmony_ci      - V4L2 Control ID
3798c2ecf20Sopenharmony_ci    * - ``volume``
3808c2ecf20Sopenharmony_ci      - ``V4L2_CID_AUDIO_VOLUME``
3818c2ecf20Sopenharmony_ci    * - ``bass``
3828c2ecf20Sopenharmony_ci      - ``V4L2_CID_AUDIO_BASS``
3838c2ecf20Sopenharmony_ci    * - ``treble``
3848c2ecf20Sopenharmony_ci      - ``V4L2_CID_AUDIO_TREBLE``
3858c2ecf20Sopenharmony_ci    * - ``balance``
3868c2ecf20Sopenharmony_ci      - ``V4L2_CID_AUDIO_BALANCE``
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ciTo determine which of these controls are supported by a driver V4L
3898c2ecf20Sopenharmony_ciprovides the ``flags`` ``VIDEO_AUDIO_VOLUME``, ``VIDEO_AUDIO_BASS``,
3908c2ecf20Sopenharmony_ci``VIDEO_AUDIO_TREBLE`` and ``VIDEO_AUDIO_BALANCE``. In the V4L2 API the
3918c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCTRL` ioctl reports if the
3928c2ecf20Sopenharmony_cirespective control is supported. Accordingly the ``VIDEO_AUDIO_MUTABLE``
3938c2ecf20Sopenharmony_ciand ``VIDEO_AUDIO_MUTE`` flags where replaced by the boolean
3948c2ecf20Sopenharmony_ci``V4L2_CID_AUDIO_MUTE`` control.
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ciAll V4L2 controls have a ``step`` attribute replacing the struct
3978c2ecf20Sopenharmony_ci``video_audio`` ``step`` field. The V4L audio controls
3988c2ecf20Sopenharmony_ciare assumed to range from 0 to 65535 with no particular reset value. The
3998c2ecf20Sopenharmony_ciV4L2 API permits arbitrary limits and defaults which can be queried with
4008c2ecf20Sopenharmony_cithe :ref:`VIDIOC_QUERYCTRL` ioctl. For general
4018c2ecf20Sopenharmony_ciinformation about controls see :ref:`control`.
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ciFrame Buffer Overlay
4048c2ecf20Sopenharmony_ci====================
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ciThe V4L2 ioctls equivalent to ``VIDIOCGFBUF`` and ``VIDIOCSFBUF`` are
4078c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` and
4088c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>`. The ``base`` field of struct
4098c2ecf20Sopenharmony_ci``video_buffer`` remained unchanged, except V4L2 defines
4108c2ecf20Sopenharmony_cia flag to indicate non-destructive overlays instead of a ``NULL``
4118c2ecf20Sopenharmony_cipointer. All other fields moved into the struct
4128c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format` ``fmt`` substructure of
4138c2ecf20Sopenharmony_cistruct :c:type:`v4l2_framebuffer`. The ``depth``
4148c2ecf20Sopenharmony_cifield was replaced by ``pixelformat``. See :ref:`pixfmt-rgb` for a
4158c2ecf20Sopenharmony_cilist of RGB formats and their respective color depths.
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ciInstead of the special ioctls ``VIDIOCGWIN`` and ``VIDIOCSWIN`` V4L2
4188c2ecf20Sopenharmony_ciuses the general-purpose data format negotiation ioctls
4198c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
4208c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. They take a pointer to a struct
4218c2ecf20Sopenharmony_ci:c:type:`v4l2_format` as argument. Here the ``win`` member
4228c2ecf20Sopenharmony_ciof the ``fmt`` union is used, a struct
4238c2ecf20Sopenharmony_ci:c:type:`v4l2_window`.
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ciThe ``x``, ``y``, ``width`` and ``height`` fields of struct
4268c2ecf20Sopenharmony_ci``video_window`` moved into struct
4278c2ecf20Sopenharmony_ci:c:type:`v4l2_rect` substructure ``w`` of struct
4288c2ecf20Sopenharmony_ci:c:type:`v4l2_window`. The ``chromakey``, ``clips``, and
4298c2ecf20Sopenharmony_ci``clipcount`` fields remained unchanged. Struct
4308c2ecf20Sopenharmony_ci``video_clip`` was renamed to struct
4318c2ecf20Sopenharmony_ci:c:type:`v4l2_clip`, also containing a struct
4328c2ecf20Sopenharmony_ci:c:type:`v4l2_rect`, but the semantics are still the same.
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ciThe ``VIDEO_WINDOW_INTERLACE`` flag was dropped. Instead applications
4358c2ecf20Sopenharmony_cimust set the ``field`` field to ``V4L2_FIELD_ANY`` or
4368c2ecf20Sopenharmony_ci``V4L2_FIELD_INTERLACED``. The ``VIDEO_WINDOW_CHROMAKEY`` flag moved
4378c2ecf20Sopenharmony_ciinto struct :c:type:`v4l2_framebuffer`, under the new
4388c2ecf20Sopenharmony_ciname ``V4L2_FBUF_FLAG_CHROMAKEY``.
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ciIn V4L, storing a bitmap pointer in ``clips`` and setting ``clipcount``
4418c2ecf20Sopenharmony_cito ``VIDEO_CLIP_BITMAP`` (-1) requests bitmap clipping, using a fixed
4428c2ecf20Sopenharmony_cisize bitmap of 1024 × 625 bits. Struct :c:type:`v4l2_window`
4438c2ecf20Sopenharmony_cihas a separate ``bitmap`` pointer field for this purpose and the bitmap
4448c2ecf20Sopenharmony_cisize is determined by ``w.width`` and ``w.height``.
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ciThe ``VIDIOCCAPTURE`` ioctl to enable or disable overlay was renamed to
4478c2ecf20Sopenharmony_ci:ref:`VIDIOC_OVERLAY`.
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ciCropping
4508c2ecf20Sopenharmony_ci========
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ciTo capture only a subsection of the full picture V4L defines the
4538c2ecf20Sopenharmony_ci``VIDIOCGCAPTURE`` and ``VIDIOCSCAPTURE`` ioctls using struct
4548c2ecf20Sopenharmony_ci``video_capture``. The equivalent V4L2 ioctls are
4558c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and
4568c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` using struct
4578c2ecf20Sopenharmony_ci:c:type:`v4l2_crop`, and the related
4588c2ecf20Sopenharmony_ci:ref:`VIDIOC_CROPCAP` ioctl. This is a rather
4598c2ecf20Sopenharmony_cicomplex matter, see :ref:`crop` for details.
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ciThe ``x``, ``y``, ``width`` and ``height`` fields moved into struct
4628c2ecf20Sopenharmony_ci:c:type:`v4l2_rect` substructure ``c`` of struct
4638c2ecf20Sopenharmony_ci:c:type:`v4l2_crop`. The ``decimation`` field was dropped. In
4648c2ecf20Sopenharmony_cithe V4L2 API the scaling factor is implied by the size of the cropping
4658c2ecf20Sopenharmony_cirectangle and the size of the captured or overlaid image.
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ciThe ``VIDEO_CAPTURE_ODD`` and ``VIDEO_CAPTURE_EVEN`` flags to capture
4688c2ecf20Sopenharmony_cionly the odd or even field, respectively, were replaced by
4698c2ecf20Sopenharmony_ci``V4L2_FIELD_TOP`` and ``V4L2_FIELD_BOTTOM`` in the field named
4708c2ecf20Sopenharmony_ci``field`` of struct :c:type:`v4l2_pix_format` and
4718c2ecf20Sopenharmony_cistruct :c:type:`v4l2_window`. These structures are used to
4728c2ecf20Sopenharmony_ciselect a capture or overlay format with the
4738c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ciReading Images, Memory Mapping
4768c2ecf20Sopenharmony_ci==============================
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ciCapturing using the read method
4798c2ecf20Sopenharmony_ci-------------------------------
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ciThere is no essential difference between reading images from a V4L or
4828c2ecf20Sopenharmony_ciV4L2 device using the :c:func:`read()` function, however V4L2
4838c2ecf20Sopenharmony_cidrivers are not required to support this I/O method. Applications can
4848c2ecf20Sopenharmony_cidetermine if the function is available with the
4858c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. All V4L2 devices
4868c2ecf20Sopenharmony_ciexchanging data with applications must support the
4878c2ecf20Sopenharmony_ci:c:func:`select()` and :c:func:`poll()`
4888c2ecf20Sopenharmony_cifunctions.
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ciTo select an image format and size, V4L provides the ``VIDIOCSPICT`` and
4918c2ecf20Sopenharmony_ci``VIDIOCSWIN`` ioctls. V4L2 uses the general-purpose data format
4928c2ecf20Sopenharmony_cinegotiation ioctls :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
4938c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. They take a pointer to a struct
4948c2ecf20Sopenharmony_ci:c:type:`v4l2_format` as argument, here the struct
4958c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format` named ``pix`` of its
4968c2ecf20Sopenharmony_ci``fmt`` union is used.
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ciFor more information about the V4L2 read interface see :ref:`rw`.
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ciCapturing using memory mapping
5018c2ecf20Sopenharmony_ci------------------------------
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ciApplications can read from V4L devices by mapping buffers in device
5048c2ecf20Sopenharmony_cimemory, or more often just buffers allocated in DMA-able system memory,
5058c2ecf20Sopenharmony_ciinto their address space. This avoids the data copying overhead of the
5068c2ecf20Sopenharmony_ciread method. V4L2 supports memory mapping as well, with a few
5078c2ecf20Sopenharmony_cidifferences.
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci.. flat-table::
5118c2ecf20Sopenharmony_ci    :header-rows:  1
5128c2ecf20Sopenharmony_ci    :stub-columns: 0
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci    * - V4L
5158c2ecf20Sopenharmony_ci      - V4L2
5168c2ecf20Sopenharmony_ci    * -
5178c2ecf20Sopenharmony_ci      - The image format must be selected before buffers are allocated,
5188c2ecf20Sopenharmony_ci	with the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. When no
5198c2ecf20Sopenharmony_ci	format is selected the driver may use the last, possibly by
5208c2ecf20Sopenharmony_ci	another application requested format.
5218c2ecf20Sopenharmony_ci    * - Applications cannot change the number of buffers. The it is built
5228c2ecf20Sopenharmony_ci	into the driver, unless it has a module option to change the
5238c2ecf20Sopenharmony_ci	number when the driver module is loaded.
5248c2ecf20Sopenharmony_ci      - The :ref:`VIDIOC_REQBUFS` ioctl allocates the
5258c2ecf20Sopenharmony_ci	desired number of buffers, this is a required step in the
5268c2ecf20Sopenharmony_ci	initialization sequence.
5278c2ecf20Sopenharmony_ci    * - Drivers map all buffers as one contiguous range of memory. The
5288c2ecf20Sopenharmony_ci	``VIDIOCGMBUF`` ioctl is available to query the number of buffers,
5298c2ecf20Sopenharmony_ci	the offset of each buffer from the start of the virtual file, and
5308c2ecf20Sopenharmony_ci	the overall amount of memory used, which can be used as arguments
5318c2ecf20Sopenharmony_ci	for the :c:func:`mmap()` function.
5328c2ecf20Sopenharmony_ci      - Buffers are individually mapped. The offset and size of each
5338c2ecf20Sopenharmony_ci	buffer can be determined with the
5348c2ecf20Sopenharmony_ci	:ref:`VIDIOC_QUERYBUF` ioctl.
5358c2ecf20Sopenharmony_ci    * - The ``VIDIOCMCAPTURE`` ioctl prepares a buffer for capturing. It
5368c2ecf20Sopenharmony_ci	also determines the image format for this buffer. The ioctl
5378c2ecf20Sopenharmony_ci	returns immediately, eventually with an ``EAGAIN`` error code if no
5388c2ecf20Sopenharmony_ci	video signal had been detected. When the driver supports more than
5398c2ecf20Sopenharmony_ci	one buffer applications can call the ioctl multiple times and thus
5408c2ecf20Sopenharmony_ci	have multiple outstanding capture requests.
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci	The ``VIDIOCSYNC`` ioctl suspends execution until a particular
5438c2ecf20Sopenharmony_ci	buffer has been filled.
5448c2ecf20Sopenharmony_ci      - Drivers maintain an incoming and outgoing queue.
5458c2ecf20Sopenharmony_ci	:ref:`VIDIOC_QBUF` enqueues any empty buffer into
5468c2ecf20Sopenharmony_ci	the incoming queue. Filled buffers are dequeued from the outgoing
5478c2ecf20Sopenharmony_ci	queue with the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. To wait
5488c2ecf20Sopenharmony_ci	until filled buffers become available this function,
5498c2ecf20Sopenharmony_ci	:c:func:`select()` or :c:func:`poll()` can
5508c2ecf20Sopenharmony_ci	be used. The :ref:`VIDIOC_STREAMON` ioctl
5518c2ecf20Sopenharmony_ci	must be called once after enqueuing one or more buffers to start
5528c2ecf20Sopenharmony_ci	capturing. Its counterpart
5538c2ecf20Sopenharmony_ci	:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` stops capturing and
5548c2ecf20Sopenharmony_ci	dequeues all buffers from both queues. Applications can query the
5558c2ecf20Sopenharmony_ci	signal status, if known, with the
5568c2ecf20Sopenharmony_ci	:ref:`VIDIOC_ENUMINPUT` ioctl.
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ciFor a more in-depth discussion of memory mapping and examples, see
5598c2ecf20Sopenharmony_ci:ref:`mmap`.
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ciReading Raw VBI Data
5628c2ecf20Sopenharmony_ci====================
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ciOriginally the V4L API did not specify a raw VBI capture interface, only
5658c2ecf20Sopenharmony_cithe device file ``/dev/vbi`` was reserved for this purpose. The only
5668c2ecf20Sopenharmony_cidriver supporting this interface was the BTTV driver, de-facto defining
5678c2ecf20Sopenharmony_cithe V4L VBI interface. Reading from the device yields a raw VBI image
5688c2ecf20Sopenharmony_ciwith the following parameters:
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci.. flat-table::
5728c2ecf20Sopenharmony_ci    :header-rows:  1
5738c2ecf20Sopenharmony_ci    :stub-columns: 0
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_vbi_format`
5768c2ecf20Sopenharmony_ci      - V4L, BTTV driver
5778c2ecf20Sopenharmony_ci    * - sampling_rate
5788c2ecf20Sopenharmony_ci      - 28636363 Hz NTSC (or any other 525-line standard); 35468950 Hz PAL
5798c2ecf20Sopenharmony_ci	and SECAM (625-line standards)
5808c2ecf20Sopenharmony_ci    * - offset
5818c2ecf20Sopenharmony_ci      - ?
5828c2ecf20Sopenharmony_ci    * - samples_per_line
5838c2ecf20Sopenharmony_ci      - 2048
5848c2ecf20Sopenharmony_ci    * - sample_format
5858c2ecf20Sopenharmony_ci      - V4L2_PIX_FMT_GREY. The last four bytes (a machine endianness
5868c2ecf20Sopenharmony_ci	integer) contain a frame counter.
5878c2ecf20Sopenharmony_ci    * - start[]
5888c2ecf20Sopenharmony_ci      - 10, 273 NTSC; 22, 335 PAL and SECAM
5898c2ecf20Sopenharmony_ci    * - count[]
5908c2ecf20Sopenharmony_ci      - 16, 16 [#f9]_
5918c2ecf20Sopenharmony_ci    * - flags
5928c2ecf20Sopenharmony_ci      - 0
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ciUndocumented in the V4L specification, in Linux 2.3 the
5958c2ecf20Sopenharmony_ci``VIDIOCGVBIFMT`` and ``VIDIOCSVBIFMT`` ioctls using struct
5968c2ecf20Sopenharmony_ci``vbi_format`` were added to determine the VBI image
5978c2ecf20Sopenharmony_ciparameters. These ioctls are only partially compatible with the V4L2 VBI
5988c2ecf20Sopenharmony_ciinterface specified in :ref:`raw-vbi`.
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ciAn ``offset`` field does not exist, ``sample_format`` is supposed to be
6018c2ecf20Sopenharmony_ci``VIDEO_PALETTE_RAW``, equivalent to ``V4L2_PIX_FMT_GREY``. The
6028c2ecf20Sopenharmony_ciremaining fields are probably equivalent to struct
6038c2ecf20Sopenharmony_ci:c:type:`v4l2_vbi_format`.
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ciApparently only the Zoran (ZR 36120) driver implements these ioctls. The
6068c2ecf20Sopenharmony_cisemantics differ from those specified for V4L2 in two ways. The
6078c2ecf20Sopenharmony_ciparameters are reset on :c:func:`open()` and
6088c2ecf20Sopenharmony_ci``VIDIOCSVBIFMT`` always returns an ``EINVAL`` error code if the parameters
6098c2ecf20Sopenharmony_ciare invalid.
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ciMiscellaneous
6128c2ecf20Sopenharmony_ci=============
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ciV4L2 has no equivalent of the ``VIDIOCGUNIT`` ioctl. Applications can
6158c2ecf20Sopenharmony_cifind the VBI device associated with a video capture device (or vice
6168c2ecf20Sopenharmony_civersa) by reopening the device and requesting VBI data. For details see
6178c2ecf20Sopenharmony_ci:ref:`open`.
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ciNo replacement exists for ``VIDIOCKEY``, and the V4L functions for
6208c2ecf20Sopenharmony_cimicrocode programming. A new interface for MPEG compression and playback
6218c2ecf20Sopenharmony_cidevices is documented in :ref:`extended-controls`.
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci.. [#f1]
6248c2ecf20Sopenharmony_ci   According to Documentation/admin-guide/devices.rst these should be symbolic links
6258c2ecf20Sopenharmony_ci   to ``/dev/video0``. Note the original bttv interface is not
6268c2ecf20Sopenharmony_ci   compatible with V4L or V4L2.
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci.. [#f2]
6298c2ecf20Sopenharmony_ci   According to ``Documentation/admin-guide/devices.rst`` a symbolic link to
6308c2ecf20Sopenharmony_ci   ``/dev/radio0``.
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci.. [#f3]
6338c2ecf20Sopenharmony_ci   This is a custom format used by the BTTV driver, not one of the V4L2
6348c2ecf20Sopenharmony_ci   standard formats.
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ci.. [#f4]
6378c2ecf20Sopenharmony_ci   Presumably all V4L RGB formats are little-endian, although some
6388c2ecf20Sopenharmony_ci   drivers might interpret them according to machine endianness. V4L2
6398c2ecf20Sopenharmony_ci   defines little-endian, big-endian and red/blue swapped variants. For
6408c2ecf20Sopenharmony_ci   details see :ref:`pixfmt-rgb`.
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci.. [#f5]
6438c2ecf20Sopenharmony_ci   ``VIDEO_PALETTE_YUV422`` and ``VIDEO_PALETTE_YUYV`` are the same
6448c2ecf20Sopenharmony_ci   formats. Some V4L drivers respond to one, some to the other.
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci.. [#f6]
6478c2ecf20Sopenharmony_ci   Not to be confused with ``V4L2_PIX_FMT_YUV411P``, which is a planar
6488c2ecf20Sopenharmony_ci   format.
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci.. [#f7]
6518c2ecf20Sopenharmony_ci   V4L explains this as: "RAW capture (BT848)"
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci.. [#f8]
6548c2ecf20Sopenharmony_ci   Not to be confused with ``V4L2_PIX_FMT_Y41P``, which is a packed
6558c2ecf20Sopenharmony_ci   format.
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci.. [#f9]
6588c2ecf20Sopenharmony_ci   Old driver versions used different values, eventually the custom
6598c2ecf20Sopenharmony_ci   ``BTTV_VBISIZE`` ioctl was added to query the correct values.
660