Skip to content

Commit 1601cd5

Browse files
kennylevinsentiwai
authored andcommitted
ALSA: usb-audio: Name feature ctl using output if input is PCM
When building feature controls from a unit without a name, we try to derive a name first from the feature unit's input, then fall back to the output terminal. If a feature unit connects directly to a "USB Streaming" input terminal rather than a mixer or other virtual type, the control receives the somewhat meaningless name "PCM", even if the output had a descriptive type such as "Headset" or "Speaker". Here is an example of such AudioControl descriptor from a USB headset which ends up named "PCM Playback" and is therefore not recognized as headphones by userspace: AudioControl Interface Descriptor: bLength 12 bDescriptorType 36 bDescriptorSubtype 2 (INPUT_TERMINAL) bTerminalID 4 wTerminalType 0x0101 USB Streaming bAssocTerminal 5 bNrChannels 2 wChannelConfig 0x0003 Left Front (L) Right Front (R) iChannelNames 0 iTerminal 0 AudioControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 3 (OUTPUT_TERMINAL) bTerminalID 5 wTerminalType 0x0402 Headset bAssocTerminal 4 bSourceID 6 iTerminal 0 AudioControl Interface Descriptor: bLength 13 bDescriptorType 36 bDescriptorSubtype 6 (FEATURE_UNIT) bUnitID 6 bSourceID 4 bControlSize 2 bmaControls(0) 0x0002 Volume Control bmaControls(1) 0x0000 bmaControls(2) 0x0000 iFeature 0 Other headsets and DACs I tried that used their output terminal for naming only did so due to their input being an unnamed sidetone mixer. Instead of always starting with the input terminal, check the type of it first. If it seems uninteresting, invert the order and use the output terminal first for naming. This makes userspace recognize headsets with simple controls as headphones, and leads to more consistent naming of playback devices based on their outputs irrespective of sidetone mixers. Signed-off-by: Kenny Levinsen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 72165c8 commit 1601cd5

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

sound/usb/mixer.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,34 @@ static const struct usb_feature_control_info *get_feature_control_info(int contr
16521652
return NULL;
16531653
}
16541654

1655+
static int feature_unit_mutevol_ctl_name(struct usb_mixer_interface *mixer,
1656+
struct snd_kcontrol *kctl,
1657+
struct usb_audio_term *iterm,
1658+
struct usb_audio_term *oterm)
1659+
{
1660+
struct usb_audio_term *aterm, *bterm;
1661+
bool output_first;
1662+
int len = 0;
1663+
1664+
/*
1665+
* If the input terminal is USB Streaming, we try getting the name of
1666+
* the output terminal first in hopes of getting something more
1667+
* descriptive than "PCM".
1668+
*/
1669+
output_first = iterm && !(iterm->type >> 16) && (iterm->type & 0xff00) == 0x0100;
1670+
1671+
aterm = output_first ? oterm : iterm;
1672+
bterm = output_first ? iterm : oterm;
1673+
1674+
if (aterm)
1675+
len = get_term_name(mixer->chip, aterm, kctl->id.name,
1676+
sizeof(kctl->id.name), 1);
1677+
if (!len && bterm)
1678+
len = get_term_name(mixer->chip, bterm, kctl->id.name,
1679+
sizeof(kctl->id.name), 1);
1680+
return len;
1681+
}
1682+
16551683
static void __build_feature_ctl(struct usb_mixer_interface *mixer,
16561684
const struct usbmix_name_map *imap,
16571685
unsigned int ctl_mask, int control,
@@ -1733,22 +1761,15 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
17331761
case UAC_FU_MUTE:
17341762
case UAC_FU_VOLUME:
17351763
/*
1736-
* determine the control name. the rule is:
1737-
* - if a name id is given in descriptor, use it.
1738-
* - if the connected input can be determined, then use the name
1739-
* of terminal type.
1740-
* - if the connected output can be determined, use it.
1741-
* - otherwise, anonymous name.
1764+
* Determine the control name:
1765+
* - If a name id is given in descriptor, use it.
1766+
* - If input and output terminals are present, try to derive
1767+
* the name from either of these.
1768+
* - Otherwise, make up a name using the feature unit ID.
17421769
*/
17431770
if (!len) {
1744-
if (iterm)
1745-
len = get_term_name(mixer->chip, iterm,
1746-
kctl->id.name,
1747-
sizeof(kctl->id.name), 1);
1748-
if (!len && oterm)
1749-
len = get_term_name(mixer->chip, oterm,
1750-
kctl->id.name,
1751-
sizeof(kctl->id.name), 1);
1771+
len = feature_unit_mutevol_ctl_name(mixer, kctl, iterm,
1772+
oterm);
17521773
if (!len)
17531774
snprintf(kctl->id.name, sizeof(kctl->id.name),
17541775
"Feature %d", unitid);

0 commit comments

Comments
 (0)