control_external.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /**
  2. * \file include/control_external.h
  3. * \brief External control plugin SDK
  4. * \author Takashi Iwai <tiwai@suse.de>
  5. * \date 2005
  6. *
  7. * External control plugin SDK.
  8. */
  9. /*
  10. * This library is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as
  12. * published by the Free Software Foundation; either version 2.1 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #ifndef __ALSA_CONTROL_EXTERNAL_H
  26. #define __ALSA_CONTROL_EXTERNAL_H
  27. #include "control.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * \defgroup CtlPlugin_SDK External Control Plugin SDK
  33. * \{
  34. */
  35. /**
  36. * Define the object entry for external control plugins
  37. */
  38. #define SND_CTL_PLUGIN_ENTRY(name) _snd_ctl_##name##_open
  39. /**
  40. * Define the symbols of the given control plugin with versions
  41. */
  42. #define SND_CTL_PLUGIN_SYMBOL(name) SND_DLSYM_BUILD_VERSION(SND_CTL_PLUGIN_ENTRY(name), SND_CONTROL_DLSYM_VERSION);
  43. /**
  44. * Define the control plugin
  45. */
  46. #define SND_CTL_PLUGIN_DEFINE_FUNC(plugin) \
  47. int SND_CTL_PLUGIN_ENTRY(plugin) (snd_ctl_t **handlep, const char *name,\
  48. snd_config_t *root, snd_config_t *conf, int mode)
  49. /** External control plugin handle */
  50. typedef struct snd_ctl_ext snd_ctl_ext_t;
  51. /** Callback table of control ext */
  52. typedef struct snd_ctl_ext_callback snd_ctl_ext_callback_t;
  53. /** Key to access a control pointer */
  54. typedef unsigned long snd_ctl_ext_key_t;
  55. #ifdef DOC_HIDDEN
  56. /* redefine typedef's for stupid doxygen */
  57. typedef snd_ctl_ext snd_ctl_ext_t;
  58. typedef snd_ctl_ext_callback snd_ctl_ext_callback_t;
  59. #endif
  60. /** Callback to handle TLV commands. */
  61. typedef int (snd_ctl_ext_tlv_rw_t)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int op_flag, unsigned int numid,
  62. unsigned int *tlv, unsigned int tlv_size);
  63. /*
  64. * Protocol version
  65. */
  66. #define SND_CTL_EXT_VERSION_MAJOR 1 /**< Protocol major version */
  67. #define SND_CTL_EXT_VERSION_MINOR 0 /**< Protocol minor version */
  68. #define SND_CTL_EXT_VERSION_TINY 1 /**< Protocol tiny version */
  69. /**
  70. * external plugin protocol version
  71. */
  72. #define SND_CTL_EXT_VERSION ((SND_CTL_EXT_VERSION_MAJOR<<16) |\
  73. (SND_CTL_EXT_VERSION_MINOR<<8) |\
  74. (SND_CTL_EXT_VERSION_TINY))
  75. /** Handle of control ext */
  76. struct snd_ctl_ext {
  77. /**
  78. * protocol version; #SND_CTL_EXT_VERSION must be filled here
  79. * before calling #snd_ctl_ext_create()
  80. */
  81. unsigned int version;
  82. /**
  83. * Index of this card; must be filled before calling #snd_ctl_ext_create()
  84. */
  85. int card_idx;
  86. /**
  87. * ID string of this card; must be filled before calling #snd_ctl_ext_create()
  88. */
  89. char id[16];
  90. /**
  91. * Driver name of this card; must be filled before calling #snd_ctl_ext_create()
  92. */
  93. char driver[16];
  94. /**
  95. * short name of this card; must be filled before calling #snd_ctl_ext_create()
  96. */
  97. char name[32];
  98. /**
  99. * Long name of this card; must be filled before calling #snd_ctl_ext_create()
  100. */
  101. char longname[80];
  102. /**
  103. * Mixer name of this card; must be filled before calling #snd_ctl_ext_create()
  104. */
  105. char mixername[80];
  106. /**
  107. * poll descriptor
  108. */
  109. int poll_fd;
  110. /**
  111. * callbacks of this plugin; must be filled before calling #snd_pcm_ioplug_create()
  112. */
  113. const snd_ctl_ext_callback_t *callback;
  114. /**
  115. * private data, which can be used freely in the driver callbacks
  116. */
  117. void *private_data;
  118. /**
  119. * control handle filled by #snd_ctl_ext_create()
  120. */
  121. snd_ctl_t *handle;
  122. int nonblock; /**< non-block mode; read-only */
  123. int subscribed; /**< events subscribed; read-only */
  124. /**
  125. * optional TLV data for the control (since protocol 1.0.1)
  126. */
  127. union {
  128. snd_ctl_ext_tlv_rw_t *c;
  129. const unsigned int *p;
  130. } tlv;
  131. };
  132. /** Callback table of ext. */
  133. struct snd_ctl_ext_callback {
  134. /**
  135. * close the control handle; optional
  136. */
  137. void (*close)(snd_ctl_ext_t *ext);
  138. /**
  139. * return the total number of elements; required
  140. */
  141. int (*elem_count)(snd_ctl_ext_t *ext);
  142. /**
  143. * return the element id of the given offset (array index); required
  144. */
  145. int (*elem_list)(snd_ctl_ext_t *ext, unsigned int offset, snd_ctl_elem_id_t *id);
  146. /**
  147. * convert the element id to a search key; required
  148. */
  149. snd_ctl_ext_key_t (*find_elem)(snd_ctl_ext_t *ext, const snd_ctl_elem_id_t *id);
  150. /**
  151. * the destructor of the key; optional
  152. */
  153. void (*free_key)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key);
  154. /**
  155. * get the attribute of the element; required
  156. */
  157. int (*get_attribute)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
  158. int *type, unsigned int *acc, unsigned int *count);
  159. /**
  160. * get the element information of integer type
  161. */
  162. int (*get_integer_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
  163. long *imin, long *imax, long *istep);
  164. /**
  165. * get the element information of integer64 type
  166. */
  167. int (*get_integer64_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
  168. int64_t *imin, int64_t *imax, int64_t *istep);
  169. /**
  170. * get the element information of enumerated type
  171. */
  172. int (*get_enumerated_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
  173. /**
  174. * get the name of the enumerated item
  175. */
  176. int (*get_enumerated_name)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int item,
  177. char *name, size_t name_max_len);
  178. /**
  179. * read the current values of integer type
  180. */
  181. int (*read_integer)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value);
  182. /**
  183. * read the current values of integer64 type
  184. */
  185. int (*read_integer64)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int64_t *value);
  186. /**
  187. * read the current values of enumerated type
  188. */
  189. int (*read_enumerated)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
  190. /**
  191. * read the current values of bytes type
  192. */
  193. int (*read_bytes)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char *data,
  194. size_t max_bytes);
  195. /**
  196. * read the current values of iec958 type
  197. */
  198. int (*read_iec958)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, snd_aes_iec958_t *iec958);
  199. /**
  200. * update the current values of integer type with the given values
  201. */
  202. int (*write_integer)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value);
  203. /**
  204. * update the current values of integer64 type with the given values
  205. */
  206. int (*write_integer64)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int64_t *value);
  207. /**
  208. * update the current values of enumerated type with the given values
  209. */
  210. int (*write_enumerated)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
  211. /**
  212. * update the current values of bytes type with the given values
  213. */
  214. int (*write_bytes)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char *data,
  215. size_t max_bytes);
  216. /**
  217. * update the current values of iec958 type with the given values
  218. */
  219. int (*write_iec958)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, snd_aes_iec958_t *iec958);
  220. /**
  221. * subscribe/unsubscribe the event notification; optional
  222. */
  223. void (*subscribe_events)(snd_ctl_ext_t *ext, int subscribe);
  224. /**
  225. * read a pending notification event; optional
  226. */
  227. int (*read_event)(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, unsigned int *event_mask);
  228. /**
  229. * return the number of poll descriptors; optional
  230. */
  231. int (*poll_descriptors_count)(snd_ctl_ext_t *ext);
  232. /**
  233. * fill the poll descriptors; optional
  234. */
  235. int (*poll_descriptors)(snd_ctl_ext_t *ext, struct pollfd *pfds, unsigned int space);
  236. /**
  237. * mangle the revents of poll descriptors
  238. */
  239. int (*poll_revents)(snd_ctl_ext_t *ext, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
  240. };
  241. /**
  242. * The access type bits stored in get_attribute callback
  243. */
  244. typedef enum snd_ctl_ext_access {
  245. SND_CTL_EXT_ACCESS_READ = (1<<0),
  246. SND_CTL_EXT_ACCESS_WRITE = (1<<1),
  247. SND_CTL_EXT_ACCESS_READWRITE = (3<<0),
  248. SND_CTL_EXT_ACCESS_VOLATILE = (1<<2),
  249. SND_CTL_EXT_ACCESS_TLV_READ = (1<<4),
  250. SND_CTL_EXT_ACCESS_TLV_WRITE = (1<<5),
  251. SND_CTL_EXT_ACCESS_TLV_READWRITE = (3<<4),
  252. SND_CTL_EXT_ACCESS_TLV_COMMAND = (1<<6),
  253. SND_CTL_EXT_ACCESS_INACTIVE = (1<<8),
  254. SND_CTL_EXT_ACCESS_TLV_CALLBACK = (1<<28),
  255. } snd_ctl_ext_access_t;
  256. /**
  257. * find_elem callback returns this if no matching control element is found
  258. */
  259. #define SND_CTL_EXT_KEY_NOT_FOUND (snd_ctl_ext_key_t)(-1)
  260. int snd_ctl_ext_create(snd_ctl_ext_t *ext, const char *name, int mode);
  261. int snd_ctl_ext_delete(snd_ctl_ext_t *ext);
  262. /** \} */
  263. #ifdef __cplusplus
  264. }
  265. #endif
  266. #endif /* __ALSA_CONTROL_EXTERNAL_H */