Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Terry Junge <linuxhid@cosmicgizmosystems.com>
Cc: Jiri Kosina <jikos@kernel.org>, Takashi Iwai <tiwai@suse.com>,
	Wade Wang <wade.wang@hp.com>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>,
	linux-input@vger.kernel.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH 2/2] ALSA: usb-audio: Add quirk for Plantronics headsets to fix control names
Date: Mon, 25 Nov 2024 10:25:38 +0100	[thread overview]
Message-ID: <87frnfzmul.wl-tiwai@suse.de> (raw)
In-Reply-To: <20241124203252.28701-3-linuxhid@cosmicgizmosystems.com>

On Sun, 24 Nov 2024 21:32:41 +0100,
Terry Junge wrote:
> 
> Many Poly/Plantronics headset families name the feature, input,
> and/or output units in a such a way to produce control names
> that are not recognized by user space. As such, the volume and
> mute events do not get routed to the headset's audio controls.
> 
> As an example from a product family:
> 
> The microphone mute control is named
> Headset Microphone Capture Switch
> and the headset volume control is named
> Headset Earphone Playback Volume
> 
> The quirk fixes these to become
> Headset Capture Switch
> Headset Playback Volume
> 
> Signed-off-by: Terry Junge <linuxhid@cosmicgizmosystems.com>

Thanks, this description looks much more understandable now.
Meanwhile...

> ---
>  sound/usb/mixer_quirks.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
> index 8bbf070b3676..20d63efd5498 100644
> --- a/sound/usb/mixer_quirks.c
> +++ b/sound/usb/mixer_quirks.c
> @@ -4215,6 +4215,37 @@ static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer,
>  	}
>  }
>  
> +static void snd_fix_plt_control_name(struct snd_kcontrol *kctl)
> +{
> +	static const char * const names_to_remove[] = {
> +		"Earphone",
> +		"Microphone",
> +		"Receive",
> +		"Transmit",
> +		NULL
> +	};
> +	const char * const *n2r;
> +	char *dst, *src;
> +	size_t len;
> +
> +	for (n2r = names_to_remove; *n2r; ++n2r) {
> +		dst = strstr(kctl->id.name, *n2r);
> +		if (dst) {
> +			src = dst + strlen(*n2r);
> +			len = strlen(src) + 1;
> +			if ((char *)kctl->id.name != dst && *(dst - 1) == ' ')
> +				--dst;
> +			memmove(dst, src, len);
> +		}
> +	}
> +	if (kctl->id.name[0] == ' ') {
> +		char rcat[sizeof(kctl->id.name)] = { "Headset" };
> +
> +		strlcat(rcat, kctl->id.name, sizeof(rcat));
> +		strscpy(kctl->id.name, rcat, sizeof(kctl->id.name));
> +	}
> +}

... the code itself isn't really trivial (due to the poor string
handling by nature of C language), so it's better to put some brief
comment what this function really does, too.


thanks,

Takashi

  reply	other threads:[~2024-11-25  9:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-24 20:32 [PATCH 0/2] Introduce Poly/Plantronics mute event support Terry Junge
2024-11-24 20:32 ` [PATCH 1/2] HID: hid-plantronics: Add mic mute mapping and generalize quirks Terry Junge
2024-11-24 20:32 ` [PATCH 2/2] ALSA: usb-audio: Add quirk for Plantronics headsets to fix control names Terry Junge
2024-11-25  9:25   ` Takashi Iwai [this message]
2024-12-02 22:36     ` Terry Junge
2024-11-25  1:38 ` [PATCH 0/2] Introduce Poly/Plantronics mute event support Wang, Wade
2024-11-25  8:55 ` Takashi Iwai
2024-12-02 22:35   ` Terry Junge
2024-12-03  7:32     ` Takashi Iwai
2024-12-04  5:23       ` Terry Junge
2024-12-04  5:38         ` Wang, Wade
2024-12-04  6:56         ` Takashi Iwai
2024-12-05 22:19           ` Terry Junge
2024-12-10 16:22             ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87frnfzmul.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linuxhid@cosmicgizmosystems.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=wade.wang@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox