Merge branches 'acpi-button', 'acpica' and 'acpi-sysfs'
[sfrench/cifs-2.6.git] / Documentation / media / uapi / v4l / buffer.rst
1 .. -*- coding: utf-8; mode: rst -*-
2
3 .. _buffer:
4
5 *******
6 Buffers
7 *******
8
9 A buffer contains data exchanged by application and driver using one of
10 the Streaming I/O methods. In the multi-planar API, the data is held in
11 planes, while the buffer structure acts as a container for the planes.
12 Only pointers to buffers (planes) are exchanged, the data itself is not
13 copied. These pointers, together with meta-information like timestamps
14 or field parity, are stored in a struct :c:type:`v4l2_buffer`,
15 argument to the :ref:`VIDIOC_QUERYBUF`,
16 :ref:`VIDIOC_QBUF` and
17 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. In the multi-planar API,
18 some plane-specific members of struct :c:type:`v4l2_buffer`,
19 such as pointers and sizes for each plane, are stored in struct
20 struct :c:type:`v4l2_plane` instead. In that case, struct
21 struct :c:type:`v4l2_buffer` contains an array of plane structures.
22
23 Dequeued video buffers come with timestamps. The driver decides at which
24 part of the frame and with which clock the timestamp is taken. Please
25 see flags in the masks ``V4L2_BUF_FLAG_TIMESTAMP_MASK`` and
26 ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` in :ref:`buffer-flags`. These flags
27 are always valid and constant across all buffers during the whole video
28 stream. Changes in these flags may take place as a side effect of
29 :ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` or
30 :ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` however. The
31 ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` timestamp type which is used by e.g. on
32 mem-to-mem devices is an exception to the rule: the timestamp source
33 flags are copied from the OUTPUT video buffer to the CAPTURE video
34 buffer.
35
36
37 Interactions between formats, controls and buffers
38 ==================================================
39
40 V4L2 exposes parameters that influence the buffer size, or the way data is
41 laid out in the buffer. Those parameters are exposed through both formats and
42 controls. One example of such a control is the ``V4L2_CID_ROTATE`` control
43 that modifies the direction in which pixels are stored in the buffer, as well
44 as the buffer size when the selected format includes padding at the end of
45 lines.
46
47 The set of information needed to interpret the content of a buffer (e.g. the
48 pixel format, the line stride, the tiling orientation or the rotation) is
49 collectively referred to in the rest of this section as the buffer layout.
50
51 Controls that can modify the buffer layout shall set the
52 ``V4L2_CTRL_FLAG_MODIFY_LAYOUT`` flag.
53
54 Modifying formats or controls that influence the buffer size or layout require
55 the stream to be stopped. Any attempt at such a modification while the stream
56 is active shall cause the ioctl setting the format or the control to return
57 the ``EBUSY`` error code. In that case drivers shall also set the
58 ``V4L2_CTRL_FLAG_GRABBED`` flag when calling
59 :c:func:`VIDIOC_QUERYCTRL` or :c:func:`VIDIOC_QUERY_EXT_CTRL` for such a
60 control while the stream is active.
61
62 .. note::
63
64    The :c:func:`VIDIOC_S_SELECTION` ioctl can, depending on the hardware (for
65    instance if the device doesn't include a scaler), modify the format in
66    addition to the selection rectangle. Similarly, the
67    :c:func:`VIDIOC_S_INPUT`, :c:func:`VIDIOC_S_OUTPUT`, :c:func:`VIDIOC_S_STD`
68    and :c:func:`VIDIOC_S_DV_TIMINGS` ioctls can also modify the format and
69    selection rectangles. When those ioctls result in a buffer size or layout
70    change, drivers shall handle that condition as they would handle it in the
71    :c:func:`VIDIOC_S_FMT` ioctl in all cases described in this section.
72
73 Controls that only influence the buffer layout can be modified at any time
74 when the stream is stopped. As they don't influence the buffer size, no
75 special handling is needed to synchronize those controls with buffer
76 allocation and the ``V4L2_CTRL_FLAG_GRABBED`` flag is cleared once the
77 stream is stopped.
78
79 Formats and controls that influence the buffer size interact with buffer
80 allocation. The simplest way to handle this is for drivers to always require
81 buffers to be reallocated in order to change those formats or controls. In
82 that case, to perform such changes, userspace applications shall first stop
83 the video stream with the :c:func:`VIDIOC_STREAMOFF` ioctl if it is running
84 and free all buffers with the :c:func:`VIDIOC_REQBUFS` ioctl if they are
85 allocated. After freeing all buffers the ``V4L2_CTRL_FLAG_GRABBED`` flag
86 for controls is cleared. The format or controls can then be modified, and
87 buffers shall then be reallocated and the stream restarted. A typical ioctl
88 sequence is
89
90  #. VIDIOC_STREAMOFF
91  #. VIDIOC_REQBUFS(0)
92  #. VIDIOC_S_EXT_CTRLS
93  #. VIDIOC_S_FMT
94  #. VIDIOC_REQBUFS(n)
95  #. VIDIOC_QBUF
96  #. VIDIOC_STREAMON
97
98 The second :c:func:`VIDIOC_REQBUFS` call will take the new format and control
99 value into account to compute the buffer size to allocate. Applications can
100 also retrieve the size by calling the :c:func:`VIDIOC_G_FMT` ioctl if needed.
101
102 .. note::
103
104    The API doesn't mandate the above order for control (3.) and format (4.)
105    changes. Format and controls can be set in a different order, or even
106    interleaved, depending on the device and use case. For instance some
107    controls might behave differently for different pixel formats, in which
108    case the format might need to be set first.
109
110 When reallocation is required, any attempt to modify format or controls that
111 influences the buffer size while buffers are allocated shall cause the format
112 or control set ioctl to return the ``EBUSY`` error. Any attempt to queue a
113 buffer too small for the current format or controls shall cause the
114 :c:func:`VIDIOC_QBUF` ioctl to return a ``EINVAL`` error.
115
116 Buffer reallocation is an expensive operation. To avoid that cost, drivers can
117 (and are encouraged to) allow format or controls that influence the buffer
118 size to be changed with buffers allocated. In that case, a typical ioctl
119 sequence to modify format and controls is
120
121  #. VIDIOC_STREAMOFF
122  #. VIDIOC_S_EXT_CTRLS
123  #. VIDIOC_S_FMT
124  #. VIDIOC_QBUF
125  #. VIDIOC_STREAMON
126
127 For this sequence to operate correctly, queued buffers need to be large enough
128 for the new format or controls. Drivers shall return a ``ENOSPC`` error in
129 response to format change (:c:func:`VIDIOC_S_FMT`) or control changes
130 (:c:func:`VIDIOC_S_CTRL` or :c:func:`VIDIOC_S_EXT_CTRLS`) if buffers too small
131 for the new format are currently queued. As a simplification, drivers are
132 allowed to return a ``EBUSY`` error from these ioctls if any buffer is
133 currently queued, without checking the queued buffers sizes.
134
135 Additionally, drivers shall return a ``EINVAL`` error from the
136 :c:func:`VIDIOC_QBUF` ioctl if the buffer being queued is too small for the
137 current format or controls. Together, these requirements ensure that queued
138 buffers will always be large enough for the configured format and controls.
139
140 Userspace applications can query the buffer size required for a given format
141 and controls by first setting the desired control values and then trying the
142 desired format. The :c:func:`VIDIOC_TRY_FMT` ioctl will return the required
143 buffer size.
144
145  #. VIDIOC_S_EXT_CTRLS(x)
146  #. VIDIOC_TRY_FMT()
147  #. VIDIOC_S_EXT_CTRLS(y)
148  #. VIDIOC_TRY_FMT()
149
150 The :c:func:`VIDIOC_CREATE_BUFS` ioctl can then be used to allocate buffers
151 based on the queried sizes (for instance by allocating a set of buffers large
152 enough for all the desired formats and controls, or by allocating separate set
153 of appropriately sized buffers for each use case).
154
155
156 .. c:type:: v4l2_buffer
157
158 struct v4l2_buffer
159 ==================
160
161 .. tabularcolumns:: |p{2.8cm}|p{2.5cm}|p{1.3cm}|p{10.5cm}|
162
163 .. cssclass:: longtable
164
165 .. flat-table:: struct v4l2_buffer
166     :header-rows:  0
167     :stub-columns: 0
168     :widths:       1 2 1 10
169
170     * - __u32
171       - ``index``
172       -
173       - Number of the buffer, set by the application except when calling
174         :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`, then it is set by the
175         driver. This field can range from zero to the number of buffers
176         allocated with the :ref:`VIDIOC_REQBUFS` ioctl
177         (struct :c:type:`v4l2_requestbuffers`
178         ``count``), plus any buffers allocated with
179         :ref:`VIDIOC_CREATE_BUFS` minus one.
180     * - __u32
181       - ``type``
182       -
183       - Type of the buffer, same as struct
184         :c:type:`v4l2_format` ``type`` or struct
185         :c:type:`v4l2_requestbuffers` ``type``, set
186         by the application. See :c:type:`v4l2_buf_type`
187     * - __u32
188       - ``bytesused``
189       -
190       - The number of bytes occupied by the data in the buffer. It depends
191         on the negotiated data format and may change with each buffer for
192         compressed variable size data like JPEG images. Drivers must set
193         this field when ``type`` refers to a capture stream, applications
194         when it refers to an output stream. If the application sets this
195         to 0 for an output stream, then ``bytesused`` will be set to the
196         size of the buffer (see the ``length`` field of this struct) by
197         the driver. For multiplanar formats this field is ignored and the
198         ``planes`` pointer is used instead.
199     * - __u32
200       - ``flags``
201       -
202       - Flags set by the application or driver, see :ref:`buffer-flags`.
203     * - __u32
204       - ``field``
205       -
206       - Indicates the field order of the image in the buffer, see
207         :c:type:`v4l2_field`. This field is not used when the buffer
208         contains VBI data. Drivers must set it when ``type`` refers to a
209         capture stream, applications when it refers to an output stream.
210     * - struct timeval
211       - ``timestamp``
212       -
213       - For capture streams this is time when the first data byte was
214         captured, as returned by the :c:func:`clock_gettime()` function
215         for the relevant clock id; see ``V4L2_BUF_FLAG_TIMESTAMP_*`` in
216         :ref:`buffer-flags`. For output streams the driver stores the
217         time at which the last data byte was actually sent out in the
218         ``timestamp`` field. This permits applications to monitor the
219         drift between the video and system clock. For output streams that
220         use ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` the application has to fill
221         in the timestamp which will be copied by the driver to the capture
222         stream.
223     * - struct :c:type:`v4l2_timecode`
224       - ``timecode``
225       -
226       - When ``type`` is ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` and the
227         ``V4L2_BUF_FLAG_TIMECODE`` flag is set in ``flags``, this
228         structure contains a frame timecode. In
229         :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and
230         bottom field contain the same timecode. Timecodes are intended to
231         help video editing and are typically recorded on video tapes, but
232         also embedded in compressed formats like MPEG. This field is
233         independent of the ``timestamp`` and ``sequence`` fields.
234     * - __u32
235       - ``sequence``
236       -
237       - Set by the driver, counting the frames (not fields!) in sequence.
238         This field is set for both input and output devices.
239     * - :cspan:`3`
240
241         In :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and
242         bottom field have the same sequence number. The count starts at
243         zero and includes dropped or repeated frames. A dropped frame was
244         received by an input device but could not be stored due to lack of
245         free buffer space. A repeated frame was displayed again by an
246         output device because the application did not pass new data in
247         time.
248
249         .. note::
250
251            This may count the frames received e.g. over USB, without
252            taking into account the frames dropped by the remote hardware due
253            to limited compression throughput or bus bandwidth. These devices
254            identify by not enumerating any video standards, see
255            :ref:`standard`.
256
257     * - __u32
258       - ``memory``
259       -
260       - This field must be set by applications and/or drivers in
261         accordance with the selected I/O method. See :c:type:`v4l2_memory`
262     * - union
263       - ``m``
264     * -
265       - __u32
266       - ``offset``
267       - For the single-planar API and when ``memory`` is
268         ``V4L2_MEMORY_MMAP`` this is the offset of the buffer from the
269         start of the device memory. The value is returned by the driver
270         and apart of serving as parameter to the
271         :ref:`mmap() <func-mmap>` function not useful for applications.
272         See :ref:`mmap` for details
273     * -
274       - unsigned long
275       - ``userptr``
276       - For the single-planar API and when ``memory`` is
277         ``V4L2_MEMORY_USERPTR`` this is a pointer to the buffer (casted to
278         unsigned long type) in virtual memory, set by the application. See
279         :ref:`userp` for details.
280     * -
281       - struct v4l2_plane
282       - ``*planes``
283       - When using the multi-planar API, contains a userspace pointer to
284         an array of struct :c:type:`v4l2_plane`. The size of
285         the array should be put in the ``length`` field of this
286         struct :c:type:`v4l2_buffer` structure.
287     * -
288       - int
289       - ``fd``
290       - For the single-plane API and when ``memory`` is
291         ``V4L2_MEMORY_DMABUF`` this is the file descriptor associated with
292         a DMABUF buffer.
293     * - __u32
294       - ``length``
295       -
296       - Size of the buffer (not the payload) in bytes for the
297         single-planar API. This is set by the driver based on the calls to
298         :ref:`VIDIOC_REQBUFS` and/or
299         :ref:`VIDIOC_CREATE_BUFS`. For the
300         multi-planar API the application sets this to the number of
301         elements in the ``planes`` array. The driver will fill in the
302         actual number of valid elements in that array.
303     * - __u32
304       - ``reserved2``
305       -
306       - A place holder for future extensions. Drivers and applications
307         must set this to 0.
308     * - __u32
309       - ``reserved``
310       -
311       - A place holder for future extensions. Drivers and applications
312         must set this to 0.
313
314
315
316 .. c:type:: v4l2_plane
317
318 struct v4l2_plane
319 =================
320
321 .. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{7.0cm}|
322
323 .. cssclass:: longtable
324
325 .. flat-table::
326     :header-rows:  0
327     :stub-columns: 0
328     :widths:       1 1 1 2
329
330     * - __u32
331       - ``bytesused``
332       -
333       - The number of bytes occupied by data in the plane (its payload).
334         Drivers must set this field when ``type`` refers to a capture
335         stream, applications when it refers to an output stream. If the
336         application sets this to 0 for an output stream, then
337         ``bytesused`` will be set to the size of the plane (see the
338         ``length`` field of this struct) by the driver.
339
340         .. note::
341
342            Note that the actual image data starts at ``data_offset``
343            which may not be 0.
344     * - __u32
345       - ``length``
346       -
347       - Size in bytes of the plane (not its payload). This is set by the
348         driver based on the calls to
349         :ref:`VIDIOC_REQBUFS` and/or
350         :ref:`VIDIOC_CREATE_BUFS`.
351     * - union
352       - ``m``
353       -
354       -
355     * -
356       - __u32
357       - ``mem_offset``
358       - When the memory type in the containing struct
359         :c:type:`v4l2_buffer` is ``V4L2_MEMORY_MMAP``, this
360         is the value that should be passed to :ref:`mmap() <func-mmap>`,
361         similar to the ``offset`` field in struct
362         :c:type:`v4l2_buffer`.
363     * -
364       - unsigned long
365       - ``userptr``
366       - When the memory type in the containing struct
367         :c:type:`v4l2_buffer` is ``V4L2_MEMORY_USERPTR``,
368         this is a userspace pointer to the memory allocated for this plane
369         by an application.
370     * -
371       - int
372       - ``fd``
373       - When the memory type in the containing struct
374         :c:type:`v4l2_buffer` is ``V4L2_MEMORY_DMABUF``,
375         this is a file descriptor associated with a DMABUF buffer, similar
376         to the ``fd`` field in struct :c:type:`v4l2_buffer`.
377     * - __u32
378       - ``data_offset``
379       -
380       - Offset in bytes to video data in the plane. Drivers must set this
381         field when ``type`` refers to a capture stream, applications when
382         it refers to an output stream.
383
384         .. note::
385
386            That data_offset is included  in ``bytesused``. So the
387            size of the image in the plane is ``bytesused``-``data_offset``
388            at offset ``data_offset`` from the start of the plane.
389     * - __u32
390       - ``reserved[11]``
391       -
392       - Reserved for future use. Should be zeroed by drivers and
393         applications.
394
395
396
397 .. c:type:: v4l2_buf_type
398
399 enum v4l2_buf_type
400 ==================
401
402 .. cssclass:: longtable
403
404 .. tabularcolumns:: |p{7.2cm}|p{0.6cm}|p{9.7cm}|
405
406 .. flat-table::
407     :header-rows:  0
408     :stub-columns: 0
409     :widths:       4 1 9
410
411     * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE``
412       - 1
413       - Buffer of a single-planar video capture stream, see
414         :ref:`capture`.
415     * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``
416       - 9
417       - Buffer of a multi-planar video capture stream, see
418         :ref:`capture`.
419     * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
420       - 2
421       - Buffer of a single-planar video output stream, see
422         :ref:`output`.
423     * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``
424       - 10
425       - Buffer of a multi-planar video output stream, see :ref:`output`.
426     * - ``V4L2_BUF_TYPE_VIDEO_OVERLAY``
427       - 3
428       - Buffer for video overlay, see :ref:`overlay`.
429     * - ``V4L2_BUF_TYPE_VBI_CAPTURE``
430       - 4
431       - Buffer of a raw VBI capture stream, see :ref:`raw-vbi`.
432     * - ``V4L2_BUF_TYPE_VBI_OUTPUT``
433       - 5
434       - Buffer of a raw VBI output stream, see :ref:`raw-vbi`.
435     * - ``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE``
436       - 6
437       - Buffer of a sliced VBI capture stream, see :ref:`sliced`.
438     * - ``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``
439       - 7
440       - Buffer of a sliced VBI output stream, see :ref:`sliced`.
441     * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``
442       - 8
443       - Buffer for video output overlay (OSD), see :ref:`osd`.
444     * - ``V4L2_BUF_TYPE_SDR_CAPTURE``
445       - 11
446       - Buffer for Software Defined Radio (SDR) capture stream, see
447         :ref:`sdr`.
448     * - ``V4L2_BUF_TYPE_SDR_OUTPUT``
449       - 12
450       - Buffer for Software Defined Radio (SDR) output stream, see
451         :ref:`sdr`.
452     * - ``V4L2_BUF_TYPE_META_CAPTURE``
453       - 13
454       - Buffer for metadata capture, see :ref:`metadata`.
455
456
457
458 .. _buffer-flags:
459
460 Buffer Flags
461 ============
462
463 .. tabularcolumns:: |p{7.0cm}|p{2.2cm}|p{8.3cm}|
464
465 .. cssclass:: longtable
466
467 .. flat-table::
468     :header-rows:  0
469     :stub-columns: 0
470     :widths:       3 1 4
471
472     * .. _`V4L2-BUF-FLAG-MAPPED`:
473
474       - ``V4L2_BUF_FLAG_MAPPED``
475       - 0x00000001
476       - The buffer resides in device memory and has been mapped into the
477         application's address space, see :ref:`mmap` for details.
478         Drivers set or clear this flag when the
479         :ref:`VIDIOC_QUERYBUF`,
480         :ref:`VIDIOC_QBUF` or
481         :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Set by the
482         driver.
483     * .. _`V4L2-BUF-FLAG-QUEUED`:
484
485       - ``V4L2_BUF_FLAG_QUEUED``
486       - 0x00000002
487       - Internally drivers maintain two buffer queues, an incoming and
488         outgoing queue. When this flag is set, the buffer is currently on
489         the incoming queue. It automatically moves to the outgoing queue
490         after the buffer has been filled (capture devices) or displayed
491         (output devices). Drivers set or clear this flag when the
492         ``VIDIOC_QUERYBUF`` ioctl is called. After (successful) calling
493         the ``VIDIOC_QBUF``\ ioctl it is always set and after
494         ``VIDIOC_DQBUF`` always cleared.
495     * .. _`V4L2-BUF-FLAG-DONE`:
496
497       - ``V4L2_BUF_FLAG_DONE``
498       - 0x00000004
499       - When this flag is set, the buffer is currently on the outgoing
500         queue, ready to be dequeued from the driver. Drivers set or clear
501         this flag when the ``VIDIOC_QUERYBUF`` ioctl is called. After
502         calling the ``VIDIOC_QBUF`` or ``VIDIOC_DQBUF`` it is always
503         cleared. Of course a buffer cannot be on both queues at the same
504         time, the ``V4L2_BUF_FLAG_QUEUED`` and ``V4L2_BUF_FLAG_DONE`` flag
505         are mutually exclusive. They can be both cleared however, then the
506         buffer is in "dequeued" state, in the application domain so to
507         say.
508     * .. _`V4L2-BUF-FLAG-ERROR`:
509
510       - ``V4L2_BUF_FLAG_ERROR``
511       - 0x00000040
512       - When this flag is set, the buffer has been dequeued successfully,
513         although the data might have been corrupted. This is recoverable,
514         streaming may continue as normal and the buffer may be reused
515         normally. Drivers set this flag when the ``VIDIOC_DQBUF`` ioctl is
516         called.
517     * .. _`V4L2-BUF-FLAG-KEYFRAME`:
518
519       - ``V4L2_BUF_FLAG_KEYFRAME``
520       - 0x00000008
521       - Drivers set or clear this flag when calling the ``VIDIOC_DQBUF``
522         ioctl. It may be set by video capture devices when the buffer
523         contains a compressed image which is a key frame (or field), i. e.
524         can be decompressed on its own. Also known as an I-frame.
525         Applications can set this bit when ``type`` refers to an output
526         stream.
527     * .. _`V4L2-BUF-FLAG-PFRAME`:
528
529       - ``V4L2_BUF_FLAG_PFRAME``
530       - 0x00000010
531       - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags predicted frames
532         or fields which contain only differences to a previous key frame.
533         Applications can set this bit when ``type`` refers to an output
534         stream.
535     * .. _`V4L2-BUF-FLAG-BFRAME`:
536
537       - ``V4L2_BUF_FLAG_BFRAME``
538       - 0x00000020
539       - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags a bi-directional
540         predicted frame or field which contains only the differences
541         between the current frame and both the preceding and following key
542         frames to specify its content. Applications can set this bit when
543         ``type`` refers to an output stream.
544     * .. _`V4L2-BUF-FLAG-TIMECODE`:
545
546       - ``V4L2_BUF_FLAG_TIMECODE``
547       - 0x00000100
548       - The ``timecode`` field is valid. Drivers set or clear this flag
549         when the ``VIDIOC_DQBUF`` ioctl is called. Applications can set
550         this bit and the corresponding ``timecode`` structure when
551         ``type`` refers to an output stream.
552     * .. _`V4L2-BUF-FLAG-PREPARED`:
553
554       - ``V4L2_BUF_FLAG_PREPARED``
555       - 0x00000400
556       - The buffer has been prepared for I/O and can be queued by the
557         application. Drivers set or clear this flag when the
558         :ref:`VIDIOC_QUERYBUF`,
559         :ref:`VIDIOC_PREPARE_BUF <VIDIOC_QBUF>`,
560         :ref:`VIDIOC_QBUF` or
561         :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called.
562     * .. _`V4L2-BUF-FLAG-NO-CACHE-INVALIDATE`:
563
564       - ``V4L2_BUF_FLAG_NO_CACHE_INVALIDATE``
565       - 0x00000800
566       - Caches do not have to be invalidated for this buffer. Typically
567         applications shall use this flag if the data captured in the
568         buffer is not going to be touched by the CPU, instead the buffer
569         will, probably, be passed on to a DMA-capable hardware unit for
570         further processing or output.
571     * .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`:
572
573       - ``V4L2_BUF_FLAG_NO_CACHE_CLEAN``
574       - 0x00001000
575       - Caches do not have to be cleaned for this buffer. Typically
576         applications shall use this flag for output buffers if the data in
577         this buffer has not been created by the CPU but by some
578         DMA-capable unit, in which case caches have not been used.
579     * .. _`V4L2-BUF-FLAG-LAST`:
580
581       - ``V4L2_BUF_FLAG_LAST``
582       - 0x00100000
583       - Last buffer produced by the hardware. mem2mem codec drivers set
584         this flag on the capture queue for the last buffer when the
585         :ref:`VIDIOC_QUERYBUF` or
586         :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Due to
587         hardware limitations, the last buffer may be empty. In this case
588         the driver will set the ``bytesused`` field to 0, regardless of
589         the format. Any Any subsequent call to the
590         :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
591         but return an ``EPIPE`` error code.
592     * .. _`V4L2-BUF-FLAG-TIMESTAMP-MASK`:
593
594       - ``V4L2_BUF_FLAG_TIMESTAMP_MASK``
595       - 0x0000e000
596       - Mask for timestamp types below. To test the timestamp type, mask
597         out bits not belonging to timestamp type by performing a logical
598         and operation with buffer flags and timestamp mask.
599     * .. _`V4L2-BUF-FLAG-TIMESTAMP-UNKNOWN`:
600
601       - ``V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN``
602       - 0x00000000
603       - Unknown timestamp type. This type is used by drivers before Linux
604         3.9 and may be either monotonic (see below) or realtime (wall
605         clock). Monotonic clock has been favoured in embedded systems
606         whereas most of the drivers use the realtime clock. Either kinds
607         of timestamps are available in user space via
608         :c:func:`clock_gettime` using clock IDs ``CLOCK_MONOTONIC``
609         and ``CLOCK_REALTIME``, respectively.
610     * .. _`V4L2-BUF-FLAG-TIMESTAMP-MONOTONIC`:
611
612       - ``V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC``
613       - 0x00002000
614       - The buffer timestamp has been taken from the ``CLOCK_MONOTONIC``
615         clock. To access the same clock outside V4L2, use
616         :c:func:`clock_gettime`.
617     * .. _`V4L2-BUF-FLAG-TIMESTAMP-COPY`:
618
619       - ``V4L2_BUF_FLAG_TIMESTAMP_COPY``
620       - 0x00004000
621       - The CAPTURE buffer timestamp has been taken from the corresponding
622         OUTPUT buffer. This flag applies only to mem2mem devices.
623     * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-MASK`:
624
625       - ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK``
626       - 0x00070000
627       - Mask for timestamp sources below. The timestamp source defines the
628         point of time the timestamp is taken in relation to the frame.
629         Logical 'and' operation between the ``flags`` field and
630         ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` produces the value of the
631         timestamp source. Applications must set the timestamp source when
632         ``type`` refers to an output stream and
633         ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` is set.
634     * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-EOF`:
635
636       - ``V4L2_BUF_FLAG_TSTAMP_SRC_EOF``
637       - 0x00000000
638       - End Of Frame. The buffer timestamp has been taken when the last
639         pixel of the frame has been received or the last pixel of the
640         frame has been transmitted. In practice, software generated
641         timestamps will typically be read from the clock a small amount of
642         time after the last pixel has been received or transmitten,
643         depending on the system and other activity in it.
644     * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-SOE`:
645
646       - ``V4L2_BUF_FLAG_TSTAMP_SRC_SOE``
647       - 0x00010000
648       - Start Of Exposure. The buffer timestamp has been taken when the
649         exposure of the frame has begun. This is only valid for the
650         ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type.
651
652
653
654 .. c:type:: v4l2_memory
655
656 enum v4l2_memory
657 ================
658
659 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
660
661 .. flat-table::
662     :header-rows:  0
663     :stub-columns: 0
664     :widths:       3 1 4
665
666     * - ``V4L2_MEMORY_MMAP``
667       - 1
668       - The buffer is used for :ref:`memory mapping <mmap>` I/O.
669     * - ``V4L2_MEMORY_USERPTR``
670       - 2
671       - The buffer is used for :ref:`user pointer <userp>` I/O.
672     * - ``V4L2_MEMORY_OVERLAY``
673       - 3
674       - [to do]
675     * - ``V4L2_MEMORY_DMABUF``
676       - 4
677       - The buffer is used for :ref:`DMA shared buffer <dmabuf>` I/O.
678
679
680
681 Timecodes
682 =========
683
684 The struct :c:type:`v4l2_timecode` structure is designed to hold a
685 :ref:`smpte12m` or similar timecode. (struct
686 struct :c:type:`timeval` timestamps are stored in struct
687 :c:type:`v4l2_buffer` field ``timestamp``.)
688
689
690 .. c:type:: v4l2_timecode
691
692 struct v4l2_timecode
693 --------------------
694
695 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
696
697 .. flat-table::
698     :header-rows:  0
699     :stub-columns: 0
700     :widths:       1 1 2
701
702     * - __u32
703       - ``type``
704       - Frame rate the timecodes are based on, see :ref:`timecode-type`.
705     * - __u32
706       - ``flags``
707       - Timecode flags, see :ref:`timecode-flags`.
708     * - __u8
709       - ``frames``
710       - Frame count, 0 ... 23/24/29/49/59, depending on the type of
711         timecode.
712     * - __u8
713       - ``seconds``
714       - Seconds count, 0 ... 59. This is a binary, not BCD number.
715     * - __u8
716       - ``minutes``
717       - Minutes count, 0 ... 59. This is a binary, not BCD number.
718     * - __u8
719       - ``hours``
720       - Hours count, 0 ... 29. This is a binary, not BCD number.
721     * - __u8
722       - ``userbits``\ [4]
723       - The "user group" bits from the timecode.
724
725
726
727 .. _timecode-type:
728
729 Timecode Types
730 --------------
731
732 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
733
734 .. flat-table::
735     :header-rows:  0
736     :stub-columns: 0
737     :widths:       3 1 4
738
739     * - ``V4L2_TC_TYPE_24FPS``
740       - 1
741       - 24 frames per second, i. e. film.
742     * - ``V4L2_TC_TYPE_25FPS``
743       - 2
744       - 25 frames per second, i. e. PAL or SECAM video.
745     * - ``V4L2_TC_TYPE_30FPS``
746       - 3
747       - 30 frames per second, i. e. NTSC video.
748     * - ``V4L2_TC_TYPE_50FPS``
749       - 4
750       -
751     * - ``V4L2_TC_TYPE_60FPS``
752       - 5
753       -
754
755
756
757 .. _timecode-flags:
758
759 Timecode Flags
760 --------------
761
762 .. tabularcolumns:: |p{6.6cm}|p{1.4cm}|p{9.5cm}|
763
764 .. flat-table::
765     :header-rows:  0
766     :stub-columns: 0
767     :widths:       3 1 4
768
769     * - ``V4L2_TC_FLAG_DROPFRAME``
770       - 0x0001
771       - Indicates "drop frame" semantics for counting frames in 29.97 fps
772         material. When set, frame numbers 0 and 1 at the start of each
773         minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the
774         count.
775     * - ``V4L2_TC_FLAG_COLORFRAME``
776       - 0x0002
777       - The "color frame" flag.
778     * - ``V4L2_TC_USERBITS_field``
779       - 0x000C
780       - Field mask for the "binary group flags".
781     * - ``V4L2_TC_USERBITS_USERDEFINED``
782       - 0x0000
783       - Unspecified format.
784     * - ``V4L2_TC_USERBITS_8BITCHARS``
785       - 0x0008
786       - 8-bit ISO characters.