[pulseaudio-discuss] [PATCH 07/17] alsa: Move the port name and description logic

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Mon Dec 30 05:04:42 PST 2013


I think the new place makes more sense. Or if nothing else, at least
the parameter list of device_port_alsa_init() is now shorter.
---
 src/modules/alsa/alsa-mixer.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 316f546..5dc0d4f 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4480,18 +4480,30 @@ void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
 }
 
 static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
-    const char* name,
-    const char* description,
     pa_alsa_path *path,
     pa_alsa_setting *setting,
     pa_card_profile *cp,
     pa_hashmap *extra, /* sink/source ports */
     pa_core *core) {
 
+    char *name = NULL;
+    char *description = NULL;
     pa_device_port *p;
 
     pa_assert(path);
 
+    if (setting) {
+        name = pa_sprintf_malloc("%s;%s", path->name, setting->name);
+
+        if (setting->description[0])
+            description = pa_sprintf_malloc("%s / %s", path->description, setting->description);
+        else
+            description = pa_xstrdup(path->description);
+    } else {
+        name = pa_xstrdup(path->name);
+        description = pa_xstrdup(path->description);
+    }
+
     p = pa_hashmap_get(ports, name);
 
     if (!p) {
@@ -4509,7 +4521,7 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
 
         if (!p) {
             pa_log("Failed to create port %s.", name);
-            goto fail;
+            goto finish;
         }
 
         pa_hashmap_put(ports, p->name, p);
@@ -4530,10 +4542,11 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
         pa_device_port_ref(p);
     }
 
-    return p;
+finish:
+    pa_xfree(description);
+    pa_xfree(name);
 
-fail:
-    return NULL;
+    return p;
 }
 
 void pa_alsa_path_set_add_ports(
@@ -4555,8 +4568,7 @@ void pa_alsa_path_set_add_ports(
         if (!path->settings || !path->settings->next) {
             /* If there is no or just one setting we only need a
              * single entry */
-            pa_device_port *port = device_port_alsa_init(ports, path->name,
-                path->description, path, path->settings, cp, extra, core);
+            pa_device_port *port = device_port_alsa_init(ports, path, path->settings, cp, extra, core);
 
             if (!port)
                 continue;
@@ -4567,18 +4579,8 @@ void pa_alsa_path_set_add_ports(
             pa_alsa_setting *s;
             PA_LLIST_FOREACH(s, path->settings) {
                 pa_device_port *port;
-                char *n, *d;
 
-                n = pa_sprintf_malloc("%s;%s", path->name, s->name);
-
-                if (s->description[0])
-                    d = pa_sprintf_malloc("%s / %s", path->description, s->description);
-                else
-                    d = pa_xstrdup(path->description);
-
-                port = device_port_alsa_init(ports, n, d, path, s, cp, extra, core);
-                pa_xfree(n);
-                pa_xfree(d);
+                port = device_port_alsa_init(ports, path, s, cp, extra, core);
 
                 if (!port)
                     continue;
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list