From 1a44754f8d831a71603ec343aae2bde7a1371c8a Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 1 Apr 2023 20:48:44 +0300 Subject: [PATCH] bluez5: wait for devices in the same set before emitting nodes Emit nodes only after all devices in the same set are ready, or until add timeout elapses. --- spa/plugins/bluez5/bluez5-dbus.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index b85ffaeec..a8978dcf6 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -1758,6 +1758,7 @@ static int device_stop_timer(struct spa_bt_device *device) int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force) { struct spa_bt_monitor *monitor = device->monitor; + struct spa_bt_set_membership *s, *set; uint32_t connected_profiles = device->connected_profiles; uint32_t connectable_profiles = device->adapter ? adapter_connectable_profiles(device->adapter) : 0; @@ -1767,6 +1768,7 @@ int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force) SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY, }; bool direction_connected = false; + bool set_connected = true; bool all_connected; size_t i; @@ -1783,14 +1785,19 @@ int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force) all_connected = (device->profiles & connected_profiles) == device->profiles; - spa_log_debug(monitor->log, "device %p: profiles %08x %08x connectable:%08x added:%d all:%d dir:%d", + spa_list_for_each(set, &device->set_membership_list, link) + spa_bt_for_each_set_member(s, set) + if ((s->device->connected_profiles & s->device->profiles) != s->device->profiles) + set_connected = false; + + spa_log_debug(monitor->log, "device %p: profiles %08x %08x connectable:%08x added:%d all:%d dir:%d set:%d", device, device->profiles, connected_profiles, connectable_profiles, - device->added, all_connected, direction_connected); + device->added, all_connected, direction_connected, set_connected); if (connected_profiles == 0 && spa_list_is_empty(&device->codec_switch_list)) { device_stop_timer(device); device_connected(monitor, device, BT_DEVICE_DISCONNECTED); - } else if (force || direction_connected || all_connected) { + } else if (force || ((direction_connected || all_connected) && set_connected)) { device_stop_timer(device); device_connected(monitor, device, BT_DEVICE_CONNECTED); } else {