From: hcj <1224667075@qq.com> Date: Tue, 22 Oct 2024 08:34:23 +0000 (+0800) Subject: 优化电话对音频的处理 X-Git-Tag: fd230_release_V1.3.102~193^2~1^2~10 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=d44618741497ad9dd175fe38b228f809f2fcf611;p=mirrors%2FFD230.git 优化电话对音频的处理 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmClockModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmClockModel.cpp index 5cc06d62c..09f26ef68 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmClockModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmClockModel.cpp @@ -858,7 +858,6 @@ int AlarmClockModel::AlarmPlayerStat() int32_t ret; if(NotificationManager::GetInstance()->GetWatchCallStatus()) { - return 0; } @@ -900,8 +899,17 @@ int AlarmClockModel::AlarmPlayerStat() } playerCtr->SetAudioSessionId(sessionId); playerCtr->SetVolume(amIntance.GetMaxVolume(AUDIO_STREAM_MUSIC),amIntance.GetMaxVolume(AUDIO_STREAM_MUSIC)); + playerCtr->EnableSingleLooping(true); // 播放 - playerCtr->Play(); + // playerCtr->Play(); + + ret = playerCtr->Play(); + if (ret != 0) { + playerCtr->Stop(); // 暂停 + playerCtr->Reset(); // 初始化 + + AudioManager::GetInstance().DeactivateAudioInterrupt(interrupt); + } return OHOS_SUCCESS; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h index e21444227..ab02f9fcf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h @@ -27,6 +27,8 @@ int uapi_close_br_scan(void); int uapi_open_br_scan(void); //int uapi_disconnect_remote_device_(void); +int32_t BtA2dpSnkAudioDestroy(void); + int uapi_reconnect_(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index ddf86afd5..31111536a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -1430,7 +1430,7 @@ static int32_t BtA2dpSnkAudioCreate() return 0; } -static int32_t BtA2dpSnkAudioDestroy() +int32_t BtA2dpSnkAudioDestroy(void) { #if MEDIA_A2DP_SNK_INTERFACE int32_t ret = AudioManagerA2dpSinkDestroy(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/callerlog/src/CallerLogModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/callerlog/src/CallerLogModel.cpp index 29286fb76..74af04e7d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/callerlog/src/CallerLogModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/callerlog/src/CallerLogModel.cpp @@ -44,7 +44,7 @@ osTimerId_t g_startCounting = nullptr; // 定时器 // osTimerId_t g_shake = nullptr; // 循环震动定时器 -static constexpr uint64_t MS_ONE_SECONDS = 1000; +static constexpr uint64_t MS_ONE_SECONDS = 2000; static PhoneCallInfo callList[MULTI_CALL_MAX_NUME]{}; // 电话优先级标志位 static int g_firstPriority = NO_NUMBER_STATUS; @@ -134,7 +134,7 @@ void StatusReset(void) DisableCallingTimer(); if(CallerLogModel::GetInstance()->GetCallSource()==CallerLogModel::CallSourceCat1) - uapi_cat1_stop_volte_voice(); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CAT1_AUDIO_STOP, nullptr, 0); CallerLogModel::GetInstance()->Setphonebname("0",0); CallerLogModel::GetInstance()->SetCallDial(CallerLogModel::HFP_PHONE_DIAL); @@ -190,7 +190,7 @@ static void CallTimerCallbackProc(int data) if(!MainCallingView::GetInstance()->GetDisplayGroup()->IsVisible()) { if(!volte_voice_state()) - uapi_cat1_start_volte_voice(); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CAT1_AUDIO_START, nullptr, 0); } { diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h index 6d58cc71b..742fc10d8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h @@ -286,6 +286,13 @@ int SaveCallLog(CallLogInfo **info,int num); int32_t SetMicMutecat1(bool isMute); +void AudioActInterrupt(AudioStreamType type); + + + + + + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h index be1825b31..0cf660c3f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h @@ -22,6 +22,11 @@ int uapi_open_voice_recognition(void ); int uapi_close_voice_recognition(void ); +void cat1_audio_AudioSetup(void); + +void cat1_audio_AudioRelease(void); + + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp index aa2dec3d7..05a7d7b0c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp @@ -151,20 +151,23 @@ static void AudioDeactInterrupt(AudioStreamType type) type, g_audioState); if ((type == AUDIO_STREAM_VOICE_CALL_BT_SCO && g_audioState >= AUDIO_ACT_INTERRUPT_BT_SCO) || - (type == AUDIO_STREAM_RING && g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING)) { + (type == AUDIO_STREAM_RING && g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING) + || type ==AUDIO_STREAM_VOICE_CALL_VOLTE && g_audioState >= AUDIO_STREAM_VOICE_CALL_VOLTE ) { (void)PhoneAudioManagerDeactInterrupt(); } } + + // 申请音频焦点 -static void AudioActInterrupt(AudioStreamType type) +void AudioActInterrupt(AudioStreamType type) { int ret = OHOS_SUCCESS; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] start type:0x%x, audioState:0x%x", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] start type:0x%x, audioState:0x%x", type, g_audioState); - if (type != AUDIO_STREAM_VOICE_CALL_BT_SCO && type != AUDIO_STREAM_RING) { +if (type != AUDIO_STREAM_VOICE_CALL_BT_SCO && type != AUDIO_STREAM_RING && type != AUDIO_STREAM_VOICE_CALL_VOLTE) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] failed! type:0x%x, audioState:0x%x", type, g_audioState); return; @@ -181,12 +184,26 @@ static void AudioActInterrupt(AudioStreamType type) if (ret == OHOS_SUCCESS) { g_audioState = AUDIO_ACT_INTERRUPT_BT_SCO; } - } else if (type == AUDIO_STREAM_RING && g_audioState < AUDIO_ACT_INTERRUPT_WATCH_RING) { + } + else if (type == AUDIO_STREAM_RING && g_audioState < AUDIO_ACT_INTERRUPT_WATCH_RING) + { ret = PhoneAudioManagerActInterrupt(type); if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_ACT_INTERRUPT_WATCH_RING; + g_audioState = AUDIO_ACT_INTERRUPT_WATCH_RING; } } + else if (type == AUDIO_STREAM_VOICE_CALL_VOLTE && g_audioState < AUDIO_STREAM_VOICE_CALL_VOLTE) + { + if (g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING) { + AudioDeactInterrupt(AUDIO_STREAM_RING); + } + + ret = PhoneAudioManagerActInterrupt(type); + if (ret == OHOS_SUCCESS) { + g_audioState = AUDIO_STREAM_VOICE_CALL_VOLTE; + } + } + if (ret != OHOS_SUCCESS) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] failed! type:0x%x, audioState:0x%x", @@ -262,7 +279,7 @@ static void AudioUpStart(void) if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_STREAM_INIT) { return; - } +} MUTEX_Lock(g_audioMutex); if (g_audioState < AUDIO_STREAM_START_UP) { @@ -370,6 +387,27 @@ static void AudioDnStart(void) return; } +#include "PlayersModelC.h" +#include "BluetoothModelC.h" + +void cat1_audio_AudioSetup(void) +{ + //AudioActInterrupt(AUDIO_STREAM_VOICE_CALL_VOLTE); + if(stopPhonePlayingMusic()) + { + BtA2dpSnkAudioDestroy(); + sleep(1);//等待释放音频 + } + uapi_cat1_start_volte_voice(); +} + +void cat1_audio_AudioRelease(void) +{ + uapi_cat1_stop_volte_voice(); +} + + + // 同步音量 static void SyncVolume(void) { @@ -422,6 +460,7 @@ static void AudioUp(void) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "[AudioUp] audioState:%d", g_audioState); } + static void AudioSetup(void) { //如果已经建立了cat1 媒体通路,不能再建立,SCO通路 @@ -438,6 +477,9 @@ static void AudioSetup(void) } } + + + static void AudioUpRelease(void) { int ret; @@ -527,7 +569,7 @@ void AudioRelease(void) /* 释放音频焦点 */ AudioDeactInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); AudioDeactInterrupt(AUDIO_STREAM_RING); // 适配某些机型不触发SCO - g_audioState = AUDIO_UNKNOW; + g_audioState = AUDIO_UNKNOW; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "[AudioRelease] audioState:%d,", g_audioState); MUTEX_Unlock(g_audioMutex); diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h index 955de6879..a0dd42e1d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h @@ -19,6 +19,7 @@ extern "C" void stopPlayingMusic(void); void custom_setUpListCase(void); bool canSyncMusic(uint32_t songSize); + bool stopPhonePlayingMusic(void); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp index 64f2806b2..508f9981a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -1179,6 +1179,19 @@ extern "C" return OHOS::SystemLogModel::GetInstance()->canSyncFile(APP_MUSIC_PATH,TOTAL_MUSIC_SPACE,songSize); } + + bool stopPhonePlayingMusic(void) + { + if( OHOS::PlayersModel::GetInstance()->get_a2dp_sink_playing_state()) + { + OHOS::PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PAUSE); // 控制手机音乐暂停 + return true; + + } + return false; + } + + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 3a58e6760..73bdca59b 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -921,6 +921,7 @@ void MsgCenterNotifyCatIncomingCallProc(const Topic topic, Request* req) } stopPlayingMusic(); + PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐 const power_display_svr_api_t *display_api = power_display_svr_get_api(); if (display_api->get_screen_state() != SCREEN_ON) @@ -960,7 +961,7 @@ void MsgCenterNotifyCat1CallConnectedProc(const Topic topic, Request* req) } AlarmClockModel::GetInstance()->AlarmPlayerStop(); //AlarmViewEventListener::GetInstance()->CancelAlarmRing(); - uapi_cat1_start_volte_voice(); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CAT1_AUDIO_START, nullptr, 0); CallerLogModel::GetInstance()->SetCallSource(CallerLogModel::CallSource::CallSourceCat1); @@ -975,6 +976,7 @@ void MsgCenterNotifyCat1CallConnectedProc(const Topic topic, Request* req) } #include "BluetoothModelC.h" #include "audio_manager_c_wrapper.h" +#include "PhoneService.h" //拨号处理函数 void MsgCenterNotifyCat1dialProc(const Topic topic, Request* req) { @@ -991,11 +993,8 @@ void MsgCenterNotifyCat1dialProc(const Topic topic, Request* req) // int ret = PlayersModel::GetInstance()->PlayerStop(); stopPlayingMusic(); - // PlayersModel::GetInstance()->HandPausePhoneMusci(); // 暂停手机音乐 - // AudioManagerDeactivateInterrupt(); - //BtA2dpSnkAudioDestroy(); + - //uapi_hfp_disconnect(); if(strcmp(call_data,"SOS")==0) { free(call_data); @@ -1003,15 +1002,20 @@ void MsgCenterNotifyCat1dialProc(const Topic topic, Request* req) return; } - cat1_call_dial(call_data); + cat1_call_dial(call_data); + + CallerLogModel::GetInstance()->SetoperateNumber(call_data,req->len); - uapi_cat1_start_volte_voice(); + CallerLogModel::GetInstance()->SetCallSource(CallerLogModel::CallSource::CallSourceCat1); + NotificationManager::GetInstance()->SetWatchCallStatus(true); - CallerLogModel::GetInstance()->SetoperateNumber(call_data,req->len); - CallerLogModel::GetInstance()->SetCallSource(CallerLogModel::CallSource::CallSourceCat1); - cat1_phone_state_change_cb(OPERATE_DIALING); - NotificationManager::GetInstance()->SetWatchCallStatus(true); + cat1_phone_state_change_cb(OPERATE_DIALING); + + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CAT1_AUDIO_START, nullptr, 0); + + + } free(call_data); } diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index 4811b315c..50ae4ae0c 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -309,6 +309,13 @@ static void custom_cmd_service_check_task(void const *arg) case CUSTOM_CMD_MSG_CHECK_DIAL_SPACE: check_dial_space(); break; + case CUSTOM_CMD_MSG_CAT1_AUDIO_START: + cat1_audio_AudioSetup(); + break; + case CUSTOM_CMD_MSG_CAT1_AUDIO_STOP: + cat1_audio_AudioRelease(); + break; + default: PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd); break; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 2f8ccb1c7..aa299e62a 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -226,6 +226,9 @@ uint32_t uapi_calendar_store_date(void); #define CUSTOM_CMD_MSG_CHECK_DIAL_SPACE 0x12 +#define CUSTOM_CMD_MSG_CAT1_AUDIO_START 0x13 + +#define CUSTOM_CMD_MSG_CAT1_AUDIO_STOP 0x14 typedef enum { BR_HFP_CONNECT=1, BR_HFP_DISCONNECT,