format.rst 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _format:
  4. ************
  5. Data Formats
  6. ************
  7. Data Format Negotiation
  8. =======================
  9. Different devices exchange different kinds of data with applications,
  10. for example video images, raw or sliced VBI data, RDS datagrams. Even
  11. within one kind many different formats are possible, in particular there is an
  12. abundance of image formats. Although drivers must provide a default and
  13. the selection persists across closing and reopening a device,
  14. applications should always negotiate a data format before engaging in
  15. data exchange. Negotiation means the application asks for a particular
  16. format and the driver selects and reports the best the hardware can do
  17. to satisfy the request. Of course applications can also just query the
  18. current selection.
  19. A single mechanism exists to negotiate all data formats using the
  20. aggregate struct :c:type:`v4l2_format` and the
  21. :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
  22. :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctls. Additionally the
  23. :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to examine
  24. what the hardware *could* do, without actually selecting a new data
  25. format. The data formats supported by the V4L2 API are covered in the
  26. respective device section in :ref:`devices`. For a closer look at
  27. image formats see :ref:`pixfmt`.
  28. The :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl is a major turning-point in the
  29. initialization sequence. Prior to this point multiple panel applications
  30. can access the same device concurrently to select the current input,
  31. change controls or modify other properties. The first :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
  32. assigns a logical stream (video data, VBI data etc.) exclusively to one
  33. file descriptor.
  34. Exclusive means no other application, more precisely no other file
  35. descriptor, can grab this stream or change device properties
  36. inconsistent with the negotiated parameters. A video standard change for
  37. example, when the new standard uses a different number of scan lines,
  38. can invalidate the selected image format. Therefore only the file
  39. descriptor owning the stream can make invalidating changes. Accordingly
  40. multiple file descriptors which grabbed different logical streams
  41. prevent each other from interfering with their settings. When for
  42. example video overlay is about to start or already in progress,
  43. simultaneous video capturing may be restricted to the same cropping and
  44. image size.
  45. When applications omit the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl its locking side
  46. effects are implied by the next step, the selection of an I/O method
  47. with the :ref:`VIDIOC_REQBUFS` ioctl or implicit
  48. with the first :c:func:`read()` or
  49. :c:func:`write()` call.
  50. Generally only one logical stream can be assigned to a file descriptor,
  51. the exception being drivers permitting simultaneous video capturing and
  52. overlay using the same file descriptor for compatibility with V4L and
  53. earlier versions of V4L2. Switching the logical stream or returning into
  54. "panel mode" is possible by closing and reopening the device. Drivers
  55. *may* support a switch using :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`.
  56. All drivers exchanging data with applications must support the
  57. :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. Implementation of the
  58. :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is highly recommended but optional.
  59. Image Format Enumeration
  60. ========================
  61. Apart of the generic format negotiation functions a special ioctl to
  62. enumerate all image formats supported by video capture, overlay or
  63. output devices is available. [#f1]_
  64. The :ref:`VIDIOC_ENUM_FMT` ioctl must be supported
  65. by all drivers exchanging image data with applications.
  66. .. important::
  67. Drivers are not supposed to convert image formats in kernel space.
  68. They must enumerate only formats directly supported by the hardware.
  69. If necessary driver writers should publish an example conversion
  70. routine or library for integration into applications.
  71. .. [#f1]
  72. Enumerating formats an application has no a-priori knowledge of
  73. (otherwise it could explicitly ask for them and need not enumerate)
  74. seems useless, but there are applications serving as proxy between
  75. drivers and the actual video applications for which this is useful.