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

Commit 26fcb4d8 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Update the A2DP codec setup and selection mechanism

* Update bta_av_co_audio_set_codec() so it can select among
  multiple available A2DP source codecs.
* Rename A2DP_SetCodec() to A2DP_SetSourceCodec() and update
  it to use tA2DP_CODEC_SEP_INDEX as an argument to specify
  the particular codec (instead of using SBC as default).

Also:
* Move the definition of AVDT_CODEC_SIZE from bt_target.h
  to avdt_api.h and increased its value from 10 to 20
* Add missing bta_av_co_audio_sink_has_scmst() check inside
  bta_av_co_find_peer_sink_supports_codec()
* Rename (inside bta_av_co.cc): cfg -> config

Bug: 30958229
Test: unit tests and A2DP streaming
Change-Id: I49fcf5063c3b6c4060abdfb60c2db171fa1ff747
parent b11d8133
Loading
Loading
Loading
Loading
+31 −19
Original line number Diff line number Diff line
@@ -457,6 +457,7 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
        p_bta_av_cfg  = (tBTA_AV_CFG *) &bta_av_cfg;
    }

    APPL_TRACE_DEBUG("%s: profile: 0x%x", __func__, profile_initialized);
    if (p_bta_av_cfg == NULL)
    {
        APPL_TRACE_ERROR("AV configuration is null!");
@@ -563,7 +564,10 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
            cs.media_type    = AVDT_MEDIA_TYPE_AUDIO;
            cs.mtu           = p_bta_av_cfg->audio_mtu;
            cs.flush_to      = L2CAP_DEFAULT_FLUSH_TO;
            tA2DP_CODEC_SEP_INDEX codec_sep_index = A2DP_CODEC_SEP_INDEX_SBC;
            tA2DP_CODEC_SEP_INDEX codec_sep_index_min =
                A2DP_CODEC_SEP_INDEX_SOURCE_MIN;
            tA2DP_CODEC_SEP_INDEX codec_sep_index_max =
                A2DP_CODEC_SEP_INDEX_SOURCE_MAX;

#if (AVDT_REPORTING == TRUE)
            if(bta_av_cb.features & BTA_AV_FEAT_REPORT)
@@ -578,13 +582,15 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
            if (profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE)
            {
                cs.tsep = AVDT_TSEP_SRC;
                codec_sep_index = A2DP_CODEC_SEP_INDEX_SBC;
                codec_sep_index_min = A2DP_CODEC_SEP_INDEX_SOURCE_MIN;
                codec_sep_index_max = A2DP_CODEC_SEP_INDEX_SOURCE_MAX;
            }
            else if (profile_initialized == UUID_SERVCLASS_AUDIO_SINK)
            {
                cs.tsep = AVDT_TSEP_SNK;
                cs.p_sink_data_cback = bta_av_sink_data_cback;
                codec_sep_index = A2DP_CODEC_SEP_INDEX_SBC_SINK;
                codec_sep_index_min = A2DP_CODEC_SEP_INDEX_SINK_MIN;
                codec_sep_index_max = A2DP_CODEC_SEP_INDEX_SINK_MAX;
            }

            /* Initialize handles to zero */
@@ -595,9 +601,16 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)

            /* keep the configuration in the stream control block */
            memcpy(&p_scb->cfg, &cs.cfg, sizeof(tAVDT_CFG));
            if ((*bta_av_a2dp_cos.init)(codec_sep_index, &cs.cfg)) {
                if (AVDT_CreateStream(&p_scb->seps[codec_sep_index].av_handle, &cs)
                    == AVDT_SUCCESS) {
            for (int i = 0; i < A2DP_CODEC_SEP_INDEX_MAX; i++) {
                tA2DP_CODEC_SEP_INDEX codec_sep_index =
                    static_cast<tA2DP_CODEC_SEP_INDEX>(i);
                if (!(*bta_av_a2dp_cos.init)(codec_sep_index, &cs.cfg)) {
                    continue;
                }
                if (AVDT_CreateStream(&p_scb->seps[codec_sep_index].av_handle,
                                      &cs) != AVDT_SUCCESS) {
                    continue;
                }
                /* Save a copy of the codec */
                memcpy(p_scb->seps[codec_sep_index].codec_info,
                       cs.cfg.codec_info, AVDT_CODEC_SIZE);
@@ -612,7 +625,6 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
                    p_scb->seps[codec_sep_index].p_app_sink_data_cback = NULL;
                }
            }
            }

            if(!bta_av_cb.reg_audio)
            {
+137 −129

File changed.

Preview size limit exceeded, changes collapsed.

+0 −5
Original line number Diff line number Diff line
@@ -1145,11 +1145,6 @@
#define AVDT_NUM_TC_TBL             6
#endif

/* Maximum size in bytes of the codec capabilities information element. */
#ifndef AVDT_CODEC_SIZE
#define AVDT_CODEC_SIZE             10
#endif

/* Maximum size in bytes of the content protection information element. */
#ifndef AVDT_PROTECT_SIZE
#define AVDT_PROTECT_SIZE           90
+17 −8

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ void A2DP_InitDefaultCodecSbc(uint8_t* p_codec_info) {
  }
}

bool A2DP_SetCodecSbc(const tA2DP_FEEDING_PARAMS* p_feeding_params,
bool A2DP_SetSourceCodecSbc(const tA2DP_FEEDING_PARAMS* p_feeding_params,
                            uint8_t* p_codec_info) {
  tA2DP_SBC_CIE sbc_config = a2dp_sbc_default_config;

Loading