From e6bcc415fcdd599cd8c2f4e4c39f090e11b8d97b Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 2 Oct 2024 12:54:08 -0400 Subject: [PATCH] acp: Trim trailing whitespace in monitor name from HDMI ELD The ELD ends with a \n and spaces to pad the length, but most drivers except NVidia trim that out while presenting to userspace. While this is being tracked upstream [1], let's deal with this locally. [1] https://github.com/NVIDIA/open-gpu-kernel-modules/pull/715 Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4332 --- spa/plugins/alsa/acp/acp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index 8e8d5499d..240697f20 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -955,7 +955,7 @@ static int hdmi_eld_changed(snd_mixer_elem_t *melem, unsigned int mask) { pa_card *impl = snd_mixer_elem_get_callback_private(melem); snd_hctl_elem_t **_elem = snd_mixer_elem_get_private(melem), *elem; - int device; + int device, i; const char *old_monitor_name; pa_device_port *p; pa_hdmi_eld eld; @@ -977,6 +977,15 @@ static int hdmi_eld_changed(snd_mixer_elem_t *melem, unsigned int mask) if (pa_alsa_get_hdmi_eld(elem, &eld) < 0) memset(&eld, 0, sizeof(eld)); + // Strip trailing whitespace from monitor_name (primarily an NVidia driver bug for now) + for (i = strlen(eld.monitor_name) - 1; i >= 0; i--) { + if (eld.monitor_name[i] == '\n' || eld.monitor_name[i] == '\r' || eld.monitor_name[i] == '\t' || + eld.monitor_name[i] == ' ') + eld.monitor_name[i] = 0; + else + break; + } + old_monitor_name = pa_proplist_gets(p->proplist, PA_PROP_DEVICE_PRODUCT_NAME); if (eld.monitor_name[0] == '\0') { changed |= old_monitor_name != NULL;