2016-06-30 21:18:56 +08:00
|
|
|
.. -*- coding: utf-8; mode: rst -*-
|
|
|
|
|
|
|
|
.. _standard:
|
|
|
|
|
|
|
|
***************
|
|
|
|
Video Standards
|
|
|
|
***************
|
|
|
|
|
|
|
|
Video devices typically support one or more different video standards or
|
|
|
|
variations of standards. Each video input and output may support another
|
|
|
|
set of standards. This set is reported by the ``std`` field of struct
|
|
|
|
:ref:`v4l2_input <v4l2-input>` and struct
|
|
|
|
:ref:`v4l2_output <v4l2-output>` returned by the
|
2016-07-02 00:58:44 +08:00
|
|
|
:ref:`VIDIOC_ENUMINPUT` and
|
|
|
|
:ref:`VIDIOC_ENUMOUTPUT` ioctls, respectively.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
V4L2 defines one bit for each analog video standard currently in use
|
|
|
|
worldwide, and sets aside bits for driver defined standards, e. g.
|
|
|
|
hybrid standards to watch NTSC video tapes on PAL TVs and vice versa.
|
|
|
|
Applications can use the predefined bits to select a particular
|
|
|
|
standard, although presenting the user a menu of supported standards is
|
|
|
|
preferred. To enumerate and query the attributes of the supported
|
2016-07-02 00:58:44 +08:00
|
|
|
standards applications use the :ref:`VIDIOC_ENUMSTD`
|
2016-06-30 21:18:56 +08:00
|
|
|
ioctl.
|
|
|
|
|
|
|
|
Many of the defined standards are actually just variations of a few
|
|
|
|
major standards. The hardware may in fact not distinguish between them,
|
|
|
|
or do so internal and switch automatically. Therefore enumerated
|
|
|
|
standards also contain sets of one or more standard bits.
|
|
|
|
|
|
|
|
Assume a hypothetic tuner capable of demodulating B/PAL, G/PAL and I/PAL
|
|
|
|
signals. The first enumerated standard is a set of B and G/PAL, switched
|
|
|
|
automatically depending on the selected radio frequency in UHF or VHF
|
|
|
|
band. Enumeration gives a "PAL-B/G" or "PAL-I" choice. Similar a
|
|
|
|
Composite input may collapse standards, enumerating "PAL-B/G/H/I",
|
|
|
|
"NTSC-M" and "SECAM-D/K". [1]_
|
|
|
|
|
|
|
|
To query and select the standard used by the current video input or
|
2016-07-03 21:02:29 +08:00
|
|
|
output applications call the :ref:`VIDIOC_G_STD <VIDIOC_G_STD>` and
|
2016-07-02 00:42:29 +08:00
|
|
|
:ref:`VIDIOC_S_STD <VIDIOC_G_STD>` ioctl, respectively. The
|
2016-06-30 21:18:56 +08:00
|
|
|
*received* standard can be sensed with the
|
2016-07-02 00:58:44 +08:00
|
|
|
:ref:`VIDIOC_QUERYSTD` ioctl. Note that the
|
2016-06-30 21:18:56 +08:00
|
|
|
parameter of all these ioctls is a pointer to a
|
|
|
|
:ref:`v4l2_std_id <v4l2-std-id>` type (a standard set), *not* an
|
|
|
|
index into the standard enumeration. Drivers must implement all video
|
|
|
|
standard ioctls when the device has one or more video inputs or outputs.
|
|
|
|
|
|
|
|
Special rules apply to devices such as USB cameras where the notion of
|
|
|
|
video standards makes little sense. More generally for any capture or
|
|
|
|
output device which is:
|
|
|
|
|
|
|
|
- incapable of capturing fields or frames at the nominal rate of the
|
|
|
|
video standard, or
|
|
|
|
|
|
|
|
- that does not support the video standard formats at all.
|
|
|
|
|
|
|
|
Here the driver shall set the ``std`` field of struct
|
|
|
|
:ref:`v4l2_input <v4l2-input>` and struct
|
2016-07-03 21:02:29 +08:00
|
|
|
:ref:`v4l2_output <v4l2-output>` to zero and the :ref:`VIDIOC_G_STD <VIDIOC_G_STD>`,
|
2016-07-02 01:33:56 +08:00
|
|
|
:ref:`VIDIOC_S_STD <VIDIOC_G_STD>`, :ref:`VIDIOC_QUERYSTD` and :ref:`VIDIOC_ENUMSTD` ioctls
|
2016-07-03 22:53:09 +08:00
|
|
|
shall return the ``ENOTTY`` error code or the ``EINVAL`` error code.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
Applications can make use of the :ref:`input-capabilities` and
|
|
|
|
:ref:`output-capabilities` flags to determine whether the video
|
|
|
|
standard ioctls can be used with the given input or output.
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Information about the current video standard
|
|
|
|
=====================================================
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
v4l2_std_id std_id;
|
|
|
|
struct v4l2_standard standard;
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_G_STD, &std_id)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
/* Note when VIDIOC_ENUMSTD always returns ENOTTY this
|
|
|
|
is no video device or it falls under the USB exception,
|
|
|
|
and VIDIOC_G_STD returning ENOTTY is no error. */
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_G_STD");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&standard, 0, sizeof(standard));
|
|
|
|
standard.index = 0;
|
|
|
|
|
|
|
|
while (0 == ioctl(fd, VIDIOC_ENUMSTD, &standard)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
if (standard.id & std_id) {
|
|
|
|
printf("Current video standard: %s\\n", standard.name);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-05 03:25:48 +08:00
|
|
|
standard.index++;
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EINVAL indicates the end of the enumeration, which cannot be
|
|
|
|
empty unless this device falls under the USB exception. */
|
|
|
|
|
|
|
|
if (errno == EINVAL || standard.index == 0) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_ENUMSTD");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Listing the video standards supported by the current input
|
|
|
|
===================================================================
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
struct v4l2_input input;
|
|
|
|
struct v4l2_standard standard;
|
|
|
|
|
|
|
|
memset(&input, 0, sizeof(input));
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_G_INPUT, &input.index)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_G_INPUT");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_ENUM_INPUT");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Current input %s supports:\\n", input.name);
|
|
|
|
|
|
|
|
memset(&standard, 0, sizeof(standard));
|
|
|
|
standard.index = 0;
|
|
|
|
|
|
|
|
while (0 == ioctl(fd, VIDIOC_ENUMSTD, &standard)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
if (standard.id & input.std)
|
|
|
|
printf("%s\\n", standard.name);
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-05 03:25:48 +08:00
|
|
|
standard.index++;
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EINVAL indicates the end of the enumeration, which cannot be
|
|
|
|
empty unless this device falls under the USB exception. */
|
|
|
|
|
|
|
|
if (errno != EINVAL || standard.index == 0) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_ENUMSTD");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Selecting a new video standard
|
|
|
|
=======================================
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
struct v4l2_input input;
|
|
|
|
v4l2_std_id std_id;
|
|
|
|
|
|
|
|
memset(&input, 0, sizeof(input));
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_G_INPUT, &input.index)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_G_INPUT");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_ENUM_INPUT");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == (input.std & V4L2_STD_PAL_BG)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
fprintf(stderr, "Oops. B/G PAL is not supported.\\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note this is also supposed to work when only B
|
|
|
|
or G/PAL is supported. */
|
|
|
|
|
|
|
|
std_id = V4L2_STD_PAL_BG;
|
|
|
|
|
|
|
|
if (-1 == ioctl(fd, VIDIOC_S_STD, &std_id)) {
|
2016-07-05 03:25:48 +08:00
|
|
|
perror("VIDIOC_S_STD");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-06-30 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.. [1]
|
|
|
|
Some users are already confused by technical terms PAL, NTSC and
|
|
|
|
SECAM. There is no point asking them to distinguish between B, G, D,
|
|
|
|
or K when the software or hardware can do that automatically.
|