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>. When the application
64 calls the <constant>VIDIOC_G_FMT</constant> ioctl with a pointer to
65 this structure the driver fills the respective member of the
66 <structfield>fmt</structfield> union. In case of video capture devices
67 that is the &v4l2-pix-format; <structfield>pix</structfield> member.
68 When the requested buffer type is not supported drivers return an
71 <para>To change the current format parameters applications
72 initialize the <structfield>type</structfield> field and all
73 fields of the respective <structfield>fmt</structfield>
74 union member. For details see the documentation of the various devices
75 types in <xref linkend="devices" />. Good practice is to query the
76 current parameters first, and to
77 modify only those parameters not suitable for the application. When
78 the application calls the <constant>VIDIOC_S_FMT</constant> ioctl
79 with a pointer to a <structname>v4l2_format</structname> structure
81 and adjusts the parameters against hardware abilities. Drivers
82 should not return an error code unless the input is ambiguous, this is
83 a mechanism to fathom device capabilities and to approach parameters
84 acceptable for both the application and driver. On success the driver
85 may program the hardware, allocate resources and generally prepare for
87 Finally the <constant>VIDIOC_S_FMT</constant> ioctl returns the
88 current format parameters as <constant>VIDIOC_G_FMT</constant> does.
89 Very simple, inflexible devices may even ignore all input and always
90 return the default parameters. However all V4L2 devices exchanging
91 data with the application must implement the
92 <constant>VIDIOC_G_FMT</constant> and
93 <constant>VIDIOC_S_FMT</constant> ioctl. When the requested buffer
94 type is not supported drivers return an &EINVAL; on a
95 <constant>VIDIOC_S_FMT</constant> attempt. When I/O is already in
96 progress or the resource is not available for other reasons drivers
97 return the &EBUSY;.</para>
99 <para>The <constant>VIDIOC_TRY_FMT</constant> ioctl is equivalent
100 to <constant>VIDIOC_S_FMT</constant> with one exception: it does not
101 change driver state. It can also be called at any time, never
102 returning <errorcode>EBUSY</errorcode>. This function is provided to
103 negotiate parameters, to learn about hardware limitations, without
104 disabling I/O or possibly time consuming hardware preparations.
105 Although strongly recommended drivers are not required to implement
108 <table pgwide="1" frame="none" id="v4l2-format">
109 <title>struct <structname>v4l2_format</structname></title>
111 <colspec colname="c1" />
112 <colspec colname="c2" />
113 <colspec colname="c3" />
114 <colspec colname="c4" />
117 <entry>&v4l2-buf-type;</entry>
118 <entry><structfield>type</structfield></entry>
120 <entry>Type of the data stream, see <xref
121 linkend="v4l2-buf-type" />.</entry>
125 <entry><structfield>fmt</structfield></entry>
129 <entry>&v4l2-pix-format;</entry>
130 <entry><structfield>pix</structfield></entry>
131 <entry>Definition of an image format, see <xref
132 linkend="pixfmt" />, used by video capture and output
137 <entry>&v4l2-window;</entry>
138 <entry><structfield>win</structfield></entry>
139 <entry>Definition of an overlaid image, see <xref
140 linkend="overlay" />, used by video overlay devices.</entry>
144 <entry>&v4l2-vbi-format;</entry>
145 <entry><structfield>vbi</structfield></entry>
146 <entry>Raw VBI capture or output parameters. This is
147 discussed in more detail in <xref linkend="raw-vbi" />. Used by raw VBI
148 capture and output devices.</entry>
152 <entry>&v4l2-sliced-vbi-format;</entry>
153 <entry><structfield>sliced</structfield></entry>
154 <entry>Sliced VBI capture or output parameters. See
155 <xref linkend="sliced" /> for details. Used by sliced VBI
156 capture and output devices.</entry>
161 <entry><structfield>raw_data</structfield>[200]</entry>
162 <entry>Place holder for future extensions and custom
163 (driver defined) formats with <structfield>type</structfield>
164 <constant>V4L2_BUF_TYPE_PRIVATE</constant> and higher.</entry>
176 <term><errorcode>EBUSY</errorcode></term>
178 <para>The data format cannot be changed at this
179 time, for example because I/O is already in progress.</para>
183 <term><errorcode>EINVAL</errorcode></term>
185 <para>The &v4l2-format; <structfield>type</structfield>
186 field is invalid, the requested buffer type not supported, or
187 <constant>VIDIOC_TRY_FMT</constant> was called and is not
188 supported with this buffer type.</para>
198 sgml-parent-document: "v4l2.sgml"
199 indent-tabs-mode: nil