xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/v4l/vidioc-g-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_G_FMT:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun************************************************
7*4882a593Smuzhiyunioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT
8*4882a593Smuzhiyun************************************************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunVIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSynopsis
16*4882a593Smuzhiyun========
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun.. c:macro:: VIDIOC_G_FMT
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_G_FMT, struct v4l2_format *argp)``
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun.. c:macro:: VIDIOC_S_FMT
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_S_FMT, struct v4l2_format *argp)``
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun.. c:macro:: VIDIOC_TRY_FMT
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_TRY_FMT, struct v4l2_format *argp)``
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunArguments
31*4882a593Smuzhiyun=========
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun``fd``
34*4882a593Smuzhiyun    File descriptor returned by :c:func:`open()`.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun``argp``
37*4882a593Smuzhiyun    Pointer to struct :c:type:`v4l2_format`.
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunDescription
40*4882a593Smuzhiyun===========
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThese ioctls are used to negotiate the format of data (typically image
43*4882a593Smuzhiyunformat) exchanged between driver and application.
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunTo query the current parameters applications set the ``type`` field of a
46*4882a593Smuzhiyunstruct :c:type:`v4l2_format` to the respective buffer (stream)
47*4882a593Smuzhiyuntype. For example video capture devices use
48*4882a593Smuzhiyun``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
49*4882a593Smuzhiyun``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``. When the application calls the
50*4882a593Smuzhiyun:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this structure the driver fills
51*4882a593Smuzhiyunthe respective member of the ``fmt`` union. In case of video capture
52*4882a593Smuzhiyundevices that is either the struct
53*4882a593Smuzhiyun:c:type:`v4l2_pix_format` ``pix`` or the struct
54*4882a593Smuzhiyun:c:type:`v4l2_pix_format_mplane` ``pix_mp``
55*4882a593Smuzhiyunmember. When the requested buffer type is not supported drivers return
56*4882a593Smuzhiyunan ``EINVAL`` error code.
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunTo change the current format parameters applications initialize the
59*4882a593Smuzhiyun``type`` field and all fields of the respective ``fmt`` union member.
60*4882a593SmuzhiyunFor details see the documentation of the various devices types in
61*4882a593Smuzhiyun:ref:`devices`. Good practice is to query the current parameters
62*4882a593Smuzhiyunfirst, and to modify only those parameters not suitable for the
63*4882a593Smuzhiyunapplication. When the application calls the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
64*4882a593Smuzhiyuna pointer to a struct :c:type:`v4l2_format` structure the driver
65*4882a593Smuzhiyunchecks and adjusts the parameters against hardware abilities. Drivers
66*4882a593Smuzhiyunshould not return an error code unless the ``type`` field is invalid,
67*4882a593Smuzhiyunthis is a mechanism to fathom device capabilities and to approach
68*4882a593Smuzhiyunparameters acceptable for both the application and driver. On success
69*4882a593Smuzhiyunthe driver may program the hardware, allocate resources and generally
70*4882a593Smuzhiyunprepare for data exchange. Finally the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl returns
71*4882a593Smuzhiyunthe current format parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Very simple,
72*4882a593Smuzhiyuninflexible devices may even ignore all input and always return the
73*4882a593Smuzhiyundefault parameters. However all V4L2 devices exchanging data with the
74*4882a593Smuzhiyunapplication must implement the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
75*4882a593Smuzhiyunioctl. When the requested buffer type is not supported drivers return an
76*4882a593SmuzhiyunEINVAL error code on a :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` attempt. When I/O is already in
77*4882a593Smuzhiyunprogress or the resource is not available for other reasons drivers
78*4882a593Smuzhiyunreturn the ``EBUSY`` error code.
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunThe :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl is equivalent to :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` with one
81*4882a593Smuzhiyunexception: it does not change driver state. It can also be called at any
82*4882a593Smuzhiyuntime, never returning ``EBUSY``. This function is provided to negotiate
83*4882a593Smuzhiyunparameters, to learn about hardware limitations, without disabling I/O
84*4882a593Smuzhiyunor possibly time consuming hardware preparations. Although strongly
85*4882a593Smuzhiyunrecommended drivers are not required to implement this ioctl.
86*4882a593Smuzhiyun
87*4882a593SmuzhiyunThe format as returned by :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` must be identical to what
88*4882a593Smuzhiyun:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` returns for the same input or output.
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun.. c:type:: v4l2_format
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun.. tabularcolumns::  |p{1.2cm}|p{4.6cm}|p{3.0cm}|p{8.6cm}|
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun.. flat-table:: struct v4l2_format
95*4882a593Smuzhiyun    :header-rows:  0
96*4882a593Smuzhiyun    :stub-columns: 0
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun    * - __u32
99*4882a593Smuzhiyun      - ``type``
100*4882a593Smuzhiyun      - Type of the data stream, see :c:type:`v4l2_buf_type`.
101*4882a593Smuzhiyun    * - union {
102*4882a593Smuzhiyun      - ``fmt``
103*4882a593Smuzhiyun    * - struct :c:type:`v4l2_pix_format`
104*4882a593Smuzhiyun      - ``pix``
105*4882a593Smuzhiyun      - Definition of an image format, see :ref:`pixfmt`, used by video
106*4882a593Smuzhiyun	capture and output devices.
107*4882a593Smuzhiyun    * - struct :c:type:`v4l2_pix_format_mplane`
108*4882a593Smuzhiyun      - ``pix_mp``
109*4882a593Smuzhiyun      - Definition of an image format, see :ref:`pixfmt`, used by video
110*4882a593Smuzhiyun	capture and output devices that support the
111*4882a593Smuzhiyun	:ref:`multi-planar version of the API <planar-apis>`.
112*4882a593Smuzhiyun    * - struct :c:type:`v4l2_window`
113*4882a593Smuzhiyun      - ``win``
114*4882a593Smuzhiyun      - Definition of an overlaid image, see :ref:`overlay`, used by
115*4882a593Smuzhiyun	video overlay devices.
116*4882a593Smuzhiyun    * - struct :c:type:`v4l2_vbi_format`
117*4882a593Smuzhiyun      - ``vbi``
118*4882a593Smuzhiyun      - Raw VBI capture or output parameters. This is discussed in more
119*4882a593Smuzhiyun	detail in :ref:`raw-vbi`. Used by raw VBI capture and output
120*4882a593Smuzhiyun	devices.
121*4882a593Smuzhiyun    * - struct :c:type:`v4l2_sliced_vbi_format`
122*4882a593Smuzhiyun      - ``sliced``
123*4882a593Smuzhiyun      - Sliced VBI capture or output parameters. See :ref:`sliced` for
124*4882a593Smuzhiyun	details. Used by sliced VBI capture and output devices.
125*4882a593Smuzhiyun    * - struct :c:type:`v4l2_sdr_format`
126*4882a593Smuzhiyun      - ``sdr``
127*4882a593Smuzhiyun      - Definition of a data format, see :ref:`pixfmt`, used by SDR
128*4882a593Smuzhiyun	capture and output devices.
129*4882a593Smuzhiyun    * - struct :c:type:`v4l2_meta_format`
130*4882a593Smuzhiyun      - ``meta``
131*4882a593Smuzhiyun      - Definition of a metadata format, see :ref:`meta-formats`, used by
132*4882a593Smuzhiyun	metadata capture devices.
133*4882a593Smuzhiyun    * - __u8
134*4882a593Smuzhiyun      - ``raw_data``\ [200]
135*4882a593Smuzhiyun      - Place holder for future extensions.
136*4882a593Smuzhiyun    * - }
137*4882a593Smuzhiyun      -
138*4882a593Smuzhiyun
139*4882a593SmuzhiyunReturn Value
140*4882a593Smuzhiyun============
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set
143*4882a593Smuzhiyunappropriately. The generic error codes are described at the
144*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
145*4882a593Smuzhiyun
146*4882a593SmuzhiyunEINVAL
147*4882a593Smuzhiyun    The struct :c:type:`v4l2_format` ``type`` field is
148*4882a593Smuzhiyun    invalid or the requested buffer type not supported.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunEBUSY
151*4882a593Smuzhiyun    The device is busy and cannot change the format. This could be
152*4882a593Smuzhiyun    because or the device is streaming or buffers are allocated or
153*4882a593Smuzhiyun    queued to the driver. Relevant for :ref:`VIDIOC_S_FMT
154*4882a593Smuzhiyun    <VIDIOC_G_FMT>` only.
155