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.
This commit is contained in:
Tanu Kaskinen 2012-11-22 15:20:26 +01:00
parent 59c8476d64
commit ebf5f29bb3
3 changed files with 27 additions and 4 deletions

View file

@ -1000,6 +1000,31 @@ pa_bluetooth_transport* pa_bluetooth_device_get_transport(pa_bluetooth_device *d
return NULL; 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) { int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu) {
DBusMessage *m, *r; DBusMessage *m, *r;
DBusError err; DBusError err;

View 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_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); 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); 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); void pa_bluetooth_transport_release(pa_bluetooth_transport *t, const char *accesstype);

View 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); mi = pa_hashmap_get(u->hashmap, d->path);
if (!d->dead && if (pa_bluetooth_device_any_audio_connected(d)) {
(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 (!mi) { if (!mi) {
pa_module *m = NULL; pa_module *m = NULL;