diff options
author | Szymon Janc <szymon.janc@tieto.com> | 2015-02-16 16:15:53 +0100 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2015-02-17 18:36:43 +0100 |
commit | 449381885f9ea3424bb721d7c9930d5b5a45a6c3 (patch) | |
tree | 703f0634c7d8240f3b13be8ccd4418c0787b7263 /android/handsfree.c | |
parent | 606b5e7054bbb5128f2fe000c2736efe475f2b9f (diff) | |
download | bluez-449381885f9ea3424bb721d7c9930d5b5a45a6c3.tar.gz |
android/handsfree: Refactor connect_sco_cb
This is to avoid unnecessary connecting->disconnected
and disconnected->connecting transitions when doing fallback to
CVSD codec.
Diffstat (limited to 'android/handsfree.c')
-rw-r--r-- | android/handsfree.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/android/handsfree.c b/android/handsfree.c index ba798ee18..7cdc8b4a8 100644 --- a/android/handsfree.c +++ b/android/handsfree.c @@ -968,24 +968,21 @@ static void connect_sco_cb(enum sco_status status, const bdaddr_t *addr) return; } - if (status != SCO_STATUS_OK) { - error("handsfree: audio connect failed"); - - set_audio_state(dev, HAL_EV_HANDSFREE_AUDIO_STATE_DISCONNECTED); - - if (!codec_negotiation_supported(dev)) - return; - - /* If other failed, try connecting with CVSD */ - if (dev->negotiated_codec != CODEC_ID_CVSD) { - info("handsfree: trying fallback with CVSD"); - select_codec(dev, CODEC_ID_CVSD); - } + if (status == SCO_STATUS_OK) { + set_audio_state(dev, HAL_EV_HANDSFREE_AUDIO_STATE_CONNECTED); + return; + } + /* Try fallback to CVSD first */ + if (codec_negotiation_supported(dev) && + dev->negotiated_codec != CODEC_ID_CVSD) { + info("handsfree: trying fallback with CVSD"); + select_codec(dev, CODEC_ID_CVSD); return; } - set_audio_state(dev, HAL_EV_HANDSFREE_AUDIO_STATE_CONNECTED); + error("handsfree: audio connect failed"); + set_audio_state(dev, HAL_EV_HANDSFREE_AUDIO_STATE_DISCONNECTED); } static bool connect_sco(struct hf_device *dev) |