Commit 47eaebfd authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] Use standard bitmap functions

Modules: ALSA<-OSS emulation

Use standard bitmap functions instead of in-house ones.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 230b5c1a
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin, static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels, const snd_pcm_plugin_channel_t *src_channels,
snd_pcm_plugin_channel_t *dst_channels ATTRIBUTE_UNUSED, snd_pcm_plugin_channel_t *dst_channels,
snd_pcm_uframes_t frames) snd_pcm_uframes_t frames)
{ {
snd_assert(plugin != NULL, return -ENXIO); snd_assert(plugin != NULL, return -ENXIO);
...@@ -59,7 +59,7 @@ static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin, ...@@ -59,7 +59,7 @@ static snd_pcm_sframes_t io_playback_transfer(snd_pcm_plugin_t *plugin,
} }
static snd_pcm_sframes_t io_capture_transfer(snd_pcm_plugin_t *plugin, static snd_pcm_sframes_t io_capture_transfer(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels ATTRIBUTE_UNUSED, const snd_pcm_plugin_channel_t *src_channels,
snd_pcm_plugin_channel_t *dst_channels, snd_pcm_plugin_channel_t *dst_channels,
snd_pcm_uframes_t frames) snd_pcm_uframes_t frames)
{ {
......
...@@ -37,21 +37,21 @@ ...@@ -37,21 +37,21 @@
#define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last) #define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last)
static int snd_pcm_plugin_src_channels_mask(snd_pcm_plugin_t *plugin, static int snd_pcm_plugin_src_channels_mask(snd_pcm_plugin_t *plugin,
bitset_t *dst_vmask, unsigned long *dst_vmask,
bitset_t **src_vmask) unsigned long **src_vmask)
{ {
bitset_t *vmask = plugin->src_vmask; unsigned long *vmask = plugin->src_vmask;
bitset_copy(vmask, dst_vmask, plugin->src_format.channels); bitmap_copy(vmask, dst_vmask, plugin->src_format.channels);
*src_vmask = vmask; *src_vmask = vmask;
return 0; return 0;
} }
static int snd_pcm_plugin_dst_channels_mask(snd_pcm_plugin_t *plugin, static int snd_pcm_plugin_dst_channels_mask(snd_pcm_plugin_t *plugin,
bitset_t *src_vmask, unsigned long *src_vmask,
bitset_t **dst_vmask) unsigned long **dst_vmask)
{ {
bitset_t *vmask = plugin->dst_vmask; unsigned long *vmask = plugin->dst_vmask;
bitset_copy(vmask, src_vmask, plugin->dst_format.channels); bitmap_copy(vmask, src_vmask, plugin->dst_format.channels);
*dst_vmask = vmask; *dst_vmask = vmask;
return 0; return 0;
} }
...@@ -193,12 +193,12 @@ int snd_pcm_plugin_build(snd_pcm_plug_t *plug, ...@@ -193,12 +193,12 @@ int snd_pcm_plugin_build(snd_pcm_plug_t *plug,
snd_pcm_plugin_free(plugin); snd_pcm_plugin_free(plugin);
return -ENOMEM; return -ENOMEM;
} }
plugin->src_vmask = bitset_alloc(src_format->channels); plugin->src_vmask = bitmap_alloc(src_format->channels);
if (plugin->src_vmask == NULL) { if (plugin->src_vmask == NULL) {
snd_pcm_plugin_free(plugin); snd_pcm_plugin_free(plugin);
return -ENOMEM; return -ENOMEM;
} }
plugin->dst_vmask = bitset_alloc(dst_format->channels); plugin->dst_vmask = bitmap_alloc(dst_format->channels);
if (plugin->dst_vmask == NULL) { if (plugin->dst_vmask == NULL) {
snd_pcm_plugin_free(plugin); snd_pcm_plugin_free(plugin);
return -ENOMEM; return -ENOMEM;
...@@ -651,18 +651,18 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *plug, ...@@ -651,18 +651,18 @@ snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(snd_pcm_plug_t *plug,
} }
static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug, static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug,
bitset_t *client_vmask) unsigned long *client_vmask)
{ {
snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug); snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
if (plugin == NULL) { if (plugin == NULL) {
return 0; return 0;
} else { } else {
int schannels = plugin->dst_format.channels; int schannels = plugin->dst_format.channels;
bitset_t bs[bitset_size(schannels)]; DECLARE_BITMAP(bs, schannels);
bitset_t *srcmask; unsigned long *srcmask;
bitset_t *dstmask = bs; unsigned long *dstmask = bs;
int err; int err;
bitset_one(dstmask, schannels); bitmap_fill(dstmask, schannels);
while (1) { while (1) {
err = plugin->src_channels_mask(plugin, dstmask, &srcmask); err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
...@@ -673,7 +673,7 @@ static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug, ...@@ -673,7 +673,7 @@ static int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug,
break; break;
plugin = plugin->prev; plugin = plugin->prev;
} }
bitset_and(client_vmask, dstmask, plugin->src_format.channels); bitmap_and(client_vmask, client_vmask, dstmask, plugin->src_format.channels);
return 0; return 0;
} }
} }
...@@ -683,21 +683,21 @@ static int snd_pcm_plug_playback_disable_useless_channels(snd_pcm_plug_t *plug, ...@@ -683,21 +683,21 @@ static int snd_pcm_plug_playback_disable_useless_channels(snd_pcm_plug_t *plug,
{ {
snd_pcm_plugin_t *plugin = snd_pcm_plug_first(plug); snd_pcm_plugin_t *plugin = snd_pcm_plug_first(plug);
unsigned int nchannels = plugin->src_format.channels; unsigned int nchannels = plugin->src_format.channels;
bitset_t bs[bitset_size(nchannels)]; DECLARE_BITMAP(bs, nchannels);
bitset_t *srcmask = bs; unsigned long *srcmask = bs;
int err; int err;
unsigned int channel; unsigned int channel;
for (channel = 0; channel < nchannels; channel++) { for (channel = 0; channel < nchannels; channel++) {
if (src_channels[channel].enabled) if (src_channels[channel].enabled)
bitset_set(srcmask, channel); set_bit(channel, srcmask);
else else
bitset_reset(srcmask, channel); clear_bit(channel, srcmask);
} }
err = snd_pcm_plug_playback_channels_mask(plug, srcmask); err = snd_pcm_plug_playback_channels_mask(plug, srcmask);
if (err < 0) if (err < 0)
return err; return err;
for (channel = 0; channel < nchannels; channel++) { for (channel = 0; channel < nchannels; channel++) {
if (!bitset_get(srcmask, channel)) if (!test_bit(channel, srcmask))
src_channels[channel].enabled = 0; src_channels[channel].enabled = 0;
} }
return 0; return 0;
...@@ -709,16 +709,16 @@ static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug, ...@@ -709,16 +709,16 @@ static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug,
{ {
snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug); snd_pcm_plugin_t *plugin = snd_pcm_plug_last(plug);
unsigned int nchannels = plugin->dst_format.channels; unsigned int nchannels = plugin->dst_format.channels;
bitset_t bs[bitset_size(nchannels)]; DECLARE_BITMAP(bs, nchannels);
bitset_t *dstmask = bs; unsigned long *dstmask = bs;
bitset_t *srcmask; unsigned long *srcmask;
int err; int err;
unsigned int channel; unsigned int channel;
for (channel = 0; channel < nchannels; channel++) { for (channel = 0; channel < nchannels; channel++) {
if (client_channels[channel].enabled) if (client_channels[channel].enabled)
bitset_set(dstmask, channel); set_bit(channel, dstmask);
else else
bitset_reset(dstmask, channel); clear_bit(channel, dstmask);
} }
while (plugin) { while (plugin) {
err = plugin->src_channels_mask(plugin, dstmask, &srcmask); err = plugin->src_channels_mask(plugin, dstmask, &srcmask);
...@@ -730,7 +730,7 @@ static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug, ...@@ -730,7 +730,7 @@ static int snd_pcm_plug_capture_disable_useless_channels(snd_pcm_plug_t *plug,
plugin = snd_pcm_plug_first(plug); plugin = snd_pcm_plug_first(plug);
nchannels = plugin->src_format.channels; nchannels = plugin->src_format.channels;
for (channel = 0; channel < nchannels; channel++) { for (channel = 0; channel < nchannels; channel++) {
if (!bitset_get(dstmask, channel)) if (!test_bit(channel, dstmask))
src_channels[channel].enabled = 0; src_channels[channel].enabled = 0;
} }
return 0; return 0;
......
...@@ -22,71 +22,11 @@ ...@@ -22,71 +22,11 @@
* *
*/ */
#ifndef ATTRIBUTE_UNUSED #include <linux/bitmap.h>
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
typedef unsigned int bitset_t;
static inline size_t bitset_size(int nbits)
{
return (nbits + sizeof(bitset_t) * 8 - 1) / (sizeof(bitset_t) * 8);
}
static inline bitset_t *bitset_alloc(int nbits)
{
return kcalloc(bitset_size(nbits), sizeof(bitset_t), GFP_KERNEL);
}
static inline void bitset_set(bitset_t *bitmap, unsigned int pos)
{
size_t bits = sizeof(*bitmap) * 8;
bitmap[pos / bits] |= 1 << (pos % bits);
}
static inline void bitset_reset(bitset_t *bitmap, unsigned int pos)
{
size_t bits = sizeof(*bitmap) * 8;
bitmap[pos / bits] &= ~(1 << (pos % bits));
}
static inline int bitset_get(bitset_t *bitmap, unsigned int pos)
{
size_t bits = sizeof(*bitmap) * 8;
return !!(bitmap[pos / bits] & (1 << (pos % bits)));
}
static inline void bitset_copy(bitset_t *dst, bitset_t *src, unsigned int nbits)
{
memcpy(dst, src, bitset_size(nbits) * sizeof(bitset_t));
}
static inline void bitset_and(bitset_t *dst, bitset_t *bs, unsigned int nbits)
{
bitset_t *end = dst + bitset_size(nbits);
while (dst < end)
*dst++ &= *bs++;
}
static inline void bitset_or(bitset_t *dst, bitset_t *bs, unsigned int nbits)
{
bitset_t *end = dst + bitset_size(nbits);
while (dst < end)
*dst++ |= *bs++;
}
static inline void bitset_zero(bitset_t *dst, unsigned int nbits)
{
bitset_t *end = dst + bitset_size(nbits);
while (dst < end)
*dst++ = 0;
}
static inline void bitset_one(bitset_t *dst, unsigned int nbits) static inline unsigned long *bitmap_alloc(unsigned int nbits)
{ {
bitset_t *end = dst + bitset_size(nbits); return kmalloc(BITS_TO_LONGS(nbits), GFP_KERNEL);
while (dst < end)
*dst++ = ~(bitset_t)0;
} }
#define snd_pcm_plug_t snd_pcm_substream_t #define snd_pcm_plug_t snd_pcm_substream_t
...@@ -131,11 +71,11 @@ struct _snd_pcm_plugin { ...@@ -131,11 +71,11 @@ struct _snd_pcm_plugin {
snd_pcm_uframes_t frames, snd_pcm_uframes_t frames,
snd_pcm_plugin_channel_t **channels); snd_pcm_plugin_channel_t **channels);
int (*src_channels_mask)(snd_pcm_plugin_t *plugin, int (*src_channels_mask)(snd_pcm_plugin_t *plugin,
bitset_t *dst_vmask, unsigned long *dst_vmask,
bitset_t **src_vmask); unsigned long **src_vmask);
int (*dst_channels_mask)(snd_pcm_plugin_t *plugin, int (*dst_channels_mask)(snd_pcm_plugin_t *plugin,
bitset_t *src_vmask, unsigned long *src_vmask,
bitset_t **dst_vmask); unsigned long **dst_vmask);
snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin, snd_pcm_sframes_t (*transfer)(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels, const snd_pcm_plugin_channel_t *src_channels,
snd_pcm_plugin_channel_t *dst_channels, snd_pcm_plugin_channel_t *dst_channels,
...@@ -151,8 +91,8 @@ struct _snd_pcm_plugin { ...@@ -151,8 +91,8 @@ struct _snd_pcm_plugin {
char *buf; char *buf;
snd_pcm_uframes_t buf_frames; snd_pcm_uframes_t buf_frames;
snd_pcm_plugin_channel_t *buf_channels; snd_pcm_plugin_channel_t *buf_channels;
bitset_t *src_vmask; unsigned long *src_vmask;
bitset_t *dst_vmask; unsigned long *dst_vmask;
char extra_data[0]; char extra_data[0];
}; };
......
...@@ -315,7 +315,7 @@ static snd_pcm_sframes_t rate_transfer(snd_pcm_plugin_t *plugin, ...@@ -315,7 +315,7 @@ static snd_pcm_sframes_t rate_transfer(snd_pcm_plugin_t *plugin,
static int rate_action(snd_pcm_plugin_t *plugin, static int rate_action(snd_pcm_plugin_t *plugin,
snd_pcm_plugin_action_t action, snd_pcm_plugin_action_t action,
unsigned long udata ATTRIBUTE_UNUSED) unsigned long udata)
{ {
snd_assert(plugin != NULL, return -ENXIO); snd_assert(plugin != NULL, return -ENXIO);
switch (action) { switch (action) {
......
...@@ -70,9 +70,9 @@ typedef union { ...@@ -70,9 +70,9 @@ typedef union {
static void route_to_channel_from_zero(snd_pcm_plugin_t *plugin, static void route_to_channel_from_zero(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels ATTRIBUTE_UNUSED, const snd_pcm_plugin_channel_t *src_channels,
snd_pcm_plugin_channel_t *dst_channel, snd_pcm_plugin_channel_t *dst_channel,
ttable_dst_t* ttable ATTRIBUTE_UNUSED, snd_pcm_uframes_t frames) ttable_dst_t* ttable, snd_pcm_uframes_t frames)
{ {
if (dst_channel->wanted) if (dst_channel->wanted)
snd_pcm_area_silence(&dst_channel->area, 0, frames, plugin->dst_format.format); snd_pcm_area_silence(&dst_channel->area, 0, frames, plugin->dst_format.format);
...@@ -298,46 +298,46 @@ static void route_to_channel(snd_pcm_plugin_t *plugin, ...@@ -298,46 +298,46 @@ static void route_to_channel(snd_pcm_plugin_t *plugin,
} }
static int route_src_channels_mask(snd_pcm_plugin_t *plugin, static int route_src_channels_mask(snd_pcm_plugin_t *plugin,
bitset_t *dst_vmask, unsigned long *dst_vmask,
bitset_t **src_vmask) unsigned long **src_vmask)
{ {
route_t *data = (route_t *)plugin->extra_data; route_t *data = (route_t *)plugin->extra_data;
int schannels = plugin->src_format.channels; int schannels = plugin->src_format.channels;
int dchannels = plugin->dst_format.channels; int dchannels = plugin->dst_format.channels;
bitset_t *vmask = plugin->src_vmask; unsigned long *vmask = plugin->src_vmask;
int channel; int channel;
ttable_dst_t *dp = data->ttable; ttable_dst_t *dp = data->ttable;
bitset_zero(vmask, schannels); bitmap_zero(vmask, schannels);
for (channel = 0; channel < dchannels; channel++, dp++) { for (channel = 0; channel < dchannels; channel++, dp++) {
unsigned int src; unsigned int src;
ttable_src_t *sp; ttable_src_t *sp;
if (!bitset_get(dst_vmask, channel)) if (!test_bit(channel, dst_vmask))
continue; continue;
sp = dp->srcs; sp = dp->srcs;
for (src = 0; src < dp->nsrcs; src++, sp++) for (src = 0; src < dp->nsrcs; src++, sp++)
bitset_set(vmask, sp->channel); set_bit(sp->channel, vmask);
} }
*src_vmask = vmask; *src_vmask = vmask;
return 0; return 0;
} }
static int route_dst_channels_mask(snd_pcm_plugin_t *plugin, static int route_dst_channels_mask(snd_pcm_plugin_t *plugin,
bitset_t *src_vmask, unsigned long *src_vmask,
bitset_t **dst_vmask) unsigned long **dst_vmask)
{ {
route_t *data = (route_t *)plugin->extra_data; route_t *data = (route_t *)plugin->extra_data;
int dchannels = plugin->dst_format.channels; int dchannels = plugin->dst_format.channels;
bitset_t *vmask = plugin->dst_vmask; unsigned long *vmask = plugin->dst_vmask;
int channel; int channel;
ttable_dst_t *dp = data->ttable; ttable_dst_t *dp = data->ttable;
bitset_zero(vmask, dchannels); bitmap_zero(vmask, dchannels);
for (channel = 0; channel < dchannels; channel++, dp++) { for (channel = 0; channel < dchannels; channel++, dp++) {
unsigned int src; unsigned int src;
ttable_src_t *sp; ttable_src_t *sp;
sp = dp->srcs; sp = dp->srcs;
for (src = 0; src < dp->nsrcs; src++, sp++) { for (src = 0; src < dp->nsrcs; src++, sp++) {
if (bitset_get(src_vmask, sp->channel)) { if (test_bit(sp->channel, src_vmask)) {
bitset_set(vmask, channel); set_bit(channel, vmask);
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment