Based on kernel version 4.7.2. Page generated on 2016-08-22 22:45 EST.
1 <refentry id="vidioc-g-fmt"> 2 <refmeta> 3 <refentrytitle>ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, 4 VIDIOC_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 57 application.</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) 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 71 &EINVAL;.</para> 72 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 82 the driver checks 83 and adjusts the parameters against hardware abilities. Drivers 84 should not return an error code unless the <structfield>type</structfield> field is invalid, 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 88 data exchange. 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> 100 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 108 this ioctl.</para> 109 110 <para>The format as returned by <constant>VIDIOC_TRY_FMT</constant> 111 must be identical to what <constant>VIDIOC_S_FMT</constant> returns for 112 the same input or output.</para> 113 114 <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> 123 <entry>__u32</entry> 124 <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 139 devices.</entry> 140 </row> 141 <row> 142 <entry></entry> 143 <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 147 devices that support the <link linkend="planar-apis">multi-planar 148 version of the API</link>.</entry> 149 </row> 150 <row> 151 <entry></entry> 152 <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 162 discussed in more detail in <xref linkend="raw-vbi" />. Used by raw VBI 163 capture 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 171 capture and output devices.</entry> 172 </row> 173 <row> 174 <entry></entry> 175 <entry>&v4l2-sdr-format;</entry> 176 <entry><structfield>sdr</structfield></entry> 177 <entry>Definition of a data format, see 178 <xref linkend="pixfmt" />, used by SDR capture and output devices.</entry> 179 </row> 180 <row> 181 <entry></entry> 182 <entry>__u8</entry> 183 <entry><structfield>raw_data</structfield>[200]</entry> 184 <entry>Place holder for future extensions.</entry> 185 </row> 186 </tbody> 187 </tgroup> 188 </table> 189 </refsect1> 190 191 <refsect1> 192 &return-value; 193 194 <variablelist> 195 <varlistentry> 196 <term><errorcode>EINVAL</errorcode></term> 197 <listitem> 198 <para>The &v4l2-format; <structfield>type</structfield> 199 field is invalid or the requested buffer type not supported.</para> 200 </listitem> 201 </varlistentry> 202 </variablelist> 203 </refsect1> 204 </refentry>