alsa-ucm: Remove combination port generation logic

A previous commit makes mapping names depend on the UCM device name.
Since UCM device names are unique, this means a mapping will at most
have one port and thus no combination ports can be generated.

This removes the dead code in the pa_alsa_ucm_add_ports_combination()
function, unrolls the remaining code in its helper functions that it
used, and renames it to pa_alsa_ucm_add_port() to signal that it no
longer generates combinations.

Link: 0789a8fb76
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
[Wim: Apply to acp add_profiles(), acp_card_set_profile(), compat.h]
This commit is contained in:
Alper Nebi Yasak 2023-11-27 23:30:36 +03:00 committed by Wim Taymans
parent 833c86d35b
commit 0fc80db7fe
4 changed files with 52 additions and 107 deletions

View file

@ -511,7 +511,7 @@ static void add_profiles(pa_card *impl)
} }
if (impl->use_ucm) { if (impl->use_ucm) {
if (m->ucm_context.ucm_devices) { if (m->ucm_context.ucm_devices) {
pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, pa_alsa_ucm_add_port(NULL, &m->ucm_context,
true, impl->ports, ap, NULL); true, impl->ports, ap, NULL);
pa_alsa_ucm_add_ports(&dev->ports, m->proplist, &m->ucm_context, pa_alsa_ucm_add_ports(&dev->ports, m->proplist, &m->ucm_context,
true, impl, dev->pcm_handle, impl->profile_set->ignore_dB); true, impl, dev->pcm_handle, impl->profile_set->ignore_dB);
@ -535,7 +535,7 @@ static void add_profiles(pa_card *impl)
if (impl->use_ucm) { if (impl->use_ucm) {
if (m->ucm_context.ucm_devices) { if (m->ucm_context.ucm_devices) {
pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, pa_alsa_ucm_add_port(NULL, &m->ucm_context,
false, impl->ports, ap, NULL); false, impl->ports, ap, NULL);
pa_alsa_ucm_add_ports(&dev->ports, m->proplist, &m->ucm_context, pa_alsa_ucm_add_ports(&dev->ports, m->proplist, &m->ucm_context,
false, impl, dev->pcm_handle, impl->profile_set->ignore_dB); false, impl, dev->pcm_handle, impl->profile_set->ignore_dB);
@ -1518,7 +1518,7 @@ int acp_card_set_profile(struct acp_card *card, uint32_t new_index, uint32_t fla
if (impl->use_ucm) { if (impl->use_ucm) {
/* Update ports priorities */ /* Update ports priorities */
if (am->ucm_context.ucm_devices) { if (am->ucm_context.ucm_devices) {
pa_alsa_ucm_add_ports_combination(am->output.ports, &am->ucm_context, pa_alsa_ucm_add_port(am->output.ports, &am->ucm_context,
true, impl->ports, np, NULL); true, impl->ports, np, NULL);
} }
} }
@ -1531,7 +1531,7 @@ int acp_card_set_profile(struct acp_card *card, uint32_t new_index, uint32_t fla
if (impl->use_ucm) { if (impl->use_ucm) {
/* Update ports priorities */ /* Update ports priorities */
if (am->ucm_context.ucm_devices) { if (am->ucm_context.ucm_devices) {
pa_alsa_ucm_add_ports_combination(am->input.ports, &am->ucm_context, pa_alsa_ucm_add_port(am->input.ports, &am->ucm_context,
false, impl->ports, np, NULL); false, impl->ports, np, NULL);
} }
} }

View file

@ -1071,7 +1071,7 @@ static void ucm_add_port_props(
pa_proplist_sets(port->proplist, "device.icon_name", icon); pa_proplist_sets(port->proplist, "device.icon_name", icon);
} }
static char *devset_name(pa_idxset *devices, const char *sep) { PA_UNUSED static char *devset_name(pa_idxset *devices, const char *sep) {
int i = 0; int i = 0;
int num = pa_idxset_size(devices); int num = pa_idxset_size(devices);
pa_alsa_ucm_device *sorted[num], *dev; pa_alsa_ucm_device *sorted[num], *dev;
@ -1103,7 +1103,7 @@ static char *devset_name(pa_idxset *devices, const char *sep) {
return dev_names; return dev_names;
} }
static char *devset_description(pa_idxset *devices, const char *sep) { PA_UNUSED static char *devset_description(pa_idxset *devices, const char *sep) {
int i = 0; int i = 0;
int num = pa_idxset_size(devices); int num = pa_idxset_size(devices);
pa_alsa_ucm_device *sorted[num], *dev; pa_alsa_ucm_device *sorted[num], *dev;
@ -1138,7 +1138,7 @@ static char *devset_description(pa_idxset *devices, const char *sep) {
/* If invert is true, uses the formula 1/p = 1/p1 + 1/p2 + ... 1/pn. /* If invert is true, uses the formula 1/p = 1/p1 + 1/p2 + ... 1/pn.
* This way, the result will always be less than the individual components, * This way, the result will always be less than the individual components,
* yet higher components will lead to higher result. */ * yet higher components will lead to higher result. */
static unsigned devset_playback_priority(pa_idxset *devices, bool invert) { PA_UNUSED static unsigned devset_playback_priority(pa_idxset *devices, bool invert) {
pa_alsa_ucm_device *dev; pa_alsa_ucm_device *dev;
uint32_t idx; uint32_t idx;
double priority = 0; double priority = 0;
@ -1156,7 +1156,7 @@ static unsigned devset_playback_priority(pa_idxset *devices, bool invert) {
return (unsigned) priority; return (unsigned) priority;
} }
static unsigned devset_capture_priority(pa_idxset *devices, bool invert) { PA_UNUSED static unsigned devset_capture_priority(pa_idxset *devices, bool invert) {
pa_alsa_ucm_device *dev; pa_alsa_ucm_device *dev;
uint32_t idx; uint32_t idx;
double priority = 0; double priority = 0;
@ -1174,75 +1174,42 @@ static unsigned devset_capture_priority(pa_idxset *devices, bool invert) {
return (unsigned) priority; return (unsigned) priority;
} }
static void ucm_add_port_combination( void pa_alsa_ucm_add_port(
pa_hashmap *hash, pa_hashmap *hash,
pa_alsa_ucm_mapping_context *context, pa_alsa_ucm_mapping_context *context,
bool is_sink, bool is_sink,
pa_idxset *devices,
pa_hashmap *ports, pa_hashmap *ports,
pa_card_profile *cp, pa_card_profile *cp,
pa_core *core) { pa_core *core) {
pa_device_port *port; pa_device_port *port;
int i;
int num = pa_idxset_size(devices);
uint32_t idx;
unsigned priority; unsigned priority;
char *name, *desc, *tmp; char *name, *desc;
const char *dev_name;
const char *direction; const char *direction;
const char *profile; const char *profile;
pa_alsa_ucm_device *sorted[num], *dev; pa_alsa_ucm_device *dev;
pa_alsa_ucm_port_data *data; pa_alsa_ucm_port_data *data;
pa_alsa_ucm_volume *vol; pa_alsa_ucm_volume *vol;
pa_alsa_jack *jack, *jack2; pa_alsa_jack *jack;
pa_device_port_type_t type, type2; pa_device_port_type_t type;
uint32_t idx;
void *state; void *state;
i = 0; pa_assert(context->ucm_devices);
PA_IDXSET_FOREACH(dev, devices, idx) { pa_assert(pa_idxset_size(context->ucm_devices) <= 1);
sorted[i] = dev;
i++;
}
/* Sort by alphabetical order so as to have a deterministic naming scheme dev = pa_idxset_first(context->ucm_devices, &idx);
* for combination ports */ if (!dev)
qsort(&sorted[0], num, sizeof(pa_alsa_ucm_device *), pa_alsa_ucm_device_cmp); return;
name = devset_name(devices, "+"); dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME);
tmp = pa_sprintf_malloc("%s%s", is_sink ? PA_UCM_PRE_TAG_OUTPUT : PA_UCM_PRE_TAG_INPUT, name); name = pa_sprintf_malloc("%s%s", is_sink ? PA_UCM_PRE_TAG_OUTPUT : PA_UCM_PRE_TAG_INPUT, dev_name);
pa_xfree(name); desc = pa_xstrdup(pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_DESCRIPTION));
name = tmp; priority = is_sink ? dev->playback_priority : dev->capture_priority;
desc = devset_description(devices, ", ");
if (pa_idxset_size(devices) > 1) {
tmp = pa_sprintf_malloc("Combination port for %s", desc);
pa_xfree(desc);
desc = tmp;
}
/* Make combination ports always have lower priority */
priority = is_sink ? devset_playback_priority(devices, true) : devset_capture_priority(devices, true);
dev = sorted[0];
jack = ucm_get_jack(context->ucm, dev); jack = ucm_get_jack(context->ucm, dev);
type = dev->type; type = dev->type;
for (i = 1; i < num; i++) {
jack2 = ucm_get_jack(context->ucm, dev);
if (jack2) {
if (jack && jack != jack2)
pa_log_warn("Multiple jacks per combined device '%s': '%s' '%s'", name, jack->name, jack2->name);
jack = jack2;
}
type2 = dev->type;
if (type2 != PA_DEVICE_PORT_TYPE_UNKNOWN) {
if (type != PA_DEVICE_PORT_TYPE_UNKNOWN && type != type2)
pa_log_warn("Multiple device types per combined device '%s': %d %d", name, type, type2);
type = type2;
}
}
port = pa_hashmap_get(ports, name); port = pa_hashmap_get(ports, name);
if (!port) { if (!port) {
pa_device_port_new_data port_data; pa_device_port_new_data port_data;
@ -1259,38 +1226,33 @@ static void ucm_add_port_combination(
pa_device_port_new_data_done(&port_data); pa_device_port_new_data_done(&port_data);
data = PA_DEVICE_PORT_DATA(port); data = PA_DEVICE_PORT_DATA(port);
ucm_port_data_init(data, context->ucm, port, sorted, num); ucm_port_data_init(data, context->ucm, port, &dev, 1);
port->impl_free = ucm_port_data_free; port->impl_free = ucm_port_data_free;
pa_hashmap_put(ports, port->name, port); pa_hashmap_put(ports, port->name, port);
pa_log_debug("Add port %s: %s", port->name, port->description); pa_log_debug("Add port %s: %s", port->name, port->description);
ucm_add_port_props(port, is_sink); ucm_add_port_props(port, is_sink);
if (num == 1) { PA_HASHMAP_FOREACH_KV(profile, vol, is_sink ? dev->playback_volumes : dev->capture_volumes, state) {
/* To keep things simple and not worry about stacking controls, we only support hardware volumes on non-combination pa_alsa_path *path = pa_alsa_path_synthesize(vol->mixer_elem,
* ports. */ is_sink ? PA_ALSA_DIRECTION_OUTPUT : PA_ALSA_DIRECTION_INPUT);
PA_HASHMAP_FOREACH_KV(profile, vol, is_sink ? dev->playback_volumes : dev->capture_volumes, state) {
pa_alsa_path *path = pa_alsa_path_synthesize(vol->mixer_elem,
is_sink ? PA_ALSA_DIRECTION_OUTPUT : PA_ALSA_DIRECTION_INPUT);
if (!path) if (!path)
pa_log_warn("Failed to set up volume control: %s", vol->mixer_elem); pa_log_warn("Failed to set up volume control: %s", vol->mixer_elem);
else { else {
if (vol->master_elem) { if (vol->master_elem) {
pa_alsa_element *e = pa_alsa_element_get(path, vol->master_elem, false); pa_alsa_element *e = pa_alsa_element_get(path, vol->master_elem, false);
e->switch_use = PA_ALSA_SWITCH_MUTE; e->switch_use = PA_ALSA_SWITCH_MUTE;
e->volume_use = PA_ALSA_VOLUME_MERGE; e->volume_use = PA_ALSA_VOLUME_MERGE;
}
pa_hashmap_put(data->paths, pa_xstrdup(profile), path);
/* Add path also to already created empty path set */
dev = sorted[0];
if (is_sink)
pa_hashmap_put(dev->playback_mapping->output_path_set->paths, pa_xstrdup(vol->mixer_elem), path);
else
pa_hashmap_put(dev->capture_mapping->input_path_set->paths, pa_xstrdup(vol->mixer_elem), path);
} }
pa_hashmap_put(data->paths, pa_xstrdup(profile), path);
/* Add path also to already created empty path set */
if (is_sink)
pa_hashmap_put(dev->playback_mapping->output_path_set->paths, pa_xstrdup(vol->mixer_elem), path);
else
pa_hashmap_put(dev->capture_mapping->input_path_set->paths, pa_xstrdup(vol->mixer_elem), path);
} }
} }
} }
@ -1311,6 +1273,9 @@ static void ucm_add_port_combination(
if (hash) { if (hash) {
pa_hashmap_put(hash, port->name, port); pa_hashmap_put(hash, port->name, port);
} }
/* ELD devices */
set_eld_devices(ports);
} }
static int ucm_port_contains(const char *port_name, const char *dev_name, bool is_sink) { static int ucm_port_contains(const char *port_name, const char *dev_name, bool is_sink) {
@ -1372,7 +1337,7 @@ static bool devset_supports_device(pa_idxset *devices, pa_alsa_ucm_device *dev)
* *state should be NULL. It's not safe to modify the devices argument * *state should be NULL. It's not safe to modify the devices argument
* until iteration ends. The returned idxsets must be freed by the * until iteration ends. The returned idxsets must be freed by the
* caller. */ * caller. */
static pa_idxset *iterate_device_subsets(pa_idxset *devices, void **state) { PA_UNUSED static pa_idxset *iterate_device_subsets(pa_idxset *devices, void **state) {
uint32_t idx; uint32_t idx;
pa_alsa_ucm_device *dev; pa_alsa_ucm_device *dev;
@ -1439,28 +1404,6 @@ static char* merge_roles(const char *cur, const char *add) {
return ret; return ret;
} }
void pa_alsa_ucm_add_ports_combination(
pa_hashmap *p,
pa_alsa_ucm_mapping_context *context,
bool is_sink,
pa_hashmap *ports,
pa_card_profile *cp,
pa_core *core) {
pa_idxset *devices;
void *state = NULL;
pa_assert(context->ucm_devices);
while ((devices = iterate_device_subsets(context->ucm_devices, &state))) {
ucm_add_port_combination(p, context, is_sink, devices, ports, cp, core);
pa_idxset_free(devices, NULL);
}
/* ELD devices */
set_eld_devices(ports);
}
void pa_alsa_ucm_add_ports( void pa_alsa_ucm_add_ports(
pa_hashmap **p, pa_hashmap **p,
pa_proplist *proplist, pa_proplist *proplist,
@ -1481,7 +1424,7 @@ void pa_alsa_ucm_add_ports(
pa_assert(*p); pa_assert(*p);
/* add ports first */ /* add ports first */
pa_alsa_ucm_add_ports_combination(*p, context, is_sink, card->ports, NULL, card->core); pa_alsa_ucm_add_port(*p, context, is_sink, card->ports, NULL, card->core);
/* now set up volume paths if any */ /* now set up volume paths if any */
probe_volumes(*p, is_sink, pcm_handle, context->ucm->mixers, ignore_dB); probe_volumes(*p, is_sink, pcm_handle, context->ucm->mixers, ignore_dB);
@ -2565,7 +2508,7 @@ void pa_alsa_ucm_add_ports(
bool ignore_dB) { bool ignore_dB) {
} }
void pa_alsa_ucm_add_ports_combination( void pa_alsa_ucm_add_port(
pa_hashmap *hash, pa_hashmap *hash,
pa_alsa_ucm_mapping_context *context, pa_alsa_ucm_mapping_context *context,
bool is_sink, bool is_sink,

View file

@ -160,7 +160,7 @@ void pa_alsa_ucm_add_ports(
pa_card *card, pa_card *card,
snd_pcm_t *pcm_handle, snd_pcm_t *pcm_handle,
bool ignore_dB); bool ignore_dB);
void pa_alsa_ucm_add_ports_combination( void pa_alsa_ucm_add_port(
pa_hashmap *hash, pa_hashmap *hash,
pa_alsa_ucm_mapping_context *context, pa_alsa_ucm_mapping_context *context,
bool is_sink, bool is_sink,

View file

@ -47,10 +47,12 @@ typedef void (*pa_free_cb_t)(void *p);
#define PA_LIKELY(x) (__builtin_expect(!!(x),1)) #define PA_LIKELY(x) (__builtin_expect(!!(x),1))
#define PA_UNLIKELY(x) (__builtin_expect(!!(x),0)) #define PA_UNLIKELY(x) (__builtin_expect(!!(x),0))
#define PA_PRINTF_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) #define PA_PRINTF_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
#define PA_UNUSED __attribute__ ((unused))
#else #else
#define PA_LIKELY(x) (x) #define PA_LIKELY(x) (x)
#define PA_UNLIKELY(x) (x) #define PA_UNLIKELY(x) (x)
#define PA_PRINTF_FUNC(fmt, arg1) #define PA_PRINTF_FUNC(fmt, arg1)
#define PA_UNUSED
#endif #endif
#define PA_MIN(a,b) \ #define PA_MIN(a,b) \