summaryrefslogtreecommitdiffstats
path: root/src/modules/bluetooth/module-bluetooth-device.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-02-12 22:09:00 +0100
committerLennart Poettering <lennart@poettering.net>2009-02-12 22:09:00 +0100
commit52bfd47a493d927b4dac3c725454d2e7d4f8ca05 (patch)
treeccf939a22b1858a28fd256ef01f72deb6fda8044 /src/modules/bluetooth/module-bluetooth-device.c
parentb18c8755d6de107486ebb305d0bb2909278bf29b (diff)
use the same service fd shutdown logic when destructing module and changing profile
Diffstat (limited to 'src/modules/bluetooth/module-bluetooth-device.c')
-rw-r--r--src/modules/bluetooth/module-bluetooth-device.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 9414eee8..3498088d 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1412,10 +1412,9 @@ static int add_source(struct userdata *u) {
return 0;
}
-static int init_bt(struct userdata *u) {
+static void shutdown_bt(struct userdata *u) {
pa_assert(u);
- /* shutdown bt */
if (u->stream_fd >= 0) {
pa_close(u->stream_fd);
u->stream_fd = -1;
@@ -1425,15 +1424,21 @@ static int init_bt(struct userdata *u) {
pa_close(u->service_fd);
u->service_fd = -1;
}
+}
+
+static int init_bt(struct userdata *u) {
+ pa_assert(u);
+
+ shutdown_bt(u);
u->stream_write_type = u->stream_read_type = 0;
- u->service_write_type = u->stream_write_type = 0;
+ u->service_write_type = u->service_write_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");
return -1;
}
+
pa_log_debug("Connected to the bluetooth audio service");
return 0;
@@ -1576,7 +1581,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
}
stop_thread(u);
- init_bt(u);
+ shutdown_bt(u);
if (u->write_memchunk.memblock) {
pa_memblock_unref(u->write_memchunk.memblock);
@@ -1586,6 +1591,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
u->profile = *d;
u->sample_spec = u->requested_sample_spec;
+ init_bt(u);
init_profile(u);
if (u->sink || u->source)
@@ -1923,11 +1929,7 @@ void pa__done(pa_module *m) {
if (u->read_smoother)
pa_smoother_free(u->read_smoother);
- if (u->stream_fd >= 0)
- pa_close(u->stream_fd);
-
- if (u->service_fd >= 0)
- pa_close(u->service_fd);
+ shutdown_bt(u);
if (u->device)
pa_bluetooth_device_free(u->device);