Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc910940 authored by Zhihai Xu's avatar Zhihai Xu
Browse files

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
parent e9967ae9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "gki.h"
#include "bd.h"
#include "btu.h"
#include "bt_utils.h"

/*****************************************************************************
**  Constants & Macros
@@ -586,9 +587,17 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data

            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:
+1 −0
Original line number Diff line number Diff line
@@ -39,5 +39,6 @@ typedef enum {
void bt_utils_init();
void bt_utils_cleanup();
void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task);
void adjust_priority_a2dp(int start);

#endif /* BT_UTILS_H */
+32 −0
Original line number Diff line number Diff line
@@ -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);
            }
        }
    }
}