vidioc-dqevent.rst 11.9 KB
Newer Older
1 2
.. -*- coding: utf-8; mode: rst -*-

3
.. _VIDIOC_DQEVENT:
4 5 6 7 8

********************
ioctl VIDIOC_DQEVENT
********************

9
Name
10
====
11

12
VIDIOC_DQEVENT - Dequeue event
13

14 15

Synopsis
16 17
========

18 19
.. c:function:: int ioctl( int fd, VIDIOC_DQEVENT, struct v4l2_event *argp )
    :name: VIDIOC_DQEVENT
20

21

22
Arguments
23 24 25 26 27 28 29 30
=========

``fd``
    File descriptor returned by :ref:`open() <func-open>`.

``argp``


31
Description
32 33 34
===========

Dequeue an event from a video device. No input is required for this
35
ioctl. All the fields of the struct :c:type:`v4l2_event`
36 37 38 39 40
structure are filled by the driver. The file handle will also receive
exceptions which the application may get by e.g. using the select system
call.


41 42
.. tabularcolumns:: |p{3.0cm}|p{4.3cm}|p{2.5cm}|p{7.7cm}|

43
.. c:type:: v4l2_event
44

45
.. cssclass: longtable
46

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


    -  .. row 1

       -  __u32

       -  ``type``

59
       -
60 61 62 63 64 65 66 67
       -  Type of the event, see :ref:`event-type`.

    -  .. row 2

       -  union

       -  ``u``

68 69
       -
       -
70 71 72

    -  .. row 3

73
       -
74
       -  struct :c:type:`v4l2_event_vsync`
75 76 77 78 79 80 81

       -  ``vsync``

       -  Event data for event ``V4L2_EVENT_VSYNC``.

    -  .. row 4

82
       -
83
       -  struct :c:type:`v4l2_event_ctrl`
84 85 86 87 88 89 90

       -  ``ctrl``

       -  Event data for event ``V4L2_EVENT_CTRL``.

    -  .. row 5

91
       -
92
       -  struct :c:type:`v4l2_event_frame_sync`
93 94 95 96 97 98 99

       -  ``frame_sync``

       -  Event data for event ``V4L2_EVENT_FRAME_SYNC``.

    -  .. row 6

100
       -
101
       -  struct :c:type:`v4l2_event_motion_det`
102 103 104 105 106 107 108

       -  ``motion_det``

       -  Event data for event V4L2_EVENT_MOTION_DET.

    -  .. row 7

109
       -
110
       -  struct :c:type:`v4l2_event_src_change`
111 112 113 114 115 116 117

       -  ``src_change``

       -  Event data for event V4L2_EVENT_SOURCE_CHANGE.

    -  .. row 8

118
       -
119 120
       -  __u8

121
       -  ``data``\ [64]
122 123

       -  Event data. Defined by the event type. The union should be used to
124
	  define easily accessible type for events.
125 126 127 128 129 130 131

    -  .. row 9

       -  __u32

       -  ``pending``

132
       -
133 134 135 136 137 138 139 140
       -  Number of pending events excluding this one.

    -  .. row 10

       -  __u32

       -  ``sequence``

141
       -
142
       -  Event sequence number. The sequence number is incremented for
143 144
	  every subscribed event that takes place. If sequence numbers are
	  not contiguous it means that events have been lost.
145 146 147 148 149 150 151

    -  .. row 11

       -  struct timespec

       -  ``timestamp``

152
       -
153
       -  Event timestamp. The timestamp has been taken from the
154
	  ``CLOCK_MONOTONIC`` clock. To access the same clock outside V4L2,
155
	  use :c:func:`clock_gettime`.
156 157 158 159 160 161 162

    -  .. row 12

       -  u32

       -  ``id``

163
       -
164
       -  The ID associated with the event source. If the event does not
165 166
	  have an associated ID (this depends on the event type), then this
	  is 0.
167 168 169 170 171

    -  .. row 13

       -  __u32

172
       -  ``reserved``\ [8]
173

174
       -
175
       -  Reserved for future extensions. Drivers must set the array to
176
	  zero.
177 178 179



180 181
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|

182 183
.. cssclass:: longtable

184 185
.. _event-type:

186 187 188 189 190 191 192 193 194 195 196 197 198
.. flat-table:: Event Types
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_EVENT_ALL``

       -  0

       -  All events. V4L2_EVENT_ALL is valid only for
199
	  VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.
200 201 202 203 204 205 206 207

    -  .. row 2

       -  ``V4L2_EVENT_VSYNC``

       -  1

       -  This event is triggered on the vertical sync. This event has a
208
	  struct :c:type:`v4l2_event_vsync` associated
209
	  with it.
210 211 212 213 214 215 216 217

    -  .. row 3

       -  ``V4L2_EVENT_EOS``

       -  2

       -  This event is triggered when the end of a stream is reached. This
218 219
	  is typically used with MPEG decoders to report to the application
	  when the last of the MPEG stream has been decoded.
220 221 222 223 224 225 226 227

    -  .. row 4

       -  ``V4L2_EVENT_CTRL``

       -  3

       -  This event requires that the ``id`` matches the control ID from
228 229 230
	  which you want to receive events. This event is triggered if the
	  control's value changes, if a button control is pressed or if the
	  control's flags change. This event has a struct
231
	  :c:type:`v4l2_event_ctrl` associated with it.
232 233
	  This struct contains much of the same information as struct
	  :ref:`v4l2_queryctrl <v4l2-queryctrl>` and struct
234
	  :c:type:`v4l2_control`.
235 236 237 238 239 240 241 242 243 244 245

	  If the event is generated due to a call to
	  :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` or
	  :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then the
	  event will *not* be sent to the file handle that called the ioctl
	  function. This prevents nasty feedback loops. If you *do* want to
	  get the event, then set the ``V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK``
	  flag.

	  This event type will ensure that no information is lost when more
	  events are raised than there is room internally. In that case the
246
	  struct :c:type:`v4l2_event_ctrl` of the
247 248 249
	  second-oldest event is kept, but the ``changes`` field of the
	  second-oldest event is ORed with the ``changes`` field of the
	  oldest event.
250 251 252 253 254 255 256 257

    -  .. row 5

       -  ``V4L2_EVENT_FRAME_SYNC``

       -  4

       -  Triggered immediately when the reception of a frame has begun.
258
	  This event has a struct
259
	  :c:type:`v4l2_event_frame_sync`
260
	  associated with it.
261

262 263 264
	  If the hardware needs to be stopped in the case of a buffer
	  underrun it might not be able to generate this event. In such
	  cases the ``frame_sequence`` field in struct
265
	  :c:type:`v4l2_event_frame_sync` will not
266 267
	  be incremented. This causes two consecutive frame sequence numbers
	  to have n times frame interval in between them.
268 269 270 271 272 273 274 275

    -  .. row 6

       -  ``V4L2_EVENT_SOURCE_CHANGE``

       -  5

       -  This event is triggered when a source parameter change is detected
276 277 278 279 280 281 282 283
	  during runtime by the video device. It can be a runtime resolution
	  change triggered by a video decoder or the format change happening
	  on an input connector. This event requires that the ``id`` matches
	  the input index (when used with a video device node) or the pad
	  index (when used with a subdevice node) from which you want to
	  receive events.

	  This event has a struct
284
	  :c:type:`v4l2_event_src_change`
285 286 287 288
	  associated with it. The ``changes`` bitfield denotes what has
	  changed for the subscribed pad. If multiple events occurred before
	  application could dequeue them, then the changes will have the
	  ORed value of all the events generated.
289 290 291 292 293 294 295 296

    -  .. row 7

       -  ``V4L2_EVENT_MOTION_DET``

       -  6

       -  Triggered whenever the motion detection state for one or more of
297
	  the regions changes. This event has a struct
298
	  :c:type:`v4l2_event_motion_det`
299
	  associated with it.
300 301 302 303 304 305 306 307 308 309 310

    -  .. row 8

       -  ``V4L2_EVENT_PRIVATE_START``

       -  0x08000000

       -  Base event number for driver-private events.



311 312
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|

313
.. c:type:: v4l2_event_vsync
314

315 316 317 318 319 320 321 322 323 324 325 326
.. flat-table:: struct v4l2_event_vsync
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u8

       -  ``field``

327
       -  The upcoming field. See enum :c:type:`v4l2_field`.
328 329 330



331
.. tabularcolumns:: |p{3.5cm}|p{3.0cm}|p{1.8cm}|p{8.5cm}|
332

333
.. c:type:: v4l2_event_ctrl
334

335 336 337 338 339 340 341 342 343 344 345 346
.. flat-table:: struct v4l2_event_ctrl
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2 1


    -  .. row 1

       -  __u32

       -  ``changes``

347
       -
348
       -  A bitmask that tells what has changed. See
349
	  :ref:`ctrl-changes-flags`.
350 351 352 353 354 355 356

    -  .. row 2

       -  __u32

       -  ``type``

357
       -
358
       -  The type of the control. See enum
359
	  :c:type:`v4l2_ctrl_type`.
360 361 362 363 364

    -  .. row 3

       -  union (anonymous)

365 366 367
       -
       -
       -
368 369 370

    -  .. row 4

371
       -
372 373 374 375 376
       -  __s32

       -  ``value``

       -  The 32-bit value of the control for 32-bit control types. This is
377 378
	  0 for string controls since the value of a string cannot be passed
	  using :ref:`VIDIOC_DQEVENT`.
379 380 381

    -  .. row 5

382
       -
383 384 385 386 387 388 389 390 391 392 393 394
       -  __s64

       -  ``value64``

       -  The 64-bit value of the control for 64-bit control types.

    -  .. row 6

       -  __u32

       -  ``flags``

395
       -
396 397 398 399 400 401 402 403
       -  The control flags. See :ref:`control-flags`.

    -  .. row 7

       -  __s32

       -  ``minimum``

404
       -
405
       -  The minimum value of the control. See struct
406
	  :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
407 408 409 410 411 412 413

    -  .. row 8

       -  __s32

       -  ``maximum``

414
       -
415
       -  The maximum value of the control. See struct
416
	  :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
417 418 419 420 421 422 423

    -  .. row 9

       -  __s32

       -  ``step``

424
       -
425
       -  The step value of the control. See struct
426
	  :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
427 428 429 430 431 432 433

    -  .. row 10

       -  __s32

       -  ``default_value``

434
       -
435
       -  The default value value of the control. See struct
436
	  :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
437 438 439



440 441
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|

442
.. c:type:: v4l2_event_frame_sync
443

444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
.. flat-table:: struct v4l2_event_frame_sync
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u32

       -  ``frame_sequence``

       -  The sequence number of the frame being received.



460 461
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|

462
.. c:type:: v4l2_event_src_change
463

464 465 466 467 468 469 470 471 472 473 474 475 476
.. flat-table:: struct v4l2_event_src_change
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u32

       -  ``changes``

       -  A bitmask that tells what has changed. See
477
	  :ref:`src-changes-flags`.
478 479 480



481 482
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|

483
.. c:type:: v4l2_event_motion_det
484

485 486 487 488 489 490 491 492 493 494 495 496 497
.. flat-table:: struct v4l2_event_motion_det
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u32

       -  ``flags``

       -  Currently only one flag is available: if
498 499 500
	  ``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` is set, then the
	  ``frame_sequence`` field is valid, otherwise that field should be
	  ignored.
501 502 503 504 505 506 507 508

    -  .. row 2

       -  __u32

       -  ``frame_sequence``

       -  The sequence number of the frame being received. Only valid if the
509
	  ``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` flag was set.
510 511 512 513 514 515 516 517

    -  .. row 3

       -  __u32

       -  ``region_mask``

       -  The bitmask of the regions that reported motion. There is at least
518 519 520 521 522
	  one region. If this field is 0, then no motion was detected at
	  all. If there is no ``V4L2_CID_DETECT_MD_REGION_GRID`` control
	  (see :ref:`detect-controls`) to assign a different region to
	  each cell in the motion detection grid, then that all cells are
	  automatically assigned to the default region 0.
523 524 525



526 527
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|

528 529
.. _ctrl-changes-flags:

530 531 532 533 534 535 536 537 538 539 540 541 542
.. flat-table:: Control Changes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_EVENT_CTRL_CH_VALUE``

       -  0x0001

       -  This control event was triggered because the value of the control
543 544 545
	  changed. Special cases: Volatile controls do no generate this
	  event; If a control has the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
	  flag set, then this event is sent as well, regardless its value.
546 547 548 549 550 551 552 553

    -  .. row 2

       -  ``V4L2_EVENT_CTRL_CH_FLAGS``

       -  0x0002

       -  This control event was triggered because the control flags
554
	  changed.
555 556 557 558 559 560 561 562

    -  .. row 3

       -  ``V4L2_EVENT_CTRL_CH_RANGE``

       -  0x0004

       -  This control event was triggered because the minimum, maximum,
563
	  step or the default value of the control changed.
564 565 566



567 568
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|

569 570
.. _src-changes-flags:

571 572 573 574 575 576 577 578 579 580 581 582 583
.. flat-table:: Source Changes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_EVENT_SRC_CH_RESOLUTION``

       -  0x0001

       -  This event gets triggered when a resolution change is detected at
584 585
	  an input. This can come from an input connector or from a video
	  decoder.
586 587


588
Return Value
589 590 591 592 593
============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.