diff --git a/system/bta/av/bta_av_aact.c b/system/bta/av/bta_av_aact.c index 0ee9947932bb29f8b83019d5c25fc92b69f63335..f36f43eacf22928131d6ba21f22d9334f262f52a 100644 --- a/system/bta/av/bta_av_aact.c +++ b/system/bta/av/bta_av_aact.c @@ -27,6 +27,7 @@ #include "bt_target.h" #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) +#include <assert.h> #include <string.h> #include "bta_av_int.h" #include "avdt_api.h" @@ -56,6 +57,8 @@ #define BTA_AV_RECONFIG_RETRY 6 #endif +static void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); + /* state machine states */ enum { @@ -234,7 +237,7 @@ tAVDT_CTRL_CBACK * const bta_av_dt_cback[] = ** ** Returns void ***********************************************/ -UINT8 bta_av_get_scb_handle ( tBTA_AV_SCB *p_scb, UINT8 local_sep ) +static UINT8 bta_av_get_scb_handle(tBTA_AV_SCB *p_scb, UINT8 local_sep) { UINT8 xx =0; for (xx = 0; xx<BTA_AV_MAX_SEPS; xx++) @@ -256,7 +259,7 @@ UINT8 bta_av_get_scb_handle ( tBTA_AV_SCB *p_scb, UINT8 local_sep ) ** ** Returns void ***********************************************/ -UINT8 bta_av_get_scb_sep_type ( tBTA_AV_SCB *p_scb, UINT8 tavdt_handle) +static UINT8 bta_av_get_scb_sep_type(tBTA_AV_SCB *p_scb, UINT8 tavdt_handle) { UINT8 xx =0; for (xx = 0; xx<BTA_AV_MAX_SEPS; xx++) @@ -328,7 +331,7 @@ static void notify_start_failed(tBTA_AV_SCB *p_scb) ** Returns void ** *******************************************************************************/ -void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) +static void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) { UNUSED(p_data); @@ -424,7 +427,7 @@ static BOOLEAN bta_av_next_getcap(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) ** Returns void ** *******************************************************************************/ -void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data, int index) +static void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data, int index) { tBTA_AV_STR_MSG *p_msg; UINT16 sec_len = 0; @@ -2038,7 +2041,7 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; bta_sys_set_policy(BTA_ID_AV, policy, p_scb->peer_addr); - if(p_scb->co_started) + if (p_scb->co_started) { bta_av_stream_chg(p_scb, FALSE); p_scb->co_started = FALSE; @@ -2048,15 +2051,16 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) } /* if q_info.a2d_list is not empty, drop it now */ - if(BTA_AV_CHNL_AUDIO == p_scb->chnl) { - while (!list_is_empty(p_scb->q_info.a2d_list)) { - p_buf = (BT_HDR*)list_front(p_scb->q_info.a2d_list); - list_remove(p_scb->q_info.a2d_list, p_buf); - GKI_freebuf(p_buf); - } + if (BTA_AV_CHNL_AUDIO == p_scb->chnl) { + while (!list_is_empty(p_scb->a2d_list)) + { + p_buf = (BT_HDR *)list_front(p_scb->a2d_list); + list_remove(p_scb->a2d_list, p_buf); + GKI_freebuf(p_buf); + } /* drop the audio buffers queued in L2CAP */ - if(p_data && p_data->api_stop.flush) + if (p_data && p_data->api_stop.flush) L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL); } @@ -2191,7 +2195,7 @@ void bta_av_reconfig (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) *******************************************************************************/ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) { - BT_HDR *p_buf; + BT_HDR *p_buf = NULL; UINT32 data_len; UINT32 timestamp; BOOLEAN new_buf = FALSE; @@ -2199,80 +2203,82 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data) tAVDT_DATA_OPT_MASK opt; UNUSED(p_data); - if (!p_scb->cong) + if (p_scb->cong) { - /* - APPL_TRACE_ERROR("q: %d", p_scb->l2c_bufs); - */ - //Always get the current number of bufs que'd up - p_scb->l2c_bufs = (UINT8)L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_GET); + return; + } - if (!list_is_empty(p_scb->q_info.a2d_list)) { - p_buf = (BT_HDR *)list_front(p_scb->q_info.a2d_list); - list_remove(p_scb->q_info.a2d_list, p_buf); - /* use q_info.a2d data, read the timestamp */ - timestamp = *(UINT32 *)(p_buf + 1); - } - else - { - new_buf = TRUE; - /* q_info.a2d_list empty, call co_data, dup data to other channels */ - p_buf = (BT_HDR *)p_scb->p_cos->data(p_scb->codec_type, &data_len, - ×tamp); + /* + APPL_TRACE_ERROR("q: %d", p_scb->l2c_bufs); + */ + //Always get the current number of bufs que'd up + p_scb->l2c_bufs = (UINT8)L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_GET); - if (p_buf) - { - /* use the offset area for the time stamp */ - *(UINT32 *)(p_buf + 1) = timestamp; + if (!list_is_empty(p_scb->a2d_list)) { + p_buf = (BT_HDR *)list_front(p_scb->a2d_list); + list_remove(p_scb->a2d_list, p_buf); + /* use q_info.a2d data, read the timestamp */ + timestamp = *(UINT32 *)(p_buf + 1); + } + else + { + new_buf = TRUE; + /* a2d_list empty, call co_data, dup data to other channels */ + p_buf = (BT_HDR *)p_scb->p_cos->data(p_scb->codec_type, &data_len, + ×tamp); - /* dup the data to other channels */ - bta_av_dup_audio_buf(p_scb, p_buf); - } + if (p_buf) + { + /* use the offset area for the time stamp */ + *(UINT32 *)(p_buf + 1) = timestamp; + + /* dup the data to other channels */ + bta_av_dup_audio_buf(p_scb, p_buf); } + } - if(p_buf) + if(p_buf) + { + if(p_scb->l2c_bufs < (BTA_AV_QUEUE_DATA_CHK_NUM)) { - if(p_scb->l2c_bufs < (BTA_AV_QUEUE_DATA_CHK_NUM)) + /* there's a buffer, just queue it to L2CAP */ + /* There's no need to increment it here, it is always read from L2CAP see above */ + /* p_scb->l2c_bufs++; */ + /* + APPL_TRACE_ERROR("qw: %d", p_scb->l2c_bufs); + */ + + /* opt is a bit mask, it could have several options set */ + opt = AVDT_DATA_OPT_NONE; + if (p_scb->no_rtp_hdr) { - /* there's a buffer, just queue it to L2CAP */ - /* There's no need to increment it here, it is always read from L2CAP see above */ - /* p_scb->l2c_bufs++; */ - /* - APPL_TRACE_ERROR("qw: %d", p_scb->l2c_bufs); - */ - - /* opt is a bit mask, it could have several options set */ - opt = AVDT_DATA_OPT_NONE; - if (p_scb->no_rtp_hdr) - { - opt |= AVDT_DATA_OPT_NO_RTP; - } + opt |= AVDT_DATA_OPT_NO_RTP; + } - AVDT_WriteReqOpt(p_scb->avdt_handle, p_buf, timestamp, m_pt, opt); - p_scb->cong = TRUE; + AVDT_WriteReqOpt(p_scb->avdt_handle, p_buf, timestamp, m_pt, opt); + p_scb->cong = TRUE; + } + else + { + /* there's a buffer, but L2CAP does not seem to be moving data */ + if(new_buf) + { + /* just got this buffer from co_data, + * put it in queue */ + list_append(p_scb->a2d_list, p_buf); } else { - /* there's a buffer, but L2CAP does not seem to be moving data */ - if(new_buf) - { - /* just got this buffer from co_data, - * put it in queue */ - list_append(p_scb->q_info.a2d_list, p_buf); + /* just dequeue it from the a2d_list */ + if (list_length(p_scb->a2d_list) < 3) { + /* put it back to the queue */ + list_prepend(p_scb->a2d_list, p_buf); } else { - /* just dequeue it from the q_info.a2d_list */ - if (list_length(p_scb->q_info.a2d_list) < 3) { - /* put it back to the queue */ - list_prepend(p_scb->q_info.a2d_list, p_buf); - } - else - { - /* too many buffers in q_info.a2d_list, drop it. */ - bta_av_co_audio_drop(p_scb->hndl); - GKI_freebuf(p_buf); - } + /* too many buffers in a2d_list, drop it. */ + bta_av_co_audio_drop(p_scb->hndl); + GKI_freebuf(p_buf); } } } diff --git a/system/bta/av/bta_av_act.c b/system/bta/av/bta_av_act.c index b6f339b96d7fe9144a6cd6ae2cf7c8d572bcdd5a..a86e43a477c5b6e71cb564c689e34eb2182c9cd3 100644 --- a/system/bta/av/bta_av_act.c +++ b/system/bta/av/bta_av_act.c @@ -1980,11 +1980,11 @@ void bta_av_dereg_comp(tBTA_AV_DATA *p_data) } p_cb->conn_audio &= ~mask; - if (p_scb->q_tag == BTA_AV_Q_TAG_STREAM) { - /* make sure no buffers are in q_info.a2d */ - while (!list_is_empty(p_scb->q_info.a2d_list)) { - p_buf = (BT_HDR*)list_front(p_scb->q_info.a2d_list); - list_remove(p_scb->q_info.a2d_list, p_buf); + if (p_scb->q_tag == BTA_AV_Q_TAG_STREAM && p_scb->a2d_list) { + /* make sure no buffers are in a2d_list */ + while (!list_is_empty(p_scb->a2d_list)) { + p_buf = (BT_HDR*)list_front(p_scb->a2d_list); + list_remove(p_scb->a2d_list, p_buf); GKI_freebuf(p_buf); } } diff --git a/system/bta/av/bta_av_int.h b/system/bta/av/bta_av_int.h index 7e186fd3fae9b6726007a956187fd8b265964966..6764e941dd109047410393a7f12947093e9fa069 100644 --- a/system/bta/av/bta_av_int.h +++ b/system/bta/av/bta_av_int.h @@ -438,7 +438,6 @@ typedef struct typedef union { - list_t *a2d_list; /* used for audio channels only */ tBTA_AV_VF_INFO vdp; /* used for video channels only */ tBTA_AV_API_OPEN open; /* used only before open and role switch is needed on another AV channel */ @@ -471,6 +470,7 @@ typedef struct tSDP_DISCOVERY_DB *p_disc_db; /* pointer to discovery database */ tBTA_AV_SEP seps[BTA_AV_MAX_SEPS]; tAVDT_CFG *p_cap; /* buffer used for get capabilities */ + list_t *a2d_list; /* used for audio channels only */ tBTA_AV_Q_INFO q_info; tAVDT_SEP_INFO sep_info[BTA_AV_NUM_SEPS]; /* stream discovery results */ tAVDT_CFG cfg; /* local SEP configuration */ @@ -626,7 +626,6 @@ extern void bta_av_restore_switch (void); extern UINT16 bta_av_chk_mtu(tBTA_AV_SCB *p_scb, UINT16 mtu); extern void bta_av_conn_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data); extern UINT8 bta_av_rc_create(tBTA_AV_CB *p_cb, UINT8 role, UINT8 shdl, UINT8 lidx); -extern void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data, int index); extern void bta_av_stream_chg(tBTA_AV_SCB *p_scb, BOOLEAN started); extern BOOLEAN bta_av_is_scb_opening (tBTA_AV_SCB *p_scb); extern BOOLEAN bta_av_is_scb_incoming (tBTA_AV_SCB *p_scb); @@ -683,7 +682,6 @@ extern void bta_av_disconnect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); extern void bta_av_security_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); extern void bta_av_security_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); extern void bta_av_setconfig_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); -extern void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); extern void bta_av_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); extern void bta_av_security_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); extern void bta_av_security_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data); diff --git a/system/bta/av/bta_av_main.c b/system/bta/av/bta_av_main.c index 47f830f21eb405909ffa4c32dcb1ef79c454da04..4d7ead546fb64fead14ecfa5a31fe9bd94bbbc45 100644 --- a/system/bta/av/bta_av_main.c +++ b/system/bta/av/bta_av_main.c @@ -25,6 +25,7 @@ #include "bt_target.h" #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) +#include <assert.h> #include <string.h> #include "bta_av_int.h" #include "utl.h" @@ -383,6 +384,7 @@ static tBTA_AV_SCB * bta_av_alloc_scb(tBTA_AV_CHNL chnl) p_ret->chnl = chnl; p_ret->hndl = (tBTA_AV_HNDL)((xx + 1) | chnl); p_ret->hdi = xx; + p_ret->a2d_list = list_new(NULL); bta_av_cb.p_scb[xx] = p_ret; } break; @@ -392,6 +394,25 @@ static tBTA_AV_SCB * bta_av_alloc_scb(tBTA_AV_CHNL chnl) return p_ret; } +/******************************************************************************* +** +** Function bta_av_free_scb +** +** Description free stream control block, +** +** +** Returns void +** +*******************************************************************************/ +static void bta_av_free_scb(tBTA_AV_SCB *p_scb) +{ + // NOTE(google) This free currently is not called + assert(p_scb != NULL); + + list_free(p_scb->a2d_list); + GKI_freebuf(p_scb); +} + /******************************************************************************* *******************************************************************************/ void bta_av_conn_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data) @@ -1200,11 +1221,12 @@ void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf) if(p_new) { memcpy(p_new, p_buf, copy_size); - list_append(p_scbi->q_info.a2d_list, p_new); - if (list_length(p_scbi->q_info.a2d_list) > p_bta_av_cfg->audio_mqs) { + list_append(p_scbi->a2d_list, p_new); + if (list_length(p_scbi->a2d_list) > p_bta_av_cfg->audio_mqs) { + // Drop the oldest packet bta_av_co_audio_drop(p_scbi->hndl); - BT_HDR *p_buf = list_front(p_scbi->q_info.a2d_list); - list_remove(p_scbi->q_info.a2d_list, p_buf); + BT_HDR *p_buf = list_front(p_scbi->a2d_list); + list_remove(p_scbi->a2d_list, p_buf); GKI_freebuf(p_buf); } }