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