mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-07 13:30:03 -05:00
sink, source: Always create a hashmap for ports.
Having the hashmap sometimes NULL requires a lot of checking here and there, so ensuring that the hashmap is always non-NULL simplifies the code.
This commit is contained in:
parent
21c6c70438
commit
1a6da64b16
10 changed files with 56 additions and 66 deletions
|
|
@ -4462,17 +4462,21 @@ void pa_alsa_path_set_add_ports(
|
|||
}
|
||||
}
|
||||
|
||||
void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps, pa_card *card) {
|
||||
void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_card *card) {
|
||||
pa_hashmap *ports;
|
||||
|
||||
pa_assert(p);
|
||||
pa_assert(!*p);
|
||||
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);
|
||||
*p = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
pa_alsa_path_set_add_ports(ps, NULL, card->ports, *p, card->core);
|
||||
pa_alsa_path_set_add_ports(ps, NULL, card->ports, ports, card->core);
|
||||
}
|
||||
|
||||
pa_log_debug("Added %u ports", *p ? pa_hashmap_size(*p) : 0);
|
||||
pa_log_debug("Added %u ports", pa_hashmap_size(ports));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ struct pa_alsa_port_data {
|
|||
pa_alsa_setting *setting;
|
||||
};
|
||||
|
||||
void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps, pa_card *card);
|
||||
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, pa_core *core);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2226,7 +2226,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
|
|||
}
|
||||
|
||||
if (u->mixer_path_set)
|
||||
pa_alsa_add_ports(&data.ports, u->mixer_path_set, card);
|
||||
pa_alsa_add_ports(&data, u->mixer_path_set, card);
|
||||
|
||||
u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE | PA_SINK_LATENCY | (u->use_tsched ? PA_SINK_DYNAMIC_LATENCY : 0) |
|
||||
(set_formats ? PA_SINK_SET_FORMATS : 0));
|
||||
|
|
|
|||
|
|
@ -1952,7 +1952,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
|
|||
}
|
||||
|
||||
if (u->mixer_path_set)
|
||||
pa_alsa_add_ports(&data.ports, u->mixer_path_set, card);
|
||||
pa_alsa_add_ports(&data, u->mixer_path_set, card);
|
||||
|
||||
u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY|(u->use_tsched ? PA_SOURCE_DYNAMIC_LATENCY : 0));
|
||||
pa_source_new_data_done(&data);
|
||||
|
|
|
|||
|
|
@ -2073,13 +2073,10 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_
|
|||
} data;
|
||||
pa_device_port *port;
|
||||
|
||||
if (direction == PA_DIRECTION_OUTPUT) {
|
||||
if (direction == PA_DIRECTION_OUTPUT)
|
||||
data.sink_new_data = sink_or_source_new_data;
|
||||
data.sink_new_data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
} else {
|
||||
else
|
||||
data.source_new_data = sink_or_source_new_data;
|
||||
data.source_new_data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
}
|
||||
|
||||
switch (u->profile) {
|
||||
case PROFILE_A2DP:
|
||||
|
|
@ -2118,7 +2115,7 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_
|
|||
|
||||
default:
|
||||
pa_assert_not_reached();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Run from main thread */
|
||||
|
|
|
|||
|
|
@ -1189,6 +1189,8 @@ static void subscription_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t
|
|||
|
||||
pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_sink *sink) {
|
||||
pa_dbusiface_device *d = NULL;
|
||||
pa_device_port *port;
|
||||
void *state;
|
||||
|
||||
pa_assert(core);
|
||||
pa_assert(sink);
|
||||
|
|
@ -1203,20 +1205,14 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
|
|||
d->sink_state = pa_sink_get_state(sink);
|
||||
d->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
d->next_port_index = 0;
|
||||
d->active_port = NULL;
|
||||
d->active_port = sink->active_port;
|
||||
d->proplist = pa_proplist_copy(sink->proplist);
|
||||
d->dbus_protocol = pa_dbus_protocol_get(sink->core);
|
||||
d->subscription = pa_subscription_new(sink->core, PA_SUBSCRIPTION_MASK_SINK, subscription_cb, d);
|
||||
|
||||
if (sink->ports) {
|
||||
pa_device_port *port;
|
||||
void *state = NULL;
|
||||
|
||||
PA_HASHMAP_FOREACH(port, sink->ports, state) {
|
||||
pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, sink->core, port, d->next_port_index++);
|
||||
pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
|
||||
}
|
||||
pa_assert_se(d->active_port = sink->active_port);
|
||||
PA_HASHMAP_FOREACH(port, sink->ports, state) {
|
||||
pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, sink->core, port, d->next_port_index++);
|
||||
pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
|
||||
}
|
||||
|
||||
pa_assert_se(pa_dbus_protocol_add_interface(d->dbus_protocol, d->path, &device_interface_info, d) >= 0);
|
||||
|
|
@ -1227,6 +1223,8 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
|
|||
|
||||
pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_source *source) {
|
||||
pa_dbusiface_device *d = NULL;
|
||||
pa_device_port *port;
|
||||
void *state;
|
||||
|
||||
pa_assert(core);
|
||||
pa_assert(source);
|
||||
|
|
@ -1241,20 +1239,14 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
|
|||
d->source_state = pa_source_get_state(source);
|
||||
d->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
d->next_port_index = 0;
|
||||
d->active_port = NULL;
|
||||
d->active_port = source->active_port;
|
||||
d->proplist = pa_proplist_copy(source->proplist);
|
||||
d->dbus_protocol = pa_dbus_protocol_get(source->core);
|
||||
d->subscription = pa_subscription_new(source->core, PA_SUBSCRIPTION_MASK_SOURCE, subscription_cb, d);
|
||||
|
||||
if (source->ports) {
|
||||
pa_device_port *port;
|
||||
void *state = NULL;
|
||||
|
||||
PA_HASHMAP_FOREACH(port, source->ports, state) {
|
||||
pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, source->core, port, d->next_port_index++);
|
||||
pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
|
||||
}
|
||||
pa_assert_se(d->active_port = source->active_port);
|
||||
PA_HASHMAP_FOREACH(port, source->ports, state) {
|
||||
pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, source->core, port, d->next_port_index++);
|
||||
pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
|
||||
}
|
||||
|
||||
pa_assert_se(pa_dbus_protocol_add_interface(d->dbus_protocol, d->path, &device_interface_info, d) >= 0);
|
||||
|
|
|
|||
|
|
@ -121,12 +121,12 @@ static void find_sink_and_source(pa_card *card, pa_device_port *port, pa_sink **
|
|||
|
||||
if (port->is_output)
|
||||
PA_IDXSET_FOREACH(sink, card->sinks, state)
|
||||
if (sink->ports && port == pa_hashmap_get(sink->ports, port->name))
|
||||
if (port == pa_hashmap_get(sink->ports, port->name))
|
||||
break;
|
||||
|
||||
if (port->is_input)
|
||||
PA_IDXSET_FOREACH(source, card->sources, state)
|
||||
if (source->ports && port == pa_hashmap_get(source->ports, port->name))
|
||||
if (port == pa_hashmap_get(source->ports, port->name))
|
||||
break;
|
||||
|
||||
*si = sink;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue