Card implementations don't need to care about adding the ports to sinks and sources, so a lot of code can be removed. --- src/modules/alsa/alsa-mixer.c | 72 ------------- src/modules/alsa/alsa-sink.c | 5 +- src/modules/alsa/alsa-source.c | 5 +- src/modules/alsa/alsa-ucm.c | 129 ------------------------ src/modules/alsa/alsa-ucm.h | 11 -- src/modules/alsa/module-alsa-card.c | 8 -- src/modules/bluetooth/module-bluetooth-device.c | 17 ---- src/pulsecore/sink.c | 8 ++ src/pulsecore/source.c | 8 ++ 9 files changed, 18 insertions(+), 245 deletions(-) diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index 61d292d..d48d789 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -4523,78 +4523,6 @@ void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) { } } -static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */ - pa_alsa_path *path, - pa_alsa_setting *setting, - pa_hashmap *extra /* sink/source ports */) { - - char *name = NULL; - pa_device_port *p; - - pa_assert(path); - - if (setting) - name = pa_sprintf_malloc("%s;%s", path->name, setting->name); - else - name = pa_xstrdup(path->name); - - p = pa_hashmap_get(ports, name); - pa_assert(p); - pa_xfree(name); - - if (extra) { - pa_hashmap_put(extra, p->name, p); - pa_device_port_ref(p); - } - - return p; -} - -void pa_alsa_path_set_add_ports( - pa_alsa_path_set *ps, - pa_hashmap *ports, /* card ports */ - pa_hashmap *extra /* sink/source ports */) { - - pa_alsa_path *path; - void *state; - - pa_assert(ports); - - if (!ps) - return; - - PA_HASHMAP_FOREACH(path, ps->paths, state) { - if (!path->settings || !path->settings->next) - /* If there is no or just one setting we only need a - * single entry */ - device_port_alsa_init(ports, path, path->settings, extra); - else { - pa_alsa_setting *s; - PA_LLIST_FOREACH(s, path->settings) - device_port_alsa_init(ports, path, s, extra); - } - } -} - -void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_card *card) { - pa_hashmap *ports; - - pa_assert(sink_or_source_new_data); - pa_assert(ps); - - if (ps->direction == PA_ALSA_DIRECTION_OUTPUT) - ports = ((pa_sink_new_data *) sink_or_source_new_data)->ports; - else - ports = ((pa_source_new_data *) sink_or_source_new_data)->ports; - - if (ps->paths && pa_hashmap_size(ps->paths) > 0) { - pa_assert(card); - pa_alsa_path_set_add_ports(ps, card->ports, ports); - } - - pa_log_debug("Added %u ports", pa_hashmap_size(ports)); -} - static pa_device_port *create_port(pa_core *core, pa_alsa_path *path, pa_alsa_setting *setting) { char *name = NULL; char *description = NULL; diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index aa81a6f..2f80ef8 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -2285,11 +2285,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca goto fail; } - if (u->ucm_context) { - pa_alsa_ucm_add_ports(&data.ports, u->ucm_context, true, card); + if (u->ucm_context) pa_alsa_ucm_set_intended_roles(data.proplist, u->ucm_context, PA_DIRECTION_OUTPUT); - } else if (u->mixer_path_set) - pa_alsa_add_ports(&data, u->mixer_path_set, card); if (mapping) pa_sink_new_data_set_prototype(&data, mapping->sink_prototype); diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index feb4f0f..d2d4332 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -1991,11 +1991,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p goto fail; } - if (u->ucm_context) { - pa_alsa_ucm_add_ports(&data.ports, u->ucm_context, false, card); + if (u->ucm_context) pa_alsa_ucm_set_intended_roles(data.proplist, u->ucm_context, PA_DIRECTION_INPUT); - } else if (u->mixer_path_set) - pa_alsa_add_ports(&data, u->mixer_path_set, card); if (mapping) pa_source_new_data_set_prototype(&data, mapping->source_prototype); diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c index 21efc40..d9137ad 100644 --- a/src/modules/alsa/alsa-ucm.c +++ b/src/modules/alsa/alsa-ucm.c @@ -664,49 +664,6 @@ int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, const char *verb_name, cons return 0; } -static void ucm_add_port_combination( - pa_hashmap *hash, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_alsa_ucm_device **pdevices, - int num, - pa_hashmap *ports, - pa_core *core) { - - pa_device_port *port; - int i; - char *name = NULL; - const char *dev_name; - pa_alsa_ucm_device *dev; - - dev = pdevices[0]; - dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME); - - name = pa_sprintf_malloc("%s%s", is_sink ? PA_UCM_PRE_TAG_OUTPUT : PA_UCM_PRE_TAG_INPUT, dev_name); - - for (i = 1; i < num; i++) { - char *tmp; - - dev = pdevices[i]; - dev_name = pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME); - - tmp = pa_sprintf_malloc("%s+%s", name, dev_name); - pa_xfree(name); - name = tmp; - } - - port = pa_hashmap_get(ports, name); - pa_assert(port); - pa_xfree(name); - - if (hash) { - pa_hashmap_put(hash, port->name, port); - pa_device_port_ref(port); - } - - return; -} - static int ucm_port_contains(const char *port_name, const char *dev_name, bool is_sink) { int ret = 0; const char *r; @@ -771,47 +728,6 @@ static bool ucm_check_conformance( return true; } -static inline pa_alsa_ucm_device *get_next_device(pa_idxset *idxset, uint32_t *idx) { - pa_alsa_ucm_device *dev; - - if (*idx == PA_IDXSET_INVALID) - dev = pa_idxset_first(idxset, idx); - else - dev = pa_idxset_next(idxset, idx); - - return dev; -} - -static void ucm_add_ports_combination( - pa_hashmap *hash, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_alsa_ucm_device **pdevices, - int dev_num, - uint32_t map_index, - pa_hashmap *ports, - pa_core *core) { - - pa_alsa_ucm_device *dev; - uint32_t idx = map_index; - - if ((dev = get_next_device(context->ucm_devices, &idx)) == NULL) - return; - - /* check if device at map_index can combine with existing devices combination */ - if (ucm_check_conformance(pdevices, dev_num, dev)) { - /* add device at map_index to devices combination */ - pdevices[dev_num] = dev; - /* add current devices combination as a new port */ - ucm_add_port_combination(hash, context, is_sink, pdevices, dev_num + 1, ports, core); - /* try more elements combination */ - ucm_add_ports_combination(hash, context, is_sink, pdevices, dev_num + 1, idx, ports, core); - } - - /* try other device with current elements number */ - ucm_add_ports_combination(hash, context, is_sink, pdevices, dev_num, idx, ports, core); -} - static char* merge_roles(const char *cur, const char *add) { char *r, *ret; const char *state = NULL; @@ -841,36 +757,6 @@ static char* merge_roles(const char *cur, const char *add) { 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_core *core) { - - pa_alsa_ucm_device **pdevices; - - pa_assert(context->ucm_devices); - - if (pa_idxset_size(context->ucm_devices) > 0) { - pdevices = pa_xnew(pa_alsa_ucm_device *, pa_idxset_size(context->ucm_devices)); - ucm_add_ports_combination(p, context, is_sink, pdevices, 0, PA_IDXSET_INVALID, ports, core); - pa_xfree(pdevices); - } -} - -void pa_alsa_ucm_add_ports( - pa_hashmap **p, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_card *card) { - - pa_assert(p); - pa_assert(*p); - - pa_alsa_ucm_add_ports_combination(*p, context, is_sink, card->ports, card->core); -} - void pa_alsa_ucm_set_intended_roles(pa_proplist *proplist, pa_alsa_ucm_mapping_context *context, pa_direction_t direction) { uint32_t idx; char *merged_roles; @@ -1760,21 +1646,6 @@ int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, const char *verb_name, cons return -1; } -void pa_alsa_ucm_add_ports( - pa_hashmap **hash, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_card *card) { -} - -void pa_alsa_ucm_add_ports_combination( - pa_hashmap *hash, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_hashmap *ports, - pa_core *core) { -} - void pa_alsa_ucm_set_intended_roles(pa_proplist *proplist, pa_alsa_ucm_mapping_context *context, pa_direction_t direction) { } diff --git a/src/modules/alsa/alsa-ucm.h b/src/modules/alsa/alsa-ucm.h index 476ba41..c3195f8 100644 --- a/src/modules/alsa/alsa-ucm.h +++ b/src/modules/alsa/alsa-ucm.h @@ -98,17 +98,6 @@ int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, const char *new_profile, co int pa_alsa_ucm_get_verb(snd_use_case_mgr_t *uc_mgr, const char *verb_name, const char *verb_desc, pa_alsa_ucm_verb **p_verb); -void pa_alsa_ucm_add_ports( - pa_hashmap **hash, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_card *card); -void pa_alsa_ucm_add_ports_combination( - pa_hashmap *hash, - pa_alsa_ucm_mapping_context *context, - bool is_sink, - pa_hashmap *ports, - pa_core *core); void pa_alsa_ucm_set_intended_roles(pa_proplist *proplist, pa_alsa_ucm_mapping_context *context, pa_direction_t direction); int pa_alsa_ucm_set_port(pa_alsa_ucm_mapping_context *context, pa_device_port *port, bool is_sink); diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 64c6fa0..b27f885 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -179,10 +179,6 @@ static void add_profiles(struct userdata *u, pa_card_new_data *data) { PA_IDXSET_FOREACH(m, ap->output_mappings, idx) { pa_hashmap_put(cp->sink_prototypes, m->sink_prototype, m->sink_prototype); - if (u->use_ucm) - pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, true, data->ports, u->core); - else - pa_alsa_path_set_add_ports(m->output_path_set, data->ports, NULL); if (m->channel_map.channels > cp->max_sink_channels) cp->max_sink_channels = m->channel_map.channels; } @@ -192,10 +188,6 @@ static void add_profiles(struct userdata *u, pa_card_new_data *data) { PA_IDXSET_FOREACH(m, ap->input_mappings, idx) { pa_hashmap_put(cp->source_prototypes, m->source_prototype, m->source_prototype); - if (u->use_ucm) - pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, false, data->ports, u->core); - else - pa_alsa_path_set_add_ports(m->input_path_set, data->ports, NULL); if (m->channel_map.channels > cp->max_source_channels) cp->max_source_channels = m->channel_map.channels; } diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 05ff5a1..199c85e 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -1503,20 +1503,6 @@ static pa_hook_result_t transport_speaker_gain_changed_cb(pa_bluetooth_discovery return PA_HOOK_OK; } -static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_direction_t direction) { - if (direction == PA_DIRECTION_OUTPUT) { - pa_sink_new_data *sink_new_data = sink_or_source_new_data; - - pa_assert_se(pa_hashmap_put(sink_new_data->ports, u->output_port->name, u->output_port) >= 0); - pa_device_port_ref(u->output_port); - } else { - pa_source_new_data *source_new_data = sink_or_source_new_data; - - pa_assert_se(pa_hashmap_put(source_new_data->ports, u->input_port->name, u->input_port) >= 0); - pa_device_port_ref(u->input_port); - } -} - static int sink_set_port_cb(pa_sink *s, pa_device_port *p) { return 0; } @@ -1559,7 +1545,6 @@ static int add_sink(struct userdata *u) { pa_sink_new_data_done(&data); return -1; } - connect_ports(u, &data, PA_DIRECTION_OUTPUT); if (!u->transport_acquired) switch (u->profile) { @@ -1633,8 +1618,6 @@ static int add_source(struct userdata *u) { return -1; } - connect_ports(u, &data, PA_DIRECTION_INPUT); - if (!u->transport_acquired) switch (u->profile) { case PROFILE_HSP: diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 8bd9544..1045952 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -140,9 +140,17 @@ void pa_sink_new_data_set_port(pa_sink_new_data *data, const char *port) { } void pa_sink_new_data_set_prototype(pa_sink_new_data *data, pa_device_prototype *prototype) { + pa_device_port *port; + void *state; + pa_assert(data); + pa_assert(prototype); + pa_assert(!data->prototype); data->prototype = prototype; + + PA_HASHMAP_FOREACH(port, prototype->ports, state) + pa_hashmap_put(data->ports, port->name, pa_device_port_ref(port)); } void pa_sink_new_data_done(pa_sink_new_data *data) { diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 25b7a78..08a816b 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -137,9 +137,17 @@ void pa_source_new_data_set_port(pa_source_new_data *data, const char *port) { } void pa_source_new_data_set_prototype(pa_source_new_data *data, pa_device_prototype *prototype) { + pa_device_port *port; + void *state; + pa_assert(data); + pa_assert(prototype); + pa_assert(!data->prototype); data->prototype = prototype; + + PA_HASHMAP_FOREACH(port, prototype->ports, state) + pa_hashmap_put(data->ports, port->name, pa_device_port_ref(port)); } void pa_source_new_data_done(pa_source_new_data *data) { -- 1.8.3.1