From fa7fe111cbb586f0b4772f27d2b6b3188bb90290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 26 Nov 2023 21:19:10 +0300 Subject: [PATCH 1/2] alsa: Allow to augment ucm port properties Since UCM doesn't perform the path lookups of alsa-mixer all UCM devices fall back to the card's properties for e.g. icons and hence usually show the `audio-card` icon for all ports giving a confusing UI to users as all ports show the same icon. As ucm names are pretty standard augment some common port names with icons. Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/88bb0bd7ccab9bf6c1183e4231d541f72fe1bdbb --- src/modules/alsa/alsa-ucm.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c index 018c01739..1cf54ebe6 100644 --- a/src/modules/alsa/alsa-ucm.c +++ b/src/modules/alsa/alsa-ucm.c @@ -1208,6 +1208,40 @@ static unsigned devset_capture_priority(pa_idxset *devices, bool invert) { return (unsigned) priority; } +static void ucm_add_port_props( + pa_device_port *port, + bool is_sink) +{ + const char *icon; + + if (is_sink) { + switch (port->type) { + case PA_DEVICE_PORT_TYPE_HEADPHONES: + icon = "audio-headphones"; + break; + case PA_DEVICE_PORT_TYPE_HDMI: + icon = "video-display"; + break; + case PA_DEVICE_PORT_TYPE_SPEAKER: + default: + icon = "audio-speakers"; + break; + } + } else { + switch (port->type) { + case PA_DEVICE_PORT_TYPE_HEADSET: + icon = "audio-headset"; + break; + case PA_DEVICE_PORT_TYPE_MIC: + default: + icon = "audio-input-microphone"; + break; + } + } + + pa_proplist_sets(port->proplist, "device.icon_name", icon); +} + void pa_alsa_ucm_add_port( pa_hashmap *hash, pa_alsa_ucm_mapping_context *context, @@ -1261,6 +1295,7 @@ void pa_alsa_ucm_add_port( pa_hashmap_put(ports, port->name, port); pa_log_debug("Add port %s: %s", port->name, port->description); + ucm_add_port_props(port, is_sink); PA_HASHMAP_FOREACH_KV(verb_name, vol, is_sink ? dev->playback_volumes : dev->capture_volumes, state) { pa_alsa_path *path = pa_alsa_path_synthesize(vol->mixer_elem, From 2dcb4fd4028081c6ed10551ce1ba6ca0573fb134 Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Sun, 26 Nov 2023 23:32:06 +0300 Subject: [PATCH 2/2] alsa-ucm: Set icon names for mappings as well A previous commit adds icon properties for some common port names, so that GUIs can show a relevant icon to help disambiguate devices. However, these still do not show up in pavucontrol, because it shows icons based on mappings' properties. Add the relevant property to mappings as well. Signed-off-by: Alper Nebi Yasak --- src/modules/alsa/alsa-ucm.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c index 1cf54ebe6..3271bd32a 100644 --- a/src/modules/alsa/alsa-ucm.c +++ b/src/modules/alsa/alsa-ucm.c @@ -1208,14 +1208,14 @@ static unsigned devset_capture_priority(pa_idxset *devices, bool invert) { return (unsigned) priority; } -static void ucm_add_port_props( - pa_device_port *port, - bool is_sink) -{ +static void proplist_set_icon_name( + pa_proplist *proplist, + pa_device_port_type_t type, + bool is_sink) { const char *icon; if (is_sink) { - switch (port->type) { + switch (type) { case PA_DEVICE_PORT_TYPE_HEADPHONES: icon = "audio-headphones"; break; @@ -1228,7 +1228,7 @@ static void ucm_add_port_props( break; } } else { - switch (port->type) { + switch (type) { case PA_DEVICE_PORT_TYPE_HEADSET: icon = "audio-headset"; break; @@ -1239,7 +1239,14 @@ static void ucm_add_port_props( } } - pa_proplist_sets(port->proplist, "device.icon_name", icon); + pa_proplist_sets(proplist, PA_PROP_DEVICE_ICON_NAME, icon); +} + +static void ucm_add_port_props( + pa_device_port *port, + bool is_sink) +{ + proplist_set_icon_name(port->proplist, port->type, is_sink); } void pa_alsa_ucm_add_port( @@ -1690,6 +1697,8 @@ static void alsa_mapping_add_ucm_device(pa_alsa_mapping *m, pa_alsa_ucm_device * else device->capture_mapping = m; + proplist_set_icon_name(m->proplist, device->type, is_sink); + mdev = get_mixer_device(device, is_sink); if (mdev) pa_proplist_sets(m->proplist, "alsa.mixer_device", mdev);