]> code.delx.au - pulseaudio/commitdiff
bluetooth: Add helper pa_bluetooth_device_any_audio_connected()
authorTanu Kaskinen <tanuk@iki.fi>
Thu, 22 Nov 2012 14:20:26 +0000 (15:20 +0100)
committerTanu Kaskinen <tanuk@iki.fi>
Thu, 22 Nov 2012 22:04:17 +0000 (00:04 +0200)
The new helper function makes it easier to check whether any audio
profiles are connected. That information is needed by the discovery
module for deciding whether a new device module should be loaded. The
device module should use this information too to unload itself at the
right time, but that's currently not implemented.

src/modules/bluetooth/bluetooth-util.c
src/modules/bluetooth/bluetooth-util.h
src/modules/bluetooth/module-bluetooth-discover.c

index 565bfce52ee6bea87458d21aacbbf1b8ef293792..19e6b47af160810ae56477c67655cdefb60b64b8 100644 (file)
@@ -1000,6 +1000,31 @@ pa_bluetooth_transport* pa_bluetooth_device_get_transport(pa_bluetooth_device *d
     return NULL;
 }
 
+bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
+    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 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.
+     * Checking only audio_state means that this function will return false at
+     * the time when only the first connection has been made. This is good,
+     * because otherwise, if the first connection is for HSP and we would
+     * already load a new device module instance, and module-card-restore tries
+     * to restore the A2DP profile, that would fail because A2DP is not yet
+     * 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->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED ||
+        d->hfgw_state >= PA_BT_AUDIO_STATE_CONNECTED;
+}
+
 int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu) {
     DBusMessage *m, *r;
     DBusError err;
index 1ec9e8c6d37134b6adbc297881b3e5c8a05319e3..874baa01862143542459e656a46e51c3fffb0f7a 100644 (file)
@@ -144,6 +144,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discover
 
 pa_bluetooth_transport* pa_bluetooth_discovery_get_transport(pa_bluetooth_discovery *y, const char *path);
 pa_bluetooth_transport* pa_bluetooth_device_get_transport(pa_bluetooth_device *d, enum profile profile);
+bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d);
 
 int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu);
 void pa_bluetooth_transport_release(pa_bluetooth_transport *t, const char *accesstype);
index aef9492ed8a48ca67e9965820050a170d9f68174..48d0beecc9d83b7ffee690905a66df3136a7ab32 100644 (file)
@@ -74,10 +74,7 @@ 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->audio_state >= PA_BT_AUDIO_STATE_CONNECTED ||
-         d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED ||
-         d->hfgw_state >= PA_BT_AUDIO_STATE_CONNECTED)) {
+    if (pa_bluetooth_device_any_audio_connected(d)) {
 
         if (!mi) {
             pa_module *m = NULL;