diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-05-29 14:10:33 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-05-29 14:10:33 +0200 |
commit | bbf0d38ac59a825677e3abb93e5029da7ebad8e3 (patch) | |
tree | cf9166c7ee82714a99a51ea2d7c0cb7f18300380 | |
parent | 988d93abfe4438aad1a8db907fa8b12e740089f3 (diff) | |
download | hda-emu-bbf0d38ac59a825677e3abb93e5029da7ebad8e3.tar.gz |
Add jack string uniqueness check
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | ctljack.c | 45 | ||||
-rw-r--r-- | include/sound/control.h | 5 | ||||
-rw-r--r-- | snd-wrapper.c | 2 |
3 files changed, 50 insertions, 2 deletions
@@ -30,15 +30,58 @@ static struct snd_kcontrol_new jack_detect_kctl = { .get = jack_detect_kctl_get, }; +#ifdef NEW_JACK_API +static int get_available_index(struct snd_card *card, const char *name) +{ + struct snd_ctl_elem_id sid; + + memset(&sid, 0, sizeof(sid)); + + sid.index = 0; + sid.iface = SNDRV_CTL_ELEM_IFACE_CARD; + strlcpy(sid.name, name, sizeof(sid.name)); + + while (snd_ctl_find_id(card, &sid)) + sid.index++; + + return sid.index; +} + +static void jack_kctl_name_gen(char *name, const char *src_name, int size) +{ + size_t count = strlen(src_name); + bool need_cat = true; + + /* remove redundant " Jack" from src_name */ + if (count >= 5) + need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false; + + snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name); + +} +#endif + +#ifdef NEW_JACK_API +struct snd_kcontrol * +snd_kctl_jack_new(const char *name, struct snd_card *card) +#else struct snd_kcontrol * snd_kctl_jack_new(const char *name, int idx, void *private_data) +#endif { struct snd_kcontrol *kctl; +#ifdef NEW_JACK_API + kctl = snd_ctl_new1(&jack_detect_kctl, NULL); + if (!kctl) + return NULL; + jack_kctl_name_gen(kctl->id.name, name, sizeof(kctl->id.name)); + kctl->id.index = get_available_index(card, kctl->id.name); +#else kctl = snd_ctl_new1(&jack_detect_kctl, private_data); if (!kctl) return NULL; - snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name); kctl->id.index = idx; +#endif kctl->private_value = 0; return kctl; } diff --git a/include/sound/control.h b/include/sound/control.h index eaaada4..e3318b9 100644 --- a/include/sound/control.h +++ b/include/sound/control.h @@ -168,8 +168,13 @@ void snd_ctl_sync_vmaster(struct snd_kcontrol *kctl, bool hook_only); /* * Helper functions for jack-detection controls */ +#ifdef NEW_JACK_API +struct snd_kcontrol * +snd_kctl_jack_new(const char *name, struct snd_card *card); +#else struct snd_kcontrol * snd_kctl_jack_new(const char *name, int idx, void *private_data); +#endif void snd_kctl_jack_report(struct snd_card *card, struct snd_kcontrol *kctl, bool status); diff --git a/snd-wrapper.c b/snd-wrapper.c index ad1f9d9..c090a20 100644 --- a/snd-wrapper.c +++ b/snd-wrapper.c @@ -374,7 +374,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type, hda_log(HDA_LOG_INFO, "JACK created %s, type %d\n", id, type); *jack = jp; #ifdef NEW_JACK_API - jp->kctl = snd_kctl_jack_new(id, 0, NULL); + jp->kctl = snd_kctl_jack_new(id, card); snd_ctl_add(card, jp->kctl); #endif return 0; |