From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx> Merge the existing two ports into a single port, because the state is redundant and actually PulseAudio supports input-output ports. This new representation is not only more natural, but also more friendly with module-switch-on-port-available. This module will now integrate nicely by switching between A2DP and HFP/HSP profiles when the ports become available. --- src/modules/bluetooth/module-bluetooth-device.c | 46 +++++------------------ 1 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index c1a88b0..a65eb2f 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -1320,10 +1320,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us pa_device_port *port; pa_port_available_t available = audio_state_to_availability(state); - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw-output")); - pa_device_port_set_available(port, available); - - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw-input")); + pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw")); pa_device_port_set_available(port, available); acquire = (available == PA_PORT_AVAILABLE_YES && u->profile == PROFILE_HFGW); @@ -1335,10 +1332,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us pa_device_port *port; pa_port_available_t available = audio_state_to_availability(state); - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp-output")); - pa_device_port_set_available(port, available); - - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp-input")); + pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp")); pa_device_port_set_available(port, available); acquire = (available == PA_PORT_AVAILABLE_YES && u->profile == PROFILE_HSP); @@ -1586,24 +1580,20 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_ break; case PROFILE_HSP: - if (direction == PA_DIRECTION_OUTPUT) { - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp-output")); + pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp")); + if (direction == PA_DIRECTION_OUTPUT) pa_assert_se(pa_hashmap_put(data.sink_new_data->ports, port->name, port) >= 0); - } else { - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp-input")); + else pa_assert_se(pa_hashmap_put(data.source_new_data->ports, port->name, port) >= 0); - } pa_device_port_ref(port); break; case PROFILE_HFGW: - if (direction == PA_DIRECTION_OUTPUT) { - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw-output")); + pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw")); + if (direction == PA_DIRECTION_OUTPUT) pa_assert_se(pa_hashmap_put(data.sink_new_data->ports, port->name, port) >= 0); - } else { - pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw-input")); + else pa_assert_se(pa_hashmap_put(data.source_new_data->ports, port->name, port) >= 0); - } pa_device_port_ref(port); break; @@ -2234,17 +2224,9 @@ static void create_ports_for_profile(struct userdata *u, const pa_bluetooth_devi break; case PROFILE_HSP: - pa_assert_se(port = pa_device_port_new(u->core, "hsp-output", _("Bluetooth Telephony (HSP/HFP)"), 0)); + pa_assert_se(port = pa_device_port_new(u->core, "hsp", _("Bluetooth Telephony (HSP/HFP)"), 0)); pa_assert_se(pa_hashmap_put(card_new_data->ports, port->name, port) >= 0); port->is_output = 1; - port->is_input = 0; - port->priority = profile->priority * 100; - port->available = audio_state_to_availability(device->headset_state); - pa_hashmap_put(port->profiles, profile->name, profile); - - pa_assert_se(port = pa_device_port_new(u->core, "hsp-input", _("Bluetooth Telephony (HSP/HFP)"), 0)); - pa_assert_se(pa_hashmap_put(card_new_data->ports, port->name, port) >= 0); - port->is_output = 0; port->is_input = 1; port->priority = profile->priority * 100; port->available = audio_state_to_availability(device->headset_state); @@ -2252,17 +2234,9 @@ static void create_ports_for_profile(struct userdata *u, const pa_bluetooth_devi break; case PROFILE_HFGW: - pa_assert_se(port = pa_device_port_new(u->core, "hfgw-output", _("Bluetooth Handsfree Gateway"), 0)); + pa_assert_se(port = pa_device_port_new(u->core, "hfgw", _("Bluetooth Handsfree Gateway"), 0)); pa_assert_se(pa_hashmap_put(card_new_data->ports, port->name, port) >= 0); port->is_output = 1; - port->is_input = 0; - port->priority = profile->priority * 100; - port->available = audio_state_to_availability(device->hfgw_state); - pa_hashmap_put(port->profiles, profile->name, profile); - - pa_assert_se(port = pa_device_port_new(u->core, "hfgw-input", _("Bluetooth Handsfree Gateway"), 0)); - pa_assert_se(pa_hashmap_put(card_new_data->ports, port->name, port) >= 0); - port->is_output = 0; port->is_input = 1; port->priority = profile->priority * 100; port->available = audio_state_to_availability(device->hfgw_state); -- 1.7.7.6