18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _VIDIOC_G_FMT:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci************************************************
78c2ecf20Sopenharmony_ciioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT
88c2ecf20Sopenharmony_ci************************************************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciVIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_G_FMT
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_G_FMT, struct v4l2_format *argp)``
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_S_FMT
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_S_FMT, struct v4l2_format *argp)``
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_TRY_FMT
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_TRY_FMT, struct v4l2_format *argp)``
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciArguments
318c2ecf20Sopenharmony_ci=========
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci``fd``
348c2ecf20Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci``argp``
378c2ecf20Sopenharmony_ci    Pointer to struct :c:type:`v4l2_format`.
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciDescription
408c2ecf20Sopenharmony_ci===========
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciThese ioctls are used to negotiate the format of data (typically image
438c2ecf20Sopenharmony_ciformat) exchanged between driver and application.
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciTo query the current parameters applications set the ``type`` field of a
468c2ecf20Sopenharmony_cistruct :c:type:`v4l2_format` to the respective buffer (stream)
478c2ecf20Sopenharmony_citype. For example video capture devices use
488c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
498c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``. When the application calls the
508c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this structure the driver fills
518c2ecf20Sopenharmony_cithe respective member of the ``fmt`` union. In case of video capture
528c2ecf20Sopenharmony_cidevices that is either the struct
538c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format` ``pix`` or the struct
548c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format_mplane` ``pix_mp``
558c2ecf20Sopenharmony_cimember. When the requested buffer type is not supported drivers return
568c2ecf20Sopenharmony_cian ``EINVAL`` error code.
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciTo change the current format parameters applications initialize the
598c2ecf20Sopenharmony_ci``type`` field and all fields of the respective ``fmt`` union member.
608c2ecf20Sopenharmony_ciFor details see the documentation of the various devices types in
618c2ecf20Sopenharmony_ci:ref:`devices`. Good practice is to query the current parameters
628c2ecf20Sopenharmony_cifirst, and to modify only those parameters not suitable for the
638c2ecf20Sopenharmony_ciapplication. When the application calls the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
648c2ecf20Sopenharmony_cia pointer to a struct :c:type:`v4l2_format` structure the driver
658c2ecf20Sopenharmony_cichecks and adjusts the parameters against hardware abilities. Drivers
668c2ecf20Sopenharmony_cishould not return an error code unless the ``type`` field is invalid,
678c2ecf20Sopenharmony_cithis is a mechanism to fathom device capabilities and to approach
688c2ecf20Sopenharmony_ciparameters acceptable for both the application and driver. On success
698c2ecf20Sopenharmony_cithe driver may program the hardware, allocate resources and generally
708c2ecf20Sopenharmony_ciprepare for data exchange. Finally the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl returns
718c2ecf20Sopenharmony_cithe current format parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Very simple,
728c2ecf20Sopenharmony_ciinflexible devices may even ignore all input and always return the
738c2ecf20Sopenharmony_cidefault parameters. However all V4L2 devices exchanging data with the
748c2ecf20Sopenharmony_ciapplication must implement the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
758c2ecf20Sopenharmony_ciioctl. When the requested buffer type is not supported drivers return an
768c2ecf20Sopenharmony_ciEINVAL error code on a :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` attempt. When I/O is already in
778c2ecf20Sopenharmony_ciprogress or the resource is not available for other reasons drivers
788c2ecf20Sopenharmony_cireturn the ``EBUSY`` error code.
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciThe :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl is equivalent to :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` with one
818c2ecf20Sopenharmony_ciexception: it does not change driver state. It can also be called at any
828c2ecf20Sopenharmony_citime, never returning ``EBUSY``. This function is provided to negotiate
838c2ecf20Sopenharmony_ciparameters, to learn about hardware limitations, without disabling I/O
848c2ecf20Sopenharmony_cior possibly time consuming hardware preparations. Although strongly
858c2ecf20Sopenharmony_cirecommended drivers are not required to implement this ioctl.
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciThe format as returned by :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` must be identical to what
888c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` returns for the same input or output.
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci.. c:type:: v4l2_format
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci.. tabularcolumns::  |p{1.2cm}|p{4.6cm}|p{3.0cm}|p{8.6cm}|
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_format
958c2ecf20Sopenharmony_ci    :header-rows:  0
968c2ecf20Sopenharmony_ci    :stub-columns: 0
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci    * - __u32
998c2ecf20Sopenharmony_ci      - ``type``
1008c2ecf20Sopenharmony_ci      - Type of the data stream, see :c:type:`v4l2_buf_type`.
1018c2ecf20Sopenharmony_ci    * - union {
1028c2ecf20Sopenharmony_ci      - ``fmt``
1038c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_pix_format`
1048c2ecf20Sopenharmony_ci      - ``pix``
1058c2ecf20Sopenharmony_ci      - Definition of an image format, see :ref:`pixfmt`, used by video
1068c2ecf20Sopenharmony_ci	capture and output devices.
1078c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_pix_format_mplane`
1088c2ecf20Sopenharmony_ci      - ``pix_mp``
1098c2ecf20Sopenharmony_ci      - Definition of an image format, see :ref:`pixfmt`, used by video
1108c2ecf20Sopenharmony_ci	capture and output devices that support the
1118c2ecf20Sopenharmony_ci	:ref:`multi-planar version of the API <planar-apis>`.
1128c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_window`
1138c2ecf20Sopenharmony_ci      - ``win``
1148c2ecf20Sopenharmony_ci      - Definition of an overlaid image, see :ref:`overlay`, used by
1158c2ecf20Sopenharmony_ci	video overlay devices.
1168c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_vbi_format`
1178c2ecf20Sopenharmony_ci      - ``vbi``
1188c2ecf20Sopenharmony_ci      - Raw VBI capture or output parameters. This is discussed in more
1198c2ecf20Sopenharmony_ci	detail in :ref:`raw-vbi`. Used by raw VBI capture and output
1208c2ecf20Sopenharmony_ci	devices.
1218c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_sliced_vbi_format`
1228c2ecf20Sopenharmony_ci      - ``sliced``
1238c2ecf20Sopenharmony_ci      - Sliced VBI capture or output parameters. See :ref:`sliced` for
1248c2ecf20Sopenharmony_ci	details. Used by sliced VBI capture and output devices.
1258c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_sdr_format`
1268c2ecf20Sopenharmony_ci      - ``sdr``
1278c2ecf20Sopenharmony_ci      - Definition of a data format, see :ref:`pixfmt`, used by SDR
1288c2ecf20Sopenharmony_ci	capture and output devices.
1298c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_meta_format`
1308c2ecf20Sopenharmony_ci      - ``meta``
1318c2ecf20Sopenharmony_ci      - Definition of a metadata format, see :ref:`meta-formats`, used by
1328c2ecf20Sopenharmony_ci	metadata capture devices.
1338c2ecf20Sopenharmony_ci    * - __u8
1348c2ecf20Sopenharmony_ci      - ``raw_data``\ [200]
1358c2ecf20Sopenharmony_ci      - Place holder for future extensions.
1368c2ecf20Sopenharmony_ci    * - }
1378c2ecf20Sopenharmony_ci      -
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciReturn Value
1408c2ecf20Sopenharmony_ci============
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
1438c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
1448c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciEINVAL
1478c2ecf20Sopenharmony_ci    The struct :c:type:`v4l2_format` ``type`` field is
1488c2ecf20Sopenharmony_ci    invalid or the requested buffer type not supported.
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciEBUSY
1518c2ecf20Sopenharmony_ci    The device is busy and cannot change the format. This could be
1528c2ecf20Sopenharmony_ci    because or the device is streaming or buffers are allocated or
1538c2ecf20Sopenharmony_ci    queued to the driver. Relevant for :ref:`VIDIOC_S_FMT
1548c2ecf20Sopenharmony_ci    <VIDIOC_G_FMT>` only.
155