diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 027ed9d9226a04b7ee441f8602edb0a8107207f7..dc1835816667528dfa10f6dab848d4342ffa5a33 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -691,14 +691,11 @@ int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationSta { std::lock_guard lock(dynamicMutex_); std::shared_ptr audioEffectRotation = AudioEffectRotation::GetInstance(); - int32_t ret; - if (((deviceType_ == DEVICE_TYPE_SPEAKER) && (spkOffloadEnabled_)) || - ((deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP) && (btOffloadEnabled_))) { - ret = EffectDspRotationUpdate(audioEffectRotation, rotationState); - } else { - ret = EffectApRotationUpdate(audioEffectRotation, rotationState); - } - return ret; + AUDIO_INFO_LOG("rotation update to %{public}u", rotationState); + EffectDspRotationUpdate(audioEffectRotation, rotationState); + EffectApRotationUpdate(audioEffectRotation, rotationState); + + return SUCCESS; } #endif diff --git a/services/audio_policy/server/include/service/audio_policy_service.h b/services/audio_policy/server/include/service/audio_policy_service.h index c8aec2c43f6681944e8d1a0f6b2d2667162a9296..eded989b92145e8da2e22714d8f85ac347759108 100644 --- a/services/audio_policy/server/include/service/audio_policy_service.h +++ b/services/audio_policy/server/include/service/audio_policy_service.h @@ -527,6 +527,8 @@ public: AudioScene GetLastAudioScene() const; + void SetRotationToEffect(const uint32_t rotate); + private: AudioPolicyService() :audioPolicyManager_(AudioPolicyManagerFactory::GetAudioPolicyManager()), diff --git a/services/audio_policy/server/src/audio_policy_server.cpp b/services/audio_policy/server/src/audio_policy_server.cpp index 2d25e69371bd6fe750992d5e56214778b0747083..6ac01eb0918cfbe54ea75d3ce818635d122bbe24 100644 --- a/services/audio_policy/server/src/audio_policy_server.cpp +++ b/services/audio_policy/server/src/audio_policy_server.cpp @@ -209,6 +209,7 @@ void AudioPolicyServer::OnAddSystemAbility(int32_t systemAbilityId, const std::s case COMMON_EVENT_SERVICE_ID: AUDIO_INFO_LOG("OnAddSystemAbility common event service start"); SubscribeCommonEvent("usual.event.DATA_SHARE_READY"); + SubscribeCommonEvent("custom.event.display_rotation_changed"); break; default: AUDIO_WARNING_LOG("OnAddSystemAbility unhandled sysabilityId:%{public}d", systemAbilityId); @@ -511,6 +512,10 @@ void AudioPolicyServer::OnReceiveEvent(const EventFwk::CommonEventData &eventDat if (isInitMuteState_ == false && action == "usual.event.DATA_SHARE_READY") { AUDIO_INFO_LOG("receive DATA_SHARE_READY action and need init mic mute state"); InitMicrophoneMute(); + } else if (action == "custom.event.display_rotation_changed") { + uint32_t rotate = static_cast(want.GetIntParam("rotation", 0)); + AUDIO_INFO_LOG("Set rotation to audioeffectchainmanager is %{public}d", rotate); + audioPolicyService_.SetRotationToEffect(rotate); } } diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index 04645b507b21d2e78b82c43b8fa6f853b9058ca3..4afd18b7be2aae44788282f64e61d69371071510 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -8353,5 +8353,15 @@ void AudioPolicyService::ResetOffloadModeOnSpatializationChanged(std::vector gsp = GetAudioServerProxy(); + CHECK_AND_RETURN_LOG(gsp != nullptr, "error for g_adProxy null"); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); + gsp->SetRotationToEffect(rotate); + IPCSkeleton::SetCallingIdentity(identity); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/include/audio_manager_base.h b/services/audio_service/client/include/audio_manager_base.h index 929b4dfb4af5a932ccda1c1177c42a80c3fe78df..e0600112d40014eb541d26b8170f33ab332f37a7 100644 --- a/services/audio_service/client/include/audio_manager_base.h +++ b/services/audio_service/client/include/audio_manager_base.h @@ -432,6 +432,11 @@ public: * Set Sink Mute For Switch Device. */ virtual int32_t SetSinkMuteForSwitchDevice(const std::string &devceClass, int32_t durationUs, bool mute) = 0; + + /** + * Set Rotation To Effect. + */ + virtual void SetRotationToEffect(const uint32_t rotate) = 0; public: DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioService"); }; @@ -502,6 +507,7 @@ private: int HandleSecondPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); int HandleThirdPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); int HandleFourthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + int HandleSetRotationToEffect(MessageParcel &data, MessageParcel &reply); }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/include/audio_manager_proxy.h b/services/audio_service/client/include/audio_manager_proxy.h index d2df7b775e7e94c4754eaea0f8c37fd221ea016b..12706be356f6d8a56dfec4e18ed192d04cdc3610 100644 --- a/services/audio_service/client/include/audio_manager_proxy.h +++ b/services/audio_service/client/include/audio_manager_proxy.h @@ -96,6 +96,7 @@ public: void LoadHdiEffectModel() override; void UpdateEffectBtOffloadSupported(const bool &isSupported) override; int32_t SetSinkMuteForSwitchDevice(const std::string &devceClass, int32_t durationUs, bool mute) override; + void SetRotationToEffect(const uint32_t rotate) override; private: static inline BrokerDelegator delegator_; }; 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 30ec9912eff72a41b2cc50c321c18f6556e1316a..b0a6cf189065ccdeeb7147a8abd02874c3c37808 100644 --- a/services/audio_service/client/include/pulseaudio_ipc_interface_code.h +++ b/services/audio_service/client/include/pulseaudio_ipc_interface_code.h @@ -79,7 +79,8 @@ namespace AudioStandard { LOAD_HDI_EFFECT_MODEL, UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED, SET_SINK_MUTE_FOR_SWITCH_DEVICE, - AUDIO_SERVER_CODE_MAX = SET_SINK_MUTE_FOR_SWITCH_DEVICE, + SET_ROTATION_TO_EFFECT, + AUDIO_SERVER_CODE_MAX = SET_ROTATION_TO_EFFECT, }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/client/src/audio_manager_proxy.cpp b/services/audio_service/client/src/audio_manager_proxy.cpp index 8562a66013bc56242980912b3af14953834dee2e..c9bb57a18336095b9e4ae0ba6b777683a0a62b44 100644 --- a/services/audio_service/client/src/audio_manager_proxy.cpp +++ b/services/audio_service/client/src/audio_manager_proxy.cpp @@ -1181,5 +1181,20 @@ int32_t AudioManagerProxy::SetSinkMuteForSwitchDevice(const std::string &devceCl CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed, error:%{public}d", error); return reply.ReadInt32(); } + +void AudioManagerProxy::SetRotationToEffect(const uint32_t rotate) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool ret = data.WriteInterfaceToken(GetDescriptor()); + CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed"); + data.WriteUint32(rotate); + + int32_t error = Remote()->SendRequest( + static_cast(AudioServerInterfaceCode::SET_ROTATION_TO_EFFECT), data, reply, option); + CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/server/include/audio_server.h b/services/audio_service/server/include/audio_server.h index 4fad113f974348867cb8004b7180d6a856d12b28..341e9a925dc73c01c83e8bb24caa6e98cb329f17 100644 --- a/services/audio_service/server/include/audio_server.h +++ b/services/audio_service/server/include/audio_server.h @@ -159,6 +159,8 @@ public: void LoadHdiEffectModel() override; void UpdateEffectBtOffloadSupported(const bool &isSupported) override; + + void SetRotationToEffect(const uint32_t rotate) override; protected: void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; diff --git a/services/audio_service/server/src/audio_manager_stub.cpp b/services/audio_service/server/src/audio_manager_stub.cpp index 37681c5cac822563f4e9a2abf7338c1a7f9ad050..e10576676c557684c113f434b0d4848b27654ac0 100644 --- a/services/audio_service/server/src/audio_manager_stub.cpp +++ b/services/audio_service/server/src/audio_manager_stub.cpp @@ -87,6 +87,7 @@ const char *g_audioServerCodeStrs[] = { "LOAD_HDI_EFFECT_MODEL", "UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED", "SET_SINK_MUTE_FOR_SWITCH_DEVICE", + "SET_ROTATION_TO_EFFECT", }; constexpr size_t codeNums = sizeof(g_audioServerCodeStrs) / sizeof(const char *); static_assert(codeNums == (static_cast (AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX) + 1), @@ -736,6 +737,8 @@ int AudioManagerStub::HandleFourthPartCode(uint32_t code, MessageParcel &data, M return HandleUpdateEffectBtOffloadSupported(data, reply); case static_cast(AudioServerInterfaceCode::SET_SINK_MUTE_FOR_SWITCH_DEVICE): return HandleSetSinkMuteForSwitchDevice(data, reply); + case static_cast(AudioServerInterfaceCode::SET_ROTATION_TO_EFFECT): + return HandleSetRotationToEffect(data, reply); default: AUDIO_ERR_LOG("default case, need check AudioManagerStub"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -883,5 +886,11 @@ int AudioManagerStub::HandleSetSinkMuteForSwitchDevice(MessageParcel &data, Mess return AUDIO_OK; } +int AudioManagerStub::HandleSetRotationToEffect(MessageParcel &data, MessageParcel &reply) +{ + SetRotationToEffect(data.ReadUint32()); + return AUDIO_OK; +} + } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/server/src/audio_server.cpp b/services/audio_service/server/src/audio_server.cpp index 4a2af7b1312f5196f953200cc1291037bd24180e..0a68b7a0991c377db57a069fa7a53bb9f8800b22 100644 --- a/services/audio_service/server/src/audio_server.cpp +++ b/services/audio_service/server/src/audio_server.cpp @@ -2112,5 +2112,15 @@ void AudioServer::UpdateEffectBtOffloadSupported(const bool &isSupported) CHECK_AND_RETURN_LOG(audioEffectChainManager != nullptr, "audioEffectChainManager is nullptr"); audioEffectChainManager->UpdateEffectBtOffloadSupported(isSupported); } + +void AudioServer::SetRotationToEffect(const uint32_t rotate) +{ + int32_t callingUid = IPCSkeleton::GetCallingUid(); + CHECK_AND_RETURN_LOG(callingUid == audioUid_, "set rotation to effect refused for %{public}d", callingUid); + + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_LOG(audioEffectChainManager != nullptr, "audioEffectChainManager is nullptr"); + audioEffectChainManager->EffectRotationUpdate(rotate); +} } // namespace AudioStandard } // namespace OHOS