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