[pulseaudio-discuss] [PATCH next v0 09/10] bluetooth: Use transport state instead of profile states

Mikel Astiz mikel.astiz.oss at gmail.com
Wed Dec 12 04:17:09 PST 2012


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

The transport state also reflects the state of the audio interface. The
state redundancy can thus be minimized by always using the first one,
and avoiding the use of profile-specific states with the exception of
finding out the initial state of a transport.
---
 src/modules/bluetooth/bluetooth-util.c          | 13 ++++++++++++-
 src/modules/bluetooth/module-bluetooth-device.c |  4 ++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 18e456d..79c4a7d 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1058,7 +1058,7 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
         return false;
 
     for (i = 0; i < PA_BLUETOOTH_PROFILE_COUNT; i++)
-        if (d->profile_state[i] >= PA_BT_AUDIO_STATE_CONNECTED)
+        if (d->transports[i])
             return true;
 
     return false;
@@ -1234,6 +1234,7 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
     enum profile p;
     DBusMessageIter args, props;
     DBusMessage *r;
+    bool old_any_connected;
 
     dbus_message_iter_init(m, &args);
 
@@ -1307,6 +1308,8 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
         goto fail;
     }
 
+    old_any_connected = pa_bluetooth_device_any_audio_connected(d);
+
     sender = dbus_message_get_sender(m);
 
     t = transport_new(d, sender, path, p, config, size);
@@ -1320,6 +1323,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
 
     pa_assert_se(r = dbus_message_new_method_return(m));
 
+    if (old_any_connected != pa_bluetooth_device_any_audio_connected(d))
+        run_callback(d, FALSE);
+
     return r;
 
 fail:
@@ -1345,12 +1351,17 @@ static DBusMessage *endpoint_clear_configuration(DBusConnection *c, DBusMessage
     }
 
     if ((t = pa_hashmap_get(y->transports, path))) {
+        bool old_any_connected = t->device ? pa_bluetooth_device_any_audio_connected(t->device) : false;
+
         pa_log_debug("Clearing transport %s profile %d", t->path, t->profile);
         t->device->transports[t->profile] = NULL;
         pa_hashmap_remove(y->transports, t->path);
         t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
         pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
         transport_free(t);
+
+        if (t->device && old_any_connected != pa_bluetooth_device_any_audio_connected(t->device))
+            run_callback(t->device, FALSE);
     }
 
     pa_assert_se(r = dbus_message_new_method_return(m));
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index aa6a05e..254ff3b 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2123,7 +2123,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
     if (*d != PROFILE_OFF) {
         const pa_bluetooth_device *device = u->device;
 
-        if (device->profile_state[*d] < PA_BT_AUDIO_STATE_CONNECTED) {
+        if (!device->transports[*d]) {
             pa_log_warn("Profile not connected, refused to switch profile to %s", new_profile->name);
             return -PA_ERR_IO;
         }
@@ -2386,7 +2386,7 @@ static int add_card(struct userdata *u) {
 
     d = PA_CARD_PROFILE_DATA(u->card->active_profile);
 
-    if (*d != PROFILE_OFF && (device->profile_state[*d] < PA_BT_AUDIO_STATE_CONNECTED)) {
+    if (*d != PROFILE_OFF && !device->transports[*d]) {
         pa_log_warn("Default profile not connected, selecting off profile");
         u->card->active_profile = pa_hashmap_get(u->card->profiles, "off");
         u->card->save_profile = FALSE;
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list