找回密码
 立即注册

使用微信账号登录

只需一步,快速开始

csr8675 adk4.4 source工程切换aptx-HD和aptx-LL codec的方法

2021-5-30 20:53| 发布者: 522315697| 查看: 2637| 评论: 7

摘要: 1. 添加按键切换修改source_buttons.button文件2. 增加按键相关代码修改source_button_handler.c和source_a2dp.c文件。
1. 添加按键切换
修改source_buttons.button文件

2. 增加按键相关代码

修改source_button_handler.c和source_a2dp.c文件。

a2dpInstance *a2dp_get_inst(void)
{
    return A2DP_RUNDATA.inst;
}
case BUTTON_MSG_SW_CODEC:
        BUTTONS_DEBUG(("BUTTON_MSG_SW_CODEC\n"));
        if(a2dp_any_media_connections())
        {
            if(codec_mode)
            {
                codec_mode=0;
            }
            else
            {
                codec_mode=1;
            }
             BUTTONS_DEBUG(("codec_mode = %d\n",codec_mode));
            MessageSend(&a2dp_get_inst()->a2dpTask,A2DP_INTERNAL_MEDIA_CLOSE_REQ,0);
            MessageSendLater(&a2dp_get_inst()->a2dpTask,A2DP_INTERNAL_MEDIA_OPEN_REQ,0,500);
        }
        break;

代码如图所示

3. 修改source_a2dp.c文件
static void a2dp_enter_state_connecting_media_local(a2dpInstance *inst, A2DP_STATE_T old_state)
{
    uint8 a2dp_seid_list[A2DP_MAX_ENDPOINTS];
    uint8 a2dp_seid_preference[A2DP_MAX_ENDPOINTS];
    uint16 current_endpoint = 0;
    uint16 i = 0;
    uint16 j = 0;
    uint16 k = 0;
    uint16 temp_id;
    uint16 temp_pref;
    uint16 preference = 1;
    a2dp_codecs_config_def_t a2dp_config_data;
    
    memset(&a2dp_config_data,0,sizeof(a2dp_codecs_config_def_t));
    memset(&a2dp_seid_list,0,sizeof(a2dp_seid_list));
    memset(&a2dp_seid_preference,0,sizeof(a2dp_seid_preference));

    /*Get the codec config values from the  a2dp module config xml files.*/
    a2dp_get_codec_enable_values(&a2dp_config_data);

    if (inst && inst->a2dp_reconfiguring)
    {
        /* this is a reconfigure so chose CODECS based on what is set as a2dp_reconfigure_codec */
        if (a2dp_seid_is_aptx(inst->a2dp_reconfigure_codec))
        {
            a2dp_seid_list[current_endpoint] = A2DP_SEID_APTX;
            a2dp_seid_preference[current_endpoint++] = preference++;                   
        }
        a2dp_seid_list[current_endpoint] = A2DP_SEID_SBC;
        a2dp_seid_preference[current_endpoint++] = preference++;
    }
    else
    {
        /* this is a standard A2DP Open so choose CODECS based on PS configuration */
        if(a2dp_config_data.a2dpCodecsSBCEnable)
        {
            a2dp_seid_list[current_endpoint] = A2DP_SEID_SBC;
            a2dp_seid_preference[current_endpoint++] =a2dp_config_data.a2dpCodecsSBCPref;
        }
        if(a2dp_config_data.a2dpCodecsFastStreamEnable)
        {
            a2dp_seid_list[current_endpoint] = A2DP_SEID_FASTSTREAM;
            a2dp_seid_preference[current_endpoint++] = a2dp_config_data.a2dpFastStreamPref;
        }    
        if(a2dp_config_data.a2dpCodecsAptXEnable)
        {
            a2dp_seid_list[current_endpoint] = A2DP_SEID_APTX;
            a2dp_seid_preference[current_endpoint++] = a2dp_config_data.a2dpCodecsAptXPref;
        }
        if(codec_mode == 0) //切换部分代码,codec_mode=0屏蔽aptx-LL,codec_mode=1屏蔽aptx-HD

        {   
        if(a2dp_config_data.a2dpCodecsAptXLLEnable)
        {
            a2dp_seid_list[current_endpoint] = A2DP_SEID_APTX_LOW_LATENCY;
            a2dp_seid_preference[current_endpoint++] =a2dp_config_data.a2dpCodecsAptXLLPref;
        }
        }
        else
        {
        if(a2dp_config_data.a2dpCodecsAptXHDEnable)
        {
            a2dp_seid_list[current_endpoint] = A2DP_SEID_APTXHD;
            a2dp_seid_preference[current_endpoint++] = a2dp_config_data.a2dpCodecsAptXHDPref;
        } 
        }
    }
    
    /* sort list to try preferred codecs first */
    for (i = 1; i < current_endpoint; i++)
    {
        for (j = 0; j < i; j++)
        {
            if (a2dp_seid_preference[i] < a2dp_seid_preference[j])
            {
                temp_id = a2dp_seid_list[i];
                temp_pref = a2dp_seid_preference[i];
                for (k = i; k > j; k--)
                { 
                    a2dp_seid_list[k] = a2dp_seid_list[k - 1];
                    a2dp_seid_preference[k] = a2dp_seid_preference[k - 1];
                }
                a2dp_seid_list[j] = temp_id;
                a2dp_seid_preference[j] = temp_pref;
            }
        }
    }
    
#ifdef DEBUG_A2DP
    A2DP_DEBUG(("A2DP: Preferred List:\n"));
    for (i = 0; i < current_endpoint; i++)
    {
        A2DP_DEBUG(("    ID:[0x%x] Pref:[0x%x]\n", a2dp_seid_list[i], a2dp_seid_preference[i]));
    }
#endif    
    
    if (!A2dpMediaOpenRequest(inst->a2dp_device_id, current_endpoint, a2dp_seid_list))
    {
        MessageSend(&inst->a2dpTask, A2DP_INTERNAL_SIGNALLING_DISCONNECT_REQ, 0);
    }
}

3

路过

雷人

握手

鲜花

鸡蛋

刚表态过的朋友 (3 人)

相关阅读

发表评论

最新评论

引用 lyz 2023-9-11 06:29
学习了,谢谢
引用 snowfox 2021-12-25 09:35
不错
引用 想~nl 2021-7-27 21:48
学习了,好东西
引用 keping1010 2021-6-20 08:06
感谢分享!学习
引用 喜欢≠爱 2021-6-4 12:23
学习了
引用 喜欢≠爱 2021-6-4 12:22
学习了
引用 音魅蓝牙测试仪 2021-6-3 16:16
学习了

查看全部评论(7)

小黑屋|手机版|我爱蓝牙网 - 52Bluetooth

GMT+8, 2024-3-29 13:01 , Processed in 0.120732 second(s), 32 queries , Gzip On, MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部