2016-07-22 17:54:48 +08:00
|
|
|
|
|
|
|
V4L2 events
|
|
|
|
-----------
|
|
|
|
|
|
|
|
The V4L2 events provide a generic way to pass events to user space.
|
2016-07-22 19:43:30 +08:00
|
|
|
The driver must use :c:type:`v4l2_fh` to be able to support V4L2 events.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
|
|
|
Events are defined by a type and an optional ID. The ID may refer to a V4L2
|
|
|
|
object such as a control ID. If unused, then the ID is 0.
|
|
|
|
|
|
|
|
When the user subscribes to an event the driver will allocate a number of
|
|
|
|
kevent structs for that event. So every (type, ID) event tuple will have
|
|
|
|
its own set of kevent structs. This guarantees that if a driver is generating
|
|
|
|
lots of events of one type in a short time, then that will not overwrite
|
|
|
|
events of another type.
|
|
|
|
|
|
|
|
But if you get more events of one type than the number of kevents that were
|
|
|
|
reserved, then the oldest event will be dropped and the new one added.
|
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
Furthermore, the internal struct :c:type:`v4l2_subscribed_event` has
|
|
|
|
``merge()`` and ``replace()`` callbacks which drivers can set. These
|
|
|
|
callbacks are called when a new event is raised and there is no more room.
|
|
|
|
The ``replace()`` callback allows you to replace the payload of the old event
|
|
|
|
with that of the new event, merging any relevant data from the old payload
|
|
|
|
into the new payload that replaces it. It is called when this event type has
|
|
|
|
only one kevent struct allocated. The ``merge()`` callback allows you to merge
|
|
|
|
the oldest event payload into that of the second-oldest event payload. It is
|
|
|
|
called when there are two or more kevent structs allocated.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
|
|
|
This way no status information is lost, just the intermediate steps leading
|
|
|
|
up to that state.
|
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
A good example of these ``replace``/``merge`` callbacks is in v4l2-event.c:
|
|
|
|
``ctrls_replace()`` and ``ctrls_merge()`` callbacks for the control event.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
.. note::
|
|
|
|
these callbacks can be called from interrupt context, so they must
|
|
|
|
be fast.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
In order to queue events to video device, drivers should call:
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
:cpp:func:`v4l2_event_queue <v4l2_event_queue>`
|
|
|
|
(:c:type:`vdev <video_device>`, :ref:`ev <v4l2-event>`)
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
The driver's only responsibility is to fill in the type and the data fields.
|
|
|
|
The other fields will be filled in by V4L2.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
Event subscription
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
Subscribing to an event is via:
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
:cpp:func:`v4l2_event_subscribe <v4l2_event_subscribe>`
|
|
|
|
(:c:type:`fh <v4l2_fh>`, :ref:`sub <v4l2-event-subscription>` ,
|
|
|
|
elems, :c:type:`ops <v4l2_subscribed_event_ops>`)
|
2016-07-22 17:54:48 +08:00
|
|
|
|
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
This function is used to implement :c:type:`video_device`->
|
|
|
|
:c:type:`ioctl_ops <v4l2_ioctl_ops>`-> ``vidioc_subscribe_event``,
|
|
|
|
but the driver must check first if the driver is able to produce events
|
|
|
|
with specified event id, and then should call
|
|
|
|
:cpp:func:`v4l2_event_subscribe` to subscribe the event.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
The elems argument is the size of the event queue for this event. If it is 0,
|
|
|
|
then the framework will fill in a default value (this depends on the event
|
|
|
|
type).
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
The ops argument allows the driver to specify a number of callbacks:
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
======== ==============================================================
|
|
|
|
Callback Description
|
|
|
|
======== ==============================================================
|
|
|
|
add called when a new listener gets added (subscribing to the same
|
|
|
|
event twice will only cause this callback to get called once)
|
|
|
|
del called when a listener stops listening
|
|
|
|
replace replace event 'old' with event 'new'.
|
|
|
|
merge merge event 'old' into event 'new'.
|
|
|
|
======== ==============================================================
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
All 4 callbacks are optional, if you don't want to specify any callbacks
|
|
|
|
the ops argument itself maybe ``NULL``.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
Unsubscribing an event
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
Unsubscribing to an event is via:
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
:cpp:func:`v4l2_event_unsubscribe <v4l2_event_unsubscribe>`
|
|
|
|
(:c:type:`fh <v4l2_fh>`, :ref:`sub <v4l2-event-subscription>`)
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
This function is used to implement :c:type:`video_device`->
|
|
|
|
:c:type:`ioctl_ops <v4l2_ioctl_ops>`-> ``vidioc_unsubscribe_event``.
|
|
|
|
A driver may call :cpp:func:`v4l2_event_unsubscribe` directly unless it
|
|
|
|
wants to be involved in unsubscription process.
|
|
|
|
|
|
|
|
The special type ``V4L2_EVENT_ALL`` may be used to unsubscribe all events. The
|
|
|
|
drivers may want to handle this in a special way.
|
|
|
|
|
|
|
|
Check if there's a pending event
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Checking if there's a pending event is via:
|
|
|
|
|
|
|
|
:cpp:func:`v4l2_event_pending <v4l2_event_pending>`
|
|
|
|
(:c:type:`fh <v4l2_fh>`)
|
|
|
|
|
|
|
|
|
|
|
|
This function returns the number of pending events. Useful when implementing
|
|
|
|
poll.
|
|
|
|
|
|
|
|
How events work
|
|
|
|
~~~~~~~~~~~~~~~
|
2016-07-22 17:54:48 +08:00
|
|
|
|
|
|
|
Events are delivered to user space through the poll system call. The driver
|
2016-07-22 19:43:30 +08:00
|
|
|
can use :c:type:`v4l2_fh`->wait (a wait_queue_head_t) as the argument for
|
|
|
|
``poll_wait()``.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
|
|
|
There are standard and private events. New standard events must use the
|
|
|
|
smallest available event type. The drivers must allocate their events from
|
|
|
|
their own class starting from class base. Class base is
|
2016-07-22 19:43:30 +08:00
|
|
|
``V4L2_EVENT_PRIVATE_START`` + n * 1000 where n is the lowest available number.
|
2016-07-22 17:54:48 +08:00
|
|
|
The first event type in the class is reserved for future use, so the first
|
|
|
|
available event type is 'class base + 1'.
|
|
|
|
|
|
|
|
An example on how the V4L2 events may be used can be found in the OMAP
|
2016-07-22 19:43:30 +08:00
|
|
|
3 ISP driver (``drivers/media/platform/omap3isp``).
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 19:43:30 +08:00
|
|
|
A subdev can directly send an event to the :c:type:`v4l2_device` notify
|
|
|
|
function with ``V4L2_DEVICE_NOTIFY_EVENT``. This allows the bridge to map
|
|
|
|
the subdev that sends the event to the video node(s) associated with the
|
|
|
|
subdev that need to be informed about such an event.
|
2016-07-22 17:54:48 +08:00
|
|
|
|
2016-07-22 21:15:42 +08:00
|
|
|
V4L2 event functions and data structures
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2016-07-21 01:14:37 +08:00
|
|
|
|
|
|
|
.. kernel-doc:: include/media/v4l2-event.h
|
2016-07-22 21:15:42 +08:00
|
|
|
|