天天看点

关于蓝牙耳机通话,切换声音路径

今天遇到一个问题,不大不小:
 
1.声音从本机切换到蓝牙耳机
 (1)如果此时静音功能关闭,切换到BT耳机后,静音功能仍关闭,[静音]菜单显示正常,之后开启、关闭操作也正常;
 (2)如果此时静音功能开启,切换到BT耳机后,静音功能被关闭,但是[静音]菜单的显示仍然是开启,即:切换声音路径到BT耳机时,自动关闭了静音功能,但是[静音]菜单的显示没有响应的变化,导致错误。2.声音从蓝牙耳机切换到本机
 现象类似。一路追踪代码,过程如下:
1. [静音]菜单的操作函数:mmi_ucm_set_mute()2.切换声音路径的操作:
(1)mmi_ucm_bt_set_audio_path()-->
(2)mmi_bt_switch_voice_path_incall( )-->
(3)(*g_mmi_bt_scr_cntx.stack_cb_tbl.mmi_bt_switch_voice_path_incall) (is_on);   is_on=1表示切换声音到蓝牙耳机。这是个函数指针,在函数
mmi_bt_init_stack_cb()中调用mmi_bt_reg_stack_cb()注册的即:
(4)mmi_bth_switch_voice_path_incall()-->
(4-1)mmi_profiles_bt_connect_req(MMI_PROFILES_BT_HFP_SCO);     切换到蓝牙耳机
   mdi_audio_bt_open_stream()-->
 aud_send_bt_audio_open_req( )-->
 aud_send_msg_to_med( MSG_ID_MEDIA_BT_AUDIO_OPEN_REQ) 底层aud_bt_main()函数接收到这个消息后,执行:
 aud_bt_audio_open_req_hdlr()-->
 aud_bt_hfp_open_req_hdlr()--> 执行if分支:
 aud_bt_hfp_sco_connect_req( )-->
 aud_bt_hfp_set_audio_path_on( )-->设置音频输出路径
 bt_hfg_send_sco_connect_req(MOD_MED, aud_bt_hfp_ctx.connect_id); 发送消息:MSG_ID_BT_HFG_SCO_CONNECT_REQ 蓝牙返回MSG_ID_BT_HFG_SCO_CONNECT_CNF,在aud_bt_main()中被捕捉到,进入:
 aud_bt_hfp_sco_connect_cnf_hdlr() -->
 aud_send_bt_audio_open_ind( )-->
  aud_send_msg_from_med(MSG_ID_MEDIA_BT_AUDIO_OPEN_IND),进入函数:
  mdi_audio_bt_open_stream_ind()--即:(5)中所注册的回调函数
 aud_bt_hfp_set_audio_path(KAL_TRUE); 比较关键的函数
  aud_bt_hfp_set_audio_path_on();
              aud_bt_hfp_set_speech_path_on(); 先调用L1SP_MuteMicrophone(KAL_TRUE);开启静音,然后启动一定时器,定时器响应关闭静音!(4-2) mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_HFP_SCO); 切换到本机
 mdi_audio_bt_close_stream( )-->
 media_aud_bt_audio_close( )-->
 aud_send_bt_audio_close_req( )-->
 aud_send_msg_to_med(MSG_ID_MEDIA_BT_AUDIO_CLOSE_REQ ) 底层aud_bt_main()函数接收到这个消息后,执行:
 aud_bt_audio_close_req_hdlr()-->
 aud_bt_hfp_close_req_hdlr( )-->
 aud_bt_hfp_set_audio_path( FALSE)--> 比较关键的函数!!!
  aud_bt_hfp_set_audio_path_off();
              aud_bt_hfp_set_speech_path_off();-->L1SP_MuteMicrophone(KAL_FALSE);  关闭静音功能!!!!!
 aud_send_bt_audio_close_cnf()-->
 aud_send_msg_from_med(MSG_ID_MEDIA_BT_AUDIO_CLOSE_CNF),进入函数:
 mdi_audio_bt_close_stream_cnf()--即:(5)中所注册的回调函数(5)在函数mdi_audio_init_event_hdlrs()中注册了:
    SetProtocolEventHandler(mdi_audio_bt_close_stream_cnf, MSG_ID_MEDIA_BT_AUDIO_CLOSE_CNF);
    SetProtocolEventHandler(mdi_audio_bt_close_stream_ind, MSG_ID_MEDIA_BT_AUDIO_CLOSE_IND);
    SetProtocolEventHandler(mdi_audio_bt_open_stream_cnf, MSG_ID_MEDIA_BT_AUDIO_OPEN_CNF);
    SetProtocolEventHandler(mdi_audio_bt_open_stream_ind, MSG_ID_MEDIA_BT_AUDIO_OPEN_IND);
    以上4个响应函数都调用mdi_audio_bt_cntx.close_hdlr[profile]注册的函数。而这个函数的注册是在:InitProfileApp()-->
 mdi_audio_bt_init(BT_HFP, mmi_profiles_bt_open_stream_callback, mmi_profiles_bt_close_stream_callback);来完成的。
    即:mmi_profiles_bt_open_stream_callback( ),mmi_profiles_bt_close_stream_callback( )这2个函数是切换声音路径最后调用的函数。(6-1) mmi_profiles_bt_open_stream_callback()--> 切换到BT耳机
 mmi_profiles_bt_connect_callback(MMI_PROFILES_BT_HFP_SCO, MMI_PROFILES_BT_RSP, res);-->
 mmi_bth_sco_connect_ind_hdler( )
  (*g_mmi_bth_cntx.scr_cb_tbl.mmi_bt_scr_cb_sco_ind)( ) 函数指针,即:mmi_bt_sco_ind(res)。res=1表示切换到BT耳机。
   如果当前开启免提,则把免提关闭;显示提示信息:声音转至免持装置。    
 然后启动定时器mmi_profiles_bt_sco_timeout(),定期检查蓝牙耳机是否断开,是的话执行mmi_profiles_bt_disconnect_sco()。 (6-2)mmi_profiles_bt_close_stream_callback()--> 切换到本机
 mmi_profiles_bt_disconnect_callback(MMI_PROFILES_BT_HFP_SCO, MMI_PROFILES_BT_RSP, MMI_PROFILES_BT_OK);-->
 mmi_bth_sco_disconnect_ind_hdler()
  (*g_mmi_bth_cntx.scr_cb_tbl.mmi_bt_scr_cb_sco_ind)( ) 函数指针,即:mmi_bt_sco_ind(res)
   提示信息:声音转回手机端   即:切换声音完成之后,都会进入函数mmi_bt_sco_ind()中,显示提示信息。      

继续阅读