alsa-mixer: Introduce "description-key" option for paths

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).
This commit is contained in:
Tanu Kaskinen 2012-06-29 18:04:57 +03:00 committed by Arun Raghavan
parent 66aeea7f72
commit 3c1ca6d4b8
20 changed files with 43 additions and 27 deletions

View file

@ -53,15 +53,18 @@
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();

View 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;

View file

@ -20,7 +20,7 @@
[General]
priority = 80
name = analog-input
description-key = analog-input
[Element Capture]
switch = mute

View 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

View file

@ -20,7 +20,7 @@
[General]
priority = 70
name = analog-input-radio
description-key = analog-input-radio
[Element Capture]
switch = mute

View 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

View file

@ -21,7 +21,7 @@
[General]
priority = 87
name = analog-input-microphone
description-key = analog-input-microphone
[Jack Headphone Mic]
required-any = any

View 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

View file

@ -21,7 +21,7 @@
[General]
priority = 89
name = analog-input-microphone-internal
description-key = analog-input-microphone-internal
[Jack Mic]
state.plugged = no

View file

@ -21,7 +21,7 @@
[General]
priority = 89
name = analog-input-microphone-internal
description-key = analog-input-microphone-internal
[Jack Mic]
state.plugged = no

View file

@ -20,7 +20,7 @@
[General]
priority = 85
name = analog-input
description-key = analog-input
[Element Capture]
switch = mute

View file

@ -20,7 +20,7 @@
[General]
priority = 87
name = analog-input-microphone
description-key = analog-input-microphone
[Jack Mic]
required-any = any

View 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

View file

@ -20,7 +20,7 @@
[General]
priority = 70
name = analog-input-video
description-key = analog-input-video
[Element Capture]
switch = mute

View file

@ -20,7 +20,7 @@
[General]
priority = 101
name = analog-output-speaker
description-key = analog-output-speaker
[Properties]
device.icon_name = audio-speakers

View file

@ -20,7 +20,7 @@
[General]
priority = 89
name = analog-output-headphones
description-key = analog-output-headphones
[Properties]
device.icon_name = audio-headphones

View file

@ -20,7 +20,7 @@
[General]
priority = 90
name = analog-output-headphones
description-key = analog-output-headphones
[Properties]
device.icon_name = audio-headphones

View file

@ -21,7 +21,7 @@
[General]
priority = 100
name = analog-output-speaker
description-key = analog-output-speaker
[Properties]
device.icon_name = audio-speakers

View file

@ -20,7 +20,7 @@
[General]
priority = 100
name = analog-output-speaker
description-key = analog-output-speaker
[Properties]
device.icon_name = audio-speakers

View file

@ -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.
; 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.