io.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * PCM I/O Plug-In Interface
  3. * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>
  4. *
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Library General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #ifdef CONFIG_SND_PCM_OSS_PLUGINS
  23. #include <linux/time.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include "pcm_plugin.h"
  28. #define pcm_write(plug,buf,count) snd_pcm_oss_write3(plug,buf,count,1)
  29. #define pcm_writev(plug,vec,count) snd_pcm_oss_writev3(plug,vec,count,1)
  30. #define pcm_read(plug,buf,count) snd_pcm_oss_read3(plug,buf,count,1)
  31. #define pcm_readv(plug,vec,count) snd_pcm_oss_readv3(plug,vec,count,1)
  32. /*
  33. * Basic io plugin
  34. */
  35. static snd_pcm_sframes_t io_playback_transfer(struct snd_pcm_plugin *plugin,
  36. const struct snd_pcm_plugin_channel *src_channels,
  37. struct snd_pcm_plugin_channel *dst_channels,
  38. snd_pcm_uframes_t frames)
  39. {
  40. snd_assert(plugin != NULL, return -ENXIO);
  41. snd_assert(src_channels != NULL, return -ENXIO);
  42. if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
  43. return pcm_write(plugin->plug, src_channels->area.addr, frames);
  44. } else {
  45. int channel, channels = plugin->dst_format.channels;
  46. void **bufs = (void**)plugin->extra_data;
  47. snd_assert(bufs != NULL, return -ENXIO);
  48. for (channel = 0; channel < channels; channel++) {
  49. if (src_channels[channel].enabled)
  50. bufs[channel] = src_channels[channel].area.addr;
  51. else
  52. bufs[channel] = NULL;
  53. }
  54. return pcm_writev(plugin->plug, bufs, frames);
  55. }
  56. }
  57. static snd_pcm_sframes_t io_capture_transfer(struct snd_pcm_plugin *plugin,
  58. const struct snd_pcm_plugin_channel *src_channels,
  59. struct snd_pcm_plugin_channel *dst_channels,
  60. snd_pcm_uframes_t frames)
  61. {
  62. snd_assert(plugin != NULL, return -ENXIO);
  63. snd_assert(dst_channels != NULL, return -ENXIO);
  64. if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
  65. return pcm_read(plugin->plug, dst_channels->area.addr, frames);
  66. } else {
  67. int channel, channels = plugin->dst_format.channels;
  68. void **bufs = (void**)plugin->extra_data;
  69. snd_assert(bufs != NULL, return -ENXIO);
  70. for (channel = 0; channel < channels; channel++) {
  71. if (dst_channels[channel].enabled)
  72. bufs[channel] = dst_channels[channel].area.addr;
  73. else
  74. bufs[channel] = NULL;
  75. }
  76. return pcm_readv(plugin->plug, bufs, frames);
  77. }
  78. return 0;
  79. }
  80. static snd_pcm_sframes_t io_src_channels(struct snd_pcm_plugin *plugin,
  81. snd_pcm_uframes_t frames,
  82. struct snd_pcm_plugin_channel **channels)
  83. {
  84. int err;
  85. unsigned int channel;
  86. struct snd_pcm_plugin_channel *v;
  87. err = snd_pcm_plugin_client_channels(plugin, frames, &v);
  88. if (err < 0)
  89. return err;
  90. *channels = v;
  91. if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
  92. for (channel = 0; channel < plugin->src_format.channels; ++channel, ++v)
  93. v->wanted = 1;
  94. }
  95. return frames;
  96. }
  97. int snd_pcm_plugin_build_io(struct snd_pcm_substream *plug,
  98. struct snd_pcm_hw_params *params,
  99. struct snd_pcm_plugin **r_plugin)
  100. {
  101. int err;
  102. struct snd_pcm_plugin_format format;
  103. struct snd_pcm_plugin *plugin;
  104. snd_assert(r_plugin != NULL, return -ENXIO);
  105. *r_plugin = NULL;
  106. snd_assert(plug != NULL && params != NULL, return -ENXIO);
  107. format.format = params_format(params);
  108. format.rate = params_rate(params);
  109. format.channels = params_channels(params);
  110. err = snd_pcm_plugin_build(plug, "I/O io",
  111. &format, &format,
  112. sizeof(void *) * format.channels,
  113. &plugin);
  114. if (err < 0)
  115. return err;
  116. plugin->access = params_access(params);
  117. if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) {
  118. plugin->transfer = io_playback_transfer;
  119. if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED)
  120. plugin->client_channels = io_src_channels;
  121. } else {
  122. plugin->transfer = io_capture_transfer;
  123. }
  124. *r_plugin = plugin;
  125. return 0;
  126. }
  127. #endif