It's a valid assumption nowadays, because the hashmap is created in pa_device_port_new(). --- src/modules/module-switch-on-port-available.c | 63 ++++++++++++------------- src/pulsecore/protocol-native.c | 13 +++-- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c index 5788825..4c3d4af 100644 --- a/src/modules/module-switch-on-port-available.c +++ b/src/modules/module-switch-on-port-available.c @@ -55,47 +55,47 @@ static pa_bool_t try_to_switch_profile(pa_card *card, pa_device_port *port) { pa_log_debug("Finding best profile"); - if (port->profiles) - PA_HASHMAP_FOREACH(profile, port->profiles, state) { - if (best_profile && best_profile->priority >= profile->priority) - continue; + PA_HASHMAP_FOREACH(profile, port->profiles, state) { + if (best_profile && best_profile->priority >= profile->priority) + continue; + /* We make a best effort to keep other direction unchanged */ + if (!port->is_input) { + if (card->active_profile->n_sources != profile->n_sources) + continue; - /* We make a best effort to keep other direction unchanged */ - if (!port->is_input) { - if (card->active_profile->n_sources != profile->n_sources) - continue; + if (card->active_profile->max_source_channels != profile->max_source_channels) + continue; + } - if (card->active_profile->max_source_channels != profile->max_source_channels) - continue; - } + if (!port->is_output) { + if (card->active_profile->n_sinks != profile->n_sinks) + continue; - if (!port->is_output) { - if (card->active_profile->n_sinks != profile->n_sinks) - continue; + if (card->active_profile->max_sink_channels != profile->max_sink_channels) + continue; + } - if (card->active_profile->max_sink_channels != profile->max_sink_channels) - continue; - } + if (port->is_output) { + /* Try not to switch to HDMI sinks from analog when HDMI is becoming available */ + uint32_t state2; + pa_sink *sink; + pa_bool_t found_active_port = FALSE; - if (port->is_output) { - /* Try not to switch to HDMI sinks from analog when HDMI is becoming available */ - uint32_t state2; - pa_sink *sink; - pa_bool_t found_active_port = FALSE; - PA_IDXSET_FOREACH(sink, card->sinks, state2) { - if (!sink->active_port) - continue; - if (sink->active_port->available != PA_PORT_AVAILABLE_NO) - found_active_port = TRUE; - } - if (found_active_port) + PA_IDXSET_FOREACH(sink, card->sinks, state2) { + if (!sink->active_port) continue; + if (sink->active_port->available != PA_PORT_AVAILABLE_NO) + found_active_port = TRUE; } - best_profile = profile; + if (found_active_port) + continue; } + best_profile = profile; + } + if (!best_profile) { pa_log_debug("No suitable profile found"); return FALSE; @@ -152,8 +152,7 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port find_sink_and_source(card, port, &sink, &source); - is_active_profile = port->profiles && - card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name); + is_active_profile = card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name); is_active_port = (sink && sink->active_port == port) || (source && source->active_port == port); if (port->available == PA_PORT_AVAILABLE_NO && !is_active_port) diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 5fbc4a0..bdd79aa 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -3262,6 +3262,8 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car pa_tagstruct_putu32(t, pa_hashmap_size(card->ports)); PA_HASHMAP_FOREACH(port, card->ports, state) { + void *state2; + pa_tagstruct_puts(t, port->name); pa_tagstruct_puts(t, port->description); pa_tagstruct_putu32(t, port->priority); @@ -3269,13 +3271,10 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car pa_tagstruct_putu8(t, /* FIXME: port->direction */ (port->is_input ? PA_DIRECTION_INPUT : 0) | (port->is_output ? PA_DIRECTION_OUTPUT : 0)); pa_tagstruct_put_proplist(t, proplist); - if (port->profiles) { - void* state2; - pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles)); - PA_HASHMAP_FOREACH(p, port->profiles, state2) - pa_tagstruct_puts(t, p->name); - } else - pa_tagstruct_putu32(t, 0); + pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles)); + + PA_HASHMAP_FOREACH(p, port->profiles, state2) + pa_tagstruct_puts(t, p->name); } pa_proplist_free(proplist); -- 1.7.10