From d6f6c3d6770044e89f9f19221141072d3e3f0400 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Wed, 26 Jun 2019 12:51:22 +0300
Subject: [PATCH] softdsp-endpoint: give a proper name to the endpoint based on
 alsa properties

---
 modules/module-pw-alsa-udev.c              |  6 +-----
 modules/module-pw-audio-softdsp-endpoint.c | 14 +++++++++++---
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/modules/module-pw-alsa-udev.c b/modules/module-pw-alsa-udev.c
index 576e1e2c..4aaab88c 100644
--- a/modules/module-pw-alsa-udev.c
+++ b/modules/module-pw-alsa-udev.c
@@ -47,7 +47,7 @@ on_node_added(WpRemotePipewire *rp, guint id, guint parent_id, gconstpointer p,
   struct impl *impl = d;
   const struct spa_dict *props = p;
   g_autoptr (WpCore) core = wp_module_get_core (impl->module);
-  const gchar *name, *media_class;
+  const gchar *media_class;
   GVariantBuilder b;
   g_autoptr (GVariant) endpoint_props = NULL;
 
@@ -55,7 +55,6 @@ on_node_added(WpRemotePipewire *rp, guint id, guint parent_id, gconstpointer p,
   g_return_if_fail(props);
 
   /* Get the name and media_class */
-  name = spa_dict_lookup(props, "node.name");
   media_class = spa_dict_lookup(props, "media.class");
 
   /* Make sure the media class is non-dsp audio */
@@ -66,9 +65,6 @@ on_node_added(WpRemotePipewire *rp, guint id, guint parent_id, gconstpointer p,
 
   /* Set the properties */
   g_variant_builder_init (&b, G_VARIANT_TYPE_VARDICT);
-  g_variant_builder_add (&b, "{sv}",
-      "name", g_variant_new_take_string (g_strdup_printf (
-          "Endpoint %u: %s", id, name)));
   g_variant_builder_add (&b, "{sv}",
       "media-class", g_variant_new_string (media_class));
   g_variant_builder_add (&b, "{sv}",
diff --git a/modules/module-pw-audio-softdsp-endpoint.c b/modules/module-pw-audio-softdsp-endpoint.c
index d7da449d..cba819ad 100644
--- a/modules/module-pw-audio-softdsp-endpoint.c
+++ b/modules/module-pw-audio-softdsp-endpoint.c
@@ -352,11 +352,22 @@ on_proxy_node_created(GObject *initable, GAsyncResult *res, gpointer data)
 {
   WpPwAudioSoftdspEndpoint *self = data;
   GVariantDict d;
+  g_autofree gchar *name;
+  const struct spa_dict *props;
 
   /* Get the proxy node */
   self->proxy_node = wp_proxy_node_new_finish(initable, res, NULL);
   g_return_if_fail (self->proxy_node);
 
+  /* Give a proper name to this endpoint based on ALSA properties */
+  props = wp_proxy_node_get_info (self->proxy_node)->props;
+  name = g_strdup_printf ("%s on %s (%s / node %d)",
+      spa_dict_lookup (props, "alsa.pcm.name"),
+      spa_dict_lookup (props, "alsa.card.name"),
+      spa_dict_lookup (props, "alsa.device"),
+      wp_proxy_node_get_info (self->proxy_node)->id);
+  g_object_set (self, "name", name, NULL);
+
   /* Emit the audio DSP node */
   emit_audio_dsp_node(self);
 
@@ -705,8 +716,6 @@ endpoint_factory (WpFactory * factory, GType type, GVariant * properties,
   g_return_if_fail (core);
 
   /* Get the properties */
-  if (!g_variant_lookup (properties, "name", "&s", &name))
-      return;
   if (!g_variant_lookup (properties, "media-class", "&s", &media_class))
       return;
   if (!g_variant_lookup (properties, "global-id", "u", &global_id))
@@ -716,7 +725,6 @@ endpoint_factory (WpFactory * factory, GType type, GVariant * properties,
   g_async_initable_new_async (
       endpoint_get_type (), G_PRIORITY_DEFAULT, NULL, ready, user_data,
       "core", core,
-      "name", name,
       "media-class", media_class,
       "global-id", global_id,
       NULL);
-- 
GitLab