From: Mikel Astiz <mikel.as...@bmw-carit.de> The transport state also reflects the state of the audio interface. The state redundancy can thus be minimized by always using the first one, and avoiding the use of profile-specific states with the exception of finding out the initial state of a transport. --- src/modules/bluetooth/bluetooth-util.c | 13 ++++++++++++- src/modules/bluetooth/module-bluetooth-device.c | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index e324336..3ce21c6 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -1087,7 +1087,7 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) { return false; for (i = 0; i < PA_BLUETOOTH_PROFILE_COUNT; i++) - if (d->profile_state[i] >= PA_BT_AUDIO_STATE_CONNECTED) + if (d->transports[i]) return true; return false; @@ -1257,6 +1257,7 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage enum profile p; DBusMessageIter args, props; DBusMessage *r; + bool old_any_connected; dbus_message_iter_init(m, &args); @@ -1330,6 +1331,8 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage goto fail; } + old_any_connected = pa_bluetooth_device_any_audio_connected(d); + sender = dbus_message_get_sender(m); t = transport_new(d, sender, path, p, config, size); @@ -1343,6 +1346,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage pa_assert_se(r = dbus_message_new_method_return(m)); + if (old_any_connected != pa_bluetooth_device_any_audio_connected(d)) + run_callback(d, FALSE); + return r; fail: @@ -1368,12 +1374,17 @@ static DBusMessage *endpoint_clear_configuration(DBusConnection *c, DBusMessage } if ((t = pa_hashmap_get(y->transports, path))) { + bool old_any_connected = t->device ? pa_bluetooth_device_any_audio_connected(t->device) : false; + pa_log_debug("Clearing transport %s profile %d", t->path, t->profile); t->device->transports[t->profile] = NULL; pa_hashmap_remove(y->transports, t->path); t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED; pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t); transport_free(t); + + if (t->device && old_any_connected != pa_bluetooth_device_any_audio_connected(t->device)) + run_callback(t->device, FALSE); } pa_assert_se(r = dbus_message_new_method_return(m)); diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index f0fcdac..91e9d15 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -2094,7 +2094,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) { if (*d != PROFILE_OFF) { const pa_bluetooth_device *device = u->device; - if (device->profile_state[*d] < PA_BT_AUDIO_STATE_CONNECTED) { + if (!device->transports[*d]) { pa_log_warn("Profile not connected, refused to switch profile to %s", new_profile->name); return -PA_ERR_IO; } @@ -2357,7 +2357,7 @@ static int add_card(struct userdata *u) { d = PA_CARD_PROFILE_DATA(u->card->active_profile); - if (*d != PROFILE_OFF && (device->profile_state[*d] < PA_BT_AUDIO_STATE_CONNECTED)) { + if (*d != PROFILE_OFF && !device->transports[*d]) { pa_log_warn("Default profile not connected, selecting off profile"); u->card->active_profile = pa_hashmap_get(u->card->profiles, "off"); u->card->save_profile = FALSE; -- 1.7.11.7 _______________________________________________ pulseaudio-discuss mailing list pulseaudio-discuss@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss