^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) .. c:namespace:: V4L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) .. _VIDIOC_SUBDEV_G_FMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) **********************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) **********************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) VIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) Synopsis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .. c:macro:: VIDIOC_SUBDEV_G_FMT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ``int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .. c:macro:: VIDIOC_SUBDEV_S_FMT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) ``int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) Arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ``fd``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) File descriptor returned by :c:func:`open()`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ``argp``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Pointer to struct :c:type:`v4l2_subdev_format`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) These ioctls are used to negotiate the frame format at specific subdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) pads in the image pipeline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) To retrieve the current format applications set the ``pad`` field of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct :c:type:`v4l2_subdev_format` to the desired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) pad number as reported by the media API and the ``which`` field to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) driver fills the members of the ``format`` field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) To change the current format applications set both the ``pad`` and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ``which`` fields and all members of the ``format`` field. When they call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) the ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) driver verifies the requested format, adjusts it based on the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) capabilities and configures the device. Upon return the struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) :c:type:`v4l2_subdev_format` contains the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) format as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) Applications can query the device capabilities by setting the ``which``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) to ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) to the device by the driver, but are changed exactly as active formats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) and stored in the sub-device file handle. Two applications querying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) same sub-device would thus not interact with each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) For instance, to try a format at the output pad of a sub-device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) applications would first set the try format at the sub-device input with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) the ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) default format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) or set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ioctl and check the returned value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) Try formats do not depend on active formats, but can depend on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) current links configuration or sub-device controls value. For instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) a low-pass noise filter might crop pixels at the frame boundaries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) modifying its output frame size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) If the subdev device node has been registered in read-only mode, calls to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) variable is set to ``-EPERM``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) Drivers must not return an error solely because the requested format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) doesn't match the device capabilities. They must instead modify the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) format to match what the hardware can provide. The modified format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) should be as close as possible to the original request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .. c:type:: v4l2_subdev_format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .. flat-table:: struct v4l2_subdev_format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) :header-rows: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) :stub-columns: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) :widths: 1 1 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * - __u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) - ``pad``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) - Pad number as reported by the media controller API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * - __u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) - ``which``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) - Format to modified, from enum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * - struct :c:type:`v4l2_mbus_framefmt`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) - ``format``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * - __u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) - ``reserved``\ [8]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) - Reserved for future extensions. Applications and drivers must set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) the array to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .. _v4l2-subdev-format-whence:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .. flat-table:: enum v4l2_subdev_format_whence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) :header-rows: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) :stub-columns: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) :widths: 3 1 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * - V4L2_SUBDEV_FORMAT_TRY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) - 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) - Try formats, used for querying device capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * - V4L2_SUBDEV_FORMAT_ACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) - 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) - Active formats, applied to the hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) Return Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) On success 0 is returned, on error -1 and the ``errno`` variable is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) appropriately. The generic error codes are described at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) :ref:`Generic Error Codes <gen-errors>` chapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) EBUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) The format can't be changed because the pad is currently busy. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) can be caused, for instance, by an active video stream on the pad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) The ioctl must not be retried without performing another action to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) EINVAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) The struct :c:type:`v4l2_subdev_format`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ``pad`` references a non-existing pad, or the ``which`` field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) references a non-existing format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) EPERM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) On success 0 is returned, on error -1 and the ``errno`` variable is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) appropriately. The generic error codes are described at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) :ref:`Generic Error Codes <gen-errors>` chapter.