[pulseaudio-discuss] [PATCH v0 6/7] bluetooth: Remove device_is_audio_ready()
Mikel Astiz
mikel.astiz.oss at gmail.com
Fri Jan 11 02:07:48 PST 2013
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
The function was used to check whether the basic properties of the
Bluetooth device have been received. This can be simplified by just
checking d->device_info_valid, since the state of the audio interface
is only relevant inside pa_bluetooth_device_any_audio_connected(), which
is used to trigger the discovery callback.
While checking device_info_valid, special care must be taken with all
three possible values: when set to -1, it means some error was triggered
while getting the device properties. Therefore, these devices can also
be ignored outside bluetooth-util.
Besides that, the patch slightly modifies the behavior of the internal
API affecting pa_bluetooth_discovery_get_by_address() and
pa_bluetooth_discovery_get_by_path(), since they will return the device
no matter the state of the audio interface. This however makes sense and
should have no influence in the current codebase given that the modules
make use of devices only after the discovery hook has been triggered.
---
src/modules/bluetooth/bluetooth-util.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 149a476..48e12da 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -234,15 +234,6 @@ static void device_free(pa_bluetooth_device *d) {
pa_xfree(d);
}
-static pa_bool_t device_is_audio_ready(const pa_bluetooth_device *d) {
- pa_assert(d);
-
- if (!d->device_info_valid || d->audio_state == PA_BT_AUDIO_STATE_INVALID)
- return false;
-
- return true;
-}
-
static const char *check_variant_property(DBusMessageIter *i) {
const char *key;
@@ -611,7 +602,7 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
static void run_callback(pa_bluetooth_device *d, pa_bool_t dead) {
pa_assert(d);
- if (!device_is_audio_ready(d))
+ if (d->device_info_valid != 1)
return;
d->dead = dead;
@@ -1054,7 +1045,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discover
while ((d = pa_hashmap_iterate(y->devices, &state, NULL)))
if (pa_streq(d->address, address))
- return device_is_audio_ready(d) ? d : NULL;
+ return d->device_info_valid == 1 ? d : NULL;
return NULL;
}
@@ -1067,7 +1058,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *
pa_assert(path);
if ((d = pa_hashmap_get(y->devices, path)))
- if (device_is_audio_ready(d))
+ if (d->device_info_valid == 1)
return d;
return NULL;
@@ -1078,7 +1069,10 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
pa_assert(d);
- if (d->dead || !device_is_audio_ready(d))
+ if (d->dead || d->device_info_valid != 1)
+ return false;
+
+ if (d->audio_state == PA_BT_AUDIO_STATE_INVALID)
return false;
/* Make sure audio_state is *not* in CONNECTING state before we fire the
--
1.7.11.7
More information about the pulseaudio-discuss
mailing list