acp: sync with pulseaudio

This commit is contained in:
Wim Taymans 2022-01-03 17:21:28 +01:00
parent 2f4c589d5b
commit b63a6a1b66
5 changed files with 93 additions and 60 deletions

View file

@ -255,10 +255,10 @@ static void init_device(pa_card *impl, pa_alsa_device *dev, pa_alsa_direction_t
pa_idxset_string_compare_func);
if (m->ucm_context.ucm) {
dev->ucm_context = &m->ucm_context;
if (impl->ucm.alibpref != NULL) {
if (impl->ucm.alib_prefix != NULL) {
for (d = m->device_strings; *d; d++) {
if (pa_startswith(*d, impl->ucm.alibpref)) {
size_t plen = strlen(impl->ucm.alibpref);
if (pa_startswith(*d, impl->ucm.alib_prefix)) {
size_t plen = strlen(impl->ucm.alib_prefix);
size_t len = strlen(*d);
memmove(*d, (*d) + plen, len - plen + 1);
dev->device.flags |= ACP_DEVICE_UCM_DEVICE;

View file

@ -100,8 +100,8 @@ struct pa_alsa_setting {
/* An entry for one ALSA mixer */
struct pa_alsa_mixer {
struct pa_alsa_mixer *alias;
snd_mixer_t *mixer_handle;
int card_index;
bool used_for_poll:1;
bool used_for_probe_only:1;
};

View file

@ -779,6 +779,14 @@ int pa_alsa_ucm_query_profiles(pa_alsa_ucm_config *ucm, int card_index) {
pa_log_info("UCM available for card %s", card_name);
if (snd_use_case_get(ucm->ucm_mgr, "_alibpref", &value) == 0) {
if (value[0]) {
ucm->alib_prefix = pa_xstrdup(value);
pa_log_debug("UCM _alibpref=%s", ucm->alib_prefix);
}
free((void *)value);
}
/* get a list of all UCM verbs (profiles) for this card */
num_verbs = snd_use_case_verb_list(ucm->ucm_mgr, &verb_list);
if (num_verbs < 0) {
@ -806,16 +814,12 @@ int pa_alsa_ucm_query_profiles(pa_alsa_ucm_config *ucm, int card_index) {
err = -PA_ALSA_ERR_UCM_NO_VERB;
}
snd_use_case_get(ucm->ucm_mgr, "_alibpref", (const char**)&ucm->alibpref);
snd_use_case_free_list(verb_list, num_verbs);
ucm_verb_fail:
if (err < 0) {
snd_use_case_mgr_close(ucm->ucm_mgr);
ucm->ucm_mgr = NULL;
free(ucm->alibpref);
ucm->alibpref = NULL;
}
ucm_mgr_fail:
@ -1324,6 +1328,11 @@ void pa_alsa_ucm_add_ports(
/* now set up volume paths if any */
probe_volumes(*p, is_sink, pcm_handle, context->ucm->mixers, ignore_dB);
/* probe_volumes() removes per-profile paths from ports if probing them
* fails. The path for the current profile is cached in
* pa_alsa_ucm_port_data.path, which is not cleared by probe_volumes() if
* the path gets removed, so we have to call update_mixer_paths() here to
* unset the cached path if needed. */
if (card->card.active_profile_index < card->card.n_profiles)
update_mixer_paths(*p, card->card.profiles[card->card.active_profile_index]->name);
@ -1541,8 +1550,9 @@ static pa_alsa_mapping* ucm_alsa_mapping_get(pa_alsa_ucm_config *ucm, pa_alsa_pr
size_t ucm_alibpref_len = 0;
/* find private alsa-lib's configuration device prefix */
if (ucm->alibpref != NULL && ucm->alibpref[0] && pa_startswith(device_str, ucm->alibpref))
ucm_alibpref_len = strlen(ucm->alibpref);
if (ucm->alib_prefix && pa_startswith(device_str, ucm->alib_prefix))
ucm_alibpref_len = strlen(ucm->alib_prefix);
mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, device_str + ucm_alibpref_len, is_sink ? "sink" : "source");
@ -1865,7 +1875,7 @@ static void mapping_init_eld(pa_alsa_mapping *m, snd_pcm_t *pcm)
pa_alsa_ucm_mapping_context *context = &m->ucm_context;
pa_alsa_ucm_device *dev;
uint32_t idx;
char *mdev;
char *mdev, *alib_prefix;
snd_pcm_info_t *info;
int pcm_card, pcm_device;
@ -1878,8 +1888,10 @@ static void mapping_init_eld(pa_alsa_mapping *m, snd_pcm_t *pcm)
if ((pcm_device = snd_pcm_info_get_device(info)) < 0)
return;
alib_prefix = context->ucm->alib_prefix;
PA_IDXSET_FOREACH(dev, context->ucm_devices, idx) {
mdev = pa_sprintf_malloc("hw:%i", pcm_card);
mdev = pa_sprintf_malloc("%shw:%i", alib_prefix ? alib_prefix : "", pcm_card);
if (mdev == NULL)
continue;
dev->eld_mixer_device_name = mdev;
@ -2149,8 +2161,8 @@ void pa_alsa_ucm_free(pa_alsa_ucm_config *ucm) {
snd_use_case_mgr_close(ucm->ucm_mgr);
ucm->ucm_mgr = NULL;
}
free(ucm->alibpref);
ucm->alibpref = NULL;
pa_xfree(ucm->alib_prefix);
ucm->alib_prefix = NULL;
}
void pa_alsa_ucm_mapping_context_free(pa_alsa_ucm_mapping_context *context) {

View file

@ -259,12 +259,11 @@ struct pa_alsa_ucm_config {
snd_use_case_mgr_t *ucm_mgr;
pa_alsa_ucm_verb *active_verb;
char *alib_prefix;
pa_hashmap *mixers;
PA_LLIST_HEAD(pa_alsa_ucm_verb, verbs);
PA_LLIST_HEAD(pa_alsa_jack, jacks);
char *alibpref;
};
struct pa_alsa_ucm_mapping_context {

View file

@ -1659,14 +1659,14 @@ static int mixer_class_event(snd_mixer_class_t *class, unsigned int mask,
return 0;
}
static int prepare_mixer(snd_mixer_t *mixer, const char *dev) {
static int prepare_mixer(snd_mixer_t *mixer, const char *dev, snd_hctl_t *hctl) {
int err;
snd_mixer_class_t *class;
pa_assert(mixer);
pa_assert(dev);
if ((err = snd_mixer_attach(mixer, dev)) < 0) {
if ((err = snd_mixer_attach_hctl(mixer, hctl)) < 0) {
pa_log_info("Unable to attach to mixer %s: %s", dev, pa_alsa_strerror(err));
return -1;
}
@ -1705,37 +1705,29 @@ snd_mixer_t *pa_alsa_open_mixer(pa_hashmap *mixers, int alsa_card_index, bool pr
return m;
}
pa_alsa_mixer *pa_alsa_create_mixer(pa_hashmap *mixers, const char *dev, snd_mixer_t *m, bool probe) {
pa_alsa_mixer *pm;
pm = pa_xnew0(pa_alsa_mixer, 1);
if (pm == NULL)
return NULL;
pm->used_for_probe_only = probe;
pm->mixer_handle = m;
pa_hashmap_put(mixers, pa_xstrdup(dev), pm);
return pm;
}
snd_mixer_t *pa_alsa_open_mixer_by_name(pa_hashmap *mixers, const char *dev, bool probe) {
int err;
snd_mixer_t *m;
snd_hctl_t *hctl;
pa_alsa_mixer *pm;
char *dev2;
void *state;
pa_assert(mixers);
pa_assert(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 (!probe)
pm->used_for_probe_only = false;
@ -1747,27 +1739,55 @@ snd_mixer_t *pa_alsa_open_mixer_by_name(pa_hashmap *mixers, const char *dev, boo
return NULL;
}
if (prepare_mixer(m, dev) >= 0) {
pm = pa_xnew0(pa_alsa_mixer, 1);
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->mixer_handle = m;
pa_hashmap_put(mixers, pa_xstrdup(dev), pm);
return m;
}
err = snd_hctl_open(&hctl, dev, 0);
if (err < 0) {
pa_log("Error opening hctl device: %s", pa_alsa_strerror(err));
goto __close;
}
if (prepare_mixer(m, dev, hctl) >= 0) {
/* get the ALSA card number (index) and ID (alias) and create two identical mixers */
char *p, *dev2, *dev_idx, *dev_id;
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)
goto __std;
dev2 = pa_xstrdup(dev);
if (dev2 == NULL)
goto __close;
p = strchr(dev2, ':');
/* sanity check - only hw: devices */
if (p == NULL || (p - dev2) < 2 || !pa_strneq(p - 2, "hw:", 3)) {
pa_xfree(dev2);
goto __std;
}
*p = '\0';
dev_idx = pa_sprintf_malloc("%s:%u", dev2, snd_ctl_card_info_get_card(info));
dev_id = pa_sprintf_malloc("%s:%s", dev2, snd_ctl_card_info_get_id(info));
pa_log_debug("ALSA alias mixers: %s = %s", dev_idx, dev_id);
if (dev_idx && dev_id && (strcmp(dev, dev_idx) == 0 || strcmp(dev, dev_id) == 0)) {
pm = pa_alsa_create_mixer(mixers, dev_idx, m, probe);
if (pm) {
pa_alsa_mixer *pm2;
pm2 = pa_alsa_create_mixer(mixers, dev_id, m, probe);
if (pm2) {
pm->alias = pm2;
pm2->alias = pm;
}
}
}
pa_xfree(dev_id);
pa_xfree(dev_idx);
pa_xfree(dev2);
__std:
if (pm == NULL)
pm = pa_alsa_create_mixer(mixers, dev, m, probe);
if (pm)
return m;
}
__close:
snd_mixer_close(m);
return NULL;
}
@ -1808,8 +1828,10 @@ void pa_alsa_mixer_set_fdlist(pa_hashmap *mixers, snd_mixer_t *mixer_handle, pa_
void pa_alsa_mixer_free(pa_alsa_mixer *mixer)
{
if (mixer->mixer_handle)
if (mixer->mixer_handle && mixer->alias == NULL)
snd_mixer_close(mixer->mixer_handle);
if (mixer->alias)
mixer->alias->alias = NULL;
pa_xfree(mixer);
}