v4l2-event.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * v4l2-event.h
  3. *
  4. * V4L2 events.
  5. *
  6. * Copyright (C) 2009--2010 Nokia Corporation.
  7. *
  8. * Contact: Sakari Ailus <sakari.ailus@iki.fi>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * version 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. */
  19. #ifndef V4L2_EVENT_H
  20. #define V4L2_EVENT_H
  21. #include <linux/types.h>
  22. #include <linux/videodev2.h>
  23. #include <linux/wait.h>
  24. /*
  25. * Overview:
  26. *
  27. * Events are subscribed per-filehandle. An event specification consists of a
  28. * type and is optionally associated with an object identified through the
  29. * 'id' field. So an event is uniquely identified by the (type, id) tuple.
  30. *
  31. * The v4l2-fh struct has a list of subscribed events. The v4l2_subscribed_event
  32. * struct is added to that list, one for every subscribed event.
  33. *
  34. * Each v4l2_subscribed_event struct ends with an array of v4l2_kevent structs.
  35. * This array (ringbuffer, really) is used to store any events raised by the
  36. * driver. The v4l2_kevent struct links into the 'available' list of the
  37. * v4l2_fh struct so VIDIOC_DQEVENT will know which event to dequeue first.
  38. *
  39. * Finally, if the event subscription is associated with a particular object
  40. * such as a V4L2 control, then that object needs to know about that as well
  41. * so that an event can be raised by that object. So the 'node' field can
  42. * be used to link the v4l2_subscribed_event struct into a list of that
  43. * object.
  44. *
  45. * So to summarize:
  46. *
  47. * struct v4l2_fh has two lists: one of the subscribed events, and one of the
  48. * pending events.
  49. *
  50. * struct v4l2_subscribed_event has a ringbuffer of raised (pending) events of
  51. * that particular type.
  52. *
  53. * If struct v4l2_subscribed_event is associated with a specific object, then
  54. * that object will have an internal list of struct v4l2_subscribed_event so
  55. * it knows who subscribed an event to that object.
  56. */
  57. struct v4l2_fh;
  58. struct v4l2_subdev;
  59. struct v4l2_subscribed_event;
  60. struct video_device;
  61. /**
  62. * struct v4l2_kevent - Internal kernel event struct.
  63. * @list: List node for the v4l2_fh->available list.
  64. * @sev: Pointer to parent v4l2_subscribed_event.
  65. * @event: The event itself.
  66. */
  67. struct v4l2_kevent {
  68. struct list_head list;
  69. struct v4l2_subscribed_event *sev;
  70. struct v4l2_event event;
  71. };
  72. /**
  73. * struct v4l2_subscribed_event_ops - Subscribed event operations.
  74. *
  75. * @add: Optional callback, called when a new listener is added
  76. * @del: Optional callback, called when a listener stops listening
  77. * @replace: Optional callback that can replace event 'old' with event 'new'.
  78. * @merge: Optional callback that can merge event 'old' into event 'new'.
  79. */
  80. struct v4l2_subscribed_event_ops {
  81. int (*add)(struct v4l2_subscribed_event *sev, unsigned int elems);
  82. void (*del)(struct v4l2_subscribed_event *sev);
  83. void (*replace)(struct v4l2_event *old, const struct v4l2_event *new);
  84. void (*merge)(const struct v4l2_event *old, struct v4l2_event *new);
  85. };
  86. /**
  87. * struct v4l2_subscribed_event - Internal struct representing a subscribed
  88. * event.
  89. *
  90. * @list: List node for the v4l2_fh->subscribed list.
  91. * @type: Event type.
  92. * @id: Associated object ID (e.g. control ID). 0 if there isn't any.
  93. * @flags: Copy of v4l2_event_subscription->flags.
  94. * @fh: Filehandle that subscribed to this event.
  95. * @node: List node that hooks into the object's event list
  96. * (if there is one).
  97. * @ops: v4l2_subscribed_event_ops
  98. * @elems: The number of elements in the events array.
  99. * @first: The index of the events containing the oldest available event.
  100. * @in_use: The number of queued events.
  101. * @events: An array of @elems events.
  102. */
  103. struct v4l2_subscribed_event {
  104. struct list_head list;
  105. u32 type;
  106. u32 id;
  107. u32 flags;
  108. struct v4l2_fh *fh;
  109. struct list_head node;
  110. const struct v4l2_subscribed_event_ops *ops;
  111. unsigned int elems;
  112. unsigned int first;
  113. unsigned int in_use;
  114. struct v4l2_kevent events[];
  115. };
  116. /**
  117. * v4l2_event_dequeue - Dequeue events from video device.
  118. *
  119. * @fh: pointer to struct v4l2_fh
  120. * @event: pointer to struct v4l2_event
  121. * @nonblocking: if not zero, waits for an event to arrive
  122. */
  123. int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
  124. int nonblocking);
  125. /**
  126. * v4l2_event_queue - Queue events to video device.
  127. *
  128. * @vdev: pointer to &struct video_device
  129. * @ev: pointer to &struct v4l2_event
  130. *
  131. * The event will be queued for all &struct v4l2_fh file handlers.
  132. *
  133. * .. note::
  134. * The driver's only responsibility is to fill in the type and the data
  135. * fields.The other fields will be filled in by V4L2.
  136. */
  137. void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
  138. /**
  139. * v4l2_event_queue_fh - Queue events to video device.
  140. *
  141. * @fh: pointer to &struct v4l2_fh
  142. * @ev: pointer to &struct v4l2_event
  143. *
  144. *
  145. * The event will be queued only for the specified &struct v4l2_fh file handler.
  146. *
  147. * .. note::
  148. * The driver's only responsibility is to fill in the type and the data
  149. * fields.The other fields will be filled in by V4L2.
  150. */
  151. void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);
  152. /**
  153. * v4l2_event_pending - Check if an event is available
  154. *
  155. * @fh: pointer to &struct v4l2_fh
  156. *
  157. * Returns the number of pending events.
  158. */
  159. int v4l2_event_pending(struct v4l2_fh *fh);
  160. /**
  161. * v4l2_event_subscribe - Subscribes to an event
  162. *
  163. * @fh: pointer to &struct v4l2_fh
  164. * @sub: pointer to &struct v4l2_event_subscription
  165. * @elems: size of the events queue
  166. * @ops: pointer to &v4l2_subscribed_event_ops
  167. *
  168. * .. note::
  169. *
  170. * if @elems is zero, the framework will fill in a default value,
  171. * with is currently 1 element.
  172. */
  173. int v4l2_event_subscribe(struct v4l2_fh *fh,
  174. const struct v4l2_event_subscription *sub,
  175. unsigned int elems,
  176. const struct v4l2_subscribed_event_ops *ops);
  177. /**
  178. * v4l2_event_unsubscribe - Unsubscribes to an event
  179. *
  180. * @fh: pointer to &struct v4l2_fh
  181. * @sub: pointer to &struct v4l2_event_subscription
  182. */
  183. int v4l2_event_unsubscribe(struct v4l2_fh *fh,
  184. const struct v4l2_event_subscription *sub);
  185. /**
  186. * v4l2_event_unsubscribe_all - Unsubscribes to all events
  187. *
  188. * @fh: pointer to &struct v4l2_fh
  189. */
  190. void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);
  191. /**
  192. * v4l2_event_subdev_unsubscribe - Subdev variant of v4l2_event_unsubscribe()
  193. *
  194. * @sd: pointer to &struct v4l2_subdev
  195. * @fh: pointer to &struct v4l2_fh
  196. * @sub: pointer to &struct v4l2_event_subscription
  197. *
  198. * .. note::
  199. *
  200. * This function should be used for the &struct v4l2_subdev_core_ops
  201. * %unsubscribe_event field.
  202. */
  203. int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd,
  204. struct v4l2_fh *fh,
  205. struct v4l2_event_subscription *sub);
  206. /**
  207. * v4l2_src_change_event_subscribe - helper function that calls
  208. * v4l2_event_subscribe() if the event is %V4L2_EVENT_SOURCE_CHANGE.
  209. *
  210. * @fh: pointer to struct v4l2_fh
  211. * @sub: pointer to &struct v4l2_event_subscription
  212. */
  213. int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
  214. const struct v4l2_event_subscription *sub);
  215. /**
  216. * v4l2_src_change_event_subdev_subscribe - Variant of v4l2_event_subscribe(),
  217. * meant to subscribe only events of the type %V4L2_EVENT_SOURCE_CHANGE.
  218. *
  219. * @sd: pointer to &struct v4l2_subdev
  220. * @fh: pointer to &struct v4l2_fh
  221. * @sub: pointer to &struct v4l2_event_subscription
  222. */
  223. int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
  224. struct v4l2_fh *fh,
  225. struct v4l2_event_subscription *sub);
  226. #endif /* V4L2_EVENT_H */