[PATCH next v0 08/10] bluetooth: Refactor dependency to org.bluez.Audio

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx>

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 587214c..18e456d 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1034,13 +1034,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.
@@ -1052,10 +1054,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



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux