vidioc-g-ext-ctrls.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <refentry id="vidioc-g-ext-ctrls">
  2. <refmeta>
  3. <refentrytitle>ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,
  4. VIDIOC_TRY_EXT_CTRLS</refentrytitle>
  5. &manvol;
  6. </refmeta>
  7. <refnamediv>
  8. <refname>VIDIOC_G_EXT_CTRLS</refname>
  9. <refname>VIDIOC_S_EXT_CTRLS</refname>
  10. <refname>VIDIOC_TRY_EXT_CTRLS</refname>
  11. <refpurpose>Get or set the value of several controls, try control
  12. values</refpurpose>
  13. </refnamediv>
  14. <refsynopsisdiv>
  15. <funcsynopsis>
  16. <funcprototype>
  17. <funcdef>int <function>ioctl</function></funcdef>
  18. <paramdef>int <parameter>fd</parameter></paramdef>
  19. <paramdef>int <parameter>request</parameter></paramdef>
  20. <paramdef>struct v4l2_ext_controls
  21. *<parameter>argp</parameter></paramdef>
  22. </funcprototype>
  23. </funcsynopsis>
  24. </refsynopsisdiv>
  25. <refsect1>
  26. <title>Arguments</title>
  27. <variablelist>
  28. <varlistentry>
  29. <term><parameter>fd</parameter></term>
  30. <listitem>
  31. <para>&fd;</para>
  32. </listitem>
  33. </varlistentry>
  34. <varlistentry>
  35. <term><parameter>request</parameter></term>
  36. <listitem>
  37. <para>VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,
  38. VIDIOC_TRY_EXT_CTRLS</para>
  39. </listitem>
  40. </varlistentry>
  41. <varlistentry>
  42. <term><parameter>argp</parameter></term>
  43. <listitem>
  44. <para></para>
  45. </listitem>
  46. </varlistentry>
  47. </variablelist>
  48. </refsect1>
  49. <refsect1>
  50. <title>Description</title>
  51. <para>These ioctls allow the caller to get or set multiple
  52. controls atomically. Control IDs are grouped into control classes (see
  53. <xref linkend="ctrl-class" />) and all controls in the control array
  54. must belong to the same control class.</para>
  55. <para>Applications must always fill in the
  56. <structfield>count</structfield>,
  57. <structfield>ctrl_class</structfield>,
  58. <structfield>controls</structfield> and
  59. <structfield>reserved</structfield> fields of &v4l2-ext-controls;, and
  60. initialize the &v4l2-ext-control; array pointed to by the
  61. <structfield>controls</structfield> fields.</para>
  62. <para>To get the current value of a set of controls applications
  63. initialize the <structfield>id</structfield>,
  64. <structfield>size</structfield> and <structfield>reserved2</structfield> fields
  65. of each &v4l2-ext-control; and call the
  66. <constant>VIDIOC_G_EXT_CTRLS</constant> ioctl. String controls controls
  67. must also set the <structfield>string</structfield> field.</para>
  68. <para>If the <structfield>size</structfield> is too small to
  69. receive the control result (only relevant for pointer-type controls
  70. like strings), then the driver will set <structfield>size</structfield>
  71. to a valid value and return an &ENOSPC;. You should re-allocate the
  72. string memory to this new size and try again. It is possible that the
  73. same issue occurs again if the string has grown in the meantime. It is
  74. recommended to call &VIDIOC-QUERYCTRL; first and use
  75. <structfield>maximum</structfield>+1 as the new <structfield>size</structfield>
  76. value. It is guaranteed that that is sufficient memory.
  77. </para>
  78. <para>To change the value of a set of controls applications
  79. initialize the <structfield>id</structfield>, <structfield>size</structfield>,
  80. <structfield>reserved2</structfield> and
  81. <structfield>value/string</structfield> fields of each &v4l2-ext-control; and
  82. call the <constant>VIDIOC_S_EXT_CTRLS</constant> ioctl. The controls
  83. will only be set if <emphasis>all</emphasis> control values are
  84. valid.</para>
  85. <para>To check if a set of controls have correct values applications
  86. initialize the <structfield>id</structfield>, <structfield>size</structfield>,
  87. <structfield>reserved2</structfield> and
  88. <structfield>value/string</structfield> fields of each &v4l2-ext-control; and
  89. call the <constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctl. It is up to
  90. the driver whether wrong values are automatically adjusted to a valid
  91. value or if an error is returned.</para>
  92. <para>When the <structfield>id</structfield> or
  93. <structfield>ctrl_class</structfield> is invalid drivers return an
  94. &EINVAL;. When the value is out of bounds drivers can choose to take
  95. the closest valid value or return an &ERANGE;, whatever seems more
  96. appropriate. In the first case the new value is set in
  97. &v4l2-ext-control;.</para>
  98. <para>The driver will only set/get these controls if all control
  99. values are correct. This prevents the situation where only some of the
  100. controls were set/get. Only low-level errors (&eg; a failed i2c
  101. command) can still cause this situation.</para>
  102. <table pgwide="1" frame="none" id="v4l2-ext-control">
  103. <title>struct <structname>v4l2_ext_control</structname></title>
  104. <tgroup cols="4">
  105. &cs-ustr;
  106. <tbody valign="top">
  107. <row>
  108. <entry>__u32</entry>
  109. <entry><structfield>id</structfield></entry>
  110. <entry></entry>
  111. <entry>Identifies the control, set by the
  112. application.</entry>
  113. </row>
  114. <row>
  115. <entry>__u32</entry>
  116. <entry><structfield>size</structfield></entry>
  117. <entry></entry>
  118. <entry>The total size in bytes of the payload of this
  119. control. This is normally 0, but for pointer controls this should be
  120. set to the size of the memory containing the payload, or that will
  121. receive the payload. If <constant>VIDIOC_G_EXT_CTRLS</constant> finds
  122. that this value is less than is required to store
  123. the payload result, then it is set to a value large enough to store the
  124. payload result and ENOSPC is returned. Note that for string controls
  125. this <structfield>size</structfield> field should not be confused with the length of the string.
  126. This field refers to the size of the memory that contains the string.
  127. The actual <emphasis>length</emphasis> of the string may well be much smaller.
  128. </entry>
  129. </row>
  130. <row>
  131. <entry>__u32</entry>
  132. <entry><structfield>reserved2</structfield>[1]</entry>
  133. <entry></entry>
  134. <entry>Reserved for future extensions. Drivers and
  135. applications must set the array to zero.</entry>
  136. </row>
  137. <row>
  138. <entry>union</entry>
  139. <entry>(anonymous)</entry>
  140. </row>
  141. <row>
  142. <entry></entry>
  143. <entry>__s32</entry>
  144. <entry><structfield>value</structfield></entry>
  145. <entry>New value or current value.</entry>
  146. </row>
  147. <row>
  148. <entry></entry>
  149. <entry>__s64</entry>
  150. <entry><structfield>value64</structfield></entry>
  151. <entry>New value or current value.</entry>
  152. </row>
  153. <row>
  154. <entry></entry>
  155. <entry>char *</entry>
  156. <entry><structfield>string</structfield></entry>
  157. <entry>A pointer to a string.</entry>
  158. </row>
  159. </tbody>
  160. </tgroup>
  161. </table>
  162. <table pgwide="1" frame="none" id="v4l2-ext-controls">
  163. <title>struct <structname>v4l2_ext_controls</structname></title>
  164. <tgroup cols="3">
  165. &cs-str;
  166. <tbody valign="top">
  167. <row>
  168. <entry>__u32</entry>
  169. <entry><structfield>ctrl_class</structfield></entry>
  170. <entry>The control class to which all controls belong, see
  171. <xref linkend="ctrl-class" />. Drivers that use a kernel framework for handling
  172. controls will also accept a value of 0 here, meaning that the controls can
  173. belong to any control class. Whether drivers support this can be tested by setting
  174. <structfield>ctrl_class</structfield> to 0 and calling <constant>VIDIOC_TRY_EXT_CTRLS</constant>
  175. with a <structfield>count</structfield> of 0. If that succeeds, then the driver
  176. supports this feature.</entry>
  177. </row>
  178. <row>
  179. <entry>__u32</entry>
  180. <entry><structfield>count</structfield></entry>
  181. <entry>The number of controls in the controls array. May
  182. also be zero.</entry>
  183. </row>
  184. <row>
  185. <entry>__u32</entry>
  186. <entry><structfield>error_idx</structfield></entry>
  187. <entry><para>Set by the driver in case of an error. If the error is
  188. associated with a particular control, then <structfield>error_idx</structfield>
  189. is set to the index of that control. If the error is not related to a specific
  190. control, or the validation step failed (see below), then
  191. <structfield>error_idx</structfield> is set to <structfield>count</structfield>.
  192. The value is undefined if the ioctl returned 0 (success).</para>
  193. <para>Before controls are read from/written to hardware a validation step
  194. takes place: this checks if all controls in the list are valid controls,
  195. if no attempt is made to write to a read-only control or read from a write-only
  196. control, and any other up-front checks that can be done without accessing the
  197. hardware. The exact validations done during this step are driver dependent
  198. since some checks might require hardware access for some devices, thus making
  199. it impossible to do those checks up-front. However, drivers should make a
  200. best-effort to do as many up-front checks as possible.</para>
  201. <para>This check is done to avoid leaving the hardware in an inconsistent state due
  202. to easy-to-avoid problems. But it leads to another problem: the application needs to
  203. know whether an error came from the validation step (meaning that the hardware
  204. was not touched) or from an error during the actual reading from/writing to hardware.</para>
  205. <para>The, in hindsight quite poor, solution for that is to set <structfield>error_idx</structfield>
  206. to <structfield>count</structfield> if the validation failed. This has the
  207. unfortunate side-effect that it is not possible to see which control failed the
  208. validation. If the validation was successful and the error happened while
  209. accessing the hardware, then <structfield>error_idx</structfield> is less than
  210. <structfield>count</structfield> and only the controls up to
  211. <structfield>error_idx-1</structfield> were read or written correctly, and the
  212. state of the remaining controls is undefined.</para>
  213. <para>Since <constant>VIDIOC_TRY_EXT_CTRLS</constant> does not access hardware
  214. there is also no need to handle the validation step in this special way,
  215. so <structfield>error_idx</structfield> will just be set to the control that
  216. failed the validation step instead of to <structfield>count</structfield>.
  217. This means that if <constant>VIDIOC_S_EXT_CTRLS</constant> fails with
  218. <structfield>error_idx</structfield> set to <structfield>count</structfield>,
  219. then you can call <constant>VIDIOC_TRY_EXT_CTRLS</constant> to try to discover
  220. the actual control that failed the validation step. Unfortunately, there
  221. is no <constant>TRY</constant> equivalent for <constant>VIDIOC_G_EXT_CTRLS</constant>.
  222. </para></entry>
  223. </row>
  224. <row>
  225. <entry>__u32</entry>
  226. <entry><structfield>reserved</structfield>[2]</entry>
  227. <entry>Reserved for future extensions. Drivers and
  228. applications must set the array to zero.</entry>
  229. </row>
  230. <row>
  231. <entry>&v4l2-ext-control; *</entry>
  232. <entry><structfield>controls</structfield></entry>
  233. <entry>Pointer to an array of
  234. <structfield>count</structfield> v4l2_ext_control structures. Ignored
  235. if <structfield>count</structfield> equals zero.</entry>
  236. </row>
  237. </tbody>
  238. </tgroup>
  239. </table>
  240. <table pgwide="1" frame="none" id="ctrl-class">
  241. <title>Control classes</title>
  242. <tgroup cols="3">
  243. &cs-def;
  244. <tbody valign="top">
  245. <row>
  246. <entry><constant>V4L2_CTRL_CLASS_USER</constant></entry>
  247. <entry>0x980000</entry>
  248. <entry>The class containing user controls. These controls
  249. are described in <xref linkend="control" />. All controls that can be set
  250. using the &VIDIOC-S-CTRL; and &VIDIOC-G-CTRL; ioctl belong to this
  251. class.</entry>
  252. </row>
  253. <row>
  254. <entry><constant>V4L2_CTRL_CLASS_MPEG</constant></entry>
  255. <entry>0x990000</entry>
  256. <entry>The class containing MPEG compression controls.
  257. These controls are described in <xref
  258. linkend="mpeg-controls" />.</entry>
  259. </row>
  260. <row>
  261. <entry><constant>V4L2_CTRL_CLASS_CAMERA</constant></entry>
  262. <entry>0x9a0000</entry>
  263. <entry>The class containing camera controls.
  264. These controls are described in <xref
  265. linkend="camera-controls" />.</entry>
  266. </row>
  267. <row>
  268. <entry><constant>V4L2_CTRL_CLASS_FM_TX</constant></entry>
  269. <entry>0x9b0000</entry>
  270. <entry>The class containing FM Transmitter (FM TX) controls.
  271. These controls are described in <xref
  272. linkend="fm-tx-controls" />.</entry>
  273. </row>
  274. <row>
  275. <entry><constant>V4L2_CTRL_CLASS_FLASH</constant></entry>
  276. <entry>0x9c0000</entry>
  277. <entry>The class containing flash device controls.
  278. These controls are described in <xref
  279. linkend="flash-controls" />.</entry>
  280. </row>
  281. <row>
  282. <entry><constant>V4L2_CTRL_CLASS_JPEG</constant></entry>
  283. <entry>0x9d0000</entry>
  284. <entry>The class containing JPEG compression controls.
  285. These controls are described in <xref
  286. linkend="jpeg-controls" />.</entry>
  287. </row>
  288. <row>
  289. <entry><constant>V4L2_CTRL_CLASS_IMAGE_SOURCE</constant></entry>
  290. <entry>0x9e0000</entry> <entry>The class containing image
  291. source controls. These controls are described in <xref
  292. linkend="image-source-controls" />.</entry>
  293. </row>
  294. <row>
  295. <entry><constant>V4L2_CTRL_CLASS_IMAGE_PROC</constant></entry>
  296. <entry>0x9f0000</entry> <entry>The class containing image
  297. processing controls. These controls are described in <xref
  298. linkend="image-process-controls" />.</entry>
  299. </row>
  300. </tbody>
  301. </tgroup>
  302. </table>
  303. </refsect1>
  304. <refsect1>
  305. &return-value;
  306. <variablelist>
  307. <varlistentry>
  308. <term><errorcode>EINVAL</errorcode></term>
  309. <listitem>
  310. <para>The &v4l2-ext-control; <structfield>id</structfield>
  311. is invalid or the &v4l2-ext-controls;
  312. <structfield>ctrl_class</structfield> is invalid. This error code is
  313. also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and
  314. <constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctls if two or more
  315. control values are in conflict.</para>
  316. </listitem>
  317. </varlistentry>
  318. <varlistentry>
  319. <term><errorcode>ERANGE</errorcode></term>
  320. <listitem>
  321. <para>The &v4l2-ext-control; <structfield>value</structfield>
  322. is out of bounds.</para>
  323. </listitem>
  324. </varlistentry>
  325. <varlistentry>
  326. <term><errorcode>EBUSY</errorcode></term>
  327. <listitem>
  328. <para>The control is temporarily not changeable, possibly
  329. because another applications took over control of the device function
  330. this control belongs to.</para>
  331. </listitem>
  332. </varlistentry>
  333. <varlistentry>
  334. <term><errorcode>ENOSPC</errorcode></term>
  335. <listitem>
  336. <para>The space reserved for the control's payload is insufficient.
  337. The field <structfield>size</structfield> is set to a value that is enough
  338. to store the payload and this error code is returned.</para>
  339. </listitem>
  340. </varlistentry>
  341. <varlistentry>
  342. <term><errorcode>EACCES</errorcode></term>
  343. <listitem>
  344. <para>Attempt to try or set a read-only control or to get a
  345. write-only control.</para>
  346. </listitem>
  347. </varlistentry>
  348. </variablelist>
  349. </refsect1>
  350. </refentry>