From e9afadff03788df88a786130fec9454837fe5744 Mon Sep 17 00:00:00 2001 From: xupeng Date: Wed, 31 Jul 2024 11:39:20 +0800 Subject: [PATCH 1/7] Select spatial audio parameters based on spatial device type Signed-off-by: xupeng --- .../audioeffect/include/audio_effect_chain.h | 2 + .../include/audio_effect_chain_manager.h | 2 + .../audioeffect/src/audio_effect_chain.cpp | 41 +++++++++++-------- .../src/audio_effect_chain_manager.cpp | 28 +++++++++++++ .../native/audiocommon/include/audio_effect.h | 5 ++- .../audio_spatialization_service.h | 2 + .../audio_spatialization_service.cpp | 40 ++++++++++++++++++ .../client/include/audio_manager_base.h | 10 +++++ .../client/include/audio_manager_proxy.h | 1 + .../include/pulseaudio_ipc_interface_code.h | 1 + .../client/src/audio_manager_proxy.cpp | 18 ++++++++ .../server/include/audio_server.h | 2 + .../server/src/audio_manager_stub.cpp | 11 +++++ .../audio_service/server/src/audio_server.cpp | 12 ++++++ 14 files changed, 158 insertions(+), 17 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain.h b/frameworks/native/audioeffect/include/audio_effect_chain.h index f5a8fd4988..eab7c11d78 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain.h @@ -58,6 +58,7 @@ public: uint32_t GetLatency(); int32_t UpdateEffectParam(); void ResetIoBufferConfig(); + void SetSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType); private: AudioEffectConfig GetIoBufferConfig(); @@ -80,6 +81,7 @@ private: FILE *dumpFileOutput_ = nullptr; std::string dumpNameIn_ = ""; std::string dumpNameOut_ = ""; + AudioSpatialDeviceType spatialDeviceType_{ EARPHONE_TYPE_OTHERS }; #ifdef SENSOR_ENABLE std::shared_ptr headTracker_; diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 3de79618fc..3292ce9373 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -112,6 +112,7 @@ public: int32_t UpdateMultichannelConfig(const std::string &sceneType); int32_t InitAudioEffectChainDynamic(const std::string &sceneType); int32_t UpdateSpatializationState(AudioSpatializationState spatializationState); + int32_t UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType); int32_t SetHdiParam(const std::string &sceneType, const std::string &effectMode, bool enabled); int32_t SessionInfoMapAdd(const std::string &sessionID, const SessionEffectInfo &info); int32_t SessionInfoMapDelete(const std::string &sceneType, const std::string &sessionID); @@ -187,6 +188,7 @@ private: bool isCommonEffectChainExisted_ = false; bool debugArmFlag_ = false; int32_t commonEffectChainCount_ = 0; + AudioSpatialDeviceType spatialDeviceType_{ EARPHONE_TYPE_OTHERS }; #ifdef SENSOR_ENABLE std::shared_ptr headTracker_; diff --git a/frameworks/native/audioeffect/src/audio_effect_chain.cpp b/frameworks/native/audioeffect/src/audio_effect_chain.cpp index 26516f5003..efe3e4f4f9 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain.cpp @@ -27,7 +27,7 @@ namespace OHOS { namespace AudioStandard { -const uint32_t NUM_SET_EFFECT_PARAM = 6; +const uint32_t NUM_SET_EFFECT_PARAM = 7; const uint32_t DEFAULT_SAMPLE_RATE = 48000; const uint32_t DEFAULT_NUM_CHANNEL = STEREO; const uint64_t DEFAULT_NUM_CHANNELLAYOUT = CH_LAYOUT_STEREO; @@ -149,39 +149,41 @@ int32_t AudioEffectChain::SetEffectParamToHandle(AudioEffectHandle handle, int32 { AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectConfig), &ioBufferConfig_}; AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + std::vector paramBuffer(sizeof(AudioEffectParam) + NUM_SET_EFFECT_PARAM * sizeof(int32_t)); // Set param - AudioEffectParam *effectParam = - new AudioEffectParam[sizeof(AudioEffectParam) + NUM_SET_EFFECT_PARAM * sizeof(int32_t)]; + AudioEffectParam *effectParam = reinterpret_cast(paramBuffer.data()); effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; int32_t *data = &(effectParam->data[0]); - *data++ = EFFECT_SET_PARAM; - *data++ = static_cast(currSceneType_); - *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode_); + data[0] = EFFECT_SET_PARAM; + data[1] = static_cast(currSceneType_); + AUDIO_DEBUG_LOG("set ap integration scene type: %{public}d", data[1]); + data[2] = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode_); // 2:index #ifdef WINDOW_MANAGER_ENABLE std::shared_ptr audioEffectRotation = AudioEffectRotation::GetInstance(); if (audioEffectRotation == nullptr) { - *data++ = 0; + data[3] = 0; // 3:index } else { - *data++ = audioEffectRotation->GetRotation(); + data[3] = audioEffectRotation->GetRotation(); // 3:index } #else - *data++ = 0; + data[3] = 0; // 3:index #endif - AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); + AUDIO_DEBUG_LOG("set ap integration rotation: %{public}d", data[3]); // 3:index std::shared_ptr audioEffectVolume = AudioEffectVolume::GetInstance(); if (audioEffectVolume == nullptr) { - *data++ = 0; + data[4] = 0; // 4:index } else { - *data++ = audioEffectVolume->GetApVolume(sceneType_); + data[4] = audioEffectVolume->GetApVolume(sceneType_); // 4:index } - AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); - *data++ = extraEffectChainType_; - AUDIO_DEBUG_LOG("set scene type: %{public}d", extraEffectChainType_); + AUDIO_DEBUG_LOG("set ap integration volume: %{public}d", data[4]); // 4:index + data[5] = extraEffectChainType_; // 5:index + AUDIO_DEBUG_LOG("set extra effect chain type: %{public}d", extraEffectChainType_); + data[6] = spatialDeviceType_; // 6:index + AUDIO_DEBUG_LOG("set ap integration spatial device type: %{public}d", data[6]); // 6:index cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); - delete[] effectParam; return ret; } @@ -396,5 +398,12 @@ void AudioEffectChain::InitEffectChain() sceneType_.c_str(), effectMode_.c_str()); } } + +void AudioEffectChain::SetSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) +{ + spatialDeviceType_ = spatialDeviceType; + + return; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 9daeffda94..f232b06ccc 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -90,6 +90,7 @@ AudioEffectChainManager::AudioEffectChainManager() SceneTypeToEffectChainCountBackupMap_.clear(); deviceType_ = DEVICE_TYPE_SPEAKER; deviceSink_ = DEFAULT_DEVICE_SINK; + spatialDeviceType_ = EARPHONE_TYPE_OTHERS; isInitialized_ = false; #ifdef SENSOR_ENABLE @@ -379,6 +380,7 @@ int32_t AudioEffectChainManager::SetAudioEffectChainDynamic(const std::string &s audioEffectChain->SetEffectMode(effectMode); audioEffectChain->SetExtraSceneType(extraSceneType_); + audioEffectChain->SetSpatialDeviceType(spatialDeviceType_); for (std::string effect: EffectChainToEffectsMap_[effectChain]) { AudioEffectHandle handle = nullptr; AudioEffectDescriptor descriptor; @@ -757,6 +759,32 @@ int32_t AudioEffectChainManager::UpdateSpatializationState(AudioSpatializationSt return SUCCESS; } +int32_t AudioEffectChainManager::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) +{ + int32_t ret{ SUCCESS }; + spatialDeviceType_ = spatialDeviceType; + + effectHdiInput_[0] = HDI_UPDATE_SPATIAL_DEVICE_TYPE; + effectHdiInput_[1] = spatialDeviceType_; + AUDIO_INFO_LOG("set hdi spatialDeviceType: %{public}d", effectHdiInput_[1]); + ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); + if (ret != SUCCESS) { + AUDIO_WARNING_LOG("set hdi update spatial device type failed"); + } + + std::lock_guard lock(dynamicMutex_); + for (auto& sceneType2EffectChain : SceneTypeToEffectChainMap_) { + auto audioEffectChain = sceneType2EffectChain.second; + if (audioEffectChain != nullptr) { + audioEffectChain->SetSpatialDeviceType(spatialDeviceType_); + ret = audioEffectChain->UpdateEffectParam(); + CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERROR, "UpdateEffectParam failed."); + } + } + + return SUCCESS; +} + int32_t AudioEffectChainManager::ReturnEffectChannelInfo(const std::string &sceneType, uint32_t &channels, uint64_t &channelLayout) { diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 9b5caddcf1..1f8881d0bf 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -41,12 +41,15 @@ constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16; // max num of e constexpr int32_t HDI_EFFECT_NUM = 2; constexpr int32_t HDI_SET_PATAM = 6; + constexpr int32_t HDI_INIT = 0; constexpr int32_t HDI_BYPASS = 1; constexpr int32_t HDI_HEAD_MODE = 2; constexpr int32_t HDI_ROOM_MODE = 3; constexpr int32_t HDI_BLUETOOTH_MODE = 4; constexpr int32_t HDI_DESTROY = 5; +constexpr int32_t HDI_UPDATE_SPATIAL_DEVICE_TYPE = 6; + constexpr int32_t HDI_VOLUME = 7; constexpr int32_t HDI_ROTATION = 8; @@ -353,4 +356,4 @@ struct AudioRendererInfoForSpatialization { } // namespace AudioStandard } // namespace OHOS -#endif //AUDIO_FRAMEWORK_AUDIO_EFFECT_H \ No newline at end of file +#endif // AUDIO_FRAMEWORK_AUDIO_EFFECT_H \ No newline at end of file diff --git a/services/audio_policy/server/include/service/spatialization/audio_spatialization_service.h b/services/audio_policy/server/include/service/spatialization/audio_spatialization_service.h index cd7b13d972..74a5435f71 100644 --- a/services/audio_policy/server/include/service/spatialization/audio_spatialization_service.h +++ b/services/audio_policy/server/include/service/spatialization/audio_spatialization_service.h @@ -84,6 +84,7 @@ private: int32_t UpdateSpatializationStateReal(bool outputDeviceChange, std::string preDeviceAddress = ""); int32_t UpdateSpatializationState(); int32_t UpdateSpatializationSceneType(); + void UpdateSpatialDeviceType(AudioSpatialDeviceType audioSpatialDeviceType); void HandleSpatializationStateChange(bool outputDeviceChange); void WriteSpatializationStateToDb(WriteToDbOperation operation); bool IsHeadTrackingDataRequestedForCurrentDevice(); @@ -99,6 +100,7 @@ private: bool isLoadedfromDb_ = false; AudioSpatializationState spatializationStateFlag_ = {false}; AudioSpatializationSceneType spatializationSceneType_ = SPATIALIZATION_SCENE_TYPE_DEFAULT; + AudioSpatialDeviceType currSpatialDeviceType_{ EARPHONE_TYPE_OTHERS }; std::vector spatializationRendererInfoList_; std::mutex spatializationServiceMutex_; std::mutex spatializationSupportedMutex_; diff --git a/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp b/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp index 018e26483b..0499a0f466 100644 --- a/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp +++ b/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp @@ -232,6 +232,8 @@ bool AudioSpatializationService::IsHeadTrackingSupportedForDevice(const std::str int32_t AudioSpatializationService::UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState) { AUDIO_INFO_LOG("UpdateSpatialDeviceState Entered"); + AUDIO_INFO_LOG("isSpatializationSupported = %{public}d, isHeadTrackingSupported = %{public}d", + audioSpatialDeviceState.isSpatializationSupported, audioSpatialDeviceState.isHeadTrackingSupported); { std::lock_guard lock(spatializationSupportedMutex_); if (addressToSpatialDeviceStateMap_.count(audioSpatialDeviceState.address) > 0 && @@ -243,6 +245,13 @@ int32_t AudioSpatializationService::UpdateSpatialDeviceState(const AudioSpatialD addressToSpatialDeviceStateMap_[audioSpatialDeviceState.address] = audioSpatialDeviceState; } + AUDIO_INFO_LOG("currSpatialDeviceType_ = %{public}d, nextSpatialDeviceType_ = %{public}d", + currSpatialDeviceType_, audioSpatialDeviceState.spatialDeviceType); + if (audioSpatialDeviceState.spatialDeviceType != currSpatialDeviceType_) { + UpdateSpatialDeviceType(audioSpatialDeviceState.spatialDeviceType); + currSpatialDeviceType_ = audioSpatialDeviceState.spatialDeviceType; + } + std::lock_guard lock(spatializationServiceMutex_); if (UpdateSpatializationStateReal(false) != 0) { return ERROR; @@ -286,6 +295,24 @@ void AudioSpatializationService::UpdateCurrentDevice(const std::string macAddres } std::string preDeviceAddress = currentDeviceAddress_; currentDeviceAddress_ = macAddress; + + if (addressToSpatialDeviceStateMap_.find(currentDeviceAddress_) != addressToSpatialDeviceStateMap_.end()) { + auto nextSpatialDeviceType{ addressToSpatialDeviceStateMap_[currentDeviceAddress_].spatialDeviceType }; + AUDIO_INFO_LOG("currSpatialDeviceType_ = %{public}d, nextSpatialDeviceType_ = %{public}d", + currSpatialDeviceType_, nextSpatialDeviceType); + if (nextSpatialDeviceType != currSpatialDeviceType_) { + UpdateSpatialDeviceType(nextSpatialDeviceType); + currSpatialDeviceType_ = nextSpatialDeviceType; + } + } else { + AUDIO_INFO_LOG("currSpatialDeviceType_ = %{public}d, nextSpatialDeviceType_ = %{public}d", + currSpatialDeviceType_, EARPHONE_TYPE_NONE); + if (currSpatialDeviceType_ != EARPHONE_TYPE_NONE) { + UpdateSpatialDeviceType(EARPHONE_TYPE_NONE); + currSpatialDeviceType_ = EARPHONE_TYPE_NONE; + } + } + if (UpdateSpatializationStateReal(true, preDeviceAddress) != 0) { AUDIO_WARNING_LOG("UpdateSpatializationStateReal fail"); } @@ -392,6 +419,19 @@ int32_t AudioSpatializationService::UpdateSpatializationSceneType() return SPATIALIZATION_SERVICE_OK; } +void AudioSpatializationService::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) +{ + const sptr gsp = GetAudioServerProxy(); + CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable: g_adProxy null"); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); + int32_t ret = gsp->UpdateSpatialDeviceType(spatialDeviceType); + IPCSkeleton::SetCallingIdentity(identity); + CHECK_AND_RETURN_LOG(ret == 0, "AudioSpatializationService::UpdateSpatialDeviceType fail"); + + return; +} + void AudioSpatializationService::HandleSpatializationStateChange(bool outputDeviceChange) { AUDIO_INFO_LOG("Spatialization State callback is triggered"); diff --git a/services/audio_service/client/include/audio_manager_base.h b/services/audio_service/client/include/audio_manager_base.h index 929b4dfb4a..d75e8b4858 100644 --- a/services/audio_service/client/include/audio_manager_base.h +++ b/services/audio_service/client/include/audio_manager_base.h @@ -368,6 +368,15 @@ public: */ virtual int32_t UpdateSpatializationState(AudioSpatializationState spatializationState) = 0; + /** + * Update spatial device type. + * + * @param spatialDeviceType identify the spatial device type. + * + * @return result of setting. 0 if success, error number else. + */ + virtual int32_t UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) = 0; + /** * Notify Stream volume changed. * @@ -471,6 +480,7 @@ private: int HandleSetWakeupSourceCallback(MessageParcel &data, MessageParcel &reply); int HandleSetCaptureSilentState(MessageParcel &data, MessageParcel &reply); int HandleUpdateSpatializationState(MessageParcel &data, MessageParcel &reply); + int HandleUpdateSpatialDeviceType(MessageParcel& data, MessageParcel& reply); int HandleGetCapturePresentationPosition(MessageParcel &data, MessageParcel &reply); int HandleGetRenderPresentationPosition(MessageParcel &data, MessageParcel &reply); int HandleOffloadSetVolume(MessageParcel &data, MessageParcel &reply); diff --git a/services/audio_service/client/include/audio_manager_proxy.h b/services/audio_service/client/include/audio_manager_proxy.h index d2df7b775e..688672349c 100644 --- a/services/audio_service/client/include/audio_manager_proxy.h +++ b/services/audio_service/client/include/audio_manager_proxy.h @@ -76,6 +76,7 @@ public: int32_t RegiestPolicyProvider(const sptr &object) override; int32_t SetCaptureSilentState(bool state) override; int32_t UpdateSpatializationState(AudioSpatializationState spatializationState) override; + int32_t UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) override; int32_t NotifyStreamVolumeChanged(AudioStreamType streamType, float volume) override; int32_t SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType) override; int32_t ResetRouteForDisconnect(DeviceType type) override; diff --git a/services/audio_service/client/include/pulseaudio_ipc_interface_code.h b/services/audio_service/client/include/pulseaudio_ipc_interface_code.h index 30ec9912ef..a118c36ca1 100644 --- a/services/audio_service/client/include/pulseaudio_ipc_interface_code.h +++ b/services/audio_service/client/include/pulseaudio_ipc_interface_code.h @@ -51,6 +51,7 @@ namespace AudioStandard { SET_WAKEUP_CLOSE_CALLBACK, SET_CAPTURE_SILENT_STATE, UPDATE_SPATIALIZATION_STATE, + UPDATE_SPATIAL_DEVICE_TYPE, OFFLOAD_SET_VOLUME, OFFLOAD_DRAIN, OFFLOAD_GET_PRESENTATION_POSITION, diff --git a/services/audio_service/client/src/audio_manager_proxy.cpp b/services/audio_service/client/src/audio_manager_proxy.cpp index c0ee5e54ca..97466806f9 100644 --- a/services/audio_service/client/src/audio_manager_proxy.cpp +++ b/services/audio_service/client/src/audio_manager_proxy.cpp @@ -994,6 +994,24 @@ int32_t AudioManagerProxy::UpdateSpatializationState(AudioSpatializationState sp return reply.ReadInt32(); } +int32_t AudioManagerProxy::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) +{ + int32_t error; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); + data.WriteInt32(spatialDeviceType); + + error = Remote()->SendRequest( + static_cast(AudioServerInterfaceCode::UPDATE_SPATIAL_DEVICE_TYPE), data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "UpdateSpatialDeviceType failed, error: %{public}d", error); + + return reply.ReadInt32(); +} + int32_t AudioManagerProxy::SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType) { int32_t error; diff --git a/services/audio_service/server/include/audio_server.h b/services/audio_service/server/include/audio_server.h index 4fad113f97..8405a8b867 100644 --- a/services/audio_service/server/include/audio_server.h +++ b/services/audio_service/server/include/audio_server.h @@ -133,6 +133,8 @@ public: int32_t UpdateSpatializationState(AudioSpatializationState spatializationState) override; + int32_t UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) override; + int32_t NotifyStreamVolumeChanged(AudioStreamType streamType, float volume) override; int32_t SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType) override; diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index 1ed75b48c2..d8b918f61f 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -59,6 +59,7 @@ const char *g_audioServerCodeStrs[] = { "SET_WAKEUP_CLOSE_CALLBACK", "SET_CAPTURE_SILENT_STATE", "UPDATE_SPATIALIZATION_STATE", + "UPDATE_SPATIAL_DEVICE_TYPE", "OFFLOAD_SET_VOLUME", "OFFLOAD_DRAIN", "OFFLOAD_GET_PRESENTATION_POSITION", @@ -564,6 +565,14 @@ int AudioManagerStub::HandleUpdateSpatializationState(MessageParcel &data, Messa return AUDIO_OK; } +int AudioManagerStub::HandleUpdateSpatialDeviceType(MessageParcel& data, MessageParcel& reply) +{ + AudioSpatialDeviceType spatialDeviceType = static_cast(data.ReadInt32()); + int32_t ret = UpdateSpatialDeviceType(spatialDeviceType); + reply.WriteInt32(ret); + return AUDIO_OK; +} + int AudioManagerStub::HandleGetCapturePresentationPosition(MessageParcel &data, MessageParcel &reply) { const std::string deviceClass = data.ReadString(); @@ -811,6 +820,8 @@ int AudioManagerStub::HandleSecondPartCode(uint32_t code, MessageParcel &data, M return HandleSetCaptureSilentState(data, reply); case static_cast(AudioServerInterfaceCode::UPDATE_SPATIALIZATION_STATE): return HandleUpdateSpatializationState(data, reply); + case static_cast(AudioServerInterfaceCode::UPDATE_SPATIAL_DEVICE_TYPE): + return HandleUpdateSpatialDeviceType(data, reply); case static_cast(AudioServerInterfaceCode::OFFLOAD_SET_VOLUME): return HandleOffloadSetVolume(data, reply); default: diff --git a/services/audio_service/server/src/audio_server.cpp b/services/audio_service/server/src/audio_server.cpp index 0127892627..0070840fb5 100644 --- a/services/audio_service/server/src/audio_server.cpp +++ b/services/audio_service/server/src/audio_server.cpp @@ -1949,6 +1949,18 @@ int32_t AudioServer::UpdateSpatializationState(AudioSpatializationState spatiali return audioEffectChainManager->UpdateSpatializationState(spatializationState); } +int32_t AudioServer::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_RET_LOG(callingUid == audioUid_ || callingUid == ROOT_UID, + ERR_NOT_SUPPORTED, "UpdateSpatialDeviceType refused for %{public}d", callingUid); + + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, ERROR, "audioEffectChainManager is nullptr"); + + return audioEffectChainManager->UpdateSpatialDeviceType(spatialDeviceType); +} + int32_t AudioServer::NotifyStreamVolumeChanged(AudioStreamType streamType, float volume) { int32_t callingUid = IPCSkeleton::GetCallingUid(); -- Gitee From d646d0cb1bd4295adb5b726fb2d53087224db38e Mon Sep 17 00:00:00 2001 From: Gavin <14040988+GavinXu89@user.noreply.gitee.com> Date: Fri, 2 Aug 2024 02:40:18 +0000 Subject: [PATCH 2/7] update frameworks/native/audioeffect/src/audio_effect_chain.cpp. Signed-off-by: Gavin <14040988+GavinXu89@user.noreply.gitee.com> --- .../audioeffect/src/audio_effect_chain.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain.cpp b/frameworks/native/audioeffect/src/audio_effect_chain.cpp index efe3e4f4f9..adaa26fba4 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain.cpp @@ -159,29 +159,29 @@ int32_t AudioEffectChain::SetEffectParamToHandle(AudioEffectHandle handle, int32 data[0] = EFFECT_SET_PARAM; data[1] = static_cast(currSceneType_); AUDIO_DEBUG_LOG("set ap integration scene type: %{public}d", data[1]); - data[2] = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode_); // 2:index + data[2] = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode_); // 2:effect mode index #ifdef WINDOW_MANAGER_ENABLE std::shared_ptr audioEffectRotation = AudioEffectRotation::GetInstance(); if (audioEffectRotation == nullptr) { - data[3] = 0; // 3:index + data[3] = 0; // 3:rotation index } else { - data[3] = audioEffectRotation->GetRotation(); // 3:index + data[3] = audioEffectRotation->GetRotation(); // 3:rotation index } #else - data[3] = 0; // 3:index + data[3] = 0; // 3:rotation index #endif - AUDIO_DEBUG_LOG("set ap integration rotation: %{public}d", data[3]); // 3:index + AUDIO_DEBUG_LOG("set ap integration rotation: %{public}d", data[3]); // 3:rotation index std::shared_ptr audioEffectVolume = AudioEffectVolume::GetInstance(); if (audioEffectVolume == nullptr) { - data[4] = 0; // 4:index + data[4] = 0; // 4:volume index } else { - data[4] = audioEffectVolume->GetApVolume(sceneType_); // 4:index + data[4] = audioEffectVolume->GetApVolume(sceneType_); // 4:volume index } - AUDIO_DEBUG_LOG("set ap integration volume: %{public}d", data[4]); // 4:index - data[5] = extraEffectChainType_; // 5:index + AUDIO_DEBUG_LOG("set ap integration volume: %{public}d", data[4]); // 4:volume index + data[5] = extraEffectChainType_; // 5:extra effect chain type index AUDIO_DEBUG_LOG("set extra effect chain type: %{public}d", extraEffectChainType_); - data[6] = spatialDeviceType_; // 6:index - AUDIO_DEBUG_LOG("set ap integration spatial device type: %{public}d", data[6]); // 6:index + data[6] = spatialDeviceType_; // 6:spatial device type index + AUDIO_DEBUG_LOG("set ap integration spatial device type: %{public}d", data[6]); // 6:spatial device type index cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); return ret; -- Gitee From 79547a0694038e61b4e8dfd5ef0030c7bab495e4 Mon Sep 17 00:00:00 2001 From: Gavin <14040988+GavinXu89@user.noreply.gitee.com> Date: Fri, 2 Aug 2024 06:18:55 +0000 Subject: [PATCH 3/7] update services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp. Signed-off-by: Gavin <14040988+GavinXu89@user.noreply.gitee.com> --- .../service/spatialization/audio_spatialization_service.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp b/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp index 0499a0f466..5f429407ff 100644 --- a/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp +++ b/services/audio_policy/server/src/service/spatialization/audio_spatialization_service.cpp @@ -231,8 +231,8 @@ bool AudioSpatializationService::IsHeadTrackingSupportedForDevice(const std::str int32_t AudioSpatializationService::UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState) { - AUDIO_INFO_LOG("UpdateSpatialDeviceState Entered"); - AUDIO_INFO_LOG("isSpatializationSupported = %{public}d, isHeadTrackingSupported = %{public}d", + AUDIO_INFO_LOG("UpdateSpatialDeviceState Entered, " + "isSpatializationSupported = %{public}d, isHeadTrackingSupported = %{public}d", audioSpatialDeviceState.isSpatializationSupported, audioSpatialDeviceState.isHeadTrackingSupported); { std::lock_guard lock(spatializationSupportedMutex_); -- Gitee From b0dc5f0afa1e785d44c370abda9d9fb267d815a5 Mon Sep 17 00:00:00 2001 From: Gavin <14040988+GavinXu89@user.noreply.gitee.com> Date: Fri, 2 Aug 2024 06:34:29 +0000 Subject: [PATCH 4/7] update frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp. Signed-off-by: Gavin <14040988+GavinXu89@user.noreply.gitee.com> --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index f232b06ccc..e8585d80ea 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -777,10 +777,10 @@ int32_t AudioEffectChainManager::UpdateSpatialDeviceType(AudioSpatialDeviceType auto audioEffectChain = sceneType2EffectChain.second; if (audioEffectChain != nullptr) { audioEffectChain->SetSpatialDeviceType(spatialDeviceType_); - ret = audioEffectChain->UpdateEffectParam(); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERROR, "UpdateEffectParam failed."); + ret += audioEffectChain->UpdateEffectParam(); } } + CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERROR, "UpdateEffectParam failed."); return SUCCESS; } -- Gitee From be97b85a1a2f827e87a2cd89aff4df8cfee7b066 Mon Sep 17 00:00:00 2001 From: Gavin <14040988+GavinXu89@user.noreply.gitee.com> Date: Sun, 4 Aug 2024 12:35:05 +0000 Subject: [PATCH 5/7] update frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp. Signed-off-by: Gavin <14040988+GavinXu89@user.noreply.gitee.com> --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 4843479b9d..7015ccc255 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -775,10 +775,10 @@ int32_t AudioEffectChainManager::UpdateSpatialDeviceType(AudioSpatialDeviceType auto audioEffectChain = sceneType2EffectChain.second; if (audioEffectChain != nullptr) { audioEffectChain->SetSpatialDeviceType(spatialDeviceType_); - ret += audioEffectChain->UpdateEffectParam(); + ret = audioEffectChain->UpdateEffectParam(); + CHECK_AND_CONTINUE_LOG(ret == SUCCESS, ERROR, "UpdateEffectParam failed."); } } - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERROR, "UpdateEffectParam failed."); return SUCCESS; } -- Gitee From 3825b5fb6300d9ae3498f703ff663ab687a51a77 Mon Sep 17 00:00:00 2001 From: Gavin <14040988+GavinXu89@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 01:16:01 +0000 Subject: [PATCH 6/7] update frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp. Signed-off-by: Gavin <14040988+GavinXu89@user.noreply.gitee.com> --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 7015ccc255..55362de0b4 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -776,7 +776,7 @@ int32_t AudioEffectChainManager::UpdateSpatialDeviceType(AudioSpatialDeviceType if (audioEffectChain != nullptr) { audioEffectChain->SetSpatialDeviceType(spatialDeviceType_); ret = audioEffectChain->UpdateEffectParam(); - CHECK_AND_CONTINUE_LOG(ret == SUCCESS, ERROR, "UpdateEffectParam failed."); + CHECK_AND_CONTINUE_LOG(ret == SUCCESS, "UpdateEffectParam failed."); } } -- Gitee From 7aee1fa8fe2298f5e23a1f2aa16ff89cd382af0a Mon Sep 17 00:00:00 2001 From: Gavin <14040988+GavinXu89@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 11:23:44 +0000 Subject: [PATCH 7/7] update services/audio_service/server/src/audio_server.cpp. Signed-off-by: Gavin <14040988+GavinXu89@user.noreply.gitee.com> --- services/audio_service/server/src/audio_server.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/audio_service/server/src/audio_server.cpp b/services/audio_service/server/src/audio_server.cpp index 70b9f76ffb..d4386400c4 100644 --- a/services/audio_service/server/src/audio_server.cpp +++ b/services/audio_service/server/src/audio_server.cpp @@ -1927,8 +1927,7 @@ int32_t AudioServer::UpdateSpatializationState(AudioSpatializationState spatiali int32_t AudioServer::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) { int32_t callingUid = IPCSkeleton::GetCallingUid(); - CHECK_AND_RETURN_RET_LOG(callingUid == audioUid_ || callingUid == ROOT_UID, - ERR_NOT_SUPPORTED, "UpdateSpatialDeviceType refused for %{public}d", callingUid); + CHECK_AND_RETURN_RET_LOG(PermissionUtil::VerifyIsAudio(), ERR_NOT_SUPPORTED, "refused for %{public}d", callingUid); AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, ERROR, "audioEffectChainManager is nullptr"); -- Gitee