pcm_plugin.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef __PCM_PLUGIN_H
  2. #define __PCM_PLUGIN_H
  3. /*
  4. * Digital Audio (Plugin interface) abstract layer
  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. #ifndef ATTRIBUTE_UNUSED
  24. #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
  25. #endif
  26. typedef unsigned int bitset_t;
  27. static inline size_t bitset_size(int nbits)
  28. {
  29. return (nbits + sizeof(bitset_t) * 8 - 1) / (sizeof(bitset_t) * 8);
  30. }
  31. static inline bitset_t *bitset_alloc(int nbits)
  32. {
  33. return kcalloc(bitset_size(nbits), sizeof(bitset_t), GFP_KERNEL);
  34. }
  35. static inline void bitset_set(bitset_t *bitmap, unsigned int pos)
  36. {
  37. size_t bits = sizeof(*bitmap) * 8;
  38. bitmap[pos / bits] |= 1 << (pos % bits);
  39. }
  40. static inline void bitset_reset(bitset_t *bitmap, unsigned int pos)
  41. {
  42. size_t bits = sizeof(*bitmap) * 8;
  43. bitmap[pos / bits] &= ~(1 << (pos % bits));
  44. }
  45. static inline int bitset_get(bitset_t *bitmap, unsigned int pos)
  46. {
  47. size_t bits = sizeof(*bitmap) * 8;
  48. return !!(bitmap[pos / bits] & (1 << (pos % bits)));
  49. }
  50. static inline void bitset_copy(bitset_t *dst, bitset_t *src, unsigned int nbits)
  51. {
  52. memcpy(dst, src, bitset_size(nbits) * sizeof(bitset_t));
  53. }
  54. static inline void bitset_and(bitset_t *dst, bitset_t *bs, unsigned int nbits)
  55. {
  56. bitset_t *end = dst + bitset_size(nbits);
  57. while (dst < end)
  58. *dst++ &= *bs++;
  59. }
  60. static inline void bitset_or(bitset_t *dst, bitset_t *bs, unsigned int nbits)
  61. {
  62. bitset_t *end = dst + bitset_size(nbits);
  63. while (dst < end)
  64. *dst++ |= *bs++;
  65. }
  66. static inline void bitset_zero(bitset_t *dst, unsigned int nbits)
  67. {
  68. bitset_t *end = dst + bitset_size(nbits);
  69. while (dst < end)
  70. *dst++ = 0;
  71. }
  72. static inline void bitset_one(bitset_t *dst, unsigned int nbits)
  73. {
  74. bitset_t *end = dst + bitset_size(nbits);
  75. while (dst < end)
  76. *dst++ = ~(bitset_t)0;
  77. }
  78. #define snd_pcm_plug_t snd_pcm_substream_t
  79. #define snd_pcm_plug_stream(plug) ((plug)->stream)
  80. typedef enum {
  81. INIT = 0,
  82. PREPARE = 1,
  83. } snd_pcm_plugin_action_t;
  84. typedef struct _snd_pcm_channel_area {
  85. void *addr; /* base address of channel samples */
  86. unsigned int first; /* offset to first sample in bits */
  87. unsigned int step; /* samples distance in bits */
  88. } snd_pcm_channel_area_t;
  89. typedef struct _snd_pcm_plugin_channel {
  90. void *aptr; /* pointer to the allocated area */
  91. snd_pcm_channel_area_t area;
  92. snd_pcm_uframes_t frames; /* allocated frames */
  93. unsigned int enabled:1; /* channel need to be processed */
  94. unsigned int wanted:1; /* channel is wanted */
  95. } snd_pcm_plugin_channel_t;
  96. typedef struct _snd_pcm_plugin_format {
  97. int format;
  98. unsigned int rate;
  99. unsigned int channels;
  100. } snd_pcm_plugin_format_t;
  101. struct _snd_pcm_plugin {
  102. const char *name; /* plug-in name */
  103. int stream;
  104. snd_pcm_plugin_format_t src_format; /* source format */
  105. snd_pcm_plugin_format_t dst_format; /* destination format */
  106. int src_width; /* sample width in bits */
  107. int dst_width; /* sample width in bits */
  108. int access;
  109. snd_pcm_sframes_t (*src_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t dst_frames);
  110. snd_pcm_sframes_t (*dst_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t src_frames);
  111. snd_pcm_sframes_t (*client_channels)(snd_pcm_plugin_t *plugin,
  112. snd_pcm_uframes_t frames,
  113. snd_pcm_plugin_channel_t **channels);
  114. int (*src_channels_mask)(snd_pcm_plugin_t *plugin,
  115. bitset_t *dst_vmask,
  116. bitset_t **src_vmask);
  117. int (*dst_channels_mask)(snd_pcm_plugin_t *plugin,
  118. bitset_t *src_vmask,
  119. bitset_t **dst_vmask);
  120. snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin,
  121. const snd_pcm_plugin_channel_t *src_channels,
  122. snd_pcm_plugin_channel_t *dst_channels,
  123. snd_pcm_uframes_t frames);
  124. int (*action)(snd_pcm_plugin_t *plugin,
  125. snd_pcm_plugin_action_t action,
  126. unsigned long data);
  127. snd_pcm_plugin_t *prev;
  128. snd_pcm_plugin_t *next;
  129. snd_pcm_plug_t *plug;
  130. void *private_data;
  131. void (*private_free)(snd_pcm_plugin_t *plugin);
  132. char *buf;
  133. snd_pcm_uframes_t buf_frames;
  134. snd_pcm_plugin_channel_t *buf_channels;
  135. bitset_t *src_vmask;
  136. bitset_t *dst_vmask;
  137. char extra_data[0];
  138. };
  139. int snd_pcm_plugin_build(snd_pcm_plug_t *handle,
  140. const char *name,
  141. snd_pcm_plugin_format_t *src_format,
  142. snd_pcm_plugin_format_t *dst_format,
  143. size_t extra,
  144. snd_pcm_plugin_t **ret);
  145. int snd_pcm_plugin_free(snd_pcm_plugin_t *plugin);
  146. int snd_pcm_plugin_clear(snd_pcm_plugin_t **first);
  147. int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames);
  148. snd_pcm_sframes_t snd_pcm_plug_client_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t drv_size);
  149. snd_pcm_sframes_t snd_pcm_plug_slave_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t clt_size);
  150. #define FULL ROUTE_PLUGIN_RESOLUTION
  151. #define HALF ROUTE_PLUGIN_RESOLUTION / 2
  152. typedef int route_ttable_entry_t;
  153. int snd_pcm_plugin_build_io(snd_pcm_plug_t *handle,
  154. snd_pcm_hw_params_t *params,
  155. snd_pcm_plugin_t **r_plugin);
  156. int snd_pcm_plugin_build_linear(snd_pcm_plug_t *handle,
  157. snd_pcm_plugin_format_t *src_format,
  158. snd_pcm_plugin_format_t *dst_format,
  159. snd_pcm_plugin_t **r_plugin);
  160. int snd_pcm_plugin_build_mulaw(snd_pcm_plug_t *handle,
  161. snd_pcm_plugin_format_t *src_format,
  162. snd_pcm_plugin_format_t *dst_format,
  163. snd_pcm_plugin_t **r_plugin);
  164. int snd_pcm_plugin_build_rate(snd_pcm_plug_t *handle,
  165. snd_pcm_plugin_format_t *src_format,
  166. snd_pcm_plugin_format_t *dst_format,
  167. snd_pcm_plugin_t **r_plugin);
  168. int snd_pcm_plugin_build_route(snd_pcm_plug_t *handle,
  169. snd_pcm_plugin_format_t *src_format,
  170. snd_pcm_plugin_format_t *dst_format,
  171. route_ttable_entry_t *ttable,
  172. snd_pcm_plugin_t **r_plugin);
  173. int snd_pcm_plugin_build_copy(snd_pcm_plug_t *handle,
  174. snd_pcm_plugin_format_t *src_format,
  175. snd_pcm_plugin_format_t *dst_format,
  176. snd_pcm_plugin_t **r_plugin);
  177. int snd_pcm_plug_format_plugins(snd_pcm_plug_t *substream,
  178. snd_pcm_hw_params_t *params,
  179. snd_pcm_hw_params_t *slave_params);
  180. int snd_pcm_plug_slave_format(int format, snd_mask_t *format_mask);
  181. int snd_pcm_plugin_append(snd_pcm_plugin_t *plugin);
  182. snd_pcm_sframes_t snd_pcm_plug_write_transfer(snd_pcm_plug_t *handle, snd_pcm_plugin_channel_t *src_channels, snd_pcm_uframes_t size);
  183. snd_pcm_sframes_t snd_pcm_plug_read_transfer(snd_pcm_plug_t *handle, snd_pcm_plugin_channel_t *dst_channels_final, snd_pcm_uframes_t size);
  184. snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *handle,
  185. char *buf, snd_pcm_uframes_t count,
  186. snd_pcm_plugin_channel_t **channels);
  187. snd_pcm_sframes_t snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
  188. snd_pcm_uframes_t frames,
  189. snd_pcm_plugin_channel_t **channels);
  190. int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
  191. size_t samples, int format);
  192. int snd_pcm_area_copy(const snd_pcm_channel_area_t *src_channel, size_t src_offset,
  193. const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
  194. size_t samples, int format);
  195. void *snd_pcm_plug_buf_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t size);
  196. void snd_pcm_plug_buf_unlock(snd_pcm_plug_t *plug, void *ptr);
  197. snd_pcm_sframes_t snd_pcm_oss_write3(snd_pcm_substream_t *substream, const char *ptr, snd_pcm_uframes_t size, int in_kernel);
  198. snd_pcm_sframes_t snd_pcm_oss_read3(snd_pcm_substream_t *substream, char *ptr, snd_pcm_uframes_t size, int in_kernel);
  199. snd_pcm_sframes_t snd_pcm_oss_writev3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
  200. snd_pcm_sframes_t snd_pcm_oss_readv3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
  201. #define ROUTE_PLUGIN_RESOLUTION 16
  202. int getput_index(int format);
  203. int copy_index(int format);
  204. int conv_index(int src_format, int dst_format);
  205. void zero_channel(snd_pcm_plugin_t *plugin,
  206. const snd_pcm_plugin_channel_t *dst_channel,
  207. size_t samples);
  208. #ifdef PLUGIN_DEBUG
  209. #define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
  210. #else
  211. #define pdprintf( fmt, args... )
  212. #endif
  213. #endif /* __PCM_PLUGIN_H */