bluez5: backend-native: fix codec handling with simultaneous HF & AG

It may occur that we have RFCOMM connected as both HF and AG.  The codec
switching and support checks should in this case always use the remote
HF RFCOMM.

Fix by finding the RFCOMM with the correct profile, remote as HF.
This commit is contained in:
Pauli Virtanen 2023-09-24 13:22:46 +03:00
parent 099e2cf27a
commit 5f7afe588c

View file

@ -1915,11 +1915,12 @@ static const struct spa_bt_transport_implementation sco_transport_impl = {
.destroy = sco_destroy_cb, .destroy = sco_destroy_cb,
}; };
static struct rfcomm *device_find_rfcomm(struct impl *backend, struct spa_bt_device *device) static struct rfcomm *device_find_rfcomm(struct impl *backend, struct spa_bt_device *device,
enum spa_bt_profile profile)
{ {
struct rfcomm *rfcomm; struct rfcomm *rfcomm;
spa_list_for_each(rfcomm, &backend->rfcomm_list, link) { spa_list_for_each(rfcomm, &backend->rfcomm_list, link) {
if (rfcomm->device == device) if (rfcomm->device == device && (rfcomm->profile & profile))
return rfcomm; return rfcomm;
} }
return NULL; return NULL;
@ -1931,8 +1932,8 @@ static int backend_native_supports_codec(void *data, struct spa_bt_device *devic
struct impl *backend = data; struct impl *backend = data;
struct rfcomm *rfcomm; struct rfcomm *rfcomm;
rfcomm = device_find_rfcomm(backend, device); rfcomm = device_find_rfcomm(backend, device, SPA_BT_PROFILE_HFP_HF);
if (rfcomm == NULL || rfcomm->profile != SPA_BT_PROFILE_HFP_HF) if (rfcomm == NULL)
return -ENOTSUP; return -ENOTSUP;
if (codec == HFP_AUDIO_CODEC_CVSD) if (codec == HFP_AUDIO_CODEC_CVSD)
@ -2097,10 +2098,12 @@ static int backend_native_ensure_codec(void *data, struct spa_bt_device *device,
int res; int res;
res = backend_native_supports_codec(data, device, codec); res = backend_native_supports_codec(data, device, codec);
if (res <= 0) if (res < 0)
return res;
else if (!res)
return -EINVAL; return -EINVAL;
rfcomm = device_find_rfcomm(backend, device); rfcomm = device_find_rfcomm(backend, device, SPA_BT_PROFILE_HFP_HF);
if (rfcomm == NULL) if (rfcomm == NULL)
return -ENOTSUP; return -ENOTSUP;