[pulseaudio-discuss] [PATCH v2 5/6] ucm: Create only one jack object per kcontrol

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Mon May 4 11:03:44 PDT 2015


Previously the UCM code created one jack object per device name (which
is not the same thing as creating one jack object per device, because
the UCM device namespace is scoped on per-verb basis, so devices in
different verbs may have the same name). I think it's conceptually
cleaner to create one jack object per alsa kcontrol. I plan to do
similar refactoring on the traditional mixer code later.
---
 src/modules/alsa/alsa-mixer.c | 11 +++--------
 src/modules/alsa/alsa-mixer.h |  2 +-
 src/modules/alsa/alsa-ucm.c   | 34 +++++++++++++++++++++++-----------
 3 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 343c39a..6cad540 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -107,7 +107,7 @@ struct description_map {
     const char *description;
 };
 
-pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name, const char *alsa_name) {
+pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name) {
     pa_alsa_jack *jack;
 
     pa_assert(name);
@@ -115,12 +115,7 @@ pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name, const char
     jack = pa_xnew0(pa_alsa_jack, 1);
     jack->path = path;
     jack->name = pa_xstrdup(name);
-
-    if (alsa_name)
-        jack->alsa_name = pa_xstrdup(alsa_name);
-    else
-        jack->alsa_name = pa_sprintf_malloc("%s Jack", name);
-
+    jack->alsa_name = pa_sprintf_malloc("%s Jack", name);
     jack->state_unplugged = PA_AVAILABLE_NO;
     jack->state_plugged = PA_AVAILABLE_YES;
     jack->ucm_devices = pa_dynarray_new(NULL);
@@ -1857,7 +1852,7 @@ static pa_alsa_jack* jack_get(pa_alsa_path *p, const char *section) {
         if (pa_streq(j->name, section))
             goto finish;
 
-    j = pa_alsa_jack_new(p, section, NULL);
+    j = pa_alsa_jack_new(p, section);
     PA_LLIST_INSERT_AFTER(pa_alsa_jack, p->jacks, p->last_jack, j);
 
 finish:
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index e5258c1..96a7a5e 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -172,7 +172,7 @@ struct pa_alsa_jack {
     pa_dynarray *ucm_devices; /* pa_alsa_ucm_device */
 };
 
-pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name, const char *alsa_name);
+pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name);
 void pa_alsa_jack_free(pa_alsa_jack *jack);
 void pa_alsa_jack_set_has_control(pa_alsa_jack *jack, bool has_control);
 void pa_alsa_jack_set_plugged_in(pa_alsa_jack *jack, bool plugged_in);
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index fde2d0c..d2c7140 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -1292,27 +1292,39 @@ static pa_alsa_jack* ucm_get_jack(pa_alsa_ucm_config *ucm, pa_alsa_ucm_device *d
     pa_alsa_jack *j;
     const char *device_name;
     const char *jack_control;
-    char *alsa_name;
+    char *name;
 
     pa_assert(ucm);
     pa_assert(device);
 
     device_name = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_NAME);
 
-    PA_LLIST_FOREACH(j, ucm->jacks)
-        if (pa_streq(j->name, device_name))
-            return j;
-
     jack_control = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_JACK_CONTROL);
-    if (jack_control)
-        alsa_name = pa_xstrdup(jack_control);
-    else
-        alsa_name = pa_sprintf_malloc("%s Jack", device_name);
+    if (jack_control) {
+        if (!pa_endswith(jack_control, " Jack")) {
+            pa_log("[%s] Invalid JackControl value: \"%s\"", device_name, jack_control);
+            return NULL;
+        }
 
-    j = pa_alsa_jack_new(NULL, device_name, alsa_name);
-    pa_xfree(alsa_name);
+        /* pa_alsa_jack_new() expects a jack name without " Jack" at the
+         * end, so drop the trailing " Jack". */
+        name = pa_xstrndup(jack_control, strlen(jack_control) - 5);
+    } else {
+        /* The jack control hasn't been explicitly configured - try a jack name
+         * that is the same as the device name. */
+        name = pa_xstrdup(device_name);
+    }
+
+    PA_LLIST_FOREACH(j, ucm->jacks)
+        if (pa_streq(j->name, name))
+            goto finish;
+
+    j = pa_alsa_jack_new(NULL, name);
     PA_LLIST_PREPEND(pa_alsa_jack, ucm->jacks, j);
 
+finish:
+    pa_xfree(name);
+
     return j;
 }
 
-- 
1.9.3



More information about the pulseaudio-discuss mailing list