From e42261c6d25978ef9a8915c3662c45fdbdc68852 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 6 Mar 2021 14:46:57 +0200 Subject: [PATCH] bluez5: remove per-device codec filtering This does not work as intended, because we no longer do a codec switch on device connect. It should be done in a different way, but since it's not used for anything right now, can as well remove it. --- spa/plugins/bluez5/backend-hsphfpd.c | 1 - spa/plugins/bluez5/backend-native.c | 1 - spa/plugins/bluez5/backend-ofono.c | 1 - spa/plugins/bluez5/bluez5-dbus.c | 40 +++++++--------------------- spa/plugins/bluez5/bluez5-device.c | 3 +-- spa/plugins/bluez5/defs.h | 2 -- 6 files changed, 10 insertions(+), 38 deletions(-) diff --git a/spa/plugins/bluez5/backend-hsphfpd.c b/spa/plugins/bluez5/backend-hsphfpd.c index 54273ae73..b6532e9f0 100644 --- a/spa/plugins/bluez5/backend-hsphfpd.c +++ b/spa/plugins/bluez5/backend-hsphfpd.c @@ -1121,7 +1121,6 @@ static DBusHandlerResult hsphfpd_parse_endpoint_properties(struct spa_bt_backend t->n_channels = 1; t->channels[0] = SPA_AUDIO_CHANNEL_MONO; - t->enabled = true; spa_bt_device_connect_profile(t->device, t->profile); spa_log_debug(backend->log, NAME": Transport %s available for hsphfpd", endpoint->path); diff --git a/spa/plugins/bluez5/backend-native.c b/spa/plugins/bluez5/backend-native.c index c3f5b2c5b..7d0ca8e05 100644 --- a/spa/plugins/bluez5/backend-native.c +++ b/spa/plugins/bluez5/backend-native.c @@ -147,7 +147,6 @@ static struct spa_bt_transport *_transport_create(struct rfcomm *rfcomm) t->backend = backend; t->n_channels = 1; t->channels[0] = SPA_AUDIO_CHANNEL_MONO; - t->enabled = true; spa_bt_transport_add_listener(t, &rfcomm->transport_listener, &transport_events, rfcomm); diff --git a/spa/plugins/bluez5/backend-ofono.c b/spa/plugins/bluez5/backend-ofono.c index a61b994bf..71a6d9824 100644 --- a/spa/plugins/bluez5/backend-ofono.c +++ b/spa/plugins/bluez5/backend-ofono.c @@ -128,7 +128,6 @@ static struct spa_bt_transport *_transport_create(struct spa_bt_backend *backend t->codec = codec; t->n_channels = 1; t->channels[0] = SPA_AUDIO_CHANNEL_MONO; - t->enabled = true; finish: return t; diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index e03be3b48..60604f1da 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -188,6 +188,10 @@ static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint) static bool is_a2dp_codec_enabled(struct spa_bt_monitor *monitor, const struct a2dp_codec *codec) { + if (!monitor->enable_sbc_xq && codec->feature_flag != NULL && + strcmp(codec->feature_flag, "sbc-xq") == 0) + return false; + return spa_dict_lookup(&monitor->enabled_codecs, codec->name) != NULL; } @@ -783,27 +787,11 @@ static int device_update_props(struct spa_bt_device *device, return 0; } -static bool device_can_accept_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec) -{ - struct spa_bt_monitor *monitor = device->monitor; - - /* Device capability checks in addition to A2DP Capabilities. */ - - if (!is_a2dp_codec_enabled(device->monitor, codec)) - return false; - - if (codec->feature_flag != NULL && strcmp(codec->feature_flag, "sbc-xq") == 0) - return monitor->enable_sbc_xq; - - /* The rest is determined by A2DP caps */ - return true; -} - bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec) { struct spa_bt_remote_endpoint *ep; - if (!device_can_accept_a2dp_codec(device, codec)) + if (!is_a2dp_codec_enabled(device->monitor, codec)) return false; if (!device->adapter->application_registered) { @@ -1806,7 +1794,7 @@ int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a */ if (spa_list_is_empty(&device->codec_switch_list) && preferred_codec != NULL) { spa_list_for_each(t, &device->transport_list, device_link) { - if (t->a2dp_codec != preferred_codec || !t->enabled) + if (t->a2dp_codec != preferred_codec) continue; if ((device->connected_profiles & t->profile) != t->profile) @@ -1841,7 +1829,7 @@ int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a } for (i = 0, j = 0; i < num_codecs; ++i) { - if (device_can_accept_a2dp_codec(device, codecs[i])) { + if (is_a2dp_codec_enabled(device->monitor, codecs[i])) { sw->codecs[j] = codecs[i]; ++j; } @@ -1952,16 +1940,6 @@ static DBusHandlerResult endpoint_set_configuration(DBusConnection *conn, spa_log_info(monitor->log, "%p: %s validate conf channels:%d", monitor, path, transport->n_channels); - /* - * Per-device determination of which codecs are allowed needs to be done also - * here. The A2DP codec switching process does this filtering, but before that - * BlueZ may autoconnect to any endpoint with compatible caps. In case it got it - * wrong, mark the transport disabled, and we'll switch to a better one later when - * needed. (We don't want to fail the connection, because we want to keep the - * profile connected.) - */ - transport->enabled = device_can_accept_a2dp_codec(transport->device, codec); - spa_bt_device_connect_profile(transport->device, transport->profile); if ((r = dbus_message_new_method_return(m)) == NULL) @@ -3148,8 +3126,6 @@ impl_init(const struct spa_handle_factory *factory, if ((res = parse_codec_array(this, info)) < 0) return res; - register_media_application(this); - if (info) { const char *str; @@ -3158,6 +3134,8 @@ impl_init(const struct spa_handle_factory *factory, this->enable_sbc_xq = true; } + register_media_application(this); + this->backend_native = backend_native_new(this, this->conn, info, support, n_support); this->backend_ofono = backend_ofono_new(this, this->conn, info, support, n_support); this->backend_hsphfpd = backend_hsphfpd_new(this, this->conn, info, support, n_support); diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index ac9f4d132..3ef27cd74 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -181,8 +181,7 @@ static struct spa_bt_transport *find_transport(struct impl *this, int profile, c for (i = 0; i < num_codecs; ++i) { spa_list_for_each(t, &device->transport_list, device_link) { - if (t->enabled && - (t->profile & device->connected_profiles) && + if ((t->profile & device->connected_profiles) && (t->profile & profile) == t->profile && (codecs[i] == NULL || t->a2dp_codec == codecs[i])) return t; diff --git a/spa/plugins/bluez5/defs.h b/spa/plugins/bluez5/defs.h index 9d9497232..e5b9cad1f 100644 --- a/spa/plugins/bluez5/defs.h +++ b/spa/plugins/bluez5/defs.h @@ -459,8 +459,6 @@ struct spa_bt_transport { void *configuration; int configuration_len; - unsigned int enabled:1; /**< Transport ready for use in sink/source */ - uint32_t n_channels; uint32_t channels[64];