alsa-mixer: extend pa_alsa_mixer_find with the subdevice check

The full identifier check must be executed for the new melem
creation, otherwise the duplicate control element code check
is reached.

Example (using the snd-aloop driver):

numid=56,iface=PCM,name='PCM Notify',device=1,subdevice=1
numid=62,iface=PCM,name='PCM Notify',device=1,subdevice=2

Link: 81a051089f
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2023-03-20 17:50:17 +01:00 committed by Wim Taymans
parent 4066bbaf09
commit 84120e1167

View file

@ -1600,7 +1600,8 @@ static snd_mixer_elem_t *pa_alsa_mixer_find(snd_mixer_t *mixer,
snd_ctl_elem_iface_t iface, snd_ctl_elem_iface_t iface,
const char *name, const char *name,
unsigned int index, unsigned int index,
unsigned int device) { unsigned int device,
unsigned int subdevice) {
snd_mixer_elem_t *elem; snd_mixer_elem_t *elem;
for (elem = snd_mixer_first_elem(mixer); elem; elem = snd_mixer_elem_next(elem)) { for (elem = snd_mixer_first_elem(mixer); elem; elem = snd_mixer_elem_next(elem)) {
@ -1617,17 +1618,19 @@ static snd_mixer_elem_t *pa_alsa_mixer_find(snd_mixer_t *mixer,
continue; continue;
if (snd_hctl_elem_get_device(helem) != device) if (snd_hctl_elem_get_device(helem) != device)
continue; continue;
if (snd_hctl_elem_get_subdevice(helem) != subdevice)
continue;
return elem; return elem;
} }
return NULL; return NULL;
} }
snd_mixer_elem_t *pa_alsa_mixer_find_card(snd_mixer_t *mixer, struct pa_alsa_mixer_id *alsa_id, unsigned int device) { snd_mixer_elem_t *pa_alsa_mixer_find_card(snd_mixer_t *mixer, struct pa_alsa_mixer_id *alsa_id, unsigned int device) {
return pa_alsa_mixer_find(mixer, SND_CTL_ELEM_IFACE_CARD, alsa_id->name, alsa_id->index, device); return pa_alsa_mixer_find(mixer, SND_CTL_ELEM_IFACE_CARD, alsa_id->name, alsa_id->index, device, 0);
} }
snd_mixer_elem_t *pa_alsa_mixer_find_pcm(snd_mixer_t *mixer, const char *name, unsigned int device) { snd_mixer_elem_t *pa_alsa_mixer_find_pcm(snd_mixer_t *mixer, const char *name, unsigned int device) {
return pa_alsa_mixer_find(mixer, SND_CTL_ELEM_IFACE_PCM, name, 0, device); return pa_alsa_mixer_find(mixer, SND_CTL_ELEM_IFACE_PCM, name, 0, device, 0);
} }
static int mixer_class_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2) static int mixer_class_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2)
@ -1664,11 +1667,12 @@ static int mixer_class_event(snd_mixer_class_t *class, unsigned int mask,
const char *name = snd_hctl_elem_get_name(helem); const char *name = snd_hctl_elem_get_name(helem);
const int index = snd_hctl_elem_get_index(helem); const int index = snd_hctl_elem_get_index(helem);
const int device = snd_hctl_elem_get_device(helem); const int device = snd_hctl_elem_get_device(helem);
const int subdevice = snd_hctl_elem_get_subdevice(helem);
snd_mixer_elem_t *new_melem; snd_mixer_elem_t *new_melem;
bool found = true; bool found = true;
new_melem = pa_alsa_mixer_find(mixer, iface, name, index, device); new_melem = pa_alsa_mixer_find(mixer, iface, name, index, device, subdevice);
if (!new_melem) { if (!new_melem) {
_helem = pa_xmalloc(sizeof(snd_hctl_elem_t *)); _helem = pa_xmalloc(sizeof(snd_hctl_elem_t *));
*_helem = helem; *_helem = helem;