vidioc-g-ext-ctrls.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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;. If the new control value is inappropriate (e.g. the
  98. given menu index is not supported by the menu control), then this will
  99. also result in an &EINVAL; error.</para>
  100. <para>The driver will only set/get these controls if all control
  101. values are correct. This prevents the situation where only some of the
  102. controls were set/get. Only low-level errors (&eg; a failed i2c
  103. command) can still cause this situation.</para>
  104. <table pgwide="1" frame="none" id="v4l2-ext-control">
  105. <title>struct <structname>v4l2_ext_control</structname></title>
  106. <tgroup cols="4">
  107. &cs-ustr;
  108. <tbody valign="top">
  109. <row>
  110. <entry>__u32</entry>
  111. <entry><structfield>id</structfield></entry>
  112. <entry></entry>
  113. <entry>Identifies the control, set by the
  114. application.</entry>
  115. </row>
  116. <row>
  117. <entry>__u32</entry>
  118. <entry><structfield>size</structfield></entry>
  119. <entry></entry>
  120. <entry>The total size in bytes of the payload of this
  121. control. This is normally 0, but for pointer controls this should be
  122. set to the size of the memory containing the payload, or that will
  123. receive the payload. If <constant>VIDIOC_G_EXT_CTRLS</constant> finds
  124. that this value is less than is required to store
  125. the payload result, then it is set to a value large enough to store the
  126. payload result and ENOSPC is returned. Note that for string controls
  127. this <structfield>size</structfield> field should not be confused with the length of the string.
  128. This field refers to the size of the memory that contains the string.
  129. The actual <emphasis>length</emphasis> of the string may well be much smaller.
  130. </entry>
  131. </row>
  132. <row>
  133. <entry>__u32</entry>
  134. <entry><structfield>reserved2</structfield>[1]</entry>
  135. <entry></entry>
  136. <entry>Reserved for future extensions. Drivers and
  137. applications must set the array to zero.</entry>
  138. </row>
  139. <row>
  140. <entry>union</entry>
  141. <entry>(anonymous)</entry>
  142. </row>
  143. <row>
  144. <entry></entry>
  145. <entry>__s32</entry>
  146. <entry><structfield>value</structfield></entry>
  147. <entry>New value or current value.</entry>
  148. </row>
  149. <row>
  150. <entry></entry>
  151. <entry>__s64</entry>
  152. <entry><structfield>value64</structfield></entry>
  153. <entry>New value or current value.</entry>
  154. </row>
  155. <row>
  156. <entry></entry>
  157. <entry>char *</entry>
  158. <entry><structfield>string</structfield></entry>
  159. <entry>A pointer to a string.</entry>
  160. </row>
  161. </tbody>
  162. </tgroup>
  163. </table>
  164. <table pgwide="1" frame="none" id="v4l2-ext-controls">
  165. <title>struct <structname>v4l2_ext_controls</structname></title>
  166. <tgroup cols="3">
  167. &cs-str;
  168. <tbody valign="top">
  169. <row>
  170. <entry>__u32</entry>
  171. <entry><structfield>ctrl_class</structfield></entry>
  172. <entry>The control class to which all controls belong, see
  173. <xref linkend="ctrl-class" />. Drivers that use a kernel framework for handling
  174. controls will also accept a value of 0 here, meaning that the controls can
  175. belong to any control class. Whether drivers support this can be tested by setting
  176. <structfield>ctrl_class</structfield> to 0 and calling <constant>VIDIOC_TRY_EXT_CTRLS</constant>
  177. with a <structfield>count</structfield> of 0. If that succeeds, then the driver
  178. supports this feature.</entry>
  179. </row>
  180. <row>
  181. <entry>__u32</entry>
  182. <entry><structfield>count</structfield></entry>
  183. <entry>The number of controls in the controls array. May
  184. also be zero.</entry>
  185. </row>
  186. <row>
  187. <entry>__u32</entry>
  188. <entry><structfield>error_idx</structfield></entry>
  189. <entry><para>Set by the driver in case of an error. If the error is
  190. associated with a particular control, then <structfield>error_idx</structfield>
  191. is set to the index of that control. If the error is not related to a specific
  192. control, or the validation step failed (see below), then
  193. <structfield>error_idx</structfield> is set to <structfield>count</structfield>.
  194. The value is undefined if the ioctl returned 0 (success).</para>
  195. <para>Before controls are read from/written to hardware a validation step
  196. takes place: this checks if all controls in the list are valid controls,
  197. if no attempt is made to write to a read-only control or read from a write-only
  198. control, and any other up-front checks that can be done without accessing the
  199. hardware. The exact validations done during this step are driver dependent
  200. since some checks might require hardware access for some devices, thus making
  201. it impossible to do those checks up-front. However, drivers should make a
  202. best-effort to do as many up-front checks as possible.</para>
  203. <para>This check is done to avoid leaving the hardware in an inconsistent state due
  204. to easy-to-avoid problems. But it leads to another problem: the application needs to
  205. know whether an error came from the validation step (meaning that the hardware
  206. was not touched) or from an error during the actual reading from/writing to hardware.</para>
  207. <para>The, in hindsight quite poor, solution for that is to set <structfield>error_idx</structfield>
  208. to <structfield>count</structfield> if the validation failed. This has the
  209. unfortunate side-effect that it is not possible to see which control failed the
  210. validation. If the validation was successful and the error happened while
  211. accessing the hardware, then <structfield>error_idx</structfield> is less than
  212. <structfield>count</structfield> and only the controls up to
  213. <structfield>error_idx-1</structfield> were read or written correctly, and the
  214. state of the remaining controls is undefined.</para>
  215. <para>Since <constant>VIDIOC_TRY_EXT_CTRLS</constant> does not access hardware
  216. there is also no need to handle the validation step in this special way,
  217. so <structfield>error_idx</structfield> will just be set to the control that
  218. failed the validation step instead of to <structfield>count</structfield>.
  219. This means that if <constant>VIDIOC_S_EXT_CTRLS</constant> fails with
  220. <structfield>error_idx</structfield> set to <structfield>count</structfield>,
  221. then you can call <constant>VIDIOC_TRY_EXT_CTRLS</constant> to try to discover
  222. the actual control that failed the validation step. Unfortunately, there
  223. is no <constant>TRY</constant> equivalent for <constant>VIDIOC_G_EXT_CTRLS</constant>.
  224. </para></entry>
  225. </row>
  226. <row>
  227. <entry>__u32</entry>
  228. <entry><structfield>reserved</structfield>[2]</entry>
  229. <entry>Reserved for future extensions. Drivers and
  230. applications must set the array to zero.</entry>
  231. </row>
  232. <row>
  233. <entry>&v4l2-ext-control; *</entry>
  234. <entry><structfield>controls</structfield></entry>
  235. <entry>Pointer to an array of
  236. <structfield>count</structfield> v4l2_ext_control structures. Ignored
  237. if <structfield>count</structfield> equals zero.</entry>
  238. </row>
  239. </tbody>
  240. </tgroup>
  241. </table>
  242. <table pgwide="1" frame="none" id="ctrl-class">
  243. <title>Control classes</title>
  244. <tgroup cols="3">
  245. &cs-def;
  246. <tbody valign="top">
  247. <row>
  248. <entry><constant>V4L2_CTRL_CLASS_USER</constant></entry>
  249. <entry>0x980000</entry>
  250. <entry>The class containing user controls. These controls
  251. are described in <xref linkend="control" />. All controls that can be set
  252. using the &VIDIOC-S-CTRL; and &VIDIOC-G-CTRL; ioctl belong to this
  253. class.</entry>
  254. </row>
  255. <row>
  256. <entry><constant>V4L2_CTRL_CLASS_MPEG</constant></entry>
  257. <entry>0x990000</entry>
  258. <entry>The class containing MPEG compression controls.
  259. These controls are described in <xref
  260. linkend="mpeg-controls" />.</entry>
  261. </row>
  262. <row>
  263. <entry><constant>V4L2_CTRL_CLASS_CAMERA</constant></entry>
  264. <entry>0x9a0000</entry>
  265. <entry>The class containing camera controls.
  266. These controls are described in <xref
  267. linkend="camera-controls" />.</entry>
  268. </row>
  269. <row>
  270. <entry><constant>V4L2_CTRL_CLASS_FM_TX</constant></entry>
  271. <entry>0x9b0000</entry>
  272. <entry>The class containing FM Transmitter (FM TX) controls.
  273. These controls are described in <xref
  274. linkend="fm-tx-controls" />.</entry>
  275. </row>
  276. <row>
  277. <entry><constant>V4L2_CTRL_CLASS_FLASH</constant></entry>
  278. <entry>0x9c0000</entry>
  279. <entry>The class containing flash device controls.
  280. These controls are described in <xref
  281. linkend="flash-controls" />.</entry>
  282. </row>
  283. <row>
  284. <entry><constant>V4L2_CTRL_CLASS_JPEG</constant></entry>
  285. <entry>0x9d0000</entry>
  286. <entry>The class containing JPEG compression controls.
  287. These controls are described in <xref
  288. linkend="jpeg-controls" />.</entry>
  289. </row>
  290. <row>
  291. <entry><constant>V4L2_CTRL_CLASS_IMAGE_SOURCE</constant></entry>
  292. <entry>0x9e0000</entry> <entry>The class containing image
  293. source controls. These controls are described in <xref
  294. linkend="image-source-controls" />.</entry>
  295. </row>
  296. <row>
  297. <entry><constant>V4L2_CTRL_CLASS_IMAGE_PROC</constant></entry>
  298. <entry>0x9f0000</entry> <entry>The class containing image
  299. processing controls. These controls are described in <xref
  300. linkend="image-process-controls" />.</entry>
  301. </row>
  302. </tbody>
  303. </tgroup>
  304. </table>
  305. </refsect1>
  306. <refsect1>
  307. &return-value;
  308. <variablelist>
  309. <varlistentry>
  310. <term><errorcode>EINVAL</errorcode></term>
  311. <listitem>
  312. <para>The &v4l2-ext-control; <structfield>id</structfield>
  313. is invalid, the &v4l2-ext-controls;
  314. <structfield>ctrl_class</structfield> is invalid, or the &v4l2-ext-control;
  315. <structfield>value</structfield> was inappropriate (e.g. the given menu
  316. index is not supported by the driver). This error code is
  317. also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and
  318. <constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctls if two or more
  319. control values are in conflict.</para>
  320. </listitem>
  321. </varlistentry>
  322. <varlistentry>
  323. <term><errorcode>ERANGE</errorcode></term>
  324. <listitem>
  325. <para>The &v4l2-ext-control; <structfield>value</structfield>
  326. is out of bounds.</para>
  327. </listitem>
  328. </varlistentry>
  329. <varlistentry>
  330. <term><errorcode>EBUSY</errorcode></term>
  331. <listitem>
  332. <para>The control is temporarily not changeable, possibly
  333. because another applications took over control of the device function
  334. this control belongs to.</para>
  335. </listitem>
  336. </varlistentry>
  337. <varlistentry>
  338. <term><errorcode>ENOSPC</errorcode></term>
  339. <listitem>
  340. <para>The space reserved for the control's payload is insufficient.
  341. The field <structfield>size</structfield> is set to a value that is enough
  342. to store the payload and this error code is returned.</para>
  343. </listitem>
  344. </varlistentry>
  345. <varlistentry>
  346. <term><errorcode>EACCES</errorcode></term>
  347. <listitem>
  348. <para>Attempt to try or set a read-only control or to get a
  349. write-only control.</para>
  350. </listitem>
  351. </varlistentry>
  352. </variablelist>
  353. </refsect1>
  354. </refentry>