xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/v4l/vidioc-enum-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_ENUM_FMT:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun*********************
7*4882a593Smuzhiyunioctl VIDIOC_ENUM_FMT
8*4882a593Smuzhiyun*********************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunVIDIOC_ENUM_FMT - Enumerate image formats
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSynopsis
16*4882a593Smuzhiyun========
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun.. c:macro:: VIDIOC_ENUM_FMT
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_ENUM_FMT, struct v4l2_fmtdesc *argp)``
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunArguments
23*4882a593Smuzhiyun=========
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun``fd``
26*4882a593Smuzhiyun    File descriptor returned by :c:func:`open()`.
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun``argp``
29*4882a593Smuzhiyun    Pointer to struct :c:type:`v4l2_fmtdesc`.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunDescription
32*4882a593Smuzhiyun===========
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunTo enumerate image formats applications initialize the ``type``, ``mbus_code``
35*4882a593Smuzhiyunand ``index`` fields of struct :c:type:`v4l2_fmtdesc` and call
36*4882a593Smuzhiyunthe :ref:`VIDIOC_ENUM_FMT` ioctl with a pointer to this structure. Drivers
37*4882a593Smuzhiyunfill the rest of the structure or return an ``EINVAL`` error code. All
38*4882a593Smuzhiyunformats are enumerable by beginning at index zero and incrementing by
39*4882a593Smuzhiyunone until ``EINVAL`` is returned. If applicable, drivers shall return
40*4882a593Smuzhiyunformats in preference order, where preferred formats are returned before
41*4882a593Smuzhiyun(that is, with lower ``index`` value) less-preferred formats.
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunDepending on the ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`,
44*4882a593Smuzhiyunthe ``mbus_code`` field is handled differently:
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun1) ``V4L2_CAP_IO_MC`` is not set (also known as a 'video-node-centric' driver)
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun   Applications shall initialize the ``mbus_code`` field to zero and drivers
49*4882a593Smuzhiyun   shall ignore the value of the field.
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun   Drivers shall enumerate all image formats.
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun   .. note::
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun      After switching the input or output the list of enumerated image
56*4882a593Smuzhiyun      formats may be different.
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun2) ``V4L2_CAP_IO_MC`` is set (also known as an 'MC-centric' driver)
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun   If the ``mbus_code`` field is zero, then all image formats
61*4882a593Smuzhiyun   shall be enumerated.
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun   If the ``mbus_code`` field is initialized to a valid (non-zero)
64*4882a593Smuzhiyun   :ref:`media bus format code <v4l2-mbus-pixelcode>`, then drivers
65*4882a593Smuzhiyun   shall restrict enumeration to only the image formats that can produce
66*4882a593Smuzhiyun   (for video output devices) or be produced from (for video capture
67*4882a593Smuzhiyun   devices) that media bus code. If the ``mbus_code`` is unsupported by
68*4882a593Smuzhiyun   the driver, then ``EINVAL`` shall be returned.
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun   Regardless of the value of the ``mbus_code`` field, the enumerated image
71*4882a593Smuzhiyun   formats shall not depend on the active configuration of the video device
72*4882a593Smuzhiyun   or device pipeline.
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun.. c:type:: v4l2_fmtdesc
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun.. flat-table:: struct v4l2_fmtdesc
79*4882a593Smuzhiyun    :header-rows:  0
80*4882a593Smuzhiyun    :stub-columns: 0
81*4882a593Smuzhiyun    :widths:       1 1 2
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun    * - __u32
84*4882a593Smuzhiyun      - ``index``
85*4882a593Smuzhiyun      - Number of the format in the enumeration, set by the application.
86*4882a593Smuzhiyun	This is in no way related to the ``pixelformat`` field.
87*4882a593Smuzhiyun    * - __u32
88*4882a593Smuzhiyun      - ``type``
89*4882a593Smuzhiyun      - Type of the data stream, set by the application. Only these types
90*4882a593Smuzhiyun	are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``,
91*4882a593Smuzhiyun	``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``,
92*4882a593Smuzhiyun	``V4L2_BUF_TYPE_VIDEO_OUTPUT``,
93*4882a593Smuzhiyun	``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``,
94*4882a593Smuzhiyun	``V4L2_BUF_TYPE_VIDEO_OVERLAY``,
95*4882a593Smuzhiyun	``V4L2_BUF_TYPE_SDR_CAPTURE``,
96*4882a593Smuzhiyun	``V4L2_BUF_TYPE_SDR_OUTPUT``,
97*4882a593Smuzhiyun	``V4L2_BUF_TYPE_META_CAPTURE`` and
98*4882a593Smuzhiyun	``V4L2_BUF_TYPE_META_OUTPUT``.
99*4882a593Smuzhiyun	See :c:type:`v4l2_buf_type`.
100*4882a593Smuzhiyun    * - __u32
101*4882a593Smuzhiyun      - ``flags``
102*4882a593Smuzhiyun      - See :ref:`fmtdesc-flags`
103*4882a593Smuzhiyun    * - __u8
104*4882a593Smuzhiyun      - ``description``\ [32]
105*4882a593Smuzhiyun      - Description of the format, a NUL-terminated ASCII string. This
106*4882a593Smuzhiyun	information is intended for the user, for example: "YUV 4:2:2".
107*4882a593Smuzhiyun    * - __u32
108*4882a593Smuzhiyun      - ``pixelformat``
109*4882a593Smuzhiyun      - The image format identifier. This is a four character code as
110*4882a593Smuzhiyun	computed by the v4l2_fourcc() macro:
111*4882a593Smuzhiyun    * - :cspan:`2`
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun	.. _v4l2-fourcc:
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun	``#define v4l2_fourcc(a,b,c,d)``
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun	``(((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))``
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun	Several image formats are already defined by this specification in
120*4882a593Smuzhiyun	:ref:`pixfmt`.
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun	.. attention::
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun	   These codes are not the same as those used
125*4882a593Smuzhiyun	   in the Windows world.
126*4882a593Smuzhiyun    * - __u32
127*4882a593Smuzhiyun      - ``mbus_code``
128*4882a593Smuzhiyun      - Media bus code restricting the enumerated formats, set by the
129*4882a593Smuzhiyun        application. Only applicable to drivers that advertise the
130*4882a593Smuzhiyun        ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`, shall be 0
131*4882a593Smuzhiyun        otherwise.
132*4882a593Smuzhiyun    * - __u32
133*4882a593Smuzhiyun      - ``reserved``\ [3]
134*4882a593Smuzhiyun      - Reserved for future extensions. Drivers must set the array to
135*4882a593Smuzhiyun	zero.
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun.. _fmtdesc-flags:
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun.. flat-table:: Image Format Description Flags
143*4882a593Smuzhiyun    :header-rows:  0
144*4882a593Smuzhiyun    :stub-columns: 0
145*4882a593Smuzhiyun    :widths:       3 1 4
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_COMPRESSED``
148*4882a593Smuzhiyun      - 0x0001
149*4882a593Smuzhiyun      - This is a compressed format.
150*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_EMULATED``
151*4882a593Smuzhiyun      - 0x0002
152*4882a593Smuzhiyun      - This format is not native to the device but emulated through
153*4882a593Smuzhiyun	software (usually libv4l2), where possible try to use a native
154*4882a593Smuzhiyun	format instead for better performance.
155*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM``
156*4882a593Smuzhiyun      - 0x0004
157*4882a593Smuzhiyun      - The hardware decoder for this compressed bytestream format (aka coded
158*4882a593Smuzhiyun	format) is capable of parsing a continuous bytestream. Applications do
159*4882a593Smuzhiyun	not need to parse the bytestream themselves to find the boundaries
160*4882a593Smuzhiyun	between frames/fields.
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun	This flag can only be used in combination with the
163*4882a593Smuzhiyun	``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to compressed
164*4882a593Smuzhiyun	formats only. This flag is valid for stateful decoders only.
165*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_DYN_RESOLUTION``
166*4882a593Smuzhiyun      - 0x0008
167*4882a593Smuzhiyun      - Dynamic resolution switching is supported by the device for this
168*4882a593Smuzhiyun	compressed bytestream format (aka coded format). It will notify the user
169*4882a593Smuzhiyun	via the event ``V4L2_EVENT_SOURCE_CHANGE`` when changes in the video
170*4882a593Smuzhiyun	parameters are detected.
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun	This flag can only be used in combination with the
173*4882a593Smuzhiyun	``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to
174*4882a593Smuzhiyun	compressed formats only. This flag is valid for stateful codecs only.
175*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL``
176*4882a593Smuzhiyun      - 0x0010
177*4882a593Smuzhiyun      - The hardware encoder supports setting the ``CAPTURE`` coded frame
178*4882a593Smuzhiyun	interval separately from the ``OUTPUT`` raw frame interval.
179*4882a593Smuzhiyun	Setting the ``OUTPUT`` raw frame interval with :ref:`VIDIOC_S_PARM <VIDIOC_G_PARM>`
180*4882a593Smuzhiyun	also sets the ``CAPTURE`` coded frame interval to the same value.
181*4882a593Smuzhiyun	If this flag is set, then the ``CAPTURE`` coded frame interval can be
182*4882a593Smuzhiyun	set to a different value afterwards. This is typically used for
183*4882a593Smuzhiyun	offline encoding where the ``OUTPUT`` raw frame interval is used as
184*4882a593Smuzhiyun	a hint for reserving hardware encoder resources and the ``CAPTURE`` coded
185*4882a593Smuzhiyun	frame interval is the actual frame rate embedded in the encoded video
186*4882a593Smuzhiyun	stream.
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun	This flag can only be used in combination with the
189*4882a593Smuzhiyun	``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to
190*4882a593Smuzhiyun        compressed formats only. This flag is valid for stateful encoders only.
191*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_CSC_COLORSPACE``
192*4882a593Smuzhiyun      - 0x0020
193*4882a593Smuzhiyun      - The driver allows the application to try to change the default
194*4882a593Smuzhiyun	colorspace. This flag is relevant only for capture devices.
195*4882a593Smuzhiyun	The application can ask to configure the colorspace of the capture device
196*4882a593Smuzhiyun	when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
197*4882a593Smuzhiyun	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
198*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_CSC_XFER_FUNC``
199*4882a593Smuzhiyun      - 0x0040
200*4882a593Smuzhiyun      - The driver allows the application to try to change the default
201*4882a593Smuzhiyun	transfer function. This flag is relevant only for capture devices.
202*4882a593Smuzhiyun	The application can ask to configure the transfer function of the capture
203*4882a593Smuzhiyun	device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
204*4882a593Smuzhiyun	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
205*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_CSC_YCBCR_ENC``
206*4882a593Smuzhiyun      - 0x0080
207*4882a593Smuzhiyun      - The driver allows the application to try to change the default
208*4882a593Smuzhiyun	Y'CbCr encoding. This flag is relevant only for capture devices.
209*4882a593Smuzhiyun	The application can ask to configure the Y'CbCr encoding of the capture device
210*4882a593Smuzhiyun	when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
211*4882a593Smuzhiyun	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
212*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_CSC_HSV_ENC``
213*4882a593Smuzhiyun      - 0x0080
214*4882a593Smuzhiyun      - The driver allows the application to try to change the default
215*4882a593Smuzhiyun	HSV encoding. This flag is relevant only for capture devices.
216*4882a593Smuzhiyun	The application can ask to configure the HSV encoding of the capture device
217*4882a593Smuzhiyun	when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
218*4882a593Smuzhiyun	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
219*4882a593Smuzhiyun    * - ``V4L2_FMT_FLAG_CSC_QUANTIZATION``
220*4882a593Smuzhiyun      - 0x0100
221*4882a593Smuzhiyun      - The driver allows the application to try to change the default
222*4882a593Smuzhiyun	quantization. This flag is relevant only for capture devices.
223*4882a593Smuzhiyun	The application can ask to configure the quantization of the capture
224*4882a593Smuzhiyun	device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
225*4882a593Smuzhiyun	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
226*4882a593Smuzhiyun
227*4882a593SmuzhiyunReturn Value
228*4882a593Smuzhiyun============
229*4882a593Smuzhiyun
230*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set
231*4882a593Smuzhiyunappropriately. The generic error codes are described at the
232*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
233*4882a593Smuzhiyun
234*4882a593SmuzhiyunEINVAL
235*4882a593Smuzhiyun    The struct :c:type:`v4l2_fmtdesc` ``type`` is not
236*4882a593Smuzhiyun    supported or the ``index`` is out of bounds.
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun    If ``V4L2_CAP_IO_MC`` is set and the specified ``mbus_code``
239*4882a593Smuzhiyun    is unsupported, then also return this error code.
240