From a9cc3f28133ed310c31cf2b168fc32bf7644a641 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 24 Sep 2023 15:21:45 +0300 Subject: [PATCH] bluez5: deprioritize audio-gateway if remote is HFP HF + A2DP sink If remote supports both HFP HF and AG, both may get connected, which occurs with Pipewire<->Pipewire connection. In this case, Pipewire on both sides may pick the audio-gateway profile. To avoid both sides being audio-gateway, if remote is both A2DP sink and HF, use lower priority for the audio-gateway profile. Generally, BlueZ won't connect both A2DP Source and Sink between same devices at the same time, so we use that to determine which side should be the receiver. --- spa/plugins/bluez5/bluez5-device.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 23b5ec917..d5a4c444b 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -1608,7 +1608,17 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder * name = "audio-gateway"; desc = _("Audio Gateway (A2DP Source & HSP/HFP AG)"); } - priority = 256; + + /* + * If the remote is A2DP sink and HF, we likely should prioritize being + * A2DP sender, not gateway. This can occur in PW<->PW if RFCOMM gets + * connected both as AG and HF. + */ + if ((device->connected_profiles & SPA_BT_PROFILE_A2DP_SINK) && + (device->connected_profiles & SPA_BT_PROFILE_HEADSET_HEAD_UNIT)) + priority = 15; + else + priority = 256; break; } case DEVICE_PROFILE_A2DP: