mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
alsa-mixer: do the quick card number lookup to save mixer instances
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
3ceff8bb3f
commit
8837c90b7f
2 changed files with 34 additions and 0 deletions
|
|
@ -102,6 +102,7 @@ struct pa_alsa_setting {
|
||||||
/* An entry for one ALSA mixer */
|
/* An entry for one ALSA mixer */
|
||||||
struct pa_alsa_mixer {
|
struct pa_alsa_mixer {
|
||||||
snd_mixer_t *mixer_handle;
|
snd_mixer_t *mixer_handle;
|
||||||
|
int card_index;
|
||||||
pa_alsa_fdlist *fdl;
|
pa_alsa_fdlist *fdl;
|
||||||
bool used_for_probe_only:1;
|
bool used_for_probe_only:1;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1737,11 +1737,33 @@ snd_mixer_t *pa_alsa_open_mixer_by_name(pa_hashmap *mixers, const char *dev, boo
|
||||||
int err;
|
int err;
|
||||||
snd_mixer_t *m;
|
snd_mixer_t *m;
|
||||||
pa_alsa_mixer *pm;
|
pa_alsa_mixer *pm;
|
||||||
|
char *dev2;
|
||||||
|
void *state;
|
||||||
|
|
||||||
pa_assert(mixers);
|
pa_assert(mixers);
|
||||||
pa_assert(dev);
|
pa_assert(dev);
|
||||||
|
|
||||||
pm = pa_hashmap_get(mixers, dev);
|
pm = pa_hashmap_get(mixers, dev);
|
||||||
|
|
||||||
|
/* The quick card number/index lookup (hw:#)
|
||||||
|
* We already know the card number/index, thus use the mixer
|
||||||
|
* from the cache at first.
|
||||||
|
*/
|
||||||
|
if (!pm && pa_strneq(dev, "hw:", 3)) {
|
||||||
|
const char *s = dev + 3;
|
||||||
|
int card_index;
|
||||||
|
while (*s && *s >= 0 && *s <= '9') s++;
|
||||||
|
if (*s == '\0' && pa_atoi(dev + 3, &card_index) >= 0) {
|
||||||
|
PA_HASHMAP_FOREACH_KV(dev2, pm, mixers, state) {
|
||||||
|
if (pm->card_index == card_index) {
|
||||||
|
dev = dev2;
|
||||||
|
pm = pa_hashmap_get(mixers, dev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pm) {
|
if (pm) {
|
||||||
if (!probe)
|
if (!probe)
|
||||||
pm->used_for_probe_only = false;
|
pm->used_for_probe_only = false;
|
||||||
|
|
@ -1756,6 +1778,17 @@ snd_mixer_t *pa_alsa_open_mixer_by_name(pa_hashmap *mixers, const char *dev, boo
|
||||||
if (prepare_mixer(m, dev) >= 0) {
|
if (prepare_mixer(m, dev) >= 0) {
|
||||||
pm = pa_xnew0(pa_alsa_mixer, 1);
|
pm = pa_xnew0(pa_alsa_mixer, 1);
|
||||||
if (pm) {
|
if (pm) {
|
||||||
|
snd_hctl_t *hctl;
|
||||||
|
pm->card_index = -1;
|
||||||
|
/* determine the ALSA card number (index) and store it to card_index */
|
||||||
|
err = snd_mixer_get_hctl(m, dev, &hctl);
|
||||||
|
if (err >= 0) {
|
||||||
|
snd_ctl_card_info_t *info;
|
||||||
|
snd_ctl_card_info_alloca(&info);
|
||||||
|
err = snd_ctl_card_info(snd_hctl_ctl(hctl), info);
|
||||||
|
if (err >= 0)
|
||||||
|
pm->card_index = snd_ctl_card_info_get_card(info);
|
||||||
|
}
|
||||||
pm->used_for_probe_only = probe;
|
pm->used_for_probe_only = probe;
|
||||||
pm->mixer_handle = m;
|
pm->mixer_handle = m;
|
||||||
pa_hashmap_put(mixers, pa_xstrdup(dev), pm);
|
pa_hashmap_put(mixers, pa_xstrdup(dev), pm);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue