mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04: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;
|
||||
|
|
|
|||
|
|
@ -3114,19 +3114,17 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
|
|||
}
|
||||
|
||||
if (c->version >= 16) {
|
||||
pa_tagstruct_putu32(t, sink->ports ? pa_hashmap_size(sink->ports) : 0);
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
|
||||
if (sink->ports) {
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
pa_tagstruct_putu32(t, pa_hashmap_size(sink->ports));
|
||||
|
||||
PA_HASHMAP_FOREACH(p, sink->ports, state) {
|
||||
pa_tagstruct_puts(t, p->name);
|
||||
pa_tagstruct_puts(t, p->description);
|
||||
pa_tagstruct_putu32(t, p->priority);
|
||||
if (c->version >= 24)
|
||||
pa_tagstruct_putu32(t, p->available);
|
||||
}
|
||||
PA_HASHMAP_FOREACH(p, sink->ports, state) {
|
||||
pa_tagstruct_puts(t, p->name);
|
||||
pa_tagstruct_puts(t, p->description);
|
||||
pa_tagstruct_putu32(t, p->priority);
|
||||
if (c->version >= 24)
|
||||
pa_tagstruct_putu32(t, p->available);
|
||||
}
|
||||
|
||||
pa_tagstruct_puts(t, sink->active_port ? sink->active_port->name : NULL);
|
||||
|
|
@ -3186,20 +3184,17 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
|
|||
}
|
||||
|
||||
if (c->version >= 16) {
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
|
||||
pa_tagstruct_putu32(t, source->ports ? pa_hashmap_size(source->ports) : 0);
|
||||
pa_tagstruct_putu32(t, pa_hashmap_size(source->ports));
|
||||
|
||||
if (source->ports) {
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
|
||||
PA_HASHMAP_FOREACH(p, source->ports, state) {
|
||||
pa_tagstruct_puts(t, p->name);
|
||||
pa_tagstruct_puts(t, p->description);
|
||||
pa_tagstruct_putu32(t, p->priority);
|
||||
if (c->version >= 24)
|
||||
pa_tagstruct_putu32(t, p->available);
|
||||
}
|
||||
PA_HASHMAP_FOREACH(p, source->ports, state) {
|
||||
pa_tagstruct_puts(t, p->name);
|
||||
pa_tagstruct_puts(t, p->description);
|
||||
pa_tagstruct_putu32(t, p->priority);
|
||||
if (c->version >= 24)
|
||||
pa_tagstruct_putu32(t, p->available);
|
||||
}
|
||||
|
||||
pa_tagstruct_puts(t, source->active_port ? source->active_port->name : NULL);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data) {
|
|||
|
||||
pa_zero(*data);
|
||||
data->proplist = pa_proplist_new();
|
||||
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
@ -295,11 +296,11 @@ pa_sink* pa_sink_new(
|
|||
s->active_port = NULL;
|
||||
s->save_port = FALSE;
|
||||
|
||||
if (data->active_port && s->ports)
|
||||
if (data->active_port)
|
||||
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
|
||||
s->save_port = data->save_port;
|
||||
|
||||
if (!s->active_port && s->ports) {
|
||||
if (!s->active_port) {
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
|
||||
|
|
@ -3300,7 +3301,7 @@ int pa_sink_set_port(pa_sink *s, const char *name, pa_bool_t save) {
|
|||
return -PA_ERR_NOTIMPLEMENTED;
|
||||
}
|
||||
|
||||
if (!s->ports || !name)
|
||||
if (!name)
|
||||
return -PA_ERR_NOENTITY;
|
||||
|
||||
if (!(port = pa_hashmap_get(s->ports, name)))
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data) {
|
|||
|
||||
pa_zero(*data);
|
||||
data->proplist = pa_proplist_new();
|
||||
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
@ -283,11 +284,11 @@ pa_source* pa_source_new(
|
|||
s->active_port = NULL;
|
||||
s->save_port = FALSE;
|
||||
|
||||
if (data->active_port && s->ports)
|
||||
if (data->active_port)
|
||||
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
|
||||
s->save_port = data->save_port;
|
||||
|
||||
if (!s->active_port && s->ports) {
|
||||
if (!s->active_port) {
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
|
||||
|
|
@ -2570,7 +2571,7 @@ int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save) {
|
|||
return -PA_ERR_NOTIMPLEMENTED;
|
||||
}
|
||||
|
||||
if (!s->ports || !name)
|
||||
if (!name)
|
||||
return -PA_ERR_NOENTITY;
|
||||
|
||||
if (!(port = pa_hashmap_get(s->ports, name)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue