aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/oss/io.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/core/oss/io.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'sound/core/oss/io.c')
-rw-r--r--sound/core/oss/io.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/sound/core/oss/io.c b/sound/core/oss/io.c
new file mode 100644
index 000000000000..bb1c99a5b734
--- /dev/null
+++ b/sound/core/oss/io.c
@@ -0,0 +1,134 @@
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
22#include <sound/driver.h>
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
29#define pcm_write(plug,buf,count) snd_pcm_oss_write3(plug,buf,count,1)
30#define pcm_writev(plug,vec,count) snd_pcm_oss_writev3(plug,vec,count,1)
31#define pcm_read(plug,buf,count) snd_pcm_oss_read3(plug,buf,count,1)
32#define pcm_readv(plug,vec,count) snd_pcm_oss_readv3(plug,vec,count,1)
33
34/*
35 * Basic io plugin
36 */
37
38static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin,
39 const snd_pcm_plugin_channel_t *src_channels,
40 snd_pcm_plugin_channel_t *dst_channels ATTRIBUTE_UNUSED,
41 snd_pcm_uframes_t frames)
42{
43 snd_assert(plugin != NULL, return -ENXIO);
44 snd_assert(src_channels != NULL, return -ENXIO);
45 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
46 return pcm_write(plugin->plug, src_channels->area.addr, frames);
47 } else {
48 int channel, channels = plugin->dst_format.channels;
49 void **bufs = (void**)plugin->extra_data;
50 snd_assert(bufs != NULL, return -ENXIO);
51 for (channel = 0; channel < channels; channel++) {
52 if (src_channels[channel].enabled)
53 bufs[channel] = src_channels[channel].area.addr;
54 else
55 bufs[channel] = NULL;
56 }
57 return pcm_writev(plugin->plug, bufs, frames);
58 }
59}
60
61static snd_pcm_sframes_t io_capture_transfer(snd_pcm_plugin_t *plugin,
62 const snd_pcm_plugin_channel_t *src_channels ATTRIBUTE_UNUSED,
63 snd_pcm_plugin_channel_t *dst_channels,
64 snd_pcm_uframes_t frames)
65{
66 snd_assert(plugin != NULL, return -ENXIO);
67 snd_assert(dst_channels != NULL, return -ENXIO);
68 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
69 return pcm_read(plugin->plug, dst_channels->area.addr, frames);
70 } else {
71 int channel, channels = plugin->dst_format.channels;
72 void **bufs = (void**)plugin->extra_data;
73 snd_assert(bufs != NULL, return -ENXIO);
74 for (channel = 0; channel < channels; channel++) {
75 if (dst_channels[channel].enabled)
76 bufs[channel] = dst_channels[channel].area.addr;
77 else
78 bufs[channel] = NULL;
79 }
80 return pcm_readv(plugin->plug, bufs, frames);
81 }
82 return 0;
83}
84
85static snd_pcm_sframes_t io_src_channels(snd_pcm_plugin_t *plugin,
86 snd_pcm_uframes_t frames,
87 snd_pcm_plugin_channel_t **channels)
88{
89 int err;
90 unsigned int channel;
91 snd_pcm_plugin_channel_t *v;
92 err = snd_pcm_plugin_client_channels(plugin, frames, &v);
93 if (err < 0)
94 return err;
95 *channels = v;
96 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
97 for (channel = 0; channel < plugin->src_format.channels; ++channel, ++v)
98 v->wanted = 1;
99 }
100 return frames;
101}
102
103int snd_pcm_plugin_build_io(snd_pcm_plug_t *plug,
104 snd_pcm_hw_params_t *params,
105 snd_pcm_plugin_t **r_plugin)
106{
107 int err;
108 snd_pcm_plugin_format_t format;
109 snd_pcm_plugin_t *plugin;
110
111 snd_assert(r_plugin != NULL, return -ENXIO);
112 *r_plugin = NULL;
113 snd_assert(plug != NULL && params != NULL, return -ENXIO);
114 format.format = params_format(params);
115 format.rate = params_rate(params);
116 format.channels = params_channels(params);
117 err = snd_pcm_plugin_build(plug, "I/O io",
118 &format, &format,
119 sizeof(void *) * format.channels,
120 &plugin);
121 if (err < 0)
122 return err;
123 plugin->access = params_access(params);
124 if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) {
125 plugin->transfer = io_playback_transfer;
126 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED)
127 plugin->client_channels = io_src_channels;
128 } else {
129 plugin->transfer = io_capture_transfer;
130 }
131
132 *r_plugin = plugin;
133 return 0;
134}