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;
代码如图所示 

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);
}
}

|