From 2113b0a5ed97b0e9805efac954dce4acd78fc77d Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Thu, 22 Oct 2015 18:05:39 +0200 Subject: hfp_ag_bluez5: use codec negotiation --- plugins/hfp_ag_bluez5.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c index 3aca792c..22faeb78 100644 --- a/plugins/hfp_ag_bluez5.c +++ b/plugins/hfp_ag_bluez5.c @@ -38,6 +38,11 @@ #include #include +typedef struct GAtChat GAtChat; +typedef struct GAtResult GAtResult; + +#include "drivers/atmodem/atutil.h" + #include "hfp.h" #include "bluez5.h" #include "bluetooth.h" @@ -69,12 +74,59 @@ static void hfp_card_remove(struct ofono_handsfree_card *card) DBG(""); } +static void codec_negotiation_done_cb(int err, void *data) +{ + struct cb_data *cbd = data; + ofono_handsfree_card_connect_cb_t cb = cbd->cb; + + DBG("err %d", err); + + if (err < 0) { + CALLBACK_WITH_FAILURE(cb, cbd->data); + goto done; + } + + /* + * We don't have anything to do at this point as when the + * codec negotiation succeeded the emulator internally + * already triggered the SCO connection setup of the + * handsfree card which also takes over the processing + * of the pending dbus message + */ + +done: + g_free(cbd); +} + static void hfp_card_connect(struct ofono_handsfree_card *card, ofono_handsfree_card_connect_cb_t cb, void *data) { + int err; + struct ofono_emulator *em = ofono_handsfree_card_get_data(card); + struct cb_data *cbd; + DBG(""); - ofono_handsfree_card_connect_sco(card); + + cbd = cb_data_new(cb, data); + + /* + * The emulator core will take care if the remote side supports + * codec negotiation or not. + */ + err = ofono_emulator_start_codec_negotiation(em, + codec_negotiation_done_cb, cbd); + if (err < 0) { + CALLBACK_WITH_FAILURE(cb, data); + + g_free(cbd); + return; + } + + /* + * We hand over to the emulator core here to establish the + * SCO connection once the codec is negotiated + * */ } static void hfp_sco_connected_hint(struct ofono_handsfree_card *card) @@ -208,6 +260,8 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, OFONO_HANDSFREE_CARD_TYPE_GATEWAY, HFP_AG_DRIVER, em); + ofono_handsfree_card_set_data(card, em); + ofono_handsfree_card_set_local(card, local); ofono_handsfree_card_set_remote(card, remote); -- cgit v1.2.3