alsa-ucm: Make one input/output mapping per UCM device

PulseAudio combines UCM devices that have the same PlaybackPCM or
CapturePCM value into a single mapping with multiple ports. It also
creates ports in the same mapping for each valid combination of those
UCM devices.

Since mappings are the things we put in profiles, we can put in a
profile either all devices of a joint mapping or none of them. This
causes some complications with device conflicts. For example, a
different UCM device might be marked as conflicting with some (but not
all) of the devices in a joint mapping. In this case we can do one of
three things:

- Include all devices in one profile, and hope the conflicting device
  isn't chosen as the mapping's active port. We shouldn't do this as it
  puts conflicting devices in the same profile.

- Make one profile with the joint group, and one with the other device.
  This is somewhat acceptable as we have no conflicts, but we sacrifice
  some compatible combinations of devices.

- Do not group the devices into the same mapping, and make one profile
  for each compatible combination of devices. This appears to be the
  best option, one where we can always have the maximum number of
  working devices.

This patch chooses the third option and makes one input and/or output
mapping per UCM device, by using UCM device names instead of PCM device
strings in the mapping names.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
Wim Taymans 2023-03-20 16:36:40 +01:00
parent e2d642a20b
commit 96cfc9bc1a

View file

@ -1649,17 +1649,11 @@ static void alsa_mapping_add_ucm_modifier(pa_alsa_mapping *m, pa_alsa_ucm_modifi
pa_channel_map_init(&m->channel_map);
}
static pa_alsa_mapping* ucm_alsa_mapping_get(pa_alsa_ucm_config *ucm, pa_alsa_profile_set *ps, const char *verb_name, const char *device_str, bool is_sink) {
static pa_alsa_mapping* ucm_alsa_mapping_get(pa_alsa_ucm_config *ucm, pa_alsa_profile_set *ps, const char *verb_name, const char *ucm_name, bool is_sink) {
pa_alsa_mapping *m;
char *mapping_name;
size_t ucm_alibpref_len = 0;
/* find private alsa-lib's configuration device prefix */
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");
mapping_name = pa_sprintf_malloc("Mapping %s: %s: %s", verb_name, ucm_name, is_sink ? "sink" : "source");
m = pa_alsa_mapping_get(ps, mapping_name);
@ -1683,7 +1677,7 @@ static int ucm_create_mapping_direction(
pa_alsa_mapping *m;
unsigned priority, rate, channels;
m = ucm_alsa_mapping_get(ucm, ps, verb_name, device_str, is_sink);
m = ucm_alsa_mapping_get(ucm, ps, verb_name, device_name, is_sink);
if (!m)
return -1;
@ -1732,7 +1726,7 @@ static int ucm_create_mapping_for_modifier(
pa_alsa_mapping *m;
m = ucm_alsa_mapping_get(ucm, ps, verb_name, device_str, is_sink);
m = ucm_alsa_mapping_get(ucm, ps, verb_name, mod_name, is_sink);
if (!m)
return -1;