优化电话对音频的处理
authorhcj <1224667075@qq.com>
Tue, 22 Oct 2024 08:34:23 +0000 (16:34 +0800)
committerhcj <1224667075@qq.com>
Tue, 22 Oct 2024 08:34:23 +0000 (16:34 +0800)
12 files changed:
code/sdk/application/wearable/fd230app/nativeui/alarm/src/AlarmClockModel.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp
code/sdk/application/wearable/fd230app/nativeui/callerlog/src/CallerLogModel.cpp
code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h
code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h
code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp
code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h
code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 5cc06d6..09f26ef 100644 (file)
@@ -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;
 }
 
index e214442..ab02f9f 100644 (file)
@@ -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);
 
 
index ddf86af..3111153 100644 (file)
@@ -1430,7 +1430,7 @@ static int32_t BtA2dpSnkAudioCreate()
     return 0;\r
 }\r
 \r
-static int32_t BtA2dpSnkAudioDestroy()\r
+int32_t BtA2dpSnkAudioDestroy(void)\r
 {\r
 #if MEDIA_A2DP_SNK_INTERFACE\r
     int32_t ret = AudioManagerA2dpSinkDestroy();\r
index 29286fb..74af04e 100644 (file)
@@ -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);
         }
        
         {
index 6d58cc7..742fc10 100644 (file)
@@ -286,6 +286,13 @@ int SaveCallLog(CallLogInfo **info,int num);
 
 int32_t SetMicMutecat1(bool isMute);
 
+void AudioActInterrupt(AudioStreamType type);
+
+
+
+
+
+
 #ifdef __cplusplus
 }
 #endif
index be1825b..0cf660c 100644 (file)
@@ -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
index aa2dec3..05a7d7b 100644 (file)
@@ -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);
index 955de68..a0dd42e 100644 (file)
@@ -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
index 64f2806..508f998 100644 (file)
@@ -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
 }
index 3a58e67..73bdca5 100644 (file)
@@ -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);
 }
index 4811b31..50ae4ae 100644 (file)
@@ -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;
index 2f8ccb1..aa299e6 100644 (file)
@@ -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,