[pulseaudio-discuss] [RFC 2/2] bluetooth: Rank profiles based on available flag

Luiz Augusto von Dentz luiz.dentz at gmail.com
Tue Nov 12 03:02:44 PST 2013


From: Luiz Augusto von Dentz <luiz.von.dentz at intel.com>

This makes module-bluetooth-policy to rank profiles based on their
available flag and only consider their priority in case profiles have
the same rank.
---
 src/modules/bluetooth/module-bluetooth-policy.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-policy.c b/src/modules/bluetooth/module-bluetooth-policy.c
index 4a90db7..864d10d 100644
--- a/src/modules/bluetooth/module-bluetooth-policy.c
+++ b/src/modules/bluetooth/module-bluetooth-policy.c
@@ -137,21 +137,22 @@ static pa_card_profile *find_best_profile(pa_card *card) {
     void *state;
     pa_card_profile *profile;
     pa_card_profile *result = card->active_profile;
-    pa_card_profile *off;
-
-    pa_assert_se(off = pa_hashmap_get(card->profiles, "off"));
 
     PA_HASHMAP_FOREACH(profile, card->profiles, state) {
-        if (profile->available == PA_AVAILABLE_NO || profile == off)
+        if (result == profile)
+            continue;
+
+        if (profile->available > result->available) {
+            result = profile;
             continue;
+        }
 
-        if (result == NULL ||
-            (profile->available == PA_AVAILABLE_YES && result->available == PA_AVAILABLE_UNKNOWN) ||
-            (profile->available == result->available && profile->priority > profile->priority))
+        if (profile->available == result->available &&
+            profile->priority > profile->priority)
             result = profile;
     }
 
-    return result ? result : off;
+    return result;
 }
 
 static pa_hook_result_t profile_available_hook_callback(pa_core *c, pa_card_profile *profile, void *userdata) {
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list