From b35ae7f53116949d0cf5d991883e3b54f2c48aa5 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Mon, 9 Feb 2009 22:11:46 +0200 Subject: bluetooth: reconnect to audio service when switching profile Currently, Bluez audio service crash when reusing the same control socket to switch to different profiles. This typically happen when first switching from HSP to A2DP on dual headsets. --- src/modules/bluetooth/module-bluetooth-device.c | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index de6bded2..0067d91d 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -1282,6 +1282,19 @@ static int add_source(struct userdata *u) { static int init_bt(struct userdata *u) { pa_assert(u); + /* shutdown bt */ + if (u->stream_fd >= 0) { + pa_close(u->stream_fd); + u->stream_fd = -1; + } + + if (u->service_fd >= 0) { + pa_close(u->service_fd); + u->service_fd = -1; + } + + u->write_type = u->read_type = 0; + /* connect to the bluez audio service */ if ((u->service_fd = bt_audio_service_open()) < 0) { pa_log_error("Couldn't connect to bluetooth audio service"); @@ -1292,17 +1305,6 @@ static int init_bt(struct userdata *u) { return 0; } -static void shutdown_bt(struct userdata *u) { - pa_assert(u); - - if (u->stream_fd <= 0) { - pa_close(u->stream_fd); - u->stream_fd = -1; - } - - u->write_type = u->read_type = 0; -} - static int setup_bt(struct userdata *u) { pa_assert(u); @@ -1417,7 +1419,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) { } stop_thread(u); - shutdown_bt(u); + init_bt(u); if (u->write_memchunk.memblock) { pa_memblock_unref(u->write_memchunk.memblock); -- cgit