mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
bluetooth: Set to off if transport removed
The recently added hook can be used to detect that the transport being used has been removed. In this case, the profile needs to be set to off. Additionally, the change fixes a significant problem: without this transition, the transport could be destroyed while the hook slots (i.e. nrec_changed_slot) were still set. This led to a double free of these objects in stop_thread().
This commit is contained in:
parent
6e5f78e0af
commit
9b9e53d144
1 changed files with 19 additions and 0 deletions
|
|
@ -143,6 +143,7 @@ struct userdata {
|
|||
char *path;
|
||||
char *transport;
|
||||
char *accesstype;
|
||||
pa_hook_slot *transport_removed_slot;
|
||||
|
||||
pa_bluetooth_discovery *discovery;
|
||||
pa_bool_t auto_connect;
|
||||
|
|
@ -1974,6 +1975,16 @@ static void bt_transport_config(struct userdata *u) {
|
|||
bt_transport_config_a2dp(u);
|
||||
}
|
||||
|
||||
/* Run from main thread */
|
||||
static pa_hook_result_t transport_removed_cb(pa_bluetooth_transport *t, void *call_data, struct userdata *u) {
|
||||
pa_assert(t);
|
||||
pa_assert(u);
|
||||
|
||||
pa_assert_se(pa_card_set_profile(u->card, "off", false) >= 0);
|
||||
|
||||
return PA_HOOK_OK;
|
||||
}
|
||||
|
||||
/* Run from main thread */
|
||||
static int setup_transport(struct userdata *u) {
|
||||
const pa_bluetooth_device *d;
|
||||
|
|
@ -1995,6 +2006,9 @@ static int setup_transport(struct userdata *u) {
|
|||
|
||||
u->transport = pa_xstrdup(t->path);
|
||||
|
||||
u->transport_removed_slot = pa_hook_connect(&t->hooks[PA_BLUETOOTH_TRANSPORT_HOOK_REMOVED], PA_HOOK_NORMAL,
|
||||
(pa_hook_cb_t) transport_removed_cb, u);
|
||||
|
||||
bt_transport_acquire(u, FALSE);
|
||||
|
||||
bt_transport_config(u);
|
||||
|
|
@ -2064,6 +2078,11 @@ static void stop_thread(struct userdata *u) {
|
|||
u->hsp.nrec_changed_slot = NULL;
|
||||
}
|
||||
|
||||
if (u->transport_removed_slot) {
|
||||
pa_hook_slot_free(u->transport_removed_slot);
|
||||
u->transport_removed_slot = NULL;
|
||||
}
|
||||
|
||||
if (u->transport) {
|
||||
bt_transport_release(u);
|
||||
pa_xfree(u->transport);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue