]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ALSA: usb: supply channel maps even when wChannelConfig is unspecified
authorDavid Henningsson <david.henningsson@canonical.com>
Tue, 5 Nov 2013 03:41:06 +0000 (04:41 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 5 Nov 2013 06:46:15 +0000 (07:46 +0100)
If wChannelconfig is given for some formats but not others, userspace
might not be able to set the channel map.

This is RFC because I'm not sure what the best behaviour is - to guess
the channel map from the given number of channels (it's quite likely
that one channel is MONO and two channels is FL FR), or just to supply
UNKNOWN for all channels.

But the complete lack of channel map for a format leads userspace to
believe that the format is not available at all. Or am I
misunderstanding how this should be used?

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/stream.c

index c4339f97226bddea9db02c578e6fb5774d1d5a0c..b43b6eec322729c19bf81aba1ad48e37997e30d6 100644 (file)
@@ -281,8 +281,6 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
        const unsigned int *maps;
        int c;
 
-       if (!bits)
-               return NULL;
        if (channels > ARRAY_SIZE(chmap->map))
                return NULL;
 
@@ -293,9 +291,19 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
        maps = protocol == UAC_VERSION_2 ? uac2_maps : uac1_maps;
        chmap->channels = channels;
        c = 0;
-       for (; bits && *maps; maps++, bits >>= 1) {
-               if (bits & 1)
-                       chmap->map[c++] = *maps;
+
+       if (bits) {
+               for (; bits && *maps; maps++, bits >>= 1)
+                       if (bits & 1)
+                               chmap->map[c++] = *maps;
+       } else {
+               /* If we're missing wChannelConfig, then guess something
+                   to make sure the channel map is not skipped entirely */
+               if (channels == 1)
+                       chmap->map[c++] = SNDRV_CHMAP_MONO;
+               else
+                       for (; c < channels && *maps; maps++)
+                               chmap->map[c++] = *maps;
        }
 
        for (; c < channels; c++)