[pulseaudio-discuss] [PATCH next v1 09/13] bluetooth: Refactor dependency to org.bluez.Audio

Mikel Astiz mikel.astiz.oss at gmail.com
Fri Dec 14 06:14:36 PST 2012


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

The state of this interface is needed for one single reason: we need to
wait until all profiles have been connected (or more precisely, until
are connection attempts are finished). This can be made more explicit in
the code by just checking the CONNECTING state (and not loading
module-bluetooth-device during that state), but otherwise treating all
transport types equally.

Ideally, audio_state should be completely removed but it's left there to
avoid an issue with module-card-restore, as documented in the source
code's comments.
---
 src/modules/bluetooth/bluetooth-util.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 5fc3cad..e324336 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1063,13 +1063,15 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *
 }
 
 bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
+    unsigned i;
+
     pa_assert(d);
 
     if (d->dead || !device_is_audio_ready(d))
         return false;
 
-    /* Deliberately ignore audio_sink_state and headset_state since they are
-     * reflected in audio_state. This is actually very important in order to
+    /* Make sure audio_state is *not* in CONNECTING state before we fire the hook
+     * to report the new device state. This is actually very important in order to
      * make module-card-restore work well with headsets: if the headset
      * supports both HSP and A2DP, one of those profiles is connected first and
      * then the other, and lastly the Audio interface becomes connected.
@@ -1081,10 +1083,14 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
      * connected. Waiting until the Audio interface gets connected means that
      * both headset profiles will be connected when the device module is
      * loaded. */
-    return
-        d->audio_state >= PA_BT_AUDIO_STATE_CONNECTED ||
-        d->profile_state[PROFILE_A2DP_SOURCE] >= PA_BT_AUDIO_STATE_CONNECTED ||
-        d->profile_state[PROFILE_HFGW] >= PA_BT_AUDIO_STATE_CONNECTED;
+    if (d->audio_state == PA_BT_AUDIO_STATE_CONNECTING)
+        return false;
+
+    for (i = 0; i < PA_BLUETOOTH_PROFILE_COUNT; i++)
+        if (d->profile_state[i] >= PA_BT_AUDIO_STATE_CONNECTED)
+            return true;
+
+    return false;
 }
 
 int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list