summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanu Kaskinen <tanuk@iki.fi>2012-11-22 15:20:26 +0100
committerTanu Kaskinen <tanuk@iki.fi>2012-11-23 00:04:17 +0200
commitebf5f29bb32921e89ad7acb4c0d0d55ca4cf89a0 (patch)
tree7afe34836db68c3dba402f42db33f94ad250d2a2
parent59c8476d64677c852719d27e28251d325081c59b (diff)
bluetooth: Add helper pa_bluetooth_device_any_audio_connected()
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.
-rw-r--r--src/modules/bluetooth/bluetooth-util.c25
-rw-r--r--src/modules/bluetooth/bluetooth-util.h1
-rw-r--r--src/modules/bluetooth/module-bluetooth-discover.c5
3 files changed, 27 insertions, 4 deletions
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 565bfce5..19e6b47a 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -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;
diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h
index 1ec9e8c6..874baa01 100644
--- a/src/modules/bluetooth/bluetooth-util.h
+++ b/src/modules/bluetooth/bluetooth-util.h
@@ -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);
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index aef9492e..48d0beec 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -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;