ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / core / oss / pcm_plugin.h
1 #ifndef __PCM_PLUGIN_H
2 #define __PCM_PLUGIN_H
3
4 /*
5  *  Digital Audio (Plugin interface) abstract layer
6  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
7  *
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 2 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  *
23  */
24
25 #ifndef ATTRIBUTE_UNUSED
26 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
27 #endif
28
29 typedef unsigned int bitset_t;
30
31 static inline size_t bitset_size(int nbits)
32 {
33         return (nbits + sizeof(bitset_t) * 8 - 1) / (sizeof(bitset_t) * 8);
34 }
35
36 static inline bitset_t *bitset_alloc(int nbits)
37 {
38         return snd_kcalloc(bitset_size(nbits) * sizeof(bitset_t), GFP_KERNEL);
39 }
40         
41 static inline void bitset_set(bitset_t *bitmap, unsigned int pos)
42 {
43         size_t bits = sizeof(*bitmap) * 8;
44         bitmap[pos / bits] |= 1 << (pos % bits);
45 }
46
47 static inline void bitset_reset(bitset_t *bitmap, unsigned int pos)
48 {
49         size_t bits = sizeof(*bitmap) * 8;
50         bitmap[pos / bits] &= ~(1 << (pos % bits));
51 }
52
53 static inline int bitset_get(bitset_t *bitmap, unsigned int pos)
54 {
55         size_t bits = sizeof(*bitmap) * 8;
56         return !!(bitmap[pos / bits] & (1 << (pos % bits)));
57 }
58
59 static inline void bitset_copy(bitset_t *dst, bitset_t *src, unsigned int nbits)
60 {
61         memcpy(dst, src, bitset_size(nbits) * sizeof(bitset_t));
62 }
63
64 static inline void bitset_and(bitset_t *dst, bitset_t *bs, unsigned int nbits)
65 {
66         bitset_t *end = dst + bitset_size(nbits);
67         while (dst < end)
68                 *dst++ &= *bs++;
69 }
70
71 static inline void bitset_or(bitset_t *dst, bitset_t *bs, unsigned int nbits)
72 {
73         bitset_t *end = dst + bitset_size(nbits);
74         while (dst < end)
75                 *dst++ |= *bs++;
76 }
77
78 static inline void bitset_zero(bitset_t *dst, unsigned int nbits)
79 {
80         bitset_t *end = dst + bitset_size(nbits);
81         while (dst < end)
82                 *dst++ = 0;
83 }
84
85 static inline void bitset_one(bitset_t *dst, unsigned int nbits)
86 {
87         bitset_t *end = dst + bitset_size(nbits);
88         while (dst < end)
89                 *dst++ = ~(bitset_t)0;
90 }
91
92 #define snd_pcm_plug_t snd_pcm_substream_t
93 #define snd_pcm_plug_stream(plug) ((plug)->stream)
94
95 typedef enum {
96         INIT = 0,
97         PREPARE = 1,
98 } snd_pcm_plugin_action_t;
99
100 typedef struct _snd_pcm_channel_area {
101         void *addr;                     /* base address of channel samples */
102         unsigned int first;             /* offset to first sample in bits */
103         unsigned int step;              /* samples distance in bits */
104 } snd_pcm_channel_area_t;
105
106 typedef struct _snd_pcm_plugin_channel {
107         void *aptr;                     /* pointer to the allocated area */
108         snd_pcm_channel_area_t area;
109         snd_pcm_uframes_t frames;       /* allocated frames */
110         unsigned int enabled:1;         /* channel need to be processed */
111         unsigned int wanted:1;          /* channel is wanted */
112 } snd_pcm_plugin_channel_t;
113
114 typedef struct _snd_pcm_plugin_format {
115         int format;
116         unsigned int rate;
117         unsigned int channels;
118 } snd_pcm_plugin_format_t;
119
120 struct _snd_pcm_plugin {
121         const char *name;               /* plug-in name */
122         int stream;
123         snd_pcm_plugin_format_t src_format;     /* source format */
124         snd_pcm_plugin_format_t dst_format;     /* destination format */
125         int src_width;                  /* sample width in bits */
126         int dst_width;                  /* sample width in bits */
127         int access;
128         snd_pcm_sframes_t (*src_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t dst_frames);
129         snd_pcm_sframes_t (*dst_frames)(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t src_frames);
130         snd_pcm_sframes_t (*client_channels)(snd_pcm_plugin_t *plugin,
131                                  snd_pcm_uframes_t frames,
132                                  snd_pcm_plugin_channel_t **channels);
133         int (*src_channels_mask)(snd_pcm_plugin_t *plugin,
134                                bitset_t *dst_vmask,
135                                bitset_t **src_vmask);
136         int (*dst_channels_mask)(snd_pcm_plugin_t *plugin,
137                                bitset_t *src_vmask,
138                                bitset_t **dst_vmask);
139         snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin,
140                             const snd_pcm_plugin_channel_t *src_channels,
141                             snd_pcm_plugin_channel_t *dst_channels,
142                             snd_pcm_uframes_t frames);
143         int (*action)(snd_pcm_plugin_t *plugin,
144                       snd_pcm_plugin_action_t action,
145                       unsigned long data);
146         snd_pcm_plugin_t *prev;
147         snd_pcm_plugin_t *next;
148         snd_pcm_plug_t *plug;
149         void *private_data;
150         void (*private_free)(snd_pcm_plugin_t *plugin);
151         char *buf;
152         snd_pcm_uframes_t buf_frames;
153         snd_pcm_plugin_channel_t *buf_channels;
154         bitset_t *src_vmask;
155         bitset_t *dst_vmask;
156         char extra_data[0];
157 };
158
159 int snd_pcm_plugin_build(snd_pcm_plug_t *handle,
160                          const char *name,
161                          snd_pcm_plugin_format_t *src_format,
162                          snd_pcm_plugin_format_t *dst_format,
163                          size_t extra,
164                          snd_pcm_plugin_t **ret);
165 int snd_pcm_plugin_free(snd_pcm_plugin_t *plugin);
166 int snd_pcm_plugin_clear(snd_pcm_plugin_t **first);
167 int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames);
168 snd_pcm_sframes_t snd_pcm_plug_client_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t drv_size);
169 snd_pcm_sframes_t snd_pcm_plug_slave_size(snd_pcm_plug_t *handle, snd_pcm_uframes_t clt_size);
170
171 #define ROUTE_PLUGIN_USE_FLOAT 0
172 #define FULL ROUTE_PLUGIN_RESOLUTION
173 #define HALF ROUTE_PLUGIN_RESOLUTION / 2
174 typedef int route_ttable_entry_t;
175
176 int snd_pcm_plugin_build_io(snd_pcm_plug_t *handle,
177                             snd_pcm_hw_params_t *params,
178                             snd_pcm_plugin_t **r_plugin);
179 int snd_pcm_plugin_build_linear(snd_pcm_plug_t *handle,
180                                 snd_pcm_plugin_format_t *src_format,
181                                 snd_pcm_plugin_format_t *dst_format,
182                                 snd_pcm_plugin_t **r_plugin);
183 int snd_pcm_plugin_build_mulaw(snd_pcm_plug_t *handle,
184                                snd_pcm_plugin_format_t *src_format,
185                                snd_pcm_plugin_format_t *dst_format,
186                                snd_pcm_plugin_t **r_plugin);
187 int snd_pcm_plugin_build_rate(snd_pcm_plug_t *handle,
188                               snd_pcm_plugin_format_t *src_format,
189                               snd_pcm_plugin_format_t *dst_format,
190                               snd_pcm_plugin_t **r_plugin);
191 int snd_pcm_plugin_build_route(snd_pcm_plug_t *handle,
192                                snd_pcm_plugin_format_t *src_format,
193                                snd_pcm_plugin_format_t *dst_format,
194                                route_ttable_entry_t *ttable,
195                                snd_pcm_plugin_t **r_plugin);
196 int snd_pcm_plugin_build_copy(snd_pcm_plug_t *handle,
197                               snd_pcm_plugin_format_t *src_format,
198                               snd_pcm_plugin_format_t *dst_format,
199                               snd_pcm_plugin_t **r_plugin);
200
201 int snd_pcm_plug_format_plugins(snd_pcm_plug_t *substream,
202                                 snd_pcm_hw_params_t *params,
203                                 snd_pcm_hw_params_t *slave_params);
204
205 int snd_pcm_plug_slave_format(int format, snd_mask_t *format_mask);
206
207 int snd_pcm_plugin_append(snd_pcm_plugin_t *plugin);
208
209 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);
210 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);
211
212 snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *handle,
213                                          char *buf, snd_pcm_uframes_t count,
214                                          snd_pcm_plugin_channel_t **channels);
215
216 snd_pcm_sframes_t snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
217                                        snd_pcm_uframes_t frames,
218                                        snd_pcm_plugin_channel_t **channels);
219
220 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
221                          size_t samples, int format);
222 int snd_pcm_area_copy(const snd_pcm_channel_area_t *src_channel, size_t src_offset,
223                       const snd_pcm_channel_area_t *dst_channel, size_t dst_offset,
224                       size_t samples, int format);
225
226 void *snd_pcm_plug_buf_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t size);
227 void snd_pcm_plug_buf_unlock(snd_pcm_plug_t *plug, void *ptr);
228 snd_pcm_sframes_t snd_pcm_oss_write3(snd_pcm_substream_t *substream, const char *ptr, snd_pcm_uframes_t size, int in_kernel);
229 snd_pcm_sframes_t snd_pcm_oss_read3(snd_pcm_substream_t *substream, char *ptr, snd_pcm_uframes_t size, int in_kernel);
230 snd_pcm_sframes_t snd_pcm_oss_writev3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
231 snd_pcm_sframes_t snd_pcm_oss_readv3(snd_pcm_substream_t *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel);
232
233
234
235 #define ROUTE_PLUGIN_RESOLUTION 16
236
237 int getput_index(int format);
238 int copy_index(int format);
239 int conv_index(int src_format, int dst_format);
240
241 void zero_channel(snd_pcm_plugin_t *plugin,
242                   const snd_pcm_plugin_channel_t *dst_channel,
243                   size_t samples);
244
245 #ifdef PLUGIN_DEBUG
246 #define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args)
247 #else
248 #define pdprintf( fmt, args... ) 
249 #endif
250
251 #endif                          /* __PCM_PLUGIN_H */