[pulseaudio-discuss] [RFC v0 4/5] bluetooth: Use profile availability to auto-switch profiles

Tanu Kaskinen tanuk at iki.fi
Sat Feb 16 08:34:14 PST 2013


On Wed, 2013-02-13 at 14:48 +0100, Mikel Astiz wrote:
> -static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port *port, void *userdata) {
> +static pa_hook_result_t profile_available_hook_callback(pa_core *c, pa_card_profile *profile, void *userdata) {
>      pa_card *card;
>      const char *s;
> -    uint32_t state;
>      bool is_active_profile;
> -    pa_device_port *port2;
> -
> -    PA_IDXSET_FOREACH(card, c->cards, state)
> -        if (port == pa_hashmap_get(card->ports, port->name))
> -            break;
> +    pa_card_profile *selected_profile;
>  
> -    if (!card) {
> -        pa_log_warn("Did not find port %s in array of cards", port->name);
> -        return PA_HOOK_OK;
> -    }
> +    pa_assert(c);
> +    pa_assert(profile);
> +    pa_assert_se((card = profile->card));
>  
>      /* Only consider bluetooth cards */
>      s = pa_proplist_gets(card->proplist, PA_PROP_DEVICE_BUS);
> @@ -188,35 +167,46 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port
>          return PA_HOOK_OK;
>  
>      /* Do not automatically switch profiles for headsets, just in case */
> -    if (pa_hashmap_get(port->profiles, "hsp") || pa_hashmap_get(port->profiles, "a2dp"))
> +    if (pa_streq(profile->name, "hsp") || pa_streq(profile->name, "a2dp"))
>          return PA_HOOK_OK;
>  
> -    is_active_profile = card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name);
> +    is_active_profile = card->active_profile == profile;
>  
> -    if (is_active_profile && port->available == PA_PORT_AVAILABLE_YES)
> -        return PA_HOOK_OK;
> +    if (profile->available == PA_PROFILE_AVAILABLE_YES) {
> +        if (is_active_profile)
> +            return PA_HOOK_OK;
>  
> -    if (!is_active_profile && port->available != PA_PORT_AVAILABLE_YES)
> -        return PA_HOOK_OK;
> +        if (card->active_profile && card->active_profile->available == PA_PROFILE_AVAILABLE_YES &&
> +            card->active_profile->priority >= profile->priority)
> +            return PA_HOOK_OK;
>  
> -    if ((port2 = find_best_port(card->ports)) == NULL)
> -        return PA_HOOK_OK;
> +        selected_profile = profile;
> +    } else {
> +        if (!is_active_profile)
> +            return PA_HOOK_OK;
> +
> +        if (!(selected_profile = find_best_profile(card->profiles)))
> +            return PA_HOOK_OK;

I don't think find_best_profile() can return NULL. The "off" profile is
always an option, if nothing else is available.

Also, does it make sense to switch the profile if the currently active
profile availability changes from "yes" to "unknown" and the only other
profile with "yes" availability is "off"?

-- 
Tanu



More information about the pulseaudio-discuss mailing list