^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) .. _video:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) Video Inputs and Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) ************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Video inputs and outputs are physical connectors of a device. These can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) be for example: RF connectors (antenna/cable), CVBS a.k.a. Composite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) Video, S-Video and RGB connectors. Camera sensors are also considered to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) be a video input. Video and VBI capture devices have inputs. Video and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) VBI output devices have outputs, at least one each. Radio devices have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) no video inputs or outputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) To learn about the number and attributes of the available inputs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) outputs applications can enumerate them with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) :ref:`VIDIOC_ENUMINPUT` and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) :ref:`VIDIOC_ENUMOUTPUT` ioctl, respectively. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct :c:type:`v4l2_input` returned by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) :ref:`VIDIOC_ENUMINPUT` ioctl also contains signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) status information applicable when the current video input is queried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) The :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) :ref:`VIDIOC_G_OUTPUT <VIDIOC_G_OUTPUT>` ioctls return the index of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) the current video input or output. To select a different input or output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) applications call the :ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) :ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` ioctls. Drivers must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) implement all the input ioctls when the device has one or more inputs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) all the output ioctls when the device has one or more outputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) Example: Information about the current video input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ==================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .. code-block:: c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct v4l2_input input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (-1 == ioctl(fd, VIDIOC_G_INPUT, &index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) perror("VIDIOC_G_INPUT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) memset(&input, 0, sizeof(input));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) input.index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) perror("VIDIOC_ENUMINPUT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) printf("Current input: %s\\n", input.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) Example: Switching to the first video input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ===========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .. code-block:: c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (-1 == ioctl(fd, VIDIOC_S_INPUT, &index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) perror("VIDIOC_S_INPUT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) exit(EXIT_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }