blob: ee8f56e1bac0924a1cffc27462743ad24aa62088 [file] [log] [blame]
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001<refentry id="vidioc-g-fmt">
2 <refmeta>
3 <refentrytitle>ioctl VIDIOC_G_FMT, VIDIOC_S_FMT,
4VIDIOC_TRY_FMT</refentrytitle>
5 &manvol;
6 </refmeta>
7
8 <refnamediv>
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>
13 </refnamediv>
14
15 <refsynopsisdiv>
16 <funcsynopsis>
17 <funcprototype>
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>
23 </funcprototype>
24 </funcsynopsis>
25 </refsynopsisdiv>
26
27 <refsect1>
28 <title>Arguments</title>
29
30 <variablelist>
31 <varlistentry>
32 <term><parameter>fd</parameter></term>
33 <listitem>
34 <para>&fd;</para>
35 </listitem>
36 </varlistentry>
37 <varlistentry>
38 <term><parameter>request</parameter></term>
39 <listitem>
40 <para>VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</para>
41 </listitem>
42 </varlistentry>
43 <varlistentry>
44 <term><parameter>argp</parameter></term>
45 <listitem>
46 <para></para>
47 </listitem>
48 </varlistentry>
49 </variablelist>
50 </refsect1>
51
52 <refsect1>
53 <title>Description</title>
54
55 <para>These ioctls are used to negotiate the format of data
56(typically image format) exchanged between driver and
57application.</para>
58
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)
62type. For example video capture devices use
Pawel Osciak53b5d572011-01-07 01:41:33 -030063<constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant> or
64<constant>V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</constant>. When the application
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030065calls the <constant>VIDIOC_G_FMT</constant> ioctl with a pointer to
66this structure the driver fills the respective member of the
67<structfield>fmt</structfield> union. In case of video capture devices
Pawel Osciak53b5d572011-01-07 01:41:33 -030068that is either the &v4l2-pix-format; <structfield>pix</structfield> or
69the &v4l2-pix-format-mplane; <structfield>pix_mp</structfield> member.
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030070When the requested buffer type is not supported drivers return an
71&EINVAL;.</para>
72
73 <para>To change the current format parameters applications
74initialize the <structfield>type</structfield> field and all
75fields of the respective <structfield>fmt</structfield>
76union member. For details see the documentation of the various devices
77types in <xref linkend="devices" />. Good practice is to query the
78current parameters first, and to
79modify only those parameters not suitable for the application. When
80the application calls the <constant>VIDIOC_S_FMT</constant> ioctl
81with a pointer to a <structname>v4l2_format</structname> structure
82the driver checks
83and adjusts the parameters against hardware abilities. Drivers
Hans Verkuil93828d62012-09-03 09:37:18 -030084should not return an error code unless the <structfield>type</structfield> field is invalid, this is
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030085a mechanism to fathom device capabilities and to approach parameters
86acceptable for both the application and driver. On success the driver
87may program the hardware, allocate resources and generally prepare for
88data exchange.
89Finally the <constant>VIDIOC_S_FMT</constant> ioctl returns the
90current format parameters as <constant>VIDIOC_G_FMT</constant> does.
91Very simple, inflexible devices may even ignore all input and always
92return the default parameters. However all V4L2 devices exchanging
93data with the application must implement the
94<constant>VIDIOC_G_FMT</constant> and
95<constant>VIDIOC_S_FMT</constant> ioctl. When the requested buffer
96type is not supported drivers return an &EINVAL; on a
97<constant>VIDIOC_S_FMT</constant> attempt. When I/O is already in
98progress or the resource is not available for other reasons drivers
99return the &EBUSY;.</para>
100
101 <para>The <constant>VIDIOC_TRY_FMT</constant> ioctl is equivalent
102to <constant>VIDIOC_S_FMT</constant> with one exception: it does not
103change driver state. It can also be called at any time, never
104returning <errorcode>EBUSY</errorcode>. This function is provided to
105negotiate parameters, to learn about hardware limitations, without
106disabling I/O or possibly time consuming hardware preparations.
107Although strongly recommended drivers are not required to implement
108this ioctl.</para>
109
Hans Verkuil93828d62012-09-03 09:37:18 -0300110 <para>The format as returned by <constant>VIDIOC_TRY_FMT</constant>
111must be identical to what <constant>VIDIOC_S_FMT</constant> returns for
112the same input or output.</para>
113
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300114 <table pgwide="1" frame="none" id="v4l2-format">
115 <title>struct <structname>v4l2_format</structname></title>
116 <tgroup cols="4">
117 <colspec colname="c1" />
118 <colspec colname="c2" />
119 <colspec colname="c3" />
120 <colspec colname="c4" />
121 <tbody valign="top">
122 <row>
Sakari Ailus6016af82012-05-10 02:02:07 -0300123 <entry>__u32</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300124 <entry><structfield>type</structfield></entry>
125 <entry></entry>
126 <entry>Type of the data stream, see <xref
127 linkend="v4l2-buf-type" />.</entry>
128 </row>
129 <row>
130 <entry>union</entry>
131 <entry><structfield>fmt</structfield></entry>
132 </row>
133 <row>
134 <entry></entry>
135 <entry>&v4l2-pix-format;</entry>
136 <entry><structfield>pix</structfield></entry>
137 <entry>Definition of an image format, see <xref
138 linkend="pixfmt" />, used by video capture and output
139devices.</entry>
140 </row>
141 <row>
142 <entry></entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300143 <entry>&v4l2-pix-format-mplane;</entry>
144 <entry><structfield>pix_mp</structfield></entry>
145 <entry>Definition of an image format, see <xref
146 linkend="pixfmt" />, used by video capture and output
147devices that support the <link linkend="planar-apis">multi-planar
148version of the API</link>.</entry>
149 </row>
150 <row>
151 <entry></entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300152 <entry>&v4l2-window;</entry>
153 <entry><structfield>win</structfield></entry>
154 <entry>Definition of an overlaid image, see <xref
155 linkend="overlay" />, used by video overlay devices.</entry>
156 </row>
157 <row>
158 <entry></entry>
159 <entry>&v4l2-vbi-format;</entry>
160 <entry><structfield>vbi</structfield></entry>
161 <entry>Raw VBI capture or output parameters. This is
162discussed in more detail in <xref linkend="raw-vbi" />. Used by raw VBI
163capture and output devices.</entry>
164 </row>
165 <row>
166 <entry></entry>
167 <entry>&v4l2-sliced-vbi-format;</entry>
168 <entry><structfield>sliced</structfield></entry>
169 <entry>Sliced VBI capture or output parameters. See
170<xref linkend="sliced" /> for details. Used by sliced VBI
171capture and output devices.</entry>
172 </row>
173 <row>
174 <entry></entry>
175 <entry>__u8</entry>
176 <entry><structfield>raw_data</structfield>[200]</entry>
Hans Verkuil94953562012-09-03 10:09:23 -0300177 <entry>Place holder for future extensions.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300178 </row>
179 </tbody>
180 </tgroup>
181 </table>
182 </refsect1>
183
184 <refsect1>
185 &return-value;
186
187 <variablelist>
188 <varlistentry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300189 <term><errorcode>EINVAL</errorcode></term>
190 <listitem>
191 <para>The &v4l2-format; <structfield>type</structfield>
Hans Verkuil93828d62012-09-03 09:37:18 -0300192field is invalid or the requested buffer type not supported.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300193 </listitem>
194 </varlistentry>
195 </variablelist>
196 </refsect1>
197</refentry>