diff options
author | Mattias Agren <magren@broadcom.com> | 2012-04-13 12:16:49 +0200 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:17 -0700 |
commit | 2fe476a7b55eea667c854bb40e48648e8a0d5f1d (patch) | |
tree | 56e459b95e57e5b4a18c8a2ef2dc004604d19abb /btif/src | |
parent | c695e84c31973382c284e85020b0bb722597563a (diff) | |
download | external_bluetooth_bluedroid-2fe476a7b55eea667c854bb40e48648e8a0d5f1d.zip external_bluetooth_bluedroid-2fe476a7b55eea667c854bb40e48648e8a0d5f1d.tar.gz external_bluetooth_bluedroid-2fe476a7b55eea667c854bb40e48648e8a0d5f1d.tar.bz2 |
Added handling of AV HAL init if bluetooth not yet enabled
Change-Id: I19aa744676a98556b5c776c8dee73f91e0c01ff4
Diffstat (limited to 'btif/src')
-rw-r--r--[-rwxr-xr-x] | btif/src/bluetooth.c | 0 | ||||
-rw-r--r-- | btif/src/btif_av.c | 59 | ||||
-rw-r--r--[-rwxr-xr-x] | btif/src/btif_core.c | 26 | ||||
-rw-r--r--[-rwxr-xr-x] | btif/src/btif_dm.c | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | btif/src/btif_hh.c | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | btif/src/btif_hl.c | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/btif_media_task.c | 19 |
7 files changed, 85 insertions, 19 deletions
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 5864eac..5864eac 100755..100644 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c index 3c5afb4..a3987ad 100644 --- a/btif/src/btif_av.c +++ b/btif/src/btif_av.c @@ -100,7 +100,8 @@ static btif_av_cb_t btif_av_cb; static TIMER_LIST_ENT tle_av_open_on_rc; -#define CHECK_BTAV_INIT() if (bt_av_callbacks == NULL)\ +/* both interface and media task needs to be ready to alloc incoming request */ +#define CHECK_BTAV_INIT() if ((bt_av_callbacks == NULL) || (btif_av_cb.sm_handle == NULL))\ {\ BTIF_TRACE_WARNING1("%s: BTAV not initialized", __FUNCTION__);\ return BT_STATUS_NOT_READY;\ @@ -663,27 +664,21 @@ static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data) /******************************************************************************* ** -** Function init +** Function btif_av_init ** -** Description Initializes the AV interface +** Description Initializes btif AV if not already done ** ** Returns bt_status_t ** *******************************************************************************/ -static bt_status_t init(btav_callbacks_t* callbacks ) +bt_status_t btif_av_init(void) { - int status; - - BTIF_TRACE_EVENT1("%s", __FUNCTION__); - - status = btif_a2dp_start_media_task(); - - if (status != GKI_SUCCESS) + if (btif_av_cb.sm_handle == NULL) +{ + if (btif_a2dp_start_media_task() != GKI_SUCCESS) return BT_STATUS_FAIL; - bt_av_callbacks = callbacks; - btif_enable_service(BTA_A2DP_SERVICE_ID); /* Initialize the AVRC CB */ @@ -697,6 +692,43 @@ static bt_status_t init(btav_callbacks_t* callbacks ) return BT_STATUS_SUCCESS; } + return BT_STATUS_DONE; +} + +/******************************************************************************* +** +** Function init +** +** Description Initializes the AV interface +** +** Returns bt_status_t +** +*******************************************************************************/ + +static bt_status_t init(btav_callbacks_t* callbacks ) +{ + int status; + + BTIF_TRACE_EVENT1("%s", __FUNCTION__); + + if (bt_av_callbacks) + return BT_STATUS_DONE; + + bt_av_callbacks = callbacks; + btif_av_cb.sm_handle = NULL; + + /* check if stack/gki is started/enabled yet, if not defer until bluetooth + is enabled */ + + if (btif_is_enabled() == 0) + { + BTIF_TRACE_EVENT0("deferred av init until gki is enabled"); + return BT_STATUS_SUCCESS; + } + + return btif_av_init(); +} + /******************************************************************************* ** ** Function connect @@ -863,6 +895,7 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable) /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not * handle this request in order to allow incoming connections to succeed. * We need to put this back once support for this is added */ + /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not * auto-suspend av streaming on AG events(SCO or Call). The suspend shall * be initiated by the app/audioflinger layers */ diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c index b77cddb..f6f54f0 100755..100644 --- a/btif/src/btif_core.c +++ b/btif/src/btif_core.c @@ -55,6 +55,7 @@ ***********************************************************************************/ #include <hardware/bluetooth.h> + #include <string.h> #define LOG_TAG "BTIF_CORE" @@ -65,9 +66,11 @@ #include "btu.h" #include "bte.h" #include "bd.h" +#include "btif_av.h" #include "btif_storage.h" #include "btif_util.h" #include "btif_sock.h" + /************************************************************************************ ** Constants & Macros ************************************************************************************/ @@ -431,16 +434,25 @@ void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd) { /* store state */ btif_enabled = 1; - //init rfcomm & l2cap api + + /* check if we have a deferred av init */ + btif_av_init(); + + /* init rfcomm & l2cap api */ btif_sock_init(); + + /* load did configuration */ bte_load_did_conf(BTE_DID_CONF_FILE); + HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_ON); } else { - //cleanup rfcomm & l2cap api + /* cleanup rfcomm & l2cap api */ btif_sock_cleanup(); + btif_enabled = 0; + HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF); } } @@ -456,6 +468,7 @@ void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd) ** Returns void ** *******************************************************************************/ + bt_status_t btif_disable_bluetooth(void) { tBTA_STATUS status; @@ -467,8 +480,10 @@ bt_status_t btif_disable_bluetooth(void) } BTIF_TRACE_DEBUG1("%s", __FUNCTION__); - //cleanup rfcomm & l2cap api + + /* cleanup rfcomm & l2cap api */ btif_sock_cleanup(); + status = BTA_DisableBluetooth(); if (status != BTA_SUCCESS) @@ -1077,6 +1092,11 @@ tBTA_SERVICE_MASK btif_get_enabled_services_mask(void) return btif_enabled_services; } +int btif_is_enabled(void) +{ + return btif_enabled; +} + /******************************************************************************* ** ** Function btif_enable_service diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c index ee30090..ee30090 100755..100644 --- a/btif/src/btif_dm.c +++ b/btif/src/btif_dm.c diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c index 0b945a0..0b945a0 100755..100644 --- a/btif/src/btif_hh.c +++ b/btif/src/btif_hh.c diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c index 1e4ffaf..1e4ffaf 100755..100644 --- a/btif/src/btif_hl.c +++ b/btif/src/btif_hl.c diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index 70c48cc..a122408 100644..100755 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -671,6 +671,8 @@ static void btif_a2dp_encoder_update(void) int btif_a2dp_start_media_task(void) { + int retval; + if (media_task_running) { APPL_TRACE_ERROR0("warning : media task already running"); @@ -679,13 +681,22 @@ int btif_a2dp_start_media_task(void) APPL_TRACE_EVENT0("## A2DP START MEDIA TASK ##"); - media_task_running = 1; - /* start a2dp media task */ - return GKI_create_task((TASKPTR)btif_media_task, A2DP_MEDIA_TASK, + retval = GKI_create_task((TASKPTR)btif_media_task, A2DP_MEDIA_TASK, A2DP_MEDIA_TASK_TASK_STR, (UINT16 *) ((UINT8 *)a2dp_media_task_stack + A2DP_MEDIA_TASK_STACK_SIZE), sizeof(a2dp_media_task_stack)); + + if (retval != GKI_SUCCESS) + return retval; + + /* wait for task to come up to sure we are able to send messages to it */ + while (media_task_running == 0) + usleep(10); + + APPL_TRACE_EVENT0("## A2DP MEDIA TASK STARTED ##"); + + return retval; } /***************************************************************************** @@ -1123,6 +1134,8 @@ int btif_media_task(void *p) btif_media_task_init(); + media_task_running = 1; + while (1) { event = GKI_wait(0xffff, 0); |