struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
struct str_parms *parms;
char keyval[16];
- int retval = 0;
+ int retval;
+ int status = 0;
INFO("state %d", out->state);
if (strcmp(keyval, "true") == 0)
{
if (out->state == AUDIO_A2DP_STATE_STARTED)
- retval = suspend_audio_datapath(out, false);
+ status = suspend_audio_datapath(out, false);
}
else
{
if (out->state == AUDIO_A2DP_STATE_SUSPENDED)
out->state = AUDIO_A2DP_STATE_STANDBY;
/* Irrespective of the state, return 0 */
- retval = 0;
}
}
pthread_mutex_unlock(&out->lock);
str_parms_destroy(parms);
- return retval;
+ return status;
}
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
return -ENOMEM;
adev->device.common.tag = HARDWARE_DEVICE_TAG;
- adev->device.common.version = AUDIO_DEVICE_API_VERSION_CURRENT;
+ adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
adev->device.common.module = (struct hw_module_t *) module;
adev->device.common.close = adev_close;
bta_gattc_clcb_dealloc(p_clcb);
if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT)
+ {
cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific);
+ }
+ else if (p_data->hdr.event == BTA_GATTC_INT_DISCONN_EVT)
+ {
+ cb_data.close.status = p_data->int_conn.reason;
+ }
if(p_cback)
(* p_cback)(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC *)&cb_data);
{
tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if);
tBTA_GATTC cb_data;
- (void)(p_cb);
+ UNUSED(p_cb);
cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start);
#include "gki.h"
#include "bd.h"
#include "btu.h"
+#include "bt_utils.h"
/*****************************************************************************
** Constants & Macros
HAL_CBACK(bt_av_callbacks, audio_state_cb,
BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
+
+ /* increase the a2dp consumer task priority temporarily when start
+ ** audio playing, to avoid overflow the audio packet queue. */
+ adjust_priority_a2dp(TRUE);
+
break;
case BTIF_SM_EXIT_EVT:
+ /* restore the a2dp consumer task priority when stop audio playing. */
+ adjust_priority_a2dp(FALSE);
+
break;
case BTIF_AV_START_STREAM_REQ_EVT:
** Local type definitions
******************************************************************************/
-#define pthread_cond_timedwait_monotonic pthread_cond_timedwait
-
typedef struct
{
UINT8 task_id; /* GKI task id */
gki_cb.com.OSWaitEvt[task_id] = 0;
/* Initialize mutex and condition variable objects for events and timeouts */
+ pthread_condattr_t cond_attr;
+ pthread_condattr_init(&cond_attr);
+ pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
+
pthread_mutex_init(&gki_cb.os.thread_evt_mutex[task_id], NULL);
- pthread_cond_init (&gki_cb.os.thread_evt_cond[task_id], NULL);
+ pthread_cond_init (&gki_cb.os.thread_evt_cond[task_id], &cond_attr);
pthread_mutex_init(&gki_cb.os.thread_timeout_mutex[task_id], NULL);
pthread_cond_init (&gki_cb.os.thread_timeout_cond[task_id], NULL);
}
abstime.tv_sec += sec;
- pthread_cond_timedwait_monotonic(&gki_cb.os.thread_evt_cond[rtask],
+ pthread_cond_timedwait(&gki_cb.os.thread_evt_cond[rtask],
&gki_cb.os.thread_evt_mutex[rtask], &abstime);
-
}
else
{
/* The MTU size for the L2CAP configuration. */
#ifndef SDP_MTU_SIZE
-#define SDP_MTU_SIZE 256
+#define SDP_MTU_SIZE 672
#endif
/* The flush timeout for the L2CAP configuration. */
lpm_enabled = FALSE;
- bte_hci_enable();
-
GKI_create_task((TASKPTR)btu_task, BTU_TASK, BTE_BTU_TASK_STR,
(UINT16 *) ((UINT8 *)bte_btu_stack + BTE_BTU_STACK_SIZE),
sizeof(bte_btu_stack));
+ bte_hci_enable();
+
GKI_run(0);
}
BD_NAME bd_name;
memset(bd_name, 0, (BD_NAME_LEN + 1));
+ if (length > BD_NAME_LEN)
+ {
+ length = BD_NAME_LEN;
+ }
memcpy((UINT8*)bd_name, p_name, length);
if ((!status) || (length==0))
else
{
/* Get a scratch buffer to store response */
- if (!p_ccb->rsp_list)
+ if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len))
{
+ /* Free and reallocate if the earlier allocated buffer is small */
+ if (p_ccb->rsp_list)
+ {
+ GKI_freebuf (p_ccb->rsp_list);
+ }
+
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
else
{
/* Get a scratch buffer to store response */
- if (!p_ccb->rsp_list)
+ if (!p_ccb->rsp_list || (GKI_get_buf_size(p_ccb->rsp_list) < max_list_len))
{
+ /* Free and reallocate if the earlier allocated buffer is small */
+ if (p_ccb->rsp_list)
+ {
+ GKI_freebuf (p_ccb->rsp_list);
+ }
+
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
void bt_utils_init();
void bt_utils_cleanup();
void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task);
+void adjust_priority_a2dp(int start);
#define UNUSED(x) (void)(x)
static BOOLEAN g_DoSchedulingGroup[TASK_HIGH_MAX];
static pthread_mutex_t gIdxLock;
static int g_TaskIdx;
+static int g_TaskIDs[TASK_HIGH_MAX];
+#define INVALID_TASK_ID (-1)
/*****************************************************************************
**
for(i = 0; i < TASK_HIGH_MAX; i++) {
g_DoSchedulingGroupOnce[i] = PTHREAD_ONCE_INIT;
g_DoSchedulingGroup[i] = TRUE;
+ g_TaskIDs[i] = INVALID_TASK_ID;
}
pthread_mutexattr_init(&lock_attr);
pthread_mutex_init(&gIdxLock, &lock_attr);
// set_sched_policy does not support tid == 0
rc = set_sched_policy(tid, SP_FOREGROUND);
}
+ g_TaskIDs[high_task] = tid;
pthread_mutex_unlock(&gIdxLock);
if (rc) {
}
}
+/*****************************************************************************
+**
+** Function adjust_priority_a2dp
+**
+** Description increase the a2dp consumer task priority temporarily when start
+** audio playing, to avoid overflow the audio packet queue, restore
+** the a2dp consumer task priority when stop audio playing.
+**
+** Returns void
+**
+*******************************************************************************/
+void adjust_priority_a2dp(int start) {
+ int priority = start ? ANDROID_PRIORITY_URGENT_AUDIO : ANDROID_PRIORITY_AUDIO;
+ int tid;
+ int i;
+
+ for (i = TASK_HIGH_GKI_TIMER; i < TASK_HIGH_MAX; i++)
+ {
+ tid = g_TaskIDs[i];
+ if (tid != INVALID_TASK_ID)
+ {
+ if (setpriority(PRIO_PROCESS, tid, priority) < 0)
+ {
+ ALOGW("failed to change priority tid: %d to %d", tid, priority);
+ }
+ }
+ }
+}