]> err.no Git - linux-2.6/blobdiff - sound/core/oss/pcm_plugin.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6] / sound / core / oss / pcm_plugin.c
index 6430410c6c04703af940b04f377b15fdb304572a..14095a927a1b1b6e9ab7ccf7cded095be969d43c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  PCM Plug-In shared (kernel/library) code
- *  Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
  *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
  *
  *
 #define snd_pcm_plug_first(plug) ((plug)->runtime->oss.plugin_first)
 #define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last)
 
-static int snd_pcm_plugin_src_channels_mask(snd_pcm_plugin_t *plugin,
-                                           bitset_t *dst_vmask,
-                                           bitset_t **src_vmask)
-{
-       bitset_t *vmask = plugin->src_vmask;
-       bitset_copy(vmask, dst_vmask, plugin->src_format.channels);
-       *src_vmask = vmask;
-       return 0;
-}
-
-static int snd_pcm_plugin_dst_channels_mask(snd_pcm_plugin_t *plugin,
-                                           bitset_t *src_vmask,
-                                           bitset_t **dst_vmask)
-{
-       bitset_t *vmask = plugin->dst_vmask;
-       bitset_copy(vmask, src_vmask, plugin->dst_format.channels);
-       *dst_vmask = vmask;
-       return 0;
-}
-
 /*
  *  because some cards might have rates "very close", we ignore
  *  all "resampling" requests within +-5%
@@ -67,13 +47,13 @@ static int rate_match(unsigned int src_rate, unsigned int dst_rate)
        return dst_rate >= low && dst_rate <= high;
 }
 
-static int snd_pcm_plugin_alloc(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t frames)
+static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t frames)
 {
-       snd_pcm_plugin_format_t *format;
+       struct snd_pcm_plugin_format *format;
        ssize_t width;
        size_t size;
        unsigned int channel;
-       snd_pcm_plugin_channel_t *c;
+       struct snd_pcm_plugin_channel *c;
 
        if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                format = &plugin->src_format;
@@ -120,12 +100,12 @@ static int snd_pcm_plugin_alloc(snd_pcm_plugin_t *plugin, snd_pcm_uframes_t fram
        return 0;
 }
 
-int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames)
+int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames)
 {
        int err;
        snd_assert(snd_pcm_plug_first(plug) != NULL, return -ENXIO);
        if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) {
-               snd_pcm_plugin_t *plugin = snd_pcm_plug_first(plug);
+               struct snd_pcm_plugin *plugin = snd_pcm_plug_first(plug);
                while (plugin->next) {
                        if (plugin->dst_frames)
                                frames = plugin->dst_frames(plugin, frames);
@@ -136,7 +116,7 @@ int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames)
                                return err;
                }
        } else {
-               snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
+               struct snd_pcm_plugin *plugin = snd_pcm_plug_last(plug);
                while (plugin->prev) {
                        if (plugin->src_frames)
                                frames = plugin->src_frames(plugin, frames);
@@ -151,27 +131,27 @@ int snd_pcm_plug_alloc(snd_pcm_plug_t *plug, snd_pcm_uframes_t frames)
 }
 
 
-snd_pcm_sframes_t snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
+snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
                                       snd_pcm_uframes_t frames,
-                                      snd_pcm_plugin_channel_t **channels)
+                                      struct snd_pcm_plugin_channel **channels)
 {
        *channels = plugin->buf_channels;
        return frames;
 }
 
-int snd_pcm_plugin_build(snd_pcm_plug_t *plug,
+int snd_pcm_plugin_build(struct snd_pcm_substream *plug,
                         const char *name,
-                        snd_pcm_plugin_format_t *src_format,
-                        snd_pcm_plugin_format_t *dst_format,
+                        struct snd_pcm_plugin_format *src_format,
+                        struct snd_pcm_plugin_format *dst_format,
                         size_t extra,
-                        snd_pcm_plugin_t **ret)
+                        struct snd_pcm_plugin **ret)
 {
-       snd_pcm_plugin_t *plugin;
+       struct snd_pcm_plugin *plugin;
        unsigned int channels;
        
        snd_assert(plug != NULL, return -ENXIO);
        snd_assert(src_format != NULL && dst_format != NULL, return -ENXIO);
-       plugin = kcalloc(1, sizeof(*plugin) + extra, GFP_KERNEL);
+       plugin = kzalloc(sizeof(*plugin) + extra, GFP_KERNEL);
        if (plugin == NULL)
                return -ENOMEM;
        plugin->name = name;
@@ -193,24 +173,12 @@ int snd_pcm_plugin_build(snd_pcm_plug_t *plug,
                snd_pcm_plugin_free(plugin);
                return -ENOMEM;
        }
-       plugin->src_vmask = bitset_alloc(src_format->channels);
-       if (plugin->src_vmask == NULL) {
-               snd_pcm_plugin_free(plugin);
-               return -ENOMEM;
-       }
-       plugin->dst_vmask = bitset_alloc(dst_format->channels);
-       if (plugin->dst_vmask == NULL) {
-               snd_pcm_plugin_free(plugin);
-               return -ENOMEM;
-       }
        plugin->client_channels = snd_pcm_plugin_client_channels;
-       plugin->src_channels_mask = snd_pcm_plugin_src_channels_mask;
-       plugin->dst_channels_mask = snd_pcm_plugin_dst_channels_mask;
        *ret = plugin;
        return 0;
 }
 
-int snd_pcm_plugin_free(snd_pcm_plugin_t *plugin)
+int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin)
 {
        if (! plugin)
                return 0;
@@ -218,15 +186,13 @@ int snd_pcm_plugin_free(snd_pcm_plugin_t *plugin)
                plugin->private_free(plugin);
        kfree(plugin->buf_channels);
        vfree(plugin->buf);
-       kfree(plugin->src_vmask);
-       kfree(plugin->dst_vmask);
        kfree(plugin);
        return 0;
 }
 
-snd_pcm_sframes_t snd_pcm_plug_client_size(snd_pcm_plug_t *plug, snd_pcm_uframes_t drv_frames)
+snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug, snd_pcm_uframes_t drv_frames)
 {
-       snd_pcm_plugin_t *plugin, *plugin_prev, *plugin_next;
+       struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next;
        int stream = snd_pcm_plug_stream(plug);
 
        snd_assert(plug != NULL, return -ENXIO);
@@ -253,9 +219,9 @@ snd_pcm_sframes_t snd_pcm_plug_client_size(snd_pcm_plug_t *plug, snd_pcm_uframes
        return drv_frames;
 }
 
-snd_pcm_sframes_t snd_pcm_plug_slave_size(snd_pcm_plug_t *plug, snd_pcm_uframes_t clt_frames)
+snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pcm_uframes_t clt_frames)
 {
-       snd_pcm_plugin_t *plugin, *plugin_prev, *plugin_next;
+       struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next;
        snd_pcm_sframes_t frames;
        int stream = snd_pcm_plug_stream(plug);
        
@@ -290,14 +256,16 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(snd_pcm_plug_t *plug, snd_pcm_uframes_
        return frames;
 }
 
-static int snd_pcm_plug_formats(snd_mask_t *mask, int format)
+static int snd_pcm_plug_formats(struct snd_mask *mask, int format)
 {
-       snd_mask_t formats = *mask;
+       struct snd_mask formats = *mask;
        u64 linfmts = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
                       SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_S16_LE |
                       SNDRV_PCM_FMTBIT_U16_BE | SNDRV_PCM_FMTBIT_S16_BE |
                       SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_S24_LE |
                       SNDRV_PCM_FMTBIT_U24_BE | SNDRV_PCM_FMTBIT_S24_BE |
+                      SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_S24_3LE |
+                      SNDRV_PCM_FMTBIT_U24_3BE | SNDRV_PCM_FMTBIT_S24_3BE |
                       SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_S32_LE |
                       SNDRV_PCM_FMTBIT_U32_BE | SNDRV_PCM_FMTBIT_S32_BE);
        snd_mask_set(&formats, SNDRV_PCM_FORMAT_MU_LAW);
@@ -314,6 +282,10 @@ static int preferred_formats[] = {
        SNDRV_PCM_FORMAT_S16_BE,
        SNDRV_PCM_FORMAT_U16_LE,
        SNDRV_PCM_FORMAT_U16_BE,
+       SNDRV_PCM_FORMAT_S24_3LE,
+       SNDRV_PCM_FORMAT_S24_3BE,
+       SNDRV_PCM_FORMAT_U24_3LE,
+       SNDRV_PCM_FORMAT_U24_3BE,
        SNDRV_PCM_FORMAT_S24_LE,
        SNDRV_PCM_FORMAT_S24_BE,
        SNDRV_PCM_FORMAT_U24_LE,
@@ -326,43 +298,39 @@ static int preferred_formats[] = {
        SNDRV_PCM_FORMAT_U8
 };
 
-int snd_pcm_plug_slave_format(int format, snd_mask_t *format_mask)
+int snd_pcm_plug_slave_format(int format, struct snd_mask *format_mask)
 {
+       int i;
+
        if (snd_mask_test(format_mask, format))
                return format;
        if (! snd_pcm_plug_formats(format_mask, format))
                return -EINVAL;
        if (snd_pcm_format_linear(format)) {
-               int width = snd_pcm_format_width(format);
-               int unsignd = snd_pcm_format_unsigned(format);
-               int big = snd_pcm_format_big_endian(format);
-               int format1;
-               int wid, width1=width;
-               int dwidth1 = 8;
-               for (wid = 0; wid < 4; ++wid) {
-                       int end, big1 = big;
-                       for (end = 0; end < 2; ++end) {
-                               int sgn, unsignd1 = unsignd;
-                               for (sgn = 0; sgn < 2; ++sgn) {
-                                       format1 = snd_pcm_build_linear_format(width1, unsignd1, big1);
-                                       if (format1 >= 0 &&
-                                           snd_mask_test(format_mask, format1))
-                                               goto _found;
-                                       unsignd1 = !unsignd1;
-                               }
-                               big1 = !big1;
-                       }
-                       if (width1 == 32) {
-                               dwidth1 = -dwidth1;
-                               width1 = width;
+               unsigned int width = snd_pcm_format_width(format);
+               int unsignd = snd_pcm_format_unsigned(format) > 0;
+               int big = snd_pcm_format_big_endian(format) > 0;
+               unsigned int badness, best = -1;
+               int best_format = -1;
+               for (i = 0; i < ARRAY_SIZE(preferred_formats); i++) {
+                       int f = preferred_formats[i];
+                       unsigned int w;
+                       if (!snd_mask_test(format_mask, f))
+                               continue;
+                       w = snd_pcm_format_width(f);
+                       if (w >= width)
+                               badness = w - width;
+                       else
+                               badness = width - w + 32;
+                       badness += snd_pcm_format_unsigned(f) != unsignd;
+                       badness += snd_pcm_format_big_endian(f) != big;
+                       if (badness < best) {
+                               best_format = f;
+                               best = badness;
                        }
-                       width1 += dwidth1;
                }
-               return -EINVAL;
-       _found:
-               return format1;
+               return best_format >= 0 ? best_format : -EINVAL;
        } else {
-               unsigned int i;
                switch (format) {
                case SNDRV_PCM_FORMAT_MU_LAW:
                        for (i = 0; i < ARRAY_SIZE(preferred_formats); ++i) {
@@ -376,15 +344,15 @@ int snd_pcm_plug_slave_format(int format, snd_mask_t *format_mask)
        }
 }
 
-int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
-                               snd_pcm_hw_params_t *params,
-                               snd_pcm_hw_params_t *slave_params)
+int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
+                               struct snd_pcm_hw_params *params,
+                               struct snd_pcm_hw_params *slave_params)
 {
-       snd_pcm_plugin_format_t tmpformat;
-       snd_pcm_plugin_format_t dstformat;
-       snd_pcm_plugin_format_t srcformat;
+       struct snd_pcm_plugin_format tmpformat;
+       struct snd_pcm_plugin_format dstformat;
+       struct snd_pcm_plugin_format srcformat;
        int src_access, dst_access;
-       snd_pcm_plugin_t *plugin = NULL;
+       struct snd_pcm_plugin *plugin = NULL;
        int err;
        int stream = snd_pcm_plug_stream(plug);
        int slave_interleaved = (params_channels(slave_params) == 1 ||
@@ -429,24 +397,14 @@ int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
                 dstformat.channels);
 
        /* Format change (linearization) */
-       if ((srcformat.format != dstformat.format ||
-            !rate_match(srcformat.rate, dstformat.rate) ||
-            srcformat.channels != dstformat.channels) &&
-           !snd_pcm_format_linear(srcformat.format)) {
-               if (snd_pcm_format_linear(dstformat.format))
-                       tmpformat.format = dstformat.format;
-               else
-                       tmpformat.format = SNDRV_PCM_FORMAT_S16;
-               switch (srcformat.format) {
-               case SNDRV_PCM_FORMAT_MU_LAW:
-                       err = snd_pcm_plugin_build_mulaw(plug,
-                                                        &srcformat, &tmpformat,
-                                                        &plugin);
-                       break;
-               default:
+       if (! rate_match(srcformat.rate, dstformat.rate) &&
+           ! snd_pcm_format_linear(srcformat.format)) {
+               if (srcformat.format != SNDRV_PCM_FORMAT_MU_LAW)
                        return -EINVAL;
-               }
-               pdprintf("format change: src=%i, dst=%i returns %i\n", srcformat.format, tmpformat.format, err);
+               tmpformat.format = SNDRV_PCM_FORMAT_S16;
+               err = snd_pcm_plugin_build_mulaw(plug,
+                                                &srcformat, &tmpformat,
+                                                &plugin);
                if (err < 0)
                        return err;
                err = snd_pcm_plugin_append(plugin);
@@ -460,35 +418,11 @@ int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
 
        /* channels reduction */
        if (srcformat.channels > dstformat.channels) {
-               int sv = srcformat.channels;
-               int dv = dstformat.channels;
-               route_ttable_entry_t *ttable = kcalloc(dv * sv, sizeof(*ttable), GFP_KERNEL);
-               if (ttable == NULL)
-                       return -ENOMEM;
-#if 1
-               if (sv == 2 && dv == 1) {
-                       ttable[0] = HALF;
-                       ttable[1] = HALF;
-               } else
-#endif
-               {
-                       int v;
-                       for (v = 0; v < dv; ++v)
-                               ttable[v * sv + v] = FULL;
-               }
                tmpformat.channels = dstformat.channels;
-               if (rate_match(srcformat.rate, dstformat.rate) &&
-                   snd_pcm_format_linear(dstformat.format))
-                       tmpformat.format = dstformat.format;
-               err = snd_pcm_plugin_build_route(plug,
-                                                &srcformat, &tmpformat,
-                                                ttable, &plugin);
-               kfree(ttable);
+               err = snd_pcm_plugin_build_route(plug, &srcformat, &tmpformat, &plugin);
                pdprintf("channels reduction: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
-               if (err < 0) {
-                       snd_pcm_plugin_free(plugin);
+               if (err < 0)
                        return err;
-               }
                err = snd_pcm_plugin_append(plugin);
                if (err < 0) {
                        snd_pcm_plugin_free(plugin);
@@ -500,18 +434,29 @@ int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
 
        /* rate resampling */
        if (!rate_match(srcformat.rate, dstformat.rate)) {
+               if (srcformat.format != SNDRV_PCM_FORMAT_S16) {
+                       /* convert to S16 for resampling */
+                       tmpformat.format = SNDRV_PCM_FORMAT_S16;
+                       err = snd_pcm_plugin_build_linear(plug,
+                                                         &srcformat, &tmpformat,
+                                                         &plugin);
+                       if (err < 0)
+                               return err;
+                       err = snd_pcm_plugin_append(plugin);
+                       if (err < 0) {
+                               snd_pcm_plugin_free(plugin);
+                               return err;
+                       }
+                       srcformat = tmpformat;
+                       src_access = dst_access;
+               }
                tmpformat.rate = dstformat.rate;
-               if (srcformat.channels == dstformat.channels &&
-                   snd_pcm_format_linear(dstformat.format))
-                       tmpformat.format = dstformat.format;
                err = snd_pcm_plugin_build_rate(plug,
                                                &srcformat, &tmpformat,
                                                &plugin);
                pdprintf("rate down resampling: src=%i, dst=%i returns %i\n", srcformat.rate, tmpformat.rate, err);
-               if (err < 0) {
-                       snd_pcm_plugin_free(plugin);
+               if (err < 0)
                        return err;
-               }                                           
                err = snd_pcm_plugin_append(plugin);
                if (err < 0) {
                        snd_pcm_plugin_free(plugin);
@@ -521,56 +466,11 @@ int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
                src_access = dst_access;
         }
 
-       /* channels extension  */
-       if (srcformat.channels < dstformat.channels) {
-               int sv = srcformat.channels;
-               int dv = dstformat.channels;
-               route_ttable_entry_t *ttable = kcalloc(dv * sv, sizeof(*ttable), GFP_KERNEL);
-               if (ttable == NULL)
-                       return -ENOMEM;
-#if 0
-               {
-                       int v;
-                       for (v = 0; v < sv; ++v)
-                               ttable[v * sv + v] = FULL;
-               }
-#else
-               {
-                       /* Playback is spreaded on all channels */
-                       int vd, vs;
-                       for (vd = 0, vs = 0; vd < dv; ++vd) {
-                               ttable[vd * sv + vs] = FULL;
-                               vs++;
-                               if (vs == sv)
-                                       vs = 0;
-                       }
-               }
-#endif
-               tmpformat.channels = dstformat.channels;
-               if (snd_pcm_format_linear(dstformat.format))
-                       tmpformat.format = dstformat.format;
-               err = snd_pcm_plugin_build_route(plug,
-                                                &srcformat, &tmpformat,
-                                                ttable, &plugin);
-               kfree(ttable);
-               pdprintf("channels extension: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
-               if (err < 0) {
-                       snd_pcm_plugin_free(plugin);
-                       return err;
-               }                                           
-               err = snd_pcm_plugin_append(plugin);
-               if (err < 0) {
-                       snd_pcm_plugin_free(plugin);
-                       return err;
-               }
-               srcformat = tmpformat;
-               src_access = dst_access;
-       }
-
        /* format change */
        if (srcformat.format != dstformat.format) {
                tmpformat.format = dstformat.format;
-               if (tmpformat.format == SNDRV_PCM_FORMAT_MU_LAW) {
+               if (srcformat.format == SNDRV_PCM_FORMAT_MU_LAW ||
+                   tmpformat.format == SNDRV_PCM_FORMAT_MU_LAW) {
                        err = snd_pcm_plugin_build_mulaw(plug,
                                                         &srcformat, &tmpformat,
                                                         &plugin);
@@ -595,6 +495,22 @@ int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
                src_access = dst_access;
        }
 
+       /* channels extension */
+       if (srcformat.channels < dstformat.channels) {
+               tmpformat.channels = dstformat.channels;
+               err = snd_pcm_plugin_build_route(plug, &srcformat, &tmpformat, &plugin);
+               pdprintf("channels extension: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
+               if (err < 0)
+                       return err;
+               err = snd_pcm_plugin_append(plugin);
+               if (err < 0) {
+                       snd_pcm_plugin_free(plugin);
+                       return err;
+               }
+               srcformat = tmpformat;
+               src_access = dst_access;
+       }
+
        /* de-interleave */
        if (src_access != dst_access) {
                err = snd_pcm_plugin_build_copy(plug,
@@ -614,14 +530,14 @@ int snd_pcm_plug_format_plugins(snd_pcm_plug_t *plug,
        return 0;
 }
 
-snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *plug,
+snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plug,
                                         char *buf,
                                         snd_pcm_uframes_t count,
-                                        snd_pcm_plugin_channel_t **channels)
+                                        struct snd_pcm_plugin_channel **channels)
 {
-       snd_pcm_plugin_t *plugin;
-       snd_pcm_plugin_channel_t *v;
-       snd_pcm_plugin_format_t *format;
+       struct snd_pcm_plugin *plugin;
+       struct snd_pcm_plugin_channel *v;
+       struct snd_pcm_plugin_format *format;
        int width, nchannels, channel;
        int stream = snd_pcm_plug_stream(plug);
 
@@ -650,102 +566,13 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *plug,
        return count;
 }
 
-static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug,
-                                              bitset_t *client_vmask)
+snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *plug, struct snd_pcm_plugin_channel *src_channels, snd_pcm_uframes_t size)
 {
-       snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
-       if (plugin == NULL) {
-               return 0;
-       } else {
-               int schannels = plugin->dst_format.channels;
-               bitset_t bs[bitset_size(schannels)];
-               bitset_t *srcmask;
-               bitset_t *dstmask = bs;
-               int err;
-               bitset_one(dstmask, schannels);
-
-               while (1) {
-                       err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
-                       if (err < 0)
-                               return err;
-                       dstmask = srcmask;
-                       if (plugin->prev == NULL)
-                               break;
-                       plugin = plugin->prev;
-               }
-               bitset_and(client_vmask, dstmask, plugin->src_format.channels);
-               return 0;
-       }
-}
-
-static int snd_pcm_plug_playback_disable_useless_channels(snd_pcm_plug_t *plug,
-                                                         snd_pcm_plugin_channel_t *src_channels)
-{
-       snd_pcm_plugin_t *plugin = snd_pcm_plug_first(plug);
-       unsigned int nchannels = plugin->src_format.channels;
-       bitset_t bs[bitset_size(nchannels)];
-       bitset_t *srcmask = bs;
-       int err;
-       unsigned int channel;
-       for (channel = 0; channel < nchannels; channel++) {
-               if (src_channels[channel].enabled)
-                       bitset_set(srcmask, channel);
-               else
-                       bitset_reset(srcmask, channel);
-       }
-       err = snd_pcm_plug_playback_channels_mask(plug, srcmask);
-       if (err < 0)
-               return err;
-       for (channel = 0; channel < nchannels; channel++) {
-               if (!bitset_get(srcmask, channel))
-                       src_channels[channel].enabled = 0;
-       }
-       return 0;
-}
-
-static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug,
-                                                        snd_pcm_plugin_channel_t *src_channels,
-                                                        snd_pcm_plugin_channel_t *client_channels)
-{
-       snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
-       unsigned int nchannels = plugin->dst_format.channels;
-       bitset_t bs[bitset_size(nchannels)];
-       bitset_t *dstmask = bs;
-       bitset_t *srcmask;
-       int err;
-       unsigned int channel;
-       for (channel = 0; channel < nchannels; channel++) {
-               if (client_channels[channel].enabled)
-                       bitset_set(dstmask, channel);
-               else
-                       bitset_reset(dstmask, channel);
-       }
-       while (plugin) {
-               err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
-               if (err < 0)
-                       return err;
-               dstmask = srcmask;
-               plugin = plugin->prev;
-       }
-       plugin = snd_pcm_plug_first(plug);
-       nchannels = plugin->src_format.channels;
-       for (channel = 0; channel < nchannels; channel++) {
-               if (!bitset_get(dstmask, channel))
-                       src_channels[channel].enabled = 0;
-       }
-       return 0;
-}
-
-snd_pcm_sframes_t snd_pcm_plug_write_transfer(snd_pcm_plug_t *plug, snd_pcm_plugin_channel_t *src_channels, snd_pcm_uframes_t size)
-{
-       snd_pcm_plugin_t *plugin, *next;
-       snd_pcm_plugin_channel_t *dst_channels;
+       struct snd_pcm_plugin *plugin, *next;
+       struct snd_pcm_plugin_channel *dst_channels;
        int err;
        snd_pcm_sframes_t frames = size;
 
-       if ((err = snd_pcm_plug_playback_disable_useless_channels(plug, src_channels)) < 0)
-               return err;
-       
        plugin = snd_pcm_plug_first(plug);
        while (plugin && frames > 0) {
                if ((next = plugin->next) != NULL) {
@@ -771,10 +598,10 @@ snd_pcm_sframes_t snd_pcm_plug_write_transfer(snd_pcm_plug_t *plug, snd_pcm_plug
        return snd_pcm_plug_client_size(plug, frames);
 }
 
-snd_pcm_sframes_t snd_pcm_plug_read_transfer(snd_pcm_plug_t *plug, snd_pcm_plugin_channel_t *dst_channels_final, snd_pcm_uframes_t size)
+snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *plug, struct snd_pcm_plugin_channel *dst_channels_final, snd_pcm_uframes_t size)
 {
-       snd_pcm_plugin_t *plugin, *next;
-       snd_pcm_plugin_channel_t *src_channels, *dst_channels;
+       struct snd_pcm_plugin *plugin, *next;
+       struct snd_pcm_plugin_channel *src_channels, *dst_channels;
        snd_pcm_sframes_t frames = size;
        int err;
 
@@ -790,10 +617,6 @@ snd_pcm_sframes_t snd_pcm_plug_read_transfer(snd_pcm_plug_t *plug, snd_pcm_plugi
                                return err;
                        }
                        frames = err;
-                       if (!plugin->prev) {
-                               if ((err = snd_pcm_plug_capture_disable_useless_channels(plug, dst_channels, dst_channels_final)) < 0)
-                                       return err;
-                       }
                } else {
                        dst_channels = dst_channels_final;
                }
@@ -806,7 +629,7 @@ snd_pcm_sframes_t snd_pcm_plug_read_transfer(snd_pcm_plug_t *plug, snd_pcm_plugi
        return frames;
 }
 
-int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, size_t dst_offset,
+int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_area, size_t dst_offset,
                         size_t samples, int format)
 {
        /* FIXME: sub byte resolution and odd dst_offset */
@@ -852,8 +675,8 @@ int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, size_t dst_offs
        return 0;
 }
 
-int snd_pcm_area_copy(const snd_pcm_channel_area_t *src_area, size_t src_offset,
-                     const snd_pcm_channel_area_t *dst_area, size_t dst_offset,
+int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_area, size_t src_offset,
+                     const struct snd_pcm_channel_area *dst_area, size_t dst_offset,
                      size_t samples, int format)
 {
        /* FIXME: sub byte resolution and odd dst_offset */