162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: V4L
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _VIDIOC_G_FMT:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci************************************************
762306a36Sopenharmony_ciioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT
862306a36Sopenharmony_ci************************************************
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciName
1162306a36Sopenharmony_ci====
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciVIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciSynopsis
1662306a36Sopenharmony_ci========
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_G_FMT
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_G_FMT, struct v4l2_format *argp)``
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_S_FMT
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_S_FMT, struct v4l2_format *argp)``
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci.. c:macro:: VIDIOC_TRY_FMT
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_TRY_FMT, struct v4l2_format *argp)``
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciArguments
3162306a36Sopenharmony_ci=========
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci``fd``
3462306a36Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci``argp``
3762306a36Sopenharmony_ci    Pointer to struct :c:type:`v4l2_format`.
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciDescription
4062306a36Sopenharmony_ci===========
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciThese ioctls are used to negotiate the format of data (typically image
4362306a36Sopenharmony_ciformat) exchanged between driver and application.
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciTo query the current parameters applications set the ``type`` field of a
4662306a36Sopenharmony_cistruct :c:type:`v4l2_format` to the respective buffer (stream)
4762306a36Sopenharmony_citype. For example video capture devices use
4862306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
4962306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``. When the application calls the
5062306a36Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this structure the driver fills
5162306a36Sopenharmony_cithe respective member of the ``fmt`` union. In case of video capture
5262306a36Sopenharmony_cidevices that is either the struct
5362306a36Sopenharmony_ci:c:type:`v4l2_pix_format` ``pix`` or the struct
5462306a36Sopenharmony_ci:c:type:`v4l2_pix_format_mplane` ``pix_mp``
5562306a36Sopenharmony_cimember. When the requested buffer type is not supported drivers return
5662306a36Sopenharmony_cian ``EINVAL`` error code.
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciTo change the current format parameters applications initialize the
5962306a36Sopenharmony_ci``type`` field and all fields of the respective ``fmt`` union member.
6062306a36Sopenharmony_ciFor details see the documentation of the various devices types in
6162306a36Sopenharmony_ci:ref:`devices`. Good practice is to query the current parameters
6262306a36Sopenharmony_cifirst, and to modify only those parameters not suitable for the
6362306a36Sopenharmony_ciapplication. When the application calls the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
6462306a36Sopenharmony_cia pointer to a struct :c:type:`v4l2_format` structure the driver
6562306a36Sopenharmony_cichecks and adjusts the parameters against hardware abilities. Drivers
6662306a36Sopenharmony_cishould not return an error code unless the ``type`` field is invalid,
6762306a36Sopenharmony_cithis is a mechanism to fathom device capabilities and to approach
6862306a36Sopenharmony_ciparameters acceptable for both the application and driver. On success
6962306a36Sopenharmony_cithe driver may program the hardware, allocate resources and generally
7062306a36Sopenharmony_ciprepare for data exchange. Finally the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl returns
7162306a36Sopenharmony_cithe current format parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Very simple,
7262306a36Sopenharmony_ciinflexible devices may even ignore all input and always return the
7362306a36Sopenharmony_cidefault parameters. However all V4L2 devices exchanging data with the
7462306a36Sopenharmony_ciapplication must implement the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
7562306a36Sopenharmony_ciioctl. When the requested buffer type is not supported drivers return an
7662306a36Sopenharmony_ciEINVAL error code on a :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` attempt. When I/O is already in
7762306a36Sopenharmony_ciprogress or the resource is not available for other reasons drivers
7862306a36Sopenharmony_cireturn the ``EBUSY`` error code.
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciThe :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl is equivalent to :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` with one
8162306a36Sopenharmony_ciexception: it does not change driver state. It can also be called at any
8262306a36Sopenharmony_citime, never returning ``EBUSY``. This function is provided to negotiate
8362306a36Sopenharmony_ciparameters, to learn about hardware limitations, without disabling I/O
8462306a36Sopenharmony_cior possibly time consuming hardware preparations. Although strongly
8562306a36Sopenharmony_cirecommended drivers are not required to implement this ioctl.
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciThe format as returned by :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` must be identical to what
8862306a36Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` returns for the same input or output.
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci.. c:type:: v4l2_format
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci.. tabularcolumns::  |p{7.4cm}|p{4.4cm}|p{5.5cm}|
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci.. flat-table:: struct v4l2_format
9562306a36Sopenharmony_ci    :header-rows:  0
9662306a36Sopenharmony_ci    :stub-columns: 0
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci    * - __u32
9962306a36Sopenharmony_ci      - ``type``
10062306a36Sopenharmony_ci      - Type of the data stream, see :c:type:`v4l2_buf_type`.
10162306a36Sopenharmony_ci    * - union {
10262306a36Sopenharmony_ci      - ``fmt``
10362306a36Sopenharmony_ci    * - struct :c:type:`v4l2_pix_format`
10462306a36Sopenharmony_ci      - ``pix``
10562306a36Sopenharmony_ci      - Definition of an image format, see :ref:`pixfmt`, used by video
10662306a36Sopenharmony_ci	capture and output devices.
10762306a36Sopenharmony_ci    * - struct :c:type:`v4l2_pix_format_mplane`
10862306a36Sopenharmony_ci      - ``pix_mp``
10962306a36Sopenharmony_ci      - Definition of an image format, see :ref:`pixfmt`, used by video
11062306a36Sopenharmony_ci	capture and output devices that support the
11162306a36Sopenharmony_ci	:ref:`multi-planar version of the API <planar-apis>`.
11262306a36Sopenharmony_ci    * - struct :c:type:`v4l2_window`
11362306a36Sopenharmony_ci      - ``win``
11462306a36Sopenharmony_ci      - Definition of an overlaid image, see :ref:`overlay`, used by
11562306a36Sopenharmony_ci	video overlay devices.
11662306a36Sopenharmony_ci    * - struct :c:type:`v4l2_vbi_format`
11762306a36Sopenharmony_ci      - ``vbi``
11862306a36Sopenharmony_ci      - Raw VBI capture or output parameters. This is discussed in more
11962306a36Sopenharmony_ci	detail in :ref:`raw-vbi`. Used by raw VBI capture and output
12062306a36Sopenharmony_ci	devices.
12162306a36Sopenharmony_ci    * - struct :c:type:`v4l2_sliced_vbi_format`
12262306a36Sopenharmony_ci      - ``sliced``
12362306a36Sopenharmony_ci      - Sliced VBI capture or output parameters. See :ref:`sliced` for
12462306a36Sopenharmony_ci	details. Used by sliced VBI capture and output devices.
12562306a36Sopenharmony_ci    * - struct :c:type:`v4l2_sdr_format`
12662306a36Sopenharmony_ci      - ``sdr``
12762306a36Sopenharmony_ci      - Definition of a data format, see :ref:`pixfmt`, used by SDR
12862306a36Sopenharmony_ci	capture and output devices.
12962306a36Sopenharmony_ci    * - struct :c:type:`v4l2_meta_format`
13062306a36Sopenharmony_ci      - ``meta``
13162306a36Sopenharmony_ci      - Definition of a metadata format, see :ref:`meta-formats`, used by
13262306a36Sopenharmony_ci	metadata capture devices.
13362306a36Sopenharmony_ci    * - __u8
13462306a36Sopenharmony_ci      - ``raw_data``\ [200]
13562306a36Sopenharmony_ci      - Place holder for future extensions.
13662306a36Sopenharmony_ci    * - }
13762306a36Sopenharmony_ci      -
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ciReturn Value
14062306a36Sopenharmony_ci============
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
14362306a36Sopenharmony_ciappropriately. The generic error codes are described at the
14462306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ciEINVAL
14762306a36Sopenharmony_ci    The struct :c:type:`v4l2_format` ``type`` field is
14862306a36Sopenharmony_ci    invalid or the requested buffer type not supported.
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ciEBUSY
15162306a36Sopenharmony_ci    The device is busy and cannot change the format. This could be
15262306a36Sopenharmony_ci    because or the device is streaming or buffers are allocated or
15362306a36Sopenharmony_ci    queued to the driver. Relevant for :ref:`VIDIOC_S_FMT
15462306a36Sopenharmony_ci    <VIDIOC_G_FMT>` only.
155