alsa-mixer: Introduce "description-key" option for paths
authorTanu Kaskinen <tanuk@iki.fi>
Fri, 29 Jun 2012 15:04:57 +0000 (18:04 +0300)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 3 Jun 2013 19:08:39 +0000 (00:38 +0530)
Previously the path description was looked up based on the
path name only. Since there can be multiple paths that use
the same description, it had to be possible to have multiple
paths with the same name.

Having the same name with multiple paths makes identifying
the paths more complex than necessary, so the plan is to
make it impossible to have paths with the same name. This
patch prepares for that by retaining the possibility to
still have the same description with multiple paths. Instead
of the path name, the path description is looked up by using
the "path description key" if it is set (path name is still
used as a fallback lookup key).

20 files changed:
src/modules/alsa/alsa-mixer.c
src/modules/alsa/alsa-mixer.h
src/modules/alsa/mixer/paths/analog-input-aux.conf
src/modules/alsa/mixer/paths/analog-input-dock-mic.conf
src/modules/alsa/mixer/paths/analog-input-fm.conf
src/modules/alsa/mixer/paths/analog-input-front-mic.conf
src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf
src/modules/alsa/mixer/paths/analog-input-headset-mic.conf
src/modules/alsa/mixer/paths/analog-input-internal-mic-always.conf
src/modules/alsa/mixer/paths/analog-input-internal-mic.conf
src/modules/alsa/mixer/paths/analog-input-mic-line.conf
src/modules/alsa/mixer/paths/analog-input-mic.conf
src/modules/alsa/mixer/paths/analog-input-rear-mic.conf
src/modules/alsa/mixer/paths/analog-input-tvtuner.conf
src/modules/alsa/mixer/paths/analog-output-desktop-speaker.conf
src/modules/alsa/mixer/paths/analog-output-headphones-2.conf
src/modules/alsa/mixer/paths/analog-output-headphones.conf
src/modules/alsa/mixer/paths/analog-output-speaker-always.conf
src/modules/alsa/mixer/paths/analog-output-speaker.conf
src/modules/alsa/mixer/paths/analog-output.conf.common

index 21655d7..d41b584 100644 (file)
 static int setting_select(pa_alsa_setting *s, snd_mixer_t *m);
 
 struct description_map {
-    const char *name;
+    const char *key;
     const char *description;
 };
 
-static const char *lookup_description(const char *name, const struct description_map dm[], unsigned n) {
+static const char *lookup_description(const char *key, const struct description_map dm[], unsigned n) {
     unsigned i;
 
+    if (!key)
+        return NULL;
+
     for (i = 0; i < n; i++)
-        if (pa_streq(dm[i].name, name))
+        if (pa_streq(dm[i].key, key))
             return _(dm[i].description);
 
     return NULL;
@@ -2361,12 +2364,16 @@ static int path_verify(pa_alsa_path *p) {
             return -1;
 
     if (!p->description)
-        p->description = pa_xstrdup(lookup_description(p->name,
+        p->description = pa_xstrdup(lookup_description(p->description_key ? p->description_key : p->name,
                                                        well_known_descriptions,
                                                        PA_ELEMENTSOF(well_known_descriptions)));
 
-    if (!p->description)
+    if (!p->description) {
+        if (p->description_key)
+            pa_log_warn("Path %s: Unrecognized description key: %s", p->name, p->description_key);
+
         p->description = pa_xstrdup(p->name);
+    }
 
     return 0;
 }
@@ -2388,6 +2395,7 @@ pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa
     pa_config_item items[] = {
         /* [General] */
         { "priority",            pa_config_parse_unsigned,          NULL, "General" },
+        { "description-key",     pa_config_parse_string,            NULL, "General" },
         { "description",         pa_config_parse_string,            NULL, "General" },
         { "name",                pa_config_parse_string,            NULL, "General" },
         { "mute-during-activation", pa_config_parse_bool,           NULL, "General" },
@@ -2427,10 +2435,11 @@ pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa
     p->eld_device = -1;
 
     items[0].data = &p->priority;
-    items[1].data = &p->description;
-    items[2].data = &p->name;
-    items[3].data = &mute_during_activation;
-    items[4].data = &p->eld_device;
+    items[1].data = &p->description_key;
+    items[2].data = &p->description;
+    items[3].data = &p->name;
+    items[4].data = &mute_during_activation;
+    items[5].data = &p->eld_device;
 
     if (!paths_dir)
         paths_dir = get_default_paths_dir();
index b3f7455..3d50ebb 100644 (file)
@@ -180,6 +180,7 @@ struct pa_alsa_path {
     pa_device_port* port;
 
     char *name;
+    char *description_key;
     char *description;
     unsigned priority;
     int eld_device;
index e6aa064..a5a4baa 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 80
-name = analog-input
+description-key = analog-input
 
 [Element Capture]
 switch = mute
index f6ea94b..9334d45 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 78
-name = analog-input-microphone-dock
+description-key = analog-input-microphone-dock
 
 [Jack Dock Mic]
 required-any = any
index 7f150e3..dfadb00 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 70
-name = analog-input-radio
+description-key = analog-input-radio
 
 [Element Capture]
 switch = mute
index bb2e806..3fb5f5e 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 85
-name = analog-input-microphone-front
+description-key = analog-input-microphone-front
 
 [Jack Front Mic]
 required-any = any
index 9b9213a..688b8ac 100644 (file)
@@ -21,7 +21,7 @@
 
 [General]
 priority = 87
-name = analog-input-microphone
+description-key = analog-input-microphone
 
 [Jack Headphone Mic]
 required-any = any
index 9a9dc35..0a3d661 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 87
-name = analog-input-microphone-headset
+description-key = analog-input-microphone-headset
 
 [Jack Headset Mic]
 required-any = any
index 37f9b17..cd08531 100644 (file)
@@ -21,7 +21,7 @@
 
 [General]
 priority = 89
-name = analog-input-microphone-internal
+description-key = analog-input-microphone-internal
 
 [Jack Mic]
 state.plugged = no
index 4718dd0..ae3e9a8 100644 (file)
@@ -21,7 +21,7 @@
 
 [General]
 priority = 89
-name = analog-input-microphone-internal
+description-key = analog-input-microphone-internal
 
 [Jack Mic]
 state.plugged = no
index fb80838..13db33b 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 85
-name = analog-input
+description-key = analog-input
 
 [Element Capture]
 switch = mute
index 9e5f044..17f3988 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 87
-name = analog-input-microphone
+description-key = analog-input-microphone
 
 [Jack Mic]
 required-any = any
index 397efba..ac78b5b 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 82
-name = analog-input-microphone-rear
+description-key = analog-input-microphone-rear
 
 [Jack Rear Mic]
 required-any = any
index fae3ce8..446446a 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 70
-name = analog-input-video
+description-key = analog-input-video
 
 [Element Capture]
 switch = mute
index 099823e..2b68117 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 101
-name = analog-output-speaker
+description-key = analog-output-speaker
 
 [Properties]
 device.icon_name = audio-speakers
index 6161ff5..7568924 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 89
-name = analog-output-headphones
+description-key = analog-output-headphones
 
 [Properties]
 device.icon_name = audio-headphones
index 76cd01e..e682033 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 90
-name = analog-output-headphones
+description-key = analog-output-headphones
 
 [Properties]
 device.icon_name = audio-headphones
index 8a2b3df..c511813 100644 (file)
@@ -21,7 +21,7 @@
 
 [General]
 priority = 100
-name = analog-output-speaker
+description-key = analog-output-speaker
 
 [Properties]
 device.icon_name = audio-speakers
index 7b47fc2..8416a25 100644 (file)
@@ -20,7 +20,7 @@
 
 [General]
 priority = 100
-name = analog-output-speaker
+description-key = analog-output-speaker
 
 [Properties]
 device.icon_name = audio-speakers
index 73d09f8..727b776 100644 (file)
 
 ; [General]
 ; priority = ...                         # Priority for this path
-; description = ...
+; description-key = ...                  # The path description is looked up from a table in path_verify() in
+;                                        # src/modules/alsa/alsa-mixer.c. By default the path name (i.e. the file name
+;                                        # minus the ".conf" suffix) is used as the lookup key, but if this option is
+;                                        # set, then the given string is used as the key instead. In any case the
+;                                        # "description" option can be used to override the path description.
+; description = ...                      # Description for this path. Overrides the normal description lookup logic, as
+;                                        # described in the "description-key" documentation above.
 ; mute-during-activation = yes | no      # If this path supports hardware mute, should the hw mute be used while activating this
 ;                                        # path? In some cases this can reduce extra noises during port switching, while in other
 ;                                        # cases this can increase such noises. Default: no.