diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index c2e4a7ba7..6fd375781 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -1867,6 +1867,7 @@ void spa_bt_transport_free(struct spa_bt_transport *transport) if (device && device->connected_profiles != prev_connected) spa_bt_device_emit_profiles_changed(device, device->profiles, prev_connected); + free(transport->endpoint_path); free(transport->path); free(transport); } @@ -2530,6 +2531,7 @@ static void a2dp_codec_switch_next(struct spa_bt_a2dp_codec_switch *sw) static bool a2dp_codec_switch_process_current(struct spa_bt_a2dp_codec_switch *sw) { struct spa_bt_remote_endpoint *ep; + struct spa_bt_transport *t; const struct a2dp_codec *codec; uint8_t config[A2DP_MAX_CAPS_SIZE]; char *local_endpoint_base; @@ -2584,6 +2586,19 @@ static bool a2dp_codec_switch_process_current(struct spa_bt_a2dp_codec_switch *s goto next; } + /* Each endpoint can be used by only one device at a time (on each adapter) */ + spa_list_for_each(t, &sw->device->monitor->transport_list, link) { + if (t->device == sw->device) + continue; + if (t->device->adapter != sw->device->adapter) + continue; + if (spa_streq(t->endpoint_path, local_endpoint)) { + spa_log_debug(sw->device->monitor->log, "a2dp codec switch %p: endpoint %s in use, try next", + sw, local_endpoint); + goto next; + } + } + res = codec->select_config(codec, 0, ep->capabilities, ep->capabilities_len, &sw->device->monitor->default_audio_info, sw->device->settings, config); @@ -3031,6 +3046,8 @@ static DBusHandlerResult endpoint_set_configuration(DBusConnection *conn, transport->volumes[i].hw_volume_max = SPA_BT_VOLUME_A2DP_MAX; } + free(transport->endpoint_path); + transport->endpoint_path = strdup(endpoint); transport->profile = profile; transport->a2dp_codec = codec; transport_update_props(transport, &it[1], NULL); diff --git a/spa/plugins/bluez5/defs.h b/spa/plugins/bluez5/defs.h index 5efb2407f..2bdace5d3 100644 --- a/spa/plugins/bluez5/defs.h +++ b/spa/plugins/bluez5/defs.h @@ -574,6 +574,7 @@ struct spa_bt_transport { unsigned int codec; void *configuration; int configuration_len; + char *endpoint_path; uint32_t n_channels; uint32_t channels[64];