summaryrefslogtreecommitdiffstats
path: root/utils/src
diff options
context:
space:
mode:
authorZhihai Xu <zhihaixu@google.com>2014-01-08 11:45:17 -0800
committerZhihai Xu <zhihaixu@google.com>2014-01-08 11:45:17 -0800
commit4128e36cd8430dfbed16d364e6ab5265e1642db5 (patch)
tree83f18430a833bce1f059ea32d83a0266cbc42fa3 /utils/src
parent6567fa2d9d9d4f30e9ff5d1eb17794fae4771458 (diff)
downloadandroid_system_bt-4128e36cd8430dfbed16d364e6ab5265e1642db5.tar.gz
android_system_bt-4128e36cd8430dfbed16d364e6ab5265e1642db5.tar.bz2
android_system_bt-4128e36cd8430dfbed16d364e6ab5265e1642db5.zip
increase the bluetooth task priority when start a2dp.
change the BT task priority based on audio play state. increase the BT task priority to ANDROID_PRIORITY_URGENT_AUDIO ,when start ad2p audio playing. to better prevent CPU premption by other process/task(UI). restore the BT task priority when stop a2dp audio playing. bug:12082841 Change-Id: I34e8344cffea87f68987149c820cd3e84a4196d1
Diffstat (limited to 'utils/src')
-rw-r--r--utils/src/bt_utils.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/utils/src/bt_utils.c b/utils/src/bt_utils.c
index aeb929297..6decacf00 100644
--- a/utils/src/bt_utils.c
+++ b/utils/src/bt_utils.c
@@ -50,6 +50,8 @@ static pthread_once_t g_DoSchedulingGroupOnce[TASK_HIGH_MAX];
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)
/*****************************************************************************
**
@@ -67,6 +69,7 @@ void bt_utils_init() {
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);
@@ -126,6 +129,7 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) {
// 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) {
@@ -137,3 +141,31 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) {
}
}
+/*****************************************************************************
+**
+** 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);
+ }
+ }
+ }
+}