[pulseaudio-discuss] [PATCH v2 1/5] bluetooth: Ignore Device.Connected and the whole org.bluez.Audio interface.

Tanu Kaskinen tanuk at iki.fi
Tue Nov 20 06:48:09 PST 2012


The Device.Connected property and the Audio interface were only used
for tracking whether a device module should be loaded, but that
information is already included in the individual profile state
properties. The Device.Connected property and the Audio interface can
therefore be completely ignored without any loss in functionality.
---
 src/modules/bluetooth/bluetooth-util.c            |   38 ++++-----------------
 src/modules/bluetooth/bluetooth-util.h            |    4 ---
 src/modules/bluetooth/module-bluetooth-discover.c |    5 +--
 3 files changed, 9 insertions(+), 38 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 272b6ce..06b4348 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -124,13 +124,11 @@ static pa_bluetooth_device* device_new(const char *path) {
     d->transports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
     d->paired = -1;
     d->alias = NULL;
-    d->device_connected = -1;
     PA_LLIST_HEAD_INIT(pa_bluetooth_uuid, d->uuids);
     d->address = NULL;
     d->class = -1;
     d->trusted = -1;
 
-    d->audio_state = PA_BT_AUDIO_STATE_INVALID;
     d->audio_sink_state = PA_BT_AUDIO_STATE_INVALID;
     d->audio_source_state = PA_BT_AUDIO_STATE_INVALID;
     d->headset_state = PA_BT_AUDIO_STATE_INVALID;
@@ -189,10 +187,9 @@ static pa_bool_t device_is_audio(pa_bluetooth_device *d) {
 
     return
         d->device_info_valid && (d->hfgw_state != PA_BT_AUDIO_STATE_INVALID ||
-        (d->audio_state != PA_BT_AUDIO_STATE_INVALID &&
-         (d->audio_sink_state != PA_BT_AUDIO_STATE_INVALID ||
-          d->audio_source_state != PA_BT_AUDIO_STATE_INVALID ||
-          d->headset_state != PA_BT_AUDIO_STATE_INVALID)));
+                                 d->audio_sink_state != PA_BT_AUDIO_STATE_INVALID ||
+                                 d->audio_source_state != PA_BT_AUDIO_STATE_INVALID ||
+                                 d->headset_state != PA_BT_AUDIO_STATE_INVALID);
 }
 
 static const char *check_variant_property(DBusMessageIter *i) {
@@ -345,8 +342,6 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device
 
             if (pa_streq(key, "Paired"))
                 d->paired = !!value;
-            else if (pa_streq(key, "Connected"))
-                d->device_connected = !!value;
             else if (pa_streq(key, "Trusted"))
                 d->trusted = !!value;
 
@@ -375,8 +370,8 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device
 
             if (dbus_message_iter_get_arg_type(&ai) == DBUS_TYPE_STRING &&
                 pa_streq(key, "UUIDs")) {
-                    DBusMessage *m;
-                    pa_bool_t has_audio = FALSE;
+
+                DBusMessage *m;
 
                 while (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_INVALID) {
                     pa_bluetooth_uuid *node;
@@ -398,29 +393,19 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device
                     if (strcasecmp(HSP_AG_UUID, value) == 0 || strcasecmp(HFP_AG_UUID, value) == 0) {
                         pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.HandsfreeGateway", "GetProperties"));
                         send_and_add_to_pending(y, m, get_properties_reply, d);
-                        has_audio = TRUE;
                     } else if (strcasecmp(HSP_HS_UUID, value) == 0 || strcasecmp(HFP_HS_UUID, value) == 0) {
                         pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.Headset", "GetProperties"));
                         send_and_add_to_pending(y, m, get_properties_reply, d);
-                        has_audio = TRUE;
                     } else if (strcasecmp(A2DP_SINK_UUID, value) == 0) {
                         pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSink", "GetProperties"));
                         send_and_add_to_pending(y, m, get_properties_reply, d);
-                        has_audio = TRUE;
                     } else if (strcasecmp(A2DP_SOURCE_UUID, value) == 0) {
                         pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSource", "GetProperties"));
                         send_and_add_to_pending(y, m, get_properties_reply, d);
-                        has_audio = TRUE;
                     }
 
                     dbus_message_iter_next(&ai);
                 }
-
-                /* this might eventually be racy if .Audio is not there yet, but the State change will come anyway later, so this call is for cold-detection mostly */
-                if (has_audio) {
-                    pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.Audio", "GetProperties"));
-                    send_and_add_to_pending(y, m, get_properties_reply, d);
-                }
             }
 
             break;
@@ -583,10 +568,6 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) {
                 if (parse_device_property(y, d, &dict_i) < 0)
                     goto finish;
 
-            } else if (dbus_message_has_interface(p->message, "org.bluez.Audio")) {
-                if (parse_audio_property(y, &d->audio_state, &dict_i) < 0)
-                    goto finish;
-
             } else if (dbus_message_has_interface(p->message, "org.bluez.Headset")) {
                 if (parse_audio_property(y, &d->headset_state, &dict_i) < 0)
                     goto finish;
@@ -835,8 +816,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
         found_adapter(y, path);
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-    } else if (dbus_message_is_signal(m, "org.bluez.Audio", "PropertyChanged") ||
-               dbus_message_is_signal(m, "org.bluez.Headset", "PropertyChanged") ||
+    } else if (dbus_message_is_signal(m, "org.bluez.Headset", "PropertyChanged") ||
                dbus_message_is_signal(m, "org.bluez.AudioSink", "PropertyChanged") ||
                dbus_message_is_signal(m, "org.bluez.AudioSource", "PropertyChanged") ||
                dbus_message_is_signal(m, "org.bluez.HandsfreeGateway", "PropertyChanged") ||
@@ -856,10 +836,6 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
                 if (parse_device_property(y, d, &arg_i) < 0)
                     goto fail;
 
-            } else if (dbus_message_has_interface(m, "org.bluez.Audio")) {
-                if (parse_audio_property(y, &d->audio_state, &arg_i) < 0)
-                    goto fail;
-
             } else if (dbus_message_has_interface(m, "org.bluez.Headset")) {
                 if (parse_audio_property(y, &d->headset_state, &arg_i) < 0)
                     goto fail;
@@ -1476,7 +1452,6 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
                 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
                 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
                 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
-                "type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
                 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
                 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'",
                 "type='signal',sender='org.bluez',interface='org.bluez.AudioSource',member='PropertyChanged'",
@@ -1541,7 +1516,6 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
                                "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
                                "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
                                "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
-                               "type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
                                "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
                                "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'",
                                "type='signal',sender='org.bluez',interface='org.bluez.AudioSource',member='PropertyChanged'",
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index 8a3f2ad..3846498 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -109,15 +109,11 @@ struct pa_bluetooth_device {
     pa_hashmap *transports;
     int paired;
     char *alias;
-    int device_connected;
     PA_LLIST_HEAD(pa_bluetooth_uuid, uuids);
     char *address;
     int class;
     int trusted;
 
-    /* Audio state */
-    pa_bt_audio_state_t audio_state;
-
     /* AudioSink state */
     pa_bt_audio_state_t audio_sink_state;
 
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 2dc7cf5..8d64834 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -74,9 +74,10 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
 
     mi = pa_hashmap_get(u->hashmap, d->path);
 
-    if (!d->dead && d->device_connected > 0 &&
-        (d->audio_state >= PA_BT_AUDIO_STATE_CONNECTED ||
+    if (!d->dead &&
+        (d->audio_sink_state >= PA_BT_AUDIO_STATE_CONNECTED ||
          d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED ||
+         d->headset_state >= PA_BT_AUDIO_STATE_CONNECTED ||
          d->hfgw_state >= PA_BT_AUDIO_STATE_CONNECTED)) {
 
         if (!mi) {
-- 
1.7.10.4



More information about the pulseaudio-discuss mailing list