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

Commit 45ba86fc authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Andre Eisenbach
Browse files

Removed usage of A2DP codec_type as a separate field

The value of codec_type can be extracted from the codec_info,
so it is not needed to pass it around as an argument, or keep
it as an field.

Also:
* Added new APIs and the corresponding unit tests:
  - A2D_GetPacketTimestamp()
  - A2D_BuildCodecHeader() - replacement for bta_av_sbc_bld_hdr()
  - A2D_CodecName()
* Replaced tBTA_AV_SEP.codec_type with tBTA_AV_SEP.codec_info

Bug: 30958229
Test: A2DP tested manually. Unit tests included in the CL.
Change-Id: I3bfd4750e8639d77a9938ab3c274c9d6ea859fb6
parent 3278b4de
Loading
Loading
Loading
Loading
+37 −40
Original line number Diff line number Diff line
@@ -252,9 +252,11 @@ static uint8_t bta_av_get_scb_handle(tBTA_AV_SCB *p_scb, uint8_t local_sep)
{
    for (int i = 0; i < A2D_CODEC_SEP_INDEX_MAX; i++) {
        if ((p_scb->seps[i].tsep == local_sep) &&
            (p_scb->seps[i].codec_type == p_scb->codec_type))
            A2D_CodecTypeEquals(p_scb->seps[i].codec_info,
                                p_scb->cfg.codec_info)) {
            return (p_scb->seps[i].av_handle);
        }
    }
    APPL_TRACE_DEBUG("%s: local sep_type %d not found", __func__, local_sep)
    return 0; /* return invalid handle */
}
@@ -743,13 +745,16 @@ static void bta_av_a2d_sdp_cback(bool found, tA2D_Service *p_service)
*******************************************************************************/
static void bta_av_adjust_seps_idx(tBTA_AV_SCB *p_scb, uint8_t avdt_handle)
{
    APPL_TRACE_DEBUG("%s: codec_type: %d", __func__, p_scb->codec_type);
    for (int i = 0; i < A2D_CODEC_SEP_INDEX_MAX; i++) {
        APPL_TRACE_DEBUG("%s: av_handle: %d codec_type: %d", __func__,
            p_scb->seps[i].av_handle, p_scb->seps[i].codec_type);
        if((p_scb->seps[i].av_handle && p_scb->codec_type == p_scb->seps[i].codec_type)
            && (p_scb->seps[i].av_handle == avdt_handle))
        {
    APPL_TRACE_DEBUG("%s: codec: %s", __func__,
                     A2D_CodecName(p_scb->cfg.codec_info));
    for (tA2D_CODEC_SEP_INDEX i = 0; i < A2D_CODEC_SEP_INDEX_MAX; i++) {
        APPL_TRACE_DEBUG("%s: av_handle: %d codec: %d", __func__,
                         p_scb->seps[i].av_handle,
                         A2D_CodecName(p_scb->seps[i].codec_info));
        if (p_scb->seps[i].av_handle &&
            (p_scb->seps[i].av_handle == avdt_handle) &&
            A2D_CodecTypeEquals(p_scb->seps[i].codec_info,
                                p_scb->cfg.codec_info)) {
            p_scb->sep_idx = i;
            p_scb->avdt_handle = p_scb->seps[i].av_handle;
            break;
@@ -1145,7 +1150,6 @@ void bta_av_config_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    local_sep = bta_av_get_scb_sep_type(p_scb, p_msg->handle);
    p_scb->avdt_label = p_data->str_msg.msg.hdr.label;
    memcpy(p_scb->cfg.codec_info, p_evt_cfg->codec_info, AVDT_CODEC_SIZE);
    p_scb->codec_type = A2D_GetCodecType(p_evt_cfg->codec_info);
    bta_av_save_addr(p_scb, p_data->str_msg.bd_addr);

    /* Clear collision mask */
@@ -1189,7 +1193,7 @@ void bta_av_config_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        /*  in case of A2DP SINK this is the first time peer data is being sent to co functions */
        if (local_sep == AVDT_TSEP_SNK)
        {
            p_scb->p_cos->setcfg(p_scb->hndl, p_scb->codec_type,
            p_scb->p_cos->setcfg(p_scb->hndl,
                             p_evt_cfg->codec_info,
                             p_info->seid,
                             p_scb->peer_addr,
@@ -1200,7 +1204,7 @@ void bta_av_config_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        }
        else
        {
            p_scb->p_cos->setcfg(p_scb->hndl, p_scb->codec_type,
            p_scb->p_cos->setcfg(p_scb->hndl,
                             p_evt_cfg->codec_info,
                             p_info->seid,
                             p_scb->peer_addr,
@@ -1337,8 +1341,8 @@ void bta_av_setconfig_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
            p_scb->avdt_version = AVDT_VERSION_SYNC;


        if (p_scb->codec_type == A2D_MEDIA_CT_SBC || num > 1)
        {
        if (A2D_GetCodecType(p_scb->cfg.codec_info) == A2D_MEDIA_CT_SBC ||
            num > 1) {
            /* if SBC is used by the SNK as INT, discover req is not sent in bta_av_config_ind.
                       * call disc_res now */
           /* this is called in A2DP SRC path only, In case of SINK we don't need it  */
@@ -1417,8 +1421,7 @@ void bta_av_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    memset(&p_scb->q_info, 0, sizeof(tBTA_AV_Q_INFO));

    p_scb->l2c_bufs = 0;
    p_scb->p_cos->open(p_scb->hndl,
        p_scb->codec_type, p_scb->cfg.codec_info, mtu);
    p_scb->p_cos->open(p_scb->hndl, p_scb->cfg.codec_info, mtu);

    {
        /* TODO check if other audio channel is open.
@@ -1735,9 +1738,8 @@ void bta_av_save_caps(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        p_scb->num_seps, p_scb->sep_info_idx, p_scb->wait);
    memcpy(&cfg, p_scb->p_cap, sizeof(tAVDT_CFG));
    /* let application know the capability of the SNK */
    p_scb->p_cos->getcfg(p_scb->hndl, A2D_GetCodecType(cfg.codec_info),
        cfg.codec_info, &p_scb->sep_info_idx, p_info->seid,
        &cfg.num_protect, cfg.protect_info);
    p_scb->p_cos->getcfg(p_scb->hndl, cfg.codec_info, &p_scb->sep_info_idx,
                         p_info->seid, &cfg.num_protect, cfg.protect_info);

    p_scb->sep_info_idx++;
    if(p_scb->num_seps > p_scb->sep_info_idx)
@@ -1796,7 +1798,7 @@ void bta_av_cco_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)

    mtu = bta_av_chk_mtu(p_scb, BTA_AV_MAX_A2DP_MTU);

    p_scb->p_cos->close(p_scb->hndl, p_scb->codec_type, mtu);
    p_scb->p_cos->close(p_scb->hndl, mtu);
}

/*******************************************************************************
@@ -1893,18 +1895,15 @@ void bta_av_getcap_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    /* if codec present and we get a codec configuration */
    if ((p_scb->p_cap->num_codec != 0) &&
        (media_type == p_scb->media_type) &&
        (p_scb->p_cos->getcfg(p_scb->hndl,
                              A2D_GetCodecType(p_scb->p_cap->codec_info),
                              cfg.codec_info, &p_scb->sep_info_idx,
                              p_info->seid, &cfg.num_protect,
                              cfg.protect_info) == A2D_SUCCESS))
    {
        (p_scb->p_cos->getcfg(p_scb->hndl, cfg.codec_info,
                              &p_scb->sep_info_idx, p_info->seid,
                              &cfg.num_protect, cfg.protect_info) ==
         A2D_SUCCESS)) {
#if AVDT_MULTIPLEXING == TRUE
        cfg.mux_mask &= p_scb->p_cap->mux_mask;
        APPL_TRACE_DEBUG("%s: mux_mask used x%x", __func__, cfg.mux_mask);
#endif
        /* save copy of codec type and configuration */
        p_scb->codec_type = A2D_GetCodecType(cfg.codec_info);
        /* save copy of codec configuration */
        memcpy(&p_scb->cfg, &cfg, sizeof(tAVDT_CFG));

        uuid_int = p_scb->uuid_int;
@@ -2109,7 +2108,7 @@ void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        bta_av_stream_chg(p_scb, false);
        p_scb->co_started = false;

        p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
        p_scb->p_cos->stop(p_scb->hndl);
        L2CA_SetFlushTimeout(p_scb->peer_addr, L2CAP_DEFAULT_FLUSH_TO);
    }

@@ -2246,17 +2245,15 @@ 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 = NULL;
    uint32_t  data_len;
    uint32_t  timestamp;
    bool new_buf = false;
    uint8_t   m_pt = 0x60 | p_scb->codec_type;
    tA2D_CODEC_TYPE codec_type = A2D_GetCodecType(p_scb->cfg.codec_info);
    uint8_t   m_pt = 0x60 | codec_type;
    tAVDT_DATA_OPT_MASK     opt;
    UNUSED(p_data);

    if (p_scb->cong)
    {
        return;
    }

    //Always get the current number of bufs que'd up
    p_scb->l2c_bufs = (uint8_t)L2CA_FlushChannel (p_scb->l2c_cid, L2CAP_FLUSH_CHANS_GET);
@@ -2271,7 +2268,7 @@ void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    {
        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,
        p_buf = (BT_HDR *)p_scb->p_cos->data(p_scb->cfg.codec_info,
                                             &timestamp);

        if (p_buf)
@@ -2483,7 +2480,8 @@ void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        p_scb->role &= ~BTA_AV_ROLE_SUSPEND_OPT;

        p_scb->no_rtp_hdr = false;
        p_scb->p_cos->start(p_scb->hndl, p_scb->codec_type, p_scb->cfg.codec_info, &p_scb->no_rtp_hdr);
        p_scb->p_cos->start(p_scb->hndl, p_scb->cfg.codec_info,
                            &p_scb->no_rtp_hdr);
        p_scb->co_started = true;

        APPL_TRACE_DEBUG("%s: suspending: %d, role:x%x, init %d", __func__,
@@ -2501,7 +2499,7 @@ void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
            p_scb->role |= BTA_AV_ROLE_SUSPEND;
            p_scb->cong = true;  /* do not allow the media data to go through */
            /* do not duplicate the media packets to this channel */
            p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
            p_scb->p_cos->stop(p_scb->hndl);
            p_scb->co_started = false;
            stop.flush   = false;
            stop.suspend = true;
@@ -2590,7 +2588,7 @@ void bta_av_str_closed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        mtu = bta_av_chk_mtu(p_scb, BTA_AV_MAX_A2DP_MTU);

        {
            p_scb->p_cos->close(p_scb->hndl, p_scb->codec_type, mtu);
            p_scb->p_cos->close(p_scb->hndl, mtu);
            data.close.chnl = p_scb->chnl;
            data.close.hndl = p_scb->hndl;
            event = BTA_AV_CLOSE_EVT;
@@ -2695,7 +2693,7 @@ void bta_av_suspend_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)

        {
            p_scb->co_started = false;
            p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
            p_scb->p_cos->stop(p_scb->hndl);
        }
        L2CA_SetFlushTimeout(p_scb->peer_addr, L2CAP_DEFAULT_FLUSH_TO);
    }
@@ -2943,14 +2941,13 @@ void bta_av_rcfg_open (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    if (p_scb->num_disc_snks == 0)
    {
        /* Need to update call-out module so that it will be ready for discover */
        p_scb->p_cos->stop(p_scb->hndl, p_scb->codec_type);
        p_scb->p_cos->stop(p_scb->hndl);

        /* send avdtp discover request */
        AVDT_DiscoverReq(p_scb->peer_addr, p_scb->sep_info, BTA_AV_NUM_SEPS, bta_av_dt_cback[p_scb->hdi]);
    }
    else
    {
        p_scb->codec_type = A2D_GetCodecType(p_scb->p_cap->codec_info);
        memcpy(p_scb->cfg.codec_info, p_scb->p_cap->codec_info, AVDT_CODEC_SIZE);
        /* we may choose to use a different SEP at reconfig.
         * adjust the sep_idx now */
+10 −14
Original line number Diff line number Diff line
@@ -159,27 +159,24 @@ typedef void (*tBTA_AV_CO_DISC_RES) (tBTA_AV_HNDL hndl, uint8_t num_seps,
                                     uint8_t num_snk, uint8_t num_src,
                                     BD_ADDR addr, uint16_t uuid_local);
typedef tA2D_STATUS (*tBTA_AV_CO_GETCFG) (tBTA_AV_HNDL hndl,
                                          tA2D_CODEC_TYPE codec_type,
                                          uint8_t *p_codec_info,
                                          uint8_t *p_sep_info_idx,
                                          uint8_t seid,
                                          uint8_t *p_num_protect,
                                          uint8_t *p_protect_info);
typedef void (*tBTA_AV_CO_SETCFG) (tBTA_AV_HNDL hndl,
                                   tA2D_CODEC_TYPE codec_type,
                                   uint8_t *p_codec_info, uint8_t seid,
                                   const uint8_t *p_codec_info, uint8_t seid,
                                   BD_ADDR addr, uint8_t num_protect,
                                   uint8_t *p_protect_info,
                                   uint8_t t_local_sep, uint8_t avdt_handle);
typedef void (*tBTA_AV_CO_OPEN) (tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
                                 uint8_t *p_codec_info, uint16_t mtu);
typedef void (*tBTA_AV_CO_CLOSE) (tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
typedef void (*tBTA_AV_CO_OPEN) (tBTA_AV_HNDL hndl, uint8_t *p_codec_info,
                                 uint16_t mtu);
typedef void (*tBTA_AV_CO_START) (tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
                                  uint8_t *p_codec_info, bool *p_no_rtp_hdr);
typedef void (*tBTA_AV_CO_STOP) (tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type);
typedef void * (*tBTA_AV_CO_DATAPATH) (tA2D_CODEC_TYPE codec_type,
                                       uint32_t *p_len, uint32_t *p_timestamp);
typedef void (*tBTA_AV_CO_CLOSE) (tBTA_AV_HNDL hndl, uint16_t mtu);
typedef void (*tBTA_AV_CO_START) (tBTA_AV_HNDL hndl, uint8_t *p_codec_info,
                                  bool *p_no_rtp_hdr);
typedef void (*tBTA_AV_CO_STOP) (tBTA_AV_HNDL hndl);
typedef void * (*tBTA_AV_CO_DATAPATH) (const uint8_t *p_codec_info,
                                       uint32_t *p_timestamp);
typedef void (*tBTA_AV_CO_DELAY) (tBTA_AV_HNDL hndl, uint16_t delay);

/* the call-out functions for one stream */
@@ -395,8 +392,8 @@ typedef struct
typedef struct
{
    uint8_t             av_handle;         /* AVDTP handle */
    tA2D_CODEC_TYPE     codec_type;        /* codec type */
    uint8_t             tsep;              /* SEP type of local SEP */
    uint8_t codec_info[AVDT_CODEC_SIZE];   /* Codec info */
    tBTA_AV_SINK_DATA_CBACK *p_app_sink_data_cback; /* Sink application callback for media packets */
} tBTA_AV_SEP;

@@ -480,7 +477,6 @@ typedef struct
    uint16_t            stream_mtu;     /* MTU of stream */
    uint16_t            avdt_version;   /* the avdt version of peer device */
    tBTA_SEC            sec_mask;       /* security mask */
    tA2D_CODEC_TYPE     codec_type;     /* codec type */
    uint8_t             media_type;     /* Media type: AVDT_MEDIA_TYPE_* */
    bool                cong;           /* true if AVDTP congested */
    tBTA_AV_STATUS      open_status;    /* open failure status */
+3 −2
Original line number Diff line number Diff line
@@ -595,8 +595,9 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
            if ((*bta_av_a2d_cos.init)(codec_sep_index, &cs.cfg)) {
                if (AVDT_CreateStream(&p_scb->seps[codec_sep_index].av_handle, &cs)
                    == AVDT_SUCCESS) {
                    p_scb->seps[codec_sep_index].codec_type =
                        A2D_GetCodecType(cs.cfg.codec_info);
                    /* Save a copy of the codec */
                    memcpy(p_scb->seps[codec_sep_index].codec_info,
                           cs.cfg.codec_info, AVDT_CODEC_SIZE);
                    p_scb->seps[codec_sep_index].tsep = cs.tsep;
                    if (cs.tsep == AVDT_TSEP_SNK) {
                        p_scb->seps[codec_sep_index].p_app_sink_data_cback =
+0 −20
Original line number Diff line number Diff line
@@ -406,23 +406,3 @@ int bta_av_sbc_up_sample_8m (void *p_src, void *p_dst,
    *p_ret = ((char *)p_src_tmp - (char *)p_src);
    return ((char *)p_dst_tmp - (char *)p_dst);
}

/*******************************************************************************
**
** Function         bta_av_sbc_bld_hdr
**
** Description      This function builds the packet header for MPF1.
**
** Returns          void
**
*******************************************************************************/
void bta_av_sbc_bld_hdr(BT_HDR *p_buf, uint16_t fr_per_pkt)
{
    uint8_t   *p;

    p_buf->offset -= BTA_AV_SBC_HDR_SIZE;
    p = (uint8_t *) (p_buf + 1) + p_buf->offset;
    p_buf->len += BTA_AV_SBC_HDR_SIZE;
    A2D_BldSbcMplHdr(p, false, false, false, (uint8_t) fr_per_pkt);
}
+10 −13
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ void bta_av_co_audio_disc_res(tBTA_AV_HNDL hndl, uint8_t num_seps,
**
*******************************************************************************/
tA2D_STATUS bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl,
                                      tA2D_CODEC_TYPE codec_type,
                                      uint8_t *p_codec_info,
                                      uint8_t *p_sep_info_idx, uint8_t seid,
                                      uint8_t *p_num_protect,
@@ -109,9 +108,8 @@ tA2D_STATUS bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl,
** Returns          void
**
*******************************************************************************/
void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
                               uint8_t *p_codec_info, uint8_t seid,
                               BD_ADDR addr, uint8_t num_protect,
void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, const uint8_t *p_codec_info,
                               uint8_t seid, BD_ADDR addr, uint8_t num_protect,
                               uint8_t *p_protect_info,uint8_t t_local_sep,
                               uint8_t avdt_handle);

@@ -128,8 +126,8 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
** Returns          void
**
*******************************************************************************/
void bta_av_co_audio_open(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
                          uint8_t *p_codec_info, uint16_t mtu);
void bta_av_co_audio_open(tBTA_AV_HNDL hndl, uint8_t *p_codec_info,
                          uint16_t mtu);

/*******************************************************************************
**
@@ -145,8 +143,7 @@ void bta_av_co_audio_open(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
** Returns          void
**
*******************************************************************************/
void bta_av_co_audio_close(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
                           uint16_t mtu);
void bta_av_co_audio_close(tBTA_AV_HNDL hndl, uint16_t mtu);

/*******************************************************************************
**
@@ -159,8 +156,8 @@ void bta_av_co_audio_close(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
** Returns          void
**
*******************************************************************************/
void bta_av_co_audio_start(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
                           uint8_t *p_codec_info, bool *p_no_rtp_hdr);
void bta_av_co_audio_start(tBTA_AV_HNDL hndl, uint8_t *p_codec_info,
                           bool *p_no_rtp_hdr);

/*******************************************************************************
**
@@ -173,7 +170,7 @@ void bta_av_co_audio_start(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type,
** Returns          void
**
*******************************************************************************/
void bta_av_co_audio_stop(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type);
void bta_av_co_audio_stop(tBTA_AV_HNDL hndl);

/*******************************************************************************
**
@@ -183,10 +180,10 @@ void bta_av_co_audio_stop(tBTA_AV_HNDL hndl, tA2D_CODEC_TYPE codec_type);
**                  the audio codec
**
** Returns          NULL if data is not ready.
**                  Otherwise, a GKI buffer (BT_HDR*) containing the audio data.
**                  Otherwise, a buffer (BT_HDR*) containing the audio data.
**
*******************************************************************************/
void *bta_av_co_audio_src_data_path(tA2D_CODEC_TYPE codec_type, uint32_t *p_len,
void *bta_av_co_audio_src_data_path(const uint8_t *p_codec_info,
                                    uint32_t *p_timestamp);

/*******************************************************************************
Loading