common.xml 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. <title>Common API Elements</title>
  2. <para>Programming a V4L2 device consists of these
  3. steps:</para>
  4. <itemizedlist>
  5. <listitem>
  6. <para>Opening the device</para>
  7. </listitem>
  8. <listitem>
  9. <para>Changing device properties, selecting a video and audio
  10. input, video standard, picture brightness a.&nbsp;o.</para>
  11. </listitem>
  12. <listitem>
  13. <para>Negotiating a data format</para>
  14. </listitem>
  15. <listitem>
  16. <para>Negotiating an input/output method</para>
  17. </listitem>
  18. <listitem>
  19. <para>The actual input/output loop</para>
  20. </listitem>
  21. <listitem>
  22. <para>Closing the device</para>
  23. </listitem>
  24. </itemizedlist>
  25. <para>In practice most steps are optional and can be executed out of
  26. order. It depends on the V4L2 device type, you can read about the
  27. details in <xref linkend="devices" />. In this chapter we will discuss
  28. the basic concepts applicable to all devices.</para>
  29. <section id="open">
  30. <title>Opening and Closing Devices</title>
  31. <section>
  32. <title>Device Naming</title>
  33. <para>V4L2 drivers are implemented as kernel modules, loaded
  34. manually by the system administrator or automatically when a device is
  35. first discovered. The driver modules plug into the "videodev" kernel
  36. module. It provides helper functions and a common application
  37. interface specified in this document.</para>
  38. <para>Each driver thus loaded registers one or more device nodes
  39. with major number 81 and a minor number between 0 and 255. Minor numbers
  40. are allocated dynamically unless the kernel is compiled with the kernel
  41. option CONFIG_VIDEO_FIXED_MINOR_RANGES. In that case minor numbers are
  42. allocated in ranges depending on the device node type (video, radio, etc.).</para>
  43. <para>Many drivers support "video_nr", "radio_nr" or "vbi_nr"
  44. module options to select specific video/radio/vbi node numbers. This allows
  45. the user to request that the device node is named e.g. /dev/video5 instead
  46. of leaving it to chance. When the driver supports multiple devices of the same
  47. type more than one device node number can be assigned, separated by commas:
  48. <informalexample>
  49. <screen>
  50. &gt; modprobe mydriver video_nr=0,1 radio_nr=0,1</screen>
  51. </informalexample></para>
  52. <para>In <filename>/etc/modules.conf</filename> this may be
  53. written as: <informalexample>
  54. <screen>
  55. options mydriver video_nr=0,1 radio_nr=0,1
  56. </screen>
  57. </informalexample> When no device node number is given as module
  58. option the driver supplies a default.</para>
  59. <para>Normally udev will create the device nodes in /dev automatically
  60. for you. If udev is not installed, then you need to enable the
  61. CONFIG_VIDEO_FIXED_MINOR_RANGES kernel option in order to be able to correctly
  62. relate a minor number to a device node number. I.e., you need to be certain
  63. that minor number 5 maps to device node name video5. With this kernel option
  64. different device types have different minor number ranges. These ranges are
  65. listed in <xref linkend="devices" />.
  66. </para>
  67. <para>The creation of character special files (with
  68. <application>mknod</application>) is a privileged operation and
  69. devices cannot be opened by major and minor number. That means
  70. applications cannot <emphasis>reliable</emphasis> scan for loaded or
  71. installed drivers. The user must enter a device name, or the
  72. application can try the conventional device names.</para>
  73. </section>
  74. <section id="related">
  75. <title>Related Devices</title>
  76. <para>Devices can support several functions. For example
  77. video capturing, VBI capturing and radio support.</para>
  78. <para>The V4L2 API creates different nodes for each of these functions.</para>
  79. <para>The V4L2 API was designed with the idea that one device node could support
  80. all functions. However, in practice this never worked: this 'feature'
  81. was never used by applications and many drivers did not support it and if
  82. they did it was certainly never tested. In addition, switching a device
  83. node between different functions only works when using the streaming I/O
  84. API, not with the read()/write() API.</para>
  85. <para>Today each device node supports just one function.</para>
  86. <para>Besides video input or output the hardware may also
  87. support audio sampling or playback. If so, these functions are
  88. implemented as ALSA PCM devices with optional ALSA audio mixer
  89. devices.</para>
  90. <para>One problem with all these devices is that the V4L2 API
  91. makes no provisions to find these related devices. Some really
  92. complex devices use the Media Controller (see <xref linkend="media_controller" />)
  93. which can be used for this purpose. But most drivers do not use it,
  94. and while some code exists that uses sysfs to discover related devices
  95. (see libmedia_dev in the <ulink url="http://git.linuxtv.org/cgit.cgi/v4l-utils.git/">v4l-utils</ulink>
  96. git repository), there is no library yet that can provide a single API towards
  97. both Media Controller-based devices and devices that do not use the Media Controller.
  98. If you want to work on this please write to the linux-media mailing list: &v4l-ml;.</para>
  99. </section>
  100. <section>
  101. <title>Multiple Opens</title>
  102. <para>V4L2 devices can be opened more than once.<footnote><para>
  103. There are still some old and obscure drivers that have not been updated to
  104. allow for multiple opens. This implies that for such drivers &func-open; can
  105. return an &EBUSY; when the device is already in use.</para></footnote>
  106. When this is supported by the driver, users can for example start a
  107. "panel" application to change controls like brightness or audio
  108. volume, while another application captures video and audio. In other words, panel
  109. applications are comparable to an ALSA audio mixer application.
  110. Just opening a V4L2 device should not change the state of the device.<footnote>
  111. <para>Unfortunately, opening a radio device often switches the state of the
  112. device to radio mode in many drivers. This behavior should be fixed eventually
  113. as it violates the V4L2 specification.</para></footnote></para>
  114. <para>Once an application has allocated the memory buffers needed for
  115. streaming data (by calling the &VIDIOC-REQBUFS; or &VIDIOC-CREATE-BUFS; ioctls,
  116. or implicitly by calling the &func-read; or &func-write; functions) that
  117. application (filehandle) becomes the owner of the device. It is no longer
  118. allowed to make changes that would affect the buffer sizes (e.g. by calling
  119. the &VIDIOC-S-FMT; ioctl) and other applications are no longer allowed to allocate
  120. buffers or start or stop streaming. The &EBUSY; will be returned instead.</para>
  121. <para>Merely opening a V4L2 device does not grant exclusive
  122. access.<footnote>
  123. <para>Drivers could recognize the
  124. <constant>O_EXCL</constant> open flag. Presently this is not required,
  125. so applications cannot know if it really works.</para>
  126. </footnote> Initiating data exchange however assigns the right
  127. to read or write the requested type of data, and to change related
  128. properties, to this file descriptor. Applications can request
  129. additional access privileges using the priority mechanism described in
  130. <xref linkend="app-pri" />.</para>
  131. </section>
  132. <section>
  133. <title>Shared Data Streams</title>
  134. <para>V4L2 drivers should not support multiple applications
  135. reading or writing the same data stream on a device by copying
  136. buffers, time multiplexing or similar means. This is better handled by
  137. a proxy application in user space.</para>
  138. </section>
  139. <section>
  140. <title>Functions</title>
  141. <para>To open and close V4L2 devices applications use the
  142. &func-open; and &func-close; function, respectively. Devices are
  143. programmed using the &func-ioctl; function as explained in the
  144. following sections.</para>
  145. </section>
  146. </section>
  147. <section id="querycap">
  148. <title>Querying Capabilities</title>
  149. <para>Because V4L2 covers a wide variety of devices not all
  150. aspects of the API are equally applicable to all types of devices.
  151. Furthermore devices of the same type have different capabilities and
  152. this specification permits the omission of a few complicated and less
  153. important parts of the API.</para>
  154. <para>The &VIDIOC-QUERYCAP; ioctl is available to check if the kernel
  155. device is compatible with this specification, and to query the <link
  156. linkend="devices">functions</link> and <link linkend="io">I/O
  157. methods</link> supported by the device.</para>
  158. <para>Starting with kernel version 3.1, VIDIOC-QUERYCAP will return the
  159. V4L2 API version used by the driver, with generally matches the Kernel version.
  160. There's no need of using &VIDIOC-QUERYCAP; to check if a specific ioctl is
  161. supported, the V4L2 core now returns ENOTTY if a driver doesn't provide
  162. support for an ioctl.</para>
  163. <para>Other features can be queried
  164. by calling the respective ioctl, for example &VIDIOC-ENUMINPUT;
  165. to learn about the number, types and names of video connectors on the
  166. device. Although abstraction is a major objective of this API, the
  167. &VIDIOC-QUERYCAP; ioctl also allows driver specific applications to reliably identify
  168. the driver.</para>
  169. <para>All V4L2 drivers must support
  170. <constant>VIDIOC_QUERYCAP</constant>. Applications should always call
  171. this ioctl after opening the device.</para>
  172. </section>
  173. <section id="app-pri">
  174. <title>Application Priority</title>
  175. <para>When multiple applications share a device it may be
  176. desirable to assign them different priorities. Contrary to the
  177. traditional "rm -rf /" school of thought a video recording application
  178. could for example block other applications from changing video
  179. controls or switching the current TV channel. Another objective is to
  180. permit low priority applications working in background, which can be
  181. preempted by user controlled applications and automatically regain
  182. control of the device at a later time.</para>
  183. <para>Since these features cannot be implemented entirely in user
  184. space V4L2 defines the &VIDIOC-G-PRIORITY; and &VIDIOC-S-PRIORITY;
  185. ioctls to request and query the access priority associate with a file
  186. descriptor. Opening a device assigns a medium priority, compatible
  187. with earlier versions of V4L2 and drivers not supporting these ioctls.
  188. Applications requiring a different priority will usually call
  189. <constant>VIDIOC_S_PRIORITY</constant> after verifying the device with
  190. the &VIDIOC-QUERYCAP; ioctl.</para>
  191. <para>Ioctls changing driver properties, such as &VIDIOC-S-INPUT;,
  192. return an &EBUSY; after another application obtained higher priority.</para>
  193. </section>
  194. <section id="video">
  195. <title>Video Inputs and Outputs</title>
  196. <para>Video inputs and outputs are physical connectors of a
  197. device. These can be for example RF connectors (antenna/cable), CVBS
  198. a.k.a. Composite Video, S-Video or RGB connectors. Video and VBI
  199. capture devices have inputs. Video and VBI output devices have outputs,
  200. at least one each. Radio devices have no video inputs or outputs.</para>
  201. <para>To learn about the number and attributes of the
  202. available inputs and outputs applications can enumerate them with the
  203. &VIDIOC-ENUMINPUT; and &VIDIOC-ENUMOUTPUT; ioctl, respectively. The
  204. &v4l2-input; returned by the <constant>VIDIOC_ENUMINPUT</constant>
  205. ioctl also contains signal status information applicable when the
  206. current video input is queried.</para>
  207. <para>The &VIDIOC-G-INPUT; and &VIDIOC-G-OUTPUT; ioctls return the
  208. index of the current video input or output. To select a different
  209. input or output applications call the &VIDIOC-S-INPUT; and
  210. &VIDIOC-S-OUTPUT; ioctls. Drivers must implement all the input ioctls
  211. when the device has one or more inputs, all the output ioctls when the
  212. device has one or more outputs.</para>
  213. <example>
  214. <title>Information about the current video input</title>
  215. <programlisting>
  216. &v4l2-input; input;
  217. int index;
  218. if (-1 == ioctl(fd, &VIDIOC-G-INPUT;, &amp;index)) {
  219. perror("VIDIOC_G_INPUT");
  220. exit(EXIT_FAILURE);
  221. }
  222. memset(&amp;input, 0, sizeof(input));
  223. input.index = index;
  224. if (-1 == ioctl(fd, &VIDIOC-ENUMINPUT;, &amp;input)) {
  225. perror("VIDIOC_ENUMINPUT");
  226. exit(EXIT_FAILURE);
  227. }
  228. printf("Current input: %s\n", input.name);
  229. </programlisting>
  230. </example>
  231. <example>
  232. <title>Switching to the first video input</title>
  233. <programlisting>
  234. int index;
  235. index = 0;
  236. if (-1 == ioctl(fd, &VIDIOC-S-INPUT;, &amp;index)) {
  237. perror("VIDIOC_S_INPUT");
  238. exit(EXIT_FAILURE);
  239. }
  240. </programlisting>
  241. </example>
  242. </section>
  243. <section id="audio">
  244. <title>Audio Inputs and Outputs</title>
  245. <para>Audio inputs and outputs are physical connectors of a
  246. device. Video capture devices have inputs, output devices have
  247. outputs, zero or more each. Radio devices have no audio inputs or
  248. outputs. They have exactly one tuner which in fact
  249. <emphasis>is</emphasis> an audio source, but this API associates
  250. tuners with video inputs or outputs only, and radio devices have
  251. none of these.<footnote>
  252. <para>Actually &v4l2-audio; ought to have a
  253. <structfield>tuner</structfield> field like &v4l2-input;, not only
  254. making the API more consistent but also permitting radio devices with
  255. multiple tuners.</para>
  256. </footnote> A connector on a TV card to loop back the received
  257. audio signal to a sound card is not considered an audio output.</para>
  258. <para>Audio and video inputs and outputs are associated. Selecting
  259. a video source also selects an audio source. This is most evident when
  260. the video and audio source is a tuner. Further audio connectors can
  261. combine with more than one video input or output. Assumed two
  262. composite video inputs and two audio inputs exist, there may be up to
  263. four valid combinations. The relation of video and audio connectors
  264. is defined in the <structfield>audioset</structfield> field of the
  265. respective &v4l2-input; or &v4l2-output;, where each bit represents
  266. the index number, starting at zero, of one audio input or output.</para>
  267. <para>To learn about the number and attributes of the
  268. available inputs and outputs applications can enumerate them with the
  269. &VIDIOC-ENUMAUDIO; and &VIDIOC-ENUMAUDOUT; ioctl, respectively. The
  270. &v4l2-audio; returned by the <constant>VIDIOC_ENUMAUDIO</constant> ioctl
  271. also contains signal status information applicable when the current
  272. audio input is queried.</para>
  273. <para>The &VIDIOC-G-AUDIO; and &VIDIOC-G-AUDOUT; ioctls report
  274. the current audio input and output, respectively. Note that, unlike
  275. &VIDIOC-G-INPUT; and &VIDIOC-G-OUTPUT; these ioctls return a structure
  276. as <constant>VIDIOC_ENUMAUDIO</constant> and
  277. <constant>VIDIOC_ENUMAUDOUT</constant> do, not just an index.</para>
  278. <para>To select an audio input and change its properties
  279. applications call the &VIDIOC-S-AUDIO; ioctl. To select an audio
  280. output (which presently has no changeable properties) applications
  281. call the &VIDIOC-S-AUDOUT; ioctl.</para>
  282. <para>Drivers must implement all audio input ioctls when the device
  283. has multiple selectable audio inputs, all audio output ioctls when the
  284. device has multiple selectable audio outputs. When the device has any
  285. audio inputs or outputs the driver must set the <constant>V4L2_CAP_AUDIO</constant>
  286. flag in the &v4l2-capability; returned by the &VIDIOC-QUERYCAP; ioctl.</para>
  287. <example>
  288. <title>Information about the current audio input</title>
  289. <programlisting>
  290. &v4l2-audio; audio;
  291. memset(&amp;audio, 0, sizeof(audio));
  292. if (-1 == ioctl(fd, &VIDIOC-G-AUDIO;, &amp;audio)) {
  293. perror("VIDIOC_G_AUDIO");
  294. exit(EXIT_FAILURE);
  295. }
  296. printf("Current input: %s\n", audio.name);
  297. </programlisting>
  298. </example>
  299. <example>
  300. <title>Switching to the first audio input</title>
  301. <programlisting>
  302. &v4l2-audio; audio;
  303. memset(&amp;audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */
  304. audio.index = 0;
  305. if (-1 == ioctl(fd, &VIDIOC-S-AUDIO;, &amp;audio)) {
  306. perror("VIDIOC_S_AUDIO");
  307. exit(EXIT_FAILURE);
  308. }
  309. </programlisting>
  310. </example>
  311. </section>
  312. <section id="tuner">
  313. <title>Tuners and Modulators</title>
  314. <section>
  315. <title>Tuners</title>
  316. <para>Video input devices can have one or more tuners
  317. demodulating a RF signal. Each tuner is associated with one or more
  318. video inputs, depending on the number of RF connectors on the tuner.
  319. The <structfield>type</structfield> field of the respective
  320. &v4l2-input; returned by the &VIDIOC-ENUMINPUT; ioctl is set to
  321. <constant>V4L2_INPUT_TYPE_TUNER</constant> and its
  322. <structfield>tuner</structfield> field contains the index number of
  323. the tuner.</para>
  324. <para>Radio input devices have exactly one tuner with index zero, no
  325. video inputs.</para>
  326. <para>To query and change tuner properties applications use the
  327. &VIDIOC-G-TUNER; and &VIDIOC-S-TUNER; ioctls, respectively. The
  328. &v4l2-tuner; returned by <constant>VIDIOC_G_TUNER</constant> also
  329. contains signal status information applicable when the tuner of the
  330. current video or radio input is queried. Note that
  331. <constant>VIDIOC_S_TUNER</constant> does not switch the current tuner,
  332. when there is more than one at all. The tuner is solely determined by
  333. the current video input. Drivers must support both ioctls and set the
  334. <constant>V4L2_CAP_TUNER</constant> flag in the &v4l2-capability;
  335. returned by the &VIDIOC-QUERYCAP; ioctl when the device has one or
  336. more tuners.</para>
  337. </section>
  338. <section>
  339. <title>Modulators</title>
  340. <para>Video output devices can have one or more modulators, uh,
  341. modulating a video signal for radiation or connection to the antenna
  342. input of a TV set or video recorder. Each modulator is associated with
  343. one or more video outputs, depending on the number of RF connectors on
  344. the modulator. The <structfield>type</structfield> field of the
  345. respective &v4l2-output; returned by the &VIDIOC-ENUMOUTPUT; ioctl is
  346. set to <constant>V4L2_OUTPUT_TYPE_MODULATOR</constant> and its
  347. <structfield>modulator</structfield> field contains the index number
  348. of the modulator.</para>
  349. <para>Radio output devices have exactly one modulator with index
  350. zero, no video outputs.</para>
  351. <para>A video or radio device cannot support both a tuner and a
  352. modulator. Two separate device nodes will have to be used for such
  353. hardware, one that supports the tuner functionality and one that supports
  354. the modulator functionality. The reason is a limitation with the
  355. &VIDIOC-S-FREQUENCY; ioctl where you cannot specify whether the frequency
  356. is for a tuner or a modulator.</para>
  357. <para>To query and change modulator properties applications use
  358. the &VIDIOC-G-MODULATOR; and &VIDIOC-S-MODULATOR; ioctl. Note that
  359. <constant>VIDIOC_S_MODULATOR</constant> does not switch the current
  360. modulator, when there is more than one at all. The modulator is solely
  361. determined by the current video output. Drivers must support both
  362. ioctls and set the <constant>V4L2_CAP_MODULATOR</constant> flag in
  363. the &v4l2-capability; returned by the &VIDIOC-QUERYCAP; ioctl when the
  364. device has one or more modulators.</para>
  365. </section>
  366. <section>
  367. <title>Radio Frequency</title>
  368. <para>To get and set the tuner or modulator radio frequency
  369. applications use the &VIDIOC-G-FREQUENCY; and &VIDIOC-S-FREQUENCY;
  370. ioctl which both take a pointer to a &v4l2-frequency;. These ioctls
  371. are used for TV and radio devices alike. Drivers must support both
  372. ioctls when the tuner or modulator ioctls are supported, or
  373. when the device is a radio device.</para>
  374. </section>
  375. </section>
  376. <section id="standard">
  377. <title>Video Standards</title>
  378. <para>Video devices typically support one or more different video
  379. standards or variations of standards. Each video input and output may
  380. support another set of standards. This set is reported by the
  381. <structfield>std</structfield> field of &v4l2-input; and
  382. &v4l2-output; returned by the &VIDIOC-ENUMINPUT; and
  383. &VIDIOC-ENUMOUTPUT; ioctls, respectively.</para>
  384. <para>V4L2 defines one bit for each analog video standard
  385. currently in use worldwide, and sets aside bits for driver defined
  386. standards, &eg; hybrid standards to watch NTSC video tapes on PAL TVs
  387. and vice versa. Applications can use the predefined bits to select a
  388. particular standard, although presenting the user a menu of supported
  389. standards is preferred. To enumerate and query the attributes of the
  390. supported standards applications use the &VIDIOC-ENUMSTD; ioctl.</para>
  391. <para>Many of the defined standards are actually just variations
  392. of a few major standards. The hardware may in fact not distinguish
  393. between them, or do so internal and switch automatically. Therefore
  394. enumerated standards also contain sets of one or more standard
  395. bits.</para>
  396. <para>Assume a hypothetic tuner capable of demodulating B/PAL,
  397. G/PAL and I/PAL signals. The first enumerated standard is a set of B
  398. and G/PAL, switched automatically depending on the selected radio
  399. frequency in UHF or VHF band. Enumeration gives a "PAL-B/G" or "PAL-I"
  400. choice. Similar a Composite input may collapse standards, enumerating
  401. "PAL-B/G/H/I", "NTSC-M" and "SECAM-D/K".<footnote>
  402. <para>Some users are already confused by technical terms PAL,
  403. NTSC and SECAM. There is no point asking them to distinguish between
  404. B, G, D, or K when the software or hardware can do that
  405. automatically.</para>
  406. </footnote></para>
  407. <para>To query and select the standard used by the current video
  408. input or output applications call the &VIDIOC-G-STD; and
  409. &VIDIOC-S-STD; ioctl, respectively. The <emphasis>received</emphasis>
  410. standard can be sensed with the &VIDIOC-QUERYSTD; ioctl. Note that the
  411. parameter of all these ioctls is a pointer to a &v4l2-std-id; type
  412. (a standard set), <emphasis>not</emphasis> an index into the standard
  413. enumeration. Drivers must implement all video standard ioctls
  414. when the device has one or more video inputs or outputs.</para>
  415. <para>Special rules apply to devices such as USB cameras where the notion of video
  416. standards makes little sense. More generally for any capture or output device
  417. which is: <itemizedlist>
  418. <listitem>
  419. <para>incapable of capturing fields or frames at the nominal
  420. rate of the video standard, or</para>
  421. </listitem>
  422. <listitem>
  423. <para>that does not support the video standard formats at all.</para>
  424. </listitem>
  425. </itemizedlist> Here the driver shall set the
  426. <structfield>std</structfield> field of &v4l2-input; and &v4l2-output;
  427. to zero and the <constant>VIDIOC_G_STD</constant>,
  428. <constant>VIDIOC_S_STD</constant>,
  429. <constant>VIDIOC_QUERYSTD</constant> and
  430. <constant>VIDIOC_ENUMSTD</constant> ioctls shall return the
  431. &ENOTTY; or the &EINVAL;.</para>
  432. <para>Applications can make use of the <xref linkend="input-capabilities" /> and
  433. <xref linkend="output-capabilities"/> flags to determine whether the video standard ioctls
  434. can be used with the given input or output.</para>
  435. <example>
  436. <title>Information about the current video standard</title>
  437. <programlisting>
  438. &v4l2-std-id; std_id;
  439. &v4l2-standard; standard;
  440. if (-1 == ioctl(fd, &VIDIOC-G-STD;, &amp;std_id)) {
  441. /* Note when VIDIOC_ENUMSTD always returns ENOTTY this
  442. is no video device or it falls under the USB exception,
  443. and VIDIOC_G_STD returning ENOTTY is no error. */
  444. perror("VIDIOC_G_STD");
  445. exit(EXIT_FAILURE);
  446. }
  447. memset(&amp;standard, 0, sizeof(standard));
  448. standard.index = 0;
  449. while (0 == ioctl(fd, &VIDIOC-ENUMSTD;, &amp;standard)) {
  450. if (standard.id &amp; std_id) {
  451. printf("Current video standard: %s\n", standard.name);
  452. exit(EXIT_SUCCESS);
  453. }
  454. standard.index++;
  455. }
  456. /* EINVAL indicates the end of the enumeration, which cannot be
  457. empty unless this device falls under the USB exception. */
  458. if (errno == EINVAL || standard.index == 0) {
  459. perror("VIDIOC_ENUMSTD");
  460. exit(EXIT_FAILURE);
  461. }
  462. </programlisting>
  463. </example>
  464. <example>
  465. <title>Listing the video standards supported by the current
  466. input</title>
  467. <programlisting>
  468. &v4l2-input; input;
  469. &v4l2-standard; standard;
  470. memset(&amp;input, 0, sizeof(input));
  471. if (-1 == ioctl(fd, &VIDIOC-G-INPUT;, &amp;input.index)) {
  472. perror("VIDIOC_G_INPUT");
  473. exit(EXIT_FAILURE);
  474. }
  475. if (-1 == ioctl(fd, &VIDIOC-ENUMINPUT;, &amp;input)) {
  476. perror("VIDIOC_ENUM_INPUT");
  477. exit(EXIT_FAILURE);
  478. }
  479. printf("Current input %s supports:\n", input.name);
  480. memset(&amp;standard, 0, sizeof(standard));
  481. standard.index = 0;
  482. while (0 == ioctl(fd, &VIDIOC-ENUMSTD;, &amp;standard)) {
  483. if (standard.id &amp; input.std)
  484. printf("%s\n", standard.name);
  485. standard.index++;
  486. }
  487. /* EINVAL indicates the end of the enumeration, which cannot be
  488. empty unless this device falls under the USB exception. */
  489. if (errno != EINVAL || standard.index == 0) {
  490. perror("VIDIOC_ENUMSTD");
  491. exit(EXIT_FAILURE);
  492. }
  493. </programlisting>
  494. </example>
  495. <example>
  496. <title>Selecting a new video standard</title>
  497. <programlisting>
  498. &v4l2-input; input;
  499. &v4l2-std-id; std_id;
  500. memset(&amp;input, 0, sizeof(input));
  501. if (-1 == ioctl(fd, &VIDIOC-G-INPUT;, &amp;input.index)) {
  502. perror("VIDIOC_G_INPUT");
  503. exit(EXIT_FAILURE);
  504. }
  505. if (-1 == ioctl(fd, &VIDIOC-ENUMINPUT;, &amp;input)) {
  506. perror("VIDIOC_ENUM_INPUT");
  507. exit(EXIT_FAILURE);
  508. }
  509. if (0 == (input.std &amp; V4L2_STD_PAL_BG)) {
  510. fprintf(stderr, "Oops. B/G PAL is not supported.\n");
  511. exit(EXIT_FAILURE);
  512. }
  513. /* Note this is also supposed to work when only B
  514. <emphasis>or</emphasis> G/PAL is supported. */
  515. std_id = V4L2_STD_PAL_BG;
  516. if (-1 == ioctl(fd, &VIDIOC-S-STD;, &amp;std_id)) {
  517. perror("VIDIOC_S_STD");
  518. exit(EXIT_FAILURE);
  519. }
  520. </programlisting>
  521. </example>
  522. </section>
  523. <section id="dv-timings">
  524. <title>Digital Video (DV) Timings</title>
  525. <para>
  526. The video standards discussed so far have been dealing with Analog TV and the
  527. corresponding video timings. Today there are many more different hardware interfaces
  528. such as High Definition TV interfaces (HDMI), VGA, DVI connectors etc., that carry
  529. video signals and there is a need to extend the API to select the video timings
  530. for these interfaces. Since it is not possible to extend the &v4l2-std-id; due to
  531. the limited bits available, a new set of ioctls was added to set/get video timings at
  532. the input and output.</para>
  533. <para>These ioctls deal with the detailed digital video timings that define
  534. each video format. This includes parameters such as the active video width and height,
  535. signal polarities, frontporches, backporches, sync widths etc. The <filename>linux/v4l2-dv-timings.h</filename>
  536. header can be used to get the timings of the formats in the <xref linkend="cea861" /> and
  537. <xref linkend="vesadmt" /> standards.
  538. </para>
  539. <para>To enumerate and query the attributes of the DV timings supported by a device
  540. applications use the &VIDIOC-ENUM-DV-TIMINGS; and &VIDIOC-DV-TIMINGS-CAP; ioctls.
  541. To set DV timings for the device applications use the
  542. &VIDIOC-S-DV-TIMINGS; ioctl and to get current DV timings they use the
  543. &VIDIOC-G-DV-TIMINGS; ioctl. To detect the DV timings as seen by the video receiver applications
  544. use the &VIDIOC-QUERY-DV-TIMINGS; ioctl.</para>
  545. <para>Applications can make use of the <xref linkend="input-capabilities" /> and
  546. <xref linkend="output-capabilities"/> flags to determine whether the digital video ioctls
  547. can be used with the given input or output.</para>
  548. </section>
  549. &sub-controls;
  550. <section id="format">
  551. <title>Data Formats</title>
  552. <section>
  553. <title>Data Format Negotiation</title>
  554. <para>Different devices exchange different kinds of data with
  555. applications, for example video images, raw or sliced VBI data, RDS
  556. datagrams. Even within one kind many different formats are possible,
  557. in particular an abundance of image formats. Although drivers must
  558. provide a default and the selection persists across closing and
  559. reopening a device, applications should always negotiate a data format
  560. before engaging in data exchange. Negotiation means the application
  561. asks for a particular format and the driver selects and reports the
  562. best the hardware can do to satisfy the request. Of course
  563. applications can also just query the current selection.</para>
  564. <para>A single mechanism exists to negotiate all data formats
  565. using the aggregate &v4l2-format; and the &VIDIOC-G-FMT; and
  566. &VIDIOC-S-FMT; ioctls. Additionally the &VIDIOC-TRY-FMT; ioctl can be
  567. used to examine what the hardware <emphasis>could</emphasis> do,
  568. without actually selecting a new data format. The data formats
  569. supported by the V4L2 API are covered in the respective device section
  570. in <xref linkend="devices" />. For a closer look at image formats see
  571. <xref linkend="pixfmt" />.</para>
  572. <para>The <constant>VIDIOC_S_FMT</constant> ioctl is a major
  573. turning-point in the initialization sequence. Prior to this point
  574. multiple panel applications can access the same device concurrently to
  575. select the current input, change controls or modify other properties.
  576. The first <constant>VIDIOC_S_FMT</constant> assigns a logical stream
  577. (video data, VBI data etc.) exclusively to one file descriptor.</para>
  578. <para>Exclusive means no other application, more precisely no
  579. other file descriptor, can grab this stream or change device
  580. properties inconsistent with the negotiated parameters. A video
  581. standard change for example, when the new standard uses a different
  582. number of scan lines, can invalidate the selected image format.
  583. Therefore only the file descriptor owning the stream can make
  584. invalidating changes. Accordingly multiple file descriptors which
  585. grabbed different logical streams prevent each other from interfering
  586. with their settings. When for example video overlay is about to start
  587. or already in progress, simultaneous video capturing may be restricted
  588. to the same cropping and image size.</para>
  589. <para>When applications omit the
  590. <constant>VIDIOC_S_FMT</constant> ioctl its locking side effects are
  591. implied by the next step, the selection of an I/O method with the
  592. &VIDIOC-REQBUFS; ioctl or implicit with the first &func-read; or
  593. &func-write; call.</para>
  594. <para>Generally only one logical stream can be assigned to a
  595. file descriptor, the exception being drivers permitting simultaneous
  596. video capturing and overlay using the same file descriptor for
  597. compatibility with V4L and earlier versions of V4L2. Switching the
  598. logical stream or returning into "panel mode" is possible by closing
  599. and reopening the device. Drivers <emphasis>may</emphasis> support a
  600. switch using <constant>VIDIOC_S_FMT</constant>.</para>
  601. <para>All drivers exchanging data with
  602. applications must support the <constant>VIDIOC_G_FMT</constant> and
  603. <constant>VIDIOC_S_FMT</constant> ioctl. Implementation of the
  604. <constant>VIDIOC_TRY_FMT</constant> is highly recommended but
  605. optional.</para>
  606. </section>
  607. <section>
  608. <title>Image Format Enumeration</title>
  609. <para>Apart of the generic format negotiation functions
  610. a special ioctl to enumerate all image formats supported by video
  611. capture, overlay or output devices is available.<footnote>
  612. <para>Enumerating formats an application has no a-priori
  613. knowledge of (otherwise it could explicitly ask for them and need not
  614. enumerate) seems useless, but there are applications serving as proxy
  615. between drivers and the actual video applications for which this is
  616. useful.</para>
  617. </footnote></para>
  618. <para>The &VIDIOC-ENUM-FMT; ioctl must be supported
  619. by all drivers exchanging image data with applications.</para>
  620. <important>
  621. <para>Drivers are not supposed to convert image formats in
  622. kernel space. They must enumerate only formats directly supported by
  623. the hardware. If necessary driver writers should publish an example
  624. conversion routine or library for integration into applications.</para>
  625. </important>
  626. </section>
  627. </section>
  628. &sub-planar-apis;
  629. <section id="crop">
  630. <title>Image Cropping, Insertion and Scaling</title>
  631. <para>Some video capture devices can sample a subsection of the
  632. picture and shrink or enlarge it to an image of arbitrary size. We
  633. call these abilities cropping and scaling. Some video output devices
  634. can scale an image up or down and insert it at an arbitrary scan line
  635. and horizontal offset into a video signal.</para>
  636. <para>Applications can use the following API to select an area in
  637. the video signal, query the default area and the hardware limits.
  638. <emphasis>Despite their name, the &VIDIOC-CROPCAP;, &VIDIOC-G-CROP;
  639. and &VIDIOC-S-CROP; ioctls apply to input as well as output
  640. devices.</emphasis></para>
  641. <para>Scaling requires a source and a target. On a video capture
  642. or overlay device the source is the video signal, and the cropping
  643. ioctls determine the area actually sampled. The target are images
  644. read by the application or overlaid onto the graphics screen. Their
  645. size (and position for an overlay) is negotiated with the
  646. &VIDIOC-G-FMT; and &VIDIOC-S-FMT; ioctls.</para>
  647. <para>On a video output device the source are the images passed in
  648. by the application, and their size is again negotiated with the
  649. <constant>VIDIOC_G/S_FMT</constant> ioctls, or may be encoded in a
  650. compressed video stream. The target is the video signal, and the
  651. cropping ioctls determine the area where the images are
  652. inserted.</para>
  653. <para>Source and target rectangles are defined even if the device
  654. does not support scaling or the <constant>VIDIOC_G/S_CROP</constant>
  655. ioctls. Their size (and position where applicable) will be fixed in
  656. this case. <emphasis>All capture and output device must support the
  657. <constant>VIDIOC_CROPCAP</constant> ioctl such that applications can
  658. determine if scaling takes place.</emphasis></para>
  659. <section>
  660. <title>Cropping Structures</title>
  661. <figure id="crop-scale">
  662. <title>Image Cropping, Insertion and Scaling</title>
  663. <mediaobject>
  664. <imageobject>
  665. <imagedata fileref="crop.pdf" format="PS" />
  666. </imageobject>
  667. <imageobject>
  668. <imagedata fileref="crop.gif" format="GIF" />
  669. </imageobject>
  670. <textobject>
  671. <phrase>The cropping, insertion and scaling process</phrase>
  672. </textobject>
  673. </mediaobject>
  674. </figure>
  675. <para>For capture devices the coordinates of the top left
  676. corner, width and height of the area which can be sampled is given by
  677. the <structfield>bounds</structfield> substructure of the
  678. &v4l2-cropcap; returned by the <constant>VIDIOC_CROPCAP</constant>
  679. ioctl. To support a wide range of hardware this specification does not
  680. define an origin or units. However by convention drivers should
  681. horizontally count unscaled samples relative to 0H (the leading edge
  682. of the horizontal sync pulse, see <xref linkend="vbi-hsync" />).
  683. Vertically ITU-R line
  684. numbers of the first field (<xref linkend="vbi-525" />, <xref
  685. linkend="vbi-625" />), multiplied by two if the driver can capture both
  686. fields.</para>
  687. <para>The top left corner, width and height of the source
  688. rectangle, that is the area actually sampled, is given by &v4l2-crop;
  689. using the same coordinate system as &v4l2-cropcap;. Applications can
  690. use the <constant>VIDIOC_G_CROP</constant> and
  691. <constant>VIDIOC_S_CROP</constant> ioctls to get and set this
  692. rectangle. It must lie completely within the capture boundaries and
  693. the driver may further adjust the requested size and/or position
  694. according to hardware limitations.</para>
  695. <para>Each capture device has a default source rectangle, given
  696. by the <structfield>defrect</structfield> substructure of
  697. &v4l2-cropcap;. The center of this rectangle shall align with the
  698. center of the active picture area of the video signal, and cover what
  699. the driver writer considers the complete picture. Drivers shall reset
  700. the source rectangle to the default when the driver is first loaded,
  701. but not later.</para>
  702. <para>For output devices these structures and ioctls are used
  703. accordingly, defining the <emphasis>target</emphasis> rectangle where
  704. the images will be inserted into the video signal.</para>
  705. </section>
  706. <section>
  707. <title>Scaling Adjustments</title>
  708. <para>Video hardware can have various cropping, insertion and
  709. scaling limitations. It may only scale up or down, support only
  710. discrete scaling factors, or have different scaling abilities in
  711. horizontal and vertical direction. Also it may not support scaling at
  712. all. At the same time the &v4l2-crop; rectangle may have to be
  713. aligned, and both the source and target rectangles may have arbitrary
  714. upper and lower size limits. In particular the maximum
  715. <structfield>width</structfield> and <structfield>height</structfield>
  716. in &v4l2-crop; may be smaller than the
  717. &v4l2-cropcap;.<structfield>bounds</structfield> area. Therefore, as
  718. usual, drivers are expected to adjust the requested parameters and
  719. return the actual values selected.</para>
  720. <para>Applications can change the source or the target rectangle
  721. first, as they may prefer a particular image size or a certain area in
  722. the video signal. If the driver has to adjust both to satisfy hardware
  723. limitations, the last requested rectangle shall take priority, and the
  724. driver should preferably adjust the opposite one. The &VIDIOC-TRY-FMT;
  725. ioctl however shall not change the driver state and therefore only
  726. adjust the requested rectangle.</para>
  727. <para>Suppose scaling on a video capture device is restricted to
  728. a factor 1:1 or 2:1 in either direction and the target image size must
  729. be a multiple of 16&nbsp;&times;&nbsp;16 pixels. The source cropping
  730. rectangle is set to defaults, which are also the upper limit in this
  731. example, of 640&nbsp;&times;&nbsp;400 pixels at offset 0,&nbsp;0. An
  732. application requests an image size of 300&nbsp;&times;&nbsp;225
  733. pixels, assuming video will be scaled down from the "full picture"
  734. accordingly. The driver sets the image size to the closest possible
  735. values 304&nbsp;&times;&nbsp;224, then chooses the cropping rectangle
  736. closest to the requested size, that is 608&nbsp;&times;&nbsp;224
  737. (224&nbsp;&times;&nbsp;2:1 would exceed the limit 400). The offset
  738. 0,&nbsp;0 is still valid, thus unmodified. Given the default cropping
  739. rectangle reported by <constant>VIDIOC_CROPCAP</constant> the
  740. application can easily propose another offset to center the cropping
  741. rectangle.</para>
  742. <para>Now the application may insist on covering an area using a
  743. picture aspect ratio closer to the original request, so it asks for a
  744. cropping rectangle of 608&nbsp;&times;&nbsp;456 pixels. The present
  745. scaling factors limit cropping to 640&nbsp;&times;&nbsp;384, so the
  746. driver returns the cropping size 608&nbsp;&times;&nbsp;384 and adjusts
  747. the image size to closest possible 304&nbsp;&times;&nbsp;192.</para>
  748. </section>
  749. <section>
  750. <title>Examples</title>
  751. <para>Source and target rectangles shall remain unchanged across
  752. closing and reopening a device, such that piping data into or out of a
  753. device will work without special preparations. More advanced
  754. applications should ensure the parameters are suitable before starting
  755. I/O.</para>
  756. <example>
  757. <title>Resetting the cropping parameters</title>
  758. <para>(A video capture device is assumed; change
  759. <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant> for other
  760. devices.)</para>
  761. <programlisting>
  762. &v4l2-cropcap; cropcap;
  763. &v4l2-crop; crop;
  764. memset (&amp;cropcap, 0, sizeof (cropcap));
  765. cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  766. if (-1 == ioctl (fd, &VIDIOC-CROPCAP;, &amp;cropcap)) {
  767. perror ("VIDIOC_CROPCAP");
  768. exit (EXIT_FAILURE);
  769. }
  770. memset (&amp;crop, 0, sizeof (crop));
  771. crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  772. crop.c = cropcap.defrect;
  773. /* Ignore if cropping is not supported (EINVAL). */
  774. if (-1 == ioctl (fd, &VIDIOC-S-CROP;, &amp;crop)
  775. &amp;&amp; errno != EINVAL) {
  776. perror ("VIDIOC_S_CROP");
  777. exit (EXIT_FAILURE);
  778. }
  779. </programlisting>
  780. </example>
  781. <example>
  782. <title>Simple downscaling</title>
  783. <para>(A video capture device is assumed.)</para>
  784. <programlisting>
  785. &v4l2-cropcap; cropcap;
  786. &v4l2-format; format;
  787. reset_cropping_parameters ();
  788. /* Scale down to 1/4 size of full picture. */
  789. memset (&amp;format, 0, sizeof (format)); /* defaults */
  790. format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  791. format.fmt.pix.width = cropcap.defrect.width &gt;&gt; 1;
  792. format.fmt.pix.height = cropcap.defrect.height &gt;&gt; 1;
  793. format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
  794. if (-1 == ioctl (fd, &VIDIOC-S-FMT;, &amp;format)) {
  795. perror ("VIDIOC_S_FORMAT");
  796. exit (EXIT_FAILURE);
  797. }
  798. /* We could check the actual image size now, the actual scaling factor
  799. or if the driver can scale at all. */
  800. </programlisting>
  801. </example>
  802. <example>
  803. <title>Selecting an output area</title>
  804. <programlisting>
  805. &v4l2-cropcap; cropcap;
  806. &v4l2-crop; crop;
  807. memset (&amp;cropcap, 0, sizeof (cropcap));
  808. cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  809. if (-1 == ioctl (fd, VIDIOC_CROPCAP;, &amp;cropcap)) {
  810. perror ("VIDIOC_CROPCAP");
  811. exit (EXIT_FAILURE);
  812. }
  813. memset (&amp;crop, 0, sizeof (crop));
  814. crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  815. crop.c = cropcap.defrect;
  816. /* Scale the width and height to 50 % of their original size
  817. and center the output. */
  818. crop.c.width /= 2;
  819. crop.c.height /= 2;
  820. crop.c.left += crop.c.width / 2;
  821. crop.c.top += crop.c.height / 2;
  822. /* Ignore if cropping is not supported (EINVAL). */
  823. if (-1 == ioctl (fd, VIDIOC_S_CROP, &amp;crop)
  824. &amp;&amp; errno != EINVAL) {
  825. perror ("VIDIOC_S_CROP");
  826. exit (EXIT_FAILURE);
  827. }
  828. </programlisting>
  829. </example>
  830. <example>
  831. <title>Current scaling factor and pixel aspect</title>
  832. <para>(A video capture device is assumed.)</para>
  833. <programlisting>
  834. &v4l2-cropcap; cropcap;
  835. &v4l2-crop; crop;
  836. &v4l2-format; format;
  837. double hscale, vscale;
  838. double aspect;
  839. int dwidth, dheight;
  840. memset (&amp;cropcap, 0, sizeof (cropcap));
  841. cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  842. if (-1 == ioctl (fd, &VIDIOC-CROPCAP;, &amp;cropcap)) {
  843. perror ("VIDIOC_CROPCAP");
  844. exit (EXIT_FAILURE);
  845. }
  846. memset (&amp;crop, 0, sizeof (crop));
  847. crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  848. if (-1 == ioctl (fd, &VIDIOC-G-CROP;, &amp;crop)) {
  849. if (errno != EINVAL) {
  850. perror ("VIDIOC_G_CROP");
  851. exit (EXIT_FAILURE);
  852. }
  853. /* Cropping not supported. */
  854. crop.c = cropcap.defrect;
  855. }
  856. memset (&amp;format, 0, sizeof (format));
  857. format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  858. if (-1 == ioctl (fd, &VIDIOC-G-FMT;, &amp;format)) {
  859. perror ("VIDIOC_G_FMT");
  860. exit (EXIT_FAILURE);
  861. }
  862. /* The scaling applied by the driver. */
  863. hscale = format.fmt.pix.width / (double) crop.c.width;
  864. vscale = format.fmt.pix.height / (double) crop.c.height;
  865. aspect = cropcap.pixelaspect.numerator /
  866. (double) cropcap.pixelaspect.denominator;
  867. aspect = aspect * hscale / vscale;
  868. /* Devices following ITU-R BT.601 do not capture
  869. square pixels. For playback on a computer monitor
  870. we should scale the images to this size. */
  871. dwidth = format.fmt.pix.width / aspect;
  872. dheight = format.fmt.pix.height;
  873. </programlisting>
  874. </example>
  875. </section>
  876. </section>
  877. &sub-selection-api;
  878. <section id="streaming-par">
  879. <title>Streaming Parameters</title>
  880. <para>Streaming parameters are intended to optimize the video
  881. capture process as well as I/O. Presently applications can request a
  882. high quality capture mode with the &VIDIOC-S-PARM; ioctl.</para>
  883. <para>The current video standard determines a nominal number of
  884. frames per second. If less than this number of frames is to be
  885. captured or output, applications can request frame skipping or
  886. duplicating on the driver side. This is especially useful when using
  887. the &func-read; or &func-write;, which are not augmented by timestamps
  888. or sequence counters, and to avoid unnecessary data copying.</para>
  889. <para>Finally these ioctls can be used to determine the number of
  890. buffers used internally by a driver in read/write mode. For
  891. implications see the section discussing the &func-read;
  892. function.</para>
  893. <para>To get and set the streaming parameters applications call
  894. the &VIDIOC-G-PARM; and &VIDIOC-S-PARM; ioctl, respectively. They take
  895. a pointer to a &v4l2-streamparm;, which contains a union holding
  896. separate parameters for input and output devices.</para>
  897. <para>These ioctls are optional, drivers need not implement
  898. them. If so, they return the &EINVAL;.</para>
  899. </section>