[pulseaudio-discuss] [PATCH 15/17] card: Add the profiles to ports in pa_card_new_data_add_profile()
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Mon Dec 30 05:04:50 PST 2013
Card implementations don't need to do that themselves any more.
---
src/modules/alsa/alsa-mixer.c | 11 +++--------
src/modules/alsa/alsa-mixer.h | 2 +-
src/modules/alsa/alsa-ucm.c | 19 +++++--------------
src/modules/alsa/alsa-ucm.h | 1 -
src/modules/alsa/module-alsa-card.c | 8 ++++----
src/modules/bluetooth/module-bluetooth-device.c | 8 --------
src/pulsecore/card.c | 18 ++++++++++++++++++
src/pulsecore/card.h | 1 +
8 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index c5af98e..61d292d 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4526,7 +4526,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_card_profile *cp,
pa_hashmap *extra /* sink/source ports */) {
char *name = NULL;
@@ -4543,9 +4542,6 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
pa_assert(p);
pa_xfree(name);
- if (cp)
- pa_hashmap_put(p->profiles, cp->name, cp);
-
if (extra) {
pa_hashmap_put(extra, p->name, p);
pa_device_port_ref(p);
@@ -4556,7 +4552,6 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
void pa_alsa_path_set_add_ports(
pa_alsa_path_set *ps,
- pa_card_profile *cp,
pa_hashmap *ports, /* card ports */
pa_hashmap *extra /* sink/source ports */) {
@@ -4572,11 +4567,11 @@ void pa_alsa_path_set_add_ports(
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, cp, extra);
+ 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, cp, extra);
+ device_port_alsa_init(ports, path, s, extra);
}
}
}
@@ -4594,7 +4589,7 @@ void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_c
if (ps->paths && pa_hashmap_size(ps->paths) > 0) {
pa_assert(card);
- pa_alsa_path_set_add_ports(ps, NULL, card->ports, ports);
+ pa_alsa_path_set_add_ports(ps, card->ports, ports);
}
pa_log_debug("Added %u ports", pa_hashmap_size(ports));
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index 0a2a4e5..e44efa0 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -357,7 +357,7 @@ struct pa_alsa_port_data {
};
void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_card *card);
-void pa_alsa_path_set_add_ports(pa_alsa_path_set *ps, pa_card_profile *cp, pa_hashmap *ports, pa_hashmap *extra);
+void pa_alsa_path_set_add_ports(pa_alsa_path_set *ps, pa_hashmap *ports, pa_hashmap *extra);
void pa_alsa_profile_set_create_ports(pa_core *core, pa_alsa_profile_set *profile_set, pa_hashmap *ports);
#endif
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index 2924506..e7fde1a 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -671,7 +671,6 @@ static void ucm_add_port_combination(
pa_alsa_ucm_device **pdevices,
int num,
pa_hashmap *ports,
- pa_card_profile *cp,
pa_core *core) {
pa_device_port *port;
@@ -700,11 +699,6 @@ static void ucm_add_port_combination(
pa_assert(port);
pa_xfree(name);
- if (cp) {
- pa_log_debug("Adding profile %s to port %s.", cp->name, port->name);
- pa_hashmap_put(port->profiles, cp->name, cp);
- }
-
if (hash) {
pa_hashmap_put(hash, port->name, port);
pa_device_port_ref(port);
@@ -796,7 +790,6 @@ static void ucm_add_ports_combination(
int dev_num,
uint32_t map_index,
pa_hashmap *ports,
- pa_card_profile *cp,
pa_core *core) {
pa_alsa_ucm_device *dev;
@@ -810,13 +803,13 @@ static void ucm_add_ports_combination(
/* 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, cp, core);
+ 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, cp, core);
+ 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, cp, core);
+ ucm_add_ports_combination(hash, context, is_sink, pdevices, dev_num, idx, ports, core);
}
static char* merge_roles(const char *cur, const char *add) {
@@ -853,7 +846,6 @@ void pa_alsa_ucm_add_ports_combination(
pa_alsa_ucm_mapping_context *context,
bool is_sink,
pa_hashmap *ports,
- pa_card_profile *cp,
pa_core *core) {
pa_alsa_ucm_device **pdevices;
@@ -862,7 +854,7 @@ void pa_alsa_ucm_add_ports_combination(
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, cp, core);
+ ucm_add_ports_combination(p, context, is_sink, pdevices, 0, PA_IDXSET_INVALID, ports, core);
pa_xfree(pdevices);
}
}
@@ -885,7 +877,7 @@ void pa_alsa_ucm_add_ports(
pa_assert(*p);
/* add ports first */
- pa_alsa_ucm_add_ports_combination(*p, context, is_sink, card->ports, NULL, card->core);
+ pa_alsa_ucm_add_ports_combination(*p, context, is_sink, card->ports, card->core);
/* then set property PA_PROP_DEVICE_INTENDED_ROLES */
merged_roles = pa_xstrdup(pa_proplist_gets(proplist, PA_PROP_DEVICE_INTENDED_ROLES));
@@ -1779,7 +1771,6 @@ void pa_alsa_ucm_add_ports_combination(
pa_alsa_ucm_mapping_context *context,
bool is_sink,
pa_hashmap *ports,
- pa_card_profile *cp,
pa_core *core) {
}
diff --git a/src/modules/alsa/alsa-ucm.h b/src/modules/alsa/alsa-ucm.h
index 605b1a3..42e82b0 100644
--- a/src/modules/alsa/alsa-ucm.h
+++ b/src/modules/alsa/alsa-ucm.h
@@ -109,7 +109,6 @@ void pa_alsa_ucm_add_ports_combination(
pa_alsa_ucm_mapping_context *context,
bool is_sink,
pa_hashmap *ports,
- pa_card_profile *cp,
pa_core *core);
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 c427386..64c6fa0 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -180,9 +180,9 @@ static void add_profiles(struct userdata *u, pa_card_new_data *data) {
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, cp, u->core);
+ 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, cp, data->ports, NULL);
+ 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;
}
@@ -193,9 +193,9 @@ static void add_profiles(struct userdata *u, pa_card_new_data *data) {
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, cp, u->core);
+ 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, cp, data->ports, NULL);
+ 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 676f36a..05ff5a1 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2209,7 +2209,6 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
pa_hashmap_put(p->sink_prototypes, u->sink_prototype, u->sink_prototype);
p->max_sink_channels = 2;
p->max_source_channels = 0;
- pa_hashmap_put(u->output_port->profiles, p->name, p);
d = PA_CARD_PROFILE_DATA(p);
*d = PROFILE_A2DP;
@@ -2219,7 +2218,6 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
pa_hashmap_put(p->source_prototypes, u->source_prototype, u->source_prototype);
p->max_sink_channels = 0;
p->max_source_channels = 2;
- pa_hashmap_put(u->input_port->profiles, p->name, p);
d = PA_CARD_PROFILE_DATA(p);
*d = PROFILE_A2DP_SOURCE;
@@ -2234,9 +2232,6 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
p->max_source_channels = 1;
}
- pa_hashmap_put(u->input_port->profiles, p->name, p);
- pa_hashmap_put(u->output_port->profiles, p->name, p);
-
d = PA_CARD_PROFILE_DATA(p);
*d = PROFILE_HSP;
} else if (profile == PROFILE_HFGW) {
@@ -2250,9 +2245,6 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
p->max_source_channels = 1;
}
- pa_hashmap_put(u->input_port->profiles, p->name, p);
- pa_hashmap_put(u->output_port->profiles, p->name, p);
-
d = PA_CARD_PROFILE_DATA(p);
*d = PROFILE_HFGW;
}
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index 3e2ec69..3de2787 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -143,10 +143,19 @@ void pa_card_new_data_add_device_prototype(pa_card_new_data *data, pa_device_pro
}
void pa_card_new_data_add_profile(pa_card_new_data *data, pa_card_profile *profile) {
+ pa_device_prototype *prototype;
+ pa_device_port *port;
+ void *state, *state2;
+
pa_assert(data);
pa_assert(profile);
pa_assert_se(pa_hashmap_put(data->profiles, profile->name, profile) >= 0);
+
+ PA_HASHMAP_FOREACH(prototype, profile->sink_prototypes, state) {
+ PA_HASHMAP_FOREACH(port, prototype->ports, state2)
+ pa_hashmap_put(port->profiles, profile->name, profile);
+ }
}
void pa_card_new_data_set_profile(pa_card_new_data *data, const char *profile) {
@@ -301,6 +310,10 @@ void pa_card_free(pa_card *c) {
}
void pa_card_add_profile(pa_card *c, pa_card_profile *profile) {
+ pa_device_prototype *prototype;
+ pa_device_port *port;
+ void *state, *state2;
+
pa_assert(c);
pa_assert(profile);
@@ -308,6 +321,11 @@ void pa_card_add_profile(pa_card *c, pa_card_profile *profile) {
pa_assert_se(pa_hashmap_put(c->profiles, profile->name, profile) >= 0);
profile->card = c;
+ PA_HASHMAP_FOREACH(prototype, profile->sink_prototypes, state) {
+ PA_HASHMAP_FOREACH(port, prototype->ports, state2)
+ pa_hashmap_put(port->profiles, profile->name, profile);
+ }
+
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], profile);
diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
index e46b86d..241d404 100644
--- a/src/pulsecore/card.h
+++ b/src/pulsecore/card.h
@@ -65,6 +65,7 @@ typedef struct pa_card_profile {
unsigned priority;
pa_available_t available; /* PA_AVAILABLE_UNKNOWN, PA_AVAILABLE_NO or PA_AVAILABLE_YES */
+ /* Populate these before calling pa_card_new_data_add_profile(). */
pa_hashmap *sink_prototypes; /* pa_device_prototype -> pa_device_prototype (hashmap-as-a-set) */
pa_hashmap *source_prototypes; /* pa_device_prototype -> pa_device_prototype (hashmap-as-a-set) */
--
1.8.3.1
More information about the pulseaudio-discuss
mailing list