From d184b54d7c93c18d7211cc4bf4b6a0bac0581e44 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Fri, 8 Jun 2012 21:49:11 +0300 Subject: [PATCH] Assume that the profiles hashmap of ports is always non-NULL. 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 57888257..4c3d4afa 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 cb322ccd..bb61f75d 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -3261,6 +3261,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); @@ -3268,13 +3270,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, port->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); } } else -- 2.11.4.GIT