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

Commit afa8eac4 authored by Chris Manton's avatar Chris Manton Committed by Andre Eisenbach
Browse files

Allocate a2d list properly

Some other minor cosmetic improvements
parent cd563c0d
Loading
Loading
Loading
Loading
+78 −72
Original line number Diff line number Diff line
@@ -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;
@@ -2049,9 +2052,10 @@ 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);
        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);
        }

@@ -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,24 +2203,27 @@ 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)
    {
        return;
    }

    /*
    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 (!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 (!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;
            /* q_info.a2d_list empty, call co_data, dup data to other channels */
        /* 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,
                                         &timestamp);

@@ -2258,18 +2265,18 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
            {
                /* just got this buffer from co_data,
                 * put it in queue */
                    list_append(p_scb->q_info.a2d_list, p_buf);
                list_append(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) {
                /* 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->q_info.a2d_list, p_buf);
                    list_prepend(p_scb->a2d_list, p_buf);
                }
                else
                {
                        /* too many buffers in q_info.a2d_list, drop it. */
                    /* too many buffers in a2d_list, drop it. */
                    bta_av_co_audio_drop(p_scb->hndl);
                    GKI_freebuf(p_buf);
                }
@@ -2277,7 +2284,6 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        }
    }
}
}

/*******************************************************************************
**
+5 −5
Original line number Diff line number Diff line
@@ -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);
                }
            }
+1 −3
Original line number Diff line number Diff line
@@ -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);
+26 −4
Original line number Diff line number Diff line
@@ -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);
                    }
                }