v4l2-event.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. struct v4l2_fh;
  25. struct v4l2_subdev;
  26. struct v4l2_subscribed_event;
  27. struct video_device;
  28. /**
  29. * struct v4l2_kevent - Internal kernel event struct.
  30. * @list: List node for the v4l2_fh->available list.
  31. * @sev: Pointer to parent v4l2_subscribed_event.
  32. * @event: The event itself.
  33. */
  34. struct v4l2_kevent {
  35. struct list_head list;
  36. struct v4l2_subscribed_event *sev;
  37. struct v4l2_event event;
  38. };
  39. /**
  40. * struct v4l2_subscribed_event_ops - Subscribed event operations.
  41. *
  42. * @add: Optional callback, called when a new listener is added
  43. * @del: Optional callback, called when a listener stops listening
  44. * @replace: Optional callback that can replace event 'old' with event 'new'.
  45. * @merge: Optional callback that can merge event 'old' into event 'new'.
  46. */
  47. struct v4l2_subscribed_event_ops {
  48. int (*add)(struct v4l2_subscribed_event *sev, unsigned int elems);
  49. void (*del)(struct v4l2_subscribed_event *sev);
  50. void (*replace)(struct v4l2_event *old, const struct v4l2_event *new);
  51. void (*merge)(const struct v4l2_event *old, struct v4l2_event *new);
  52. };
  53. /**
  54. * struct v4l2_subscribed_event - Internal struct representing a subscribed
  55. * event.
  56. *
  57. * @list: List node for the v4l2_fh->subscribed list.
  58. * @type: Event type.
  59. * @id: Associated object ID (e.g. control ID). 0 if there isn't any.
  60. * @flags: Copy of v4l2_event_subscription->flags.
  61. * @fh: Filehandle that subscribed to this event.
  62. * @node: List node that hooks into the object's event list
  63. * (if there is one).
  64. * @ops: v4l2_subscribed_event_ops
  65. * @elems: The number of elements in the events array.
  66. * @first: The index of the events containing the oldest available event.
  67. * @in_use: The number of queued events.
  68. * @events: An array of @elems events.
  69. */
  70. struct v4l2_subscribed_event {
  71. struct list_head list;
  72. u32 type;
  73. u32 id;
  74. u32 flags;
  75. struct v4l2_fh *fh;
  76. struct list_head node;
  77. const struct v4l2_subscribed_event_ops *ops;
  78. unsigned int elems;
  79. unsigned int first;
  80. unsigned int in_use;
  81. struct v4l2_kevent events[];
  82. };
  83. /**
  84. * v4l2_event_dequeue - Dequeue events from video device.
  85. *
  86. * @fh: pointer to struct v4l2_fh
  87. * @event: pointer to struct v4l2_event
  88. * @nonblocking: if not zero, waits for an event to arrive
  89. */
  90. int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
  91. int nonblocking);
  92. /**
  93. * v4l2_event_queue - Queue events to video device.
  94. *
  95. * @vdev: pointer to &struct video_device
  96. * @ev: pointer to &struct v4l2_event
  97. *
  98. * The event will be queued for all &struct v4l2_fh file handlers.
  99. *
  100. * .. note::
  101. * The driver's only responsibility is to fill in the type and the data
  102. * fields.The other fields will be filled in by V4L2.
  103. */
  104. void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
  105. /**
  106. * v4l2_event_queue_fh - Queue events to video device.
  107. *
  108. * @fh: pointer to &struct v4l2_fh
  109. * @ev: pointer to &struct v4l2_event
  110. *
  111. *
  112. * The event will be queued only for the specified &struct v4l2_fh file handler.
  113. *
  114. * .. note::
  115. * The driver's only responsibility is to fill in the type and the data
  116. * fields.The other fields will be filled in by V4L2.
  117. */
  118. void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);
  119. /**
  120. * v4l2_event_pending - Check if an event is available
  121. *
  122. * @fh: pointer to &struct v4l2_fh
  123. *
  124. * Returns the number of pending events.
  125. */
  126. int v4l2_event_pending(struct v4l2_fh *fh);
  127. /**
  128. * v4l2_event_subscribe - Subscribes to an event
  129. *
  130. * @fh: pointer to &struct v4l2_fh
  131. * @sub: pointer to &struct v4l2_event_subscription
  132. * @elems: size of the events queue
  133. * @ops: pointer to &v4l2_subscribed_event_ops
  134. *
  135. * .. note::
  136. *
  137. * if @elems is zero, the framework will fill in a default value,
  138. * with is currently 1 element.
  139. */
  140. int v4l2_event_subscribe(struct v4l2_fh *fh,
  141. const struct v4l2_event_subscription *sub,
  142. unsigned int elems,
  143. const struct v4l2_subscribed_event_ops *ops);
  144. /**
  145. * v4l2_event_unsubscribe - Unsubscribes to an event
  146. *
  147. * @fh: pointer to &struct v4l2_fh
  148. * @sub: pointer to &struct v4l2_event_subscription
  149. */
  150. int v4l2_event_unsubscribe(struct v4l2_fh *fh,
  151. const struct v4l2_event_subscription *sub);
  152. /**
  153. * v4l2_event_unsubscribe_all - Unsubscribes to all events
  154. *
  155. * @fh: pointer to &struct v4l2_fh
  156. */
  157. void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);
  158. /**
  159. * v4l2_event_subdev_unsubscribe - Subdev variant of v4l2_event_unsubscribe()
  160. *
  161. * @sd: pointer to &struct v4l2_subdev
  162. * @fh: pointer to &struct v4l2_fh
  163. * @sub: pointer to &struct v4l2_event_subscription
  164. *
  165. * .. note::
  166. *
  167. * This function should be used for the &struct v4l2_subdev_core_ops
  168. * %unsubscribe_event field.
  169. */
  170. int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd,
  171. struct v4l2_fh *fh,
  172. struct v4l2_event_subscription *sub);
  173. /**
  174. * v4l2_src_change_event_subscribe - helper function that calls
  175. * v4l2_event_subscribe() if the event is %V4L2_EVENT_SOURCE_CHANGE.
  176. *
  177. * @fh: pointer to struct v4l2_fh
  178. * @sub: pointer to &struct v4l2_event_subscription
  179. */
  180. int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
  181. const struct v4l2_event_subscription *sub);
  182. /**
  183. * v4l2_src_change_event_subdev_subscribe - Variant of v4l2_event_subscribe(),
  184. * meant to subscribe only events of the type %V4L2_EVENT_SOURCE_CHANGE.
  185. *
  186. * @sd: pointer to &struct v4l2_subdev
  187. * @fh: pointer to &struct v4l2_fh
  188. * @sub: pointer to &struct v4l2_event_subscription
  189. */
  190. int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
  191. struct v4l2_fh *fh,
  192. struct v4l2_event_subscription *sub);
  193. #endif /* V4L2_EVENT_H */