18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _VIDIOC_ENUM_FMT:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci*********************
78c2ecf20Sopenharmony_ciioctl VIDIOC_ENUM_FMT
88c2ecf20Sopenharmony_ci*********************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciVIDIOC_ENUM_FMT - Enumerate image formats
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_ENUM_FMT
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_ENUM_FMT, struct v4l2_fmtdesc *argp)``
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciArguments
238c2ecf20Sopenharmony_ci=========
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci``fd``
268c2ecf20Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci``argp``
298c2ecf20Sopenharmony_ci    Pointer to struct :c:type:`v4l2_fmtdesc`.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciDescription
328c2ecf20Sopenharmony_ci===========
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciTo enumerate image formats applications initialize the ``type``, ``mbus_code``
358c2ecf20Sopenharmony_ciand ``index`` fields of struct :c:type:`v4l2_fmtdesc` and call
368c2ecf20Sopenharmony_cithe :ref:`VIDIOC_ENUM_FMT` ioctl with a pointer to this structure. Drivers
378c2ecf20Sopenharmony_cifill the rest of the structure or return an ``EINVAL`` error code. All
388c2ecf20Sopenharmony_ciformats are enumerable by beginning at index zero and incrementing by
398c2ecf20Sopenharmony_cione until ``EINVAL`` is returned. If applicable, drivers shall return
408c2ecf20Sopenharmony_ciformats in preference order, where preferred formats are returned before
418c2ecf20Sopenharmony_ci(that is, with lower ``index`` value) less-preferred formats.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciDepending on the ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`,
448c2ecf20Sopenharmony_cithe ``mbus_code`` field is handled differently:
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci1) ``V4L2_CAP_IO_MC`` is not set (also known as a 'video-node-centric' driver)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci   Applications shall initialize the ``mbus_code`` field to zero and drivers
498c2ecf20Sopenharmony_ci   shall ignore the value of the field.
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci   Drivers shall enumerate all image formats.
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci   .. note::
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci      After switching the input or output the list of enumerated image
568c2ecf20Sopenharmony_ci      formats may be different.
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci2) ``V4L2_CAP_IO_MC`` is set (also known as an 'MC-centric' driver)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci   If the ``mbus_code`` field is zero, then all image formats
618c2ecf20Sopenharmony_ci   shall be enumerated.
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci   If the ``mbus_code`` field is initialized to a valid (non-zero)
648c2ecf20Sopenharmony_ci   :ref:`media bus format code <v4l2-mbus-pixelcode>`, then drivers
658c2ecf20Sopenharmony_ci   shall restrict enumeration to only the image formats that can produce
668c2ecf20Sopenharmony_ci   (for video output devices) or be produced from (for video capture
678c2ecf20Sopenharmony_ci   devices) that media bus code. If the ``mbus_code`` is unsupported by
688c2ecf20Sopenharmony_ci   the driver, then ``EINVAL`` shall be returned.
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci   Regardless of the value of the ``mbus_code`` field, the enumerated image
718c2ecf20Sopenharmony_ci   formats shall not depend on the active configuration of the video device
728c2ecf20Sopenharmony_ci   or device pipeline.
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci.. c:type:: v4l2_fmtdesc
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_fmtdesc
798c2ecf20Sopenharmony_ci    :header-rows:  0
808c2ecf20Sopenharmony_ci    :stub-columns: 0
818c2ecf20Sopenharmony_ci    :widths:       1 1 2
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci    * - __u32
848c2ecf20Sopenharmony_ci      - ``index``
858c2ecf20Sopenharmony_ci      - Number of the format in the enumeration, set by the application.
868c2ecf20Sopenharmony_ci	This is in no way related to the ``pixelformat`` field.
878c2ecf20Sopenharmony_ci    * - __u32
888c2ecf20Sopenharmony_ci      - ``type``
898c2ecf20Sopenharmony_ci      - Type of the data stream, set by the application. Only these types
908c2ecf20Sopenharmony_ci	are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``,
918c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``,
928c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OUTPUT``,
938c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``,
948c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OVERLAY``,
958c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_SDR_CAPTURE``,
968c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_SDR_OUTPUT``,
978c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_META_CAPTURE`` and
988c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_META_OUTPUT``.
998c2ecf20Sopenharmony_ci	See :c:type:`v4l2_buf_type`.
1008c2ecf20Sopenharmony_ci    * - __u32
1018c2ecf20Sopenharmony_ci      - ``flags``
1028c2ecf20Sopenharmony_ci      - See :ref:`fmtdesc-flags`
1038c2ecf20Sopenharmony_ci    * - __u8
1048c2ecf20Sopenharmony_ci      - ``description``\ [32]
1058c2ecf20Sopenharmony_ci      - Description of the format, a NUL-terminated ASCII string. This
1068c2ecf20Sopenharmony_ci	information is intended for the user, for example: "YUV 4:2:2".
1078c2ecf20Sopenharmony_ci    * - __u32
1088c2ecf20Sopenharmony_ci      - ``pixelformat``
1098c2ecf20Sopenharmony_ci      - The image format identifier. This is a four character code as
1108c2ecf20Sopenharmony_ci	computed by the v4l2_fourcc() macro:
1118c2ecf20Sopenharmony_ci    * - :cspan:`2`
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	.. _v4l2-fourcc:
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	``#define v4l2_fourcc(a,b,c,d)``
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	``(((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))``
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	Several image formats are already defined by this specification in
1208c2ecf20Sopenharmony_ci	:ref:`pixfmt`.
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	.. attention::
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	   These codes are not the same as those used
1258c2ecf20Sopenharmony_ci	   in the Windows world.
1268c2ecf20Sopenharmony_ci    * - __u32
1278c2ecf20Sopenharmony_ci      - ``mbus_code``
1288c2ecf20Sopenharmony_ci      - Media bus code restricting the enumerated formats, set by the
1298c2ecf20Sopenharmony_ci        application. Only applicable to drivers that advertise the
1308c2ecf20Sopenharmony_ci        ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`, shall be 0
1318c2ecf20Sopenharmony_ci        otherwise.
1328c2ecf20Sopenharmony_ci    * - __u32
1338c2ecf20Sopenharmony_ci      - ``reserved``\ [3]
1348c2ecf20Sopenharmony_ci      - Reserved for future extensions. Drivers must set the array to
1358c2ecf20Sopenharmony_ci	zero.
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci.. _fmtdesc-flags:
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci.. flat-table:: Image Format Description Flags
1438c2ecf20Sopenharmony_ci    :header-rows:  0
1448c2ecf20Sopenharmony_ci    :stub-columns: 0
1458c2ecf20Sopenharmony_ci    :widths:       3 1 4
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_COMPRESSED``
1488c2ecf20Sopenharmony_ci      - 0x0001
1498c2ecf20Sopenharmony_ci      - This is a compressed format.
1508c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_EMULATED``
1518c2ecf20Sopenharmony_ci      - 0x0002
1528c2ecf20Sopenharmony_ci      - This format is not native to the device but emulated through
1538c2ecf20Sopenharmony_ci	software (usually libv4l2), where possible try to use a native
1548c2ecf20Sopenharmony_ci	format instead for better performance.
1558c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM``
1568c2ecf20Sopenharmony_ci      - 0x0004
1578c2ecf20Sopenharmony_ci      - The hardware decoder for this compressed bytestream format (aka coded
1588c2ecf20Sopenharmony_ci	format) is capable of parsing a continuous bytestream. Applications do
1598c2ecf20Sopenharmony_ci	not need to parse the bytestream themselves to find the boundaries
1608c2ecf20Sopenharmony_ci	between frames/fields.
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	This flag can only be used in combination with the
1638c2ecf20Sopenharmony_ci	``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to compressed
1648c2ecf20Sopenharmony_ci	formats only. This flag is valid for stateful decoders only.
1658c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_DYN_RESOLUTION``
1668c2ecf20Sopenharmony_ci      - 0x0008
1678c2ecf20Sopenharmony_ci      - Dynamic resolution switching is supported by the device for this
1688c2ecf20Sopenharmony_ci	compressed bytestream format (aka coded format). It will notify the user
1698c2ecf20Sopenharmony_ci	via the event ``V4L2_EVENT_SOURCE_CHANGE`` when changes in the video
1708c2ecf20Sopenharmony_ci	parameters are detected.
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	This flag can only be used in combination with the
1738c2ecf20Sopenharmony_ci	``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to
1748c2ecf20Sopenharmony_ci	compressed formats only. This flag is valid for stateful codecs only.
1758c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL``
1768c2ecf20Sopenharmony_ci      - 0x0010
1778c2ecf20Sopenharmony_ci      - The hardware encoder supports setting the ``CAPTURE`` coded frame
1788c2ecf20Sopenharmony_ci	interval separately from the ``OUTPUT`` raw frame interval.
1798c2ecf20Sopenharmony_ci	Setting the ``OUTPUT`` raw frame interval with :ref:`VIDIOC_S_PARM <VIDIOC_G_PARM>`
1808c2ecf20Sopenharmony_ci	also sets the ``CAPTURE`` coded frame interval to the same value.
1818c2ecf20Sopenharmony_ci	If this flag is set, then the ``CAPTURE`` coded frame interval can be
1828c2ecf20Sopenharmony_ci	set to a different value afterwards. This is typically used for
1838c2ecf20Sopenharmony_ci	offline encoding where the ``OUTPUT`` raw frame interval is used as
1848c2ecf20Sopenharmony_ci	a hint for reserving hardware encoder resources and the ``CAPTURE`` coded
1858c2ecf20Sopenharmony_ci	frame interval is the actual frame rate embedded in the encoded video
1868c2ecf20Sopenharmony_ci	stream.
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	This flag can only be used in combination with the
1898c2ecf20Sopenharmony_ci	``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to
1908c2ecf20Sopenharmony_ci        compressed formats only. This flag is valid for stateful encoders only.
1918c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_CSC_COLORSPACE``
1928c2ecf20Sopenharmony_ci      - 0x0020
1938c2ecf20Sopenharmony_ci      - The driver allows the application to try to change the default
1948c2ecf20Sopenharmony_ci	colorspace. This flag is relevant only for capture devices.
1958c2ecf20Sopenharmony_ci	The application can ask to configure the colorspace of the capture device
1968c2ecf20Sopenharmony_ci	when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
1978c2ecf20Sopenharmony_ci	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
1988c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_CSC_XFER_FUNC``
1998c2ecf20Sopenharmony_ci      - 0x0040
2008c2ecf20Sopenharmony_ci      - The driver allows the application to try to change the default
2018c2ecf20Sopenharmony_ci	transfer function. This flag is relevant only for capture devices.
2028c2ecf20Sopenharmony_ci	The application can ask to configure the transfer function of the capture
2038c2ecf20Sopenharmony_ci	device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
2048c2ecf20Sopenharmony_ci	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
2058c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_CSC_YCBCR_ENC``
2068c2ecf20Sopenharmony_ci      - 0x0080
2078c2ecf20Sopenharmony_ci      - The driver allows the application to try to change the default
2088c2ecf20Sopenharmony_ci	Y'CbCr encoding. This flag is relevant only for capture devices.
2098c2ecf20Sopenharmony_ci	The application can ask to configure the Y'CbCr encoding of the capture device
2108c2ecf20Sopenharmony_ci	when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
2118c2ecf20Sopenharmony_ci	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
2128c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_CSC_HSV_ENC``
2138c2ecf20Sopenharmony_ci      - 0x0080
2148c2ecf20Sopenharmony_ci      - The driver allows the application to try to change the default
2158c2ecf20Sopenharmony_ci	HSV encoding. This flag is relevant only for capture devices.
2168c2ecf20Sopenharmony_ci	The application can ask to configure the HSV encoding of the capture device
2178c2ecf20Sopenharmony_ci	when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
2188c2ecf20Sopenharmony_ci	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
2198c2ecf20Sopenharmony_ci    * - ``V4L2_FMT_FLAG_CSC_QUANTIZATION``
2208c2ecf20Sopenharmony_ci      - 0x0100
2218c2ecf20Sopenharmony_ci      - The driver allows the application to try to change the default
2228c2ecf20Sopenharmony_ci	quantization. This flag is relevant only for capture devices.
2238c2ecf20Sopenharmony_ci	The application can ask to configure the quantization of the capture
2248c2ecf20Sopenharmony_ci	device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
2258c2ecf20Sopenharmony_ci	:ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ciReturn Value
2288c2ecf20Sopenharmony_ci============
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
2318c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
2328c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ciEINVAL
2358c2ecf20Sopenharmony_ci    The struct :c:type:`v4l2_fmtdesc` ``type`` is not
2368c2ecf20Sopenharmony_ci    supported or the ``index`` is out of bounds.
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci    If ``V4L2_CAP_IO_MC`` is set and the specified ``mbus_code``
2398c2ecf20Sopenharmony_ci    is unsupported, then also return this error code.
240