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
|
|
@ -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