pcm_plugin.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #ifdef CONFIG_SND_PCM_OSS_PLUGINS
  24. #include <linux/bitmap.h>
  25. static inline unsigned long *bitmap_alloc(unsigned int nbits)
  26. {
  27. return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL);
  28. }
  29. #define snd_pcm_plug_stream(plug) ((plug)->stream)
  30. enum snd_pcm_plugin_action {
  31. INIT = 0,
  32. PREPARE = 1,
  33. };
  34. struct snd_pcm_channel_area {
  35. void *addr; /* base address of channel samples */
  36. unsigned int first; /* offset to first sample in bits */
  37. unsigned int step; /* samples distance in bits */
  38. };
  39. struct snd_pcm_plugin_channel {
  40. void *aptr; /* pointer to the allocated area */
  41. struct snd_pcm_channel_area area;
  42. snd_pcm_uframes_t frames; /* allocated frames */
  43. unsigned int enabled:1; /* channel need to be processed */
  44. unsigned int wanted:1; /* channel is wanted */
  45. };
  46. struct snd_pcm_plugin_format {
  47. int format;
  48. unsigned int rate;
  49. unsigned int channels;
  50. };
  51. struct snd_pcm_plugin {
  52. const char *name; /* plug-in name */
  53. int stream;
  54. struct snd_pcm_plugin_format src_format; /* source format */
  55. struct snd_pcm_plugin_format dst_format; /* destination format */
  56. int src_width; /* sample width in bits */
  57. int dst_width; /* sample width in bits */
  58. int access;
  59. snd_pcm_sframes_t (*src_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t dst_frames);
  60. snd_pcm_sframes_t (*dst_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t src_frames);
  61. snd_pcm_sframes_t (*client_channels)(struct snd_pcm_plugin *plugin,
  62. snd_pcm_uframes_t frames,
  63. struct snd_pcm_plugin_channel **channels);
  64. int (*src_channels_mask)(struct snd_pcm_plugin *plugin,
  65. unsigned long *dst_vmask,
  66. unsigned long **src_vmask);
  67. int (*dst_channels_mask)(struct snd_pcm_plugin *plugin,
  68. unsigned long *src_vmask,
  69. unsigned long **dst_vmask);
  70. snd_pcm_sframes_t (*transfer)(struct snd_pcm_plugin *plugin,
  71. const struct snd_pcm_plugin_channel *src_channels,
  72. struct snd_pcm_plugin_channel *dst_channels,
  73. snd_pcm_uframes_t frames);
  74. int (*action)(struct snd_pcm_plugin *plugin,
  75. enum snd_pcm_plugin_action action,
  76. unsigned long data);
  77. struct snd_pcm_plugin *prev;
  78. struct snd_pcm_plugin *next;
  79. struct snd_pcm_substream *plug;
  80. void *private_data;
  81. void (*private_free)(struct snd_pcm_plugin *plugin);
  82. char *buf;
  83. snd_pcm_uframes_t buf_frames;
  84. struct snd_pcm_plugin_channel *buf_channels;
  85. unsigned long *src_vmask;
  86. unsigned long *dst_vmask;
  87. char extra_data[0];
  88. };
  89. int snd_pcm_plugin_build(struct snd_pcm_substream *handle,
  90. const char *name,
  91. struct snd_pcm_plugin_format *src_format,
  92. struct snd_pcm_plugin_format *dst_format,
  93. size_t extra,
  94. struct snd_pcm_plugin **ret);
  95. int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin);
  96. int snd_pcm_plugin_clear(struct snd_pcm_plugin **first);
  97. int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames);
  98. snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size);
  99. snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size);
  100. #define FULL ROUTE_PLUGIN_RESOLUTION
  101. #define HALF ROUTE_PLUGIN_RESOLUTION / 2
  102. int snd_pcm_plugin_build_io(struct snd_pcm_substream *handle,
  103. struct snd_pcm_hw_params *params,
  104. struct snd_pcm_plugin **r_plugin);
  105. int snd_pcm_plugin_build_linear(struct snd_pcm_substream *handle,
  106. struct snd_pcm_plugin_format *src_format,
  107. struct snd_pcm_plugin_format *dst_format,
  108. struct snd_pcm_plugin **r_plugin);
  109. int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *handle,
  110. struct snd_pcm_plugin_format *src_format,
  111. struct snd_pcm_plugin_format *dst_format,
  112. struct snd_pcm_plugin **r_plugin);
  113. int snd_pcm_plugin_build_rate(struct snd_pcm_substream *handle,
  114. struct snd_pcm_plugin_format *src_format,
  115. struct snd_pcm_plugin_format *dst_format,
  116. struct snd_pcm_plugin **r_plugin);
  117. int snd_pcm_plugin_build_route(struct snd_pcm_substream *handle,
  118. struct snd_pcm_plugin_format *src_format,
  119. struct snd_pcm_plugin_format *dst_format,
  120. int *ttable,
  121. struct snd_pcm_plugin **r_plugin);
  122. int snd_pcm_plugin_build_copy(struct snd_pcm_substream *handle,
  123. struct snd_pcm_plugin_format *src_format,
  124. struct snd_pcm_plugin_format *dst_format,
  125. struct snd_pcm_plugin **r_plugin);
  126. int snd_pcm_plug_format_plugins(struct snd_pcm_substream *substream,
  127. struct snd_pcm_hw_params *params,
  128. struct snd_pcm_hw_params *slave_params);
  129. int snd_pcm_plug_slave_format(int format, struct snd_mask *format_mask);
  130. int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin);
  131. snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *handle,
  132. struct snd_pcm_plugin_channel *src_channels,
  133. snd_pcm_uframes_t size);
  134. snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *handle,
  135. struct snd_pcm_plugin_channel *dst_channels_final,
  136. snd_pcm_uframes_t size);
  137. snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *handle,
  138. char *buf, snd_pcm_uframes_t count,
  139. struct snd_pcm_plugin_channel **channels);
  140. snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
  141. snd_pcm_uframes_t frames,
  142. struct snd_pcm_plugin_channel **channels);
  143. int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_channel,
  144. size_t dst_offset,
  145. size_t samples, int format);
  146. int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_channel,
  147. size_t src_offset,
  148. const struct snd_pcm_channel_area *dst_channel,
  149. size_t dst_offset,
  150. size_t samples, int format);
  151. void *snd_pcm_plug_buf_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t size);
  152. void snd_pcm_plug_buf_unlock(struct snd_pcm_substream *plug, void *ptr);
  153. snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream,
  154. const char *ptr, snd_pcm_uframes_t size,
  155. int in_kernel);
  156. snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream,
  157. char *ptr, snd_pcm_uframes_t size, int in_kernel);
  158. snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream,
  159. void **bufs, snd_pcm_uframes_t frames,
  160. int in_kernel);
  161. snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream,
  162. void **bufs, snd_pcm_uframes_t frames,
  163. int in_kernel);
  164. #define ROUTE_PLUGIN_RESOLUTION 16
  165. int getput_index(int format);
  166. int copy_index(int format);
  167. int conv_index(int src_format, int dst_format);
  168. void zero_channel(struct snd_pcm_plugin *plugin,
  169. const struct snd_pcm_plugin_channel *dst_channel,
  170. size_t samples);
  171. #else
  172. static inline snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size) { return drv_size; }
  173. static inline snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size) { return clt_size; }
  174. static inline int snd_pcm_plug_slave_format(int format, struct snd_mask *format_mask) { return format; }
  175. #endif
  176. #ifdef PLUGIN_DEBUG
  177. #define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
  178. #else
  179. #define pdprintf( fmt, args... )
  180. #endif
  181. #endif /* __PCM_PLUGIN_H */