From 3056ad0cda97ac9939ec693e134749fd88b5da6c Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 9 Sep 2025 18:55:35 +0800 Subject: [PATCH 01/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../include/audio_service_adapter.h | 8 +++++ .../include/pro_audio_service_adapter_impl.h | 2 +- .../src/pro_audio_service_adapter_impl.cpp | 6 ++++ .../include/audio_effect_chain_manager.h | 1 + .../src/audio_effect_chain_manager.cpp | 35 ++++++++++++++----- .../sink/multichannel_audio_render_sink.h | 6 +++- .../sink/multichannel_audio_render_sink.cpp | 24 +++++++++++++ .../manager/src/hpae_renderer_manager.cpp | 5 --- .../node/include/hpae_node_common.h | 1 - .../node/src/hpae_node_common.cpp | 27 +++----------- .../domain/pipe/src/audio_pipe_selector.cpp | 2 ++ .../volume/include/audio_adapter_manager.h | 1 + .../volume/include/iaudio_policy_interface.h | 2 ++ .../volume/src/audio_adapter_manager.cpp | 6 ++++ .../datashare/include/audio_policy_utils.h | 2 ++ .../datashare/src/audio_policy_utils.cpp | 4 +++ 16 files changed, 92 insertions(+), 40 deletions(-) diff --git a/frameworks/native/audioadapter/include/audio_service_adapter.h b/frameworks/native/audioadapter/include/audio_service_adapter.h index 35b6189dd3..48b894347d 100644 --- a/frameworks/native/audioadapter/include/audio_service_adapter.h +++ b/frameworks/native/audioadapter/include/audio_service_adapter.h @@ -242,6 +242,14 @@ public: * @return int32_t the result, only supports proaudio for now. */ virtual int32_t SetSystemVolumeToEffect(AudioStreamType streamType, float volume) NOT_SUPPORT_RET + + /** + * @brief Check is channelLayout support for multichannel render manager + * + * @return {@link true} if support, {@link false} otherwise + */ + virtual bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) NOT_SUPPORT_RET + virtual ~AudioServiceAdapter(); }; } // namespace AudioStandard diff --git a/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h b/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h index 8fed4960e8..811195ebdd 100644 --- a/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h +++ b/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h @@ -79,7 +79,7 @@ public: virtual void OnGetAudioEnhancePropertyCbV3(int32_t result) override; virtual void OnGetAudioEnhancePropertyCb(int32_t result) override; virtual void HandleSourceAudioStreamRemoved(uint32_t sessionId) override; - + virtual bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) override; private: std::mutex lock_; // for status operation wait and notify diff --git a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp index 695f6dc90d..741d06ddbd 100644 --- a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp @@ -569,6 +569,12 @@ int32_t ProAudioServiceAdapterImpl::SetSystemVolumeToEffect(AudioStreamType stre IHpaeManager::GetHpaeManager().SetEffectSystemVolume(streamType, volume); return SUCCESS; } + +bool ProAudioServiceAdapterImpl::IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) +{ + lock_guard lock(lock_); + return AudioEffectChainManager::GetInstance().IsChannelLayoutSupportForMultiChannel(channelLayout); +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 8405aedc45..1e49711590 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -159,6 +159,7 @@ public: ProcessClusterOperation CheckProcessClusterInstances(const std::string &sceneType); int32_t GetOutputChannelInfo(const std::string &sceneType, uint32_t &channels, uint64_t &channelLayout); int32_t DeleteStreamVolume(const std::string StringSessionID); + bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout); private: int32_t SetAudioEffectChainDynamic(std::string &sceneType, const std::string &effectMode); void UpdateSensorState(); diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index d20da21de6..a5f7d9dabf 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -482,8 +482,10 @@ int32_t AudioEffectChainManager::EffectDspVolumeUpdate(std::shared_ptr(&effectHdiInput_[1]))); - ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi volume failed"); + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi volume failed"); + return ERROR; + } } return SUCCESS; } @@ -615,9 +617,10 @@ int32_t AudioEffectChainManager::EffectDspRotationUpdate(std::shared_ptrUpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi rotation failed"); - + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi rotation failed"); + return ERROR; + } return SUCCESS; } @@ -814,8 +817,10 @@ int32_t AudioEffectChainManager::SetHdiParam(const AudioEffectScene &sceneType) effectHdiInput_[0] = HDI_ROOM_MODE; effectHdiInput_[1] = sceneType; AUDIO_PRERELEASE_LOGI("set hdi room mode sceneType: %{public}d", effectHdiInput_[1]); - int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERROR, "set hdi room mode failed, ret is %{public}d", ret); + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi room mode failed"); + return ERROR; + } return SUCCESS; } @@ -1374,7 +1379,7 @@ void AudioEffectChainManager::UpdateSpatializationEnabled(AudioSpatializationSta effectHdiInput_[0] = HDI_INIT; int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { - AUDIO_ERR_LOG("set hdi init failed, enter route of escape in ARM"); + AUDIO_WARNING_LOG("set hdi init failed, enter route of escape in ARM"); btOffloadEnabled_ = false; } else { AUDIO_INFO_LOG("set hdi init succeeded, normal spatialization entered"); @@ -1385,7 +1390,7 @@ void AudioEffectChainManager::UpdateSpatializationEnabled(AudioSpatializationSta AUDIO_INFO_LOG("set hdi destroy."); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { - AUDIO_ERR_LOG("set hdi destroy failed"); + AUDIO_WARNING_LOG("set hdi destroy failed"); } if (deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP) { AUDIO_INFO_LOG("delete all chains if device type is bt."); @@ -2015,5 +2020,17 @@ int32_t AudioEffectChainManager::EffectApAbsVolumeStateUpdate(const bool absVolu return SUCCESS; } + +bool AudioEffectChainManager::IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) +{ + effectHdiInput_[0] = HDI_QUERY_CHANNELLAYOUT; + uint64_t* tempChannelLayout = reinterpret_cast(effectHdiInput_ + 1); + *tempChannelLayout = channelLayout; + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("query channel layout support failed :%{public}u", channelLayout); + return false; + } + return true; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h b/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h index 5d2f9290bb..7a50ed2afe 100644 --- a/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h +++ b/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h @@ -77,7 +77,7 @@ public: void DumpInfo(std::string &dumpString) override; void SetDmDeviceType(uint16_t dmDeviceType, DeviceType deviceType) override; - + int32_t SetSinkMuteForSwitchDevice(bool mute) override; private: static uint32_t PcmFormatToBit(AudioSampleFormat format); static AudioFormat ConvertToHdiFormat(AudioSampleFormat format); @@ -147,6 +147,10 @@ private: DeviceType currentActiveDevice_ = DEVICE_TYPE_NONE; AudioScene currentAudioScene_ = AUDIO_SCENE_DEFAULT; std::mutex sinkMutex_; + // for device switch + std::mutex switchDeviceMutex_; + int32_t muteCount_ = 0; + std::atomic switchDeviceMute_ = false; }; } // namespace AudioStandard diff --git a/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp b/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp index 4f0f36ddce..ad28926a64 100644 --- a/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp +++ b/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp @@ -725,5 +725,29 @@ void MultichannelAudioRenderSink::UpdateSinkState(bool started) started); } +int32_t MultichannelAudioRenderSink::SetSinkMuteForSwitchDevice(bool mute) +{ + std::lock_guard lock(switchDeviceMutex_); + AUDIO_INFO_LOG("set multichannel mute %{public}d", mute); + + if (mute) { + muteCount_++; + if (switchDeviceMute_) { + AUDIO_INFO_LOG("multichannel already muted"); + return SUCCESS; + } + switchDeviceMute_ = true; + } else { + muteCount_--; + if (muteCount_ > 0) { + AUDIO_WARNING_LOG("multichannel not all unmuted"); + return SUCCESS; + } + switchDeviceMute_ = false; + muteCount_ = 0; + } + + return SUCCESS; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_engine/manager/src/hpae_renderer_manager.cpp b/services/audio_engine/manager/src/hpae_renderer_manager.cpp index 5322812359..2fa5436aed 100644 --- a/services/audio_engine/manager/src/hpae_renderer_manager.cpp +++ b/services/audio_engine/manager/src/hpae_renderer_manager.cpp @@ -442,11 +442,6 @@ int32_t HpaeRendererManager::DeleteProcessCluster(uint32_t sessionId) if (outputCluster_ != nullptr) { outputCluster_->DisConnect(sceneClusterMap_[sceneType]); } - // for collaboration - if (sceneType == HPAE_SCENE_COLLABORATIVE && hpaeCoBufferNode_ != nullptr) { - hpaeCoBufferNode_->DisConnect(sceneClusterMap_[sceneType]); - TriggerCallback(DISCONNECT_CO_BUFFER_NODE, hpaeCoBufferNode_); - } sceneClusterMap_[sceneType]->SetConnectedFlag(false); } } diff --git a/services/audio_engine/node/include/hpae_node_common.h b/services/audio_engine/node/include/hpae_node_common.h index 81a59eabf6..441dd70d8f 100644 --- a/services/audio_engine/node/include/hpae_node_common.h +++ b/services/audio_engine/node/include/hpae_node_common.h @@ -36,7 +36,6 @@ uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo); size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo); std::string ConvertSessionState2Str(HpaeSessionState state); std::string ConvertStreamManagerState2Str(StreamManagerState state); -void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo); int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo); diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index 2de3e7167d..f309c3ef1a 100644 --- a/services/audio_engine/node/src/hpae_node_common.cpp +++ b/services/audio_engine/node/src/hpae_node_common.cpp @@ -285,27 +285,6 @@ AudioSampleFormat TransFormatFromStringToEnum(std::string format) return static_cast(g_formatFromParserStrToEnum[format]); } -void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) -{ - if (sinkInfo.deviceName == "DP_MCH_speaker") { - sinkInfo.channelLayout = static_cast(StringToNum(audioModuleInfo.channelLayout)); - return; - } - if (sinkInfo.deviceName != "MCH_Speaker") { - return; - } - sinkInfo.channels = static_cast(DEFAULT_MULTICHANNEL_NUM); - sinkInfo.channelLayout = DEFAULT_MULTICHANNEL_CHANNELLAYOUT; - sinkInfo.frameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * sinkInfo.samplingRate / MS_PER_SECOND; - sinkInfo.volume = MAX_SINK_VOLUME_LEVEL; - AUDIO_INFO_LOG("adjust MCH SINK info ch: %{public}u, channelLayout: %{public}" PRIu64 - " frameLen: %{public}zu volume %{public}f", - sinkInfo.channels, - sinkInfo.channelLayout, - sinkInfo.frameLen, - sinkInfo.volume); -} - int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) { if (g_formatFromParserStrToEnum.find(audioModuleInfo.format) == g_formatFromParserStrToEnum.end()) { @@ -332,7 +311,7 @@ int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, Hp "channels or format is invalid"); sinkInfo.frameLen = static_cast(bufferSize) / (sinkInfo.channels * static_cast(GetSizeFromFormat(sinkInfo.format))); - sinkInfo.channelLayout = 0ULL; + sinkInfo.channelLayout = static_cast(StringToNum(audioModuleInfo.channelLayout)); sinkInfo.deviceType = static_cast(StringToNum(audioModuleInfo.deviceType)); sinkInfo.volume = MAX_SINK_VOLUME_LEVEL; sinkInfo.openMicSpeaker = static_cast(StringToNum(audioModuleInfo.OpenMicSpeaker)); @@ -341,10 +320,12 @@ int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, Hp sinkInfo.sinkLatency = static_cast(StringToNum(audioModuleInfo.sinkLatency)); sinkInfo.fixedLatency = static_cast(StringToNum(audioModuleInfo.fixedLatency)); sinkInfo.deviceName = audioModuleInfo.name; - AdjustMchSinkInfo(audioModuleInfo, sinkInfo); if (audioModuleInfo.needEmptyChunk) { sinkInfo.needEmptyChunk = audioModuleInfo.needEmptyChunk.value(); } + AUDIO_INFO_LOG("sink info ch: %{public}u, channelLayout: %{public}" PRIu64, + sinkInfo.channels, + sinkInfo.channelLayout); return SUCCESS; } diff --git a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp index 34fc63c499..472ce38a1a 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp @@ -468,6 +468,8 @@ static void FillSpecialPipeInfo(AudioPipeInfo &info, std::shared_ptrbufferSize_ / std::stoul(info.moduleInfo_.channels)) * STEREO)); AUDIO_INFO_LOG("Buffer size: %{public}s", info.moduleInfo_.bufferSize.c_str()); + info.moduleInfo_.channelLayout = + AudioPolicyUtils::GetInstance().UpdateMultiChannelModuleInfo(info, streamPropInfo->channelLayout_); } else if (pipeInfoPtr->name_ == "offload_output") { info.moduleInfo_.className = "offload"; info.moduleInfo_.offloadEnable = "1"; diff --git a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h index fdcea314e5..6d7fabb91e 100644 --- a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h +++ b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h @@ -306,6 +306,7 @@ public: void SaveSystemVolumeForEffect(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel); int32_t GetSystemVolumeForEffect(DeviceType deviceType, AudioStreamType streamType); int32_t SetSystemVolumeToEffect(AudioStreamType streamType, float volume); + bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout); private: friend class PolicyCallbackImpl; diff --git a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h index 8be01d59d3..b4a8351c76 100644 --- a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h +++ b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h @@ -257,6 +257,8 @@ public: virtual float CalculateVolumeDbNonlinear(AudioStreamType streamType, DeviceType deviceType, int32_t volumeLevel) = 0; + + virtual bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) = 0; }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp index 6a766478dd..16d72cbd4f 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp @@ -3404,6 +3404,12 @@ int32_t AudioAdapterManager::SetSystemVolumeToEffect(AudioStreamType streamType, CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERROR, "audioServiceAdapter is null"); return audioServiceAdapter_->SetSystemVolumeToEffect(streamType, volume); } + +bool AudioAdapterManager::IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) +{ + CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERROR, "audioServiceAdapter is null"); + return audioServiceAdapter_->IsChannelLayoutSupportForMultiChannel(channelLayout); +} // LCOV_EXCL_STOP } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h b/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h index b47ce40aa9..2fbd5d4ae0 100644 --- a/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h +++ b/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h @@ -34,6 +34,7 @@ #include "audio_a2dp_offload_flag.h" #include "audio_policy_config_manager.h" +#include "audio_pipe_info.h" namespace OHOS { namespace AudioStandard { @@ -94,6 +95,7 @@ public: bool IsSupportedNearlink(const std::string &bundleName, int32_t apiVersion, bool hasSystemPermission); bool IsWirelessDevice(DeviceType deviceType); + void UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout); private: AudioPolicyUtils() : streamCollector_(AudioStreamCollector::GetAudioStreamCollector()), audioStateManager_(AudioStateManager::GetAudioStateManager()), diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index 3c4c7f74e2..b2749d3135 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -793,5 +793,9 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) } } +AudioChannelLayout UpdateMultiChannelModuleInfo(AudioChannelLayout channelLayout) +{ + if (AudioPolicyManagerFactory::GetAudioPolicyManager()->) +} } // namespace AudioStandard } // namespace OHOS -- Gitee From d8bd22ea1acf0f7d8c6b283f07741da7ee90b535 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 9 Sep 2025 18:55:35 +0800 Subject: [PATCH 02/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../include/audio_service_adapter.h | 8 ++ .../include/pro_audio_service_adapter_impl.h | 2 +- .../src/pro_audio_service_adapter_impl.cpp | 6 ++ .../pro_audio_service_adapter_unit_test.cpp | 15 ++++ .../include/audio_effect_chain_adapter.h | 1 - .../include/audio_effect_chain_manager.h | 2 +- .../src/audio_effect_chain_adapter.cpp | 12 --- .../src/audio_effect_chain_manager.cpp | 81 ++++++------------- .../sink/multichannel_audio_render_sink.h | 6 +- .../sink/multichannel_audio_render_sink.cpp | 29 ++++++- .../manager/src/hpae_renderer_manager.cpp | 5 -- .../node/include/hpae_node_common.h | 1 - .../node/src/hpae_node_common.cpp | 27 +------ .../domain/pipe/src/audio_pipe_selector.cpp | 2 + .../volume/include/audio_adapter_manager.h | 1 + .../volume/include/iaudio_policy_interface.h | 2 + .../volume/src/audio_adapter_manager.cpp | 6 ++ .../datashare/include/audio_policy_utils.h | 2 + .../datashare/src/audio_policy_utils.cpp | 9 +++ 19 files changed, 114 insertions(+), 103 deletions(-) diff --git a/frameworks/native/audioadapter/include/audio_service_adapter.h b/frameworks/native/audioadapter/include/audio_service_adapter.h index 35b6189dd3..6b368ae881 100644 --- a/frameworks/native/audioadapter/include/audio_service_adapter.h +++ b/frameworks/native/audioadapter/include/audio_service_adapter.h @@ -242,6 +242,14 @@ public: * @return int32_t the result, only supports proaudio for now. */ virtual int32_t SetSystemVolumeToEffect(AudioStreamType streamType, float volume) NOT_SUPPORT_RET + + /** + * @brief Check is channelLayout support for multichannel render manager + * + * @return {@link true} if support, {@link false} otherwise + */ + virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) NOT_SUPPORT_RET + virtual ~AudioServiceAdapter(); }; } // namespace AudioStandard diff --git a/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h b/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h index 8fed4960e8..3d33877599 100644 --- a/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h +++ b/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h @@ -79,7 +79,7 @@ public: virtual void OnGetAudioEnhancePropertyCbV3(int32_t result) override; virtual void OnGetAudioEnhancePropertyCb(int32_t result) override; virtual void HandleSourceAudioStreamRemoved(uint32_t sessionId) override; - + virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) override; private: std::mutex lock_; // for status operation wait and notify diff --git a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp index 695f6dc90d..8036725fb6 100644 --- a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp @@ -569,6 +569,12 @@ int32_t ProAudioServiceAdapterImpl::SetSystemVolumeToEffect(AudioStreamType stre IHpaeManager::GetHpaeManager().SetEffectSystemVolume(streamType, volume); return SUCCESS; } + +bool ProAudioServiceAdapterImpl::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + lock_guard lock(lock_); + return AudioEffectChainManager::GetInstance().IsChannelLayoutSupportForDspEffect(channelLayout); +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp index 6b22cecd3d..fe80abf994 100644 --- a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp +++ b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp @@ -373,5 +373,20 @@ HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_ReloadAudioPort_005, TestSize portId = impl_->ReloadAudioPort(moduleInfo.lib, moduleInfo); EXPECT_GE(0, portId); } + +/** + * @tc.name: Pro_Audio_IsChannelLayoutSupportForMultiChannel_001 + * @tc.desc: test check if channel layout support for multi channel + * @tc.type: FUNC + */ +HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_IsChannelLayoutSupportForMultiChannel_001, TestSize.Level1) +{ + AudioChannelLayout channelLayout = CH_LAYOUT_5POINT1; + int32_t ret = impl_->IsChannelLayoutSupportForMultiChannel(moduleInfo.lib, moduleInfo); + EXPECT_GE(SUCCESS, ret); + channelLayout = CH_LAYOUT_4POINT0; + ret = impl_->IsChannelLayoutSupportForMultiChannel(moduleInfo.lib, moduleInfo); + EXPECT_GE(ERROR, ret); +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h b/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h index beb67f05ab..2fe8a3c4bf 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_adapter.h @@ -63,7 +63,6 @@ void EffectChainManagerEffectUpdate(void); bool EffectChainManagerSceneCheck(const char *sinkSceneType, const char *sceneType); uint32_t EffectChainManagerGetSceneCount(const char *sceneType); void EffectChainManagerStreamUsageUpdate(); -int32_t EffectChainManagerQueryHdiSupportedChannelLayout(uint32_t *channels, uint64_t *channelLayout); #ifdef __cplusplus } #endif diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 8405aedc45..51433b935c 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -154,11 +154,11 @@ public: void UpdateStreamUsage(); int32_t InitEffectBuffer(const std::string &sessionID); int32_t QueryEffectChannelInfo(const std::string &sceneType, uint32_t &channels, uint64_t &channelLayout); - int32_t QueryHdiSupportedChannelInfo(uint32_t &channels, uint64_t &channelLayout); void LoadEffectProperties(); ProcessClusterOperation CheckProcessClusterInstances(const std::string &sceneType); int32_t GetOutputChannelInfo(const std::string &sceneType, uint32_t &channels, uint64_t &channelLayout); int32_t DeleteStreamVolume(const std::string StringSessionID); + bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout); private: int32_t SetAudioEffectChainDynamic(std::string &sceneType, const std::string &effectMode); void UpdateSensorState(); diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_adapter.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_adapter.cpp index b00485e877..6cd520fc42 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_adapter.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_adapter.cpp @@ -297,18 +297,6 @@ int32_t EffectChainManagerReturnEffectChannelInfo(const char *sceneType, uint32_ return audioEffectChainManager->QueryEffectChannelInfo(sceneTypeString, chans, chLayout); } -int32_t EffectChainManagerQueryHdiSupportedChannelLayout(uint32_t *channels, uint64_t *channelLayout) -{ - if (channels == nullptr || channelLayout == nullptr) { - return ERROR; - } - - AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); - uint32_t &chans = *channels; - uint64_t &chLayout = *channelLayout; - return audioEffectChainManager->QueryHdiSupportedChannelInfo(chans, chLayout); -} - int32_t EffectChainManagerReturnMultiChannelInfo(uint32_t *channels, uint64_t *channelLayout) { if (channels == nullptr || channelLayout == nullptr) { diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index d20da21de6..bf4a6d186f 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -482,8 +482,10 @@ int32_t AudioEffectChainManager::EffectDspVolumeUpdate(std::shared_ptr(&effectHdiInput_[1]))); - ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi volume failed"); + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi volume failed"); + return ERROR; + } } return SUCCESS; } @@ -615,9 +617,10 @@ int32_t AudioEffectChainManager::EffectDspRotationUpdate(std::shared_ptrUpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi rotation failed"); - + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi rotation failed"); + return ERROR; + } return SUCCESS; } @@ -814,58 +817,12 @@ int32_t AudioEffectChainManager::SetHdiParam(const AudioEffectScene &sceneType) effectHdiInput_[0] = HDI_ROOM_MODE; effectHdiInput_[1] = sceneType; AUDIO_PRERELEASE_LOGI("set hdi room mode sceneType: %{public}d", effectHdiInput_[1]); - int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERROR, "set hdi room mode failed, ret is %{public}d", ret); - return SUCCESS; -} - -// LCOV_EXCL_START -int32_t AudioEffectChainManager::QueryHdiSupportedChannelInfo(uint32_t &channels, uint64_t &channelLayout) -{ - std::lock_guard lock(dynamicMutex_); - uint32_t tmpChannelCount = DEFAULT_NUM_CHANNEL; - uint64_t tmpChannelLayout = DEFAULT_NUM_CHANNELLAYOUT; - if (sceneTypeToSessionIDMap_.size() == 0) { - return SUCCESS; - } - 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]; - if (info.channels > tmpChannelCount && - info.channels <= DSP_MAX_NUM_CHANNEL && - !ExistAudioEffectChainInner(it->first, info.sceneMode)) { - tmpChannelCount = info.channels; - tmpChannelLayout = info.channelLayout; - } - } - } - if (tmpChannelLayout != channelLayout) { - if (!isInitialized_) { - if (initializedLogFlag_) { - AUDIO_ERR_LOG("audioEffectChainManager has not been initialized"); - initializedLogFlag_ = false; - } - return ERROR; - } - memset_s(static_cast(effectHdiInput_), sizeof(effectHdiInput_), 0, sizeof(effectHdiInput_)); - - effectHdiInput_[0] = HDI_QUERY_CHANNELLAYOUT; - uint64_t* tempChannelLayout = (uint64_t *)(effectHdiInput_ + 1); - *tempChannelLayout = tmpChannelLayout; - AUDIO_PRERELEASE_LOGI("set hdi channel: %{public}d", channels); - int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); - if (ret != SUCCESS) { - channels = DEFAULT_MCH_NUM_CHANNEL; - channelLayout = DEFAULT_MCH_NUM_CHANNELLAYOUT; - } else { - channels = tmpChannelCount; - channelLayout = tmpChannelLayout; - } + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi room mode failed"); + return ERROR; } return SUCCESS; } -// LCOV_EXCL_STOP // LCOV_EXCL_START void AudioEffectChainManager::UpdateSensorState() @@ -1374,7 +1331,7 @@ void AudioEffectChainManager::UpdateSpatializationEnabled(AudioSpatializationSta effectHdiInput_[0] = HDI_INIT; int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { - AUDIO_ERR_LOG("set hdi init failed, enter route of escape in ARM"); + AUDIO_WARNING_LOG("set hdi init failed, enter route of escape in ARM"); btOffloadEnabled_ = false; } else { AUDIO_INFO_LOG("set hdi init succeeded, normal spatialization entered"); @@ -1385,7 +1342,7 @@ void AudioEffectChainManager::UpdateSpatializationEnabled(AudioSpatializationSta AUDIO_INFO_LOG("set hdi destroy."); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { - AUDIO_ERR_LOG("set hdi destroy failed"); + AUDIO_WARNING_LOG("set hdi destroy failed"); } if (deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP) { AUDIO_INFO_LOG("delete all chains if device type is bt."); @@ -2015,5 +1972,17 @@ int32_t AudioEffectChainManager::EffectApAbsVolumeStateUpdate(const bool absVolu return SUCCESS; } + +bool AudioEffectChainManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + effectHdiInput_[0] = HDI_QUERY_CHANNELLAYOUT; + uint64_t* tempChannelLayout = reinterpret_cast(effectHdiInput_ + 1); + *tempChannelLayout = channelLayout; + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("query channel layout support failed :%{public}u", channelLayout); + return false; + } + return true; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h b/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h index 5d2f9290bb..7a50ed2afe 100644 --- a/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h +++ b/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h @@ -77,7 +77,7 @@ public: void DumpInfo(std::string &dumpString) override; void SetDmDeviceType(uint16_t dmDeviceType, DeviceType deviceType) override; - + int32_t SetSinkMuteForSwitchDevice(bool mute) override; private: static uint32_t PcmFormatToBit(AudioSampleFormat format); static AudioFormat ConvertToHdiFormat(AudioSampleFormat format); @@ -147,6 +147,10 @@ private: DeviceType currentActiveDevice_ = DEVICE_TYPE_NONE; AudioScene currentAudioScene_ = AUDIO_SCENE_DEFAULT; std::mutex sinkMutex_; + // for device switch + std::mutex switchDeviceMutex_; + int32_t muteCount_ = 0; + std::atomic switchDeviceMute_ = false; }; } // namespace AudioStandard diff --git a/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp b/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp index 4f0f36ddce..812a9d286f 100644 --- a/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp +++ b/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp @@ -218,8 +218,9 @@ int32_t MultichannelAudioRenderSink::RenderFrame(char &data, uint64_t len, uint6 CheckUpdateState(&data, len); if (switchDeviceMute_) { Trace trace("MultichannelAudioRenderSink::RenderFrame::switch"); - writeLen = len; - return SUCCESS; + if (memset_s(reinterpret_cast(&data), static_cast(len), 0, static_cast(len)) != EOK) { + AUDIO_WARNING_LOG("call memset_s fail"); + } } if (emptyFrameCount_ > 0) { Trace trace("MultichannelAudioRenderSink::RenderFrame::renderEmpty"); @@ -725,5 +726,29 @@ void MultichannelAudioRenderSink::UpdateSinkState(bool started) started); } +int32_t MultichannelAudioRenderSink::SetSinkMuteForSwitchDevice(bool mute) +{ + std::lock_guard lock(switchDeviceMutex_); + AUDIO_INFO_LOG("set multichannel mute %{public}d", mute); + + if (mute) { + muteCount_++; + if (switchDeviceMute_) { + AUDIO_INFO_LOG("multichannel already muted"); + return SUCCESS; + } + switchDeviceMute_ = true; + } else { + muteCount_--; + if (muteCount_ > 0) { + AUDIO_WARNING_LOG("multichannel not all unmuted"); + return SUCCESS; + } + switchDeviceMute_ = false; + muteCount_ = 0; + } + + return SUCCESS; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_engine/manager/src/hpae_renderer_manager.cpp b/services/audio_engine/manager/src/hpae_renderer_manager.cpp index 5322812359..2fa5436aed 100644 --- a/services/audio_engine/manager/src/hpae_renderer_manager.cpp +++ b/services/audio_engine/manager/src/hpae_renderer_manager.cpp @@ -442,11 +442,6 @@ int32_t HpaeRendererManager::DeleteProcessCluster(uint32_t sessionId) if (outputCluster_ != nullptr) { outputCluster_->DisConnect(sceneClusterMap_[sceneType]); } - // for collaboration - if (sceneType == HPAE_SCENE_COLLABORATIVE && hpaeCoBufferNode_ != nullptr) { - hpaeCoBufferNode_->DisConnect(sceneClusterMap_[sceneType]); - TriggerCallback(DISCONNECT_CO_BUFFER_NODE, hpaeCoBufferNode_); - } sceneClusterMap_[sceneType]->SetConnectedFlag(false); } } diff --git a/services/audio_engine/node/include/hpae_node_common.h b/services/audio_engine/node/include/hpae_node_common.h index 81a59eabf6..441dd70d8f 100644 --- a/services/audio_engine/node/include/hpae_node_common.h +++ b/services/audio_engine/node/include/hpae_node_common.h @@ -36,7 +36,6 @@ uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo); size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo); std::string ConvertSessionState2Str(HpaeSessionState state); std::string ConvertStreamManagerState2Str(StreamManagerState state); -void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo); int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo); diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index 2de3e7167d..f309c3ef1a 100644 --- a/services/audio_engine/node/src/hpae_node_common.cpp +++ b/services/audio_engine/node/src/hpae_node_common.cpp @@ -285,27 +285,6 @@ AudioSampleFormat TransFormatFromStringToEnum(std::string format) return static_cast(g_formatFromParserStrToEnum[format]); } -void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) -{ - if (sinkInfo.deviceName == "DP_MCH_speaker") { - sinkInfo.channelLayout = static_cast(StringToNum(audioModuleInfo.channelLayout)); - return; - } - if (sinkInfo.deviceName != "MCH_Speaker") { - return; - } - sinkInfo.channels = static_cast(DEFAULT_MULTICHANNEL_NUM); - sinkInfo.channelLayout = DEFAULT_MULTICHANNEL_CHANNELLAYOUT; - sinkInfo.frameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * sinkInfo.samplingRate / MS_PER_SECOND; - sinkInfo.volume = MAX_SINK_VOLUME_LEVEL; - AUDIO_INFO_LOG("adjust MCH SINK info ch: %{public}u, channelLayout: %{public}" PRIu64 - " frameLen: %{public}zu volume %{public}f", - sinkInfo.channels, - sinkInfo.channelLayout, - sinkInfo.frameLen, - sinkInfo.volume); -} - int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) { if (g_formatFromParserStrToEnum.find(audioModuleInfo.format) == g_formatFromParserStrToEnum.end()) { @@ -332,7 +311,7 @@ int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, Hp "channels or format is invalid"); sinkInfo.frameLen = static_cast(bufferSize) / (sinkInfo.channels * static_cast(GetSizeFromFormat(sinkInfo.format))); - sinkInfo.channelLayout = 0ULL; + sinkInfo.channelLayout = static_cast(StringToNum(audioModuleInfo.channelLayout)); sinkInfo.deviceType = static_cast(StringToNum(audioModuleInfo.deviceType)); sinkInfo.volume = MAX_SINK_VOLUME_LEVEL; sinkInfo.openMicSpeaker = static_cast(StringToNum(audioModuleInfo.OpenMicSpeaker)); @@ -341,10 +320,12 @@ int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, Hp sinkInfo.sinkLatency = static_cast(StringToNum(audioModuleInfo.sinkLatency)); sinkInfo.fixedLatency = static_cast(StringToNum(audioModuleInfo.fixedLatency)); sinkInfo.deviceName = audioModuleInfo.name; - AdjustMchSinkInfo(audioModuleInfo, sinkInfo); if (audioModuleInfo.needEmptyChunk) { sinkInfo.needEmptyChunk = audioModuleInfo.needEmptyChunk.value(); } + AUDIO_INFO_LOG("sink info ch: %{public}u, channelLayout: %{public}" PRIu64, + sinkInfo.channels, + sinkInfo.channelLayout); return SUCCESS; } diff --git a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp index 34fc63c499..472ce38a1a 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp @@ -468,6 +468,8 @@ static void FillSpecialPipeInfo(AudioPipeInfo &info, std::shared_ptrbufferSize_ / std::stoul(info.moduleInfo_.channels)) * STEREO)); AUDIO_INFO_LOG("Buffer size: %{public}s", info.moduleInfo_.bufferSize.c_str()); + info.moduleInfo_.channelLayout = + AudioPolicyUtils::GetInstance().UpdateMultiChannelModuleInfo(info, streamPropInfo->channelLayout_); } else if (pipeInfoPtr->name_ == "offload_output") { info.moduleInfo_.className = "offload"; info.moduleInfo_.offloadEnable = "1"; diff --git a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h index fdcea314e5..fae5c03cef 100644 --- a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h +++ b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h @@ -306,6 +306,7 @@ public: void SaveSystemVolumeForEffect(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel); int32_t GetSystemVolumeForEffect(DeviceType deviceType, AudioStreamType streamType); int32_t SetSystemVolumeToEffect(AudioStreamType streamType, float volume); + bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout); private: friend class PolicyCallbackImpl; diff --git a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h index 8be01d59d3..5e3fa7c683 100644 --- a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h +++ b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h @@ -257,6 +257,8 @@ public: virtual float CalculateVolumeDbNonlinear(AudioStreamType streamType, DeviceType deviceType, int32_t volumeLevel) = 0; + + virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) = 0; }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp index 6a766478dd..3cee7c3aaa 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp @@ -3404,6 +3404,12 @@ int32_t AudioAdapterManager::SetSystemVolumeToEffect(AudioStreamType streamType, CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERROR, "audioServiceAdapter is null"); return audioServiceAdapter_->SetSystemVolumeToEffect(streamType, volume); } + +bool AudioAdapterManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERROR, "audioServiceAdapter is null"); + return audioServiceAdapter_->IsChannelLayoutSupportForDspEffect(channelLayout); +} // LCOV_EXCL_STOP } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h b/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h index b47ce40aa9..2fbd5d4ae0 100644 --- a/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h +++ b/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h @@ -34,6 +34,7 @@ #include "audio_a2dp_offload_flag.h" #include "audio_policy_config_manager.h" +#include "audio_pipe_info.h" namespace OHOS { namespace AudioStandard { @@ -94,6 +95,7 @@ public: bool IsSupportedNearlink(const std::string &bundleName, int32_t apiVersion, bool hasSystemPermission); bool IsWirelessDevice(DeviceType deviceType); + void UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout); private: AudioPolicyUtils() : streamCollector_(AudioStreamCollector::GetAudioStreamCollector()), audioStateManager_(AudioStateManager::GetAudioStateManager()), diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index 3c4c7f74e2..0ac0462c5a 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -793,5 +793,14 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) } } +void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout) +{ + if (!AudioPolicyManagerFactory::GetAudioPolicyManager()->IsChannelLayoutSupportForDspEffect(channelLayout)) { + AUDIO_INFO_LOG("not support channelLayout:%{public}u, use default 5.1", channelLayout); + info.moduleInfo_.channels = "6"; // default 5.1 + info.moduleInfo_.channelLayout_ = AUDIO_CHANNEL_LAYOUT_5_1; + } + info.moduleInfo_.channelLayout_ = channelLayout; +} } // namespace AudioStandard } // namespace OHOS -- Gitee From 12766489e9011d39cd466ba541e224805c3f64d1 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 9 Sep 2025 19:48:17 +0800 Subject: [PATCH 03/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../include/audio_service_adapter.h | 4 - .../include/pro_audio_service_adapter_impl.h | 4 - .../src/pro_audio_service_adapter_impl.cpp | 7 -- .../pro_audio_service_adapter_unit_test.cpp | 4 +- .../include/audio_effect_chain_manager.h | 4 - .../src/audio_effect_chain_manager.cpp | 54 ----------- .../audio_effect_chain_manager_unit_test.cpp | 97 ------------------- .../volume/include/audio_adapter_manager.h | 4 - .../volume/include/iaudio_policy_interface.h | 4 - .../volume/src/audio_adapter_manager.cpp | 7 -- .../datashare/src/audio_policy_utils.cpp | 6 -- 11 files changed, 2 insertions(+), 193 deletions(-) diff --git a/frameworks/native/audioadapter/include/audio_service_adapter.h b/frameworks/native/audioadapter/include/audio_service_adapter.h index ac9e2c549f..6b368ae881 100644 --- a/frameworks/native/audioadapter/include/audio_service_adapter.h +++ b/frameworks/native/audioadapter/include/audio_service_adapter.h @@ -248,11 +248,7 @@ public: * * @return {@link true} if support, {@link false} otherwise */ -<<<<<<< HEAD virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) NOT_SUPPORT_RET -======= - virtual bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) NOT_SUPPORT_RET ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c virtual ~AudioServiceAdapter(); }; diff --git a/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h b/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h index ba6f2cedc5..3d33877599 100644 --- a/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h +++ b/frameworks/native/audioadapter/include/pro_audio_service_adapter_impl.h @@ -79,11 +79,7 @@ public: virtual void OnGetAudioEnhancePropertyCbV3(int32_t result) override; virtual void OnGetAudioEnhancePropertyCb(int32_t result) override; virtual void HandleSourceAudioStreamRemoved(uint32_t sessionId) override; -<<<<<<< HEAD virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) override; -======= - virtual bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) override; ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c private: std::mutex lock_; // for status operation wait and notify diff --git a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp index 55b5cc9293..8036725fb6 100644 --- a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp @@ -570,17 +570,10 @@ int32_t ProAudioServiceAdapterImpl::SetSystemVolumeToEffect(AudioStreamType stre return SUCCESS; } -<<<<<<< HEAD bool ProAudioServiceAdapterImpl::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) { lock_guard lock(lock_); return AudioEffectChainManager::GetInstance().IsChannelLayoutSupportForDspEffect(channelLayout); -======= -bool ProAudioServiceAdapterImpl::IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) -{ - lock_guard lock(lock_); - return AudioEffectChainManager::GetInstance().IsChannelLayoutSupportForMultiChannel(channelLayout); ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c } } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp index fe80abf994..8e6dcf5b03 100644 --- a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp +++ b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp @@ -375,8 +375,8 @@ HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_ReloadAudioPort_005, TestSize } /** - * @tc.name: Pro_Audio_IsChannelLayoutSupportForMultiChannel_001 - * @tc.desc: test check if channel layout support for multi channel + * @tc.name: Pro_Audio_IsChannelLayoutSupportForDspEffect_001 + * @tc.desc: test check if channel layout support for dsp * @tc.type: FUNC */ HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_IsChannelLayoutSupportForMultiChannel_001, TestSize.Level1) diff --git a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h index 424697782b..51433b935c 100644 --- a/frameworks/native/audioeffect/include/audio_effect_chain_manager.h +++ b/frameworks/native/audioeffect/include/audio_effect_chain_manager.h @@ -158,11 +158,7 @@ public: ProcessClusterOperation CheckProcessClusterInstances(const std::string &sceneType); int32_t GetOutputChannelInfo(const std::string &sceneType, uint32_t &channels, uint64_t &channelLayout); int32_t DeleteStreamVolume(const std::string StringSessionID); -<<<<<<< HEAD bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout); -======= - bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout); ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c private: int32_t SetAudioEffectChainDynamic(std::string &sceneType, const std::string &effectMode); void UpdateSensorState(); diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 5655cf02d5..bf4a6d186f 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -820,56 +820,6 @@ int32_t AudioEffectChainManager::SetHdiParam(const AudioEffectScene &sceneType) if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { AUDIO_WARNING_LOG("set hdi room mode failed"); return ERROR; -<<<<<<< HEAD -======= - } - return SUCCESS; -} - -// LCOV_EXCL_START -int32_t AudioEffectChainManager::QueryHdiSupportedChannelInfo(uint32_t &channels, uint64_t &channelLayout) -{ - std::lock_guard lock(dynamicMutex_); - uint32_t tmpChannelCount = DEFAULT_NUM_CHANNEL; - uint64_t tmpChannelLayout = DEFAULT_NUM_CHANNELLAYOUT; - if (sceneTypeToSessionIDMap_.size() == 0) { - return SUCCESS; - } - 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]; - if (info.channels > tmpChannelCount && - info.channels <= DSP_MAX_NUM_CHANNEL && - !ExistAudioEffectChainInner(it->first, info.sceneMode)) { - tmpChannelCount = info.channels; - tmpChannelLayout = info.channelLayout; - } - } - } - if (tmpChannelLayout != channelLayout) { - if (!isInitialized_) { - if (initializedLogFlag_) { - AUDIO_ERR_LOG("audioEffectChainManager has not been initialized"); - initializedLogFlag_ = false; - } - return ERROR; - } - memset_s(static_cast(effectHdiInput_), sizeof(effectHdiInput_), 0, sizeof(effectHdiInput_)); - - effectHdiInput_[0] = HDI_QUERY_CHANNELLAYOUT; - uint64_t* tempChannelLayout = (uint64_t *)(effectHdiInput_ + 1); - *tempChannelLayout = tmpChannelLayout; - AUDIO_PRERELEASE_LOGI("set hdi channel: %{public}d", channels); - int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); - if (ret != SUCCESS) { - channels = DEFAULT_MCH_NUM_CHANNEL; - channelLayout = DEFAULT_MCH_NUM_CHANNELLAYOUT; - } else { - channels = tmpChannelCount; - channelLayout = tmpChannelLayout; - } ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c } return SUCCESS; } @@ -2023,11 +1973,7 @@ int32_t AudioEffectChainManager::EffectApAbsVolumeStateUpdate(const bool absVolu return SUCCESS; } -<<<<<<< HEAD bool AudioEffectChainManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) -======= -bool AudioEffectChainManager::IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c { effectHdiInput_[0] = HDI_QUERY_CHANNELLAYOUT; uint64_t* tempChannelLayout = reinterpret_cast(effectHdiInput_ + 1); diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index 3a35b3446d..e2a43fa2ee 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -3259,103 +3259,6 @@ HWTEST(AudioEffectChainManagerUnitTest, SendEffectApVolume_003, TestSize.Level1) AudioEffectChainManager::GetInstance()->ResetInfo(); } -/** -* @tc.name : Test QueryHdiSupportedChannelInfo API -* @tc.number : QueryHdiSupportedChannelInfo_001 -* @tc.desc : Test QueryHdiSupportedChannelInfo interface. -*/ -HWTEST(AudioEffectChainManagerUnitTest, QueryHdiSupportedChannelInfo_001, TestSize.Level1) -{ - uint32_t channels = 0; - uint64_t channelLayout = 0; - auto ret = AudioEffectChainManager::GetInstance()->QueryHdiSupportedChannelInfo(channels, channelLayout); - EXPECT_EQ(ret, SUCCESS); - AudioEffectChainManager::GetInstance()->ResetInfo(); -} - -/** -* @tc.name : Test QueryHdiSupportedChannelInfo API -* @tc.number : QueryHdiSupportedChannelInfo_002 -* @tc.desc : Test QueryHdiSupportedChannelInfo interface. -*/ -HWTEST(AudioEffectChainManagerUnitTest, QueryHdiSupportedChannelInfo_002, TestSize.Level1) -{ - uint32_t channels = 0; - uint64_t channelLayout = 10; - SessionEffectInfo sessionEffectInfo; - sessionEffectInfo.channelLayout = 1; - std::set sceneType = {"123"}; - AudioEffectChainManager::GetInstance()->sceneTypeToSessionIDMap_.insert({"test", sceneType}); - AudioEffectChainManager::GetInstance()->sessionIDToEffectInfoMap_.insert({"123", sessionEffectInfo}); - - auto ret = AudioEffectChainManager::GetInstance()->QueryHdiSupportedChannelInfo(channels, channelLayout); - EXPECT_EQ(ret, ERROR); - AudioEffectChainManager::GetInstance()->ResetInfo(); -} - -/** -* @tc.name : Test QueryHdiSupportedChannelInfo API -* @tc.number : QueryHdiSupportedChannelInfo_003 -* @tc.desc : Test QueryHdiSupportedChannelInfo interface. -*/ -HWTEST(AudioEffectChainManagerUnitTest, QueryHdiSupportedChannelInfo_003, TestSize.Level1) -{ - uint32_t channels = 0; - uint64_t channelLayout = 10; - SessionEffectInfo sessionEffectInfo; - sessionEffectInfo.channelLayout = 1; - sessionEffectInfo.channels = 5; - std::set sceneType = {"123"}; - AudioEffectChainManager::GetInstance()->initializedLogFlag_ = false; - AudioEffectChainManager::GetInstance()->sceneTypeToSessionIDMap_.insert({"test", sceneType}); - AudioEffectChainManager::GetInstance()->sessionIDToEffectInfoMap_.insert({"123", sessionEffectInfo}); - - auto ret = AudioEffectChainManager::GetInstance()->QueryHdiSupportedChannelInfo(channels, channelLayout); - EXPECT_EQ(ret, ERROR); - AudioEffectChainManager::GetInstance()->ResetInfo(); -} - -/** -* @tc.name : Test QueryHdiSupportedChannelInfo API -* @tc.number : QueryHdiSupportedChannelInfo_004 -* @tc.desc : Test QueryHdiSupportedChannelInfo interface. -*/ -HWTEST(AudioEffectChainManagerUnitTest, QueryHdiSupportedChannelInfo_004, TestSize.Level1) -{ - uint32_t channels = 0; - uint64_t channelLayout = 10; - SessionEffectInfo sessionEffectInfo; - sessionEffectInfo.channelLayout = 1; - sessionEffectInfo.channels = 20; - std::set sceneType = {"123"}; - AudioEffectChainManager::GetInstance()->isInitialized_ = true; - AudioEffectChainManager::GetInstance()->sceneTypeToSessionIDMap_.insert({"test", sceneType}); - AudioEffectChainManager::GetInstance()->sessionIDToEffectInfoMap_.insert({"123", sessionEffectInfo}); - - auto ret = AudioEffectChainManager::GetInstance()->QueryHdiSupportedChannelInfo(channels, channelLayout); - EXPECT_EQ(ret, SUCCESS); - AudioEffectChainManager::GetInstance()->ResetInfo(); -} - -/** -* @tc.name : Test QueryHdiSupportedChannelInfo API -* @tc.number : QueryHdiSupportedChannelInfo_005 -* @tc.desc : Test QueryHdiSupportedChannelInfo interface. -*/ -HWTEST(AudioEffectChainManagerUnitTest, QueryHdiSupportedChannelInfo_005, TestSize.Level1) -{ - uint32_t channels = 0; - uint64_t channelLayout = CH_LAYOUT_STEREO; - SessionEffectInfo sessionEffectInfo; - sessionEffectInfo.channels = 0; - std::set sceneType = {"123"}; - AudioEffectChainManager::GetInstance()->sceneTypeToSessionIDMap_.insert({"test", sceneType}); - - auto ret = AudioEffectChainManager::GetInstance()->QueryHdiSupportedChannelInfo(channels, channelLayout); - EXPECT_EQ(ret, SUCCESS); - AudioEffectChainManager::GetInstance()->ResetInfo(); -} - /** * @tc.name : Test SendAudioParamToHDI API * @tc.number : SendAudioParamToHDI_001 diff --git a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h index d4c7a568a1..fae5c03cef 100644 --- a/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h +++ b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h @@ -306,11 +306,7 @@ public: void SaveSystemVolumeForEffect(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel); int32_t GetSystemVolumeForEffect(DeviceType deviceType, AudioStreamType streamType); int32_t SetSystemVolumeToEffect(AudioStreamType streamType, float volume); -<<<<<<< HEAD bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout); -======= - bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout); ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c private: friend class PolicyCallbackImpl; diff --git a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h index 8c61f73fcf..5e3fa7c683 100644 --- a/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h +++ b/services/audio_policy/server/domain/volume/include/iaudio_policy_interface.h @@ -258,11 +258,7 @@ public: virtual float CalculateVolumeDbNonlinear(AudioStreamType streamType, DeviceType deviceType, int32_t volumeLevel) = 0; -<<<<<<< HEAD virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) = 0; -======= - virtual bool IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) = 0; ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp index 04222691f7..3cee7c3aaa 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp @@ -3405,17 +3405,10 @@ int32_t AudioAdapterManager::SetSystemVolumeToEffect(AudioStreamType streamType, return audioServiceAdapter_->SetSystemVolumeToEffect(streamType, volume); } -<<<<<<< HEAD bool AudioAdapterManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) { CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERROR, "audioServiceAdapter is null"); return audioServiceAdapter_->IsChannelLayoutSupportForDspEffect(channelLayout); -======= -bool AudioAdapterManager::IsChannelLayoutSupportForMultiChannel(AudioChannelLayout channelLayout) -{ - CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERROR, "audioServiceAdapter is null"); - return audioServiceAdapter_->IsChannelLayoutSupportForMultiChannel(channelLayout); ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c } // LCOV_EXCL_STOP } // namespace AudioStandard diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index 67c8495bca..0ac0462c5a 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -793,7 +793,6 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) } } -<<<<<<< HEAD void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout) { if (!AudioPolicyManagerFactory::GetAudioPolicyManager()->IsChannelLayoutSupportForDspEffect(channelLayout)) { @@ -802,11 +801,6 @@ void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioCh info.moduleInfo_.channelLayout_ = AUDIO_CHANNEL_LAYOUT_5_1; } info.moduleInfo_.channelLayout_ = channelLayout; -======= -AudioChannelLayout UpdateMultiChannelModuleInfo(AudioChannelLayout channelLayout) -{ - if (AudioPolicyManagerFactory::GetAudioPolicyManager()->) ->>>>>>> 3056ad0cda97ac9939ec693e134749fd88b5da6c } } // namespace AudioStandard } // namespace OHOS -- Gitee From 35d892b156eac29f11e366c1ac3a13b8fbe657ec Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Tue, 9 Sep 2025 21:48:09 +0800 Subject: [PATCH 04/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../include/sink/multichannel_audio_render_sink.h | 5 +---- .../hdiadapter_new/sink/multichannel_audio_render_sink.cpp | 4 ++-- .../server/infra/datashare/src/audio_policy_utils.cpp | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h b/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h index 7a50ed2afe..87a3fb42b8 100644 --- a/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h +++ b/frameworks/native/hdiadapter_new/include/sink/multichannel_audio_render_sink.h @@ -130,11 +130,8 @@ private: int64_t last10FrameStartTime_ = 0; bool startUpdate_ = false; int renderFrameNum_ = 0; - // for device switch - std::mutex switchDeviceMutex_; - std::atomic switchDeviceMute_ = false; std::atomic emptyFrameCount_ = 0; - std::condition_variable switchDeviceCV_; + std::condition_variable updateActiveDeviceCV_; // for dfx log int32_t logMode_ = 0; std::string logUtilsTag_ = "MultichannelSink"; diff --git a/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp b/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp index 812a9d286f..ff48fd0e0e 100644 --- a/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp +++ b/frameworks/native/hdiadapter_new/sink/multichannel_audio_render_sink.cpp @@ -229,7 +229,7 @@ int32_t MultichannelAudioRenderSink::RenderFrame(char &data, uint64_t len, uint6 } --emptyFrameCount_; if (emptyFrameCount_ == 0) { - switchDeviceCV_.notify_all(); + updateActiveDeviceCV_.notify_all(); } } @@ -411,7 +411,7 @@ int32_t MultichannelAudioRenderSink::UpdateActiveDevice(std::vector emptyFrameCount_ = 5; // 5: frame count before update route std::unique_lock lock(switchDeviceMutex_); - switchDeviceCV_.wait_for(lock, std::chrono::milliseconds(SLEEP_TIME_FOR_EMPTY_FRAME), [this] { + updateActiveDeviceCV_.wait_for(lock, std::chrono::milliseconds(SLEEP_TIME_FOR_EMPTY_FRAME), [this] { if (emptyFrameCount_ == 0) { AUDIO_INFO_LOG("wait for empty frame end"); return true; diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index 0ac0462c5a..e470bf38c3 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -797,10 +797,10 @@ void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioCh { if (!AudioPolicyManagerFactory::GetAudioPolicyManager()->IsChannelLayoutSupportForDspEffect(channelLayout)) { AUDIO_INFO_LOG("not support channelLayout:%{public}u, use default 5.1", channelLayout); - info.moduleInfo_.channels = "6"; // default 5.1 - info.moduleInfo_.channelLayout_ = AUDIO_CHANNEL_LAYOUT_5_1; + info.moduleInfo_.channels = std::to_string(static_cast(CHANNEL_6)); // default 5.1 + info.moduleInfo_.channelLayout_ = std::to_string(static_cast(CH_LAYOUT_5POINT1)); } - info.moduleInfo_.channelLayout_ = channelLayout; + info.moduleInfo_.channelLayout_ = std::to_string(static_cast(channelLayout)); } } // namespace AudioStandard } // namespace OHOS -- Gitee From 91e092f37522eef1091bbb6432bf34452f4f672e Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 10 Sep 2025 14:15:03 +0800 Subject: [PATCH 05/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../audioadapter/src/pro_audio_service_adapter_impl.cpp | 3 ++- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 2 +- services/audio_engine/manager/include/hpae_manager_impl.h | 2 +- services/audio_engine/manager/include/i_hpae_manager.h | 1 + services/audio_engine/manager/src/hpae_manager.cpp | 5 +++++ services/audio_engine/node/src/hpae_node_common.cpp | 2 -- .../server/domain/pipe/src/audio_pipe_selector.cpp | 3 +-- .../server/infra/datashare/src/audio_policy_utils.cpp | 8 ++++---- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp index 8036725fb6..d4d5e07da3 100644 --- a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp @@ -30,6 +30,7 @@ #include #include #include "i_hpae_manager.h" +#include "audio_effect_chain_manager.h" using namespace std; using namespace OHOS::AudioStandard::HPAE; @@ -573,7 +574,7 @@ int32_t ProAudioServiceAdapterImpl::SetSystemVolumeToEffect(AudioStreamType stre bool ProAudioServiceAdapterImpl::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) { lock_guard lock(lock_); - return AudioEffectChainManager::GetInstance().IsChannelLayoutSupportForDspEffect(channelLayout); + return IHpaeManager::GetHpaeManager().IsChannelLayoutSupportForDspEffect(channelLayout); } } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index bf4a6d186f..46054c3e1d 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -1979,7 +1979,7 @@ bool AudioEffectChainManager::IsChannelLayoutSupportForDspEffect(AudioChannelLay uint64_t* tempChannelLayout = reinterpret_cast(effectHdiInput_ + 1); *tempChannelLayout = channelLayout; if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { - AUDIO_WARNING_LOG("query channel layout support failed :%{public}u", channelLayout); + AUDIO_WARNING_LOG("query channel layout support failed :%{public}lu", channelLayout); return false; } return true; diff --git a/services/audio_engine/manager/include/hpae_manager_impl.h b/services/audio_engine/manager/include/hpae_manager_impl.h index 45218dd808..605954117b 100644 --- a/services/audio_engine/manager/include/hpae_manager_impl.h +++ b/services/audio_engine/manager/include/hpae_manager_impl.h @@ -139,7 +139,7 @@ public: int32_t UpdateCollaborativeState(bool isCollaborationEnabled) override; void AddStreamVolumeToEffect(const std::string stringSessionID, const float streamVolume) override; void DeleteStreamVolumeToEffect(const std::string stringSessionID) override; - + bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) override; // interfaces for injector void UpdateAudioPortInfo(const uint32_t &sinkPortIndex, const AudioModuleInfo &audioPortInfo) override; void AddCaptureInjector( diff --git a/services/audio_engine/manager/include/i_hpae_manager.h b/services/audio_engine/manager/include/i_hpae_manager.h index 3f1872f329..4a121bfa78 100644 --- a/services/audio_engine/manager/include/i_hpae_manager.h +++ b/services/audio_engine/manager/include/i_hpae_manager.h @@ -143,6 +143,7 @@ public: virtual int32_t UpdateCollaborativeState(bool isCollaborationEnabled) = 0; virtual void AddStreamVolumeToEffect(const std::string stringSessionID, const float streamVolume) = 0; virtual void DeleteStreamVolumeToEffect(const std::string stringSessionID) = 0; + virtual bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) = 0; // interfaces for injector virtual void UpdateAudioPortInfo(const uint32_t &sinkPortIndex, const AudioModuleInfo &audioPortInfo) = 0; diff --git a/services/audio_engine/manager/src/hpae_manager.cpp b/services/audio_engine/manager/src/hpae_manager.cpp index 6f305ce793..ad735273c7 100644 --- a/services/audio_engine/manager/src/hpae_manager.cpp +++ b/services/audio_engine/manager/src/hpae_manager.cpp @@ -2497,6 +2497,11 @@ void HpaeManager::DeleteStreamVolumeToEffect(const std::string stringSessionID) SendRequest(request, __func__); } +bool HpaeManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + return HpaePolicyManager::GetInstance().IsChannelLayoutSupportForDspEffect(channelLayout); +} + // interfaces for injector void HpaeManager::UpdateAudioPortInfo(const uint32_t &sinkPortIndex, const AudioModuleInfo &audioPortInfo) {} diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index f309c3ef1a..69571d823e 100644 --- a/services/audio_engine/node/src/hpae_node_common.cpp +++ b/services/audio_engine/node/src/hpae_node_common.cpp @@ -25,8 +25,6 @@ namespace OHOS { namespace AudioStandard { namespace HPAE { static constexpr uint64_t TIME_US_PER_S = 1000000; -static constexpr uint32_t DEFAULT_MULTICHANNEL_NUM = 6; -static constexpr uint32_t DEFAULT_MULTICHANNEL_CHANNELLAYOUT = 1551; static constexpr float MAX_SINK_VOLUME_LEVEL = 1.0; static constexpr uint32_t DEFAULT_MULTICHANNEL_FRAME_LEN_MS = 20; static constexpr uint32_t MS_PER_SECOND = 1000; diff --git a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp index 472ce38a1a..b233cc4315 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp @@ -468,8 +468,7 @@ static void FillSpecialPipeInfo(AudioPipeInfo &info, std::shared_ptrbufferSize_ / std::stoul(info.moduleInfo_.channels)) * STEREO)); AUDIO_INFO_LOG("Buffer size: %{public}s", info.moduleInfo_.bufferSize.c_str()); - info.moduleInfo_.channelLayout = - AudioPolicyUtils::GetInstance().UpdateMultiChannelModuleInfo(info, streamPropInfo->channelLayout_); + AudioPolicyUtils::GetInstance().UpdateMultiChannelModuleInfo(info, streamPropInfo->channelLayout_); } else if (pipeInfoPtr->name_ == "offload_output") { info.moduleInfo_.className = "offload"; info.moduleInfo_.offloadEnable = "1"; diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index e470bf38c3..c40ffb876e 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -795,12 +795,12 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout) { - if (!AudioPolicyManagerFactory::GetAudioPolicyManager()->IsChannelLayoutSupportForDspEffect(channelLayout)) { - AUDIO_INFO_LOG("not support channelLayout:%{public}u, use default 5.1", channelLayout); + if (!AudioPolicyManagerFactory::GetAudioPolicyManager().IsChannelLayoutSupportForDspEffect(channelLayout)) { + AUDIO_INFO_LOG("not support channelLayout:%{public}lu, use default 5.1", channelLayout); info.moduleInfo_.channels = std::to_string(static_cast(CHANNEL_6)); // default 5.1 - info.moduleInfo_.channelLayout_ = std::to_string(static_cast(CH_LAYOUT_5POINT1)); + info.moduleInfo_.channelLayout = std::to_string(static_cast(CH_LAYOUT_5POINT1)); } - info.moduleInfo_.channelLayout_ = std::to_string(static_cast(channelLayout)); + info.moduleInfo_.channelLayout = std::to_string(static_cast(channelLayout)); } } // namespace AudioStandard } // namespace OHOS -- Gitee From 9803f4678e414b0c6f3ef662d358e843d30ea820 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Wed, 10 Sep 2025 14:19:00 +0800 Subject: [PATCH 06/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- services/audio_engine/manager/include/hpae_manager.h | 1 + services/audio_engine/manager/include/hpae_manager_impl.h | 1 + .../audio_engine/manager/include/hpae_policy_manager.h | 1 + services/audio_engine/manager/src/hpae_manager_impl.cpp | 6 ++++++ services/audio_engine/manager/src/hpae_policy_manager.cpp | 7 +++++++ 5 files changed, 16 insertions(+) diff --git a/services/audio_engine/manager/include/hpae_manager.h b/services/audio_engine/manager/include/hpae_manager.h index 52f607731f..ec44298eae 100644 --- a/services/audio_engine/manager/include/hpae_manager.h +++ b/services/audio_engine/manager/include/hpae_manager.h @@ -194,6 +194,7 @@ public: void AddStreamVolumeToEffect(const std::string stringSessionID, const float streamVolume) override; void DeleteStreamVolumeToEffect(const std::string stringSessionID) override; uint64_t ProcessPendingTransitionsAndGetNextDelay(); + bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) override; // interfaces for injector void UpdateAudioPortInfo(const uint32_t &sinkPortIndex, const AudioModuleInfo &audioPortInfo) override; void AddCaptureInjector( diff --git a/services/audio_engine/manager/include/hpae_manager_impl.h b/services/audio_engine/manager/include/hpae_manager_impl.h index 605954117b..b6c9df5abd 100644 --- a/services/audio_engine/manager/include/hpae_manager_impl.h +++ b/services/audio_engine/manager/include/hpae_manager_impl.h @@ -140,6 +140,7 @@ public: void AddStreamVolumeToEffect(const std::string stringSessionID, const float streamVolume) override; void DeleteStreamVolumeToEffect(const std::string stringSessionID) override; bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) override; + // interfaces for injector void UpdateAudioPortInfo(const uint32_t &sinkPortIndex, const AudioModuleInfo &audioPortInfo) override; void AddCaptureInjector( diff --git a/services/audio_engine/manager/include/hpae_policy_manager.h b/services/audio_engine/manager/include/hpae_policy_manager.h index 8a3d742363..f4029b51a6 100644 --- a/services/audio_engine/manager/include/hpae_policy_manager.h +++ b/services/audio_engine/manager/include/hpae_policy_manager.h @@ -80,6 +80,7 @@ public: void SendInitCommandToAlgo(); void AddStreamVolumeToEffect(const std::string stringSessionId, const float streamVolume); void DeleteStreamVolumeToEffect(const std::string stringSessionID); + bool IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout); private: HpaePolicyManager(); }; diff --git a/services/audio_engine/manager/src/hpae_manager_impl.cpp b/services/audio_engine/manager/src/hpae_manager_impl.cpp index 8e4b271c78..64ae2153fb 100644 --- a/services/audio_engine/manager/src/hpae_manager_impl.cpp +++ b/services/audio_engine/manager/src/hpae_manager_impl.cpp @@ -589,6 +589,12 @@ void HpaeManagerImpl::DeleteStreamVolumeToEffect(const std::string stringSession manager_->DeleteStreamVolumeToEffect(stringSessionID); } +bool HpaeManagerImpl::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + CHECK_AND_RETURN_LOG(manager_, "manager is nullptr"); + manager_->IsChannelLayoutSupportForDspEffect(channelLayout); +} + // interfaces for injector void HpaeManagerImpl::UpdateAudioPortInfo(const uint32_t &sinkPortIndex, const AudioModuleInfo &audioPortInfo) { diff --git a/services/audio_engine/manager/src/hpae_policy_manager.cpp b/services/audio_engine/manager/src/hpae_policy_manager.cpp index 5dea3d0a21..6e40fba683 100644 --- a/services/audio_engine/manager/src/hpae_policy_manager.cpp +++ b/services/audio_engine/manager/src/hpae_policy_manager.cpp @@ -232,6 +232,13 @@ void HpaePolicyManager::DeleteStreamVolumeToEffect(const std::string stringSessi CHECK_AND_RETURN_LOG(audioEffectChainManager != nullptr, "null audioEffectChainManager"); audioEffectChainManager->DeleteStreamVolume(stringSessionId); } + +bool HpaePolicyManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); + CHECK_AND_RETURN_LOG(audioEffectChainManager != nullptr, "null audioEffectChainManager"); + return audioEffectChainManager->IsChannelLayoutSupportForDspEffect(channelLayout); +} } // namespace HPAE } // namespace AudioStandard } // namespace OHOS -- Gitee From 071743cfb02893473b4d157dd9f66614e9cf9c39 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 18:18:25 +0800 Subject: [PATCH 07/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../src/pro_audio_service_adapter_impl.cpp | 1 - .../src/audio_effect_chain_manager.cpp | 19 +++++++++++++++---- ...ltichannel_audio_render_sink_unit_test.cpp | 16 ++++++++++++++++ .../manager/src/hpae_manager_impl.cpp | 4 ++-- .../manager/src/hpae_policy_manager.cpp | 2 +- .../manager/src/hpae_renderer_manager.cpp | 1 + .../domain/pipe/src/audio_pipe_selector.cpp | 8 ++++---- .../datashare/include/audio_policy_utils.h | 2 +- .../datashare/src/audio_policy_utils.cpp | 15 +++++++++------ .../src/audio_policy_utils_unit_test.cpp | 19 +++++++++++++++++++ 10 files changed, 68 insertions(+), 19 deletions(-) diff --git a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp index d4d5e07da3..5aa991ea1e 100644 --- a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp @@ -30,7 +30,6 @@ #include #include #include "i_hpae_manager.h" -#include "audio_effect_chain_manager.h" using namespace std; using namespace OHOS::AudioStandard::HPAE; diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 46054c3e1d..eb2f1d3dcf 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -148,6 +148,7 @@ void AudioEffectChainManager::SetSpkOffloadState() if (deviceType_ == DEVICE_TYPE_SPEAKER) { if (!spkOffloadEnabled_) { effectHdiInput_[0] = HDI_INIT; + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_SPEAKER); if (ret != SUCCESS || !CheckIfSpkDsp()) { AUDIO_WARNING_LOG("set hdi init failed, backup speaker entered"); @@ -161,6 +162,7 @@ void AudioEffectChainManager::SetSpkOffloadState() } else { if (spkOffloadEnabled_) { effectHdiInput_[0] = HDI_DESTROY; + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_SPEAKER); if (ret != SUCCESS) { AUDIO_WARNING_LOG("set hdi destroy failed, backup speaker entered"); @@ -219,10 +221,7 @@ void AudioEffectChainManager::InitHdiState() void AudioEffectChainManager::InitHdiStateInner() { - if (audioEffectHdiParam_ == nullptr) { - AUDIO_INFO_LOG("audioEffectHdiParam_ is nullptr."); - return; - } + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); audioEffectHdiParam_->InitHdi(); effectHdiInput_[0] = HDI_BLUETOOTH_MODE; effectHdiInput_[1] = 1; @@ -482,6 +481,7 @@ int32_t AudioEffectChainManager::EffectDspVolumeUpdate(std::shared_ptr(&effectHdiInput_[1]))); + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, ERROR, "audioEffectHdiParam_ is nullptr"); if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { AUDIO_WARNING_LOG("set hdi volume failed"); return ERROR; @@ -617,6 +617,7 @@ int32_t AudioEffectChainManager::EffectDspRotationUpdate(std::shared_ptrUpdateHdiState(effectHdiInput_) != SUCCESS) { AUDIO_WARNING_LOG("set hdi rotation failed"); return ERROR; @@ -716,6 +717,7 @@ int32_t AudioEffectChainManager::UpdateSpatialDeviceType(AudioSpatialDeviceType effectHdiInput_[0] = HDI_UPDATE_SPATIAL_DEVICE_TYPE; effectHdiInput_[1] = spatialDeviceType_; AUDIO_INFO_LOG("set hdi spatialDeviceType: %{public}d", effectHdiInput_[1]); + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, ERROR, "audioEffectHdiParam_ is nullptr"); ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { AUDIO_WARNING_LOG("set hdi update spatial device type failed"); @@ -817,6 +819,7 @@ int32_t AudioEffectChainManager::SetHdiParam(const AudioEffectScene &sceneType) effectHdiInput_[0] = HDI_ROOM_MODE; effectHdiInput_[1] = sceneType; AUDIO_PRERELEASE_LOGI("set hdi room mode sceneType: %{public}d", effectHdiInput_[1]); + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, ERROR, "audioEffectHdiParam_ is nullptr"); if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { AUDIO_WARNING_LOG("set hdi room mode failed"); return ERROR; @@ -830,6 +833,7 @@ 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]); + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { AUDIO_WARNING_LOG("set hdi head mode failed"); @@ -949,6 +953,7 @@ int32_t AudioEffectChainManager::SetSpatializationSceneType(AudioSpatializationS effectHdiInput_[0] = HDI_SPATIALIZATION_SCENE_TYPE; effectHdiInput_[1] = static_cast(spatializationSceneType_); + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, ERROR, "audioEffectHdiParam_ is nullptr"); if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { AUDIO_WARNING_LOG("set hdi spatialization scene type failed"); } @@ -965,6 +970,7 @@ void AudioEffectChainManager::SendAudioParamToHDI( effectHdiInput_[0] = code; CHECK_AND_RETURN_LOG(StringConverter(value, effectHdiInput_[1]), "convert invalid bufferSize: %{public}s", value.c_str()); + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, device) != SUCCESS) { AUDIO_WARNING_LOG("set hdi parameter failed for code %{public}d and value %{public}s", code, value.c_str()); } @@ -1329,6 +1335,7 @@ void AudioEffectChainManager::UpdateSpatializationEnabled(AudioSpatializationSta return; } effectHdiInput_[0] = HDI_INIT; + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { AUDIO_WARNING_LOG("set hdi init failed, enter route of escape in ARM"); @@ -1340,6 +1347,7 @@ void AudioEffectChainManager::UpdateSpatializationEnabled(AudioSpatializationSta } else { effectHdiInput_[0] = HDI_DESTROY; AUDIO_INFO_LOG("set hdi destroy."); + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, DEVICE_TYPE_BLUETOOTH_A2DP); if (ret != SUCCESS) { AUDIO_WARNING_LOG("set hdi destroy failed"); @@ -1558,6 +1566,7 @@ void AudioEffectChainManager::UpdateCurrSceneTypeAndStreamUsageForDsp() SessionEffectInfo info = sessionIDToEffectInfoMap_[maxSession]; effectHdiInput_[0] = HDI_STREAM_USAGE; effectHdiInput_[1] = info.streamUsage; + CHECK_AND_RETURN_LOG(audioEffectHdiParam_ != nullptr, "audioEffectHdiParam_ is nullptr"); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); AUDIO_INFO_LOG("set hdi streamUsage: %{public}d", info.streamUsage); if (ret != SUCCESS) { @@ -1946,6 +1955,7 @@ int32_t AudioEffectChainManager::EffectDspAbsVolumeStateUpdate(const bool absVol effectHdiInput_[0] = HDI_ABS_VOLUME_STATE; effectHdiInput_[1] = static_cast(absVolumeState); + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, ERROR, "audioEffectHdiParam_ is nullptr"); int32_t ret = audioEffectHdiParam_->UpdateHdiState(effectHdiInput_); AUDIO_INFO_LOG("absVolumeState change, new state: %{public}d, previous state: %{public}d, ret: %{public}d", effectHdiInput_[1], absVolumeState_, ret); @@ -1978,6 +1988,7 @@ bool AudioEffectChainManager::IsChannelLayoutSupportForDspEffect(AudioChannelLay effectHdiInput_[0] = HDI_QUERY_CHANNELLAYOUT; uint64_t* tempChannelLayout = reinterpret_cast(effectHdiInput_ + 1); *tempChannelLayout = channelLayout; + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, false, "audioEffectHdiParam_ is nullptr"); if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { AUDIO_WARNING_LOG("query channel layout support failed :%{public}lu", channelLayout); return false; diff --git a/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp b/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp index e11d64ff27..697f478b40 100644 --- a/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp +++ b/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp @@ -666,5 +666,21 @@ HWTEST_F(MultichannelAudioRenderSinkUnitTest, MultichannelSinkUnitTest_033, Test multichannelAudioRenderSink->GetAudioParameter(key, condition); EXPECT_EQ(multichannelAudioRenderSink->adapterNameCase_, ""); } + +/** + * @tc.name : Test MultichannelSink API + * @tc.number : MultichannelSinkUnitTest_034 + * @tc.desc : Test MultichannelAudioRenderSink + */ +HWTEST_F(MultichannelAudioRenderSinkUnitTest, MultichannelSinkUnitTest_034, TestSize.Level1) +{ + auto multichannelAudioRenderSink = std::make_shared(HDI_ID_INFO_DP); + EXPECT_NE(multichannelAudioRenderSink, nullptr); + + multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(true); + EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_, true); + multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(false); + EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_, false); +} } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/services/audio_engine/manager/src/hpae_manager_impl.cpp b/services/audio_engine/manager/src/hpae_manager_impl.cpp index 64ae2153fb..bbec1c115e 100644 --- a/services/audio_engine/manager/src/hpae_manager_impl.cpp +++ b/services/audio_engine/manager/src/hpae_manager_impl.cpp @@ -591,8 +591,8 @@ void HpaeManagerImpl::DeleteStreamVolumeToEffect(const std::string stringSession bool HpaeManagerImpl::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) { - CHECK_AND_RETURN_LOG(manager_, "manager is nullptr"); - manager_->IsChannelLayoutSupportForDspEffect(channelLayout); + CHECK_AND_RETURN_RET_LOG(manager_, false, "manager is nullptr"); + return manager_->IsChannelLayoutSupportForDspEffect(channelLayout); } // interfaces for injector diff --git a/services/audio_engine/manager/src/hpae_policy_manager.cpp b/services/audio_engine/manager/src/hpae_policy_manager.cpp index 6e40fba683..be20e868bf 100644 --- a/services/audio_engine/manager/src/hpae_policy_manager.cpp +++ b/services/audio_engine/manager/src/hpae_policy_manager.cpp @@ -236,7 +236,7 @@ void HpaePolicyManager::DeleteStreamVolumeToEffect(const std::string stringSessi bool HpaePolicyManager::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) { AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); - CHECK_AND_RETURN_LOG(audioEffectChainManager != nullptr, "null audioEffectChainManager"); + CHECK_AND_RETURN_RET_LOG(audioEffectChainManager != nullptr, false, "null audioEffectChainManager"); return audioEffectChainManager->IsChannelLayoutSupportForDspEffect(channelLayout); } } // namespace HPAE diff --git a/services/audio_engine/manager/src/hpae_renderer_manager.cpp b/services/audio_engine/manager/src/hpae_renderer_manager.cpp index 2fa5436aed..63230243ac 100644 --- a/services/audio_engine/manager/src/hpae_renderer_manager.cpp +++ b/services/audio_engine/manager/src/hpae_renderer_manager.cpp @@ -889,6 +889,7 @@ int32_t HpaeRendererManager::InitManager(bool isReload) return checkRet; } nodeInfo.channels = sinkInfo_.channels; + nodeInfo.channelLayout = static_cast(sinkInfo_.channelLayout); nodeInfo.format = sinkInfo_.format; nodeInfo.frameLen = sinkInfo_.frameLen; nodeInfo.nodeId = 0; diff --git a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp index b233cc4315..d9305fe192 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp @@ -465,10 +465,10 @@ static void FillSpecialPipeInfo(AudioPipeInfo &info, std::shared_ptrbufferSize_ / std::stoul(info.moduleInfo_.channels)) * STEREO)); - AUDIO_INFO_LOG("Buffer size: %{public}s", info.moduleInfo_.bufferSize.c_str()); - AudioPolicyUtils::GetInstance().UpdateMultiChannelModuleInfo(info, streamPropInfo->channelLayout_); + AudioPolicyUtils::GetInstance().UpdateMultiChannelModuleInfo(info, streamPropInfo); + AUDIO_INFO_LOG("Buffer size: %{public}s channels: %{public}s channelLayout:%{public}s", + info.moduleInfo_.bufferSize.c_str(), info.moduleInfo_.channel.c_str(), + info.moduleInfo_.channelLayout.c_str()); } else if (pipeInfoPtr->name_ == "offload_output") { info.moduleInfo_.className = "offload"; info.moduleInfo_.offloadEnable = "1"; diff --git a/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h b/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h index 2fbd5d4ae0..4aa06f68dd 100644 --- a/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h +++ b/services/audio_policy/server/infra/datashare/include/audio_policy_utils.h @@ -95,7 +95,7 @@ public: bool IsSupportedNearlink(const std::string &bundleName, int32_t apiVersion, bool hasSystemPermission); bool IsWirelessDevice(DeviceType deviceType); - void UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout); + void UpdateMultiChannelModuleInfo(AudioPipeInfo &info, std::shared_ptr streamPropInfo); private: AudioPolicyUtils() : streamCollector_(AudioStreamCollector::GetAudioStreamCollector()), audioStateManager_(AudioStateManager::GetAudioStateManager()), diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index c40ffb876e..a3fcb526f2 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -793,14 +793,17 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) } } -void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, AudioChannelLayout channelLayout) +void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, std::shared_ptr streamPropInfo) { - if (!AudioPolicyManagerFactory::GetAudioPolicyManager().IsChannelLayoutSupportForDspEffect(channelLayout)) { - AUDIO_INFO_LOG("not support channelLayout:%{public}lu, use default 5.1", channelLayout); - info.moduleInfo_.channels = std::to_string(static_cast(CHANNEL_6)); // default 5.1 - info.moduleInfo_.channelLayout = std::to_string(static_cast(CH_LAYOUT_5POINT1)); + if (!AudioPolicyManagerFactory::GetAudioPolicyManager(). + IsChannelLayoutSupportForDspEffect(streamPropInfo->channelLayout)) { + AUDIO_INFO_LOG("not support channelLayout:%{public}" PRIu64 ", use default 5.1", channelLayout); + info.moduleInfo_.bufferSize = + std::to_string(((streamPropInfo->bufferSize_ * static_cast(CHANNEL_6)) / + std::stoul(info.moduleInfo_.channels))); + info.moduleInfo_.channels = std::to_string(static_cast(CHANNEL_6)); + info.moduleInfo_.channelLayout = std::to_string(static_cast(CH_LAYOUT_5POINT1)); } - info.moduleInfo_.channelLayout = std::to_string(static_cast(channelLayout)); } } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp index f37305b5bd..66a806669f 100644 --- a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp @@ -418,5 +418,24 @@ HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) EXPECT_EQ(ret, false); } +/** + * @tc.name : Test UpdateMultiChannelModuleInfo API + * @tc.type : FUNC + * @tc.number: AudioPolicyUtilsUnitTest_021 + * @tc.desc : Test UpdateMultiChannelModuleInfo. + */ +HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) +{ + AudioPolicyUtils* audioPolicyUtilsTest_ = nullptr; + audioPolicyUtilsTest_ = &AudioPolicyUtils::GetInstance(); + ASSERT_TRUE(audioPolicyUtilsTest_ != nullptr); + + AudioPipeInfo info; + info.moduleInfo_.channels = "4"; + streamPropInfo->channelLayout_ = CH_LAYOUT_6POINT0_FRONT; + std::shared_ptr streamPropInfo = std::make_shared(); + int32_t ret = audioPolicyUtilsTest_->UpdateMultiChannelModuleInfo(info, streamPropInfo); + EXPECT_EQ(ret, false); +} } // namespace AudioStandard } // namespace OHOS -- Gitee From 5ed669e21d929b4207834816a5be06bb55de05ab Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 18:36:46 +0800 Subject: [PATCH 08/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../unittest/src/pro_audio_service_adapter_unit_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp index a5cd2c00fb..e9ad250327 100644 --- a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp +++ b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp @@ -423,13 +423,13 @@ HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_ReloadAudioPort_007, TestSize * @tc.desc: test check if channel layout support for dsp * @tc.type: FUNC */ -HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_IsChannelLayoutSupportForMultiChannel_001, TestSize.Level1) +HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_IsChannelLayoutSupportForDspEffect_001, TestSize.Level1) { AudioChannelLayout channelLayout = CH_LAYOUT_5POINT1; - int32_t ret = impl_->IsChannelLayoutSupportForMultiChannel(moduleInfo.lib, moduleInfo); + int32_t ret = impl_->IsChannelLayoutSupportForDspEffect(moduleInfo.lib, moduleInfo); EXPECT_GE(SUCCESS, ret); channelLayout = CH_LAYOUT_4POINT0; - ret = impl_->IsChannelLayoutSupportForMultiChannel(moduleInfo.lib, moduleInfo); + ret = impl_->IsChannelLayoutSupportForDspEffect(moduleInfo.lib, moduleInfo); EXPECT_GE(ERROR, ret); } } // namespace AudioStandard -- Gitee From 87b8bbf5d14e7f0a39205816c44117fa978b0b31 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 18:47:54 +0800 Subject: [PATCH 09/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../node/src/hpae_node_common.cpp | 552 ++---------------- .../src/audio_policy_utils_unit_test.cpp | 9 +- 2 files changed, 52 insertions(+), 509 deletions(-) diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index 2e0789b8a9..8dcca37409 100644 --- a/services/audio_engine/node/src/hpae_node_common.cpp +++ b/services/audio_engine/node/src/hpae_node_common.cpp @@ -12,519 +12,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LOG_TAG -#define LOG_TAG "HpaeNodeCommon" -#endif -#include -#include "hpae_node_common.h" -#include "audio_errors.h" -#include "audio_engine_log.h" +#ifndef HPAE_NODE_COMMON_H +#define HPAE_NODE_COMMON_H +#include "hpae_define.h" +#include "audio_effect.h" +#include "audio_module_info.h" +#include "audio_service_hpae_dump_callback.h" namespace OHOS { namespace AudioStandard { namespace HPAE { -static constexpr uint64_t TIME_US_PER_S = 1000000; -static constexpr float MAX_SINK_VOLUME_LEVEL = 1.0; -static constexpr uint32_t DEFAULT_MULTICHANNEL_FRAME_LEN_MS = 20; -static constexpr uint32_t MS_PER_SECOND = 1000; -static constexpr uint32_t BASE_TEN = 10; -static constexpr uint32_t FRAME_LENGTH_LIMIT = 38400; - -static std::map g_streamTypeToSceneTypeMap = { - {STREAM_MUSIC, HPAE_SCENE_MUSIC}, - {STREAM_GAME, HPAE_SCENE_GAME}, - {STREAM_MOVIE, HPAE_SCENE_MOVIE}, - {STREAM_GAME, HPAE_SCENE_GAME}, - {STREAM_SPEECH, HPAE_SCENE_SPEECH}, - {STREAM_VOICE_RING, HPAE_SCENE_RING}, - {STREAM_VOICE_COMMUNICATION, HPAE_SCENE_VOIP_DOWN}, - {STREAM_MEDIA, HPAE_SCENE_OTHERS} -}; - -static std::map g_effectSceneToProcessorTypeMap = { - {SCENE_OTHERS, HPAE_SCENE_OTHERS}, - {SCENE_MUSIC, HPAE_SCENE_MUSIC}, - {SCENE_MOVIE, HPAE_SCENE_MOVIE}, - {SCENE_GAME, HPAE_SCENE_GAME}, - {SCENE_SPEECH, HPAE_SCENE_SPEECH}, - {SCENE_RING, HPAE_SCENE_RING}, - {SCENE_VOIP_DOWN, HPAE_SCENE_VOIP_DOWN}, - {SCENE_COLLABORATIVE, HPAE_SCENE_COLLABORATIVE} -}; - -static std::unordered_map g_sourceTypeToSceneTypeMap = { - {SOURCE_TYPE_MIC, HPAE_SCENE_RECORD}, - {SOURCE_TYPE_CAMCORDER, HPAE_SCENE_RECORD}, - {SOURCE_TYPE_VOICE_CALL, HPAE_SCENE_VOIP_UP}, - {SOURCE_TYPE_VOICE_COMMUNICATION, HPAE_SCENE_VOIP_UP}, - {SOURCE_TYPE_VOICE_TRANSCRIPTION, HPAE_SCENE_PRE_ENHANCE}, - {SOURCE_TYPE_VOICE_MESSAGE, HPAE_SCENE_VOICE_MESSAGE}, - {SOURCE_TYPE_VOICE_RECOGNITION, HPAE_SCENE_RECOGNITION} -}; - - -static std::unordered_set g_processorTypeNeedEcSet = { - HPAE_SCENE_VOIP_UP, - HPAE_SCENE_PRE_ENHANCE, - HPAE_SCENE_RECOGNITION, -}; - -static std::unordered_set g_processorTypeNeedMicRefSet = { - HPAE_SCENE_VOIP_UP, - HPAE_SCENE_RECORD, -}; - -static std::unordered_map g_processorTypeToSceneTypeMap = { - {HPAE_SCENE_RECORD, SCENE_RECORD}, - {HPAE_SCENE_VOIP_UP, SCENE_VOIP_UP}, - {HPAE_SCENE_PRE_ENHANCE, SCENE_PRE_ENHANCE}, - {HPAE_SCENE_VOICE_MESSAGE, SCENE_VOICE_MESSAGE}, - {HPAE_SCENE_RECOGNITION, SCENE_RECOGNITION}, -}; - -static std::unordered_map g_sessionStateToStrMap = { - {HPAE_SESSION_NEW, "NEW"}, - {HPAE_SESSION_PREPARED, "PREPARED"}, - {HPAE_SESSION_RUNNING, "RUNNING"}, - {HPAE_SESSION_PAUSING, "PAUSING"}, - {HPAE_SESSION_PAUSED, "PAUSED"}, - {HPAE_SESSION_STOPPING, "STOPPING"}, - {HPAE_SESSION_STOPPED, "STOPPED"}, - {HPAE_SESSION_RELEASED, "RELEASED"} -}; - -static std::unordered_map g_streamMgrStateToStrMap = { - {STREAM_MANAGER_NEW, "NEW"}, - {STREAM_MANAGER_IDLE, "IDLE"}, - {STREAM_MANAGER_RUNNING, "RUNNING"}, - {STREAM_MANAGER_SUSPENDED, "SUSPENDED"}, - {STREAM_MANAGER_RELEASED, "RELEASED"} -}; - -static std::map g_formatFromParserStrToEnum = { - {"s16", SAMPLE_S16LE}, - {"s16le", SAMPLE_S16LE}, - {"s24", SAMPLE_S24LE}, - {"s24le", SAMPLE_S24LE}, - {"s32", SAMPLE_S32LE}, - {"s32le", SAMPLE_S32LE}, - {"f32", SAMPLE_F32LE}, - {"f32le", SAMPLE_F32LE}, -}; - -static std::map g_formatFromParserEnumToStr = { - {SAMPLE_S16LE, "s16le"}, - {SAMPLE_S24LE, "s24le"}, - {SAMPLE_S32LE, "s32le"}, - {SAMPLE_F32LE, "f32le"}, -}; - -static std::unordered_map g_deviceClassToPipeMap = { - {"primary", PIPE_TYPE_NORMAL_OUT}, - {"a2dp", PIPE_TYPE_NORMAL_OUT}, - {"remote", PIPE_TYPE_NORMAL_OUT}, - {"dp", PIPE_TYPE_NORMAL_OUT}, - {"multichannel", PIPE_TYPE_MULTICHANNEL}, -}; - -static long StringToNum(const std::string &str) -{ - char *endptr; - long num = strtol(str.c_str(), &endptr, BASE_TEN); - CHECK_AND_RETURN_RET_LOG(endptr != nullptr && *endptr == '\0', 0, - "trans str \"%{public}s\" to num failed", str.c_str()); - return num; -} - -AudioPipeType ConvertDeviceClassToPipe(const std::string &deviceClass) -{ - auto item = g_deviceClassToPipeMap.find(deviceClass); - if (item == g_deviceClassToPipeMap.end()) { - return PIPE_TYPE_UNKNOWN; - } - return item->second; -} - -std::string ConvertSessionState2Str(HpaeSessionState state) -{ - if (g_sessionStateToStrMap.find(state) == g_sessionStateToStrMap.end()) { - return "UNKNOWN"; - } - return g_sessionStateToStrMap[state]; -} - -std::string ConvertStreamManagerState2Str(StreamManagerState state) -{ - if (g_streamMgrStateToStrMap.find(state) == g_streamMgrStateToStrMap.end()) { - return "UNKNOWN"; - } - return g_streamMgrStateToStrMap[state]; -} - -HpaeProcessorType TransStreamTypeToSceneType(AudioStreamType streamType) -{ - if (g_streamTypeToSceneTypeMap.find(streamType) == g_streamTypeToSceneTypeMap.end()) { - return HPAE_SCENE_EFFECT_NONE; - } else { - return g_streamTypeToSceneTypeMap[streamType]; - } -} - -HpaeProcessorType TransEffectSceneToSceneType(AudioEffectScene effectScene) -{ - if (g_effectSceneToProcessorTypeMap.find(effectScene) == g_effectSceneToProcessorTypeMap.end()) { - return HPAE_SCENE_EFFECT_NONE; - } else { - return g_effectSceneToProcessorTypeMap[effectScene]; - } -} - -void TransNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo, bool isCollaborationEnabled) -{ - if (isCollaborationEnabled) { - if (nodeInfo.effectInfo.effectScene == SCENE_MUSIC || nodeInfo.effectInfo.effectScene == SCENE_MOVIE) { - nodeInfo.effectInfo.lastEffectScene = nodeInfo.effectInfo.effectScene; - nodeInfo.effectInfo.effectScene = SCENE_COLLABORATIVE; - nodeInfo.sceneType = HPAE_SCENE_COLLABORATIVE; - AUDIO_INFO_LOG("collaboration enabled, effectScene from %{public}d, sceneType changed to %{public}d", - nodeInfo.effectInfo.lastEffectScene, nodeInfo.sceneType); - } - } else { - RecoverNodeInfoForCollaboration(nodeInfo); - } -} - -HpaeProcessorType TransSourceTypeToSceneType(SourceType sourceType) -{ - if (g_sourceTypeToSceneTypeMap.find(sourceType) == g_sourceTypeToSceneTypeMap.end()) { - return HPAE_SCENE_EFFECT_NONE; - } else { - return g_sourceTypeToSceneTypeMap[sourceType]; - } -} - -bool CheckSceneTypeNeedEc(HpaeProcessorType processorType) -{ - return g_processorTypeNeedEcSet.find(processorType) != g_processorTypeNeedEcSet.end(); -} - -bool CheckSceneTypeNeedMicRef(HpaeProcessorType processorType) -{ - return g_processorTypeNeedMicRefSet.find(processorType) != g_processorTypeNeedMicRefSet.end(); -} - -static std::unordered_map g_processorTypeToEffectSceneTypeMap = { - {HPAE_SCENE_DEFAULT, "HPAE_SCENE_DEFAULT"}, - {HPAE_SCENE_OTHERS, "SCENE_OTHERS"}, - {HPAE_SCENE_MUSIC, "SCENE_MUSIC"}, - {HPAE_SCENE_GAME, "SCENE_GAME"}, - {HPAE_SCENE_MOVIE, "SCENE_MOVIE"}, - {HPAE_SCENE_SPEECH, "SCENE_SPEECH"}, - {HPAE_SCENE_RING, "SCENE_RING"}, - {HPAE_SCENE_VOIP_DOWN, "SCENE_VOIP_DOWN"}, - {HPAE_SCENE_COLLABORATIVE, "SCENE_COLLABORATIVE"}}; - -std::string TransProcessorTypeToSceneType(HpaeProcessorType processorType) -{ - if (g_processorTypeToEffectSceneTypeMap.find(processorType) == g_processorTypeToEffectSceneTypeMap.end()) { - return "SCENE_EXTRA"; - } else { - return g_processorTypeToEffectSceneTypeMap[processorType]; - } -} - -bool CheckHpaeNodeInfoIsSame(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &curNodeInfo) -{ - return preNodeInfo.channels == curNodeInfo.channels && //&& preNodeInfo.format == curNodeInfo.format todo - preNodeInfo.samplingRate == curNodeInfo.samplingRate && - preNodeInfo.channelLayout == curNodeInfo.channelLayout; -} - -std::string TransNodeInfoToStringKey(HpaeNodeInfo& nodeInfo) -{ - std::string nodeKey = std::to_string(nodeInfo.sourceBufferType) + "_" + - std::to_string(nodeInfo.samplingRate) + "_" + - std::to_string(nodeInfo.channels) + "_" + - std::to_string(nodeInfo.format); - return nodeKey; -} - -AudioEnhanceScene TransProcessType2EnhanceScene(const HpaeProcessorType &processorType) -{ - if (g_processorTypeToSceneTypeMap.find(processorType) == g_processorTypeToSceneTypeMap.end()) { - return SCENE_NONE; - } else { - return g_processorTypeToSceneTypeMap[processorType]; - } -} - -size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo) -{ - return usTime * nodeInfo.samplingRate / TIME_US_PER_S / nodeInfo.frameLen; -} - -uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo) -{ - if (nodeInfo.channels == 0 || GetSizeFromFormat(nodeInfo.format) == 0 || nodeInfo.samplingRate == 0) { - AUDIO_ERR_LOG("invalid nodeInfo"); +bool CheckHpaeNodeInfoIsSame(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &curNodeInfo); +HpaeProcessorType TransStreamTypeToSceneType(AudioStreamType streamType); +HpaeProcessorType TransEffectSceneToSceneType(AudioEffectScene effectScene); +HpaeProcessorType TransSourceTypeToSceneType(SourceType sourceType); +bool CheckSceneTypeNeedEc(HpaeProcessorType processorType); +bool CheckSceneTypeNeedMicRef(HpaeProcessorType processorType); +std::string TransNodeInfoToStringKey(HpaeNodeInfo& nodeInfo); +AudioEnhanceScene TransProcessType2EnhanceScene(const HpaeProcessorType &processorType); +std::string TransProcessorTypeToSceneType(HpaeProcessorType processorType); +uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo); +size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo); +std::string ConvertSessionState2Str(HpaeSessionState state); +std::string ConvertStreamManagerState2Str(StreamManagerState state); +int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); +bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo); +int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo); +AudioSampleFormat TransFormatFromStringToEnum(std::string format); +void PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo); +std::string TransFormatFromEnumToString(AudioSampleFormat format); +AudioPipeType ConvertDeviceClassToPipe(const std::string &deviceClass); +void TransNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo, bool isCollaborationEnabled); +void RecoverNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo); +int32_t CheckFramelen(const HpaeSinkInfo &sinkInfo); +int32_t CheckStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSinkInfo &sinkInfo); +int32_t CheckSourceInfoFramelen(const HpaeSourceInfo &sourceInfo); +int32_t CheckSourceAndStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSourceInfo &sourceInfo); + +// for hidumper device / stream info trans, param should be HpaeSinkInfo / HpaeSourceInfo / HpaeStreamInfo +template +int32_t TransDeviceInfoToString(const T& info, std::string &config) +{ + if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { + config += TransFormatFromEnumToString(info.format) + " "; + config += std::to_string(info.channels) + "ch "; + config += std::to_string(info.samplingRate) + "Hz"; return 0; } - - double samples = static_cast(bufferSize) / - (nodeInfo.channels * GetSizeFromFormat(nodeInfo.format)); - double seconds = samples / static_cast(nodeInfo.samplingRate); - double microseconds = seconds * TIME_US_PER_S; - - return static_cast(microseconds); -} - -AudioSampleFormat TransFormatFromStringToEnum(std::string format) -{ - return static_cast(g_formatFromParserStrToEnum[format]); -} - -int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) -{ - if (g_formatFromParserStrToEnum.find(audioModuleInfo.format) == g_formatFromParserStrToEnum.end()) { - AUDIO_ERR_LOG("openaudioport failed,format:%{public}s not supported", audioModuleInfo.format.c_str()); - return ERROR; - } - sinkInfo.deviceNetId = audioModuleInfo.networkId; - sinkInfo.deviceClass = audioModuleInfo.className; - sinkInfo.suspendTime = audioModuleInfo.suspendIdleTimeout; - AUDIO_INFO_LOG("HpaeManager::deviceNetId: %{public}s, deviceClass: %{public}s, suspend_time: %{public}u", - sinkInfo.deviceNetId.c_str(), - sinkInfo.deviceClass.c_str(), - sinkInfo.suspendTime); - sinkInfo.adapterName = audioModuleInfo.adapterName; - sinkInfo.lib = audioModuleInfo.lib; - sinkInfo.splitMode = audioModuleInfo.extra; - sinkInfo.filePath = audioModuleInfo.fileName; - - sinkInfo.samplingRate = static_cast(StringToNum(audioModuleInfo.rate)); - sinkInfo.format = static_cast(TransFormatFromStringToEnum(audioModuleInfo.format)); - sinkInfo.channels = static_cast(StringToNum(audioModuleInfo.channels)); - int32_t bufferSize = static_cast(StringToNum(audioModuleInfo.bufferSize)); - CHECK_AND_RETURN_RET_LOG(sinkInfo.channels != CHANNEL_UNKNOW && sinkInfo.format != INVALID_WIDTH, ERROR, - "channels or format is invalid"); - sinkInfo.frameLen = static_cast(bufferSize) / (sinkInfo.channels * - static_cast(GetSizeFromFormat(sinkInfo.format))); - sinkInfo.channelLayout = static_cast(StringToNum(audioModuleInfo.channelLayout)); - sinkInfo.deviceType = static_cast(StringToNum(audioModuleInfo.deviceType)); - sinkInfo.volume = MAX_SINK_VOLUME_LEVEL; - sinkInfo.openMicSpeaker = static_cast(StringToNum(audioModuleInfo.OpenMicSpeaker)); - sinkInfo.renderInIdleState = static_cast(StringToNum(audioModuleInfo.renderInIdleState)); - sinkInfo.offloadEnable = static_cast(StringToNum(audioModuleInfo.offloadEnable)); - sinkInfo.sinkLatency = static_cast(StringToNum(audioModuleInfo.sinkLatency)); - sinkInfo.fixedLatency = static_cast(StringToNum(audioModuleInfo.fixedLatency)); - sinkInfo.deviceName = audioModuleInfo.name; - if (audioModuleInfo.needEmptyChunk) { - sinkInfo.needEmptyChunk = audioModuleInfo.needEmptyChunk.value(); - } - AUDIO_INFO_LOG("sink info ch: %{public}u, channelLayout: %{public}" PRIu64, - sinkInfo.channels, - sinkInfo.channelLayout); - return SUCCESS; -} - -int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo) -{ - if (g_formatFromParserStrToEnum.find(audioModuleInfo.format) == g_formatFromParserStrToEnum.end()) { - AUDIO_ERR_LOG("openaudioport failed,format:%{public}s not supported", audioModuleInfo.format.c_str()); - return ERROR; - } - sourceInfo.deviceNetId = audioModuleInfo.networkId; - sourceInfo.deviceClass = audioModuleInfo.className; - sourceInfo.adapterName = audioModuleInfo.adapterName; - sourceInfo.sourceName = audioModuleInfo.name; // built_in_mic - sourceInfo.deviceName = audioModuleInfo.name; - sourceInfo.sourceType = static_cast(StringToNum(audioModuleInfo.sourceType)); - sourceInfo.filePath = audioModuleInfo.fileName; - int32_t bufferSize = static_cast(StringToNum(audioModuleInfo.bufferSize)); - sourceInfo.channels = static_cast(StringToNum(audioModuleInfo.channels)); - sourceInfo.format = TransFormatFromStringToEnum(audioModuleInfo.format); - CHECK_AND_RETURN_RET_LOG(sourceInfo.channels != CHANNEL_UNKNOW && sourceInfo.format != INVALID_WIDTH, ERROR, - "channels or format is invalid"); - sourceInfo.frameLen = static_cast(bufferSize) / (sourceInfo.channels * - static_cast(GetSizeFromFormat(sourceInfo.format))); - sourceInfo.samplingRate = static_cast(StringToNum(audioModuleInfo.rate)); - sourceInfo.channelLayout = 0ULL; - sourceInfo.deviceType = static_cast(StringToNum(audioModuleInfo.deviceType)); - sourceInfo.volume = MAX_SINK_VOLUME_LEVEL; // 1.0f; - - sourceInfo.ecType = static_cast(StringToNum(audioModuleInfo.ecType)); - sourceInfo.ecAdapterName = audioModuleInfo.ecAdapter; - sourceInfo.ecSamplingRate = static_cast(StringToNum(audioModuleInfo.ecSamplingRate)); - sourceInfo.ecFormat = TransFormatFromStringToEnum(audioModuleInfo.ecFormat); - sourceInfo.ecChannels = static_cast(StringToNum(audioModuleInfo.ecChannels)); - sourceInfo.ecFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.ecSamplingRate / MS_PER_SECOND); - - sourceInfo.micRef = static_cast(StringToNum(audioModuleInfo.openMicRef)); - sourceInfo.micRefSamplingRate = static_cast(StringToNum(audioModuleInfo.micRefRate)); - sourceInfo.micRefFormat = TransFormatFromStringToEnum(audioModuleInfo.micRefFormat); - sourceInfo.micRefChannels = static_cast(StringToNum(audioModuleInfo.micRefChannels)); - sourceInfo.openMicSpeaker = static_cast(StringToNum(audioModuleInfo.OpenMicSpeaker)); - sourceInfo.micRefFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.micRefSamplingRate / MS_PER_SECOND); - return SUCCESS; -} - -bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo) -{ - auto getKey = [](const HpaeSourceInfo &sourceInfo) { - return std::tie( - sourceInfo.deviceNetId, - sourceInfo.deviceClass, - sourceInfo.adapterName, - sourceInfo.sourceName, - sourceInfo.sourceType, - sourceInfo.filePath, - sourceInfo.deviceName, - sourceInfo.frameLen, - sourceInfo.samplingRate, - sourceInfo.format, - sourceInfo.channels, - sourceInfo.channelLayout, - sourceInfo.deviceType, - sourceInfo.volume, - sourceInfo.openMicSpeaker, - sourceInfo.ecType, - sourceInfo.ecFrameLen, - sourceInfo.ecSamplingRate, - sourceInfo.ecFormat, - sourceInfo.ecChannels, - sourceInfo.micRef, - sourceInfo.micRefFrameLen, - sourceInfo.micRefSamplingRate, - sourceInfo.micRefFormat, - sourceInfo.micRefChannels); - }; - return getKey(info) != getKey(oldInfo); -} - -void PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo) -{ - AUDIO_INFO_LOG("rate: %{public}s ch: %{public}s buffersize: %{public}s ", - audioModuleInfo.rate.c_str(), - audioModuleInfo.channels.c_str(), - audioModuleInfo.bufferSize.c_str()); - AUDIO_INFO_LOG("format: %{public}s name: %{public}s lib: %{public}s ", - audioModuleInfo.format.c_str(), - audioModuleInfo.name.c_str(), - audioModuleInfo.lib.c_str()); - AUDIO_INFO_LOG("deviceType: %{public}s className: %{public}s adapterName: %{public}s ", - audioModuleInfo.deviceType.c_str(), - audioModuleInfo.className.c_str(), - audioModuleInfo.adapterName.c_str()); - AUDIO_INFO_LOG("OpenMicSpeaker: %{public}s networkId: %{public}s fileName: %{public}s ", - audioModuleInfo.OpenMicSpeaker.c_str(), - audioModuleInfo.networkId.c_str(), - audioModuleInfo.fileName.c_str()); - AUDIO_INFO_LOG("fixedLatency: %{public}s sinkLatency: %{public}s renderInIdleState: %{public}s ", - audioModuleInfo.fixedLatency.c_str(), - audioModuleInfo.sinkLatency.c_str(), - audioModuleInfo.renderInIdleState.c_str()); - AUDIO_INFO_LOG("sceneName: %{public}s sourceType: %{public}s offloadEnable: %{public}s ", - audioModuleInfo.sceneName.c_str(), - audioModuleInfo.sourceType.c_str(), - audioModuleInfo.offloadEnable.c_str()); -} - -std::string TransFormatFromEnumToString(AudioSampleFormat format) -{ - CHECK_AND_RETURN_RET_LOG(g_formatFromParserEnumToStr.find(format) != g_formatFromParserEnumToStr.end(), - "", "error param format"); - return g_formatFromParserEnumToStr[format]; -} - -void RecoverNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo) -{ - if (nodeInfo.effectInfo.effectScene == SCENE_COLLABORATIVE) { - nodeInfo.effectInfo.effectScene = nodeInfo.effectInfo.lastEffectScene; - nodeInfo.sceneType = TransEffectSceneToSceneType(nodeInfo.effectInfo.effectScene); - AUDIO_INFO_LOG("collaboration disabled, effectScene changed to %{public}d, sceneType changed to %{public}d", - nodeInfo.effectInfo.effectScene, nodeInfo.sceneType); - } + AUDIO_ERR_LOG("error info type"); + return ERROR_INVALID_PARAM; } - void TransStreamInfoToStreamDumpInfo(const std::unordered_map &streamInfoMap, - std::vector &dumpInfo) -{ - std::transform(streamInfoMap.begin(), streamInfoMap.end(), std::back_inserter(dumpInfo), - [](const auto &pair) { - const HpaeSessionInfo &sessionInfo = pair.second; - std::string config; - TransDeviceInfoToString(sessionInfo.streamInfo, config); - return HpaeInputOutputInfo { - .sessionId = sessionInfo.streamInfo.sessionId, - .deviceName = sessionInfo.streamInfo.deviceName, - .uid = sessionInfo.streamInfo.uid, - .pid = sessionInfo.streamInfo.pid, - .tokenId = sessionInfo.streamInfo.tokenId, - .offloadEnable = sessionInfo.offloadEnable, - .privacyType = sessionInfo.streamInfo.privacyType, - .config = config, - .state = sessionInfo.state, - .startTime = sessionInfo.startTime - }; - }); -} - -int32_t CheckStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSinkInfo &sinkInfo) -{ - if (streamInfo.frameLen == 0) { - AUDIO_ERR_LOG("FrameLen is 0."); - return ERROR; - } else if (streamInfo.frameLen > FRAME_LENGTH_LIMIT) { - AUDIO_ERR_LOG("FrameLen is over-sized."); - return ERROR; - } - if (streamInfo.frameLen * sinkInfo.samplingRate != streamInfo.samplingRate * sinkInfo.frameLen) { - AUDIO_ERR_LOG("Framelen is not proportional."); - return ERROR; - } - return SUCCESS; -} - -int32_t CheckSourceAndStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSourceInfo &sourceInfo) -{ - if (streamInfo.frameLen == 0) { - AUDIO_ERR_LOG("FrameLen is 0."); - return ERROR; - } else if (streamInfo.frameLen > FRAME_LENGTH_LIMIT) { - AUDIO_ERR_LOG("FrameLen is over-sized."); - return ERROR; - } - if (streamInfo.frameLen * sourceInfo.samplingRate != streamInfo.samplingRate * sourceInfo.frameLen) { - AUDIO_ERR_LOG("Framelen is not proportional."); - return ERROR; - } - return SUCCESS; -} - -int32_t CheckFramelen(const HpaeSinkInfo &sinkInfo) -{ - if (sinkInfo.frameLen == 0) { - AUDIO_ERR_LOG("FrameLen is 0."); - return ERROR; - } else if (sinkInfo.frameLen > FRAME_LENGTH_LIMIT) { - AUDIO_ERR_LOG("FrameLen is over-sized."); - return ERROR; - } - return SUCCESS; -} - -int32_t CheckSourceInfoFramelen(const HpaeSourceInfo &sourceInfo) -{ - if (sourceInfo.frameLen == 0) { - AUDIO_ERR_LOG("FrameLen is 0."); - return ERROR; - } else if (sourceInfo.frameLen > FRAME_LENGTH_LIMIT) { - AUDIO_ERR_LOG("FrameLen is over-sized."); - return ERROR; - } - return SUCCESS; -} + std::vector &dumpInfo); } // namespace HPAE } // namespace AudioStandard -} // namespace OHOS \ No newline at end of file +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp index 66a806669f..a950d1ef5a 100644 --- a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp @@ -424,7 +424,7 @@ HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) * @tc.number: AudioPolicyUtilsUnitTest_021 * @tc.desc : Test UpdateMultiChannelModuleInfo. */ -HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) +HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_021, TestSize.Level1) { AudioPolicyUtils* audioPolicyUtilsTest_ = nullptr; audioPolicyUtilsTest_ = &AudioPolicyUtils::GetInstance(); @@ -432,10 +432,11 @@ HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) AudioPipeInfo info; info.moduleInfo_.channels = "4"; - streamPropInfo->channelLayout_ = CH_LAYOUT_6POINT0_FRONT; std::shared_ptr streamPropInfo = std::make_shared(); - int32_t ret = audioPolicyUtilsTest_->UpdateMultiChannelModuleInfo(info, streamPropInfo); - EXPECT_EQ(ret, false); + streamPropInfo->channelLayout_ = CH_LAYOUT_6POINT0_FRONT; + audioPolicyUtilsTest_->UpdateMultiChannelModuleInfo(info, streamPropInfo); + EXPECT_EQ(info.moduleInfo_.channels, std::to_string(static_cast(CHANNEL_6))); + EXPECT_EQ(info.moduleInfo_.channelLayout, std::to_string(static_cast(CH_LAYOUT_5POINT1))); } } // namespace AudioStandard } // namespace OHOS -- Gitee From 4630592e94dc48ad983c666ed31f8d2ae1fda4be Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 18:49:06 +0800 Subject: [PATCH 10/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../node/src/hpae_node_common.cpp | 552 ++++++++++++++++-- 1 file changed, 505 insertions(+), 47 deletions(-) diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index 8dcca37409..2e0789b8a9 100644 --- a/services/audio_engine/node/src/hpae_node_common.cpp +++ b/services/audio_engine/node/src/hpae_node_common.cpp @@ -12,61 +12,519 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef LOG_TAG +#define LOG_TAG "HpaeNodeCommon" +#endif -#ifndef HPAE_NODE_COMMON_H -#define HPAE_NODE_COMMON_H -#include "hpae_define.h" -#include "audio_effect.h" -#include "audio_module_info.h" -#include "audio_service_hpae_dump_callback.h" +#include +#include "hpae_node_common.h" +#include "audio_errors.h" +#include "audio_engine_log.h" namespace OHOS { namespace AudioStandard { namespace HPAE { -bool CheckHpaeNodeInfoIsSame(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &curNodeInfo); -HpaeProcessorType TransStreamTypeToSceneType(AudioStreamType streamType); -HpaeProcessorType TransEffectSceneToSceneType(AudioEffectScene effectScene); -HpaeProcessorType TransSourceTypeToSceneType(SourceType sourceType); -bool CheckSceneTypeNeedEc(HpaeProcessorType processorType); -bool CheckSceneTypeNeedMicRef(HpaeProcessorType processorType); -std::string TransNodeInfoToStringKey(HpaeNodeInfo& nodeInfo); -AudioEnhanceScene TransProcessType2EnhanceScene(const HpaeProcessorType &processorType); -std::string TransProcessorTypeToSceneType(HpaeProcessorType processorType); -uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo); -size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo); -std::string ConvertSessionState2Str(HpaeSessionState state); -std::string ConvertStreamManagerState2Str(StreamManagerState state); -int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); -bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo); -int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo); -AudioSampleFormat TransFormatFromStringToEnum(std::string format); -void PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo); -std::string TransFormatFromEnumToString(AudioSampleFormat format); -AudioPipeType ConvertDeviceClassToPipe(const std::string &deviceClass); -void TransNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo, bool isCollaborationEnabled); -void RecoverNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo); -int32_t CheckFramelen(const HpaeSinkInfo &sinkInfo); -int32_t CheckStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSinkInfo &sinkInfo); -int32_t CheckSourceInfoFramelen(const HpaeSourceInfo &sourceInfo); -int32_t CheckSourceAndStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSourceInfo &sourceInfo); - -// for hidumper device / stream info trans, param should be HpaeSinkInfo / HpaeSourceInfo / HpaeStreamInfo -template -int32_t TransDeviceInfoToString(const T& info, std::string &config) -{ - if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) { - config += TransFormatFromEnumToString(info.format) + " "; - config += std::to_string(info.channels) + "ch "; - config += std::to_string(info.samplingRate) + "Hz"; +static constexpr uint64_t TIME_US_PER_S = 1000000; +static constexpr float MAX_SINK_VOLUME_LEVEL = 1.0; +static constexpr uint32_t DEFAULT_MULTICHANNEL_FRAME_LEN_MS = 20; +static constexpr uint32_t MS_PER_SECOND = 1000; +static constexpr uint32_t BASE_TEN = 10; +static constexpr uint32_t FRAME_LENGTH_LIMIT = 38400; + +static std::map g_streamTypeToSceneTypeMap = { + {STREAM_MUSIC, HPAE_SCENE_MUSIC}, + {STREAM_GAME, HPAE_SCENE_GAME}, + {STREAM_MOVIE, HPAE_SCENE_MOVIE}, + {STREAM_GAME, HPAE_SCENE_GAME}, + {STREAM_SPEECH, HPAE_SCENE_SPEECH}, + {STREAM_VOICE_RING, HPAE_SCENE_RING}, + {STREAM_VOICE_COMMUNICATION, HPAE_SCENE_VOIP_DOWN}, + {STREAM_MEDIA, HPAE_SCENE_OTHERS} +}; + +static std::map g_effectSceneToProcessorTypeMap = { + {SCENE_OTHERS, HPAE_SCENE_OTHERS}, + {SCENE_MUSIC, HPAE_SCENE_MUSIC}, + {SCENE_MOVIE, HPAE_SCENE_MOVIE}, + {SCENE_GAME, HPAE_SCENE_GAME}, + {SCENE_SPEECH, HPAE_SCENE_SPEECH}, + {SCENE_RING, HPAE_SCENE_RING}, + {SCENE_VOIP_DOWN, HPAE_SCENE_VOIP_DOWN}, + {SCENE_COLLABORATIVE, HPAE_SCENE_COLLABORATIVE} +}; + +static std::unordered_map g_sourceTypeToSceneTypeMap = { + {SOURCE_TYPE_MIC, HPAE_SCENE_RECORD}, + {SOURCE_TYPE_CAMCORDER, HPAE_SCENE_RECORD}, + {SOURCE_TYPE_VOICE_CALL, HPAE_SCENE_VOIP_UP}, + {SOURCE_TYPE_VOICE_COMMUNICATION, HPAE_SCENE_VOIP_UP}, + {SOURCE_TYPE_VOICE_TRANSCRIPTION, HPAE_SCENE_PRE_ENHANCE}, + {SOURCE_TYPE_VOICE_MESSAGE, HPAE_SCENE_VOICE_MESSAGE}, + {SOURCE_TYPE_VOICE_RECOGNITION, HPAE_SCENE_RECOGNITION} +}; + + +static std::unordered_set g_processorTypeNeedEcSet = { + HPAE_SCENE_VOIP_UP, + HPAE_SCENE_PRE_ENHANCE, + HPAE_SCENE_RECOGNITION, +}; + +static std::unordered_set g_processorTypeNeedMicRefSet = { + HPAE_SCENE_VOIP_UP, + HPAE_SCENE_RECORD, +}; + +static std::unordered_map g_processorTypeToSceneTypeMap = { + {HPAE_SCENE_RECORD, SCENE_RECORD}, + {HPAE_SCENE_VOIP_UP, SCENE_VOIP_UP}, + {HPAE_SCENE_PRE_ENHANCE, SCENE_PRE_ENHANCE}, + {HPAE_SCENE_VOICE_MESSAGE, SCENE_VOICE_MESSAGE}, + {HPAE_SCENE_RECOGNITION, SCENE_RECOGNITION}, +}; + +static std::unordered_map g_sessionStateToStrMap = { + {HPAE_SESSION_NEW, "NEW"}, + {HPAE_SESSION_PREPARED, "PREPARED"}, + {HPAE_SESSION_RUNNING, "RUNNING"}, + {HPAE_SESSION_PAUSING, "PAUSING"}, + {HPAE_SESSION_PAUSED, "PAUSED"}, + {HPAE_SESSION_STOPPING, "STOPPING"}, + {HPAE_SESSION_STOPPED, "STOPPED"}, + {HPAE_SESSION_RELEASED, "RELEASED"} +}; + +static std::unordered_map g_streamMgrStateToStrMap = { + {STREAM_MANAGER_NEW, "NEW"}, + {STREAM_MANAGER_IDLE, "IDLE"}, + {STREAM_MANAGER_RUNNING, "RUNNING"}, + {STREAM_MANAGER_SUSPENDED, "SUSPENDED"}, + {STREAM_MANAGER_RELEASED, "RELEASED"} +}; + +static std::map g_formatFromParserStrToEnum = { + {"s16", SAMPLE_S16LE}, + {"s16le", SAMPLE_S16LE}, + {"s24", SAMPLE_S24LE}, + {"s24le", SAMPLE_S24LE}, + {"s32", SAMPLE_S32LE}, + {"s32le", SAMPLE_S32LE}, + {"f32", SAMPLE_F32LE}, + {"f32le", SAMPLE_F32LE}, +}; + +static std::map g_formatFromParserEnumToStr = { + {SAMPLE_S16LE, "s16le"}, + {SAMPLE_S24LE, "s24le"}, + {SAMPLE_S32LE, "s32le"}, + {SAMPLE_F32LE, "f32le"}, +}; + +static std::unordered_map g_deviceClassToPipeMap = { + {"primary", PIPE_TYPE_NORMAL_OUT}, + {"a2dp", PIPE_TYPE_NORMAL_OUT}, + {"remote", PIPE_TYPE_NORMAL_OUT}, + {"dp", PIPE_TYPE_NORMAL_OUT}, + {"multichannel", PIPE_TYPE_MULTICHANNEL}, +}; + +static long StringToNum(const std::string &str) +{ + char *endptr; + long num = strtol(str.c_str(), &endptr, BASE_TEN); + CHECK_AND_RETURN_RET_LOG(endptr != nullptr && *endptr == '\0', 0, + "trans str \"%{public}s\" to num failed", str.c_str()); + return num; +} + +AudioPipeType ConvertDeviceClassToPipe(const std::string &deviceClass) +{ + auto item = g_deviceClassToPipeMap.find(deviceClass); + if (item == g_deviceClassToPipeMap.end()) { + return PIPE_TYPE_UNKNOWN; + } + return item->second; +} + +std::string ConvertSessionState2Str(HpaeSessionState state) +{ + if (g_sessionStateToStrMap.find(state) == g_sessionStateToStrMap.end()) { + return "UNKNOWN"; + } + return g_sessionStateToStrMap[state]; +} + +std::string ConvertStreamManagerState2Str(StreamManagerState state) +{ + if (g_streamMgrStateToStrMap.find(state) == g_streamMgrStateToStrMap.end()) { + return "UNKNOWN"; + } + return g_streamMgrStateToStrMap[state]; +} + +HpaeProcessorType TransStreamTypeToSceneType(AudioStreamType streamType) +{ + if (g_streamTypeToSceneTypeMap.find(streamType) == g_streamTypeToSceneTypeMap.end()) { + return HPAE_SCENE_EFFECT_NONE; + } else { + return g_streamTypeToSceneTypeMap[streamType]; + } +} + +HpaeProcessorType TransEffectSceneToSceneType(AudioEffectScene effectScene) +{ + if (g_effectSceneToProcessorTypeMap.find(effectScene) == g_effectSceneToProcessorTypeMap.end()) { + return HPAE_SCENE_EFFECT_NONE; + } else { + return g_effectSceneToProcessorTypeMap[effectScene]; + } +} + +void TransNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo, bool isCollaborationEnabled) +{ + if (isCollaborationEnabled) { + if (nodeInfo.effectInfo.effectScene == SCENE_MUSIC || nodeInfo.effectInfo.effectScene == SCENE_MOVIE) { + nodeInfo.effectInfo.lastEffectScene = nodeInfo.effectInfo.effectScene; + nodeInfo.effectInfo.effectScene = SCENE_COLLABORATIVE; + nodeInfo.sceneType = HPAE_SCENE_COLLABORATIVE; + AUDIO_INFO_LOG("collaboration enabled, effectScene from %{public}d, sceneType changed to %{public}d", + nodeInfo.effectInfo.lastEffectScene, nodeInfo.sceneType); + } + } else { + RecoverNodeInfoForCollaboration(nodeInfo); + } +} + +HpaeProcessorType TransSourceTypeToSceneType(SourceType sourceType) +{ + if (g_sourceTypeToSceneTypeMap.find(sourceType) == g_sourceTypeToSceneTypeMap.end()) { + return HPAE_SCENE_EFFECT_NONE; + } else { + return g_sourceTypeToSceneTypeMap[sourceType]; + } +} + +bool CheckSceneTypeNeedEc(HpaeProcessorType processorType) +{ + return g_processorTypeNeedEcSet.find(processorType) != g_processorTypeNeedEcSet.end(); +} + +bool CheckSceneTypeNeedMicRef(HpaeProcessorType processorType) +{ + return g_processorTypeNeedMicRefSet.find(processorType) != g_processorTypeNeedMicRefSet.end(); +} + +static std::unordered_map g_processorTypeToEffectSceneTypeMap = { + {HPAE_SCENE_DEFAULT, "HPAE_SCENE_DEFAULT"}, + {HPAE_SCENE_OTHERS, "SCENE_OTHERS"}, + {HPAE_SCENE_MUSIC, "SCENE_MUSIC"}, + {HPAE_SCENE_GAME, "SCENE_GAME"}, + {HPAE_SCENE_MOVIE, "SCENE_MOVIE"}, + {HPAE_SCENE_SPEECH, "SCENE_SPEECH"}, + {HPAE_SCENE_RING, "SCENE_RING"}, + {HPAE_SCENE_VOIP_DOWN, "SCENE_VOIP_DOWN"}, + {HPAE_SCENE_COLLABORATIVE, "SCENE_COLLABORATIVE"}}; + +std::string TransProcessorTypeToSceneType(HpaeProcessorType processorType) +{ + if (g_processorTypeToEffectSceneTypeMap.find(processorType) == g_processorTypeToEffectSceneTypeMap.end()) { + return "SCENE_EXTRA"; + } else { + return g_processorTypeToEffectSceneTypeMap[processorType]; + } +} + +bool CheckHpaeNodeInfoIsSame(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &curNodeInfo) +{ + return preNodeInfo.channels == curNodeInfo.channels && //&& preNodeInfo.format == curNodeInfo.format todo + preNodeInfo.samplingRate == curNodeInfo.samplingRate && + preNodeInfo.channelLayout == curNodeInfo.channelLayout; +} + +std::string TransNodeInfoToStringKey(HpaeNodeInfo& nodeInfo) +{ + std::string nodeKey = std::to_string(nodeInfo.sourceBufferType) + "_" + + std::to_string(nodeInfo.samplingRate) + "_" + + std::to_string(nodeInfo.channels) + "_" + + std::to_string(nodeInfo.format); + return nodeKey; +} + +AudioEnhanceScene TransProcessType2EnhanceScene(const HpaeProcessorType &processorType) +{ + if (g_processorTypeToSceneTypeMap.find(processorType) == g_processorTypeToSceneTypeMap.end()) { + return SCENE_NONE; + } else { + return g_processorTypeToSceneTypeMap[processorType]; + } +} + +size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo) +{ + return usTime * nodeInfo.samplingRate / TIME_US_PER_S / nodeInfo.frameLen; +} + +uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo) +{ + if (nodeInfo.channels == 0 || GetSizeFromFormat(nodeInfo.format) == 0 || nodeInfo.samplingRate == 0) { + AUDIO_ERR_LOG("invalid nodeInfo"); return 0; } - AUDIO_ERR_LOG("error info type"); - return ERROR_INVALID_PARAM; + + double samples = static_cast(bufferSize) / + (nodeInfo.channels * GetSizeFromFormat(nodeInfo.format)); + double seconds = samples / static_cast(nodeInfo.samplingRate); + double microseconds = seconds * TIME_US_PER_S; + + return static_cast(microseconds); +} + +AudioSampleFormat TransFormatFromStringToEnum(std::string format) +{ + return static_cast(g_formatFromParserStrToEnum[format]); +} + +int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) +{ + if (g_formatFromParserStrToEnum.find(audioModuleInfo.format) == g_formatFromParserStrToEnum.end()) { + AUDIO_ERR_LOG("openaudioport failed,format:%{public}s not supported", audioModuleInfo.format.c_str()); + return ERROR; + } + sinkInfo.deviceNetId = audioModuleInfo.networkId; + sinkInfo.deviceClass = audioModuleInfo.className; + sinkInfo.suspendTime = audioModuleInfo.suspendIdleTimeout; + AUDIO_INFO_LOG("HpaeManager::deviceNetId: %{public}s, deviceClass: %{public}s, suspend_time: %{public}u", + sinkInfo.deviceNetId.c_str(), + sinkInfo.deviceClass.c_str(), + sinkInfo.suspendTime); + sinkInfo.adapterName = audioModuleInfo.adapterName; + sinkInfo.lib = audioModuleInfo.lib; + sinkInfo.splitMode = audioModuleInfo.extra; + sinkInfo.filePath = audioModuleInfo.fileName; + + sinkInfo.samplingRate = static_cast(StringToNum(audioModuleInfo.rate)); + sinkInfo.format = static_cast(TransFormatFromStringToEnum(audioModuleInfo.format)); + sinkInfo.channels = static_cast(StringToNum(audioModuleInfo.channels)); + int32_t bufferSize = static_cast(StringToNum(audioModuleInfo.bufferSize)); + CHECK_AND_RETURN_RET_LOG(sinkInfo.channels != CHANNEL_UNKNOW && sinkInfo.format != INVALID_WIDTH, ERROR, + "channels or format is invalid"); + sinkInfo.frameLen = static_cast(bufferSize) / (sinkInfo.channels * + static_cast(GetSizeFromFormat(sinkInfo.format))); + sinkInfo.channelLayout = static_cast(StringToNum(audioModuleInfo.channelLayout)); + sinkInfo.deviceType = static_cast(StringToNum(audioModuleInfo.deviceType)); + sinkInfo.volume = MAX_SINK_VOLUME_LEVEL; + sinkInfo.openMicSpeaker = static_cast(StringToNum(audioModuleInfo.OpenMicSpeaker)); + sinkInfo.renderInIdleState = static_cast(StringToNum(audioModuleInfo.renderInIdleState)); + sinkInfo.offloadEnable = static_cast(StringToNum(audioModuleInfo.offloadEnable)); + sinkInfo.sinkLatency = static_cast(StringToNum(audioModuleInfo.sinkLatency)); + sinkInfo.fixedLatency = static_cast(StringToNum(audioModuleInfo.fixedLatency)); + sinkInfo.deviceName = audioModuleInfo.name; + if (audioModuleInfo.needEmptyChunk) { + sinkInfo.needEmptyChunk = audioModuleInfo.needEmptyChunk.value(); + } + AUDIO_INFO_LOG("sink info ch: %{public}u, channelLayout: %{public}" PRIu64, + sinkInfo.channels, + sinkInfo.channelLayout); + return SUCCESS; +} + +int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo) +{ + if (g_formatFromParserStrToEnum.find(audioModuleInfo.format) == g_formatFromParserStrToEnum.end()) { + AUDIO_ERR_LOG("openaudioport failed,format:%{public}s not supported", audioModuleInfo.format.c_str()); + return ERROR; + } + sourceInfo.deviceNetId = audioModuleInfo.networkId; + sourceInfo.deviceClass = audioModuleInfo.className; + sourceInfo.adapterName = audioModuleInfo.adapterName; + sourceInfo.sourceName = audioModuleInfo.name; // built_in_mic + sourceInfo.deviceName = audioModuleInfo.name; + sourceInfo.sourceType = static_cast(StringToNum(audioModuleInfo.sourceType)); + sourceInfo.filePath = audioModuleInfo.fileName; + int32_t bufferSize = static_cast(StringToNum(audioModuleInfo.bufferSize)); + sourceInfo.channels = static_cast(StringToNum(audioModuleInfo.channels)); + sourceInfo.format = TransFormatFromStringToEnum(audioModuleInfo.format); + CHECK_AND_RETURN_RET_LOG(sourceInfo.channels != CHANNEL_UNKNOW && sourceInfo.format != INVALID_WIDTH, ERROR, + "channels or format is invalid"); + sourceInfo.frameLen = static_cast(bufferSize) / (sourceInfo.channels * + static_cast(GetSizeFromFormat(sourceInfo.format))); + sourceInfo.samplingRate = static_cast(StringToNum(audioModuleInfo.rate)); + sourceInfo.channelLayout = 0ULL; + sourceInfo.deviceType = static_cast(StringToNum(audioModuleInfo.deviceType)); + sourceInfo.volume = MAX_SINK_VOLUME_LEVEL; // 1.0f; + + sourceInfo.ecType = static_cast(StringToNum(audioModuleInfo.ecType)); + sourceInfo.ecAdapterName = audioModuleInfo.ecAdapter; + sourceInfo.ecSamplingRate = static_cast(StringToNum(audioModuleInfo.ecSamplingRate)); + sourceInfo.ecFormat = TransFormatFromStringToEnum(audioModuleInfo.ecFormat); + sourceInfo.ecChannels = static_cast(StringToNum(audioModuleInfo.ecChannels)); + sourceInfo.ecFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.ecSamplingRate / MS_PER_SECOND); + + sourceInfo.micRef = static_cast(StringToNum(audioModuleInfo.openMicRef)); + sourceInfo.micRefSamplingRate = static_cast(StringToNum(audioModuleInfo.micRefRate)); + sourceInfo.micRefFormat = TransFormatFromStringToEnum(audioModuleInfo.micRefFormat); + sourceInfo.micRefChannels = static_cast(StringToNum(audioModuleInfo.micRefChannels)); + sourceInfo.openMicSpeaker = static_cast(StringToNum(audioModuleInfo.OpenMicSpeaker)); + sourceInfo.micRefFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.micRefSamplingRate / MS_PER_SECOND); + return SUCCESS; +} + +bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo) +{ + auto getKey = [](const HpaeSourceInfo &sourceInfo) { + return std::tie( + sourceInfo.deviceNetId, + sourceInfo.deviceClass, + sourceInfo.adapterName, + sourceInfo.sourceName, + sourceInfo.sourceType, + sourceInfo.filePath, + sourceInfo.deviceName, + sourceInfo.frameLen, + sourceInfo.samplingRate, + sourceInfo.format, + sourceInfo.channels, + sourceInfo.channelLayout, + sourceInfo.deviceType, + sourceInfo.volume, + sourceInfo.openMicSpeaker, + sourceInfo.ecType, + sourceInfo.ecFrameLen, + sourceInfo.ecSamplingRate, + sourceInfo.ecFormat, + sourceInfo.ecChannels, + sourceInfo.micRef, + sourceInfo.micRefFrameLen, + sourceInfo.micRefSamplingRate, + sourceInfo.micRefFormat, + sourceInfo.micRefChannels); + }; + return getKey(info) != getKey(oldInfo); +} + +void PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo) +{ + AUDIO_INFO_LOG("rate: %{public}s ch: %{public}s buffersize: %{public}s ", + audioModuleInfo.rate.c_str(), + audioModuleInfo.channels.c_str(), + audioModuleInfo.bufferSize.c_str()); + AUDIO_INFO_LOG("format: %{public}s name: %{public}s lib: %{public}s ", + audioModuleInfo.format.c_str(), + audioModuleInfo.name.c_str(), + audioModuleInfo.lib.c_str()); + AUDIO_INFO_LOG("deviceType: %{public}s className: %{public}s adapterName: %{public}s ", + audioModuleInfo.deviceType.c_str(), + audioModuleInfo.className.c_str(), + audioModuleInfo.adapterName.c_str()); + AUDIO_INFO_LOG("OpenMicSpeaker: %{public}s networkId: %{public}s fileName: %{public}s ", + audioModuleInfo.OpenMicSpeaker.c_str(), + audioModuleInfo.networkId.c_str(), + audioModuleInfo.fileName.c_str()); + AUDIO_INFO_LOG("fixedLatency: %{public}s sinkLatency: %{public}s renderInIdleState: %{public}s ", + audioModuleInfo.fixedLatency.c_str(), + audioModuleInfo.sinkLatency.c_str(), + audioModuleInfo.renderInIdleState.c_str()); + AUDIO_INFO_LOG("sceneName: %{public}s sourceType: %{public}s offloadEnable: %{public}s ", + audioModuleInfo.sceneName.c_str(), + audioModuleInfo.sourceType.c_str(), + audioModuleInfo.offloadEnable.c_str()); +} + +std::string TransFormatFromEnumToString(AudioSampleFormat format) +{ + CHECK_AND_RETURN_RET_LOG(g_formatFromParserEnumToStr.find(format) != g_formatFromParserEnumToStr.end(), + "", "error param format"); + return g_formatFromParserEnumToStr[format]; +} + +void RecoverNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo) +{ + if (nodeInfo.effectInfo.effectScene == SCENE_COLLABORATIVE) { + nodeInfo.effectInfo.effectScene = nodeInfo.effectInfo.lastEffectScene; + nodeInfo.sceneType = TransEffectSceneToSceneType(nodeInfo.effectInfo.effectScene); + AUDIO_INFO_LOG("collaboration disabled, effectScene changed to %{public}d, sceneType changed to %{public}d", + nodeInfo.effectInfo.effectScene, nodeInfo.sceneType); + } } + void TransStreamInfoToStreamDumpInfo(const std::unordered_map &streamInfoMap, - std::vector &dumpInfo); + std::vector &dumpInfo) +{ + std::transform(streamInfoMap.begin(), streamInfoMap.end(), std::back_inserter(dumpInfo), + [](const auto &pair) { + const HpaeSessionInfo &sessionInfo = pair.second; + std::string config; + TransDeviceInfoToString(sessionInfo.streamInfo, config); + return HpaeInputOutputInfo { + .sessionId = sessionInfo.streamInfo.sessionId, + .deviceName = sessionInfo.streamInfo.deviceName, + .uid = sessionInfo.streamInfo.uid, + .pid = sessionInfo.streamInfo.pid, + .tokenId = sessionInfo.streamInfo.tokenId, + .offloadEnable = sessionInfo.offloadEnable, + .privacyType = sessionInfo.streamInfo.privacyType, + .config = config, + .state = sessionInfo.state, + .startTime = sessionInfo.startTime + }; + }); +} + +int32_t CheckStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSinkInfo &sinkInfo) +{ + if (streamInfo.frameLen == 0) { + AUDIO_ERR_LOG("FrameLen is 0."); + return ERROR; + } else if (streamInfo.frameLen > FRAME_LENGTH_LIMIT) { + AUDIO_ERR_LOG("FrameLen is over-sized."); + return ERROR; + } + if (streamInfo.frameLen * sinkInfo.samplingRate != streamInfo.samplingRate * sinkInfo.frameLen) { + AUDIO_ERR_LOG("Framelen is not proportional."); + return ERROR; + } + return SUCCESS; +} + +int32_t CheckSourceAndStreamInfo(const HpaeStreamInfo &streamInfo, const HpaeSourceInfo &sourceInfo) +{ + if (streamInfo.frameLen == 0) { + AUDIO_ERR_LOG("FrameLen is 0."); + return ERROR; + } else if (streamInfo.frameLen > FRAME_LENGTH_LIMIT) { + AUDIO_ERR_LOG("FrameLen is over-sized."); + return ERROR; + } + if (streamInfo.frameLen * sourceInfo.samplingRate != streamInfo.samplingRate * sourceInfo.frameLen) { + AUDIO_ERR_LOG("Framelen is not proportional."); + return ERROR; + } + return SUCCESS; +} + +int32_t CheckFramelen(const HpaeSinkInfo &sinkInfo) +{ + if (sinkInfo.frameLen == 0) { + AUDIO_ERR_LOG("FrameLen is 0."); + return ERROR; + } else if (sinkInfo.frameLen > FRAME_LENGTH_LIMIT) { + AUDIO_ERR_LOG("FrameLen is over-sized."); + return ERROR; + } + return SUCCESS; +} + +int32_t CheckSourceInfoFramelen(const HpaeSourceInfo &sourceInfo) +{ + if (sourceInfo.frameLen == 0) { + AUDIO_ERR_LOG("FrameLen is 0."); + return ERROR; + } else if (sourceInfo.frameLen > FRAME_LENGTH_LIMIT) { + AUDIO_ERR_LOG("FrameLen is over-sized."); + return ERROR; + } + return SUCCESS; +} } // namespace HPAE } // namespace AudioStandard -} // namespace OHOS -#endif \ No newline at end of file +} // namespace OHOS \ No newline at end of file -- Gitee From e5faf25344023c9a59bc97125976f74330a534e0 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 18:59:27 +0800 Subject: [PATCH 11/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- services/audio_engine/node/include/hpae_node_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/audio_engine/node/include/hpae_node_common.h b/services/audio_engine/node/include/hpae_node_common.h index 8dcca37409..c698751a32 100644 --- a/services/audio_engine/node/include/hpae_node_common.h +++ b/services/audio_engine/node/include/hpae_node_common.h @@ -69,4 +69,5 @@ void TransStreamInfoToStreamDumpInfo(const std::unordered_map Date: Thu, 11 Sep 2025 19:00:17 +0800 Subject: [PATCH 12/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- services/audio_engine/node/include/hpae_node_common.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/audio_engine/node/include/hpae_node_common.h b/services/audio_engine/node/include/hpae_node_common.h index c698751a32..8dcca37409 100644 --- a/services/audio_engine/node/include/hpae_node_common.h +++ b/services/audio_engine/node/include/hpae_node_common.h @@ -69,5 +69,4 @@ void TransStreamInfoToStreamDumpInfo(const std::unordered_map Date: Thu, 11 Sep 2025 20:23:48 +0800 Subject: [PATCH 13/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- services/audio_engine/manager/src/hpae_renderer_manager.cpp | 2 +- .../server/infra/datashare/src/audio_policy_utils.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/audio_engine/manager/src/hpae_renderer_manager.cpp b/services/audio_engine/manager/src/hpae_renderer_manager.cpp index 4e282d2e80..7f8da48bb5 100644 --- a/services/audio_engine/manager/src/hpae_renderer_manager.cpp +++ b/services/audio_engine/manager/src/hpae_renderer_manager.cpp @@ -876,7 +876,7 @@ int32_t HpaeRendererManager::InitManager(bool isReload) return checkRet; } nodeInfo.channels = sinkInfo_.channels; - nodeInfo.channelLayout = static_cast(sinkInfo_.channelLayout); + nodeInfo.channelLayout = static_cast(sinkInfo_.channelLayout); nodeInfo.format = sinkInfo_.format; nodeInfo.frameLen = sinkInfo_.frameLen; nodeInfo.nodeId = 0; diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index a3fcb526f2..4f1ad1faf5 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -793,12 +793,13 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) } } -void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, std::shared_ptr streamPropInfo) +void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, + std::shared_ptr streamPropInfo) { if (!AudioPolicyManagerFactory::GetAudioPolicyManager(). IsChannelLayoutSupportForDspEffect(streamPropInfo->channelLayout)) { AUDIO_INFO_LOG("not support channelLayout:%{public}" PRIu64 ", use default 5.1", channelLayout); - info.moduleInfo_.bufferSize = + info.moduleInfo_.bufferSize = std::to_string(((streamPropInfo->bufferSize_ * static_cast(CHANNEL_6)) / std::stoul(info.moduleInfo_.channels))); info.moduleInfo_.channels = std::to_string(static_cast(CHANNEL_6)); -- Gitee From f41b07e03c1780e943c9c4e4c901faa760fb1800 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 20:56:35 +0800 Subject: [PATCH 14/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index afbb1df36f..76b93f839d 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -1999,7 +1999,7 @@ bool AudioEffectChainManager::IsChannelLayoutSupportForDspEffect(AudioChannelLay *tempChannelLayout = channelLayout; CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, false, "audioEffectHdiParam_ is nullptr"); if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { - AUDIO_WARNING_LOG("query channel layout support failed :%{public}lu", channelLayout); + AUDIO_WARNING_LOG("query channel layout support failed :%{public}" PRIu64, channelLayout); return false; } return true; -- Gitee From 52286c80f3349a23976002e877a1ab2af68138d2 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 21:45:28 +0800 Subject: [PATCH 15/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../native/audioeffect/libaudio_effect.versionscript | 1 - frameworks/native/pulseaudio/modules/hdi/hdi_sink.c | 4 ---- .../audio_effect_enhance_fuzzer.cpp | 12 ------------ 3 files changed, 17 deletions(-) diff --git a/frameworks/native/audioeffect/libaudio_effect.versionscript b/frameworks/native/audioeffect/libaudio_effect.versionscript index fd9563a196..573f9fbe16 100644 --- a/frameworks/native/audioeffect/libaudio_effect.versionscript +++ b/frameworks/native/audioeffect/libaudio_effect.versionscript @@ -75,7 +75,6 @@ *SendInitCommand*; *EnhanceChainManagerSendInitCommand*; *InitEffectBuffer*; - *EffectChainManagerQueryHdiSupportedChannelLayout*; *LoadEffectProperties*; *ApplyAudioEffectChain*; *CheckAndAddSessionID*; diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index 966f1393c7..78b8f50ecc 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -3272,8 +3272,6 @@ static void PaInputStateChangeCbMultiChannel(struct Userdata *u, pa_sink_input * const bool starting = i->thread_info.state == PA_SINK_INPUT_CORKED && state == PA_SINK_INPUT_RUNNING; const bool stopping = state == PA_SINK_INPUT_UNLINKED; - EffectChainManagerQueryHdiSupportedChannelLayout(&u->multiChannel.sinkChannel, &u->multiChannel.sinkChannelLayout); - if (corking) { SetFadeoutState(i->index, NO_FADE); } @@ -3440,7 +3438,6 @@ static void SinkRenderMultiChannelProcess(pa_sink *si, size_t length, pa_memchun pa_assert_se(u = si->userdata); UpdateStreamVolumeMap(u); - EffectChainManagerQueryHdiSupportedChannelLayout(&u->multiChannel.sinkChannel, &u->multiChannel.sinkChannelLayout); chunkIn->memblock = pa_memblock_new(si->core->mempool, length * IN_CHANNEL_NUM_MAX / DEFAULT_IN_CHANNEL_NUM); size_t tmpLength = length * u->multiChannel.sinkChannel / DEFAULT_IN_CHANNEL_NUM; @@ -4131,7 +4128,6 @@ static int32_t SinkSetStateInIoThreadCbStartMultiChannel(struct Userdata *u, pa_ u->multiChannel.timestamp = pa_rtclock_now(); - EffectChainManagerQueryHdiSupportedChannelLayout(&u->multiChannel.sinkChannel, &u->multiChannel.sinkChannelLayout); ResetMultiChannelHdiState(u); return 0; } diff --git a/test/fuzztest/audioeffectenhance_fuzzer/audio_effect_enhance_fuzzer.cpp b/test/fuzztest/audioeffectenhance_fuzzer/audio_effect_enhance_fuzzer.cpp index f344dc4142..79062bdc22 100644 --- a/test/fuzztest/audioeffectenhance_fuzzer/audio_effect_enhance_fuzzer.cpp +++ b/test/fuzztest/audioeffectenhance_fuzzer/audio_effect_enhance_fuzzer.cpp @@ -238,17 +238,6 @@ void EffectChainManagerReturnEffectChannelInfoFuzzTest() #endif } -void EffectChainManagerQueryHdiSupportedChannelLayoutFuzzTest() -{ -#ifdef SUPPORT_OLD_ENGINE - uint32_t channels = GetData(); - uint64_t channelLayout = GetData(); - // Intentionally test with nullptr for fuzzing - EffectChainManagerQueryHdiSupportedChannelLayout(nullptr, nullptr); - EffectChainManagerQueryHdiSupportedChannelLayout(&channels, &channelLayout); -#endif -} - void EffectChainManagerSceneCheckFuzzTest() { #ifdef SUPPORT_OLD_ENGINE @@ -425,7 +414,6 @@ FuzzFunc *g_fuzzFuncs[] = { ConvertChLayoutToPaChMapFuzzTest, EffectChainManagerDeleteSessionInfoFuzzTest, EffectChainManagerReturnEffectChannelInfoFuzzTest, - EffectChainManagerQueryHdiSupportedChannelLayoutFuzzTest, EffectChainManagerSceneCheckFuzzTest, EffectChainManagerGetSceneCountFuzzTest, AudioEnhanceChainMoreFuzzTest, -- Gitee From fa7484fd9d3235c4c538763df7d286daad3b5ec3 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Thu, 11 Sep 2025 21:58:36 +0800 Subject: [PATCH 16/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../server/infra/datashare/src/audio_policy_utils.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index 4f1ad1faf5..87bcf9bba5 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -797,11 +797,12 @@ void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, std::shared_ptr streamPropInfo) { if (!AudioPolicyManagerFactory::GetAudioPolicyManager(). - IsChannelLayoutSupportForDspEffect(streamPropInfo->channelLayout)) { - AUDIO_INFO_LOG("not support channelLayout:%{public}" PRIu64 ", use default 5.1", channelLayout); + IsChannelLayoutSupportForDspEffect(streamPropInfo->channelLayout_)) { + AUDIO_INFO_LOG("not support channelLayout:%{public}" PRIu64 , streamPropInfo->channelLayout_); info.moduleInfo_.bufferSize = std::to_string(((streamPropInfo->bufferSize_ * static_cast(CHANNEL_6)) / std::stoul(info.moduleInfo_.channels))); + // use default 5.1 channel for multi-channel pipe info.moduleInfo_.channels = std::to_string(static_cast(CHANNEL_6)); info.moduleInfo_.channelLayout = std::to_string(static_cast(CH_LAYOUT_5POINT1)); } -- Gitee From 03e63acaa190986f7c29a8c2f7c24ed4f7a6b206 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 09:14:25 +0800 Subject: [PATCH 17/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../audio_effect_chain_manager_unit_test.cpp | 12 +++++++++++ .../src/audio_policy_utils_unit_test.cpp | 21 ------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index e2a43fa2ee..6ccaa50f11 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -3889,5 +3889,17 @@ HWTEST(AudioEffectChainManagerUnitTest, SetAbsVolumeStateToEffect_001, TestSize. EXPECT_EQ(ret, SUCCESS); AudioEffectChainManager::GetInstance()->ResetInfo(); } + +/** +* @tc.name : Test IsChannelLayoutSupportForDspEffect API +* @tc.number : IsChannelLayoutSupportForDspEffect_004 +* @tc.desc : Test IsChannelLayoutSupportForDspEffect interface. +*/ +HWTEST(AudioEffectChainManagerUnitTest, IsChannelLayoutSupportForDspEffect_001, TestSize.Level1) +{ + AudioEffectChainManager::GetInstance()->InitHdiState(); + int32_t ret = AudioEffectChainManager::GetInstance()->IsChannelLayoutSupportForDspEffect(CH_LAYOUT_6POINT0_FRONT); + EXPECT_EQ(ret, ERROR); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp index a950d1ef5a..f29bc6ef14 100644 --- a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp @@ -417,26 +417,5 @@ HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) ret = audioPolicyUtilsTest_->IsWirelessDevice(type); EXPECT_EQ(ret, false); } - -/** - * @tc.name : Test UpdateMultiChannelModuleInfo API - * @tc.type : FUNC - * @tc.number: AudioPolicyUtilsUnitTest_021 - * @tc.desc : Test UpdateMultiChannelModuleInfo. - */ -HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_021, TestSize.Level1) -{ - AudioPolicyUtils* audioPolicyUtilsTest_ = nullptr; - audioPolicyUtilsTest_ = &AudioPolicyUtils::GetInstance(); - ASSERT_TRUE(audioPolicyUtilsTest_ != nullptr); - - AudioPipeInfo info; - info.moduleInfo_.channels = "4"; - std::shared_ptr streamPropInfo = std::make_shared(); - streamPropInfo->channelLayout_ = CH_LAYOUT_6POINT0_FRONT; - audioPolicyUtilsTest_->UpdateMultiChannelModuleInfo(info, streamPropInfo); - EXPECT_EQ(info.moduleInfo_.channels, std::to_string(static_cast(CHANNEL_6))); - EXPECT_EQ(info.moduleInfo_.channelLayout, std::to_string(static_cast(CH_LAYOUT_5POINT1))); -} } // namespace AudioStandard } // namespace OHOS -- Gitee From 629cbd42573da1b9ed553c59da436f97fffaf8a8 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 10:32:06 +0800 Subject: [PATCH 18/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../src/pro_audio_service_adapter_unit_test.cpp | 15 --------------- .../src/audio_effect_chain_manager_unit_test.cpp | 6 ++++-- .../domain/pipe/src/audio_pipe_selector.cpp | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp index e9ad250327..e07975fd19 100644 --- a/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp +++ b/frameworks/native/audioadapter/test/unittest/src/pro_audio_service_adapter_unit_test.cpp @@ -417,20 +417,5 @@ HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_ReloadAudioPort_007, TestSize portId = impl_->ReloadAudioPort(moduleInfo.lib, moduleInfo); EXPECT_EQ(portId, -1); } - -/** - * @tc.name: Pro_Audio_IsChannelLayoutSupportForDspEffect_001 - * @tc.desc: test check if channel layout support for dsp - * @tc.type: FUNC - */ -HWTEST_F(ProAudioServiceAdapterUnitTest, Pro_Audio_IsChannelLayoutSupportForDspEffect_001, TestSize.Level1) -{ - AudioChannelLayout channelLayout = CH_LAYOUT_5POINT1; - int32_t ret = impl_->IsChannelLayoutSupportForDspEffect(moduleInfo.lib, moduleInfo); - EXPECT_GE(SUCCESS, ret); - channelLayout = CH_LAYOUT_4POINT0; - ret = impl_->IsChannelLayoutSupportForDspEffect(moduleInfo.lib, moduleInfo); - EXPECT_GE(ERROR, ret); -} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index 6ccaa50f11..c90489f607 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -3897,9 +3897,11 @@ HWTEST(AudioEffectChainManagerUnitTest, SetAbsVolumeStateToEffect_001, TestSize. */ HWTEST(AudioEffectChainManagerUnitTest, IsChannelLayoutSupportForDspEffect_001, TestSize.Level1) { + std::shared_ptr audioEffectHdiParam = std::make_shared(); + AudioEffectChainManager::GetInstance()->audioEffectHdiParam_ = audioEffectHdiParam; AudioEffectChainManager::GetInstance()->InitHdiState(); - int32_t ret = AudioEffectChainManager::GetInstance()->IsChannelLayoutSupportForDspEffect(CH_LAYOUT_6POINT0_FRONT); - EXPECT_EQ(ret, ERROR); + bool ret = AudioEffectChainManager::GetInstance()->IsChannelLayoutSupportForDspEffect(CH_LAYOUT_6POINT0_FRONT); + EXPECT_EQ(ret, false); } } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp index d9305fe192..cbf1eb6af8 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_pipe_selector.cpp @@ -467,7 +467,7 @@ static void FillSpecialPipeInfo(AudioPipeInfo &info, std::shared_ptrname_ == "offload_output") { info.moduleInfo_.className = "offload"; -- Gitee From 22444dfd2a60a714848ddb8c67d17944bfb88280 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 11:06:03 +0800 Subject: [PATCH 19/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- frameworks/native/audioeffect/libaudio_effect.versionscript | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/audioeffect/libaudio_effect.versionscript b/frameworks/native/audioeffect/libaudio_effect.versionscript index 573f9fbe16..2f617f4fd0 100644 --- a/frameworks/native/audioeffect/libaudio_effect.versionscript +++ b/frameworks/native/audioeffect/libaudio_effect.versionscript @@ -97,6 +97,7 @@ *ResetInfo*; *SetAbsVolumeStateToEffect*; *DeleteStreamVolume*; + *IsChannelLayoutSupportForDspEffect*; local: *; }; \ No newline at end of file -- Gitee From 9de3b24eccfd23a27a599b38b2a37c5ffe55bba9 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 11:38:39 +0800 Subject: [PATCH 20/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../hpae_mixer_node_fuzzer.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test/fuzztest/hpaemixernode_fuzzer/hpae_mixer_node_fuzzer.cpp b/test/fuzztest/hpaemixernode_fuzzer/hpae_mixer_node_fuzzer.cpp index 15b1c5c503..f999edaf3d 100644 --- a/test/fuzztest/hpaemixernode_fuzzer/hpae_mixer_node_fuzzer.cpp +++ b/test/fuzztest/hpaemixernode_fuzzer/hpae_mixer_node_fuzzer.cpp @@ -159,20 +159,6 @@ void HpaeNodeCommonConvertDatalenToUsFuzzTest() ConvertDatalenToUs(bufferSize, nodeInfo); } -void HpaeNodeCommonAdjustMchSinkInfoFuzzTest() -{ - AudioModuleInfo audioModuleInfo; - audioModuleInfo.channelLayout = "CH_LAYOUT_STEREO"; - HpaeSinkInfo sinkInfo; - sinkInfo.deviceName = "DP_MCH_speaker"; - bool isTestString = g_fuzzUtils.GetData(); - if (isTestString) { - sinkInfo.deviceName = "test_device_name"; - } - - AdjustMchSinkInfo(audioModuleInfo, sinkInfo); -} - void HpaeNodeCommonCheckSourceInfoIsDifferentFuzzTest() { HpaeSourceInfo oldInfo; @@ -590,7 +576,6 @@ vector g_testPtrs = { HpaeNodeCommonTransProcessType2EnhanceSceneFuzzTest, HpaeNodeCommonConvertUsToFrameCountFuzzTest, HpaeNodeCommonConvertDatalenToUsFuzzTest, - HpaeNodeCommonAdjustMchSinkInfoFuzzTest, HpaeNodeCommonCheckSourceInfoIsDifferentFuzzTest, HpaeNodeCommonRecoverNodeInfoForCollaborationFuzzTest, HpaeProcessClusterDoProcessFuzzTest, -- Gitee From 7de7eb55e8d122ff9ae331fe53fd2bf6b2c8506b Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 11:44:05 +0800 Subject: [PATCH 21/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../src/audio_policy_utils_unit_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp index f29bc6ef14..f37305b5bd 100644 --- a/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_utils_unit_test/src/audio_policy_utils_unit_test.cpp @@ -417,5 +417,6 @@ HWTEST(AudioPolicyUtilsUnitTest, AudioPolicyUtilsUnitTest_020, TestSize.Level1) ret = audioPolicyUtilsTest_->IsWirelessDevice(type); EXPECT_EQ(ret, false); } + } // namespace AudioStandard } // namespace OHOS -- Gitee From 0b76c91e6143364aea52ddec9e8751d2a027f89c Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 14:17:03 +0800 Subject: [PATCH 22/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../datashare/src/audio_policy_utils.cpp | 2 +- .../audio_effect_chain_fuzzer.cpp | 22 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp index 87bcf9bba5..cd4188c5f7 100644 --- a/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp +++ b/services/audio_policy/server/infra/datashare/src/audio_policy_utils.cpp @@ -798,7 +798,7 @@ void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, { if (!AudioPolicyManagerFactory::GetAudioPolicyManager(). IsChannelLayoutSupportForDspEffect(streamPropInfo->channelLayout_)) { - AUDIO_INFO_LOG("not support channelLayout:%{public}" PRIu64 , streamPropInfo->channelLayout_); + AUDIO_INFO_LOG("not support channelLayout:%{public}" PRIu64, streamPropInfo->channelLayout_); info.moduleInfo_.bufferSize = std::to_string(((streamPropInfo->bufferSize_ * static_cast(CHANNEL_6)) / std::stoul(info.moduleInfo_.channels))); diff --git a/test/fuzztest/audioeffectchain_fuzzer/audio_effect_chain_fuzzer.cpp b/test/fuzztest/audioeffectchain_fuzzer/audio_effect_chain_fuzzer.cpp index 05d2d82281..3a31bd42e7 100644 --- a/test/fuzztest/audioeffectchain_fuzzer/audio_effect_chain_fuzzer.cpp +++ b/test/fuzztest/audioeffectchain_fuzzer/audio_effect_chain_fuzzer.cpp @@ -453,27 +453,6 @@ void AudioEffectChainStreamVolumeUpdateFuzzTest() audioEffectChainManager->StreamVolumeUpdate(sessionIDString, streamVolume); } -void AudioEffectChainQueryHdiSupportedChannelInfoFuzzTest() -{ - AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); - if (audioEffectChainManager == nullptr) { - return; - } - - uint32_t channels = GetData(); - uint64_t channelLayout = GetData(); - SessionEffectInfo sessionEffectInfo; - sessionEffectInfo.channelLayout = GetData(); - sessionEffectInfo.channels = GetData(); - std::set sceneType = {"123"}; - audioEffectChainManager->isInitialized_ = GetData(); - audioEffectChainManager->sceneTypeToSessionIDMap_.insert({"test", sceneType}); - audioEffectChainManager->sessionIDToEffectInfoMap_.insert({"123", sessionEffectInfo}); - - audioEffectChainManager->QueryHdiSupportedChannelInfo(channels, channelLayout); - audioEffectChainManager->ResetInfo(); -} - void AudioEffectChainUpdateEffectBtOffloadSupportedFuzzTest() { AudioEffectChainManager *audioEffectChainManager = AudioEffectChainManager::GetInstance(); @@ -1224,7 +1203,6 @@ TestFuncs g_testFuncs = { AudioEnhanceChainFuzzTest, AudioEffectChainGetOutputChannelInfoFuzzTest, AudioEffectChainStreamVolumeUpdateFuzzTest, - AudioEffectChainQueryHdiSupportedChannelInfoFuzzTest, AudioEffectChainUpdateEffectBtOffloadSupportedFuzzTest, AudioEffectChainLoadEffectPropertiesFuzzTest, AudioEffectChainSetAudioEffectPropertyFuzzTest, -- Gitee From c1dc8f78285be5db97e87f98e9d866cb8138edc2 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 15:19:00 +0800 Subject: [PATCH 23/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../sink/multichannel_audio_render_sink_unit_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp b/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp index 697f478b40..535fb1b65f 100644 --- a/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp +++ b/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp @@ -678,9 +678,9 @@ HWTEST_F(MultichannelAudioRenderSinkUnitTest, MultichannelSinkUnitTest_034, Test EXPECT_NE(multichannelAudioRenderSink, nullptr); multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(true); - EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_, true); + EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_.load(), true); multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(false); - EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_, false); + EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_.load(), false); } } // namespace AudioStandard } // namespace OHOS \ No newline at end of file -- Gitee From 45889447179576f62d58da59a45f7db6d84275c0 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Fri, 12 Sep 2025 16:06:42 +0800 Subject: [PATCH 24/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../sink/multichannel_audio_render_sink_unit_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp b/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp index 535fb1b65f..3ff2a4d095 100644 --- a/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp +++ b/frameworks/native/hdiadapter_new/test/unittest/sink/multichannel_audio_render_sink_unit_test.cpp @@ -677,10 +677,10 @@ HWTEST_F(MultichannelAudioRenderSinkUnitTest, MultichannelSinkUnitTest_034, Test auto multichannelAudioRenderSink = std::make_shared(HDI_ID_INFO_DP); EXPECT_NE(multichannelAudioRenderSink, nullptr); - multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(true); - EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_.load(), true); - multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(false); - EXPECT_EQ(multichannelAudioRenderSink->switchDeviceMute_.load(), false); + int32_t ret = multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(true); + EXPECT_EQ(ret, SUCCESS); + ret = multichannelAudioRenderSink->SetSinkMuteForSwitchDevice(false); + EXPECT_EQ(ret, SUCCESS); } } // namespace AudioStandard } // namespace OHOS \ No newline at end of file -- Gitee From c6d5cdd037473aa71e1617a5b5eb49de17169627 Mon Sep 17 00:00:00 2001 From: yaojingyu2008 Date: Sat, 13 Sep 2025 11:40:07 +0800 Subject: [PATCH 25/25] realize mix strategy for multichannel Signed-off-by: yaojingyu2008 --- .../native/audioeffect/src/audio_effect_chain_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp index 76b93f839d..dd0a77b6aa 100644 --- a/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp +++ b/frameworks/native/audioeffect/src/audio_effect_chain_manager.cpp @@ -1998,7 +1998,7 @@ bool AudioEffectChainManager::IsChannelLayoutSupportForDspEffect(AudioChannelLay uint64_t* tempChannelLayout = reinterpret_cast(effectHdiInput_ + 1); *tempChannelLayout = channelLayout; CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, false, "audioEffectHdiParam_ is nullptr"); - if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, deviceType_) != SUCCESS) { AUDIO_WARNING_LOG("query channel layout support failed :%{public}" PRIu64, channelLayout); return false; } -- Gitee