diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 16a184754..903fd3758 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -596,6 +596,9 @@ static void a2dp_on_timeout(struct spa_source *source) struct spa_io_buffers *io = port->io; uint64_t prev_time, now_time; + if (this->transport == NULL) + return; + if (this->started && spa_system_timerfd_read(this->data_system, this->timerfd, &exp) < 0) spa_log_warn(this->log, "error reading timerfd: %s", strerror(errno)); @@ -1221,11 +1224,23 @@ static const struct spa_node_methods impl_node = { .process = impl_node_process, }; +static int do_transport_destroy(struct spa_loop *loop, + bool async, + uint32_t seq, + const void *data, + size_t size, + void *user_data) +{ + struct impl *this = user_data; + this->transport = NULL; + return 0; +} + static void transport_destroy(void *data) { struct impl *this = data; spa_log_debug(this->log, "transport %p destroy", this->transport); - this->transport = NULL; + spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this); } static const struct spa_bt_transport_events transport_events = { diff --git a/spa/plugins/bluez5/a2dp-source.c b/spa/plugins/bluez5/a2dp-source.c index 84a8a5e9f..cc5cbd8d8 100644 --- a/spa/plugins/bluez5/a2dp-source.c +++ b/spa/plugins/bluez5/a2dp-source.c @@ -1092,11 +1092,23 @@ static const struct spa_node_methods impl_node = { .process = impl_node_process, }; +static int do_transport_destroy(struct spa_loop *loop, + bool async, + uint32_t seq, + const void *data, + size_t size, + void *user_data) +{ + struct impl *this = user_data; + this->transport = NULL; + return 0; +} + static void transport_destroy(void *data) { struct impl *this = data; spa_log_debug(this->log, "transport %p destroy", this->transport); - this->transport = NULL; + spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this); } static void transport_state_changed(void *data, enum spa_bt_transport_state old, diff --git a/spa/plugins/bluez5/sco-sink.c b/spa/plugins/bluez5/sco-sink.c index b47560bab..f45f08845 100644 --- a/spa/plugins/bluez5/sco-sink.c +++ b/spa/plugins/bluez5/sco-sink.c @@ -315,6 +315,9 @@ static void flush_data(struct impl *this) uint32_t min_in_size; uint8_t *packet; + if (this->transport == NULL) + return; + /* get buffer */ if (!port->current_buffer) { spa_return_if_fail(!spa_list_is_empty(&port->ready)); @@ -445,6 +448,9 @@ static void sco_on_timeout(struct spa_source *source) struct port *port = &this->port; uint64_t exp; + if (this->transport == NULL) + return; + /* Read the timerfd */ if (this->started && spa_system_timerfd_read(this->data_system, this->timerfd, &exp) < 0) spa_log_warn(this->log, "error reading timerfd: %s", strerror(errno)); @@ -1049,11 +1055,23 @@ static const struct spa_node_methods impl_node = { .process = impl_node_process, }; +static int do_transport_destroy(struct spa_loop *loop, + bool async, + uint32_t seq, + const void *data, + size_t size, + void *user_data) +{ + struct impl *this = user_data; + this->transport = NULL; + return 0; +} + static void transport_destroy(void *data) { struct impl *this = data; spa_log_debug(this->log, "transport %p destroy", this->transport); - this->transport = NULL; + spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this); } static const struct spa_bt_transport_events transport_events = { diff --git a/spa/plugins/bluez5/sco-source.c b/spa/plugins/bluez5/sco-source.c index 0535c0373..6da7c1d46 100644 --- a/spa/plugins/bluez5/sco-source.c +++ b/spa/plugins/bluez5/sco-source.c @@ -1068,11 +1068,23 @@ static const struct spa_node_methods impl_node = { .process = impl_node_process, }; +static int do_transport_destroy(struct spa_loop *loop, + bool async, + uint32_t seq, + const void *data, + size_t size, + void *user_data) +{ + struct impl *this = user_data; + this->transport = NULL; + return 0; +} + static void transport_destroy(void *data) { struct impl *this = data; spa_log_debug(this->log, "transport %p destroy", this->transport); - this->transport = NULL; + spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this); } static const struct spa_bt_transport_events transport_events = {