[pulseaudio-discuss] [PATCH 2/4] bluetooth: Add specific form factor for phones

Mikel Astiz mikel.astiz.oss at gmail.com
Tue Feb 19 01:33:48 PST 2013


From: Mikel Astiz <mikel.astiz at bmw-carit.de>

When a phone is paired, use PA_BT_FORM_FACTOR_PHONE to properly specify
its form factor.
---
 src/modules/bluetooth/bluetooth-util.c | 25 +++++++++++++++++--------
 src/modules/bluetooth/bluetooth-util.h |  1 +
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index faf1c41..bf1c98f 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1799,7 +1799,7 @@ pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hoo
 }
 
 pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class) {
-    unsigned i;
+    unsigned major, minor;
     pa_bt_form_factor_t r;
 
     static const pa_bt_form_factor_t table[] = {
@@ -1813,16 +1813,23 @@ pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class) {
         [10] = PA_BT_FORM_FACTOR_HIFI
     };
 
-    if (((class >> 8) & 31) != 4)
-        return PA_BT_FORM_FACTOR_UNKNOWN;
+    major = (class >> 8) & 31;
+    minor = (class >> 2) & 63;
 
-    if ((i = (class >> 2) & 63) >= PA_ELEMENTSOF(table))
-        r =  PA_BT_FORM_FACTOR_UNKNOWN;
-    else
-        r = table[i];
+    switch (major) {
+        case 2:
+            return PA_BT_FORM_FACTOR_PHONE;
+        case 4:
+            break;
+        default:
+            pa_log_debug("Unknown Bluetooth major device class %u", major);
+            return PA_BT_FORM_FACTOR_UNKNOWN;
+    }
+
+    r = minor < PA_ELEMENTSOF(table) ? table[minor] : PA_BT_FORM_FACTOR_UNKNOWN;
 
     if (!r)
-        pa_log_debug("Unknown Bluetooth minor device class %u", i);
+        pa_log_debug("Unknown Bluetooth minor device class %u", minor);
 
     return r;
 }
@@ -1847,6 +1854,8 @@ const char *pa_bt_form_factor_to_string(pa_bt_form_factor_t ff) {
             return "car";
         case PA_BT_FORM_FACTOR_HIFI:
             return "hifi";
+        case PA_BT_FORM_FACTOR_PHONE:
+            return "phone";
     }
 
     pa_assert_not_reached();
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index b59255e..3361b0f 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -164,6 +164,7 @@ typedef enum pa_bt_form_factor {
     PA_BT_FORM_FACTOR_PORTABLE,
     PA_BT_FORM_FACTOR_CAR,
     PA_BT_FORM_FACTOR_HIFI,
+    PA_BT_FORM_FACTOR_PHONE,
 } pa_bt_form_factor_t;
 
 pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class);
-- 
1.8.1



More information about the pulseaudio-discuss mailing list