standard.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _standard:
  4. ***************
  5. Video Standards
  6. ***************
  7. Video devices typically support one or more different video standards or
  8. variations of standards. Each video input and output may support another
  9. set of standards. This set is reported by the ``std`` field of struct
  10. :c:type:`v4l2_input` and struct
  11. :c:type:`v4l2_output` returned by the
  12. :ref:`VIDIOC_ENUMINPUT` and
  13. :ref:`VIDIOC_ENUMOUTPUT` ioctls, respectively.
  14. V4L2 defines one bit for each analog video standard currently in use
  15. worldwide, and sets aside bits for driver defined standards, e. g.
  16. hybrid standards to watch NTSC video tapes on PAL TVs and vice versa.
  17. Applications can use the predefined bits to select a particular
  18. standard, although presenting the user a menu of supported standards is
  19. preferred. To enumerate and query the attributes of the supported
  20. standards applications use the :ref:`VIDIOC_ENUMSTD`
  21. ioctl.
  22. Many of the defined standards are actually just variations of a few
  23. major standards. The hardware may in fact not distinguish between them,
  24. or do so internal and switch automatically. Therefore enumerated
  25. standards also contain sets of one or more standard bits.
  26. Assume a hypothetic tuner capable of demodulating B/PAL, G/PAL and I/PAL
  27. signals. The first enumerated standard is a set of B and G/PAL, switched
  28. automatically depending on the selected radio frequency in UHF or VHF
  29. band. Enumeration gives a "PAL-B/G" or "PAL-I" choice. Similar a
  30. Composite input may collapse standards, enumerating "PAL-B/G/H/I",
  31. "NTSC-M" and "SECAM-D/K". [#f1]_
  32. To query and select the standard used by the current video input or
  33. output applications call the :ref:`VIDIOC_G_STD <VIDIOC_G_STD>` and
  34. :ref:`VIDIOC_S_STD <VIDIOC_G_STD>` ioctl, respectively. The
  35. *received* standard can be sensed with the
  36. :ref:`VIDIOC_QUERYSTD` ioctl.
  37. .. note::
  38. The parameter of all these ioctls is a pointer to a
  39. :ref:`v4l2_std_id <v4l2-std-id>` type (a standard set), *not* an
  40. index into the standard enumeration. Drivers must implement all video
  41. standard ioctls when the device has one or more video inputs or outputs.
  42. Special rules apply to devices such as USB cameras where the notion of
  43. video standards makes little sense. More generally for any capture or
  44. output device which is:
  45. - incapable of capturing fields or frames at the nominal rate of the
  46. video standard, or
  47. - that does not support the video standard formats at all.
  48. Here the driver shall set the ``std`` field of struct
  49. :c:type:`v4l2_input` and struct
  50. :c:type:`v4l2_output` to zero and the :ref:`VIDIOC_G_STD <VIDIOC_G_STD>`,
  51. :ref:`VIDIOC_S_STD <VIDIOC_G_STD>`, :ref:`VIDIOC_QUERYSTD` and :ref:`VIDIOC_ENUMSTD` ioctls
  52. shall return the ``ENOTTY`` error code or the ``EINVAL`` error code.
  53. Applications can make use of the :ref:`input-capabilities` and
  54. :ref:`output-capabilities` flags to determine whether the video
  55. standard ioctls can be used with the given input or output.
  56. Example: Information about the current video standard
  57. =====================================================
  58. .. code-block:: c
  59. v4l2_std_id std_id;
  60. struct v4l2_standard standard;
  61. if (-1 == ioctl(fd, VIDIOC_G_STD, &std_id)) {
  62. /* Note when VIDIOC_ENUMSTD always returns ENOTTY this
  63. is no video device or it falls under the USB exception,
  64. and VIDIOC_G_STD returning ENOTTY is no error. */
  65. perror("VIDIOC_G_STD");
  66. exit(EXIT_FAILURE);
  67. }
  68. memset(&standard, 0, sizeof(standard));
  69. standard.index = 0;
  70. while (0 == ioctl(fd, VIDIOC_ENUMSTD, &standard)) {
  71. if (standard.id & std_id) {
  72. printf("Current video standard: %s\\n", standard.name);
  73. exit(EXIT_SUCCESS);
  74. }
  75. standard.index++;
  76. }
  77. /* EINVAL indicates the end of the enumeration, which cannot be
  78. empty unless this device falls under the USB exception. */
  79. if (errno == EINVAL || standard.index == 0) {
  80. perror("VIDIOC_ENUMSTD");
  81. exit(EXIT_FAILURE);
  82. }
  83. Example: Listing the video standards supported by the current input
  84. ===================================================================
  85. .. code-block:: c
  86. struct v4l2_input input;
  87. struct v4l2_standard standard;
  88. memset(&input, 0, sizeof(input));
  89. if (-1 == ioctl(fd, VIDIOC_G_INPUT, &input.index)) {
  90. perror("VIDIOC_G_INPUT");
  91. exit(EXIT_FAILURE);
  92. }
  93. if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
  94. perror("VIDIOC_ENUM_INPUT");
  95. exit(EXIT_FAILURE);
  96. }
  97. printf("Current input %s supports:\\n", input.name);
  98. memset(&standard, 0, sizeof(standard));
  99. standard.index = 0;
  100. while (0 == ioctl(fd, VIDIOC_ENUMSTD, &standard)) {
  101. if (standard.id & input.std)
  102. printf("%s\\n", standard.name);
  103. standard.index++;
  104. }
  105. /* EINVAL indicates the end of the enumeration, which cannot be
  106. empty unless this device falls under the USB exception. */
  107. if (errno != EINVAL || standard.index == 0) {
  108. perror("VIDIOC_ENUMSTD");
  109. exit(EXIT_FAILURE);
  110. }
  111. Example: Selecting a new video standard
  112. =======================================
  113. .. code-block:: c
  114. struct v4l2_input input;
  115. v4l2_std_id std_id;
  116. memset(&input, 0, sizeof(input));
  117. if (-1 == ioctl(fd, VIDIOC_G_INPUT, &input.index)) {
  118. perror("VIDIOC_G_INPUT");
  119. exit(EXIT_FAILURE);
  120. }
  121. if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
  122. perror("VIDIOC_ENUM_INPUT");
  123. exit(EXIT_FAILURE);
  124. }
  125. if (0 == (input.std & V4L2_STD_PAL_BG)) {
  126. fprintf(stderr, "Oops. B/G PAL is not supported.\\n");
  127. exit(EXIT_FAILURE);
  128. }
  129. /* Note this is also supposed to work when only B
  130. or G/PAL is supported. */
  131. std_id = V4L2_STD_PAL_BG;
  132. if (-1 == ioctl(fd, VIDIOC_S_STD, &std_id)) {
  133. perror("VIDIOC_S_STD");
  134. exit(EXIT_FAILURE);
  135. }
  136. .. [#f1]
  137. Some users are already confused by technical terms PAL, NTSC and
  138. SECAM. There is no point asking them to distinguish between B, G, D,
  139. or K when the software or hardware can do that automatically.