buffer.rst 24.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
.. -*- coding: utf-8; mode: rst -*-

.. _buffer:

*******
Buffers
*******

A buffer contains data exchanged by application and driver using one of
the Streaming I/O methods. In the multi-planar API, the data is held in
planes, while the buffer structure acts as a container for the planes.
Only pointers to buffers (planes) are exchanged, the data itself is not
copied. These pointers, together with meta-information like timestamps
14
or field parity, are stored in a struct :c:type:`struct v4l2_buffer <v4l2_buffer>`,
15 16
argument to the :ref:`VIDIOC_QUERYBUF`,
: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:`struct v4l2_buffer <v4l2_buffer>`,
19
such as pointers and sizes for each plane, are stored in struct
20 21
:c:type:`struct v4l2_plane <v4l2_plane>` instead. In that case, struct
:c:type:`struct v4l2_buffer <v4l2_buffer>` contains an array of plane structures.
22 23 24 25 26 27 28

Dequeued video buffers come with timestamps. The driver decides at which
part of the frame and with which clock the timestamp is taken. Please
see flags in the masks ``V4L2_BUF_FLAG_TIMESTAMP_MASK`` and
``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` in :ref:`buffer-flags`. These flags
are always valid and constant across all buffers during the whole video
stream. Changes in these flags may take place as a side effect of
29 30
:ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` or
:ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` however. The
31 32 33 34 35 36
``V4L2_BUF_FLAG_TIMESTAMP_COPY`` timestamp type which is used by e.g. on
mem-to-mem devices is an exception to the rule: the timestamp source
flags are copied from the OUTPUT video buffer to the CAPTURE video
buffer.


37
.. c:type:: v4l2_buffer
38

39 40 41
struct v4l2_buffer
==================

42
.. tabularcolumns:: |p{2.8cm}|p{2.5cm}|p{1.3cm}|p{10.5cm}|
43 44

.. cssclass:: longtable
45

46 47 48
.. flat-table:: struct v4l2_buffer
    :header-rows:  0
    :stub-columns: 0
49
    :widths:       1 2 1 10
50 51 52 53 54 55 56 57


    -  .. row 1

       -  __u32

       -  ``index``

58
       -
59
       -  Number of the buffer, set by the application except when calling
60 61 62
	  :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`, then it is set by the
	  driver. This field can range from zero to the number of buffers
	  allocated with the :ref:`VIDIOC_REQBUFS` ioctl
63
	  (struct :c:type:`v4l2_requestbuffers`
64 65
	  ``count``), plus any buffers allocated with
	  :ref:`VIDIOC_CREATE_BUFS` minus one.
66 67 68 69 70 71 72

    -  .. row 2

       -  __u32

       -  ``type``

73
       -
74
       -  Type of the buffer, same as struct
75 76
	  :c:type:`v4l2_format` ``type`` or struct
	  :c:type:`v4l2_requestbuffers` ``type``, set
77
	  by the application. See :ref:`v4l2-buf-type`
78 79 80 81 82 83 84

    -  .. row 3

       -  __u32

       -  ``bytesused``

85
       -
86
       -  The number of bytes occupied by the data in the buffer. It depends
87 88 89 90 91 92 93 94
	  on the negotiated data format and may change with each buffer for
	  compressed variable size data like JPEG images. Drivers must set
	  this field when ``type`` refers to a capture stream, applications
	  when it refers to an output stream. If the application sets this
	  to 0 for an output stream, then ``bytesused`` will be set to the
	  size of the buffer (see the ``length`` field of this struct) by
	  the driver. For multiplanar formats this field is ignored and the
	  ``planes`` pointer is used instead.
95 96 97 98 99 100 101

    -  .. row 4

       -  __u32

       -  ``flags``

102
       -
103 104 105 106 107 108 109 110
       -  Flags set by the application or driver, see :ref:`buffer-flags`.

    -  .. row 5

       -  __u32

       -  ``field``

111
       -
112
       -  Indicates the field order of the image in the buffer, see
113 114 115
	  :ref:`v4l2-field`. This field is not used when the buffer
	  contains VBI data. Drivers must set it when ``type`` refers to a
	  capture stream, applications when it refers to an output stream.
116 117 118 119 120 121 122

    -  .. row 6

       -  struct timeval

       -  ``timestamp``

123
       -
124
       -  For capture streams this is time when the first data byte was
125 126 127 128 129 130 131 132 133
	  captured, as returned by the :c:func:`clock_gettime()` function
	  for the relevant clock id; see ``V4L2_BUF_FLAG_TIMESTAMP_*`` in
	  :ref:`buffer-flags`. For output streams the driver stores the
	  time at which the last data byte was actually sent out in the
	  ``timestamp`` field. This permits applications to monitor the
	  drift between the video and system clock. For output streams that
	  use ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` the application has to fill
	  in the timestamp which will be copied by the driver to the capture
	  stream.
134 135 136

    -  .. row 7

137
       -  struct :c:type:`v4l2_timecode`
138 139 140

       -  ``timecode``

141
       -
142
       -  When ``type`` is ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` and the
143 144 145 146 147 148 149
	  ``V4L2_BUF_FLAG_TIMECODE`` flag is set in ``flags``, this
	  structure contains a frame timecode. In
	  :ref:`V4L2_FIELD_ALTERNATE <v4l2-field>` mode the top and
	  bottom field contain the same timecode. Timecodes are intended to
	  help video editing and are typically recorded on video tapes, but
	  also embedded in compressed formats like MPEG. This field is
	  independent of the ``timestamp`` and ``sequence`` fields.
150 151 152 153 154 155 156

    -  .. row 8

       -  __u32

       -  ``sequence``

157
       -
158
       -  Set by the driver, counting the frames (not fields!) in sequence.
159
	  This field is set for both input and output devices.
160 161 162 163 164

    -  .. row 9

       -  :cspan:`3`

165 166 167 168 169 170 171
	  In :ref:`V4L2_FIELD_ALTERNATE <v4l2-field>` mode the top and
	  bottom field have the same sequence number. The count starts at
	  zero and includes dropped or repeated frames. A dropped frame was
	  received by an input device but could not be stored due to lack of
	  free buffer space. A repeated frame was displayed again by an
	  output device because the application did not pass new data in
	  time.
172

173 174 175
	  .. note::

	     This may count the frames received e.g. over USB, without
176 177 178 179
	     taking into account the frames dropped by the remote hardware due
	     to limited compression throughput or bus bandwidth. These devices
	     identify by not enumerating any video standards, see
	     :ref:`standard`.
180

181

182 183 184 185 186 187
    -  .. row 10

       -  __u32

       -  ``memory``

188
       -
189
       -  This field must be set by applications and/or drivers in
190
	  accordance with the selected I/O method. See :ref:`v4l2-memory`
191 192 193 194 195 196 197 198 199

    -  .. row 11

       -  union

       -  ``m``

    -  .. row 12

200
       -
201 202 203 204 205
       -  __u32

       -  ``offset``

       -  For the single-planar API and when ``memory`` is
206 207 208 209 210
	  ``V4L2_MEMORY_MMAP`` this is the offset of the buffer from the
	  start of the device memory. The value is returned by the driver
	  and apart of serving as parameter to the
	  :ref:`mmap() <func-mmap>` function not useful for applications.
	  See :ref:`mmap` for details
211 212 213

    -  .. row 13

214
       -
215 216 217 218 219
       -  unsigned long

       -  ``userptr``

       -  For the single-planar API and when ``memory`` is
220 221 222
	  ``V4L2_MEMORY_USERPTR`` this is a pointer to the buffer (casted to
	  unsigned long type) in virtual memory, set by the application. See
	  :ref:`userp` for details.
223 224 225

    -  .. row 14

226
       -
227 228 229 230 231
       -  struct v4l2_plane

       -  ``*planes``

       -  When using the multi-planar API, contains a userspace pointer to
232
	  an array of struct :c:type:`v4l2_plane`. The size of
233
	  the array should be put in the ``length`` field of this
234
	  :c:type:`struct v4l2_buffer <v4l2_buffer>` structure.
235 236 237

    -  .. row 15

238
       -
239 240 241 242 243
       -  int

       -  ``fd``

       -  For the single-plane API and when ``memory`` is
244 245
	  ``V4L2_MEMORY_DMABUF`` this is the file descriptor associated with
	  a DMABUF buffer.
246 247 248 249 250 251 252

    -  .. row 16

       -  __u32

       -  ``length``

253
       -
254
       -  Size of the buffer (not the payload) in bytes for the
255 256 257 258 259 260
	  single-planar API. This is set by the driver based on the calls to
	  :ref:`VIDIOC_REQBUFS` and/or
	  :ref:`VIDIOC_CREATE_BUFS`. For the
	  multi-planar API the application sets this to the number of
	  elements in the ``planes`` array. The driver will fill in the
	  actual number of valid elements in that array.
261 262 263 264 265 266 267

    -  .. row 17

       -  __u32

       -  ``reserved2``

268
       -
269
       -  A place holder for future extensions. Drivers and applications
270
	  must set this to 0.
271 272 273 274 275 276 277

    -  .. row 18

       -  __u32

       -  ``reserved``

278
       -
279
       -  A place holder for future extensions. Drivers and applications
280
	  must set this to 0.
281 282 283



284
.. c:type:: v4l2_plane
285

286 287 288
struct v4l2_plane
=================

289 290
.. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{7.0cm}|

291 292
.. cssclass:: longtable

293
.. flat-table::
294 295 296 297 298 299 300 301 302 303 304
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 1 2


    -  .. row 1

       -  __u32

       -  ``bytesused``

305
       -
306
       -  The number of bytes occupied by data in the plane (its payload).
307 308 309 310
	  Drivers must set this field when ``type`` refers to a capture
	  stream, applications when it refers to an output stream. If the
	  application sets this to 0 for an output stream, then
	  ``bytesused`` will be set to the size of the plane (see the
311 312
	  ``length`` field of this struct) by the driver.

313 314 315
	  .. note::

	     Note that the actual image data starts at ``data_offset``
316
	     which may not be 0.
317 318 319 320 321 322 323

    -  .. row 2

       -  __u32

       -  ``length``

324
       -
325
       -  Size in bytes of the plane (not its payload). This is set by the
326 327 328
	  driver based on the calls to
	  :ref:`VIDIOC_REQBUFS` and/or
	  :ref:`VIDIOC_CREATE_BUFS`.
329 330 331 332 333 334 335

    -  .. row 3

       -  union

       -  ``m``

336 337
       -
       -
338 339 340

    -  .. row 4

341
       -
342 343 344 345 346
       -  __u32

       -  ``mem_offset``

       -  When the memory type in the containing struct
347
	  :c:type:`v4l2_buffer` is ``V4L2_MEMORY_MMAP``, this
348 349
	  is the value that should be passed to :ref:`mmap() <func-mmap>`,
	  similar to the ``offset`` field in struct
350
	  :c:type:`v4l2_buffer`.
351 352 353

    -  .. row 5

354
       -
355 356 357 358 359
       -  unsigned long

       -  ``userptr``

       -  When the memory type in the containing struct
360
	  :c:type:`v4l2_buffer` is ``V4L2_MEMORY_USERPTR``,
361 362
	  this is a userspace pointer to the memory allocated for this plane
	  by an application.
363 364 365

    -  .. row 6

366
       -
367 368 369 370 371
       -  int

       -  ``fd``

       -  When the memory type in the containing struct
372
	  :c:type:`v4l2_buffer` is ``V4L2_MEMORY_DMABUF``,
373
	  this is a file descriptor associated with a DMABUF buffer, similar
374
	  to the ``fd`` field in struct :c:type:`v4l2_buffer`.
375 376 377 378 379 380 381

    -  .. row 7

       -  __u32

       -  ``data_offset``

382
       -
383
       -  Offset in bytes to video data in the plane. Drivers must set this
384
	  field when ``type`` refers to a capture stream, applications when
385 386
	  it refers to an output stream.

387 388 389
	  .. note::

	     That data_offset is included  in ``bytesused``. So the
390 391
	     size of the image in the plane is ``bytesused``-``data_offset``
	     at offset ``data_offset`` from the start of the plane.
392 393 394 395 396

    -  .. row 8

       -  __u32

397
       -  ``reserved[11]``
398

399
       -
400
       -  Reserved for future use. Should be zeroed by drivers and
401
	  applications.
402 403 404 405 406



.. _v4l2-buf-type:

407 408 409
enum v4l2_buf_type
==================

410 411 412
.. cssclass:: longtable

.. tabularcolumns:: |p{7.2cm}|p{0.6cm}|p{9.7cm}|
413

414
.. flat-table::
415 416
    :header-rows:  0
    :stub-columns: 0
417
    :widths:       4 1 9
418 419 420 421 422 423 424 425 426


    -  .. row 1

       -  ``V4L2_BUF_TYPE_VIDEO_CAPTURE``

       -  1

       -  Buffer of a single-planar video capture stream, see
427
	  :ref:`capture`.
428 429 430 431 432 433 434 435

    -  .. row 2

       -  ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``

       -  9

       -  Buffer of a multi-planar video capture stream, see
436
	  :ref:`capture`.
437 438 439 440 441 442 443 444

    -  .. row 3

       -  ``V4L2_BUF_TYPE_VIDEO_OUTPUT``

       -  2

       -  Buffer of a single-planar video output stream, see
445
	  :ref:`output`.
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509

    -  .. row 4

       -  ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``

       -  10

       -  Buffer of a multi-planar video output stream, see :ref:`output`.

    -  .. row 5

       -  ``V4L2_BUF_TYPE_VIDEO_OVERLAY``

       -  3

       -  Buffer for video overlay, see :ref:`overlay`.

    -  .. row 6

       -  ``V4L2_BUF_TYPE_VBI_CAPTURE``

       -  4

       -  Buffer of a raw VBI capture stream, see :ref:`raw-vbi`.

    -  .. row 7

       -  ``V4L2_BUF_TYPE_VBI_OUTPUT``

       -  5

       -  Buffer of a raw VBI output stream, see :ref:`raw-vbi`.

    -  .. row 8

       -  ``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE``

       -  6

       -  Buffer of a sliced VBI capture stream, see :ref:`sliced`.

    -  .. row 9

       -  ``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``

       -  7

       -  Buffer of a sliced VBI output stream, see :ref:`sliced`.

    -  .. row 10

       -  ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``

       -  8

       -  Buffer for video output overlay (OSD), see :ref:`osd`.

    -  .. row 11

       -  ``V4L2_BUF_TYPE_SDR_CAPTURE``

       -  11

       -  Buffer for Software Defined Radio (SDR) capture stream, see
510
	  :ref:`sdr`.
511 512 513 514 515 516 517 518

    -  .. row 12

       -  ``V4L2_BUF_TYPE_SDR_OUTPUT``

       -  12

       -  Buffer for Software Defined Radio (SDR) output stream, see
519
	  :ref:`sdr`.
520 521 522 523 524



.. _buffer-flags:

525 526 527
Buffer Flags
============

528 529 530
.. tabularcolumns:: |p{7.0cm}|p{2.2cm}|p{8.3cm}|

.. cssclass:: longtable
531

532
.. flat-table::
533 534 535 536 537
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


538
    -  .. _`V4L2-BUF-FLAG-MAPPED`:
539 540 541 542 543 544

       -  ``V4L2_BUF_FLAG_MAPPED``

       -  0x00000001

       -  The buffer resides in device memory and has been mapped into the
545 546 547 548 549 550
	  application's address space, see :ref:`mmap` for details.
	  Drivers set or clear this flag when the
	  :ref:`VIDIOC_QUERYBUF`,
	  :ref:`VIDIOC_QBUF` or
	  :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Set by the
	  driver.
551

552
    -  .. _`V4L2-BUF-FLAG-QUEUED`:
553 554 555 556 557 558

       -  ``V4L2_BUF_FLAG_QUEUED``

       -  0x00000002

       -  Internally drivers maintain two buffer queues, an incoming and
559 560 561 562 563 564 565
	  outgoing queue. When this flag is set, the buffer is currently on
	  the incoming queue. It automatically moves to the outgoing queue
	  after the buffer has been filled (capture devices) or displayed
	  (output devices). Drivers set or clear this flag when the
	  ``VIDIOC_QUERYBUF`` ioctl is called. After (successful) calling
	  the ``VIDIOC_QBUF``\ ioctl it is always set and after
	  ``VIDIOC_DQBUF`` always cleared.
566

567
    -  .. _`V4L2-BUF-FLAG-DONE`:
568 569 570 571 572 573

       -  ``V4L2_BUF_FLAG_DONE``

       -  0x00000004

       -  When this flag is set, the buffer is currently on the outgoing
574 575 576 577 578 579 580 581
	  queue, ready to be dequeued from the driver. Drivers set or clear
	  this flag when the ``VIDIOC_QUERYBUF`` ioctl is called. After
	  calling the ``VIDIOC_QBUF`` or ``VIDIOC_DQBUF`` it is always
	  cleared. Of course a buffer cannot be on both queues at the same
	  time, the ``V4L2_BUF_FLAG_QUEUED`` and ``V4L2_BUF_FLAG_DONE`` flag
	  are mutually exclusive. They can be both cleared however, then the
	  buffer is in "dequeued" state, in the application domain so to
	  say.
582

583
    -  .. _`V4L2-BUF-FLAG-ERROR`:
584 585 586 587 588 589

       -  ``V4L2_BUF_FLAG_ERROR``

       -  0x00000040

       -  When this flag is set, the buffer has been dequeued successfully,
590 591 592 593
	  although the data might have been corrupted. This is recoverable,
	  streaming may continue as normal and the buffer may be reused
	  normally. Drivers set this flag when the ``VIDIOC_DQBUF`` ioctl is
	  called.
594

595
    -  .. _`V4L2-BUF-FLAG-KEYFRAME`:
596 597 598 599 600 601

       -  ``V4L2_BUF_FLAG_KEYFRAME``

       -  0x00000008

       -  Drivers set or clear this flag when calling the ``VIDIOC_DQBUF``
602 603 604 605 606
	  ioctl. It may be set by video capture devices when the buffer
	  contains a compressed image which is a key frame (or field), i. e.
	  can be decompressed on its own. Also known as an I-frame.
	  Applications can set this bit when ``type`` refers to an output
	  stream.
607

608
    -  .. _`V4L2-BUF-FLAG-PFRAME`:
609 610 611 612 613 614

       -  ``V4L2_BUF_FLAG_PFRAME``

       -  0x00000010

       -  Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags predicted frames
615 616 617
	  or fields which contain only differences to a previous key frame.
	  Applications can set this bit when ``type`` refers to an output
	  stream.
618

619
    -  .. _`V4L2-BUF-FLAG-BFRAME`:
620 621 622 623 624 625

       -  ``V4L2_BUF_FLAG_BFRAME``

       -  0x00000020

       -  Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags a bi-directional
626 627 628 629
	  predicted frame or field which contains only the differences
	  between the current frame and both the preceding and following key
	  frames to specify its content. Applications can set this bit when
	  ``type`` refers to an output stream.
630

631
    -  .. _`V4L2-BUF-FLAG-TIMECODE`:
632 633 634 635 636 637

       -  ``V4L2_BUF_FLAG_TIMECODE``

       -  0x00000100

       -  The ``timecode`` field is valid. Drivers set or clear this flag
638 639 640
	  when the ``VIDIOC_DQBUF`` ioctl is called. Applications can set
	  this bit and the corresponding ``timecode`` structure when
	  ``type`` refers to an output stream.
641

642
    -  .. _`V4L2-BUF-FLAG-PREPARED`:
643 644 645 646 647 648

       -  ``V4L2_BUF_FLAG_PREPARED``

       -  0x00000400

       -  The buffer has been prepared for I/O and can be queued by the
649 650 651 652 653
	  application. Drivers set or clear this flag when the
	  :ref:`VIDIOC_QUERYBUF`,
	  :ref:`VIDIOC_PREPARE_BUF <VIDIOC_QBUF>`,
	  :ref:`VIDIOC_QBUF` or
	  :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called.
654

655
    -  .. _`V4L2-BUF-FLAG-NO-CACHE-INVALIDATE`:
656 657 658 659 660 661

       -  ``V4L2_BUF_FLAG_NO_CACHE_INVALIDATE``

       -  0x00000800

       -  Caches do not have to be invalidated for this buffer. Typically
662 663 664 665
	  applications shall use this flag if the data captured in the
	  buffer is not going to be touched by the CPU, instead the buffer
	  will, probably, be passed on to a DMA-capable hardware unit for
	  further processing or output.
666

667
    -  .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`:
668 669 670 671 672 673

       -  ``V4L2_BUF_FLAG_NO_CACHE_CLEAN``

       -  0x00001000

       -  Caches do not have to be cleaned for this buffer. Typically
674 675 676
	  applications shall use this flag for output buffers if the data in
	  this buffer has not been created by the CPU but by some
	  DMA-capable unit, in which case caches have not been used.
677

678
    -  .. _`V4L2-BUF-FLAG-LAST`:
679 680 681 682 683 684

       -  ``V4L2_BUF_FLAG_LAST``

       -  0x00100000

       -  Last buffer produced by the hardware. mem2mem codec drivers set
685 686 687 688 689 690 691 692
	  this flag on the capture queue for the last buffer when the
	  :ref:`VIDIOC_QUERYBUF` or
	  :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Due to
	  hardware limitations, the last buffer may be empty. In this case
	  the driver will set the ``bytesused`` field to 0, regardless of
	  the format. Any Any subsequent call to the
	  :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
	  but return an ``EPIPE`` error code.
693

694
    -  .. _`V4L2-BUF-FLAG-TIMESTAMP-MASK`:
695 696 697 698 699 700

       -  ``V4L2_BUF_FLAG_TIMESTAMP_MASK``

       -  0x0000e000

       -  Mask for timestamp types below. To test the timestamp type, mask
701 702
	  out bits not belonging to timestamp type by performing a logical
	  and operation with buffer flags and timestamp mask.
703

704
    -  .. _`V4L2-BUF-FLAG-TIMESTAMP-UNKNOWN`:
705 706 707 708 709 710

       -  ``V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN``

       -  0x00000000

       -  Unknown timestamp type. This type is used by drivers before Linux
711 712 713 714 715 716
	  3.9 and may be either monotonic (see below) or realtime (wall
	  clock). Monotonic clock has been favoured in embedded systems
	  whereas most of the drivers use the realtime clock. Either kinds
	  of timestamps are available in user space via
	  :c:func:`clock_gettime(2)` using clock IDs ``CLOCK_MONOTONIC``
	  and ``CLOCK_REALTIME``, respectively.
717

718
    -  .. _`V4L2-BUF-FLAG-TIMESTAMP-MONOTONIC`:
719 720 721 722 723 724

       -  ``V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC``

       -  0x00002000

       -  The buffer timestamp has been taken from the ``CLOCK_MONOTONIC``
725 726
	  clock. To access the same clock outside V4L2, use
	  :c:func:`clock_gettime(2)`.
727

728
    -  .. _`V4L2-BUF-FLAG-TIMESTAMP-COPY`:
729 730 731 732 733 734

       -  ``V4L2_BUF_FLAG_TIMESTAMP_COPY``

       -  0x00004000

       -  The CAPTURE buffer timestamp has been taken from the corresponding
735
	  OUTPUT buffer. This flag applies only to mem2mem devices.
736

737
    -  .. _`V4L2-BUF-FLAG-TSTAMP-SRC-MASK`:
738 739 740 741 742 743

       -  ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK``

       -  0x00070000

       -  Mask for timestamp sources below. The timestamp source defines the
744 745 746 747 748 749
	  point of time the timestamp is taken in relation to the frame.
	  Logical 'and' operation between the ``flags`` field and
	  ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` produces the value of the
	  timestamp source. Applications must set the timestamp source when
	  ``type`` refers to an output stream and
	  ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` is set.
750

751
    -  .. _`V4L2-BUF-FLAG-TSTAMP-SRC-EOF`:
752 753 754 755 756 757

       -  ``V4L2_BUF_FLAG_TSTAMP_SRC_EOF``

       -  0x00000000

       -  End Of Frame. The buffer timestamp has been taken when the last
758 759 760 761 762
	  pixel of the frame has been received or the last pixel of the
	  frame has been transmitted. In practice, software generated
	  timestamps will typically be read from the clock a small amount of
	  time after the last pixel has been received or transmitten,
	  depending on the system and other activity in it.
763

764
    -  .. _`V4L2-BUF-FLAG-TSTAMP-SRC-SOE`:
765 766 767 768 769 770

       -  ``V4L2_BUF_FLAG_TSTAMP_SRC_SOE``

       -  0x00010000

       -  Start Of Exposure. The buffer timestamp has been taken when the
771 772
	  exposure of the frame has begun. This is only valid for the
	  ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type.
773 774 775 776 777



.. _v4l2-memory:

778 779 780
enum v4l2_memory
================

781 782
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|

783
.. flat-table::
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_MEMORY_MMAP``

       -  1

       -  The buffer is used for :ref:`memory mapping <mmap>` I/O.

    -  .. row 2

       -  ``V4L2_MEMORY_USERPTR``

       -  2

       -  The buffer is used for :ref:`user pointer <userp>` I/O.

    -  .. row 3

       -  ``V4L2_MEMORY_OVERLAY``

       -  3

       -  [to do]

    -  .. row 4

       -  ``V4L2_MEMORY_DMABUF``

       -  4

       -  The buffer is used for :ref:`DMA shared buffer <dmabuf>` I/O.



Timecodes
=========

826
The :c:type:`struct v4l2_timecode <v4l2_timecode>` structure is designed to hold a
827 828
:ref:`smpte12m` or similar timecode. (struct
:c:type:`struct timeval` timestamps are stored in struct
829
:c:type:`v4l2_buffer` field ``timestamp``.)
830 831


832
.. c:type:: v4l2_timecode
833

834 835 836
struct v4l2_timecode
--------------------

837 838
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|

839
.. flat-table::
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u32

       -  ``type``

       -  Frame rate the timecodes are based on, see :ref:`timecode-type`.

    -  .. row 2

       -  __u32

       -  ``flags``

       -  Timecode flags, see :ref:`timecode-flags`.

    -  .. row 3

       -  __u8

       -  ``frames``

       -  Frame count, 0 ... 23/24/29/49/59, depending on the type of
868
	  timecode.
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897

    -  .. row 4

       -  __u8

       -  ``seconds``

       -  Seconds count, 0 ... 59. This is a binary, not BCD number.

    -  .. row 5

       -  __u8

       -  ``minutes``

       -  Minutes count, 0 ... 59. This is a binary, not BCD number.

    -  .. row 6

       -  __u8

       -  ``hours``

       -  Hours count, 0 ... 29. This is a binary, not BCD number.

    -  .. row 7

       -  __u8

898
       -  ``userbits``\ [4]
899 900 901 902 903 904 905

       -  The "user group" bits from the timecode.



.. _timecode-type:

906 907 908
Timecode Types
--------------

909 910
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|

911
.. flat-table::
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_TC_TYPE_24FPS``

       -  1

       -  24 frames per second, i. e. film.

    -  .. row 2

       -  ``V4L2_TC_TYPE_25FPS``

       -  2

       -  25 frames per second, i. e. PAL or SECAM video.

    -  .. row 3

       -  ``V4L2_TC_TYPE_30FPS``

       -  3

       -  30 frames per second, i. e. NTSC video.

    -  .. row 4

       -  ``V4L2_TC_TYPE_50FPS``

       -  4

947
       -
948 949 950 951 952 953 954

    -  .. row 5

       -  ``V4L2_TC_TYPE_60FPS``

       -  5

955
       -
956 957 958 959 960



.. _timecode-flags:

961 962 963
Timecode Flags
--------------

964
.. tabularcolumns:: |p{6.6cm}|p{1.4cm}|p{9.5cm}|
965

966
.. flat-table::
967 968 969 970 971 972 973 974 975 976 977 978
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_TC_FLAG_DROPFRAME``

       -  0x0001

       -  Indicates "drop frame" semantics for counting frames in 29.97 fps
979 980 981
	  material. When set, frame numbers 0 and 1 at the start of each
	  minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the
	  count.
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013

    -  .. row 2

       -  ``V4L2_TC_FLAG_COLORFRAME``

       -  0x0002

       -  The "color frame" flag.

    -  .. row 3

       -  ``V4L2_TC_USERBITS_field``

       -  0x000C

       -  Field mask for the "binary group flags".

    -  .. row 4

       -  ``V4L2_TC_USERBITS_USERDEFINED``

       -  0x0000

       -  Unspecified format.

    -  .. row 5

       -  ``V4L2_TC_USERBITS_8BITCHARS``

       -  0x0008

       -  8-bit ISO characters.