control.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #ifndef __SOUND_CONTROL_H
  2. #define __SOUND_CONTROL_H
  3. /*
  4. * Header file for control interface
  5. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/asound.h>
  24. typedef struct sndrv_aes_iec958 snd_aes_iec958_t;
  25. typedef struct sndrv_ctl_card_info snd_ctl_card_info_t;
  26. typedef enum sndrv_ctl_elem_type snd_ctl_elem_type_t;
  27. typedef enum sndrv_ctl_elem_iface snd_ctl_elem_iface_t;
  28. typedef struct sndrv_ctl_elem_id snd_ctl_elem_id_t;
  29. typedef struct sndrv_ctl_elem_list snd_ctl_elem_list_t;
  30. typedef struct sndrv_ctl_elem_info snd_ctl_elem_info_t;
  31. typedef struct sndrv_ctl_elem_value snd_ctl_elem_value_t;
  32. typedef enum sndrv_ctl_event_type snd_ctl_event_type_t;
  33. typedef struct sndrv_ctl_event snd_ctl_event_t;
  34. #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
  35. typedef int (snd_kcontrol_info_t) (snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo);
  36. typedef int (snd_kcontrol_get_t) (snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
  37. typedef int (snd_kcontrol_put_t) (snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
  38. typedef struct _snd_kcontrol_new {
  39. snd_ctl_elem_iface_t iface; /* interface identifier */
  40. unsigned int device; /* device/client number */
  41. unsigned int subdevice; /* subdevice (substream) number */
  42. unsigned char *name; /* ASCII name of item */
  43. unsigned int index; /* index of item */
  44. unsigned int access; /* access rights */
  45. unsigned int count; /* count of same elements */
  46. snd_kcontrol_info_t *info;
  47. snd_kcontrol_get_t *get;
  48. snd_kcontrol_put_t *put;
  49. unsigned long private_value;
  50. } snd_kcontrol_new_t;
  51. typedef struct _snd_kcontrol_volatile {
  52. snd_ctl_file_t *owner; /* locked */
  53. pid_t owner_pid;
  54. unsigned int access; /* access rights */
  55. } snd_kcontrol_volatile_t;
  56. struct _snd_kcontrol {
  57. struct list_head list; /* list of controls */
  58. snd_ctl_elem_id_t id;
  59. unsigned int count; /* count of same elements */
  60. snd_kcontrol_info_t *info;
  61. snd_kcontrol_get_t *get;
  62. snd_kcontrol_put_t *put;
  63. unsigned long private_value;
  64. void *private_data;
  65. void (*private_free)(snd_kcontrol_t *kcontrol);
  66. snd_kcontrol_volatile_t vd[0]; /* volatile data */
  67. };
  68. #define snd_kcontrol(n) list_entry(n, snd_kcontrol_t, list)
  69. typedef struct _snd_kctl_event {
  70. struct list_head list; /* list of events */
  71. snd_ctl_elem_id_t id;
  72. unsigned int mask;
  73. } snd_kctl_event_t;
  74. #define snd_kctl_event(n) list_entry(n, snd_kctl_event_t, list)
  75. struct _snd_ctl_file {
  76. struct list_head list; /* list of all control files */
  77. snd_card_t *card;
  78. pid_t pid;
  79. int prefer_pcm_subdevice;
  80. int prefer_rawmidi_subdevice;
  81. wait_queue_head_t change_sleep;
  82. spinlock_t read_lock;
  83. struct fasync_struct *fasync;
  84. int subscribed; /* read interface is activated */
  85. struct list_head events; /* waiting events for read */
  86. };
  87. #define snd_ctl_file(n) list_entry(n, snd_ctl_file_t, list)
  88. typedef int (*snd_kctl_ioctl_func_t) (snd_card_t * card,
  89. snd_ctl_file_t * control,
  90. unsigned int cmd, unsigned long arg);
  91. void snd_ctl_notify(snd_card_t * card, unsigned int mask, snd_ctl_elem_id_t * id);
  92. snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * kcontrol, unsigned int access);
  93. snd_kcontrol_t *snd_ctl_new1(const snd_kcontrol_new_t * kcontrolnew, void * private_data);
  94. void snd_ctl_free_one(snd_kcontrol_t * kcontrol);
  95. int snd_ctl_add(snd_card_t * card, snd_kcontrol_t * kcontrol);
  96. int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol);
  97. int snd_ctl_remove_id(snd_card_t * card, snd_ctl_elem_id_t *id);
  98. int snd_ctl_rename_id(snd_card_t * card, snd_ctl_elem_id_t *src_id, snd_ctl_elem_id_t *dst_id);
  99. snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid);
  100. snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id);
  101. int snd_ctl_create(snd_card_t *card);
  102. int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn);
  103. int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn);
  104. #ifdef CONFIG_COMPAT
  105. int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn);
  106. int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn);
  107. #else
  108. #define snd_ctl_register_ioctl_compat(fcn)
  109. #define snd_ctl_unregister_ioctl_compat(fcn)
  110. #endif
  111. int snd_ctl_elem_read(snd_card_t *card, snd_ctl_elem_value_t *control);
  112. int snd_ctl_elem_write(snd_card_t *card, snd_ctl_file_t *file, snd_ctl_elem_value_t *control);
  113. static inline unsigned int snd_ctl_get_ioffnum(snd_kcontrol_t *kctl, snd_ctl_elem_id_t *id)
  114. {
  115. return id->numid - kctl->id.numid;
  116. }
  117. static inline unsigned int snd_ctl_get_ioffidx(snd_kcontrol_t *kctl, snd_ctl_elem_id_t *id)
  118. {
  119. return id->index - kctl->id.index;
  120. }
  121. static inline unsigned int snd_ctl_get_ioff(snd_kcontrol_t *kctl, snd_ctl_elem_id_t *id)
  122. {
  123. if (id->numid) {
  124. return snd_ctl_get_ioffnum(kctl, id);
  125. } else {
  126. return snd_ctl_get_ioffidx(kctl, id);
  127. }
  128. }
  129. static inline snd_ctl_elem_id_t *snd_ctl_build_ioff(snd_ctl_elem_id_t *dst_id,
  130. snd_kcontrol_t *src_kctl,
  131. unsigned int offset)
  132. {
  133. *dst_id = src_kctl->id;
  134. dst_id->index += offset;
  135. dst_id->numid += offset;
  136. return dst_id;
  137. }
  138. #endif /* __SOUND_CONTROL_H */