mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
bluetooth: add discover of bluetooth sources
This commit is contained in:
parent
65c3e6576c
commit
2772521698
3 changed files with 31 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
/***
|
/***
|
||||||
This file is part of PulseAudio.
|
This file is part of PulseAudio.
|
||||||
|
|
||||||
Copyright 2008 Joao Paulo Rechi Vita
|
Copyright 2008-2009 Joao Paulo Rechi Vita
|
||||||
|
|
||||||
PulseAudio is free software; you can redistribute it and/or modify
|
PulseAudio is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
|
@ -95,6 +95,7 @@ static pa_bluetooth_device* device_new(const char *path) {
|
||||||
|
|
||||||
d->audio_state = PA_BT_AUDIO_STATE_INVALID;
|
d->audio_state = PA_BT_AUDIO_STATE_INVALID;
|
||||||
d->audio_sink_state = PA_BT_AUDIO_STATE_INVALID;
|
d->audio_sink_state = PA_BT_AUDIO_STATE_INVALID;
|
||||||
|
d->audio_source_state = PA_BT_AUDIO_STATE_INVALID;
|
||||||
d->headset_state = PA_BT_AUDIO_STATE_INVALID;
|
d->headset_state = PA_BT_AUDIO_STATE_INVALID;
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
|
@ -124,6 +125,7 @@ static pa_bool_t device_is_audio(pa_bluetooth_device *d) {
|
||||||
d->device_info_valid &&
|
d->device_info_valid &&
|
||||||
(d->audio_state != PA_BT_AUDIO_STATE_INVALID &&
|
(d->audio_state != PA_BT_AUDIO_STATE_INVALID &&
|
||||||
(d->audio_sink_state != PA_BT_AUDIO_STATE_INVALID ||
|
(d->audio_sink_state != PA_BT_AUDIO_STATE_INVALID ||
|
||||||
|
d->audio_source_state != PA_BT_AUDIO_STATE_INVALID ||
|
||||||
d->headset_state != PA_BT_AUDIO_STATE_INVALID));
|
d->headset_state != PA_BT_AUDIO_STATE_INVALID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,6 +235,9 @@ static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device
|
||||||
} else if (strcasecmp(A2DP_SINK_UUID, value) == 0) {
|
} else if (strcasecmp(A2DP_SINK_UUID, value) == 0) {
|
||||||
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSink", "GetProperties"));
|
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSink", "GetProperties"));
|
||||||
send_and_add_to_pending(y, d, m, get_properties_reply);
|
send_and_add_to_pending(y, d, m, get_properties_reply);
|
||||||
|
} else if (strcasecmp(A2DP_SOURCE_UUID, value) == 0) {
|
||||||
|
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSource", "GetProperties"));
|
||||||
|
send_and_add_to_pending(y, d, m, get_properties_reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this might eventually be racy if .Audio is not there yet, but the State change will come anyway later, so this call is for cold-detection mostly */
|
/* this might eventually be racy if .Audio is not there yet, but the State change will come anyway later, so this call is for cold-detection mostly */
|
||||||
|
|
@ -278,7 +283,7 @@ static int parse_audio_property(pa_bluetooth_discovery *u, int *state, DBusMessa
|
||||||
|
|
||||||
dbus_message_iter_recurse(i, &variant_i);
|
dbus_message_iter_recurse(i, &variant_i);
|
||||||
|
|
||||||
/* pa_log_debug("Parsing property org.bluez.{Audio|AudioSink|Headset}.%s", key); */
|
/* pa_log_debug("Parsing property org.bluez.{Audio|AudioSink|AudioSource|Headset}.%s", key); */
|
||||||
|
|
||||||
switch (dbus_message_iter_get_arg_type(&variant_i)) {
|
switch (dbus_message_iter_get_arg_type(&variant_i)) {
|
||||||
|
|
||||||
|
|
@ -390,6 +395,9 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) {
|
||||||
} else if (dbus_message_has_interface(p->message, "org.bluez.AudioSink")) {
|
} else if (dbus_message_has_interface(p->message, "org.bluez.AudioSink")) {
|
||||||
if (parse_audio_property(y, &d->audio_sink_state, &dict_i) < 0)
|
if (parse_audio_property(y, &d->audio_sink_state, &dict_i) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
} else if (dbus_message_has_interface(p->message, "org.bluez.AudioSource")) {
|
||||||
|
if (parse_audio_property(y, &d->audio_source_state, &dict_i) < 0)
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -440,8 +448,8 @@ static void found_device(pa_bluetooth_discovery *y, const char* path) {
|
||||||
pa_assert_se(m = dbus_message_new_method_call("org.bluez", path, "org.bluez.Device", "GetProperties"));
|
pa_assert_se(m = dbus_message_new_method_call("org.bluez", path, "org.bluez.Device", "GetProperties"));
|
||||||
send_and_add_to_pending(y, d, m, get_properties_reply);
|
send_and_add_to_pending(y, d, m, get_properties_reply);
|
||||||
|
|
||||||
/* Before we read the other properties (Audio, AudioSink, Headset) we wait
|
/* Before we read the other properties (Audio, AudioSink, AudioSource,
|
||||||
* that the UUID is read */
|
* Headset) we wait that the UUID is read */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_devices_reply(DBusPendingCall *pending, void *userdata) {
|
static void list_devices_reply(DBusPendingCall *pending, void *userdata) {
|
||||||
|
|
@ -616,6 +624,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
|
||||||
} else if (dbus_message_is_signal(m, "org.bluez.Audio", "PropertyChanged") ||
|
} else if (dbus_message_is_signal(m, "org.bluez.Audio", "PropertyChanged") ||
|
||||||
dbus_message_is_signal(m, "org.bluez.Headset", "PropertyChanged") ||
|
dbus_message_is_signal(m, "org.bluez.Headset", "PropertyChanged") ||
|
||||||
dbus_message_is_signal(m, "org.bluez.AudioSink", "PropertyChanged") ||
|
dbus_message_is_signal(m, "org.bluez.AudioSink", "PropertyChanged") ||
|
||||||
|
dbus_message_is_signal(m, "org.bluez.AudioSource", "PropertyChanged") ||
|
||||||
dbus_message_is_signal(m, "org.bluez.Device", "PropertyChanged")) {
|
dbus_message_is_signal(m, "org.bluez.Device", "PropertyChanged")) {
|
||||||
|
|
||||||
pa_bluetooth_device *d;
|
pa_bluetooth_device *d;
|
||||||
|
|
@ -643,6 +652,9 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
|
||||||
} else if (dbus_message_has_interface(m, "org.bluez.AudioSink")) {
|
} else if (dbus_message_has_interface(m, "org.bluez.AudioSink")) {
|
||||||
if (parse_audio_property(y, &d->audio_sink_state, &arg_i) < 0)
|
if (parse_audio_property(y, &d->audio_sink_state, &arg_i) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
} else if (dbus_message_has_interface(m, "org.bluez.AudioSource")) {
|
||||||
|
if (parse_audio_property(y, &d->audio_source_state, &arg_i) < 0)
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
run_callback(y, d, FALSE);
|
run_callback(y, d, FALSE);
|
||||||
|
|
@ -765,7 +777,8 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
|
"type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
|
"type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
|
"type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL) < 0) {
|
"type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'",
|
||||||
|
"type='signal',sender='org.bluez',interface='org.bluez.AudioSource',member='PropertyChanged'", NULL) < 0) {
|
||||||
pa_log("Failed to add D-Bus matches: %s", err.message);
|
pa_log("Failed to add D-Bus matches: %s", err.message);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -817,7 +830,8 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
|
"type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
|
"type='signal',sender='org.bluez',interface='org.bluez.Audio',member='PropertyChanged'",
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
|
"type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
|
||||||
"type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL);
|
"type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'",
|
||||||
|
"type='signal',sender='org.bluez',interface='org.bluez.AudioSource',member='PropertyChanged'", NULL);
|
||||||
|
|
||||||
dbus_connection_remove_filter(pa_dbus_connection_get(y->connection), filter_cb, y);
|
dbus_connection_remove_filter(pa_dbus_connection_get(y->connection), filter_cb, y);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
/***
|
/***
|
||||||
This file is part of PulseAudio.
|
This file is part of PulseAudio.
|
||||||
|
|
||||||
Copyright 2008 Joao Paulo Rechi Vita
|
Copyright 2008-2009 Joao Paulo Rechi Vita
|
||||||
|
|
||||||
PulseAudio is free software; you can redistribute it and/or modify
|
PulseAudio is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
|
@ -53,7 +53,7 @@ struct pa_bluetooth_uuid {
|
||||||
PA_LLIST_FIELDS(pa_bluetooth_uuid);
|
PA_LLIST_FIELDS(pa_bluetooth_uuid);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This enum is shared among Audio, Headset, and AudioSink, although not all values are acceptable in all profiles */
|
/* This enum is shared among Audio, Headset, AudioSink, and AudioSource, although not all values are acceptable in all profiles */
|
||||||
typedef enum pa_bt_audio_state {
|
typedef enum pa_bt_audio_state {
|
||||||
PA_BT_AUDIO_STATE_INVALID = -1,
|
PA_BT_AUDIO_STATE_INVALID = -1,
|
||||||
PA_BT_AUDIO_STATE_DISCONNECTED,
|
PA_BT_AUDIO_STATE_DISCONNECTED,
|
||||||
|
|
@ -84,6 +84,9 @@ struct pa_bluetooth_device {
|
||||||
/* AudioSink state */
|
/* AudioSink state */
|
||||||
pa_bt_audio_state_t audio_sink_state;
|
pa_bt_audio_state_t audio_sink_state;
|
||||||
|
|
||||||
|
/* AudioSource state */
|
||||||
|
pa_bt_audio_state_t audio_source_state;
|
||||||
|
|
||||||
/* Headset state */
|
/* Headset state */
|
||||||
pa_bt_audio_state_t headset_state;
|
pa_bt_audio_state_t headset_state;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/***
|
/***
|
||||||
This file is part of PulseAudio.
|
This file is part of PulseAudio.
|
||||||
|
|
||||||
Copyright 2008 Joao Paulo Rechi Vita
|
Copyright 2008-2009 Joao Paulo Rechi Vita
|
||||||
|
|
||||||
PulseAudio is free software; you can redistribute it and/or modify
|
PulseAudio is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
|
@ -83,8 +83,9 @@ 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);
|
||||||
|
|
||||||
|
pa_log("dead: %d, device_connected: %d, audio_state: %d, audio_source_state: %d", d->dead, d->device_connected, d->audio_state, d->audio_source_state);
|
||||||
if (!d->dead &&
|
if (!d->dead &&
|
||||||
d->device_connected > 0 && d->audio_state >= PA_BT_AUDIO_STATE_CONNECTED) {
|
d->device_connected > 0 && (d->audio_state >= PA_BT_AUDIO_STATE_CONNECTED || d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED)) {
|
||||||
|
|
||||||
if (!mi) {
|
if (!mi) {
|
||||||
pa_module *m = NULL;
|
pa_module *m = NULL;
|
||||||
|
|
@ -116,6 +117,9 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED)
|
||||||
|
args = pa_sprintf_malloc("%s profile=\"a2dp_source\"", args);
|
||||||
|
|
||||||
pa_log_debug("Loading module-bluetooth-device %s", args);
|
pa_log_debug("Loading module-bluetooth-device %s", args);
|
||||||
m = pa_module_load(u->module->core, "module-bluetooth-device", args);
|
m = pa_module_load(u->module->core, "module-bluetooth-device", args);
|
||||||
pa_xfree(args);
|
pa_xfree(args);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue