pcm_plugin.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __PCM_PLUGIN_H
  3. #define __PCM_PLUGIN_H
  4. /*
  5. * Digital Audio (Plugin interface) abstract layer
  6. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  7. */
  8. #ifdef CONFIG_SND_PCM_OSS_PLUGINS
  9. #define snd_pcm_plug_stream(plug) ((plug)->stream)
  10. enum snd_pcm_plugin_action {
  11. INIT = 0,
  12. PREPARE = 1,
  13. };
  14. struct snd_pcm_channel_area {
  15. void *addr; /* base address of channel samples */
  16. unsigned int first; /* offset to first sample in bits */
  17. unsigned int step; /* samples distance in bits */
  18. };
  19. struct snd_pcm_plugin_channel {
  20. void *aptr; /* pointer to the allocated area */
  21. struct snd_pcm_channel_area area;
  22. snd_pcm_uframes_t frames; /* allocated frames */
  23. unsigned int enabled:1; /* channel need to be processed */
  24. unsigned int wanted:1; /* channel is wanted */
  25. };
  26. struct snd_pcm_plugin_format {
  27. snd_pcm_format_t format;
  28. unsigned int rate;
  29. unsigned int channels;
  30. };
  31. struct snd_pcm_plugin {
  32. const char *name; /* plug-in name */
  33. int stream;
  34. struct snd_pcm_plugin_format src_format; /* source format */
  35. struct snd_pcm_plugin_format dst_format; /* destination format */
  36. int src_width; /* sample width in bits */
  37. int dst_width; /* sample width in bits */
  38. snd_pcm_access_t access;
  39. snd_pcm_sframes_t (*src_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t dst_frames);
  40. snd_pcm_sframes_t (*dst_frames)(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t src_frames);
  41. snd_pcm_sframes_t (*client_channels)(struct snd_pcm_plugin *plugin,
  42. snd_pcm_uframes_t frames,
  43. struct snd_pcm_plugin_channel **channels);
  44. snd_pcm_sframes_t (*transfer)(struct snd_pcm_plugin *plugin,
  45. const struct snd_pcm_plugin_channel *src_channels,
  46. struct snd_pcm_plugin_channel *dst_channels,
  47. snd_pcm_uframes_t frames);
  48. int (*action)(struct snd_pcm_plugin *plugin,
  49. enum snd_pcm_plugin_action action,
  50. unsigned long data);
  51. struct snd_pcm_plugin *prev;
  52. struct snd_pcm_plugin *next;
  53. struct snd_pcm_substream *plug;
  54. void *private_data;
  55. void (*private_free)(struct snd_pcm_plugin *plugin);
  56. char *buf;
  57. snd_pcm_uframes_t buf_frames;
  58. struct snd_pcm_plugin_channel *buf_channels;
  59. char extra_data[];
  60. };
  61. int snd_pcm_plugin_build(struct snd_pcm_substream *handle,
  62. const char *name,
  63. struct snd_pcm_plugin_format *src_format,
  64. struct snd_pcm_plugin_format *dst_format,
  65. size_t extra,
  66. struct snd_pcm_plugin **ret);
  67. int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin);
  68. int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames);
  69. snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t drv_size);
  70. snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *handle, snd_pcm_uframes_t clt_size);
  71. #define FULL ROUTE_PLUGIN_RESOLUTION
  72. #define HALF ROUTE_PLUGIN_RESOLUTION / 2
  73. int snd_pcm_plugin_build_io(struct snd_pcm_substream *handle,
  74. struct snd_pcm_hw_params *params,
  75. struct snd_pcm_plugin **r_plugin);
  76. int snd_pcm_plugin_build_linear(struct snd_pcm_substream *handle,
  77. struct snd_pcm_plugin_format *src_format,
  78. struct snd_pcm_plugin_format *dst_format,
  79. struct snd_pcm_plugin **r_plugin);
  80. int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *handle,
  81. struct snd_pcm_plugin_format *src_format,
  82. struct snd_pcm_plugin_format *dst_format,
  83. struct snd_pcm_plugin **r_plugin);
  84. int snd_pcm_plugin_build_rate(struct snd_pcm_substream *handle,
  85. struct snd_pcm_plugin_format *src_format,
  86. struct snd_pcm_plugin_format *dst_format,
  87. struct snd_pcm_plugin **r_plugin);
  88. int snd_pcm_plugin_build_route(struct snd_pcm_substream *handle,
  89. struct snd_pcm_plugin_format *src_format,
  90. struct snd_pcm_plugin_format *dst_format,
  91. struct snd_pcm_plugin **r_plugin);
  92. int snd_pcm_plugin_build_copy(struct snd_pcm_substream *handle,
  93. struct snd_pcm_plugin_format *src_format,
  94. struct snd_pcm_plugin_format *dst_format,
  95. struct snd_pcm_plugin **r_plugin);
  96. int snd_pcm_plug_format_plugins(struct snd_pcm_substream *substream,
  97. struct snd_pcm_hw_params *params,
  98. struct snd_pcm_hw_params *slave_params);
  99. snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format,
  100. const struct snd_mask *format_mask);
  101. int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin);
  102. snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *handle,
  103. struct snd_pcm_plugin_channel *src_channels,
  104. snd_pcm_uframes_t size);
  105. snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *handle,
  106. struct snd_pcm_plugin_channel *dst_channels_final,
  107. snd_pcm_uframes_t size);
  108. snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *handle,
  109. char *buf, snd_pcm_uframes_t count,
  110. struct snd_pcm_plugin_channel **channels);
  111. snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
  112. snd_pcm_uframes_t frames,
  113. struct snd_pcm_plugin_channel **channels);
  114. int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_channel,
  115. size_t dst_offset,
  116. size_t samples, snd_pcm_format_t format);
  117. int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_channel,
  118. size_t src_offset,
  119. const struct snd_pcm_channel_area *dst_channel,
  120. size_t dst_offset,
  121. size_t samples, snd_pcm_format_t format);
  122. #else
  123. 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; }
  124. 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; }
  125. static inline int snd_pcm_plug_slave_format(int format, const struct snd_mask *format_mask) { return format; }
  126. #endif
  127. snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream,
  128. const char *ptr, snd_pcm_uframes_t size,
  129. int in_kernel);
  130. snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream,
  131. char *ptr, snd_pcm_uframes_t size, int in_kernel);
  132. snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream,
  133. void **bufs, snd_pcm_uframes_t frames);
  134. snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream,
  135. void **bufs, snd_pcm_uframes_t frames);
  136. #ifdef PLUGIN_DEBUG
  137. #define pdprintf(fmt, args...) pr_debug("plugin: " fmt, ##args)
  138. #else
  139. #define pdprintf(fmt, args...)
  140. #endif
  141. #endif /* __PCM_PLUGIN_H */