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). --- src/modules/alsa/alsa-mixer.c | 23 ++++++++++++++------ src/modules/alsa/alsa-mixer.h | 1 + src/modules/alsa/mixer/paths/analog-input-aux.conf | 2 +- .../alsa/mixer/paths/analog-input-dock-mic.conf | 2 +- src/modules/alsa/mixer/paths/analog-input-fm.conf | 2 +- .../alsa/mixer/paths/analog-input-front-mic.conf | 2 +- .../mixer/paths/analog-input-internal-mic.conf | 2 +- .../alsa/mixer/paths/analog-input-mic-line.conf | 2 +- src/modules/alsa/mixer/paths/analog-input-mic.conf | 2 +- .../alsa/mixer/paths/analog-input-rear-mic.conf | 2 +- .../alsa/mixer/paths/analog-input-tvtuner.conf | 2 +- .../mixer/paths/analog-output-desktop-speaker.conf | 2 +- .../mixer/paths/analog-output-headphones-2.conf | 2 +- .../alsa/mixer/paths/analog-output-headphones.conf | 2 +- .../alsa/mixer/paths/analog-output-speaker.conf | 2 +- .../alsa/mixer/paths/analog-output.conf.common | 8 ++++++- 16 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index ee59dea..21740c9 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -51,15 +51,18 @@ #include "alsa-util.h" 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; @@ -2331,12 +2334,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; } @@ -2357,6 +2364,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" }, @@ -2393,8 +2401,9 @@ pa_alsa_path* pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa p->direction = direction; items[0].data = &p->priority; - items[1].data = &p->description; - items[2].data = &p->name; + items[1].data = &p->description_key; + items[2].data = &p->description; + items[3].data = &p->name; if (!paths_dir) paths_dir = get_default_paths_dir(); diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h index 111dfaa..68f42cb 100644 --- a/src/modules/alsa/alsa-mixer.h +++ b/src/modules/alsa/alsa-mixer.h @@ -179,6 +179,7 @@ struct pa_alsa_path { pa_device_port* port; char *name; + char *description_key; char *description; unsigned priority; pa_proplist *proplist; diff --git a/src/modules/alsa/mixer/paths/analog-input-aux.conf b/src/modules/alsa/mixer/paths/analog-input-aux.conf index e6aa064..a5a4baa 100644 --- a/src/modules/alsa/mixer/paths/analog-input-aux.conf +++ b/src/modules/alsa/mixer/paths/analog-input-aux.conf @@ -20,7 +20,7 @@ [General] priority = 80 -name = analog-input +description-key = analog-input [Element Capture] switch = mute diff --git a/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf b/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf index 240b5f0..a4b9939 100644 --- a/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf +++ b/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf @@ -20,7 +20,7 @@ [General] priority = 78 -name = analog-input-microphone-dock +description-key = analog-input-microphone-dock [Jack Dock Mic] required-any = any diff --git a/src/modules/alsa/mixer/paths/analog-input-fm.conf b/src/modules/alsa/mixer/paths/analog-input-fm.conf index 7f150e3..dfadb00 100644 --- a/src/modules/alsa/mixer/paths/analog-input-fm.conf +++ b/src/modules/alsa/mixer/paths/analog-input-fm.conf @@ -20,7 +20,7 @@ [General] priority = 70 -name = analog-input-radio +description-key = analog-input-radio [Element Capture] switch = mute diff --git a/src/modules/alsa/mixer/paths/analog-input-front-mic.conf b/src/modules/alsa/mixer/paths/analog-input-front-mic.conf index 0b069f9..e90662a 100644 --- a/src/modules/alsa/mixer/paths/analog-input-front-mic.conf +++ b/src/modules/alsa/mixer/paths/analog-input-front-mic.conf @@ -20,7 +20,7 @@ [General] priority = 85 -name = analog-input-microphone-front +description-key = analog-input-microphone-front [Jack Front Mic] required-any = any diff --git a/src/modules/alsa/mixer/paths/analog-input-internal-mic.conf b/src/modules/alsa/mixer/paths/analog-input-internal-mic.conf index ba15f1c..95b1846 100644 --- a/src/modules/alsa/mixer/paths/analog-input-internal-mic.conf +++ b/src/modules/alsa/mixer/paths/analog-input-internal-mic.conf @@ -21,7 +21,7 @@ [General] priority = 89 -name = analog-input-microphone-internal +description-key = analog-input-microphone-internal [Jack Mic] state.plugged = no diff --git a/src/modules/alsa/mixer/paths/analog-input-mic-line.conf b/src/modules/alsa/mixer/paths/analog-input-mic-line.conf index fb80838..13db33b 100644 --- a/src/modules/alsa/mixer/paths/analog-input-mic-line.conf +++ b/src/modules/alsa/mixer/paths/analog-input-mic-line.conf @@ -20,7 +20,7 @@ [General] priority = 85 -name = analog-input +description-key = analog-input [Element Capture] switch = mute diff --git a/src/modules/alsa/mixer/paths/analog-input-mic.conf b/src/modules/alsa/mixer/paths/analog-input-mic.conf index 8aaf0cb..052f8ae 100644 --- a/src/modules/alsa/mixer/paths/analog-input-mic.conf +++ b/src/modules/alsa/mixer/paths/analog-input-mic.conf @@ -20,7 +20,7 @@ [General] priority = 87 -name = analog-input-microphone +description-key = analog-input-microphone [Jack Mic] required-any = any diff --git a/src/modules/alsa/mixer/paths/analog-input-rear-mic.conf b/src/modules/alsa/mixer/paths/analog-input-rear-mic.conf index 1e6fa57..9237cfd 100644 --- a/src/modules/alsa/mixer/paths/analog-input-rear-mic.conf +++ b/src/modules/alsa/mixer/paths/analog-input-rear-mic.conf @@ -20,7 +20,7 @@ [General] priority = 82 -name = analog-input-microphone-rear +description-key = analog-input-microphone-rear [Jack Rear Mic] required-any = any diff --git a/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf b/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf index fae3ce8..446446a 100644 --- a/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf +++ b/src/modules/alsa/mixer/paths/analog-input-tvtuner.conf @@ -20,7 +20,7 @@ [General] priority = 70 -name = analog-input-video +description-key = analog-input-video [Element Capture] switch = mute diff --git a/src/modules/alsa/mixer/paths/analog-output-desktop-speaker.conf b/src/modules/alsa/mixer/paths/analog-output-desktop-speaker.conf index dfdecf4..c914584 100644 --- a/src/modules/alsa/mixer/paths/analog-output-desktop-speaker.conf +++ b/src/modules/alsa/mixer/paths/analog-output-desktop-speaker.conf @@ -20,7 +20,7 @@ [General] priority = 101 -name = analog-output-speaker +description-key = analog-output-speaker [Element Hardware Master] switch = mute diff --git a/src/modules/alsa/mixer/paths/analog-output-headphones-2.conf b/src/modules/alsa/mixer/paths/analog-output-headphones-2.conf index 284713b..9c87db9 100644 --- a/src/modules/alsa/mixer/paths/analog-output-headphones-2.conf +++ b/src/modules/alsa/mixer/paths/analog-output-headphones-2.conf @@ -20,7 +20,7 @@ [General] priority = 89 -name = analog-output-headphones +description-key = analog-output-headphones [Element Hardware Master] switch = mute diff --git a/src/modules/alsa/mixer/paths/analog-output-headphones.conf b/src/modules/alsa/mixer/paths/analog-output-headphones.conf index 2860f28..39d7d81 100644 --- a/src/modules/alsa/mixer/paths/analog-output-headphones.conf +++ b/src/modules/alsa/mixer/paths/analog-output-headphones.conf @@ -20,7 +20,7 @@ [General] priority = 90 -name = analog-output-headphones +description-key = analog-output-headphones [Jack Headphone] required-any = any diff --git a/src/modules/alsa/mixer/paths/analog-output-speaker.conf b/src/modules/alsa/mixer/paths/analog-output-speaker.conf index 9c58ed9..3948c1e 100644 --- a/src/modules/alsa/mixer/paths/analog-output-speaker.conf +++ b/src/modules/alsa/mixer/paths/analog-output-speaker.conf @@ -20,7 +20,7 @@ [General] priority = 100 -name = analog-output-speaker +description-key = analog-output-speaker [Jack Headphone] state.plugged = no diff --git a/src/modules/alsa/mixer/paths/analog-output.conf.common b/src/modules/alsa/mixer/paths/analog-output.conf.common index d591686..e0351a1 100644 --- a/src/modules/alsa/mixer/paths/analog-output.conf.common +++ b/src/modules/alsa/mixer/paths/analog-output.conf.common @@ -55,7 +55,13 @@ ; [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. ; ; [Properties] # Property list for this path. The list is merged into the port property list. ; <key> = <value> # Each property is defined on its own line. -- 1.7.10