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
This commit is contained in:
Arun Raghavan 2024-10-02 12:54:08 -04:00 committed by Arun Raghavan
parent 3efa3483db
commit e6bcc415fc

View file

@ -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;