[pulseaudio-discuss] [PATCH v3 3/5] bluetooth: Add helper pa_bluetooth_device_any_audio_connected()
Mikel Astiz
mikel.astiz.oss at gmail.com
Thu Nov 22 06:20:26 PST 2012
From: Tanu Kaskinen <tanuk at iki.fi>
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 | 13 +++++++++++++
src/modules/bluetooth/bluetooth-util.h | 1 +
src/modules/bluetooth/module-bluetooth-discover.c | 5 +----
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 565bfce..b5064e9 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1000,6 +1000,19 @@ 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;
+
+ /* Deliverately ignore audio_sink_state and headset_state since they are reflected in audio_state */
+ 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 1ec9e8c..874baa0 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 aef9492..48d0bee 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;
--
1.7.11.7
More information about the pulseaudio-discuss
mailing list