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

Commit cc9daa7a authored by Sanket Agarwal's avatar Sanket Agarwal
Browse files

Move focus handling entirely to component calling fluoride.

Audio focus handling for A2DP sink currently split between Fluoride and
the component sitting on top of it. Since this is not the best place to
decide policies, we move all such decisions to the upper layer.

Bug: b/26928143

Change-Id: I67a1a2a50782289e7e31447b01ee29a21bc8dac2
parent cb782072
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -101,9 +101,7 @@ typedef struct

#ifdef USE_AUDIO_TRACK
typedef enum {
        BTIF_MEDIA_FOCUS_IDLE = 0,
        BTIF_MEDIA_FOCUS_READY,
        BTIF_MEDIA_FOCUS_REQUESTED,
        BTIF_MEDIA_FOCUS_NOT_GRANTED = 0,
        BTIF_MEDIA_FOCUS_GRANTED
} btif_media_audio_focus_state;

+33 −27
Original line number Diff line number Diff line
@@ -247,6 +247,16 @@ static void btif_initiate_av_open_timer_timeout(UNUSED_ATTR void *data)
**  Static functions
******************************************************************************/

/*******************************************************************************
**
** Function         btif_report_connection_state
**
** Description      Updates the components via the callbacks about the connection
**                  state of a2dp connection.
**
** Returns          None
**
*******************************************************************************/
static void btif_report_connection_state(btav_connection_state_t state, bt_bdaddr_t *bd_addr)
{
    if (bt_av_sink_callbacks != NULL) {
@@ -256,6 +266,19 @@ static void btif_report_connection_state(btav_connection_state_t state, bt_bdadd
    }
}

/*******************************************************************************
**
** Function         btif_report_audio_state
**
** Description      Updates the components via the callbacks about the audio
**                  state of a2dp connection. The state is updated when either
**                  the remote ends starts streaming (started state) or whenever
**                  it transitions out of started state (to opened or streaming)
**                  state.
**
** Returns          None
**
*******************************************************************************/
static void btif_report_audio_state(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
{
    if (bt_av_sink_callbacks != NULL) {
@@ -746,9 +769,6 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
            if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
            {
                btif_a2dp_set_rx_flush(FALSE); /*  remove flush state, ready for streaming*/
#ifdef USE_AUDIO_TRACK
                audio_focus_status(BTIF_MEDIA_FOCUS_READY);
#endif
            }

            /* change state to started, send acknowledgement if start is pending */
@@ -855,6 +875,11 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
            /* we are again in started state, clear any remote suspend flags */
            btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;

            /**
             * Report to components above that we have entered the streaming
             * stage, this should usually be followed by focus grant.
             * see update_audio_focus_state()
             */
            btif_report_audio_state(BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));

            /* increase the a2dp consumer task priority temporarily when start
@@ -960,13 +985,6 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
            btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
            break;

#ifdef USE_AUDIO_TRACK
            case BTIF_AV_SINK_FOCUS_REQ_EVT:
                HAL_CBACK(bt_av_sink_callbacks, audio_focus_request_cb,
                                                   &(btif_av_cb.peer_bda));
            break;
#endif

        case BTA_AV_STOP_EVT:

            btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
@@ -1214,32 +1232,20 @@ static bt_status_t init_sink(btav_callbacks_t* callbacks)
#ifdef USE_AUDIO_TRACK
/*******************************************************************************
**
** Function         audio_focus_status
** Function         update_audio_focus_state
**
** Description      Update Audio Focus State
** Description      Updates the final focus state reported by components calling
**                  this module.
**
** Returns          None
**
*******************************************************************************/
void audio_focus_status(int state)
void update_audio_focus_state(int state)
{
    BTIF_TRACE_DEBUG("%s state %d ",__func__, state);
    btif_a2dp_set_audio_focus_state(state);
}

/*******************************************************************************
**
** Function         btif_queue_focus_request
**
** Description      This is used to move context to btif and queue audio_focus_request
**
** Returns          none
**
*******************************************************************************/
void btif_queue_focus_request(void)
{
    btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_FOCUS_REQ_EVT, NULL, 0, NULL);
}
#endif

/*******************************************************************************
@@ -1360,7 +1366,7 @@ static const btav_interface_t bt_av_sink_interface = {
    disconnect,
    cleanup_sink,
#ifdef USE_AUDIO_TRACK
    audio_focus_status,
    update_audio_focus_state,
#else
    NULL,
#endif
+7 −19
Original line number Diff line number Diff line
@@ -891,7 +891,7 @@ void btif_a2dp_stop_media_task(void)

void btif_a2dp_on_init(void)
{
    //tput_mon(1, 0, 1);
    btif_media_cb.rx_audio_focus_state = BTIF_MEDIA_FOCUS_NOT_GRANTED;
}


@@ -965,9 +965,6 @@ void btif_a2dp_on_idle(void)
        btif_media_task_aa_rx_flush_req();
        btif_media_task_aa_handle_stop_decoding();
        btif_media_task_clear_track();
#ifdef USE_AUDIO_TRACK
        btif_media_cb.rx_audio_focus_state = BTIF_MEDIA_FOCUS_IDLE;
#endif
        APPL_TRACE_DEBUG("Stopped BT track");
    }
#endif
@@ -1266,23 +1263,14 @@ static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
    }
    else
    {

#ifdef USE_AUDIO_TRACK
        switch(btif_media_cb.rx_audio_focus_state)
        /* Don't Do anything in case of Not granted */
        if (btif_media_cb.rx_audio_focus_state == BTIF_MEDIA_FOCUS_NOT_GRANTED)
        {
            /* Don't Do anything in case of Idle, Requested */
            case BTIF_MEDIA_FOCUS_REQUESTED:
            case BTIF_MEDIA_FOCUS_IDLE:
            APPL_TRACE_DEBUG("%s skipping frames since focus is not present.", __func__);
            return;
            /* In case of Ready, request for focus and wait to move in granted */
            case BTIF_MEDIA_FOCUS_READY:
                btif_queue_focus_request();
                btif_media_cb.rx_audio_focus_state = BTIF_MEDIA_FOCUS_REQUESTED;
                return;
            /* play only in this case */
            case BTIF_MEDIA_FOCUS_GRANTED:
                break;
        }
        /* play only in BTIF_MEDIA_FOCUS_GRANTED case */
#endif
        if (btif_media_cb.rx_flush == TRUE)
        {