[pulseaudio-commits] src/modules

Arun Raghavan arun at kemper.freedesktop.org
Fri Sep 23 12:24:35 UTC 2016


 src/modules/bluetooth/module-bluetooth-policy.c |   60 +++++++++++++-----------
 1 file changed, 33 insertions(+), 27 deletions(-)

New commits:
commit e32a462cc4201d9c3c7305d0f806d16a09f08875
Author: Pali Rohár <pali.rohar at gmail.com>
Date:   Sun Sep 11 17:16:38 2016 +0200

    bluetooth: Add support for automatic switch between hsp and a2dp profiles also for bluez5
    
    Bluez5 uses different profile names as bluez4, so we need to check for
    a2dp_sink and headset_head_unit too for bluez5 support.
    
    Signed-off-by: Pali Rohár <pali.rohar at gmail.com>

diff --git a/src/modules/bluetooth/module-bluetooth-policy.c b/src/modules/bluetooth/module-bluetooth-policy.c
index 68c8ab4..e62a114 100644
--- a/src/modules/bluetooth/module-bluetooth-policy.c
+++ b/src/modules/bluetooth/module-bluetooth-policy.c
@@ -144,23 +144,29 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void *
     return PA_HOOK_OK;
 }
 
-static void card_set_profile(struct userdata *u, pa_card *card, const char *to_profile, bool revert_to_a2dp)
+static void card_set_profile(struct userdata *u, pa_card *card, bool revert_to_a2dp)
 {
     pa_card_profile *profile;
     void *state;
 
-    /* Find available to_profile and activate it */
+    /* Find available profile and activate it */
     PA_HASHMAP_FOREACH(profile, card->profiles, state) {
-        if (!pa_streq(profile->name, to_profile))
-            continue;
-
         if (profile->available == PA_AVAILABLE_NO)
             continue;
 
-        pa_log_debug("Setting card '%s' to profile '%s'", card->name, to_profile);
+        /* Check for correct profile based on revert_to_a2dp */
+        if (revert_to_a2dp) {
+            if (!pa_streq(profile->name, "a2dp") && !pa_streq(profile->name, "a2dp_sink"))
+                continue;
+        } else {
+            if (!pa_streq(profile->name, "hsp") && !pa_streq(profile->name, "headset_head_unit"))
+                continue;
+        }
+
+        pa_log_debug("Setting card '%s' to profile '%s'", card->name, profile->name);
 
         if (pa_card_set_profile(card, profile, false) != 0) {
-            pa_log_warn("Could not set profile '%s'", to_profile);
+            pa_log_warn("Could not set profile '%s'", profile->name);
             continue;
         }
 
@@ -175,18 +181,8 @@ static void card_set_profile(struct userdata *u, pa_card *card, const char *to_p
 /* Switch profile for one card */
 static void switch_profile(pa_card *card, bool revert_to_a2dp, void *userdata) {
     struct userdata *u = userdata;
-    const char *from_profile;
-    const char *to_profile;
     const char *s;
 
-    if (revert_to_a2dp) {
-        from_profile = "hsp";
-        to_profile = "a2dp";
-    } else {
-        from_profile = "a2dp";
-        to_profile = "hsp";
-    }
-
     /* Only consider bluetooth cards */
     s = pa_proplist_gets(card->proplist, PA_PROP_DEVICE_BUS);
     if (!s || !pa_streq(s, "bluetooth"))
@@ -196,17 +192,25 @@ static void switch_profile(pa_card *card, bool revert_to_a2dp, void *userdata) {
         /* In revert_to_a2dp phase only consider cards with will_need_revert flag and remove it */
         if (!pa_hashmap_remove(u->will_need_revert_card_map, card))
             return;
-    }
 
-    /* Skip card if does not have active from_profile */
-    if (!pa_streq(card->active_profile->name, from_profile))
-        return;
+        /* Skip card if does not have active hsp profile */
+        if (!pa_streq(card->active_profile->name, "hsp") && !pa_streq(card->active_profile->name, "headset_head_unit"))
+            return;
 
-    /* Skip card if already has active profile to_profile */
-    if (pa_streq(card->active_profile->name, to_profile))
-        return;
+        /* Skip card if already has active a2dp profile */
+        if (pa_streq(card->active_profile->name, "a2dp") || pa_streq(card->active_profile->name, "a2dp_sink"))
+            return;
+    } else {
+        /* Skip card if does not have active a2dp profile */
+        if (!pa_streq(card->active_profile->name, "a2dp") && !pa_streq(card->active_profile->name, "a2dp_sink"))
+            return;
+
+        /* Skip card if already has active hsp profile */
+        if (pa_streq(card->active_profile->name, "hsp") || pa_streq(card->active_profile->name, "headset_head_unit"))
+            return;
+    }
 
-    card_set_profile(u, card, to_profile, revert_to_a2dp);
+    card_set_profile(u, card, revert_to_a2dp);
 }
 
 /* Return true if we should ignore this source output */
@@ -287,11 +291,13 @@ static pa_hook_result_t card_init_profile_hook_callback(pa_core *c, pa_card *car
         return PA_HOOK_OK;
 
     /* Ignore card if has already set other initial profile than a2dp */
-    if (card->active_profile && !pa_streq(card->active_profile->name, "a2dp"))
+    if (card->active_profile &&
+        !pa_streq(card->active_profile->name, "a2dp") &&
+        !pa_streq(card->active_profile->name, "a2dp_sink"))
         return PA_HOOK_OK;
 
     /* Set initial profile to hsp */
-    card_set_profile(u, card, "hsp", false);
+    card_set_profile(u, card, false);
 
     /* Flag this card for will_need_revert */
     pa_hashmap_put(u->will_need_revert_card_map, card, PA_INT_TO_PTR(1));



More information about the pulseaudio-commits mailing list