timer.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * \file include/timer.h
  3. * \brief Application interface library for the ALSA driver
  4. * \author Jaroslav Kysela <perex@perex.cz>
  5. * \author Abramo Bagnara <abramo@alsa-project.org>
  6. * \author Takashi Iwai <tiwai@suse.de>
  7. * \date 1998-2001
  8. *
  9. * Application interface library for the ALSA driver
  10. */
  11. /*
  12. * This library is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License as
  14. * published by the Free Software Foundation; either version 2.1 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #ifndef __ALSA_TIMER_H
  28. #define __ALSA_TIMER_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /**
  33. * \defgroup Timer Timer Interface
  34. * Timer Interface. See \ref timer page for more details.
  35. * \{
  36. */
  37. /** dlsym version for interface entry callback */
  38. #define SND_TIMER_DLSYM_VERSION _dlsym_timer_001
  39. /** dlsym version for interface entry callback */
  40. #define SND_TIMER_QUERY_DLSYM_VERSION _dlsym_timer_query_001
  41. /** timer identification structure */
  42. typedef struct _snd_timer_id snd_timer_id_t;
  43. /** timer global info structure */
  44. typedef struct _snd_timer_ginfo snd_timer_ginfo_t;
  45. /** timer global params structure */
  46. typedef struct _snd_timer_gparams snd_timer_gparams_t;
  47. /** timer global status structure */
  48. typedef struct _snd_timer_gstatus snd_timer_gstatus_t;
  49. /** timer info structure */
  50. typedef struct _snd_timer_info snd_timer_info_t;
  51. /** timer params structure */
  52. typedef struct _snd_timer_params snd_timer_params_t;
  53. /** timer status structure */
  54. typedef struct _snd_timer_status snd_timer_status_t;
  55. /** timer master class */
  56. typedef enum _snd_timer_class {
  57. SND_TIMER_CLASS_NONE = -1, /**< invalid */
  58. SND_TIMER_CLASS_SLAVE = 0, /**< slave timer */
  59. SND_TIMER_CLASS_GLOBAL, /**< global timer */
  60. SND_TIMER_CLASS_CARD, /**< card timer */
  61. SND_TIMER_CLASS_PCM, /**< PCM timer */
  62. SND_TIMER_CLASS_LAST = SND_TIMER_CLASS_PCM /**< last timer */
  63. } snd_timer_class_t;
  64. /** timer slave class */
  65. typedef enum _snd_timer_slave_class {
  66. SND_TIMER_SCLASS_NONE = 0, /**< none */
  67. SND_TIMER_SCLASS_APPLICATION, /**< for internal use */
  68. SND_TIMER_SCLASS_SEQUENCER, /**< sequencer timer */
  69. SND_TIMER_SCLASS_OSS_SEQUENCER, /**< OSS sequencer timer */
  70. SND_TIMER_SCLASS_LAST = SND_TIMER_SCLASS_OSS_SEQUENCER /**< last slave timer */
  71. } snd_timer_slave_class_t;
  72. /** timer read event identification */
  73. typedef enum _snd_timer_event {
  74. SND_TIMER_EVENT_RESOLUTION = 0, /* val = resolution in ns */
  75. SND_TIMER_EVENT_TICK, /* val = ticks */
  76. SND_TIMER_EVENT_START, /* val = resolution in ns */
  77. SND_TIMER_EVENT_STOP, /* val = 0 */
  78. SND_TIMER_EVENT_CONTINUE, /* val = resolution in ns */
  79. SND_TIMER_EVENT_PAUSE, /* val = 0 */
  80. SND_TIMER_EVENT_EARLY, /* val = 0 */
  81. SND_TIMER_EVENT_SUSPEND, /* val = 0 */
  82. SND_TIMER_EVENT_RESUME, /* val = resolution in ns */
  83. /* master timer events for slave timer instances */
  84. SND_TIMER_EVENT_MSTART = SND_TIMER_EVENT_START + 10,
  85. SND_TIMER_EVENT_MSTOP = SND_TIMER_EVENT_STOP + 10,
  86. SND_TIMER_EVENT_MCONTINUE = SND_TIMER_EVENT_CONTINUE + 10,
  87. SND_TIMER_EVENT_MPAUSE = SND_TIMER_EVENT_PAUSE + 10,
  88. SND_TIMER_EVENT_MSUSPEND = SND_TIMER_EVENT_SUSPEND + 10,
  89. SND_TIMER_EVENT_MRESUME = SND_TIMER_EVENT_RESUME + 10
  90. } snd_timer_event_t;
  91. /** timer read structure */
  92. typedef struct _snd_timer_read {
  93. unsigned int resolution; /**< tick resolution in nanoseconds */
  94. unsigned int ticks; /**< count of happened ticks */
  95. } snd_timer_read_t;
  96. /** timer tstamp + event read structure */
  97. typedef struct _snd_timer_tread {
  98. snd_timer_event_t event; /**< Timer event */
  99. snd_htimestamp_t tstamp; /**< Time stamp of each event */
  100. unsigned int val; /**< Event value */
  101. } snd_timer_tread_t;
  102. /** global timer - system */
  103. #define SND_TIMER_GLOBAL_SYSTEM 0
  104. /** global timer - RTC */
  105. #define SND_TIMER_GLOBAL_RTC 1
  106. /** global timer - HPET */
  107. #define SND_TIMER_GLOBAL_HPET 2
  108. /** global timer - HRTIMER */
  109. #define SND_TIMER_GLOBAL_HRTIMER 3
  110. /** timer open mode flag - non-blocking behaviour */
  111. #define SND_TIMER_OPEN_NONBLOCK (1<<0)
  112. /** use timestamps and event notification - enhanced read */
  113. #define SND_TIMER_OPEN_TREAD (1<<1)
  114. /** timer handle type */
  115. typedef enum _snd_timer_type {
  116. /** Kernel level HwDep */
  117. SND_TIMER_TYPE_HW = 0,
  118. /** Shared memory client timer (not yet implemented) */
  119. SND_TIMER_TYPE_SHM,
  120. /** INET client timer (not yet implemented) */
  121. SND_TIMER_TYPE_INET
  122. } snd_timer_type_t;
  123. /** timer query handle */
  124. typedef struct _snd_timer_query snd_timer_query_t;
  125. /** timer handle */
  126. typedef struct _snd_timer snd_timer_t;
  127. int snd_timer_query_open(snd_timer_query_t **handle, const char *name, int mode);
  128. int snd_timer_query_open_lconf(snd_timer_query_t **handle, const char *name, int mode, snd_config_t *lconf);
  129. int snd_timer_query_close(snd_timer_query_t *handle);
  130. int snd_timer_query_next_device(snd_timer_query_t *handle, snd_timer_id_t *tid);
  131. int snd_timer_query_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info);
  132. int snd_timer_query_params(snd_timer_query_t *handle, snd_timer_gparams_t *params);
  133. int snd_timer_query_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status);
  134. int snd_timer_open(snd_timer_t **handle, const char *name, int mode);
  135. int snd_timer_open_lconf(snd_timer_t **handle, const char *name, int mode, snd_config_t *lconf);
  136. int snd_timer_close(snd_timer_t *handle);
  137. int snd_async_add_timer_handler(snd_async_handler_t **handler, snd_timer_t *timer,
  138. snd_async_callback_t callback, void *private_data);
  139. snd_timer_t *snd_async_handler_get_timer(snd_async_handler_t *handler);
  140. int snd_timer_poll_descriptors_count(snd_timer_t *handle);
  141. int snd_timer_poll_descriptors(snd_timer_t *handle, struct pollfd *pfds, unsigned int space);
  142. int snd_timer_poll_descriptors_revents(snd_timer_t *timer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
  143. int snd_timer_info(snd_timer_t *handle, snd_timer_info_t *timer);
  144. int snd_timer_params(snd_timer_t *handle, snd_timer_params_t *params);
  145. int snd_timer_status(snd_timer_t *handle, snd_timer_status_t *status);
  146. int snd_timer_start(snd_timer_t *handle);
  147. int snd_timer_stop(snd_timer_t *handle);
  148. int snd_timer_continue(snd_timer_t *handle);
  149. ssize_t snd_timer_read(snd_timer_t *handle, void *buffer, size_t size);
  150. size_t snd_timer_id_sizeof(void);
  151. /** allocate #snd_timer_id_t container on stack */
  152. #define snd_timer_id_alloca(ptr) __snd_alloca(ptr, snd_timer_id)
  153. int snd_timer_id_malloc(snd_timer_id_t **ptr);
  154. void snd_timer_id_free(snd_timer_id_t *obj);
  155. void snd_timer_id_copy(snd_timer_id_t *dst, const snd_timer_id_t *src);
  156. void snd_timer_id_set_class(snd_timer_id_t *id, int dev_class);
  157. int snd_timer_id_get_class(snd_timer_id_t *id);
  158. void snd_timer_id_set_sclass(snd_timer_id_t *id, int dev_sclass);
  159. int snd_timer_id_get_sclass(snd_timer_id_t *id);
  160. void snd_timer_id_set_card(snd_timer_id_t *id, int card);
  161. int snd_timer_id_get_card(snd_timer_id_t *id);
  162. void snd_timer_id_set_device(snd_timer_id_t *id, int device);
  163. int snd_timer_id_get_device(snd_timer_id_t *id);
  164. void snd_timer_id_set_subdevice(snd_timer_id_t *id, int subdevice);
  165. int snd_timer_id_get_subdevice(snd_timer_id_t *id);
  166. size_t snd_timer_ginfo_sizeof(void);
  167. /** allocate #snd_timer_ginfo_t container on stack */
  168. #define snd_timer_ginfo_alloca(ptr) __snd_alloca(ptr, snd_timer_ginfo)
  169. int snd_timer_ginfo_malloc(snd_timer_ginfo_t **ptr);
  170. void snd_timer_ginfo_free(snd_timer_ginfo_t *obj);
  171. void snd_timer_ginfo_copy(snd_timer_ginfo_t *dst, const snd_timer_ginfo_t *src);
  172. int snd_timer_ginfo_set_tid(snd_timer_ginfo_t *obj, snd_timer_id_t *tid);
  173. snd_timer_id_t *snd_timer_ginfo_get_tid(snd_timer_ginfo_t *obj);
  174. unsigned int snd_timer_ginfo_get_flags(snd_timer_ginfo_t *obj);
  175. int snd_timer_ginfo_get_card(snd_timer_ginfo_t *obj);
  176. char *snd_timer_ginfo_get_id(snd_timer_ginfo_t *obj);
  177. char *snd_timer_ginfo_get_name(snd_timer_ginfo_t *obj);
  178. unsigned long snd_timer_ginfo_get_resolution(snd_timer_ginfo_t *obj);
  179. unsigned long snd_timer_ginfo_get_resolution_min(snd_timer_ginfo_t *obj);
  180. unsigned long snd_timer_ginfo_get_resolution_max(snd_timer_ginfo_t *obj);
  181. unsigned int snd_timer_ginfo_get_clients(snd_timer_ginfo_t *obj);
  182. size_t snd_timer_info_sizeof(void);
  183. /** allocate #snd_timer_info_t container on stack */
  184. #define snd_timer_info_alloca(ptr) __snd_alloca(ptr, snd_timer_info)
  185. int snd_timer_info_malloc(snd_timer_info_t **ptr);
  186. void snd_timer_info_free(snd_timer_info_t *obj);
  187. void snd_timer_info_copy(snd_timer_info_t *dst, const snd_timer_info_t *src);
  188. int snd_timer_info_is_slave(snd_timer_info_t * info);
  189. int snd_timer_info_get_card(snd_timer_info_t * info);
  190. const char *snd_timer_info_get_id(snd_timer_info_t * info);
  191. const char *snd_timer_info_get_name(snd_timer_info_t * info);
  192. long snd_timer_info_get_resolution(snd_timer_info_t * info);
  193. size_t snd_timer_params_sizeof(void);
  194. /** allocate #snd_timer_params_t container on stack */
  195. #define snd_timer_params_alloca(ptr) __snd_alloca(ptr, snd_timer_params)
  196. int snd_timer_params_malloc(snd_timer_params_t **ptr);
  197. void snd_timer_params_free(snd_timer_params_t *obj);
  198. void snd_timer_params_copy(snd_timer_params_t *dst, const snd_timer_params_t *src);
  199. int snd_timer_params_set_auto_start(snd_timer_params_t * params, int auto_start);
  200. int snd_timer_params_get_auto_start(snd_timer_params_t * params);
  201. int snd_timer_params_set_exclusive(snd_timer_params_t * params, int exclusive);
  202. int snd_timer_params_get_exclusive(snd_timer_params_t * params);
  203. int snd_timer_params_set_early_event(snd_timer_params_t * params, int early_event);
  204. int snd_timer_params_get_early_event(snd_timer_params_t * params);
  205. void snd_timer_params_set_ticks(snd_timer_params_t * params, long ticks);
  206. long snd_timer_params_get_ticks(snd_timer_params_t * params);
  207. void snd_timer_params_set_queue_size(snd_timer_params_t * params, long queue_size);
  208. long snd_timer_params_get_queue_size(snd_timer_params_t * params);
  209. void snd_timer_params_set_filter(snd_timer_params_t * params, unsigned int filter);
  210. unsigned int snd_timer_params_get_filter(snd_timer_params_t * params);
  211. size_t snd_timer_status_sizeof(void);
  212. /** allocate #snd_timer_status_t container on stack */
  213. #define snd_timer_status_alloca(ptr) __snd_alloca(ptr, snd_timer_status)
  214. int snd_timer_status_malloc(snd_timer_status_t **ptr);
  215. void snd_timer_status_free(snd_timer_status_t *obj);
  216. void snd_timer_status_copy(snd_timer_status_t *dst, const snd_timer_status_t *src);
  217. snd_htimestamp_t snd_timer_status_get_timestamp(snd_timer_status_t * status);
  218. long snd_timer_status_get_resolution(snd_timer_status_t * status);
  219. long snd_timer_status_get_lost(snd_timer_status_t * status);
  220. long snd_timer_status_get_overrun(snd_timer_status_t * status);
  221. long snd_timer_status_get_queue(snd_timer_status_t * status);
  222. /* deprecated functions, for compatibility */
  223. long snd_timer_info_get_ticks(snd_timer_info_t * info);
  224. /** \} */
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif /** __ALSA_TIMER_H */