pcm_ioplug.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * \file include/pcm_ioplug.h
  3. * \brief External I/O-Plugin SDK
  4. * \author Takashi Iwai <tiwai@suse.de>
  5. * \date 2005
  6. *
  7. * External I/O-Plugin SDK
  8. */
  9. /*
  10. * ALSA external PCM plugin SDK
  11. *
  12. * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
  13. *
  14. * This library is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU Lesser General Public License as
  16. * published by the Free Software Foundation; either version 2.1 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Lesser General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Lesser General Public
  25. * License along with this library; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. */
  29. #ifndef __ALSA_PCM_IOPLUG_H
  30. #define __ALSA_PCM_IOPLUG_H
  31. /**
  32. * \defgroup PCM_IOPlug External I/O plugin SDK
  33. * \ingroup Plugin_SDK
  34. * See the \ref pcm page for more details.
  35. * \{
  36. */
  37. /** hw constraints for ioplug */
  38. enum {
  39. SND_PCM_IOPLUG_HW_ACCESS = 0, /**< access type */
  40. SND_PCM_IOPLUG_HW_FORMAT, /**< format */
  41. SND_PCM_IOPLUG_HW_CHANNELS, /**< channels */
  42. SND_PCM_IOPLUG_HW_RATE, /**< rate */
  43. SND_PCM_IOPLUG_HW_PERIOD_BYTES, /**< period bytes */
  44. SND_PCM_IOPLUG_HW_BUFFER_BYTES, /**< buffer bytes */
  45. SND_PCM_IOPLUG_HW_PERIODS, /**< number of periods */
  46. SND_PCM_IOPLUG_HW_PARAMS /**< max number of hw constraints */
  47. };
  48. /** I/O plugin handle */
  49. typedef struct snd_pcm_ioplug snd_pcm_ioplug_t;
  50. /** Callback table of ioplug */
  51. typedef struct snd_pcm_ioplug_callback snd_pcm_ioplug_callback_t;
  52. #ifdef DOC_HIDDEN
  53. /* redefine typedefs for stupid doxygen */
  54. typedef snd_pcm_ioplug snd_pcm_ioplug_t;
  55. typedef snd_pcm_ioplug_callback snd_pcm_ioplug_callback_t;
  56. #endif
  57. /*
  58. * bit flags for additional conditions
  59. */
  60. #define SND_PCM_IOPLUG_FLAG_LISTED (1<<0) /**< list up this PCM */
  61. #define SND_PCM_IOPLUG_FLAG_MONOTONIC (1<<1) /**< monotonic timestamps */
  62. /*
  63. * Protocol version
  64. */
  65. #define SND_PCM_IOPLUG_VERSION_MAJOR 1 /**< Protocol major version */
  66. #define SND_PCM_IOPLUG_VERSION_MINOR 0 /**< Protocol minor version */
  67. #define SND_PCM_IOPLUG_VERSION_TINY 2 /**< Protocol tiny version */
  68. /**
  69. * IO-plugin protocol version
  70. */
  71. #define SND_PCM_IOPLUG_VERSION ((SND_PCM_IOPLUG_VERSION_MAJOR<<16) |\
  72. (SND_PCM_IOPLUG_VERSION_MINOR<<8) |\
  73. (SND_PCM_IOPLUG_VERSION_TINY))
  74. /** Handle of ioplug */
  75. struct snd_pcm_ioplug {
  76. /**
  77. * protocol version; #SND_PCM_IOPLUG_VERSION must be filled here
  78. * before calling #snd_pcm_ioplug_create()
  79. */
  80. unsigned int version;
  81. /**
  82. * name of this plugin; must be filled before calling #snd_pcm_ioplug_create()
  83. */
  84. const char *name;
  85. unsigned int flags; /**< SND_PCM_IOPLUG_FLAG_XXX */
  86. int poll_fd; /**< poll file descriptor */
  87. unsigned int poll_events; /**< poll events */
  88. unsigned int mmap_rw; /**< pseudo mmap mode */
  89. /**
  90. * callbacks of this plugin; must be filled before calling #snd_pcm_ioplug_create()
  91. */
  92. const snd_pcm_ioplug_callback_t *callback;
  93. /**
  94. * private data, which can be used freely in the driver callbacks
  95. */
  96. void *private_data;
  97. /**
  98. * PCM handle filled by #snd_pcm_extplug_create()
  99. */
  100. snd_pcm_t *pcm;
  101. snd_pcm_stream_t stream; /**< stream direcion; read-only */
  102. snd_pcm_state_t state; /**< current PCM state; read-only */
  103. volatile snd_pcm_uframes_t appl_ptr; /**< application pointer; read-only */
  104. volatile snd_pcm_uframes_t hw_ptr; /**< hw pointer; read-only */
  105. int nonblock; /**< non-block mode; read-only */
  106. snd_pcm_access_t access; /**< access type; filled after hw_params is called */
  107. snd_pcm_format_t format; /**< PCM format; filled after hw_params is called */
  108. unsigned int channels; /**< number of channels; filled after hw_params is called */
  109. unsigned int rate; /**< rate; filled after hw_params is called */
  110. snd_pcm_uframes_t period_size; /**< period size; filled after hw_params is called */
  111. snd_pcm_uframes_t buffer_size; /**< buffer size; filled after hw_params is called */
  112. };
  113. /** Callback table of ioplug */
  114. struct snd_pcm_ioplug_callback {
  115. /**
  116. * start the PCM; required, called inside mutex lock
  117. */
  118. int (*start)(snd_pcm_ioplug_t *io);
  119. /**
  120. * stop the PCM; required, called inside mutex lock
  121. */
  122. int (*stop)(snd_pcm_ioplug_t *io);
  123. /**
  124. * get the current DMA position; required, called inside mutex lock
  125. */
  126. snd_pcm_sframes_t (*pointer)(snd_pcm_ioplug_t *io);
  127. /**
  128. * transfer the data; optional, called inside mutex lock
  129. */
  130. snd_pcm_sframes_t (*transfer)(snd_pcm_ioplug_t *io,
  131. const snd_pcm_channel_area_t *areas,
  132. snd_pcm_uframes_t offset,
  133. snd_pcm_uframes_t size);
  134. /**
  135. * close the PCM; optional
  136. */
  137. int (*close)(snd_pcm_ioplug_t *io);
  138. /**
  139. * hw_params; optional
  140. */
  141. int (*hw_params)(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params);
  142. /**
  143. * hw_free; optional
  144. */
  145. int (*hw_free)(snd_pcm_ioplug_t *io);
  146. /**
  147. * sw_params; optional
  148. */
  149. int (*sw_params)(snd_pcm_ioplug_t *io, snd_pcm_sw_params_t *params);
  150. /**
  151. * prepare; optional
  152. */
  153. int (*prepare)(snd_pcm_ioplug_t *io);
  154. /**
  155. * drain; optional
  156. */
  157. int (*drain)(snd_pcm_ioplug_t *io);
  158. /**
  159. * toggle pause; optional, called inside mutex lock
  160. */
  161. int (*pause)(snd_pcm_ioplug_t *io, int enable);
  162. /**
  163. * resume; optional
  164. */
  165. int (*resume)(snd_pcm_ioplug_t *io);
  166. /**
  167. * poll descriptors count; optional
  168. */
  169. int (*poll_descriptors_count)(snd_pcm_ioplug_t *io);
  170. /**
  171. * poll descriptors; optional
  172. */
  173. int (*poll_descriptors)(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int space);
  174. /**
  175. * mangle poll events; optional
  176. */
  177. int (*poll_revents)(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int nfds, unsigned short *revents);
  178. /**
  179. * dump; optional
  180. */
  181. void (*dump)(snd_pcm_ioplug_t *io, snd_output_t *out);
  182. /**
  183. * get the delay for the running PCM; optional; since v1.0.1
  184. */
  185. int (*delay)(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp);
  186. /**
  187. * query the channel maps; optional; since v1.0.2
  188. */
  189. snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_ioplug_t *io);
  190. /**
  191. * get the channel map; optional; since v1.0.2
  192. */
  193. snd_pcm_chmap_t *(*get_chmap)(snd_pcm_ioplug_t *io);
  194. /**
  195. * set the channel map; optional; since v1.0.2
  196. */
  197. int (*set_chmap)(snd_pcm_ioplug_t *io, const snd_pcm_chmap_t *map);
  198. };
  199. int snd_pcm_ioplug_create(snd_pcm_ioplug_t *io, const char *name,
  200. snd_pcm_stream_t stream, int mode);
  201. int snd_pcm_ioplug_delete(snd_pcm_ioplug_t *io);
  202. /* update poll_fd and mmap_rw */
  203. int snd_pcm_ioplug_reinit_status(snd_pcm_ioplug_t *ioplug);
  204. /* get a mmap area (for mmap_rw only) */
  205. const snd_pcm_channel_area_t *snd_pcm_ioplug_mmap_areas(snd_pcm_ioplug_t *ioplug);
  206. /* clear hw_parameter setting */
  207. void snd_pcm_ioplug_params_reset(snd_pcm_ioplug_t *io);
  208. /* hw_parameter setting */
  209. int snd_pcm_ioplug_set_param_minmax(snd_pcm_ioplug_t *io, int type, unsigned int min, unsigned int max);
  210. int snd_pcm_ioplug_set_param_list(snd_pcm_ioplug_t *io, int type, unsigned int num_list, const unsigned int *list);
  211. /* change PCM status */
  212. int snd_pcm_ioplug_set_state(snd_pcm_ioplug_t *ioplug, snd_pcm_state_t state);
  213. /** \} */
  214. #endif /* __ALSA_PCM_IOPLUG_H */