diff --git a/frameworks/native/audioadapter/include/audio_service_adapter.h b/frameworks/native/audioadapter/include/audio_service_adapter.h index 35b6189dd3495d85ea0d4c930705a1b72017d778..6b368ae8819d150fb2ea1166645b6ab7746ab291 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 8fed4960e8db39d16ea3da78b8b2355eda8bc487..3d3387759913200aeab294d341b7ebed940f33bf 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 76c53c3a78878a8c5e145e2f929b30750d62805d..a93bf16a9c369a37ceafd1468a20ddb4840e158d 100644 --- a/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pro_audio_service_adapter_impl.cpp @@ -568,6 +568,12 @@ int32_t ProAudioServiceAdapterImpl::SetSystemVolumeToEffect(AudioStreamType stre IHpaeManager::GetHpaeManager().SetEffectSystemVolume(streamType, volume); return SUCCESS; } + +bool ProAudioServiceAdapterImpl::IsChannelLayoutSupportForDspEffect(AudioChannelLayout channelLayout) +{ + lock_guard lock(lock_); + return IHpaeManager::GetHpaeManager().IsChannelLayoutSupportForDspEffect(channelLayout); +} } // 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 beb67f05ab9cdd756555cc767bca20dd655b2d49..2fe8a3c4bfbcb8d38541525de6d9de353b07c831 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 79b0673113a64e2ece359666864ac949e856dc15..4fc79b276d2fef421aed00f3524b88f88092b3d8 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/libaudio_effect.versionscript b/frameworks/native/audioeffect/libaudio_effect.versionscript index fd9563a1968da9a1d0b7eabab84291c13c62bb7e..2f617f4fd070c56ff375d093a7c1ad68c39d3201 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*; @@ -98,6 +97,7 @@ *ResetInfo*; *SetAbsVolumeStateToEffect*; *DeleteStreamVolume*; + *IsChannelLayoutSupportForDspEffect*; local: *; }; \ No newline at end of file diff --git a/frameworks/native/audioeffect/src/audio_effect_chain_adapter.cpp b/frameworks/native/audioeffect/src/audio_effect_chain_adapter.cpp index b00485e877fcf82dae291dd405d779a2129d7268..6cd520fc42e16225008bc8616eb87b44596b6787 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 45c8a26ace3e2ac9f845795b71755e014e4b8fc6..dd0a77b6aa823a4cd85cf1dc075e67b2a603f37d 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; @@ -490,8 +489,11 @@ 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"); + 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; + } } return SUCCESS; } @@ -623,9 +625,11 @@ int32_t AudioEffectChainManager::EffectDspRotationUpdate(std::shared_ptrUpdateHdiState(effectHdiInput_); - CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "set hdi rotation failed"); - + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, ERROR, "audioEffectHdiParam_ is nullptr"); + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_) != SUCCESS) { + AUDIO_WARNING_LOG("set hdi rotation failed"); + return ERROR; + } return SUCCESS; } @@ -721,6 +725,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"); @@ -822,58 +827,13 @@ 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; - } + 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; } return SUCCESS; } -// LCOV_EXCL_STOP // LCOV_EXCL_START void AudioEffectChainManager::UpdateSensorState() @@ -881,6 +841,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"); @@ -1000,6 +961,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"); } @@ -1016,6 +978,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()); } @@ -1381,9 +1344,10 @@ 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_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"); @@ -1392,9 +1356,10 @@ 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_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."); @@ -1610,6 +1575,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) { @@ -1998,6 +1964,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); @@ -2024,5 +1991,18 @@ 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; + CHECK_AND_RETURN_RET_LOG(audioEffectHdiParam_ != nullptr, false, "audioEffectHdiParam_ is nullptr"); + if (audioEffectHdiParam_->UpdateHdiState(effectHdiInput_, deviceType_) != SUCCESS) { + AUDIO_WARNING_LOG("query channel layout support failed :%{public}" PRIu64, channelLayout); + return false; + } + return true; +} } // 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 3a35b3446d3356ffd187bcf5b9c01e3ce484fee5..c90489f6077443150d61fee5280d902312f69fb1 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 @@ -3986,5 +3889,19 @@ 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) +{ + std::shared_ptr audioEffectHdiParam = std::make_shared(); + AudioEffectChainManager::GetInstance()->audioEffectHdiParam_ = audioEffectHdiParam; + AudioEffectChainManager::GetInstance()->InitHdiState(); + bool ret = AudioEffectChainManager::GetInstance()->IsChannelLayoutSupportForDspEffect(CH_LAYOUT_6POINT0_FRONT); + EXPECT_EQ(ret, false); +} } // 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 5d2f9290bb5ba70ce5307459bb907b2326df9456..87a3fb42b865b0394445b840bcd11d288cc6ee1b 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); @@ -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"; @@ -147,6 +144,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 4f0f36ddce2fd270f65bdc91d143630ca59e0160..ff48fd0e0ee2a32052c1fe59fba9a4fcd3700fa8 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"); @@ -228,7 +229,7 @@ int32_t MultichannelAudioRenderSink::RenderFrame(char &data, uint64_t len, uint6 } --emptyFrameCount_; if (emptyFrameCount_ == 0) { - switchDeviceCV_.notify_all(); + updateActiveDeviceCV_.notify_all(); } } @@ -410,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; @@ -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/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 e11d64ff2751460ac6463ffadfe550ca479d284b..3ff2a4d0956acaf3ca474743f9e4e62b4943b280 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); + + 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 diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index 8adbf230c96518fa29f7582eefac45138b8eea26..cf609b7f9ec39c5a479b1dac5b64e51b922986c0 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -3291,8 +3291,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); } @@ -3459,7 +3457,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; @@ -4150,7 +4147,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/services/audio_engine/manager/include/hpae_manager.h b/services/audio_engine/manager/include/hpae_manager.h index 82497ab535f29d238d8ae02115b025c43caf0948..e497b0c7b5231875cd688a87ea3e80bd1d94af51 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 45218dd808c2b95fc8cdeed780f2622146149eb7..b6c9df5abdb8912d78cc8fb9241aada8741d8a15 100644 --- a/services/audio_engine/manager/include/hpae_manager_impl.h +++ b/services/audio_engine/manager/include/hpae_manager_impl.h @@ -139,6 +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; diff --git a/services/audio_engine/manager/include/hpae_policy_manager.h b/services/audio_engine/manager/include/hpae_policy_manager.h index 8a3d74236322f4f628796df6a7c3c4c3e7342ae6..f4029b51a68eba4956b8a6068ccb75deab1d66d8 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/include/i_hpae_manager.h b/services/audio_engine/manager/include/i_hpae_manager.h index 3f1872f3299e267d82c76312ae47180bbeac8964..4a121bfa78877ae219a7777d5bc30263877e64e7 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 074f0f83502d4c8116674264a153c5ce76c406f5..5313d3f0edc6e9e6f13c61bdc2a195495fd18f18 100644 --- a/services/audio_engine/manager/src/hpae_manager.cpp +++ b/services/audio_engine/manager/src/hpae_manager.cpp @@ -2540,6 +2540,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/manager/src/hpae_manager_impl.cpp b/services/audio_engine/manager/src/hpae_manager_impl.cpp index 8e4b271c785a1d1c90693599be4cfba651e184b8..bbec1c115eb494a78754b61a77a1dbbdbd07035d 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_RET_LOG(manager_, false, "manager is nullptr"); + return 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 5dea3d0a21cd59fa57d84068047fc00d4c95dfd7..be20e868bf0dff627c5d39da885347118dc71992 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_RET_LOG(audioEffectChainManager != nullptr, false, "null audioEffectChainManager"); + return audioEffectChainManager->IsChannelLayoutSupportForDspEffect(channelLayout); +} } // namespace HPAE } // 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 2be1844cea7a574647fc5c21a5405e6063272e1e..03a5297e2bf7937944d1f529c4b87e4e48ccc2dc 100644 --- a/services/audio_engine/manager/src/hpae_renderer_manager.cpp +++ b/services/audio_engine/manager/src/hpae_renderer_manager.cpp @@ -426,11 +426,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); } } @@ -878,6 +873,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_engine/node/include/hpae_node_common.h b/services/audio_engine/node/include/hpae_node_common.h index f02e3e809c13a7c18b8a72be0fbff8a3bd495a2b..578b693c6eeb5c1fcc5837b0f5b5d39e706143e5 100644 --- a/services/audio_engine/node/include/hpae_node_common.h +++ b/services/audio_engine/node/include/hpae_node_common.h @@ -1,72 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef 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 { -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); -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); -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); -int32_t CheckSourceInfoFramelen(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; - } - AUDIO_ERR_LOG("error info type"); - return ERROR_INVALID_PARAM; -} -void TransStreamInfoToStreamDumpInfo(const std::unordered_map &streamInfoMap, - std::vector &dumpInfo); -} // namespace HPAE -} // namespace AudioStandard -} // namespace OHOS +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef 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 { +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); +int32_t CheckSourceInfoFramelen(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; + } + AUDIO_ERR_LOG("error info type"); + return ERROR_INVALID_PARAM; +} +void TransStreamInfoToStreamDumpInfo(const std::unordered_map &streamInfoMap, + std::vector &dumpInfo); +} // namespace HPAE +} // namespace AudioStandard +} // namespace OHOS #endif \ No newline at end of file diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index 629bad65fd7feb0dd76112f741a714440bd9af3f..3102ac3b6788022c5a0e93343f8eb1daa3acd4ca 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; @@ -286,27 +284,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()) { @@ -333,7 +310,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)); @@ -342,10 +319,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 34fc63c49973b52d43fdde6a20aaa2618b465ecf..cbf1eb6af84c15112c885d28ffed6e5106a89610 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,9 +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); + AUDIO_INFO_LOG("Buffer size: %{public}s channels: %{public}s channelLayout:%{public}s", + info.moduleInfo_.bufferSize.c_str(), info.moduleInfo_.channels.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/domain/volume/include/audio_adapter_manager.h b/services/audio_policy/server/domain/volume/include/audio_adapter_manager.h index 8645206c88f969faa31a594b73f9b1bbaf830d49..1153134b4809d044e04e5df3756fc83ba17fd720 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 0f50e6eae4907157d24a22da84d2e2010f2f528b..94fe1369addb44bbc44b9827465c3e341f84351a 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 @@ -263,6 +263,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 ed91ed14e95f0aa9c7441e6d3880831cae54da2e..93e2c66b56ece4560559fdab50f9086a9f3aa97a 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 @@ -3407,6 +3407,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 b47ce40aa950b693656e65bf106b9d192a6d2f02..4aa06f68dd8fff8ad0f707a48b9bbee1f91e6eb5 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, 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 3c4c7f74e2fc2677ea16be8a8f5e8b75154710fc..cd4188c5f735bdea17efb3dedf1ec6fde1190f7d 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,19 @@ bool AudioPolicyUtils::IsWirelessDevice(DeviceType deviceType) } } +void AudioPolicyUtils::UpdateMultiChannelModuleInfo(AudioPipeInfo &info, + std::shared_ptr streamPropInfo) +{ + if (!AudioPolicyManagerFactory::GetAudioPolicyManager(). + 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)); + } +} } // namespace AudioStandard } // namespace OHOS diff --git a/test/fuzztest/audioeffectchain_fuzzer/audio_effect_chain_fuzzer.cpp b/test/fuzztest/audioeffectchain_fuzzer/audio_effect_chain_fuzzer.cpp index 05d2d82281461edf0cfc7f7b1a755a8ca78227a8..3a31bd42e7d4a33d6a57819b69a5ce84a6ed00e4 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, diff --git a/test/fuzztest/audioeffectenhance_fuzzer/audio_effect_enhance_fuzzer.cpp b/test/fuzztest/audioeffectenhance_fuzzer/audio_effect_enhance_fuzzer.cpp index f344dc4142fe267aa89e92e3bfec8daeb7e4d656..79062bdc22f069a25ed3784568348bf15858c609 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, diff --git a/test/fuzztest/hpaemixernode_fuzzer/hpae_mixer_node_fuzzer.cpp b/test/fuzztest/hpaemixernode_fuzzer/hpae_mixer_node_fuzzer.cpp index 15b1c5c5036a7dd80da660808d050efe89bcdf6c..f999edaf3d432e1d17f6a6f19ab7e074dd97b46e 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,