From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx> Use the transport's state to not only update the ports availability, but also to update the card profile availability flag. The interpretation is as follows: - PA_PROFILE_AVAILABLE_UNKNOWN: BT profile is connected but no audio - PA_PROFILE_AVAILABLE_NO: BT profile disconnected - PA_PROFILE_AVAILABLE_YES: BT profile connected and audio streaming --- src/modules/bluetooth/module-bluetooth-device.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 33b2afa..0eaa4e5 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -1210,11 +1210,21 @@ static pa_port_available_t transport_state_to_availability_merged(pa_bluetooth_t return PA_PORT_AVAILABLE_UNKNOWN; } +static pa_profile_available_t transport_state_to_profile_availability(pa_bluetooth_transport_state_t state) { + if (state == PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED) + return PA_PROFILE_AVAILABLE_NO; + else if (state >= PA_BLUETOOTH_TRANSPORT_STATE_PLAYING) + return PA_PROFILE_AVAILABLE_YES; + else + return PA_PROFILE_AVAILABLE_UNKNOWN; +} + /* Run from main thread */ static void handle_transport_state_change(struct userdata *u, struct pa_bluetooth_transport *transport) { bool acquire = false; bool release = false; enum profile profile; + pa_card_profile *cp; pa_bluetooth_transport_state_t state; pa_assert(u); @@ -1223,9 +1233,13 @@ static void handle_transport_state_change(struct userdata *u, struct pa_bluetoot profile = transport->profile; state = transport->state; - if (!pa_hashmap_get(u->card->profiles, pa_bt_profile_to_string(profile))) + /* Update profile availability */ + if (!(cp = pa_hashmap_get(u->card->profiles, pa_bt_profile_to_string(profile)))) return; + pa_card_profile_set_available(cp, transport_state_to_profile_availability(state)); + + /* Update port availability */ switch (profile) { case PROFILE_HFGW: { pa_device_port *port; @@ -1301,6 +1315,7 @@ static void handle_transport_state_change(struct userdata *u, struct pa_bluetoot pa_assert_not_reached(); } + /* Acquire or release transport as needed */ if (acquire) if (bt_transport_acquire(u, true) >= 0) { if (u->source) { -- 1.8.1