From adfdda3320410c3472323c978bbc5afadc662928 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Sun, 18 Feb 2024 17:14:21 +0800 Subject: [PATCH 01/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- bundle.json | 3 +- frameworks/native/audioeffect/BUILD.gn | 4 + .../include/audio_effect_chain_adapter.h | 3 + .../include/audio_effect_chain_manager.h | 36 +-- .../include/audio_effect_hdi_param.h | 44 +++ .../include/audio_effect_rotation.h | 72 +++++ .../audioeffect/include/audio_effect_volume.h | 39 +++ .../src/audio_effect_chain_manager.cpp | 280 +++++++++++++----- .../src/audio_effect_hdi_param.cpp | 90 ++++++ .../audioeffect/src/audio_effect_rotation.cpp | 77 +++++ .../audioeffect/src/audio_effect_volume.cpp | 61 ++++ .../native/pulseaudio/modules/hdi/hdi_sink.c | 30 +- .../pulseaudio/modules/hdi/module_hdi_sink.c | 25 +- 13 files changed, 640 insertions(+), 124 deletions(-) create mode 100644 frameworks/native/audioeffect/include/audio_effect_hdi_param.h create mode 100644 frameworks/native/audioeffect/include/audio_effect_rotation.h create mode 100644 frameworks/native/audioeffect/include/audio_effect_volume.h create mode 100644 frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp create mode 100644 frameworks/native/audioeffect/src/audio_effect_rotation.cpp create mode 100644 frameworks/native/audioeffect/src/audio_effect_volume.cpp diff --git a/bundle.json b/bundle.json index 8bd0a1825e..805410c3df 100644 --- a/bundle.json +++ b/bundle.json @@ -65,7 +65,8 @@ "resource_schedule_service", "safwk", "samgr", - "sensor" + "sensor", + "window_manager" ], "third_party": [ "bounds_checking_function", diff --git a/frameworks/native/audioeffect/BUILD.gn b/frameworks/native/audioeffect/BUILD.gn index dde437aa8d..327df99422 100644 --- a/frameworks/native/audioeffect/BUILD.gn +++ b/frameworks/native/audioeffect/BUILD.gn @@ -59,6 +59,9 @@ ohos_shared_library("audio_effect") { sources = [ "src/audio_effect_chain_manager.cpp", "src/audio_head_tracker.cpp", + "src/audio_effect_hdi_param.cpp", + "src/audio_effect_rotation.cpp", + "src/audio_effect_volume.cpp", ] deps = [ "$pulseaudio_build_path/src/pulse:pulse" ] @@ -69,6 +72,7 @@ ohos_shared_library("audio_effect") { "drivers_interface_audio:libeffect_proxy_1.0", "hilog:libhilog", "ipc:ipc_single", + "window_manager:libdm", ] if (sensor_enable == true) { diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h b/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h index e83afe79e9..3a0a49ffab 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h @@ -40,6 +40,7 @@ typedef struct SessionInfoPack { const char *channelLayout; const char *sceneMode; const char *spatializationEnabled; + uint32_t volume; } SessionInfoPack; int32_t EffectChainManagerProcess(char *sceneType, BufferAttr *bufferAttr); @@ -57,6 +58,8 @@ bool EffectChainManagerCheckA2dpOffload(); int32_t EffectChainManagerDeleteSessionInfo(const char *sceneType, const char *sessionID); int32_t EffectChainManagerReturnEffectChannelInfo(const char *sceneType, uint32_t *channels, uint64_t *channelLayout); int32_t EffectChainManagerReturnMultiChannelInfo(uint32_t *channels, uint64_t *channelLayout); +int32_t EffectChainManagerVolumeUpdate(const char *sessionID, const uint32_t volume); +int32_t EffectChainManagerRotationUpdate(const uint32_t rotationState); #ifdef __cplusplus } diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 4ab47e0661..13644714d4 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -29,18 +29,21 @@ #include #include -#include "v1_0/ieffect_model.h" #include "audio_effect_chain_adapter.h" #include "audio_effect.h" #ifdef SENSOR_ENABLE #include "audio_head_tracker.h" #endif +#include "audio_effect_hdi_param.h" +#include "audio_effect_rotation.h" +#include "audio_effect_volume.h" namespace OHOS { namespace AudioStandard { -const uint32_t NUM_SET_EFFECT_PARAM = 3; +const uint32_t NUM_SET_EFFECT_PARAM_TWO = 2; +const uint32_t NUM_SET_EFFECT_PARAM_THREE = 3; const uint32_t DEFAULT_FRAMELEN = 1440; const uint32_t DEFAULT_SAMPLE_RATE = 48000; const uint32_t DEFAULT_NUM_CHANNEL = STEREO; @@ -51,8 +54,6 @@ const uint32_t FACTOR_TWO = 2; const uint32_t BASE_TEN = 10; const std::string DEFAULT_DEVICE_SINK = "Speaker"; const uint32_t SIZE_OF_SPATIALIZATION_STATE = 2; -const uint32_t SEND_HDI_COMMAND_LEN = 20; -const uint32_t GET_HDI_BUFFER_LEN = 10; const uint32_t HDI_ROOM_MODE_INDEX_TWO = 2; typedef struct sessionEffectInfo { @@ -60,6 +61,7 @@ typedef struct sessionEffectInfo { uint32_t channels; uint64_t channelLayout; std::string spatializationEnabled; + uint32_t volume; } sessionEffectInfo; const std::vector HVS_SUPPORTED_CHANNELLAYOUTS { @@ -74,22 +76,6 @@ const std::vector HVS_SUPPORTED_CHANNELLAYOUTS { CH_LAYOUT_9POINT1POINT6 }; -class AudioEffectHdi { -public: - AudioEffectHdi(); - ~AudioEffectHdi(); - void InitHdi(); - int32_t UpdateHdiState(int8_t *effectHdiInput); -private: - std::string libName; - std::string effectId; - int8_t input[SEND_HDI_COMMAND_LEN]; - int8_t output[GET_HDI_BUFFER_LEN]; - uint32_t replyLen; - IEffectModel *hdiModel_ = nullptr; - IEffectControl *hdiControl_ = nullptr; -}; - struct AudioEffectProcInfo { bool headTrackingEnabled; bool offloadEnabled; @@ -119,8 +105,8 @@ public: AudioEffectConfig GetIoBufferConfig(); void InitEffectChain(); void SetHeadTrackingDisabled(); - uint32_t GetLatency(); - + int32_t SetVolume(uint32_t volume); + int32_t SetRotation(uint32_t rotation); private: std::mutex reloadMutex; std::string sceneType; @@ -168,6 +154,8 @@ public: int32_t ReturnEffectChannelInfo(const std::string &sceneType, uint32_t *channels, uint64_t *channelLayout); int32_t ReturnMultiChannelInfo(uint32_t *channels, uint64_t *channelLayout); void RegisterEffectChainCountBackupMap(std::string sceneType, std::string operation); + int32_t EffectRotationUpdate(const uint32_t rotationState); + int32_t EffectVolumeUpdate(const std::string sessionIDString, const uint32_t volume); uint32_t GetLatency(std::string sessionId); private: @@ -200,7 +188,9 @@ private: std::shared_ptr headTracker_; #endif - std::shared_ptr audioEffectHdi_; + std::shared_ptr audioEffectHdiParam_; + std::shared_ptr audioEffectVolume_; + std::shared_ptr audioEffectRotation_; int8_t effectHdiInput[SEND_HDI_COMMAND_LEN]; }; } // namespace AudioStandard diff --git a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h new file mode 100644 index 0000000000..50320d9212 --- /dev/null +++ b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUDIO_EFFECT_HDI_PARAM_H +#define AUDIO_EFFECT_HDI_PARAM_H + +#include +#include "v1_0/ieffect_model.h" + +namespace OHOS { +namespace AudioStandard { +const uint32_t SEND_HDI_COMMAND_LEN = 20; +const uint32_t GET_HDI_BUFFER_LEN = 10; +class AudioEffectHdiParam { +public: + AudioEffectHdiParam(); + ~AudioEffectHdiParam(); + void InitHdi(); + int32_t UpdateHdiState(int8_t *effectHdiInput); +private: + int8_t input[SEND_HDI_COMMAND_LEN]; + int8_t output[GET_HDI_BUFFER_LEN]; + uint32_t replyLen; + std::string libName; + std::string effectId; + IEffectModel *hdiModel_; + std::vector libHdiControls_; + void CreateHdiControl(); +}; +} // namespace AudioStandard +} // namespace OHOS +#endif // AUDIO_EFFECT_HDI_PARAM_H \ No newline at end of file diff --git a/frameworks/native/audioeffect/include/audio_effect_rotation.h b/frameworks/native/audioeffect/include/audio_effect_rotation.h new file mode 100644 index 0000000000..c221348e64 --- /dev/null +++ b/frameworks/native/audioeffect/include/audio_effect_rotation.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUDIO_EFFECT_ROTATION_H +#define AUDIO_EFFECT_ROTATION_H + +#include +#include +#include "display_manager.h" +#include "dm_common.h" + +namespace OHOS { +namespace AudioStandard { +class AudioEffectRotation { +public: + AudioEffectRotation(); + ~AudioEffectRotation(); + static AudioEffectRotation *GetInstance(); + void Init(); + void SetRotation(uint32_t rotationState); + uint32_t GetRotation(); +private: + class AudioRotationListener : public OHOS::Rosen::DisplayManager::IDisplayListener { + public: + // AudioRotationListener(const std::shared_ptr &audioEffectRotation) + // { + // audioEffectRotation_ = audioEffectRotation; + // } + void OnCreate(Rosen::DisplayId displayId) override + { + AudioEffectRotation *audioEffectRotation = GetInstance(); + if (audioEffectRotation != nullptr) { + audioEffectRotation->OnCreate(displayId); + } + } + void OnDestroy(Rosen::DisplayId displayId) override + { + AudioEffectRotation *audioEffectRotation = GetInstance(); + if (audioEffectRotation != nullptr) { + audioEffectRotation->OnDestroy(displayId); + } + } + void OnChange(Rosen::DisplayId displayId) override + { + AudioEffectRotation *audioEffectRotation = GetInstance(); + if (audioEffectRotation != nullptr) { + audioEffectRotation->OnChange(displayId); + } + } + }; + + sptr audioRotationListener_; + uint32_t rotationState_; + void OnCreate(Rosen::DisplayId displayId); + void OnDestroy(Rosen::DisplayId displayId); + void OnChange(Rosen::DisplayId displayId); +}; +} // namespace AudioStandard +} // namespace OHOS +#endif // AUDIO_EFFECT_ROTATION_H \ No newline at end of file diff --git a/frameworks/native/audioeffect/include/audio_effect_volume.h b/frameworks/native/audioeffect/include/audio_effect_volume.h new file mode 100644 index 0000000000..10d0347e98 --- /dev/null +++ b/frameworks/native/audioeffect/include/audio_effect_volume.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUDIO_EFFECT_VOLUME_H +#define AUDIO_EFFECT_VOLUME_H + +#include +#include +#include + +namespace OHOS { +namespace AudioStandard { +class AudioEffectVolume { +public: + AudioEffectVolume(); + ~AudioEffectVolume(); + void SetApVolume(std::string sceneType, uint32_t volume); + uint32_t GetApVolume(std::string sceneType); + void SetDspVolume(uint32_t volume); + uint32_t GetDspVolume(); +private: + uint32_t dspVolume_; + std::mapSceneTypeToVolumeMap_; +}; +} // namespace AudioStandard +} // namespace OHOS +#endif // AUDIO_EFFECT_ROTATION_H \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 31f315b417..f17ec65e1c 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -165,6 +165,30 @@ int32_t EffectChainManagerMultichannelUpdate(const char *sceneType) return SUCCESS; } +// todo tranmit effectMode&sceneType +// todo tranmit bypass +int32_t EffectChainManagerVolumeUpdate(const char *sessionID, const uint32_t volume) +{ + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, ERR_INVALID_HANDLE, "null audioEffectChainManager"); + std::string sessionIDString = ""; + sessionIDString = sessionID; + if (audioEffectChainManager->EffectVolumeUpdate(sessionIDString, volume) != SUCCESS) { + return ERROR; + } + return SUCCESS; +} + +int32_t EffectChainManagerRotationUpdate(const uint32_t rotationState) +{ + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, ERR_INVALID_HANDLE, "null audioEffectChainManager"); + if (audioEffectChainManager->EffectRotationUpdate(rotationState) != SUCCESS) { + return ERROR; + } + return SUCCESS; +} + bool IsChannelLayoutHVSSupported(const uint64_t channelLayout) { return find(HVS_SUPPORTED_CHANNELLAYOUTS.begin(), HVS_SUPPORTED_CHANNELLAYOUTS.end(), @@ -267,6 +291,7 @@ int32_t EffectChainManagerAddSessionInfo(const char *sceneType, const char *sess info.channels = pack.channels; info.channelLayout = channelLayoutNum; info.spatializationEnabled = spatializationEnabledString; + info.volume = pack.volume; return audioEffectChainManager->SessionInfoMapAdd(sceneTypeString, sessionIDString, info); } @@ -422,7 +447,7 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr sceneType.c_str(), effectMode.c_str()); // Set param AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + - NUM_SET_EFFECT_PARAM * sizeof(int32_t)]; + NUM_SET_EFFECT_PARAM_THREE * sizeof(int32_t)]; effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; @@ -430,14 +455,57 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr *data++ = EFFECT_SET_PARAM; *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType); *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); - cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; + cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_THREE, effectParam}; ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); delete[] effectParam; CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], either one of libs EFFECT_CMD_SET_PARAM fail", sceneType.c_str(), effectMode.c_str()); standByEffectHandles.emplace_back(handle); libHandles.emplace_back(libHandle); - latency_ += static_cast(replyData); +} + +int32_t AudioEffectChain::SetVolume(uint32_t volume) +{ + std::lock_guard lock(reloadMutex); + for (AudioEffectHandle handle: standByEffectHandles) { + AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + + NUM_SET_EFFECT_PARAM_TWO * sizeof(int32_t)]; + effectParam->status = 0; + effectParam->paramSize = sizeof(int32_t); + effectParam->valueSize = 0; + int32_t *data = &(effectParam->data[0]); + *data++ = EFFECT_SET_PARAM; + *data++ = static_cast(volume); + int32_t replyData = 0; + AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_TWO, effectParam}; + AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); + delete[] effectParam; + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set volume EFFECT_CMD_SET_PARAM fail"); + } + return SUCCESS; +} + +int32_t AudioEffectChain::SetRotation(uint32_t rotation) +{ + std::lock_guard lock(reloadMutex); + for (AudioEffectHandle handle: standByEffectHandles) { + AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + + NUM_SET_EFFECT_PARAM_TWO * sizeof(int32_t)]; + effectParam->status = 0; + effectParam->paramSize = sizeof(int32_t); + effectParam->valueSize = 0; + int32_t *data = &(effectParam->data[0]); + *data++ = EFFECT_SET_PARAM; + *data++ = static_cast(rotation); + int32_t replyData = 0; + AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_TWO, effectParam}; + AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; + int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); + delete[] effectParam; + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set rotation EFFECT_CMD_SET_PARAM fail"); + } + return SUCCESS; } void AudioEffectChain::AddEffectHandleEnd() @@ -653,7 +721,9 @@ AudioEffectChainManager::AudioEffectChainManager() headTracker_ = std::make_shared(); #endif - audioEffectHdi_ = std::make_shared(); + audioEffectHdiParam_ = std::make_shared(); + audioEffectVolume_ = std::make_shared(); + // audioEffectRotation_ = std::make_shared(); memset_s(static_cast(effectHdiInput), sizeof(effectHdiInput), 0, sizeof(effectHdiInput)); } @@ -823,8 +893,18 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vectorInitHdi(); - + audioEffectHdiParam_->InitHdi(); + effectHdiInput[0] = HDI_BLUETOOTH_MODE; + effectHdiInput[1] = 1; + AUDIO_INFO_LOG("set hdi bluetooth mode: %{public}d", effectHdiInput[1]); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); + if (ret != 0) { + AUDIO_WARNING_LOG("set hdi bluetooth mode failed"); + } + // audioEffectRotation_->Init(); + AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); + CHECK_AND_RETURN_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + audioEffectRotation->Init(); isInitialized_ = true; } @@ -1041,6 +1121,103 @@ void AudioEffectChainManager::Dump() } } +int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDString, const uint32_t volume) +{ + std::lock_guard lock(dynamicMutex_); + // update session info + if (SessionIDToEffectInfoMap_.count(sessionIDString)) { + if (SessionIDToEffectInfoMap_[sessionIDString].volume != volume) { + SessionIDToEffectInfoMap_[sessionIDString].volume = volume; + } + } + if (offloadEnabled_){ + // update dsp volume + AUDIO_DEBUG_LOG("send volume to dsp."); + uint32_t volumeMax = 0; + for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { + std::set sessions = SceneTypeToSessionIDMap_[it->first]; + for (auto s = sessions.begin(); s != sessions.end(); s++) { + sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; + volumeMax = info.volume > volumeMax ? info.volume : volumeMax; + } + } + // send volume to dsp + if (audioEffectVolume_->GetDspVolume() != volumeMax) { + audioEffectVolume_->SetDspVolume(volumeMax); + effectHdiInput[0] = HDI_VOLUME; + effectHdiInput[1] = volumeMax; + AUDIO_INFO_LOG("set hdi volume: %{public}d", effectHdiInput[1]); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi volume failed"); + } + } else { + // send to ap + AUDIO_DEBUG_LOG("send volume to ap."); + for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { + uint32_t volumeMax = 0; + std::set sessions = SceneTypeToSessionIDMap_[it->first]; + for (auto s = sessions.begin(); s != sessions.end(); s++) { + sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; + volumeMax = info.volume > volumeMax ? info.volume : volumeMax; + } + if (audioEffectVolume_->GetApVolume(it->first) != volumeMax) { + audioEffectVolume_->SetApVolume(it->first, volumeMax); + std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); + if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { + return ERROR; + } + auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; + if (audioEffectChain == nullptr) { + return ERROR; + } + AUDIO_INFO_LOG("set ap volume: %{public}d sceneType: %{public}s", volumeMax, it->first.c_str()); + int32_t ret = audioEffectChain->SetVolume(audioEffectVolume_->GetApVolume(it->first)); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap volume failed"); + } + } + } + return SUCCESS; +} + +int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationState) +{ + std::lock_guard lock(dynamicMutex_); + AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectRotation != nullptr, ERROR, "null audioEffectRotation"); + if (offloadEnabled_) { + // send rotation to dsp + if (audioEffectRotation->GetRotation() != rotationState) { + AUDIO_DEBUG_LOG("rotationState change, previous state: %{public}d, new state: %{public}d", + rotationState, audioEffectRotation->GetRotation()); + audioEffectRotation->SetRotation(rotationState); + effectHdiInput[0] = HDI_ROTATION; + effectHdiInput[1] = rotationState; + AUDIO_INFO_LOG("set hdi rotation: %{public}d", effectHdiInput[1]); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi rotation failed"); + } + } else { + // send rotation to ap + if (audioEffectRotation->GetRotation() != rotationState) { + AUDIO_DEBUG_LOG("rotationState change, previous state: %{public}d, new state: %{public}d", + rotationState, audioEffectRotation->GetRotation()); + } + for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { + std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); + if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { + return ERROR; + } + auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; + if (audioEffectChain == nullptr) { + return ERROR; + } + int32_t ret = audioEffectChain->SetRotation(audioEffectRotation->GetRotation()); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap rotation failed"); + } + } + return SUCCESS; +} + int32_t AudioEffectChainManager::UpdateMultichannelConfig(const std::string &sceneType) { std::lock_guard lock(dynamicMutex_); @@ -1091,9 +1268,9 @@ int32_t AudioEffectChainManager::UpdateSpatializationState(AudioSpatializationSt memset_s(static_cast(effectHdiInput), sizeof(effectHdiInput), 0, sizeof(effectHdiInput)); if (spatializationEnabled_) { effectHdiInput[0] = HDI_INIT; - int32_t ret = audioEffectHdi_->UpdateHdiState(effectHdiInput); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); if (ret != 0) { - AUDIO_ERR_LOG("set hdi init failed, backup spatialization entered"); + AUDIO_WARNING_LOG("set hdi init failed, backup spatialization entered"); offloadEnabled_ = false; } else { AUDIO_INFO_LOG("set hdi init succeeded, normal spatialization entered"); @@ -1103,9 +1280,9 @@ int32_t AudioEffectChainManager::UpdateSpatializationState(AudioSpatializationSt } else { effectHdiInput[0] = HDI_DESTROY; AUDIO_INFO_LOG("set hdi destroy."); - int32_t ret = audioEffectHdi_->UpdateHdiState(effectHdiInput); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); if (ret != 0) { - AUDIO_ERR_LOG("set hdi destroy failed"); + AUDIO_WARNING_LOG("set hdi destroy failed"); } offloadEnabled_ = false; RecoverAllChains(); @@ -1180,7 +1357,8 @@ int32_t AudioEffectChainManager::SessionInfoMapAdd(std::string sceneType, std::s SceneTypeToSessionIDMap_[sceneType].insert(sessionID); SessionIDToEffectInfoMap_[sessionID] = info; } else if (SessionIDToEffectInfoMap_[sessionID].sceneMode != info.sceneMode || - SessionIDToEffectInfoMap_[sessionID].spatializationEnabled != info.spatializationEnabled) { + SessionIDToEffectInfoMap_[sessionID].spatializationEnabled != info.spatializationEnabled || + SessionIDToEffectInfoMap_[sessionID].volume != info.volume) { SessionIDToEffectInfoMap_[sessionID] = info; } else { return ERROR; @@ -1225,7 +1403,7 @@ int32_t AudioEffectChainManager::SetHdiParam(std::string sceneType, std::string effectHdiInput[0] = HDI_BYPASS; effectHdiInput[1] = enabled == true ? 0 : 1; AUDIO_INFO_LOG("set hdi bypass: %{public}d", effectHdiInput[1]); - int32_t ret = audioEffectHdi_->UpdateHdiState(effectHdiInput); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); if (ret != 0) { AUDIO_WARNING_LOG("set hdi bypass failed"); return ret; @@ -1236,7 +1414,7 @@ int32_t AudioEffectChainManager::SetHdiParam(std::string sceneType, std::string effectHdiInput[HDI_ROOM_MODE_INDEX_TWO] = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); AUDIO_INFO_LOG("set hdi room mode sceneType: %{public}d, effectMode: %{public}d", effectHdiInput[1], effectHdiInput[HDI_ROOM_MODE_INDEX_TWO]); - ret = audioEffectHdi_->UpdateHdiState(effectHdiInput); + ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); if (ret != 0) { AUDIO_WARNING_LOG("set hdi room mode failed"); return ret; @@ -1244,88 +1422,28 @@ int32_t AudioEffectChainManager::SetHdiParam(std::string sceneType, std::string return SUCCESS; } -AudioEffectHdi::AudioEffectHdi() -{ - AUDIO_INFO_LOG("AudioEffectHdi constructor!"); - memset_s(static_cast(input), sizeof(input), 0, sizeof(input)); - memset_s(static_cast(output), sizeof(output), 0, sizeof(output)); - replyLen = GET_HDI_BUFFER_LEN; -} - -AudioEffectHdi::~AudioEffectHdi() -{ - AUDIO_INFO_LOG("AudioEffectHdi destructor!"); -} - -void AudioEffectHdi::InitHdi() -{ - hdiModel_ = IEffectModelGet(false); - if (hdiModel_ == nullptr) { - AUDIO_WARNING_LOG("IEffectModelGet failed"); - hdiControl_ = nullptr; - return; - } - libName = strdup("libspatialization_processing_dsp"); - effectId = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966gg"); - EffectInfo info = { - .libName = &libName[0], - .effectId = &effectId[0], - .ioDirection = 1, - }; - ControllerId controllerId; - int32_t ret = hdiModel_->CreateEffectController(hdiModel_, &info, &hdiControl_, &controllerId); - if ((ret != 0) || (hdiControl_ == nullptr)) { - AUDIO_WARNING_LOG("hdi init failed"); - hdiControl_ = nullptr; - return; - } - - uint32_t replyLen = GET_HDI_BUFFER_LEN; - input[0] = HDI_BLUETOOTH_MODE; - input[1] = 1; - AUDIO_INFO_LOG("set hdi bluetooth mode."); - ret = hdiControl_->SendCommand(hdiControl_, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, output, &replyLen); - if (ret != 0) { - AUDIO_WARNING_LOG("set hdi bluetooth mode failed"); - hdiControl_ = nullptr; - return; - } -} - -int32_t AudioEffectHdi::UpdateHdiState(int8_t *effectHdiInput) -{ - if (hdiControl_ == nullptr) { - AUDIO_WARNING_LOG("hdiControl_ is nullptr."); - return ERROR; - } - memcpy_s(static_cast(input), sizeof(input), static_cast(effectHdiInput), sizeof(input)); - uint32_t replyLen = GET_HDI_BUFFER_LEN; - int32_t ret = hdiControl_->SendCommand(hdiControl_, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, output, &replyLen); - if (ret != 0) { - AUDIO_WARNING_LOG("hdi send command failed"); - return ret; - } - return ret; -} - void AudioEffectChainManager::UpdateSensorState() { effectHdiInput[0] = HDI_HEAD_MODE; effectHdiInput[1] = headTrackingEnabled_ == true ? 1 : 0; AUDIO_INFO_LOG("set hdi head mode: %{public}d", effectHdiInput[1]); - int32_t ret = audioEffectHdi_->UpdateHdiState(effectHdiInput); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); if (ret != 0) { - AUDIO_ERR_LOG("set hdi head mode failed"); + AUDIO_WARNING_LOG("set hdi head mode failed"); } if (headTrackingEnabled_) { #ifdef SENSOR_ENABLE if (offloadEnabled_) { headTracker_->SensorInit(); - headTracker_->SensorSetConfig(DSP_SPATIALIZER_ENGINE); + ret = headTracker_->SensorSetConfig(DSP_SPATIALIZER_ENGINE); } else { headTracker_->SensorInit(); - headTracker_->SensorSetConfig(ARM_SPATIALIZER_ENGINE); + ret = headTracker_->SensorSetConfig(ARM_SPATIALIZER_ENGINE); + } + + if (ret != 0) { + AUDIO_ERR_LOG("SensorSetConfig error!"); } if (headTracker_->SensorActive() != 0) { diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp new file mode 100644 index 0000000000..f37cced61b --- /dev/null +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "audio_effect.h" +#include "audio_effect_hdi_param.h" +#include "audio_errors.h" +#include "audio_log.h" +#include "securec.h" + +namespace OHOS { +namespace AudioStandard { +AudioEffectHdiParam::AudioEffectHdiParam() +{ + AUDIO_INFO_LOG("AudioEffectHdiParam constructor."); + libHdiControls_.clear(); + memset_s(static_cast(input), sizeof(input), 0, sizeof(input)); + memset_s(static_cast(output), sizeof(output), 0, sizeof(output)); + replyLen = GET_HDI_BUFFER_LEN; + hdiModel_ = nullptr; +} + +AudioEffectHdiParam::~AudioEffectHdiParam() +{ + AUDIO_INFO_LOG("AudioEffectHdiParam destructor!"); +} + +void AudioEffectHdiParam::CreateHdiControl() +{ + // todo read from vendor/huawei/... + libName = strdup("libspatialization_processing_dsp"); + effectId = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966gg"); + EffectInfo info = { + .libName = &libName[0], + .effectId = &effectId[0], + .ioDirection = 1, + }; + ControllerId controllerId; + IEffectControl *hdiControl = nullptr; + int32_t ret = hdiModel_->CreateEffectController(hdiModel_, &info, &hdiControl, &controllerId); + if ((ret != 0) || (hdiControl == nullptr)) { + AUDIO_WARNING_LOG("hdi init failed"); + } else { + libHdiControls_.emplace_back(hdiControl); + } + + return; +} + +void AudioEffectHdiParam::InitHdi() +{ + hdiModel_ = IEffectModelGet(false); + if (hdiModel_ == nullptr) { + AUDIO_WARNING_LOG("IEffectModelGet failed"); + return; + } + + CreateHdiControl(); +} + +int32_t AudioEffectHdiParam::UpdateHdiState(int8_t *effectHdiInput) +{ + for (IEffectControl *hdiControl : libHdiControls_) { + if (hdiControl == nullptr) { + AUDIO_WARNING_LOG("hdiControl is nullptr."); + return ERROR; + } + memcpy_s(static_cast(input), sizeof(input), static_cast(effectHdiInput), sizeof(input)); + uint32_t replyLen = GET_HDI_BUFFER_LEN; + int32_t ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, output, &replyLen); + if (ret != 0) { + AUDIO_WARNING_LOG("hdi send command failed"); + return ret; + } + } + return SUCCESS; +} +} // namespace AudioStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp new file mode 100644 index 0000000000..142c954c62 --- /dev/null +++ b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "audio_effect_chain_adapter.h" +#include "audio_effect_rotation.h" +#include "audio_log.h" + +namespace OHOS { +namespace AudioStandard { +AudioEffectRotation::AudioEffectRotation() { + AUDIO_INFO_LOG("AudioEffectRotation created!"); + rotationState_ = 0; +} + +AudioEffectRotation::~AudioEffectRotation() { + AUDIO_INFO_LOG("AudioEffectRotation destroyed!"); +} + +AudioEffectRotation *AudioEffectRotation::GetInstance() +{ + static AudioEffectRotation audioEffectRotation; + return &audioEffectRotation; +} + +void AudioEffectRotation::Init() { + AUDIO_DEBUG_LOG("Call RegisterDisplayListener."); + audioRotationListener_ = new AudioRotationListener(); + Rosen::DisplayManager::GetInstance().RegisterDisplayListener(audioRotationListener_); +} + +void AudioEffectRotation::SetRotation(uint32_t rotationState) +{ + rotationState_ = rotationState; +} + +uint32_t AudioEffectRotation::GetRotation() +{ + return rotationState_; +} + +void AudioEffectRotation::OnCreate(Rosen::DisplayId displayId) { + AUDIO_DEBUG_LOG("Onchange displayId: %{public}llu.", displayId); +} + +void AudioEffectRotation::OnDestroy(Rosen::DisplayId displayId) { + AUDIO_DEBUG_LOG("OnDestroy displayId: %{public}llu.", displayId); +} + +void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) { + AUDIO_DEBUG_LOG("Onchange displayId: %{public}llu.", displayId); + // get display + auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); + if (!display) { + AUDIO_WARNING_LOG("Get display by displayId: %{public}llu failed.", displayId); + return; + } + // get rotation + Rosen::Rotation newRotationState= display->GetRotation(); + AUDIO_DEBUG_LOG("Onchange rotationState: %{public}u.", static_cast(newRotationState)); + EffectChainManagerRotationUpdate(static_cast(newRotationState)); +} + + +} // namespace AudioStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_effect_volume.cpp b/frameworks/native/audioeffect/src/audio_effect_volume.cpp new file mode 100644 index 0000000000..7111e9bbf5 --- /dev/null +++ b/frameworks/native/audioeffect/src/audio_effect_volume.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "audio_effect_volume.h" +#include "audio_log.h" + +namespace OHOS { +namespace AudioStandard { +AudioEffectVolume::AudioEffectVolume() +{ + SceneTypeToVolumeMap_.clear(); + dspVolume_ = 0; +} + +AudioEffectVolume::~AudioEffectVolume() +{ + AUDIO_INFO_LOG("AudioEffectVolume destructor!"); +} + +void AudioEffectVolume::SetApVolume(std::string sceneType, uint32_t volume) +{ + if (!SceneTypeToVolumeMap_.count(sceneType)) { + SceneTypeToVolumeMap_.insert(std::make_pair(sceneType, volume)); + } else { + SceneTypeToVolumeMap_[sceneType] = volume; + } +} + +uint32_t AudioEffectVolume::GetApVolume(std::string sceneType) +{ + if (!SceneTypeToVolumeMap_.count(sceneType)) { + return 0; + } else { + return SceneTypeToVolumeMap_[sceneType]; + } +} + +void AudioEffectVolume::SetDspVolume(uint32_t volume) +{ + AUDIO_DEBUG_LOG("setDspVolume: %{public}u", volume); + dspVolume_ = volume; +} + +uint32_t AudioEffectVolume::GetDspVolume() +{ + return dspVolume_; +} +} // namespace AudioStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index 9a0ef23405..251e851d0e 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -146,7 +146,7 @@ struct Userdata { size_t processSize; char *sinkSceneType; char *sinkSceneMode; - bool spatialEnabled; + bool hdiEffectEnabled; pthread_mutex_t mutexPa; pthread_mutex_t mutexPa2; pthread_rwlock_t rwlockSleep; @@ -2590,7 +2590,7 @@ static void SetHdiParam(struct Userdata *userdata) int sessionIDMax = -1; char *sinkSceneTypeMax = ""; char *sinkSceneModeMax = ""; - bool spatialEnabledMax = false; + bool hdiEffectEnabledMax = false; while ((i = pa_hashmap_iterate(userdata->sink->thread_info.inputs, &state, NULL))) { pa_sink_input_assert_ref(i); const char *clientUid = pa_proplist_gets(i->proplist, "stream.client.uid"); @@ -2604,13 +2604,15 @@ static void SetHdiParam(struct Userdata *userdata) const char *sinkSessionStr = pa_proplist_gets(i->proplist, "stream.sessionID"); bool spatializationEnabled = pa_safe_streq(sinkSpatialization, "1") ? true : false; bool effectEnabled = pa_safe_streq(sinkSceneMode, "EFFECT_DEFAULT") ? true : false; - bool spatialEnabled = spatializationEnabled && effectEnabled; + bool hdiEffectEnabled = spatializationEnabled && effectEnabled; int sessionID = atoi(sinkSessionStr == NULL ? "-1" : sinkSessionStr); - if (sessionID > sessionIDMax && sinkSceneType && sinkSceneMode && sinkSpatialization) { - sessionIDMax = sessionID; - sinkSceneTypeMax = (char *)sinkSceneType; - sinkSceneModeMax = (char *)sinkSceneMode; - spatialEnabledMax = spatialEnabled; + if (sinkSceneType && sinkSceneMode && sinkSpatialization) { + if (sessionID > sessionIDMax) { + sessionIDMax = sessionID; + sinkSceneTypeMax = (char *)sinkSceneType; + sinkSceneModeMax = (char *)sinkSceneMode; + hdiEffectEnabledMax = hdiEffectEnabled; + } } } @@ -2621,12 +2623,12 @@ static void SetHdiParam(struct Userdata *userdata) if (!pa_safe_streq(userdata->sinkSceneType, sinkSceneTypeMax) || !pa_safe_streq(userdata->sinkSceneMode, sinkSceneModeMax) || - (userdata->spatialEnabled != spatialEnabledMax)) { - userdata->sinkSceneMode = sinkSceneModeMax; - userdata->sinkSceneType = sinkSceneTypeMax; - userdata->spatialEnabled = spatialEnabledMax; - EffectChainManagerSetHdiParam(userdata->sinkSceneType, userdata->sinkSceneMode, userdata->spatialEnabled); - } + (userdata->hdiEffectEnabled != hdiEffectEnabledMax)) { + userdata->sinkSceneMode = sinkSceneModeMax; + userdata->sinkSceneType = sinkSceneTypeMax; + userdata->hdiEffectEnabled = hdiEffectEnabledMax; + EffectChainManagerSetHdiParam(userdata->sinkSceneType, userdata->sinkSceneMode, userdata->hdiEffectEnabled); + } } static void ThreadFuncRendererTimerLoop(struct Userdata *u, int64_t *sleepForUsec) diff --git a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c index 3cae3497d7..5765bceb56 100644 --- a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c @@ -25,6 +25,7 @@ #include #include #include "audio_effect_chain_adapter.h" +#include "audio_log.h" #include "playback_capturer_adapter.h" pa_sink *PaHdiSinkNew(pa_module *m, pa_modargs *ma, const char *driver); @@ -89,6 +90,7 @@ static pa_hook_result_t SinkInputNewCb(pa_core *c, pa_sink_input *si) const uint32_t channels = si->sample_spec.channels; const char *channelLayout = pa_proplist_gets(si->proplist, "stream.channelLayout"); const char *spatializationEnabled = pa_proplist_gets(si->proplist, "spatialization.enabled"); + uint32_t volume = si->volume.values[0]; if (pa_safe_streq(deviceString, "remote")) { EffectChainManagerReleaseCb(sceneType, sessionID); return PA_HOOK_OK; @@ -106,15 +108,16 @@ static pa_hook_result_t SinkInputNewCb(pa_core *c, pa_sink_input *si) EffectChainManagerInitCb(sceneType); } EffectChainManagerCreateCb(sceneType, sessionID); - SessionInfoPack pack = {channels, channelLayout, sceneMode, spatializationEnabled}; + SessionInfoPack pack = {channels, channelLayout, sceneMode, spatializationEnabled, volume}; if (si->state == PA_SINK_INPUT_RUNNING && !EffectChainManagerAddSessionInfo(sceneType, sessionID, pack)) { EffectChainManagerMultichannelUpdate(sceneType); + // EffectChainManagerVolumeUpdate(); } } return PA_HOOK_OK; } -static pa_hook_result_t SinkInputUnlinkCb(pa_core *c, pa_sink_input *si) +static pa_hook_result_t SinkInputUnlinkCb(pa_core *c, pa_sink_input *si, void *u) { pa_assert(c); @@ -141,7 +144,7 @@ static pa_hook_result_t SinkInputUnlinkCb(pa_core *c, pa_sink_input *si) return PA_HOOK_OK; } -static pa_hook_result_t SourceOutputStateChangedCb(pa_core *c, pa_source_output *so) +static pa_hook_result_t SourceOutputStateChangedCb(pa_core *c, pa_source_output *so, void *u) { pa_assert(c); pa_assert(so); @@ -164,7 +167,7 @@ static pa_hook_result_t SourceOutputStateChangedCb(pa_core *c, pa_source_output return PA_HOOK_OK; } -static pa_hook_result_t SinkInputStateChangedCb(pa_core *c, pa_sink_input *si) +static pa_hook_result_t SinkInputStateChangedCb(pa_core *c, pa_sink_input *si, void *u) { pa_assert(c); pa_sink_input_assert_ref(si); @@ -177,9 +180,10 @@ static pa_hook_result_t SinkInputStateChangedCb(pa_core *c, pa_sink_input *si) const char *spatializationEnabled = pa_proplist_gets(si->proplist, "spatialization.enabled"); const char *clientUid = pa_proplist_gets(si->proplist, "stream.client.uid"); const char *bootUpMusic = "1003"; + uint32_t volume = si->volume.values[0]; if (si->state == PA_SINK_INPUT_RUNNING && si->sink && !pa_safe_streq(clientUid, bootUpMusic)) { - SessionInfoPack pack = {channels, channelLayout, sceneMode, spatializationEnabled}; + SessionInfoPack pack = {channels, channelLayout, sceneMode, spatializationEnabled, volume}; if (!EffectChainManagerAddSessionInfo(sceneType, sessionID, pack)) { EffectChainManagerMultichannelUpdate(sceneType); } @@ -194,6 +198,15 @@ static pa_hook_result_t SinkInputStateChangedCb(pa_core *c, pa_sink_input *si) return PA_HOOK_OK; } +static pa_hook_result_t SinkInputVolumeChangedCb(pa_core *c, pa_sink_input *si, void *u) { + AUDIO_DEBUG_LOG("volume changed."); + // todo test if work when stream create + const char *sessionID = pa_proplist_gets(si->proplist, "stream.sessionID"); + const uint32_t volume = si->volume.values[0]; + EffectChainManagerVolumeUpdate(sessionID, volume); + return PA_HOOK_OK; +} + int pa__init(pa_module *m) { pa_modargs *ma = NULL; @@ -216,6 +229,8 @@ int pa__init(pa_module *m) (pa_hook_cb_t)SourceOutputStateChangedCb, NULL); pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t)SinkInputStateChangedCb, NULL); + pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_VOLUME_CHANGED], PA_HOOK_LATE, + (pa_hook_cb_t)SinkInputVolumeChangedCb, NULL); pa_modargs_free(ma); -- Gitee From e225490eaa23b7d70ad6c3516801f707e80ea116 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Mon, 19 Feb 2024 10:37:17 +0800 Subject: [PATCH 02/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/include/audio_effect_chain_manager.h | 1 + frameworks/native/pulseaudio/modules/hdi/hdi_sink.c | 2 +- interfaces/inner_api/native/audiocommon/include/audio_effect.h | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 13644714d4..022b6f7bcb 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -105,6 +105,7 @@ public: AudioEffectConfig GetIoBufferConfig(); void InitEffectChain(); void SetHeadTrackingDisabled(); + uint32_t GetLatency(); int32_t SetVolume(uint32_t volume); int32_t SetRotation(uint32_t rotation); private: diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index 251e851d0e..ad530ef4a7 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -3357,7 +3357,7 @@ static void PaHdiSinkUserdataInit(struct Userdata *u) u->bufferAttr->numChanOut = u->ss.channels; u->sinkSceneMode = ""; u->sinkSceneType = ""; - u->spatialEnabled = false; + u->hdiEffectEnabled = false; } static pa_sink *PaHdiSinkInit(struct Userdata *u, pa_modargs *ma, const char *driver) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index a24b2e0edc..e0427f1e7a 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -44,6 +44,8 @@ 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_VOLUME = 7; +constexpr int32_t HDI_ROTATION = 8; enum AudioSpatialDeviceType { EARPHONE_TYPE_NONE = 0, -- Gitee From de094f4e14ba3fd3a3742164930244484ebea896 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Mon, 19 Feb 2024 11:48:49 +0800 Subject: [PATCH 03/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../src/audio_effect_chain_manager.cpp | 5 +++-- .../src/audio_effect_hdi_param.cpp | 3 ++- .../audioeffect/src/audio_effect_rotation.cpp | 20 ++++++++++++------- .../pulseaudio/modules/hdi/module_hdi_sink.c | 3 ++- services/audio_service/BUILD.gn | 1 + 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index f17ec65e1c..81de34f44d 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -499,7 +499,8 @@ int32_t AudioEffectChain::SetRotation(uint32_t rotation) *data++ = EFFECT_SET_PARAM; *data++ = static_cast(rotation); int32_t replyData = 0; - AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_TWO, effectParam}; + AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_TWO, + effectParam}; AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); delete[] effectParam; @@ -1130,7 +1131,7 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS SessionIDToEffectInfoMap_[sessionIDString].volume = volume; } } - if (offloadEnabled_){ + if (offloadEnabled_) { // update dsp volume AUDIO_DEBUG_LOG("send volume to dsp."); uint32_t volumeMax = 0; diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index f37cced61b..8529b15a6d 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -78,7 +78,8 @@ int32_t AudioEffectHdiParam::UpdateHdiState(int8_t *effectHdiInput) } memcpy_s(static_cast(input), sizeof(input), static_cast(effectHdiInput), sizeof(input)); uint32_t replyLen = GET_HDI_BUFFER_LEN; - int32_t ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, output, &replyLen); + int32_t ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, + output, &replyLen); if (ret != 0) { AUDIO_WARNING_LOG("hdi send command failed"); return ret; diff --git a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp index 142c954c62..f418f21b30 100644 --- a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp @@ -19,12 +19,14 @@ namespace OHOS { namespace AudioStandard { -AudioEffectRotation::AudioEffectRotation() { +AudioEffectRotation::AudioEffectRotation() +{ AUDIO_INFO_LOG("AudioEffectRotation created!"); rotationState_ = 0; } -AudioEffectRotation::~AudioEffectRotation() { +AudioEffectRotation::~AudioEffectRotation() +{ AUDIO_INFO_LOG("AudioEffectRotation destroyed!"); } @@ -34,7 +36,8 @@ AudioEffectRotation *AudioEffectRotation::GetInstance() return &audioEffectRotation; } -void AudioEffectRotation::Init() { +void AudioEffectRotation::Init() +{ AUDIO_DEBUG_LOG("Call RegisterDisplayListener."); audioRotationListener_ = new AudioRotationListener(); Rosen::DisplayManager::GetInstance().RegisterDisplayListener(audioRotationListener_); @@ -50,15 +53,18 @@ uint32_t AudioEffectRotation::GetRotation() return rotationState_; } -void AudioEffectRotation::OnCreate(Rosen::DisplayId displayId) { +void AudioEffectRotation::OnCreate(Rosen::DisplayId displayId) +{ AUDIO_DEBUG_LOG("Onchange displayId: %{public}llu.", displayId); } -void AudioEffectRotation::OnDestroy(Rosen::DisplayId displayId) { +void AudioEffectRotation::OnDestroy(Rosen::DisplayId displayId) +{ AUDIO_DEBUG_LOG("OnDestroy displayId: %{public}llu.", displayId); } -void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) { +void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) +{ AUDIO_DEBUG_LOG("Onchange displayId: %{public}llu.", displayId); // get display auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); @@ -67,7 +73,7 @@ void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) { return; } // get rotation - Rosen::Rotation newRotationState= display->GetRotation(); + Rosen::Rotation newRotationState = display->GetRotation(); AUDIO_DEBUG_LOG("Onchange rotationState: %{public}u.", static_cast(newRotationState)); EffectChainManagerRotationUpdate(static_cast(newRotationState)); } diff --git a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c index 5765bceb56..ffe90fade1 100644 --- a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c @@ -198,7 +198,8 @@ static pa_hook_result_t SinkInputStateChangedCb(pa_core *c, pa_sink_input *si, v return PA_HOOK_OK; } -static pa_hook_result_t SinkInputVolumeChangedCb(pa_core *c, pa_sink_input *si, void *u) { +static pa_hook_result_t SinkInputVolumeChangedCb(pa_core *c, pa_sink_input *si, void *u) +{ AUDIO_DEBUG_LOG("volume changed."); // todo test if work when stream create const char *sessionID = pa_proplist_gets(si->proplist, "stream.sessionID"); diff --git a/services/audio_service/BUILD.gn b/services/audio_service/BUILD.gn index cd3f6b7327..aff7a1f8d0 100644 --- a/services/audio_service/BUILD.gn +++ b/services/audio_service/BUILD.gn @@ -384,6 +384,7 @@ ohos_shared_library("audio_service") { "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libdm", ] if (sensor_enable == true) { -- Gitee From 0f03fa9d7eb2869b947123484bb4d0c41e93e138 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 20 Feb 2024 19:53:29 +0800 Subject: [PATCH 04/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../include/audio_effect_chain_manager.h | 4 +- .../include/audio_effect_rotation.h | 4 - .../audioeffect/include/audio_effect_volume.h | 1 + .../src/audio_effect_chain_manager.cpp | 75 ++++++++----------- .../audioeffect/src/audio_effect_volume.cpp | 6 ++ 5 files changed, 40 insertions(+), 50 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 022b6f7bcb..11ffc5de39 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -44,6 +44,7 @@ namespace AudioStandard { const uint32_t NUM_SET_EFFECT_PARAM_TWO = 2; const uint32_t NUM_SET_EFFECT_PARAM_THREE = 3; +const uint32_t NUM_SET_EFFECT_PARAM_FIVE = 5; const uint32_t DEFAULT_FRAMELEN = 1440; const uint32_t DEFAULT_SAMPLE_RATE = 48000; const uint32_t DEFAULT_NUM_CHANNEL = STEREO; @@ -106,8 +107,7 @@ public: void InitEffectChain(); void SetHeadTrackingDisabled(); uint32_t GetLatency(); - int32_t SetVolume(uint32_t volume); - int32_t SetRotation(uint32_t rotation); + int32_t SetEffectPararm(); private: std::mutex reloadMutex; std::string sceneType; diff --git a/frameworks/native/audioeffect/include/audio_effect_rotation.h b/frameworks/native/audioeffect/include/audio_effect_rotation.h index c221348e64..310ac26ba1 100644 --- a/frameworks/native/audioeffect/include/audio_effect_rotation.h +++ b/frameworks/native/audioeffect/include/audio_effect_rotation.h @@ -34,10 +34,6 @@ public: private: class AudioRotationListener : public OHOS::Rosen::DisplayManager::IDisplayListener { public: - // AudioRotationListener(const std::shared_ptr &audioEffectRotation) - // { - // audioEffectRotation_ = audioEffectRotation; - // } void OnCreate(Rosen::DisplayId displayId) override { AudioEffectRotation *audioEffectRotation = GetInstance(); diff --git a/frameworks/native/audioeffect/include/audio_effect_volume.h b/frameworks/native/audioeffect/include/audio_effect_volume.h index 10d0347e98..617a120476 100644 --- a/frameworks/native/audioeffect/include/audio_effect_volume.h +++ b/frameworks/native/audioeffect/include/audio_effect_volume.h @@ -26,6 +26,7 @@ class AudioEffectVolume { public: AudioEffectVolume(); ~AudioEffectVolume(); + static AudioEffectRotation *GetInstance(); void SetApVolume(std::string sceneType, uint32_t volume); uint32_t GetApVolume(std::string sceneType); void SetDspVolume(uint32_t volume); diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 81de34f44d..7b65d0e9e1 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -464,42 +464,27 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr libHandles.emplace_back(libHandle); } -int32_t AudioEffectChain::SetVolume(uint32_t volume) +int32_t AudioEffectChain::SetEffectParam(uint32_t rotation) { std::lock_guard lock(reloadMutex); for (AudioEffectHandle handle: standByEffectHandles) { AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + - NUM_SET_EFFECT_PARAM_TWO * sizeof(int32_t)]; + NUM_SET_EFFECT_PARAM_FIVE * sizeof(int32_t)]; effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; int32_t *data = &(effectParam->data[0]); *data++ = EFFECT_SET_PARAM; - *data++ = static_cast(volume); + *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType); + *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); + AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); + CHECK_AND_RETURN_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + *data++ = audioEffectRotation->GetRotation(); + AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); + CHECK_AND_RETURN_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); + *data++ = audioEffectVolume->GetApVolume(sceneType); int32_t replyData = 0; - AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_TWO, effectParam}; - AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; - int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); - delete[] effectParam; - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set volume EFFECT_CMD_SET_PARAM fail"); - } - return SUCCESS; -} - -int32_t AudioEffectChain::SetRotation(uint32_t rotation) -{ - std::lock_guard lock(reloadMutex); - for (AudioEffectHandle handle: standByEffectHandles) { - AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + - NUM_SET_EFFECT_PARAM_TWO * sizeof(int32_t)]; - effectParam->status = 0; - effectParam->paramSize = sizeof(int32_t); - effectParam->valueSize = 0; - int32_t *data = &(effectParam->data[0]); - *data++ = EFFECT_SET_PARAM; - *data++ = static_cast(rotation); - int32_t replyData = 0; - AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_TWO, + AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_FIVE, effectParam}; AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); @@ -1131,6 +1116,7 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS SessionIDToEffectInfoMap_[sessionIDString].volume = volume; } } + AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); if (offloadEnabled_) { // update dsp volume AUDIO_DEBUG_LOG("send volume to dsp."); @@ -1143,8 +1129,8 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS } } // send volume to dsp - if (audioEffectVolume_->GetDspVolume() != volumeMax) { - audioEffectVolume_->SetDspVolume(volumeMax); + if (audioEffectVolume->GetDspVolume() != volumeMax) { + audioEffectVolume->SetDspVolume(volumeMax); effectHdiInput[0] = HDI_VOLUME; effectHdiInput[1] = volumeMax; AUDIO_INFO_LOG("set hdi volume: %{public}d", effectHdiInput[1]); @@ -1161,8 +1147,8 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; volumeMax = info.volume > volumeMax ? info.volume : volumeMax; } - if (audioEffectVolume_->GetApVolume(it->first) != volumeMax) { - audioEffectVolume_->SetApVolume(it->first, volumeMax); + if (audioEffectVolume->GetApVolume(it->first) != volumeMax) { + audioEffectVolume->SetApVolume(it->first, volumeMax); std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { return ERROR; @@ -1172,7 +1158,7 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS return ERROR; } AUDIO_INFO_LOG("set ap volume: %{public}d sceneType: %{public}s", volumeMax, it->first.c_str()); - int32_t ret = audioEffectChain->SetVolume(audioEffectVolume_->GetApVolume(it->first)); + int32_t ret = audioEffectChain->SetEffectParam(); CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap volume failed"); } } @@ -1188,7 +1174,7 @@ int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationSta if (offloadEnabled_) { // send rotation to dsp if (audioEffectRotation->GetRotation() != rotationState) { - AUDIO_DEBUG_LOG("rotationState change, previous state: %{public}d, new state: %{public}d", + AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", rotationState, audioEffectRotation->GetRotation()); audioEffectRotation->SetRotation(rotationState); effectHdiInput[0] = HDI_ROTATION; @@ -1200,20 +1186,21 @@ int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationSta } else { // send rotation to ap if (audioEffectRotation->GetRotation() != rotationState) { - AUDIO_DEBUG_LOG("rotationState change, previous state: %{public}d, new state: %{public}d", + AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", rotationState, audioEffectRotation->GetRotation()); - } - for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { - std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); - if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { - return ERROR; - } - auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; - if (audioEffectChain == nullptr) { - return ERROR; + audioEffectRotation->SetRotation(rotationState); + for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { + std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); + if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { + return ERROR; + } + auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; + if (audioEffectChain == nullptr) { + return ERROR; + } + int32_t ret = audioEffectChain->SetEffectParam(); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap rotation failed"); } - int32_t ret = audioEffectChain->SetRotation(audioEffectRotation->GetRotation()); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap rotation failed"); } } return SUCCESS; diff --git a/frameworks/native/audioeffect/src/audio_effect_volume.cpp b/frameworks/native/audioeffect/src/audio_effect_volume.cpp index 7111e9bbf5..da80c2ac34 100644 --- a/frameworks/native/audioeffect/src/audio_effect_volume.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_volume.cpp @@ -29,6 +29,12 @@ AudioEffectVolume::~AudioEffectVolume() AUDIO_INFO_LOG("AudioEffectVolume destructor!"); } +AudioEffectVolume *AudioEffectVolume::GetInstance() +{ + static AudioEffectVolume audioEffectVolume; + return &audioEffectVolume; +} + void AudioEffectVolume::SetApVolume(std::string sceneType, uint32_t volume) { if (!SceneTypeToVolumeMap_.count(sceneType)) { -- Gitee From e35c01346a7f477365a9f827cdad016a65c4869e Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 20 Feb 2024 20:07:24 +0800 Subject: [PATCH 05/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 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 7b65d0e9e1..4313bf98a7 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -288,11 +288,12 @@ int32_t EffectChainManagerAddSessionInfo(const char *sceneType, const char *sess sessionEffectInfo info; info.sceneMode = sceneModeString; + info.sceneType = sceneTypeString; info.channels = pack.channels; info.channelLayout = channelLayoutNum; info.spatializationEnabled = spatializationEnabledString; info.volume = pack.volume; - return audioEffectChainManager->SessionInfoMapAdd(sceneTypeString, sessionIDString, info); + return audioEffectChainManager->SessionInfoMapAdd(sessionIDString, info); } int32_t EffectChainManagerDeleteSessionInfo(const char *sceneType, const char *sessionID) -- Gitee From c98a2dd19ed79947cf7a5f803bc564d8f1521bb2 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 20 Feb 2024 20:30:36 +0800 Subject: [PATCH 06/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- frameworks/native/audioeffect/BUILD.gn | 2 +- .../include/audio_effect_chain_manager.h | 2 - .../src/audio_effect_chain_manager.cpp | 169 ++++++++++-------- .../src/audio_effect_hdi_param.cpp | 2 +- .../pulseaudio/modules/hdi/module_hdi_sink.c | 1 - 5 files changed, 98 insertions(+), 78 deletions(-) diff --git a/frameworks/native/audioeffect/BUILD.gn b/frameworks/native/audioeffect/BUILD.gn index 327df99422..5ed5f0082e 100644 --- a/frameworks/native/audioeffect/BUILD.gn +++ b/frameworks/native/audioeffect/BUILD.gn @@ -58,10 +58,10 @@ ohos_shared_library("audio_effect") { sources = [ "src/audio_effect_chain_manager.cpp", - "src/audio_head_tracker.cpp", "src/audio_effect_hdi_param.cpp", "src/audio_effect_rotation.cpp", "src/audio_effect_volume.cpp", + "src/audio_head_tracker.cpp", ] deps = [ "$pulseaudio_build_path/src/pulse:pulse" ] diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 61f1faf2a6..535e0b6344 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -189,8 +189,6 @@ private: #endif std::shared_ptr audioEffectHdiParam_; - std::shared_ptr audioEffectVolume_; - std::shared_ptr audioEffectRotation_; int8_t effectHdiInput[SEND_HDI_COMMAND_LEN]; }; } // namespace AudioStandard diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 424338a496..2e8875808b 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -709,8 +709,6 @@ AudioEffectChainManager::AudioEffectChainManager() #endif audioEffectHdiParam_ = std::make_shared(); - audioEffectVolume_ = std::make_shared(); - // audioEffectRotation_ = std::make_shared(); memset_s(static_cast(effectHdiInput), sizeof(effectHdiInput), 0, sizeof(effectHdiInput)); } @@ -888,7 +886,6 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vectorInit(); AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); CHECK_AND_RETURN_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); audioEffectRotation->Init(); @@ -1106,6 +1103,59 @@ void AudioEffectChainManager::Dump() } } +int32_t AudioEffectChainManager::EffectDspVolumeUpdate() +{ + // update dsp volume + AUDIO_DEBUG_LOG("send volume to dsp."); + uint32_t volumeMax = 0; + for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { + std::set sessions = SceneTypeToSessionIDMap_[it->first]; + for (auto s = sessions.begin(); s != sessions.end(); s++) { + sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; + volumeMax = info.volume > volumeMax ? info.volume : volumeMax; + } + } + // send volume to dsp + if (audioEffectVolume->GetDspVolume() != volumeMax) { + audioEffectVolume->SetDspVolume(volumeMax); + effectHdiInput[0] = HDI_VOLUME; + effectHdiInput[1] = volumeMax; + AUDIO_INFO_LOG("set hdi volume: %{public}d", effectHdiInput[1]); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi volume failed"); + } + return SUCCESS; +} + +int32_t AudioEffectChainManager::EffectApVolumeUpdate() +{ + // send to ap + AUDIO_DEBUG_LOG("send volume to ap."); + for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { + uint32_t volumeMax = 0; + std::set sessions = SceneTypeToSessionIDMap_[it->first]; + for (auto s = sessions.begin(); s != sessions.end(); s++) { + sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; + volumeMax = info.volume > volumeMax ? info.volume : volumeMax; + } + if (audioEffectVolume->GetApVolume(it->first) != volumeMax) { + audioEffectVolume->SetApVolume(it->first, volumeMax); + std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); + if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { + return ERROR; + } + auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; + if (audioEffectChain == nullptr) { + return ERROR; + } + AUDIO_INFO_LOG("set ap volume: %{public}d sceneType: %{public}s", volumeMax, it->first.c_str()); + int32_t ret = audioEffectChain->SetEffectParam(); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap volume failed"); + } + } + return SUCCESS; +} + int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDString, const uint32_t volume) { std::lock_guard lock(dynamicMutex_); @@ -1115,54 +1165,53 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS SessionIDToEffectInfoMap_[sessionIDString].volume = volume; } } + int32_t ret; AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); if (offloadEnabled_) { - // update dsp volume - AUDIO_DEBUG_LOG("send volume to dsp."); - uint32_t volumeMax = 0; - for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { - std::set sessions = SceneTypeToSessionIDMap_[it->first]; - for (auto s = sessions.begin(); s != sessions.end(); s++) { - sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; - volumeMax = info.volume > volumeMax ? info.volume : volumeMax; - } - } - // send volume to dsp - if (audioEffectVolume->GetDspVolume() != volumeMax) { - audioEffectVolume->SetDspVolume(volumeMax); - effectHdiInput[0] = HDI_VOLUME; - effectHdiInput[1] = volumeMax; - AUDIO_INFO_LOG("set hdi volume: %{public}d", effectHdiInput[1]); - int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi volume failed"); - } + ret = EffectDspVolumeUpdate(); } else { - // send to ap - AUDIO_DEBUG_LOG("send volume to ap."); + ret = EffectApVolumeUpdate(); + } + return SUCCESS; +} + +int32_t AudioEffectChainManager::EffectDspRotationUpdate() +{ + // send rotation to dsp + if (audioEffectRotation->GetRotation() != rotationState) { + AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", + rotationState, audioEffectRotation->GetRotation()); + audioEffectRotation->SetRotation(rotationState); + effectHdiInput[0] = HDI_ROTATION; + effectHdiInput[1] = rotationState; + AUDIO_INFO_LOG("set hdi rotation: %{public}d", effectHdiInput[1]); + int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi rotation failed"); + } + return SUCCESS; +} + +int32_t AudioEffectChainManager::EffectApRotationUpdate() +{ + // send rotation to ap + if (audioEffectRotation->GetRotation() != rotationState) { + AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", + rotationState, audioEffectRotation->GetRotation()); + audioEffectRotation->SetRotation(rotationState); for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { - uint32_t volumeMax = 0; - std::set sessions = SceneTypeToSessionIDMap_[it->first]; - for (auto s = sessions.begin(); s != sessions.end(); s++) { - sessionEffectInfo info = SessionIDToEffectInfoMap_[*s]; - volumeMax = info.volume > volumeMax ? info.volume : volumeMax; + std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); + if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { + return ERROR; } - if (audioEffectVolume->GetApVolume(it->first) != volumeMax) { - audioEffectVolume->SetApVolume(it->first, volumeMax); - std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); - if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { - return ERROR; - } - auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; - if (audioEffectChain == nullptr) { - return ERROR; - } - AUDIO_INFO_LOG("set ap volume: %{public}d sceneType: %{public}s", volumeMax, it->first.c_str()); - int32_t ret = audioEffectChain->SetEffectParam(); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap volume failed"); + auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; + if (audioEffectChain == nullptr) { + return ERROR; } + int32_t ret = audioEffectChain->SetEffectParam(); + CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap rotation failed"); } } - return SUCCESS; + return ret; } int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationState) @@ -1170,39 +1219,13 @@ int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationSta std::lock_guard lock(dynamicMutex_); AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); CHECK_AND_RETURN_RET_LOG(audioEffectRotation != nullptr, ERROR, "null audioEffectRotation"); + int32_t ret; if (offloadEnabled_) { - // send rotation to dsp - if (audioEffectRotation->GetRotation() != rotationState) { - AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", - rotationState, audioEffectRotation->GetRotation()); - audioEffectRotation->SetRotation(rotationState); - effectHdiInput[0] = HDI_ROTATION; - effectHdiInput[1] = rotationState; - AUDIO_INFO_LOG("set hdi rotation: %{public}d", effectHdiInput[1]); - int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi rotation failed"); - } + ret = EffectDspRotationUpdate; } else { - // send rotation to ap - if (audioEffectRotation->GetRotation() != rotationState) { - AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", - rotationState, audioEffectRotation->GetRotation()); - audioEffectRotation->SetRotation(rotationState); - for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { - std::string sceneTypeAndDeviceKey = it->first + "_&_" + GetDeviceTypeName(); - if (!SceneTypeToEffectChainMap_.count(sceneTypeAndDeviceKey)) { - return ERROR; - } - auto *audioEffectChain = SceneTypeToEffectChainMap_[sceneTypeAndDeviceKey]; - if (audioEffectChain == nullptr) { - return ERROR; - } - int32_t ret = audioEffectChain->SetEffectParam(); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap rotation failed"); - } - } + ret = EffectApRotationUpdate; } - return SUCCESS; + return ret; } int32_t AudioEffectChainManager::UpdateMultichannelConfig(const std::string &sceneType) diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index 8529b15a6d..878f50a8a8 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -38,7 +38,7 @@ AudioEffectHdiParam::~AudioEffectHdiParam() void AudioEffectHdiParam::CreateHdiControl() { - // todo read from vendor/huawei/... + // todo read from vendor/... libName = strdup("libspatialization_processing_dsp"); effectId = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966gg"); EffectInfo info = { diff --git a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c index ffe90fade1..95ebefc84c 100644 --- a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c @@ -111,7 +111,6 @@ static pa_hook_result_t SinkInputNewCb(pa_core *c, pa_sink_input *si) SessionInfoPack pack = {channels, channelLayout, sceneMode, spatializationEnabled, volume}; if (si->state == PA_SINK_INPUT_RUNNING && !EffectChainManagerAddSessionInfo(sceneType, sessionID, pack)) { EffectChainManagerMultichannelUpdate(sceneType); - // EffectChainManagerVolumeUpdate(); } } return PA_HOOK_OK; -- Gitee From 62602d78d5cffd1609b5b3fa05d9332d898e8c40 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 20 Feb 2024 20:35:43 +0800 Subject: [PATCH 07/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/include/audio_effect_chain_manager.h | 4 ++++ frameworks/native/audioeffect/include/audio_effect_volume.h | 2 +- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 535e0b6344..a3de6781e5 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -164,6 +164,10 @@ private: void UpdateSensorState(); void DeleteAllChains(); void RecoverAllChains(); + int32_t EffectDspVolumeUpdate(); + int32_t EffectApVolumeUpdate(); + int32_t EffectDspRotationUpdate(); + int32_t EffectApRotationUpdate(); std::map EffectToLibraryEntryMap_; std::map EffectToLibraryNameMap_; std::map> EffectChainToEffectsMap_; diff --git a/frameworks/native/audioeffect/include/audio_effect_volume.h b/frameworks/native/audioeffect/include/audio_effect_volume.h index 617a120476..dfc38cc871 100644 --- a/frameworks/native/audioeffect/include/audio_effect_volume.h +++ b/frameworks/native/audioeffect/include/audio_effect_volume.h @@ -26,7 +26,7 @@ class AudioEffectVolume { public: AudioEffectVolume(); ~AudioEffectVolume(); - static AudioEffectRotation *GetInstance(); + static AudioEffectVolume *GetInstance(); void SetApVolume(std::string sceneType, uint32_t volume); uint32_t GetApVolume(std::string sceneType); void SetDspVolume(uint32_t volume); diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 2e8875808b..f4d4aa7514 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -465,7 +465,7 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr libHandles.emplace_back(libHandle); } -int32_t AudioEffectChain::SetEffectParam(uint32_t rotation) +int32_t AudioEffectChain::SetEffectParam() { std::lock_guard lock(reloadMutex); for (AudioEffectHandle handle: standByEffectHandles) { -- Gitee From 0bd19097868796102b628bc5cbb487b9cb9bd51b Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 20 Feb 2024 21:09:02 +0800 Subject: [PATCH 08/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../include/audio_effect_chain_manager.h | 10 +++--- .../src/audio_effect_chain_manager.cpp | 31 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index a3de6781e5..f1092d6cdf 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -108,7 +108,7 @@ public: void InitEffectChain(); void SetHeadTrackingDisabled(); uint32_t GetLatency(); - int32_t SetEffectPararm(); + int32_t SetEffectParam(); private: std::mutex reloadMutex; std::string sceneType; @@ -164,10 +164,10 @@ private: void UpdateSensorState(); void DeleteAllChains(); void RecoverAllChains(); - int32_t EffectDspVolumeUpdate(); - int32_t EffectApVolumeUpdate(); - int32_t EffectDspRotationUpdate(); - int32_t EffectApRotationUpdate(); + int32_t EffectDspVolumeUpdate(AudioEffectVolume *audioEffectVolume); + int32_t EffectApVolumeUpdate(AudioEffectVolume *audioEffectVolume); + int32_t EffectDspRotationUpdate(AudioEffectRotation *audioEffectRotation, const uint32_t rotationState); + int32_t EffectApRotationUpdate(AudioEffectRotation *audioEffectRotation, const uint32_t rotationState); std::map EffectToLibraryEntryMap_; std::map EffectToLibraryNameMap_; std::map> EffectChainToEffectsMap_; diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index f4d4aa7514..a40ebf1c15 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -479,10 +479,10 @@ int32_t AudioEffectChain::SetEffectParam() *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType); *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); - CHECK_AND_RETURN_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + CHECK_AND_CONTINUE_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); *data++ = audioEffectRotation->GetRotation(); AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); - CHECK_AND_RETURN_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); + CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); *data++ = audioEffectVolume->GetApVolume(sceneType); int32_t replyData = 0; AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_FIVE, @@ -1103,7 +1103,7 @@ void AudioEffectChainManager::Dump() } } -int32_t AudioEffectChainManager::EffectDspVolumeUpdate() +int32_t AudioEffectChainManager::EffectDspVolumeUpdate(AudioEffectVolume *audioEffectVolume) { // update dsp volume AUDIO_DEBUG_LOG("send volume to dsp."); @@ -1127,7 +1127,7 @@ int32_t AudioEffectChainManager::EffectDspVolumeUpdate() return SUCCESS; } -int32_t AudioEffectChainManager::EffectApVolumeUpdate() +int32_t AudioEffectChainManager::EffectApVolumeUpdate(AudioEffectVolume *audioEffectVolume) { // send to ap AUDIO_DEBUG_LOG("send volume to ap."); @@ -1165,19 +1165,22 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS SessionIDToEffectInfoMap_[sessionIDString].volume = volume; } } - int32_t ret; AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); + CHECK_AND_RETURN_RET_LOG(audioEffectVolume != nullptr, ERROR, "null audioEffectVolume"); + int32_t ret; if (offloadEnabled_) { - ret = EffectDspVolumeUpdate(); + ret = EffectDspVolumeUpdate(audioEffectVolume); } else { - ret = EffectApVolumeUpdate(); + ret = EffectApVolumeUpdate(audioEffectVolume); } - return SUCCESS; + return ret; } -int32_t AudioEffectChainManager::EffectDspRotationUpdate() +int32_t AudioEffectChainManager::EffectDspRotationUpdate(AudioEffectRotation *audioEffectRotation, + const uint32_t rotationState) { // send rotation to dsp + AUDIO_DEBUG_LOG("send rotation to dsp."); if (audioEffectRotation->GetRotation() != rotationState) { AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", rotationState, audioEffectRotation->GetRotation()); @@ -1191,9 +1194,11 @@ int32_t AudioEffectChainManager::EffectDspRotationUpdate() return SUCCESS; } -int32_t AudioEffectChainManager::EffectApRotationUpdate() +int32_t AudioEffectChainManager::EffectApRotationUpdate(AudioEffectRotation *audioEffectRotation, + const uint32_t rotationState) { // send rotation to ap + AUDIO_DEBUG_LOG("send rotation to ap."); if (audioEffectRotation->GetRotation() != rotationState) { AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", rotationState, audioEffectRotation->GetRotation()); @@ -1211,7 +1216,7 @@ int32_t AudioEffectChainManager::EffectApRotationUpdate() CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set ap rotation failed"); } } - return ret; + return SUCCESS; } int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationState) @@ -1221,9 +1226,9 @@ int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationSta CHECK_AND_RETURN_RET_LOG(audioEffectRotation != nullptr, ERROR, "null audioEffectRotation"); int32_t ret; if (offloadEnabled_) { - ret = EffectDspRotationUpdate; + ret = EffectDspRotationUpdate(audioEffectRotation); } else { - ret = EffectApRotationUpdate; + ret = EffectApRotationUpdate(audioEffectRotation); } return ret; } -- Gitee From 30d1f4e76fbf4c4e1c0793fc29538ba6919049c8 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 15:01:14 +0800 Subject: [PATCH 09/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- frameworks/native/audioeffect/BUILD.gn | 10 +++++++++- .../include/audio_effect_chain_manager.h | 4 ++++ .../include/audio_effect_rotation.h | 4 ++++ .../src/audio_effect_chain_manager.cpp | 18 ++++++++++++++---- .../audioeffect/src/audio_effect_rotation.cpp | 4 ++-- services/audio_service/BUILD.gn | 6 +++++- window_manager.gni | 18 ++++++++++++++++++ 7 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 window_manager.gni diff --git a/frameworks/native/audioeffect/BUILD.gn b/frameworks/native/audioeffect/BUILD.gn index 5ed5f0082e..b88eb3c54f 100644 --- a/frameworks/native/audioeffect/BUILD.gn +++ b/frameworks/native/audioeffect/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos.gni") import("../../../audio_ohcore.gni") import("../../../config.gni") import("../../../sensor.gni") +import("../../../window_manager.gni") pulseaudio_dir = "//third_party/pulseaudio" pulseaudio_build_path = "//third_party/pulseaudio/ohosbuild" @@ -40,6 +41,10 @@ config("audio_effect_config") { if (sensor_enable == true) { cflags += [ "-DSENSOR_ENABLE" ] } + + if (window_manager_enable == true) { + cflags += [ "-DWINDOW_MANAGER_ENABLE" ] + } } ohos_shared_library("audio_effect") { @@ -72,13 +77,16 @@ ohos_shared_library("audio_effect") { "drivers_interface_audio:libeffect_proxy_1.0", "hilog:libhilog", "ipc:ipc_single", - "window_manager:libdm", ] if (sensor_enable == true) { external_deps += [ "sensor:sensor_interface_native" ] } + if (window_manager_enable == true) { + external_deps += [ "window_manager:libdm" ] + } + version_script = "../../../audio_framework.versionscript" part_name = "audio_framework" diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index f1092d6cdf..92560e4a4e 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -36,7 +36,9 @@ #include "audio_head_tracker.h" #endif #include "audio_effect_hdi_param.h" +#ifdef WINDOW_MANAGER_ENABLE #include "audio_effect_rotation.h" +#endif #include "audio_effect_volume.h" namespace OHOS { @@ -166,8 +168,10 @@ private: void RecoverAllChains(); int32_t EffectDspVolumeUpdate(AudioEffectVolume *audioEffectVolume); int32_t EffectApVolumeUpdate(AudioEffectVolume *audioEffectVolume); +#ifdef WINDOW_MANAGER_ENABLE int32_t EffectDspRotationUpdate(AudioEffectRotation *audioEffectRotation, const uint32_t rotationState); int32_t EffectApRotationUpdate(AudioEffectRotation *audioEffectRotation, const uint32_t rotationState); +#endif std::map EffectToLibraryEntryMap_; std::map EffectToLibraryNameMap_; std::map> EffectChainToEffectsMap_; diff --git a/frameworks/native/audioeffect/include/audio_effect_rotation.h b/frameworks/native/audioeffect/include/audio_effect_rotation.h index 310ac26ba1..695dc2f959 100644 --- a/frameworks/native/audioeffect/include/audio_effect_rotation.h +++ b/frameworks/native/audioeffect/include/audio_effect_rotation.h @@ -18,11 +18,14 @@ #include #include +#ifdef WINDOW_MANAGER_ENABLE #include "display_manager.h" #include "dm_common.h" +#endif namespace OHOS { namespace AudioStandard { +#ifdef WINDOW_MANAGER_ENABLE class AudioEffectRotation { public: AudioEffectRotation(); @@ -63,6 +66,7 @@ private: void OnDestroy(Rosen::DisplayId displayId); void OnChange(Rosen::DisplayId displayId); }; +#endif } // namespace AudioStandard } // namespace OHOS #endif // AUDIO_EFFECT_ROTATION_H \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index a40ebf1c15..fbd0a00ed2 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -179,6 +179,7 @@ int32_t EffectChainManagerVolumeUpdate(const char *sessionID, const uint32_t vol return SUCCESS; } +#ifdef WINDOW_MANAGER_ENABLE int32_t EffectChainManagerRotationUpdate(const uint32_t rotationState) { AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); @@ -188,6 +189,7 @@ int32_t EffectChainManagerRotationUpdate(const uint32_t rotationState) } return SUCCESS; } +#endif bool IsChannelLayoutHVSSupported(const uint64_t channelLayout) { @@ -478,9 +480,13 @@ int32_t AudioEffectChain::SetEffectParam() *data++ = EFFECT_SET_PARAM; *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType); *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); +#ifdef WINDOW_MANAGER_ENABLE AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); CHECK_AND_CONTINUE_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); *data++ = audioEffectRotation->GetRotation(); +#else + *data++ = 0; +#endif AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); *data++ = audioEffectVolume->GetApVolume(sceneType); @@ -1107,6 +1113,7 @@ int32_t AudioEffectChainManager::EffectDspVolumeUpdate(AudioEffectVolume *audioE { // update dsp volume AUDIO_DEBUG_LOG("send volume to dsp."); + CHECK_AND_RETURN_RET_LOG(audioEffectVolume != nullptr, ERROR, "null audioEffectVolume"); uint32_t volumeMax = 0; for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { std::set sessions = SceneTypeToSessionIDMap_[it->first]; @@ -1131,6 +1138,7 @@ int32_t AudioEffectChainManager::EffectApVolumeUpdate(AudioEffectVolume *audioEf { // send to ap AUDIO_DEBUG_LOG("send volume to ap."); + CHECK_AND_RETURN_RET_LOG(audioEffectVolume != nullptr, ERROR, "null audioEffectVolume"); for (auto it = SceneTypeToSessionIDMap_.begin(); it != SceneTypeToSessionIDMap_.end(); it++) { uint32_t volumeMax = 0; std::set sessions = SceneTypeToSessionIDMap_[it->first]; @@ -1166,7 +1174,6 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS } } AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); - CHECK_AND_RETURN_RET_LOG(audioEffectVolume != nullptr, ERROR, "null audioEffectVolume"); int32_t ret; if (offloadEnabled_) { ret = EffectDspVolumeUpdate(audioEffectVolume); @@ -1176,11 +1183,13 @@ int32_t AudioEffectChainManager::EffectVolumeUpdate(const std::string sessionIDS return ret; } +#ifdef WINDOW_MANAGER_ENABLE int32_t AudioEffectChainManager::EffectDspRotationUpdate(AudioEffectRotation *audioEffectRotation, const uint32_t rotationState) { // send rotation to dsp AUDIO_DEBUG_LOG("send rotation to dsp."); + CHECK_AND_RETURN_RET_LOG(audioEffectRotation != nullptr, ERROR, "null audioEffectRotation"); if (audioEffectRotation->GetRotation() != rotationState) { AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", rotationState, audioEffectRotation->GetRotation()); @@ -1199,6 +1208,7 @@ int32_t AudioEffectChainManager::EffectApRotationUpdate(AudioEffectRotation *aud { // send rotation to ap AUDIO_DEBUG_LOG("send rotation to ap."); + CHECK_AND_RETURN_RET_LOG(audioEffectRotation != nullptr, ERROR, "null audioEffectRotation"); if (audioEffectRotation->GetRotation() != rotationState) { AUDIO_DEBUG_LOG("rotationState change, new state: %{public}d, previous state: %{public}d", rotationState, audioEffectRotation->GetRotation()); @@ -1223,15 +1233,15 @@ int32_t AudioEffectChainManager::EffectRotationUpdate(const uint32_t rotationSta { std::lock_guard lock(dynamicMutex_); AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); - CHECK_AND_RETURN_RET_LOG(audioEffectRotation != nullptr, ERROR, "null audioEffectRotation"); int32_t ret; if (offloadEnabled_) { - ret = EffectDspRotationUpdate(audioEffectRotation); + ret = EffectDspRotationUpdate(audioEffectRotation, rotationState); } else { - ret = EffectApRotationUpdate(audioEffectRotation); + ret = EffectApRotationUpdate(audioEffectRotation, rotationState); } return ret; } +#endif int32_t AudioEffectChainManager::UpdateMultichannelConfig(const std::string &sceneType) { diff --git a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp index f418f21b30..5e18ce5955 100644 --- a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp @@ -19,6 +19,7 @@ namespace OHOS { namespace AudioStandard { +#ifdef WINDOW_MANAGER_ENABLE AudioEffectRotation::AudioEffectRotation() { AUDIO_INFO_LOG("AudioEffectRotation created!"); @@ -77,7 +78,6 @@ void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) AUDIO_DEBUG_LOG("Onchange rotationState: %{public}u.", static_cast(newRotationState)); EffectChainManagerRotationUpdate(static_cast(newRotationState)); } - - +#endif } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/services/audio_service/BUILD.gn b/services/audio_service/BUILD.gn index aff7a1f8d0..41dc29e271 100644 --- a/services/audio_service/BUILD.gn +++ b/services/audio_service/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos.gni") import("../../config.gni") import("../../ressche_part.gni") import("../../sensor.gni") +import("../../window_manager.gni") pulseaudio_dir = "//third_party/pulseaudio" pulseaudio_build_path = "//third_party/pulseaudio/ohosbuild" @@ -384,13 +385,16 @@ ohos_shared_library("audio_service") { "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libdm", ] if (sensor_enable == true) { external_deps += [ "sensor:sensor_interface_native" ] } + if (window_manager_enable == true) { + external_deps += [ "window_manager:libdm" ] + } + if (ressche_enable == true) { external_deps += [ "resource_schedule_service:ressched_client" ] } diff --git a/window_manager.gni b/window_manager.gni new file mode 100644 index 0000000000..c7d21a085d --- /dev/null +++ b/window_manager.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (defined(global_parts_info) && defined(global_parts_info.window_window_manager)) { + window_manager_enable = true +} else { + window_manager_enable = false +} \ No newline at end of file -- Gitee From 04d7b7e116560b68efaecde9e79dad7566457851 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 16:11:47 +0800 Subject: [PATCH 10/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../src/audio_effect_chain_manager.cpp | 18 ++++++++++++++++-- window_manager.gni | 18 ------------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index fbd0a00ed2..5101d2922f 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -450,7 +450,7 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr sceneType.c_str(), effectMode.c_str()); // Set param AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + - NUM_SET_EFFECT_PARAM_THREE * sizeof(int32_t)]; + NUM_SET_EFFECT_PARAM_FIVE * sizeof(int32_t)]; effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; @@ -458,7 +458,19 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr *data++ = EFFECT_SET_PARAM; *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_TYPES, sceneType); *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); - cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_THREE, effectParam}; +#ifdef WINDOW_MANAGER_ENABLE + AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); + CHECK_AND_CONTINUE_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + *data++ = audioEffectRotation->GetRotation(); +#else + *data++ = 0; +#endif + AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); + AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); + CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); + *data++ = audioEffectVolume->GetApVolume(sceneType); + AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); + cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_FIVE, effectParam}; ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); delete[] effectParam; CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], either one of libs EFFECT_CMD_SET_PARAM fail", @@ -487,9 +499,11 @@ int32_t AudioEffectChain::SetEffectParam() #else *data++ = 0; #endif + AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); *data++ = audioEffectVolume->GetApVolume(sceneType); + AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); int32_t replyData = 0; AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_FIVE, effectParam}; diff --git a/window_manager.gni b/window_manager.gni index c7d21a085d..e69de29bb2 100644 --- a/window_manager.gni +++ b/window_manager.gni @@ -1,18 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -if (defined(global_parts_info) && defined(global_parts_info.window_window_manager)) { - window_manager_enable = true -} else { - window_manager_enable = false -} \ No newline at end of file -- Gitee From 82f918288559eb3d7f39f8f8e1d8012c3e15ccf2 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 17:13:07 +0800 Subject: [PATCH 11/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- window_manager.gni | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/window_manager.gni b/window_manager.gni index e69de29bb2..c7d21a085d 100644 --- a/window_manager.gni +++ b/window_manager.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (defined(global_parts_info) && defined(global_parts_info.window_window_manager)) { + window_manager_enable = true +} else { + window_manager_enable = false +} \ No newline at end of file -- Gitee From 5b2714cfc1681184df57e7a2167e53a6c2dccf38 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 18:24:10 +0800 Subject: [PATCH 12/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../include/audio_effect_chain_manager.h | 4 +- .../include/audio_effect_hdi_param.h | 16 ++++---- .../include/audio_effect_rotation.h | 29 +++------------ .../src/audio_effect_chain_manager.cpp | 11 +++--- .../src/audio_effect_hdi_param.cpp | 27 ++++++++------ .../audioeffect/src/audio_effect_rotation.cpp | 37 +++++++++++++++---- .../audioeffect/src/audio_effect_volume.cpp | 3 +- .../pulseaudio/modules/hdi/module_hdi_sink.c | 1 - 8 files changed, 68 insertions(+), 60 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 92560e4a4e..27c55d8e13 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -44,9 +44,7 @@ namespace OHOS { namespace AudioStandard { -const uint32_t NUM_SET_EFFECT_PARAM_TWO = 2; -const uint32_t NUM_SET_EFFECT_PARAM_THREE = 3; -const uint32_t NUM_SET_EFFECT_PARAM_FIVE = 5; +const uint32_t NUM_SET_EFFECT_PARAM = 5; const uint32_t DEFAULT_FRAMELEN = 1440; const uint32_t DEFAULT_SAMPLE_RATE = 48000; const uint32_t DEFAULT_NUM_CHANNEL = STEREO; diff --git a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h index 50320d9212..7e57f74b91 100644 --- a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h +++ b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h @@ -21,23 +21,23 @@ namespace OHOS { namespace AudioStandard { -const uint32_t SEND_HDI_COMMAND_LEN = 20; -const uint32_t GET_HDI_BUFFER_LEN = 10; class AudioEffectHdiParam { public: + static const uint32_t SEND_HDI_COMMAND_LEN = 20; + static const uint32_t GET_HDI_BUFFER_LEN = 10; AudioEffectHdiParam(); ~AudioEffectHdiParam(); void InitHdi(); int32_t UpdateHdiState(int8_t *effectHdiInput); private: - int8_t input[SEND_HDI_COMMAND_LEN]; - int8_t output[GET_HDI_BUFFER_LEN]; - uint32_t replyLen; - std::string libName; - std::string effectId; + void CreateHdiControl(); + int8_t input_[SEND_HDI_COMMAND_LEN]; + int8_t output_[GET_HDI_BUFFER_LEN]; + uint32_t replyLen_; + std::string libName_; + std::string effectId_; IEffectModel *hdiModel_; std::vector libHdiControls_; - void CreateHdiControl(); }; } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/include/audio_effect_rotation.h b/frameworks/native/audioeffect/include/audio_effect_rotation.h index 695dc2f959..c92bddd87e 100644 --- a/frameworks/native/audioeffect/include/audio_effect_rotation.h +++ b/frameworks/native/audioeffect/include/audio_effect_rotation.h @@ -37,34 +37,17 @@ public: private: class AudioRotationListener : public OHOS::Rosen::DisplayManager::IDisplayListener { public: - void OnCreate(Rosen::DisplayId displayId) override - { - AudioEffectRotation *audioEffectRotation = GetInstance(); - if (audioEffectRotation != nullptr) { - audioEffectRotation->OnCreate(displayId); - } - } - void OnDestroy(Rosen::DisplayId displayId) override - { - AudioEffectRotation *audioEffectRotation = GetInstance(); - if (audioEffectRotation != nullptr) { - audioEffectRotation->OnDestroy(displayId); - } - } - void OnChange(Rosen::DisplayId displayId) override - { - AudioEffectRotation *audioEffectRotation = GetInstance(); - if (audioEffectRotation != nullptr) { - audioEffectRotation->OnChange(displayId); - } - } + void OnCreate(Rosen::DisplayId displayId) override; + void OnDestroy(Rosen::DisplayId displayId) override; + void OnChange(Rosen::DisplayId displayId) override; }; - sptr audioRotationListener_; - uint32_t rotationState_; void OnCreate(Rosen::DisplayId displayId); void OnDestroy(Rosen::DisplayId displayId); void OnChange(Rosen::DisplayId displayId); + + sptr audioRotationListener_; + uint32_t rotationState_; }; #endif } // namespace AudioStandard diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 5101d2922f..097ff8fc3a 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -165,8 +165,6 @@ int32_t EffectChainManagerMultichannelUpdate(const char *sceneType) return SUCCESS; } -// todo tranmit effectMode&sceneType -// todo tranmit bypass int32_t EffectChainManagerVolumeUpdate(const char *sessionID, const uint32_t volume) { AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); @@ -450,7 +448,7 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr sceneType.c_str(), effectMode.c_str()); // Set param AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + - NUM_SET_EFFECT_PARAM_FIVE * sizeof(int32_t)]; + NUM_SET_EFFECT_PARAM * sizeof(int32_t)]; effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; @@ -470,13 +468,14 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); - cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_FIVE, effectParam}; + cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); delete[] effectParam; CHECK_AND_RETURN_LOG(ret == 0, "[%{public}s] with mode [%{public}s], either one of libs EFFECT_CMD_SET_PARAM fail", sceneType.c_str(), effectMode.c_str()); standByEffectHandles.emplace_back(handle); libHandles.emplace_back(libHandle); + latency_ += static_cast(replyData); } int32_t AudioEffectChain::SetEffectParam() @@ -484,7 +483,7 @@ int32_t AudioEffectChain::SetEffectParam() std::lock_guard lock(reloadMutex); for (AudioEffectHandle handle: standByEffectHandles) { AudioEffectParam *effectParam = new AudioEffectParam[sizeof(AudioEffectParam) + - NUM_SET_EFFECT_PARAM_FIVE * sizeof(int32_t)]; + NUM_SET_EFFECT_PARAM * sizeof(int32_t)]; effectParam->status = 0; effectParam->paramSize = sizeof(int32_t); effectParam->valueSize = 0; @@ -505,7 +504,7 @@ int32_t AudioEffectChain::SetEffectParam() *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); int32_t replyData = 0; - AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM_FIVE, + AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; AudioEffectTransInfo replyInfo = {sizeof(int32_t), &replyData}; int32_t ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index 878f50a8a8..8321618a1e 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -23,17 +23,17 @@ namespace OHOS { namespace AudioStandard { AudioEffectHdiParam::AudioEffectHdiParam() { - AUDIO_INFO_LOG("AudioEffectHdiParam constructor."); + AUDIO_DEBUG_LOG("constructor."); libHdiControls_.clear(); - memset_s(static_cast(input), sizeof(input), 0, sizeof(input)); - memset_s(static_cast(output), sizeof(output), 0, sizeof(output)); - replyLen = GET_HDI_BUFFER_LEN; + memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); + memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); + replyLen_ = GET_HDI_BUFFER_LEN; hdiModel_ = nullptr; } AudioEffectHdiParam::~AudioEffectHdiParam() { - AUDIO_INFO_LOG("AudioEffectHdiParam destructor!"); + AUDIO_DEBUG_LOG("destructor!"); } void AudioEffectHdiParam::CreateHdiControl() @@ -62,7 +62,7 @@ void AudioEffectHdiParam::InitHdi() { hdiModel_ = IEffectModelGet(false); if (hdiModel_ == nullptr) { - AUDIO_WARNING_LOG("IEffectModelGet failed"); + AUDIO_ERR_LOG("IEffectModelGet failed"); return; } @@ -71,21 +71,26 @@ void AudioEffectHdiParam::InitHdi() int32_t AudioEffectHdiParam::UpdateHdiState(int8_t *effectHdiInput) { + int32_t ret; for (IEffectControl *hdiControl : libHdiControls_) { if (hdiControl == nullptr) { AUDIO_WARNING_LOG("hdiControl is nullptr."); - return ERROR; + continue; + } + ret = memcpy_s(static_cast(input), sizeof(input), static_cast(effectHdiInput), sizeof(input)); + if (ret != 0) { + AUDIO_WARNING_LOG("hdi memcpy failed"); + continue; } - memcpy_s(static_cast(input), sizeof(input), static_cast(effectHdiInput), sizeof(input)); uint32_t replyLen = GET_HDI_BUFFER_LEN; - int32_t ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, + ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, output, &replyLen); if (ret != 0) { AUDIO_WARNING_LOG("hdi send command failed"); - return ret; + continue; } } - return SUCCESS; + return ret; } } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp index 5e18ce5955..88da724c33 100644 --- a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp @@ -20,15 +20,37 @@ namespace OHOS { namespace AudioStandard { #ifdef WINDOW_MANAGER_ENABLE +void AudioRotationListener::OnCreate(Rosen::DisplayId displayId) override +{ + AudioEffectRotation *audioEffectRotation = GetInstance(); + if (audioEffectRotation != nullptr) { + audioEffectRotation->OnCreate(displayId); + } +} +void AudioRotationListener::OnDestroy(Rosen::DisplayId displayId) override +{ + AudioEffectRotation *audioEffectRotation = GetInstance(); + if (audioEffectRotation != nullptr) { + audioEffectRotation->OnDestroy(displayId); + } +} +void AudioRotationListener::OnChange(Rosen::DisplayId displayId) override +{ + AudioEffectRotation *audioEffectRotation = GetInstance(); + if (audioEffectRotation != nullptr) { + audioEffectRotation->OnChange(displayId); + } +} + AudioEffectRotation::AudioEffectRotation() { - AUDIO_INFO_LOG("AudioEffectRotation created!"); + AUDIO_DEBUG_LOG("created!"); rotationState_ = 0; } AudioEffectRotation::~AudioEffectRotation() { - AUDIO_INFO_LOG("AudioEffectRotation destroyed!"); + AUDIO_DEBUG_LOG("destroyed!"); } AudioEffectRotation *AudioEffectRotation::GetInstance() @@ -56,26 +78,27 @@ uint32_t AudioEffectRotation::GetRotation() void AudioEffectRotation::OnCreate(Rosen::DisplayId displayId) { - AUDIO_DEBUG_LOG("Onchange displayId: %{public}llu.", displayId); + AUDIO_DEBUG_LOG("Onchange displayId: %{public}d.", static_castdisplayId); } void AudioEffectRotation::OnDestroy(Rosen::DisplayId displayId) { - AUDIO_DEBUG_LOG("OnDestroy displayId: %{public}llu.", displayId); + AUDIO_DEBUG_LOG("Onchange displayId: %{public}d.", static_castdisplayId); } void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) { - AUDIO_DEBUG_LOG("Onchange displayId: %{public}llu.", displayId); // get display auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); if (!display) { - AUDIO_WARNING_LOG("Get display by displayId: %{public}llu failed.", displayId); + AUDIO_WARNING_LOG("Get display by displayId: %{public}d failed.", + static_castdisplayIddisplayId); return; } // get rotation Rosen::Rotation newRotationState = display->GetRotation(); - AUDIO_DEBUG_LOG("Onchange rotationState: %{public}u.", static_cast(newRotationState)); + AUDIO_DEBUG_LOG("Onchange displayId: %{public}d rotationState: %{public}u.", + static_castdisplayId, static_cast(newRotationState)); EffectChainManagerRotationUpdate(static_cast(newRotationState)); } #endif diff --git a/frameworks/native/audioeffect/src/audio_effect_volume.cpp b/frameworks/native/audioeffect/src/audio_effect_volume.cpp index da80c2ac34..3b3c002273 100644 --- a/frameworks/native/audioeffect/src/audio_effect_volume.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_volume.cpp @@ -20,13 +20,14 @@ namespace OHOS { namespace AudioStandard { AudioEffectVolume::AudioEffectVolume() { + AUDIO_DEBUG_LOG("created!"); SceneTypeToVolumeMap_.clear(); dspVolume_ = 0; } AudioEffectVolume::~AudioEffectVolume() { - AUDIO_INFO_LOG("AudioEffectVolume destructor!"); + AUDIO_DEBUG_LOG("destructor!"); } AudioEffectVolume *AudioEffectVolume::GetInstance() diff --git a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c index 95ebefc84c..e344218e2b 100644 --- a/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/module_hdi_sink.c @@ -200,7 +200,6 @@ static pa_hook_result_t SinkInputStateChangedCb(pa_core *c, pa_sink_input *si, v static pa_hook_result_t SinkInputVolumeChangedCb(pa_core *c, pa_sink_input *si, void *u) { AUDIO_DEBUG_LOG("volume changed."); - // todo test if work when stream create const char *sessionID = pa_proplist_gets(si->proplist, "stream.sessionID"); const uint32_t volume = si->volume.values[0]; EffectChainManagerVolumeUpdate(sessionID, volume); -- Gitee From 90566fa48d565cd49e7476fc30691745580b3ead Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 18:35:00 +0800 Subject: [PATCH 13/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- window_manager.gni | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/window_manager.gni b/window_manager.gni index c7d21a085d..451bb74ae8 100644 --- a/window_manager.gni +++ b/window_manager.gni @@ -11,8 +11,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (defined(global_parts_info) && defined(global_parts_info.window_window_manager)) { +if (defined(global_parts_info) && + defined(global_parts_info.window_window_manager)) { window_manager_enable = true } else { window_manager_enable = false -} \ No newline at end of file +} -- Gitee From 5f70d814f97ec84f70d4585c62c86324dab66476 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 19:07:47 +0800 Subject: [PATCH 14/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 3 ++- .../native/audioeffect/src/audio_effect_rotation.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 097ff8fc3a..8ee5249911 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -896,7 +896,6 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vectorInitHdi(); effectHdiInput[0] = HDI_BLUETOOTH_MODE; effectHdiInput[1] = 1; @@ -905,9 +904,11 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vectorInit(); +#endif isInitialized_ = true; } diff --git a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp index 88da724c33..d3550ee390 100644 --- a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp @@ -78,12 +78,12 @@ uint32_t AudioEffectRotation::GetRotation() void AudioEffectRotation::OnCreate(Rosen::DisplayId displayId) { - AUDIO_DEBUG_LOG("Onchange displayId: %{public}d.", static_castdisplayId); + AUDIO_DEBUG_LOG("Onchange displayId: %{public}d.", static_cast(displayId)); } void AudioEffectRotation::OnDestroy(Rosen::DisplayId displayId) { - AUDIO_DEBUG_LOG("Onchange displayId: %{public}d.", static_castdisplayId); + AUDIO_DEBUG_LOG("Onchange displayId: %{public}d.", static_cast(displayId)); } void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) @@ -92,13 +92,13 @@ void AudioEffectRotation::OnChange(Rosen::DisplayId displayId) auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); if (!display) { AUDIO_WARNING_LOG("Get display by displayId: %{public}d failed.", - static_castdisplayIddisplayId); + static_cast(displayId)); return; } // get rotation Rosen::Rotation newRotationState = display->GetRotation(); AUDIO_DEBUG_LOG("Onchange displayId: %{public}d rotationState: %{public}u.", - static_castdisplayId, static_cast(newRotationState)); + static_cast(displayId), static_cast(newRotationState)); EffectChainManagerRotationUpdate(static_cast(newRotationState)); } #endif -- Gitee From d0bf24fc6fa9087aada6d526b71d05828fb989cb Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 19:33:11 +0800 Subject: [PATCH 15/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../src/audio_effect_hdi_param.cpp | 31 +++++++++---------- .../audioeffect/src/audio_effect_rotation.cpp | 6 ++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index 8321618a1e..dd083ebf73 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -25,8 +25,11 @@ AudioEffectHdiParam::AudioEffectHdiParam() { AUDIO_DEBUG_LOG("constructor."); libHdiControls_.clear(); - memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); - memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); + int32_t ret; + ret = memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); + CHECK_AND_CONTINUE_LOG(ret == 0, "hdi constructor memcpy input failed"); + ret = memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); + CHECK_AND_CONTINUE_LOG(ret == 0, "hdi constructor memcpy output failed"); replyLen_ = GET_HDI_BUFFER_LEN; hdiModel_ = nullptr; } @@ -39,11 +42,11 @@ AudioEffectHdiParam::~AudioEffectHdiParam() void AudioEffectHdiParam::CreateHdiControl() { // todo read from vendor/... - libName = strdup("libspatialization_processing_dsp"); - effectId = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966gg"); + libName_ = strdup("libspatialization_processing_dsp"); + effectId_ = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966gg"); EffectInfo info = { - .libName = &libName[0], - .effectId = &effectId[0], + .libName = &libName_[0], + .effectId = &effectId_[0], .ioDirection = 1, }; ControllerId controllerId; @@ -77,18 +80,12 @@ int32_t AudioEffectHdiParam::UpdateHdiState(int8_t *effectHdiInput) AUDIO_WARNING_LOG("hdiControl is nullptr."); continue; } - ret = memcpy_s(static_cast(input), sizeof(input), static_cast(effectHdiInput), sizeof(input)); - if (ret != 0) { - AUDIO_WARNING_LOG("hdi memcpy failed"); - continue; - } + ret = memcpy_s(static_cast(input_), sizeof(input_), static_cast(effectHdiInput), sizeof(input_)); + CHECK_AND_CONTINUE_LOG(ret == 0, "hdi memcpy failed"); uint32_t replyLen = GET_HDI_BUFFER_LEN; - ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input, SEND_HDI_COMMAND_LEN, - output, &replyLen); - if (ret != 0) { - AUDIO_WARNING_LOG("hdi send command failed"); - continue; - } + ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input_, SEND_HDI_COMMAND_LEN, + output_, &replyLen); + CHECK_AND_CONTINUE_LOG(ret == 0, "hdi send command failed"); } return ret; } diff --git a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp index d3550ee390..d992a21deb 100644 --- a/frameworks/native/audioeffect/src/audio_effect_rotation.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_rotation.cpp @@ -20,21 +20,21 @@ namespace OHOS { namespace AudioStandard { #ifdef WINDOW_MANAGER_ENABLE -void AudioRotationListener::OnCreate(Rosen::DisplayId displayId) override +void AudioEffectRotation::AudioRotationListener::OnCreate(Rosen::DisplayId displayId) { AudioEffectRotation *audioEffectRotation = GetInstance(); if (audioEffectRotation != nullptr) { audioEffectRotation->OnCreate(displayId); } } -void AudioRotationListener::OnDestroy(Rosen::DisplayId displayId) override +void AudioEffectRotation::AudioRotationListener::OnDestroy(Rosen::DisplayId displayId) { AudioEffectRotation *audioEffectRotation = GetInstance(); if (audioEffectRotation != nullptr) { audioEffectRotation->OnDestroy(displayId); } } -void AudioRotationListener::OnChange(Rosen::DisplayId displayId) override +void AudioEffectRotation::AudioRotationListener::OnChange(Rosen::DisplayId displayId) { AudioEffectRotation *audioEffectRotation = GetInstance(); if (audioEffectRotation != nullptr) { -- Gitee From 1afab676d7074152d43db6e095460f8ac0195c4e Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 19:49:00 +0800 Subject: [PATCH 16/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_hdi_param.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index dd083ebf73..2d24c5ed5f 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -25,11 +25,8 @@ AudioEffectHdiParam::AudioEffectHdiParam() { AUDIO_DEBUG_LOG("constructor."); libHdiControls_.clear(); - int32_t ret; - ret = memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); - CHECK_AND_CONTINUE_LOG(ret == 0, "hdi constructor memcpy input failed"); - ret = memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); - CHECK_AND_CONTINUE_LOG(ret == 0, "hdi constructor memcpy output failed"); + memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); + memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); replyLen_ = GET_HDI_BUFFER_LEN; hdiModel_ = nullptr; } -- Gitee From 3cd471e81a6398816c06e228ff2ced4fb94b8420 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 19:49:50 +0800 Subject: [PATCH 17/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index 2d24c5ed5f..d92573baee 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -77,7 +77,8 @@ int32_t AudioEffectHdiParam::UpdateHdiState(int8_t *effectHdiInput) AUDIO_WARNING_LOG("hdiControl is nullptr."); continue; } - ret = memcpy_s(static_cast(input_), sizeof(input_), static_cast(effectHdiInput), sizeof(input_)); + ret = memcpy_s(static_cast(input_), sizeof(input_), + static_cast(effectHdiInput), sizeof(input_)); CHECK_AND_CONTINUE_LOG(ret == 0, "hdi memcpy failed"); uint32_t replyLen = GET_HDI_BUFFER_LEN; ret = hdiControl->SendCommand(hdiControl, HDI_SET_PATAM, input_, SEND_HDI_COMMAND_LEN, -- Gitee From 68bcccf9b788e0b4159addc06be1367444fdaa66 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 19:51:32 +0800 Subject: [PATCH 18/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_hdi_param.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index d92573baee..2932718455 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -25,8 +25,10 @@ AudioEffectHdiParam::AudioEffectHdiParam() { AUDIO_DEBUG_LOG("constructor."); libHdiControls_.clear(); - memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); - memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); + int32_t ret = memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); + CHECK_AND_RETURN_LOG(ret == 0, "hdi constructor memcpy input failed"); + ret = memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); + CHECK_AND_RETURN_LOG(ret == 0, "hdi constructor memcpy output failed"); replyLen_ = GET_HDI_BUFFER_LEN; hdiModel_ = nullptr; } -- Gitee From 80be306c9b868a7665e75eb89ae0e42ac7049a39 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 20:15:04 +0800 Subject: [PATCH 19/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- frameworks/native/audioeffect/include/audio_effect_hdi_param.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h index 7e57f74b91..f196a947e7 100644 --- a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h +++ b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h @@ -19,11 +19,12 @@ #include #include "v1_0/ieffect_model.h" +const uint32_t SEND_HDI_COMMAND_LEN = 20; + namespace OHOS { namespace AudioStandard { class AudioEffectHdiParam { public: - static const uint32_t SEND_HDI_COMMAND_LEN = 20; static const uint32_t GET_HDI_BUFFER_LEN = 10; AudioEffectHdiParam(); ~AudioEffectHdiParam(); -- Gitee From 0aaacd32568e91000f0ec7f2f6c25c7fc3fa70ea Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 21 Feb 2024 20:39:28 +0800 Subject: [PATCH 20/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../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 8ee5249911..5a9a4bc2e7 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -458,14 +458,14 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); #ifdef WINDOW_MANAGER_ENABLE AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); - CHECK_AND_CONTINUE_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + CHECK_AND_RETURN_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); *data++ = audioEffectRotation->GetRotation(); #else *data++ = 0; #endif AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); - CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); + CHECK_AND_RETURN_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; -- Gitee From 6f0dc38d5c1c19a4da13315cacd859580986d03e Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 22 Feb 2024 11:06:23 +0800 Subject: [PATCH 21/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../src/audio_effect_chain_manager.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 5a9a4bc2e7..fc0d770e8d 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -458,14 +458,18 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); #ifdef WINDOW_MANAGER_ENABLE AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); - CHECK_AND_RETURN_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + if (audioEffectRotation == nullptr) { + AUDIO_DEBUG_LOG("null audioEffectRotation"); + } *data++ = audioEffectRotation->GetRotation(); #else *data++ = 0; #endif AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); - CHECK_AND_RETURN_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); + if (audioEffectVolume == nullptr) { + AUDIO_DEBUG_LOG("null audioEffectVolume"); + } *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; @@ -493,14 +497,18 @@ int32_t AudioEffectChain::SetEffectParam() *data++ = GetKeyFromValue(AUDIO_SUPPORTED_SCENE_MODES, effectMode); #ifdef WINDOW_MANAGER_ENABLE AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); - CHECK_AND_CONTINUE_LOG(audioEffectRotation != nullptr, "null audioEffectRotation"); + if (audioEffectRotation == nullptr) { + AUDIO_DEBUG_LOG("null audioEffectRotation"); + } *data++ = audioEffectRotation->GetRotation(); #else *data++ = 0; #endif AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); - CHECK_AND_CONTINUE_LOG(audioEffectVolume != nullptr, "null audioEffectVolume"); + if (audioEffectVolume == nullptr) { + AUDIO_DEBUG_LOG("null audioEffectVolume"); + } *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); int32_t replyData = 0; -- Gitee From 3c2b75a11be6dc86ce90562127b6c0f19618e4a8 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 22 Feb 2024 11:14:20 +0800 Subject: [PATCH 22/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../src/audio_effect_chain_manager.cpp | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index fc0d770e8d..6af0b3b17b 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -460,8 +460,10 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); if (audioEffectRotation == nullptr) { AUDIO_DEBUG_LOG("null audioEffectRotation"); + *data++ = 0; + } else { + *data++ = audioEffectRotation->GetRotation(); } - *data++ = audioEffectRotation->GetRotation(); #else *data++ = 0; #endif @@ -469,8 +471,10 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); if (audioEffectVolume == nullptr) { AUDIO_DEBUG_LOG("null audioEffectVolume"); + *data++ = 0; + } else { + *data++ = audioEffectVolume->GetApVolume(sceneType); } - *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, effectParam}; ret = (*handle)->command(handle, EFFECT_CMD_SET_PARAM, &cmdInfo, &replyInfo); @@ -499,8 +503,10 @@ int32_t AudioEffectChain::SetEffectParam() AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); if (audioEffectRotation == nullptr) { AUDIO_DEBUG_LOG("null audioEffectRotation"); + *data++ = 0; + } else { + *data++ = audioEffectRotation->GetRotation(); } - *data++ = audioEffectRotation->GetRotation(); #else *data++ = 0; #endif @@ -508,8 +514,10 @@ int32_t AudioEffectChain::SetEffectParam() AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); if (audioEffectVolume == nullptr) { AUDIO_DEBUG_LOG("null audioEffectVolume"); + *data++ = 0; + } else { + *data++ = audioEffectVolume->GetApVolume(sceneType); } - *data++ = audioEffectVolume->GetApVolume(sceneType); AUDIO_DEBUG_LOG("set ap integration volume: %{public}u", *(data - 1)); int32_t replyData = 0; AudioEffectTransInfo cmdInfo = {sizeof(AudioEffectParam) + sizeof(int32_t) * NUM_SET_EFFECT_PARAM, @@ -914,8 +922,11 @@ void AudioEffectChainManager::InitAudioEffectChainManager(std::vectorInit(); + if (audioEffectRotation == nullptr) { + AUDIO_DEBUG_LOG("null audioEffectRotation"); + } else { + audioEffectRotation->Init(); + } #endif isInitialized_ = true; } -- Gitee From 142b4b6727d04c339a1be4550c20cf5fc9e2b724 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 22 Feb 2024 11:18:12 +0800 Subject: [PATCH 23/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_hdi_param.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index 2932718455..622e793093 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -26,9 +26,13 @@ AudioEffectHdiParam::AudioEffectHdiParam() AUDIO_DEBUG_LOG("constructor."); libHdiControls_.clear(); int32_t ret = memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); - CHECK_AND_RETURN_LOG(ret == 0, "hdi constructor memcpy input failed"); + if (ret == 0) { + AUDIO_DEBUG_LOG("hdi constructor memset input failed"); + } ret = memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); - CHECK_AND_RETURN_LOG(ret == 0, "hdi constructor memcpy output failed"); + if (ret == 0) { + AUDIO_DEBUG_LOG("hdi constructor memset output failed"); + } replyLen_ = GET_HDI_BUFFER_LEN; hdiModel_ = nullptr; } -- Gitee From 292e786078ca889239927b9755c404700e2ec769 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 22 Feb 2024 11:48:07 +0800 Subject: [PATCH 24/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 2 -- 1 file changed, 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 6af0b3b17b..b72ebcbd07 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -459,7 +459,6 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr #ifdef WINDOW_MANAGER_ENABLE AudioEffectRotation *audioEffectRotation = AudioEffectRotation::GetInstance(); if (audioEffectRotation == nullptr) { - AUDIO_DEBUG_LOG("null audioEffectRotation"); *data++ = 0; } else { *data++ = audioEffectRotation->GetRotation(); @@ -470,7 +469,6 @@ void AudioEffectChain::AddEffectHandle(AudioEffectHandle handle, AudioEffectLibr AUDIO_DEBUG_LOG("set ap integration rotation: %{public}u", *(data - 1)); AudioEffectVolume *audioEffectVolume = AudioEffectVolume::GetInstance(); if (audioEffectVolume == nullptr) { - AUDIO_DEBUG_LOG("null audioEffectVolume"); *data++ = 0; } else { *data++ = audioEffectVolume->GetApVolume(sceneType); -- Gitee From ec7550be3b0333805d563f762b964d7cbca60016 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 22 Feb 2024 13:02:57 +0800 Subject: [PATCH 25/25] transmit volume and rotation state Signed-off-by: yaojingyu2008 --- .../native/audioeffect/include/audio_effect_hdi_param.h | 2 +- frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h index f196a947e7..8ebc0c3906 100644 --- a/frameworks/native/audioeffect/include/audio_effect_hdi_param.h +++ b/frameworks/native/audioeffect/include/audio_effect_hdi_param.h @@ -25,12 +25,12 @@ namespace OHOS { namespace AudioStandard { class AudioEffectHdiParam { public: - static const uint32_t GET_HDI_BUFFER_LEN = 10; AudioEffectHdiParam(); ~AudioEffectHdiParam(); void InitHdi(); int32_t UpdateHdiState(int8_t *effectHdiInput); private: + static const uint32_t GET_HDI_BUFFER_LEN = 10; void CreateHdiControl(); int8_t input_[SEND_HDI_COMMAND_LEN]; int8_t output_[GET_HDI_BUFFER_LEN]; diff --git a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp index 622e793093..f376907ebc 100644 --- a/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_hdi_param.cpp @@ -27,11 +27,11 @@ AudioEffectHdiParam::AudioEffectHdiParam() libHdiControls_.clear(); int32_t ret = memset_s(static_cast(input_), sizeof(input_), 0, sizeof(input_)); if (ret == 0) { - AUDIO_DEBUG_LOG("hdi constructor memset input failed"); + AUDIO_ERR_LOG("hdi constructor memset input failed"); } ret = memset_s(static_cast(output_), sizeof(output_), 0, sizeof(output_)); if (ret == 0) { - AUDIO_DEBUG_LOG("hdi constructor memset output failed"); + AUDIO_ERR_LOG("hdi constructor memset output failed"); } replyLen_ = GET_HDI_BUFFER_LEN; hdiModel_ = nullptr; -- Gitee