diff options
author | Tanu Kaskinen <tanuk@iki.fi> | 2012-11-22 15:20:26 +0100 |
---|---|---|
committer | Tanu Kaskinen <tanuk@iki.fi> | 2012-11-23 00:04:17 +0200 |
commit | ebf5f29bb32921e89ad7acb4c0d0d55ca4cf89a0 (patch) | |
tree | 7afe34836db68c3dba402f42db33f94ad250d2a2 /src/modules/bluetooth/bluetooth-util.c | |
parent | 59c8476d64677c852719d27e28251d325081c59b (diff) | |
download | pulseaudio-ebf5f29bb32921e89ad7acb4c0d0d55ca4cf89a0.tar.gz |
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.
Diffstat (limited to 'src/modules/bluetooth/bluetooth-util.c')
-rw-r--r-- | src/modules/bluetooth/bluetooth-util.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 565bfce52..19e6b47af 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; |