162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_ENUM_FMT: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci********************* 762306a36Sopenharmony_ciioctl VIDIOC_ENUM_FMT 862306a36Sopenharmony_ci********************* 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_ENUM_FMT - Enumerate image formats 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_ENUM_FMT 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_ENUM_FMT, struct v4l2_fmtdesc *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciArguments 2362306a36Sopenharmony_ci========= 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci``fd`` 2662306a36Sopenharmony_ci File descriptor returned by :c:func:`open()`. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci``argp`` 2962306a36Sopenharmony_ci Pointer to struct :c:type:`v4l2_fmtdesc`. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciDescription 3262306a36Sopenharmony_ci=========== 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciTo enumerate image formats applications initialize the ``type``, ``mbus_code`` 3562306a36Sopenharmony_ciand ``index`` fields of struct :c:type:`v4l2_fmtdesc` and call 3662306a36Sopenharmony_cithe :ref:`VIDIOC_ENUM_FMT` ioctl with a pointer to this structure. Drivers 3762306a36Sopenharmony_cifill the rest of the structure or return an ``EINVAL`` error code. All 3862306a36Sopenharmony_ciformats are enumerable by beginning at index zero and incrementing by 3962306a36Sopenharmony_cione until ``EINVAL`` is returned. If applicable, drivers shall return 4062306a36Sopenharmony_ciformats in preference order, where preferred formats are returned before 4162306a36Sopenharmony_ci(that is, with lower ``index`` value) less-preferred formats. 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciDepending on the ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`, 4462306a36Sopenharmony_cithe ``mbus_code`` field is handled differently: 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci1) ``V4L2_CAP_IO_MC`` is not set (also known as a 'video-node-centric' driver) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci Applications shall initialize the ``mbus_code`` field to zero and drivers 4962306a36Sopenharmony_ci shall ignore the value of the field. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci Drivers shall enumerate all image formats. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci .. note:: 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci After switching the input or output the list of enumerated image 5662306a36Sopenharmony_ci formats may be different. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci2) ``V4L2_CAP_IO_MC`` is set (also known as an 'MC-centric' driver) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci If the ``mbus_code`` field is zero, then all image formats 6162306a36Sopenharmony_ci shall be enumerated. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci If the ``mbus_code`` field is initialized to a valid (non-zero) 6462306a36Sopenharmony_ci :ref:`media bus format code <v4l2-mbus-pixelcode>`, then drivers 6562306a36Sopenharmony_ci shall restrict enumeration to only the image formats that can produce 6662306a36Sopenharmony_ci (for video output devices) or be produced from (for video capture 6762306a36Sopenharmony_ci devices) that media bus code. If the ``mbus_code`` is unsupported by 6862306a36Sopenharmony_ci the driver, then ``EINVAL`` shall be returned. 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci Regardless of the value of the ``mbus_code`` field, the enumerated image 7162306a36Sopenharmony_ci formats shall not depend on the active configuration of the video device 7262306a36Sopenharmony_ci or device pipeline. 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci.. c:type:: v4l2_fmtdesc 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci.. cssclass:: longtable 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci.. flat-table:: struct v4l2_fmtdesc 8162306a36Sopenharmony_ci :header-rows: 0 8262306a36Sopenharmony_ci :stub-columns: 0 8362306a36Sopenharmony_ci :widths: 1 1 2 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci * - __u32 8662306a36Sopenharmony_ci - ``index`` 8762306a36Sopenharmony_ci - Number of the format in the enumeration, set by the application. 8862306a36Sopenharmony_ci This is in no way related to the ``pixelformat`` field. 8962306a36Sopenharmony_ci * - __u32 9062306a36Sopenharmony_ci - ``type`` 9162306a36Sopenharmony_ci - Type of the data stream, set by the application. Only these types 9262306a36Sopenharmony_ci are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``, 9362306a36Sopenharmony_ci ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``, 9462306a36Sopenharmony_ci ``V4L2_BUF_TYPE_VIDEO_OUTPUT``, 9562306a36Sopenharmony_ci ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``, 9662306a36Sopenharmony_ci ``V4L2_BUF_TYPE_VIDEO_OVERLAY``, 9762306a36Sopenharmony_ci ``V4L2_BUF_TYPE_SDR_CAPTURE``, 9862306a36Sopenharmony_ci ``V4L2_BUF_TYPE_SDR_OUTPUT``, 9962306a36Sopenharmony_ci ``V4L2_BUF_TYPE_META_CAPTURE`` and 10062306a36Sopenharmony_ci ``V4L2_BUF_TYPE_META_OUTPUT``. 10162306a36Sopenharmony_ci See :c:type:`v4l2_buf_type`. 10262306a36Sopenharmony_ci * - __u32 10362306a36Sopenharmony_ci - ``flags`` 10462306a36Sopenharmony_ci - See :ref:`fmtdesc-flags` 10562306a36Sopenharmony_ci * - __u8 10662306a36Sopenharmony_ci - ``description``\ [32] 10762306a36Sopenharmony_ci - Description of the format, a NUL-terminated ASCII string. This 10862306a36Sopenharmony_ci information is intended for the user, for example: "YUV 4:2:2". 10962306a36Sopenharmony_ci * - __u32 11062306a36Sopenharmony_ci - ``pixelformat`` 11162306a36Sopenharmony_ci - The image format identifier. This is a four character code as 11262306a36Sopenharmony_ci computed by the v4l2_fourcc() macro: 11362306a36Sopenharmony_ci * - :cspan:`2` 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci .. _v4l2-fourcc: 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci ``#define v4l2_fourcc(a,b,c,d)`` 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci ``(((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))`` 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci Several image formats are already defined by this specification in 12262306a36Sopenharmony_ci :ref:`pixfmt`. 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci .. attention:: 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci These codes are not the same as those used 12762306a36Sopenharmony_ci in the Windows world. 12862306a36Sopenharmony_ci * - __u32 12962306a36Sopenharmony_ci - ``mbus_code`` 13062306a36Sopenharmony_ci - Media bus code restricting the enumerated formats, set by the 13162306a36Sopenharmony_ci application. Only applicable to drivers that advertise the 13262306a36Sopenharmony_ci ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`, shall be 0 13362306a36Sopenharmony_ci otherwise. 13462306a36Sopenharmony_ci * - __u32 13562306a36Sopenharmony_ci - ``reserved``\ [3] 13662306a36Sopenharmony_ci - Reserved for future extensions. Drivers must set the array to 13762306a36Sopenharmony_ci zero. 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci.. tabularcolumns:: |p{8.4cm}|p{1.8cm}|p{7.1cm}| 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci.. cssclass:: longtable 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci.. _fmtdesc-flags: 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci.. flat-table:: Image Format Description Flags 14762306a36Sopenharmony_ci :header-rows: 0 14862306a36Sopenharmony_ci :stub-columns: 0 14962306a36Sopenharmony_ci :widths: 3 1 4 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_COMPRESSED`` 15262306a36Sopenharmony_ci - 0x0001 15362306a36Sopenharmony_ci - This is a compressed format. 15462306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_EMULATED`` 15562306a36Sopenharmony_ci - 0x0002 15662306a36Sopenharmony_ci - This format is not native to the device but emulated through 15762306a36Sopenharmony_ci software (usually libv4l2), where possible try to use a native 15862306a36Sopenharmony_ci format instead for better performance. 15962306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM`` 16062306a36Sopenharmony_ci - 0x0004 16162306a36Sopenharmony_ci - The hardware decoder for this compressed bytestream format (aka coded 16262306a36Sopenharmony_ci format) is capable of parsing a continuous bytestream. Applications do 16362306a36Sopenharmony_ci not need to parse the bytestream themselves to find the boundaries 16462306a36Sopenharmony_ci between frames/fields. 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci This flag can only be used in combination with the 16762306a36Sopenharmony_ci ``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to compressed 16862306a36Sopenharmony_ci formats only. This flag is valid for stateful decoders only. 16962306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_DYN_RESOLUTION`` 17062306a36Sopenharmony_ci - 0x0008 17162306a36Sopenharmony_ci - Dynamic resolution switching is supported by the device for this 17262306a36Sopenharmony_ci compressed bytestream format (aka coded format). It will notify the user 17362306a36Sopenharmony_ci via the event ``V4L2_EVENT_SOURCE_CHANGE`` when changes in the video 17462306a36Sopenharmony_ci parameters are detected. 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci This flag can only be used in combination with the 17762306a36Sopenharmony_ci ``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to 17862306a36Sopenharmony_ci compressed formats only. This flag is valid for stateful codecs only. 17962306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL`` 18062306a36Sopenharmony_ci - 0x0010 18162306a36Sopenharmony_ci - The hardware encoder supports setting the ``CAPTURE`` coded frame 18262306a36Sopenharmony_ci interval separately from the ``OUTPUT`` raw frame interval. 18362306a36Sopenharmony_ci Setting the ``OUTPUT`` raw frame interval with :ref:`VIDIOC_S_PARM <VIDIOC_G_PARM>` 18462306a36Sopenharmony_ci also sets the ``CAPTURE`` coded frame interval to the same value. 18562306a36Sopenharmony_ci If this flag is set, then the ``CAPTURE`` coded frame interval can be 18662306a36Sopenharmony_ci set to a different value afterwards. This is typically used for 18762306a36Sopenharmony_ci offline encoding where the ``OUTPUT`` raw frame interval is used as 18862306a36Sopenharmony_ci a hint for reserving hardware encoder resources and the ``CAPTURE`` coded 18962306a36Sopenharmony_ci frame interval is the actual frame rate embedded in the encoded video 19062306a36Sopenharmony_ci stream. 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci This flag can only be used in combination with the 19362306a36Sopenharmony_ci ``V4L2_FMT_FLAG_COMPRESSED`` flag, since this applies to 19462306a36Sopenharmony_ci compressed formats only. This flag is valid for stateful encoders only. 19562306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_CSC_COLORSPACE`` 19662306a36Sopenharmony_ci - 0x0020 19762306a36Sopenharmony_ci - The driver allows the application to try to change the default 19862306a36Sopenharmony_ci colorspace. This flag is relevant only for capture devices. 19962306a36Sopenharmony_ci The application can ask to configure the colorspace of the capture device 20062306a36Sopenharmony_ci when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with 20162306a36Sopenharmony_ci :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set. 20262306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_CSC_XFER_FUNC`` 20362306a36Sopenharmony_ci - 0x0040 20462306a36Sopenharmony_ci - The driver allows the application to try to change the default 20562306a36Sopenharmony_ci transfer function. This flag is relevant only for capture devices. 20662306a36Sopenharmony_ci The application can ask to configure the transfer function of the capture 20762306a36Sopenharmony_ci device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with 20862306a36Sopenharmony_ci :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set. 20962306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_CSC_YCBCR_ENC`` 21062306a36Sopenharmony_ci - 0x0080 21162306a36Sopenharmony_ci - The driver allows the application to try to change the default 21262306a36Sopenharmony_ci Y'CbCr encoding. This flag is relevant only for capture devices. 21362306a36Sopenharmony_ci The application can ask to configure the Y'CbCr encoding of the capture device 21462306a36Sopenharmony_ci when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with 21562306a36Sopenharmony_ci :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set. 21662306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_CSC_HSV_ENC`` 21762306a36Sopenharmony_ci - 0x0080 21862306a36Sopenharmony_ci - The driver allows the application to try to change the default 21962306a36Sopenharmony_ci HSV encoding. This flag is relevant only for capture devices. 22062306a36Sopenharmony_ci The application can ask to configure the HSV encoding of the capture device 22162306a36Sopenharmony_ci when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with 22262306a36Sopenharmony_ci :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set. 22362306a36Sopenharmony_ci * - ``V4L2_FMT_FLAG_CSC_QUANTIZATION`` 22462306a36Sopenharmony_ci - 0x0100 22562306a36Sopenharmony_ci - The driver allows the application to try to change the default 22662306a36Sopenharmony_ci quantization. This flag is relevant only for capture devices. 22762306a36Sopenharmony_ci The application can ask to configure the quantization of the capture 22862306a36Sopenharmony_ci device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with 22962306a36Sopenharmony_ci :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set. 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ciReturn Value 23262306a36Sopenharmony_ci============ 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 23562306a36Sopenharmony_ciappropriately. The generic error codes are described at the 23662306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ciEINVAL 23962306a36Sopenharmony_ci The struct :c:type:`v4l2_fmtdesc` ``type`` is not 24062306a36Sopenharmony_ci supported or the ``index`` is out of bounds. 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci If ``V4L2_CAP_IO_MC`` is set and the specified ``mbus_code`` 24362306a36Sopenharmony_ci is unsupported, then also return this error code. 244