1 <refentry id="vidioc-g-fmt">
3 <refentrytitle>ioctl VIDIOC_G_FMT, VIDIOC_S_FMT,
4 VIDIOC_TRY_FMT</refentrytitle>
9 <refname>VIDIOC_G_FMT</refname>
10 <refname>VIDIOC_S_FMT</refname>
11 <refname>VIDIOC_TRY_FMT</refname>
12 <refpurpose>Get or set the data format, try a format</refpurpose>
18 <funcdef>int <function>ioctl</function></funcdef>
19 <paramdef>int <parameter>fd</parameter></paramdef>
20 <paramdef>int <parameter>request</parameter></paramdef>
21 <paramdef>struct v4l2_format
22 *<parameter>argp</parameter></paramdef>
28 <title>Arguments</title>
32 <term><parameter>fd</parameter></term>
38 <term><parameter>request</parameter></term>
40 <para>VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</para>
44 <term><parameter>argp</parameter></term>
53 <title>Description</title>
55 <para>These ioctls are used to negotiate the format of data
56 (typically image format) exchanged between driver and
59 <para>To query the current parameters applications set the
60 <structfield>type</structfield> field of a struct
61 <structname>v4l2_format</structname> to the respective buffer (stream)
62 type. For example video capture devices use
63 <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant> or
64 <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</constant>. When the application
65 calls the <constant>VIDIOC_G_FMT</constant> ioctl with a pointer to
66 this structure the driver fills the respective member of the
67 <structfield>fmt</structfield> union. In case of video capture devices
68 that is either the &v4l2-pix-format; <structfield>pix</structfield> or
69 the &v4l2-pix-format-mplane; <structfield>pix_mp</structfield> member.
70 When the requested buffer type is not supported drivers return an
73 <para>To change the current format parameters applications
74 initialize the <structfield>type</structfield> field and all
75 fields of the respective <structfield>fmt</structfield>
76 union member. For details see the documentation of the various devices
77 types in <xref linkend="devices" />. Good practice is to query the
78 current parameters first, and to
79 modify only those parameters not suitable for the application. When
80 the application calls the <constant>VIDIOC_S_FMT</constant> ioctl
81 with a pointer to a <structname>v4l2_format</structname> structure
83 and adjusts the parameters against hardware abilities. Drivers
84 should not return an error code unless the input is ambiguous, this is
85 a mechanism to fathom device capabilities and to approach parameters
86 acceptable for both the application and driver. On success the driver
87 may program the hardware, allocate resources and generally prepare for
89 Finally the <constant>VIDIOC_S_FMT</constant> ioctl returns the
90 current format parameters as <constant>VIDIOC_G_FMT</constant> does.
91 Very simple, inflexible devices may even ignore all input and always
92 return the default parameters. However all V4L2 devices exchanging
93 data with the application must implement the
94 <constant>VIDIOC_G_FMT</constant> and
95 <constant>VIDIOC_S_FMT</constant> ioctl. When the requested buffer
96 type is not supported drivers return an &EINVAL; on a
97 <constant>VIDIOC_S_FMT</constant> attempt. When I/O is already in
98 progress or the resource is not available for other reasons drivers
99 return the &EBUSY;.</para>
101 <para>The <constant>VIDIOC_TRY_FMT</constant> ioctl is equivalent
102 to <constant>VIDIOC_S_FMT</constant> with one exception: it does not
103 change driver state. It can also be called at any time, never
104 returning <errorcode>EBUSY</errorcode>. This function is provided to
105 negotiate parameters, to learn about hardware limitations, without
106 disabling I/O or possibly time consuming hardware preparations.
107 Although strongly recommended drivers are not required to implement
110 <table pgwide="1" frame="none" id="v4l2-format">
111 <title>struct <structname>v4l2_format</structname></title>
113 <colspec colname="c1" />
114 <colspec colname="c2" />
115 <colspec colname="c3" />
116 <colspec colname="c4" />
119 <entry>&v4l2-buf-type;</entry>
120 <entry><structfield>type</structfield></entry>
122 <entry>Type of the data stream, see <xref
123 linkend="v4l2-buf-type" />.</entry>
127 <entry><structfield>fmt</structfield></entry>
131 <entry>&v4l2-pix-format;</entry>
132 <entry><structfield>pix</structfield></entry>
133 <entry>Definition of an image format, see <xref
134 linkend="pixfmt" />, used by video capture and output
139 <entry>&v4l2-pix-format-mplane;</entry>
140 <entry><structfield>pix_mp</structfield></entry>
141 <entry>Definition of an image format, see <xref
142 linkend="pixfmt" />, used by video capture and output
143 devices that support the <link linkend="planar-apis">multi-planar
144 version of the API</link>.</entry>
148 <entry>&v4l2-window;</entry>
149 <entry><structfield>win</structfield></entry>
150 <entry>Definition of an overlaid image, see <xref
151 linkend="overlay" />, used by video overlay devices.</entry>
155 <entry>&v4l2-vbi-format;</entry>
156 <entry><structfield>vbi</structfield></entry>
157 <entry>Raw VBI capture or output parameters. This is
158 discussed in more detail in <xref linkend="raw-vbi" />. Used by raw VBI
159 capture and output devices.</entry>
163 <entry>&v4l2-sliced-vbi-format;</entry>
164 <entry><structfield>sliced</structfield></entry>
165 <entry>Sliced VBI capture or output parameters. See
166 <xref linkend="sliced" /> for details. Used by sliced VBI
167 capture and output devices.</entry>
172 <entry><structfield>raw_data</structfield>[200]</entry>
173 <entry>Place holder for future extensions and custom
174 (driver defined) formats with <structfield>type</structfield>
175 <constant>V4L2_BUF_TYPE_PRIVATE</constant> and higher.</entry>
187 <term><errorcode>EBUSY</errorcode></term>
189 <para>The data format cannot be changed at this
190 time, for example because I/O is already in progress.</para>
194 <term><errorcode>EINVAL</errorcode></term>
196 <para>The &v4l2-format; <structfield>type</structfield>
197 field is invalid, the requested buffer type not supported, or
198 <constant>VIDIOC_TRY_FMT</constant> was called and is not
199 supported with this buffer type.</para>
209 sgml-parent-document: "v4l2.sgml"
210 indent-tabs-mode: nil