diff-v4l.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _diff-v4l:
  4. ********************************
  5. Differences between V4L and V4L2
  6. ********************************
  7. The Video For Linux API was first introduced in Linux 2.1 to unify and
  8. replace various TV and radio device related interfaces, developed
  9. independently by driver writers in prior years. Starting with Linux 2.5
  10. the much improved V4L2 API replaces the V4L API. The support for the old
  11. V4L calls were removed from Kernel, but the library :ref:`libv4l`
  12. supports the conversion of a V4L API system call into a V4L2 one.
  13. Opening and Closing Devices
  14. ===========================
  15. For compatibility reasons the character device file names recommended
  16. for V4L2 video capture, overlay, radio and raw vbi capture devices did
  17. not change from those used by V4L. They are listed in :ref:`devices`
  18. and below in :ref:`v4l-dev`.
  19. The teletext devices (minor range 192-223) have been removed in V4L2 and
  20. no longer exist. There is no hardware available anymore for handling
  21. pure teletext. Instead raw or sliced VBI is used.
  22. The V4L ``videodev`` module automatically assigns minor numbers to
  23. drivers in load order, depending on the registered device type. We
  24. recommend that V4L2 drivers by default register devices with the same
  25. numbers, but the system administrator can assign arbitrary minor numbers
  26. using driver module options. The major device number remains 81.
  27. .. _v4l-dev:
  28. .. flat-table:: V4L Device Types, Names and Numbers
  29. :header-rows: 1
  30. :stub-columns: 0
  31. * - Device Type
  32. - File Name
  33. - Minor Numbers
  34. * - Video capture and overlay
  35. - ``/dev/video`` and ``/dev/bttv0``\ [#f1]_, ``/dev/video0`` to
  36. ``/dev/video63``
  37. - 0-63
  38. * - Radio receiver
  39. - ``/dev/radio``\ [#f2]_, ``/dev/radio0`` to ``/dev/radio63``
  40. - 64-127
  41. * - Raw VBI capture
  42. - ``/dev/vbi``, ``/dev/vbi0`` to ``/dev/vbi31``
  43. - 224-255
  44. V4L prohibits (or used to prohibit) multiple opens of a device file.
  45. V4L2 drivers *may* support multiple opens, see :ref:`open` for details
  46. and consequences.
  47. V4L drivers respond to V4L2 ioctls with an ``EINVAL`` error code.
  48. Querying Capabilities
  49. =====================
  50. The V4L ``VIDIOCGCAP`` ioctl is equivalent to V4L2's
  51. :ref:`VIDIOC_QUERYCAP`.
  52. The ``name`` field in struct ``video_capability`` became
  53. ``card`` in struct :c:type:`v4l2_capability`, ``type``
  54. was replaced by ``capabilities``. Note V4L2 does not distinguish between
  55. device types like this, better think of basic video input, video output
  56. and radio devices supporting a set of related functions like video
  57. capturing, video overlay and VBI capturing. See :ref:`open` for an
  58. introduction.
  59. .. raw:: latex
  60. \small
  61. .. tabularcolumns:: |p{5.3cm}|p{6.7cm}|p{5.3cm}|
  62. .. cssclass:: longtable
  63. .. flat-table::
  64. :header-rows: 1
  65. :stub-columns: 0
  66. * - ``struct video_capability`` ``type``
  67. - struct :c:type:`v4l2_capability`
  68. ``capabilities`` flags
  69. - Purpose
  70. * - ``VID_TYPE_CAPTURE``
  71. - ``V4L2_CAP_VIDEO_CAPTURE``
  72. - The :ref:`video capture <capture>` interface is supported.
  73. * - ``VID_TYPE_TUNER``
  74. - ``V4L2_CAP_TUNER``
  75. - The device has a :ref:`tuner or modulator <tuner>`.
  76. * - ``VID_TYPE_TELETEXT``
  77. - ``V4L2_CAP_VBI_CAPTURE``
  78. - The :ref:`raw VBI capture <raw-vbi>` interface is supported.
  79. * - ``VID_TYPE_OVERLAY``
  80. - ``V4L2_CAP_VIDEO_OVERLAY``
  81. - The :ref:`video overlay <overlay>` interface is supported.
  82. * - ``VID_TYPE_CHROMAKEY``
  83. - ``V4L2_FBUF_CAP_CHROMAKEY`` in field ``capability`` of struct
  84. :c:type:`v4l2_framebuffer`
  85. - Whether chromakey overlay is supported. For more information on
  86. overlay see :ref:`overlay`.
  87. * - ``VID_TYPE_CLIPPING``
  88. - ``V4L2_FBUF_CAP_LIST_CLIPPING`` and
  89. ``V4L2_FBUF_CAP_BITMAP_CLIPPING`` in field ``capability`` of
  90. struct :c:type:`v4l2_framebuffer`
  91. - Whether clipping the overlaid image is supported, see
  92. :ref:`overlay`.
  93. * - ``VID_TYPE_FRAMERAM``
  94. - ``V4L2_FBUF_CAP_EXTERNOVERLAY`` *not set* in field ``capability``
  95. of struct :c:type:`v4l2_framebuffer`
  96. - Whether overlay overwrites frame buffer memory, see
  97. :ref:`overlay`.
  98. * - ``VID_TYPE_SCALES``
  99. - ``-``
  100. - This flag indicates if the hardware can scale images. The V4L2 API
  101. implies the scale factor by setting the cropping dimensions and
  102. image size with the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` and
  103. :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, respectively. The
  104. driver returns the closest sizes possible. For more information on
  105. cropping and scaling see :ref:`crop`.
  106. * - ``VID_TYPE_MONOCHROME``
  107. - ``-``
  108. - Applications can enumerate the supported image formats with the
  109. :ref:`VIDIOC_ENUM_FMT` ioctl to determine if
  110. the device supports grey scale capturing only. For more
  111. information on image formats see :ref:`pixfmt`.
  112. * - ``VID_TYPE_SUBCAPTURE``
  113. - ``-``
  114. - Applications can call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>`
  115. ioctl to determine if the device supports capturing a subsection
  116. of the full picture ("cropping" in V4L2). If not, the ioctl
  117. returns the ``EINVAL`` error code. For more information on cropping
  118. and scaling see :ref:`crop`.
  119. * - ``VID_TYPE_MPEG_DECODER``
  120. - ``-``
  121. - Applications can enumerate the supported image formats with the
  122. :ref:`VIDIOC_ENUM_FMT` ioctl to determine if
  123. the device supports MPEG streams.
  124. * - ``VID_TYPE_MPEG_ENCODER``
  125. - ``-``
  126. - See above.
  127. * - ``VID_TYPE_MJPEG_DECODER``
  128. - ``-``
  129. - See above.
  130. * - ``VID_TYPE_MJPEG_ENCODER``
  131. - ``-``
  132. - See above.
  133. .. raw:: latex
  134. \normalsize
  135. The ``audios`` field was replaced by ``capabilities`` flag
  136. ``V4L2_CAP_AUDIO``, indicating *if* the device has any audio inputs or
  137. outputs. To determine their number applications can enumerate audio
  138. inputs with the :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` ioctl. The
  139. audio ioctls are described in :ref:`audio`.
  140. The ``maxwidth``, ``maxheight``, ``minwidth`` and ``minheight`` fields
  141. were removed. Calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
  142. :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl with the desired
  143. dimensions returns the closest size possible, taking into account the
  144. current video standard, cropping and scaling limitations.
  145. Video Sources
  146. =============
  147. V4L provides the ``VIDIOCGCHAN`` and ``VIDIOCSCHAN`` ioctl using struct
  148. ``video_channel`` to enumerate the video inputs of a V4L
  149. device. The equivalent V4L2 ioctls are
  150. :ref:`VIDIOC_ENUMINPUT`,
  151. :ref:`VIDIOC_G_INPUT <VIDIOC_G_INPUT>` and
  152. :ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` using struct
  153. :c:type:`v4l2_input` as discussed in :ref:`video`.
  154. The ``channel`` field counting inputs was renamed to ``index``, the
  155. video input types were renamed as follows:
  156. .. flat-table::
  157. :header-rows: 1
  158. :stub-columns: 0
  159. * - struct ``video_channel`` ``type``
  160. - struct :c:type:`v4l2_input` ``type``
  161. * - ``VIDEO_TYPE_TV``
  162. - ``V4L2_INPUT_TYPE_TUNER``
  163. * - ``VIDEO_TYPE_CAMERA``
  164. - ``V4L2_INPUT_TYPE_CAMERA``
  165. Unlike the ``tuners`` field expressing the number of tuners of this
  166. input, V4L2 assumes each video input is connected to at most one tuner.
  167. However a tuner can have more than one input, i. e. RF connectors, and a
  168. device can have multiple tuners. The index number of the tuner
  169. associated with the input, if any, is stored in field ``tuner`` of
  170. struct :c:type:`v4l2_input`. Enumeration of tuners is
  171. discussed in :ref:`tuner`.
  172. The redundant ``VIDEO_VC_TUNER`` flag was dropped. Video inputs
  173. associated with a tuner are of type ``V4L2_INPUT_TYPE_TUNER``. The
  174. ``VIDEO_VC_AUDIO`` flag was replaced by the ``audioset`` field. V4L2
  175. considers devices with up to 32 audio inputs. Each set bit in the
  176. ``audioset`` field represents one audio input this video input combines
  177. with. For information about audio inputs and how to switch between them
  178. see :ref:`audio`.
  179. The ``norm`` field describing the supported video standards was replaced
  180. by ``std``. The V4L specification mentions a flag ``VIDEO_VC_NORM``
  181. indicating whether the standard can be changed. This flag was a later
  182. addition together with the ``norm`` field and has been removed in the
  183. meantime. V4L2 has a similar, albeit more comprehensive approach to
  184. video standards, see :ref:`standard` for more information.
  185. Tuning
  186. ======
  187. The V4L ``VIDIOCGTUNER`` and ``VIDIOCSTUNER`` ioctl and struct
  188. ``video_tuner`` can be used to enumerate the tuners of a
  189. V4L TV or radio device. The equivalent V4L2 ioctls are
  190. :ref:`VIDIOC_G_TUNER <VIDIOC_G_TUNER>` and
  191. :ref:`VIDIOC_S_TUNER <VIDIOC_G_TUNER>` using struct
  192. :c:type:`v4l2_tuner`. Tuners are covered in :ref:`tuner`.
  193. The ``tuner`` field counting tuners was renamed to ``index``. The fields
  194. ``name``, ``rangelow`` and ``rangehigh`` remained unchanged.
  195. The ``VIDEO_TUNER_PAL``, ``VIDEO_TUNER_NTSC`` and ``VIDEO_TUNER_SECAM``
  196. flags indicating the supported video standards were dropped. This
  197. information is now contained in the associated struct
  198. :c:type:`v4l2_input`. No replacement exists for the
  199. ``VIDEO_TUNER_NORM`` flag indicating whether the video standard can be
  200. switched. The ``mode`` field to select a different video standard was
  201. replaced by a whole new set of ioctls and structures described in
  202. :ref:`standard`. Due to its ubiquity it should be mentioned the BTTV
  203. driver supports several standards in addition to the regular
  204. ``VIDEO_MODE_PAL`` (0), ``VIDEO_MODE_NTSC``, ``VIDEO_MODE_SECAM`` and
  205. ``VIDEO_MODE_AUTO`` (3). Namely N/PAL Argentina, M/PAL, N/PAL, and NTSC
  206. Japan with numbers 3-6 (sic).
  207. The ``VIDEO_TUNER_STEREO_ON`` flag indicating stereo reception became
  208. ``V4L2_TUNER_SUB_STEREO`` in field ``rxsubchans``. This field also
  209. permits the detection of monaural and bilingual audio, see the
  210. definition of struct :c:type:`v4l2_tuner` for details.
  211. Presently no replacement exists for the ``VIDEO_TUNER_RDS_ON`` and
  212. ``VIDEO_TUNER_MBS_ON`` flags.
  213. The ``VIDEO_TUNER_LOW`` flag was renamed to ``V4L2_TUNER_CAP_LOW`` in
  214. the struct :c:type:`v4l2_tuner` ``capability`` field.
  215. The ``VIDIOCGFREQ`` and ``VIDIOCSFREQ`` ioctl to change the tuner
  216. frequency where renamed to
  217. :ref:`VIDIOC_G_FREQUENCY <VIDIOC_G_FREQUENCY>` and
  218. :ref:`VIDIOC_S_FREQUENCY <VIDIOC_G_FREQUENCY>`. They take a pointer
  219. to a struct :c:type:`v4l2_frequency` instead of an
  220. unsigned long integer.
  221. .. _v4l-image-properties:
  222. Image Properties
  223. ================
  224. V4L2 has no equivalent of the ``VIDIOCGPICT`` and ``VIDIOCSPICT`` ioctl
  225. and struct ``video_picture``. The following fields where
  226. replaced by V4L2 controls accessible with the
  227. :ref:`VIDIOC_QUERYCTRL`,
  228. :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` and
  229. :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` ioctls:
  230. .. flat-table::
  231. :header-rows: 1
  232. :stub-columns: 0
  233. * - struct ``video_picture``
  234. - V4L2 Control ID
  235. * - ``brightness``
  236. - ``V4L2_CID_BRIGHTNESS``
  237. * - ``hue``
  238. - ``V4L2_CID_HUE``
  239. * - ``colour``
  240. - ``V4L2_CID_SATURATION``
  241. * - ``contrast``
  242. - ``V4L2_CID_CONTRAST``
  243. * - ``whiteness``
  244. - ``V4L2_CID_WHITENESS``
  245. The V4L picture controls are assumed to range from 0 to 65535 with no
  246. particular reset value. The V4L2 API permits arbitrary limits and
  247. defaults which can be queried with the
  248. :ref:`VIDIOC_QUERYCTRL` ioctl. For general
  249. information about controls see :ref:`control`.
  250. The ``depth`` (average number of bits per pixel) of a video image is
  251. implied by the selected image format. V4L2 does not explicitly provide
  252. such information assuming applications recognizing the format are aware
  253. of the image depth and others need not know. The ``palette`` field moved
  254. into the struct :c:type:`v4l2_pix_format`:
  255. .. flat-table::
  256. :header-rows: 1
  257. :stub-columns: 0
  258. * - struct ``video_picture`` ``palette``
  259. - struct :c:type:`v4l2_pix_format` ``pixfmt``
  260. * - ``VIDEO_PALETTE_GREY``
  261. - :ref:`V4L2_PIX_FMT_GREY <V4L2-PIX-FMT-GREY>`
  262. * - ``VIDEO_PALETTE_HI240``
  263. - :ref:`V4L2_PIX_FMT_HI240 <pixfmt-reserved>` [#f3]_
  264. * - ``VIDEO_PALETTE_RGB565``
  265. - :ref:`V4L2_PIX_FMT_RGB565 <pixfmt-rgb>`
  266. * - ``VIDEO_PALETTE_RGB555``
  267. - :ref:`V4L2_PIX_FMT_RGB555 <pixfmt-rgb>`
  268. * - ``VIDEO_PALETTE_RGB24``
  269. - :ref:`V4L2_PIX_FMT_BGR24 <pixfmt-rgb>`
  270. * - ``VIDEO_PALETTE_RGB32``
  271. - :ref:`V4L2_PIX_FMT_BGR32 <pixfmt-rgb>` [#f4]_
  272. * - ``VIDEO_PALETTE_YUV422``
  273. - :ref:`V4L2_PIX_FMT_YUYV <V4L2-PIX-FMT-YUYV>`
  274. * - ``VIDEO_PALETTE_YUYV``\ [#f5]_
  275. - :ref:`V4L2_PIX_FMT_YUYV <V4L2-PIX-FMT-YUYV>`
  276. * - ``VIDEO_PALETTE_UYVY``
  277. - :ref:`V4L2_PIX_FMT_UYVY <V4L2-PIX-FMT-UYVY>`
  278. * - ``VIDEO_PALETTE_YUV420``
  279. - None
  280. * - ``VIDEO_PALETTE_YUV411``
  281. - :ref:`V4L2_PIX_FMT_Y41P <V4L2-PIX-FMT-Y41P>` [#f6]_
  282. * - ``VIDEO_PALETTE_RAW``
  283. - None [#f7]_
  284. * - ``VIDEO_PALETTE_YUV422P``
  285. - :ref:`V4L2_PIX_FMT_YUV422P <V4L2-PIX-FMT-YUV422P>`
  286. * - ``VIDEO_PALETTE_YUV411P``
  287. - :ref:`V4L2_PIX_FMT_YUV411P <V4L2-PIX-FMT-YUV411P>` [#f8]_
  288. * - ``VIDEO_PALETTE_YUV420P``
  289. - :ref:`V4L2_PIX_FMT_YVU420 <V4L2-PIX-FMT-YVU420>`
  290. * - ``VIDEO_PALETTE_YUV410P``
  291. - :ref:`V4L2_PIX_FMT_YVU410 <V4L2-PIX-FMT-YVU410>`
  292. V4L2 image formats are defined in :ref:`pixfmt`. The image format can
  293. be selected with the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
  294. Audio
  295. =====
  296. The ``VIDIOCGAUDIO`` and ``VIDIOCSAUDIO`` ioctl and struct
  297. ``video_audio`` are used to enumerate the audio inputs
  298. of a V4L device. The equivalent V4L2 ioctls are
  299. :ref:`VIDIOC_G_AUDIO <VIDIOC_G_AUDIO>` and
  300. :ref:`VIDIOC_S_AUDIO <VIDIOC_G_AUDIO>` using struct
  301. :c:type:`v4l2_audio` as discussed in :ref:`audio`.
  302. The ``audio`` "channel number" field counting audio inputs was renamed
  303. to ``index``.
  304. On ``VIDIOCSAUDIO`` the ``mode`` field selects *one* of the
  305. ``VIDEO_SOUND_MONO``, ``VIDEO_SOUND_STEREO``, ``VIDEO_SOUND_LANG1`` or
  306. ``VIDEO_SOUND_LANG2`` audio demodulation modes. When the current audio
  307. standard is BTSC ``VIDEO_SOUND_LANG2`` refers to SAP and
  308. ``VIDEO_SOUND_LANG1`` is meaningless. Also undocumented in the V4L
  309. specification, there is no way to query the selected mode. On
  310. ``VIDIOCGAUDIO`` the driver returns the *actually received* audio
  311. programmes in this field. In the V4L2 API this information is stored in
  312. the struct :c:type:`v4l2_tuner` ``rxsubchans`` and
  313. ``audmode`` fields, respectively. See :ref:`tuner` for more
  314. information on tuners. Related to audio modes struct
  315. :c:type:`v4l2_audio` also reports if this is a mono or
  316. stereo input, regardless if the source is a tuner.
  317. The following fields where replaced by V4L2 controls accessible with the
  318. :ref:`VIDIOC_QUERYCTRL`,
  319. :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` and
  320. :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` ioctls:
  321. .. flat-table::
  322. :header-rows: 1
  323. :stub-columns: 0
  324. * - struct ``video_audio``
  325. - V4L2 Control ID
  326. * - ``volume``
  327. - ``V4L2_CID_AUDIO_VOLUME``
  328. * - ``bass``
  329. - ``V4L2_CID_AUDIO_BASS``
  330. * - ``treble``
  331. - ``V4L2_CID_AUDIO_TREBLE``
  332. * - ``balance``
  333. - ``V4L2_CID_AUDIO_BALANCE``
  334. To determine which of these controls are supported by a driver V4L
  335. provides the ``flags`` ``VIDEO_AUDIO_VOLUME``, ``VIDEO_AUDIO_BASS``,
  336. ``VIDEO_AUDIO_TREBLE`` and ``VIDEO_AUDIO_BALANCE``. In the V4L2 API the
  337. :ref:`VIDIOC_QUERYCTRL` ioctl reports if the
  338. respective control is supported. Accordingly the ``VIDEO_AUDIO_MUTABLE``
  339. and ``VIDEO_AUDIO_MUTE`` flags where replaced by the boolean
  340. ``V4L2_CID_AUDIO_MUTE`` control.
  341. All V4L2 controls have a ``step`` attribute replacing the struct
  342. ``video_audio`` ``step`` field. The V4L audio controls
  343. are assumed to range from 0 to 65535 with no particular reset value. The
  344. V4L2 API permits arbitrary limits and defaults which can be queried with
  345. the :ref:`VIDIOC_QUERYCTRL` ioctl. For general
  346. information about controls see :ref:`control`.
  347. Frame Buffer Overlay
  348. ====================
  349. The V4L2 ioctls equivalent to ``VIDIOCGFBUF`` and ``VIDIOCSFBUF`` are
  350. :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` and
  351. :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>`. The ``base`` field of struct
  352. ``video_buffer`` remained unchanged, except V4L2 defines
  353. a flag to indicate non-destructive overlays instead of a ``NULL``
  354. pointer. All other fields moved into the struct
  355. :c:type:`v4l2_pix_format` ``fmt`` substructure of
  356. struct :c:type:`v4l2_framebuffer`. The ``depth``
  357. field was replaced by ``pixelformat``. See :ref:`pixfmt-rgb` for a
  358. list of RGB formats and their respective color depths.
  359. Instead of the special ioctls ``VIDIOCGWIN`` and ``VIDIOCSWIN`` V4L2
  360. uses the general-purpose data format negotiation ioctls
  361. :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
  362. :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. They take a pointer to a struct
  363. :c:type:`v4l2_format` as argument. Here the ``win`` member
  364. of the ``fmt`` union is used, a struct
  365. :c:type:`v4l2_window`.
  366. The ``x``, ``y``, ``width`` and ``height`` fields of struct
  367. ``video_window`` moved into struct
  368. :c:type:`v4l2_rect` substructure ``w`` of struct
  369. :c:type:`v4l2_window`. The ``chromakey``, ``clips``, and
  370. ``clipcount`` fields remained unchanged. Struct
  371. ``video_clip`` was renamed to struct
  372. :c:type:`v4l2_clip`, also containing a struct
  373. :c:type:`v4l2_rect`, but the semantics are still the same.
  374. The ``VIDEO_WINDOW_INTERLACE`` flag was dropped. Instead applications
  375. must set the ``field`` field to ``V4L2_FIELD_ANY`` or
  376. ``V4L2_FIELD_INTERLACED``. The ``VIDEO_WINDOW_CHROMAKEY`` flag moved
  377. into struct :c:type:`v4l2_framebuffer`, under the new
  378. name ``V4L2_FBUF_FLAG_CHROMAKEY``.
  379. In V4L, storing a bitmap pointer in ``clips`` and setting ``clipcount``
  380. to ``VIDEO_CLIP_BITMAP`` (-1) requests bitmap clipping, using a fixed
  381. size bitmap of 1024 × 625 bits. Struct :c:type:`v4l2_window`
  382. has a separate ``bitmap`` pointer field for this purpose and the bitmap
  383. size is determined by ``w.width`` and ``w.height``.
  384. The ``VIDIOCCAPTURE`` ioctl to enable or disable overlay was renamed to
  385. :ref:`VIDIOC_OVERLAY`.
  386. Cropping
  387. ========
  388. To capture only a subsection of the full picture V4L defines the
  389. ``VIDIOCGCAPTURE`` and ``VIDIOCSCAPTURE`` ioctls using struct
  390. ``video_capture``. The equivalent V4L2 ioctls are
  391. :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and
  392. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` using struct
  393. :c:type:`v4l2_crop`, and the related
  394. :ref:`VIDIOC_CROPCAP` ioctl. This is a rather
  395. complex matter, see :ref:`crop` for details.
  396. The ``x``, ``y``, ``width`` and ``height`` fields moved into struct
  397. :c:type:`v4l2_rect` substructure ``c`` of struct
  398. :c:type:`v4l2_crop`. The ``decimation`` field was dropped. In
  399. the V4L2 API the scaling factor is implied by the size of the cropping
  400. rectangle and the size of the captured or overlaid image.
  401. The ``VIDEO_CAPTURE_ODD`` and ``VIDEO_CAPTURE_EVEN`` flags to capture
  402. only the odd or even field, respectively, were replaced by
  403. ``V4L2_FIELD_TOP`` and ``V4L2_FIELD_BOTTOM`` in the field named
  404. ``field`` of struct :c:type:`v4l2_pix_format` and
  405. struct :c:type:`v4l2_window`. These structures are used to
  406. select a capture or overlay format with the
  407. :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
  408. Reading Images, Memory Mapping
  409. ==============================
  410. Capturing using the read method
  411. -------------------------------
  412. There is no essential difference between reading images from a V4L or
  413. V4L2 device using the :c:func:`read()` function, however V4L2
  414. drivers are not required to support this I/O method. Applications can
  415. determine if the function is available with the
  416. :ref:`VIDIOC_QUERYCAP` ioctl. All V4L2 devices
  417. exchanging data with applications must support the
  418. :c:func:`select()` and :c:func:`poll()`
  419. functions.
  420. To select an image format and size, V4L provides the ``VIDIOCSPICT`` and
  421. ``VIDIOCSWIN`` ioctls. V4L2 uses the general-purpose data format
  422. negotiation ioctls :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
  423. :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. They take a pointer to a struct
  424. :c:type:`v4l2_format` as argument, here the struct
  425. :c:type:`v4l2_pix_format` named ``pix`` of its
  426. ``fmt`` union is used.
  427. For more information about the V4L2 read interface see :ref:`rw`.
  428. Capturing using memory mapping
  429. ------------------------------
  430. Applications can read from V4L devices by mapping buffers in device
  431. memory, or more often just buffers allocated in DMA-able system memory,
  432. into their address space. This avoids the data copying overhead of the
  433. read method. V4L2 supports memory mapping as well, with a few
  434. differences.
  435. .. flat-table::
  436. :header-rows: 1
  437. :stub-columns: 0
  438. * - V4L
  439. - V4L2
  440. * -
  441. - The image format must be selected before buffers are allocated,
  442. with the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. When no
  443. format is selected the driver may use the last, possibly by
  444. another application requested format.
  445. * - Applications cannot change the number of buffers. The it is built
  446. into the driver, unless it has a module option to change the
  447. number when the driver module is loaded.
  448. - The :ref:`VIDIOC_REQBUFS` ioctl allocates the
  449. desired number of buffers, this is a required step in the
  450. initialization sequence.
  451. * - Drivers map all buffers as one contiguous range of memory. The
  452. ``VIDIOCGMBUF`` ioctl is available to query the number of buffers,
  453. the offset of each buffer from the start of the virtual file, and
  454. the overall amount of memory used, which can be used as arguments
  455. for the :c:func:`mmap()` function.
  456. - Buffers are individually mapped. The offset and size of each
  457. buffer can be determined with the
  458. :ref:`VIDIOC_QUERYBUF` ioctl.
  459. * - The ``VIDIOCMCAPTURE`` ioctl prepares a buffer for capturing. It
  460. also determines the image format for this buffer. The ioctl
  461. returns immediately, eventually with an ``EAGAIN`` error code if no
  462. video signal had been detected. When the driver supports more than
  463. one buffer applications can call the ioctl multiple times and thus
  464. have multiple outstanding capture requests.
  465. The ``VIDIOCSYNC`` ioctl suspends execution until a particular
  466. buffer has been filled.
  467. - Drivers maintain an incoming and outgoing queue.
  468. :ref:`VIDIOC_QBUF` enqueues any empty buffer into
  469. the incoming queue. Filled buffers are dequeued from the outgoing
  470. queue with the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. To wait
  471. until filled buffers become available this function,
  472. :c:func:`select()` or :c:func:`poll()` can
  473. be used. The :ref:`VIDIOC_STREAMON` ioctl
  474. must be called once after enqueuing one or more buffers to start
  475. capturing. Its counterpart
  476. :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` stops capturing and
  477. dequeues all buffers from both queues. Applications can query the
  478. signal status, if known, with the
  479. :ref:`VIDIOC_ENUMINPUT` ioctl.
  480. For a more in-depth discussion of memory mapping and examples, see
  481. :ref:`mmap`.
  482. Reading Raw VBI Data
  483. ====================
  484. Originally the V4L API did not specify a raw VBI capture interface, only
  485. the device file ``/dev/vbi`` was reserved for this purpose. The only
  486. driver supporting this interface was the BTTV driver, de-facto defining
  487. the V4L VBI interface. Reading from the device yields a raw VBI image
  488. with the following parameters:
  489. .. flat-table::
  490. :header-rows: 1
  491. :stub-columns: 0
  492. * - struct :c:type:`v4l2_vbi_format`
  493. - V4L, BTTV driver
  494. * - sampling_rate
  495. - 28636363 Hz NTSC (or any other 525-line standard); 35468950 Hz PAL
  496. and SECAM (625-line standards)
  497. * - offset
  498. - ?
  499. * - samples_per_line
  500. - 2048
  501. * - sample_format
  502. - V4L2_PIX_FMT_GREY. The last four bytes (a machine endianness
  503. integer) contain a frame counter.
  504. * - start[]
  505. - 10, 273 NTSC; 22, 335 PAL and SECAM
  506. * - count[]
  507. - 16, 16 [#f9]_
  508. * - flags
  509. - 0
  510. Undocumented in the V4L specification, in Linux 2.3 the
  511. ``VIDIOCGVBIFMT`` and ``VIDIOCSVBIFMT`` ioctls using struct
  512. ``vbi_format`` were added to determine the VBI image
  513. parameters. These ioctls are only partially compatible with the V4L2 VBI
  514. interface specified in :ref:`raw-vbi`.
  515. An ``offset`` field does not exist, ``sample_format`` is supposed to be
  516. ``VIDEO_PALETTE_RAW``, equivalent to ``V4L2_PIX_FMT_GREY``. The
  517. remaining fields are probably equivalent to struct
  518. :c:type:`v4l2_vbi_format`.
  519. Apparently only the Zoran (ZR 36120) driver implements these ioctls. The
  520. semantics differ from those specified for V4L2 in two ways. The
  521. parameters are reset on :c:func:`open()` and
  522. ``VIDIOCSVBIFMT`` always returns an ``EINVAL`` error code if the parameters
  523. are invalid.
  524. Miscellaneous
  525. =============
  526. V4L2 has no equivalent of the ``VIDIOCGUNIT`` ioctl. Applications can
  527. find the VBI device associated with a video capture device (or vice
  528. versa) by reopening the device and requesting VBI data. For details see
  529. :ref:`open`.
  530. No replacement exists for ``VIDIOCKEY``, and the V4L functions for
  531. microcode programming. A new interface for MPEG compression and playback
  532. devices is documented in :ref:`extended-controls`.
  533. .. [#f1]
  534. According to Documentation/admin-guide/devices.rst these should be symbolic links
  535. to ``/dev/video0``. Note the original bttv interface is not
  536. compatible with V4L or V4L2.
  537. .. [#f2]
  538. According to ``Documentation/admin-guide/devices.rst`` a symbolic link to
  539. ``/dev/radio0``.
  540. .. [#f3]
  541. This is a custom format used by the BTTV driver, not one of the V4L2
  542. standard formats.
  543. .. [#f4]
  544. Presumably all V4L RGB formats are little-endian, although some
  545. drivers might interpret them according to machine endianness. V4L2
  546. defines little-endian, big-endian and red/blue swapped variants. For
  547. details see :ref:`pixfmt-rgb`.
  548. .. [#f5]
  549. ``VIDEO_PALETTE_YUV422`` and ``VIDEO_PALETTE_YUYV`` are the same
  550. formats. Some V4L drivers respond to one, some to the other.
  551. .. [#f6]
  552. Not to be confused with ``V4L2_PIX_FMT_YUV411P``, which is a planar
  553. format.
  554. .. [#f7]
  555. V4L explains this as: "RAW capture (BT848)"
  556. .. [#f8]
  557. Not to be confused with ``V4L2_PIX_FMT_Y41P``, which is a packed
  558. format.
  559. .. [#f9]
  560. Old driver versions used different values, eventually the custom
  561. ``BTTV_VBISIZE`` ioctl was added to query the correct values.