From: Takashi Iwai Subject: Re: [RFC] ALSA: usb: supply channel maps even when wChannelConfig is unspecified Date: Mon, 04 Nov 2013 09:58:29 +0100 Message-ID: References: <1383320339-22666-1-git-send-email-david.henningsson@canonical.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id AEA85261A40 for ; Mon, 4 Nov 2013 09:58:29 +0100 (CET) In-Reply-To: <1383320339-22666-1-git-send-email-david.henningsson@canonical.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: David Henningsson Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Fri, 1 Nov 2013 16:38:59 +0100, David Henningsson wrote: > > 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. > In the case of USB-audio, I guess this is OK to fill the guessed chmaps, especially for the mono channel. So I can take this patch if you already tested on your device. > 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? The chmap is just an optional information, thus excluding the format due to the lack of chmap doesn't sound right. The lack of chmap means merely that the hardware doesn't give the chmap information, but the format itself must be available. So, in the case of PA, I'd expect it handles such a format as is of now, just guessing / using the pre-defined chmaps. thanks, Takashi > > Signed-off-by: David Henningsson > --- > sound/usb/stream.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/sound/usb/stream.c b/sound/usb/stream.c > index c4339f9..b43b6ee 100644 > --- a/sound/usb/stream.c > +++ b/sound/usb/stream.c > @@ -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++) > -- > 1.7.9.5 >