From b92a378a299ae5411392ba81e80df1f9f3550e77 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Thu, 6 Jan 2022 21:07:01 +0200 Subject: [PATCH] bluez5: mark connected when all source/sink profiles connected Don't require all device profiles to be connected before marking the device as connected before profile timeout. Show device already when all A2DP/HSP/HFP profiles for sink/source direction have connected. There are devices that in principle can have both sink/source profiles present, but cannot operate both directions at the same time. In case profiles come online later, the only effect is that the device profiles will get an update after the device is published. --- spa/plugins/bluez5/bluez5-dbus.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index 32d540bf1..20e46a191 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -1238,19 +1238,34 @@ int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force) { struct spa_bt_monitor *monitor = device->monitor; uint32_t connected_profiles = device->connected_profiles; + uint32_t direction_masks[2] = { + SPA_BT_PROFILE_A2DP_SINK | SPA_BT_PROFILE_HEADSET_AUDIO, + SPA_BT_PROFILE_A2DP_SOURCE | SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY, + }; + bool direction_connected = false; + bool all_connected; + size_t i; if (connected_profiles & SPA_BT_PROFILE_HEADSET_HEAD_UNIT) connected_profiles |= SPA_BT_PROFILE_HEADSET_HEAD_UNIT; if (connected_profiles & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY) connected_profiles |= SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY; + for (i = 0; i < SPA_N_ELEMENTS(direction_masks); ++i) { + uint32_t mask = direction_masks[i] & device->profiles; + if (mask && (connected_profiles & mask) == mask) + direction_connected = true; + } + + all_connected = (device->profiles & connected_profiles) == device->profiles; + spa_log_debug(monitor->log, "device %p: profiles %08x %08x %d", device, device->profiles, connected_profiles, device->added); 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 || (device->profiles & connected_profiles) == device->profiles) { + } else if (force || direction_connected || all_connected) { device_stop_timer(device); device_connected(monitor, device, BT_DEVICE_CONNECTED); } else {