From 8ec61ed96667a72055352e75289f54ab953327a3 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 12 May 2025 14:09:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?proaudio=E4=B8=8A=E8=A1=8C=E5=B9=B6?= =?UTF-8?q?=E5=8F=91bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles --- services/audio_engine/BUILD.gn | 1 + .../manager/include/hpae_capturer_manager.h | 1 + .../manager/include/hpae_manager.h | 5 - .../manager/src/hpae_capturer_manager.cpp | 18 ++- .../audio_engine/manager/src/hpae_manager.cpp | 143 ----------------- .../node/include/hpae_node_common.h | 6 + .../node/include/hpae_source_input_node.h | 1 + .../node/src/hpae_node_common.cpp | 148 ++++++++++++++++++ .../node/src/hpae_source_input_node.cpp | 56 +++---- 9 files changed, 194 insertions(+), 185 deletions(-) diff --git a/services/audio_engine/BUILD.gn b/services/audio_engine/BUILD.gn index ec3f751a14..0b92360c10 100644 --- a/services/audio_engine/BUILD.gn +++ b/services/audio_engine/BUILD.gn @@ -116,6 +116,7 @@ config("audio_engine_node_config") { "../audio_service/common/include", "../audio_service/common/include/limiter", "../audio_service/server/include", + "../audio_policy/server/inlcude/service/common", "../audio_policy/util/include", "../../frameworks/native/audioeffect/include", "../../interfaces/inner_api/native/audiocommon/include", diff --git a/services/audio_engine/manager/include/hpae_capturer_manager.h b/services/audio_engine/manager/include/hpae_capturer_manager.h index 990d3dec29..5bdd36a565 100644 --- a/services/audio_engine/manager/include/hpae_capturer_manager.h +++ b/services/audio_engine/manager/include/hpae_capturer_manager.h @@ -95,6 +95,7 @@ private: void CreateSourceAttr(IAudioSourceAttr &attr); int32_t CapturerSourceStart(); int32_t CapturerSourceStop(); + void CheckIfAnyStreamRunning(); private: HpaeNoLockQueue hpaeNoLockQueue_; diff --git a/services/audio_engine/manager/include/hpae_manager.h b/services/audio_engine/manager/include/hpae_manager.h index 48a6f97d0c..695756e761 100644 --- a/services/audio_engine/manager/include/hpae_manager.h +++ b/services/audio_engine/manager/include/hpae_manager.h @@ -169,14 +169,9 @@ public: bool GetEffectLiveParameter(const std::vector &subKeys, std::vector> &result) override; private: - 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); int32_t CloseOutAudioPort(std::string &sinkName); void PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo); int32_t CloseInAudioPort(std::string &sourceName); - void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo); template void RegisterHandler(HpaeMsgCode cmdID, void (HpaeManager::*func)(Args...)); void HandleUpdateStatus( diff --git a/services/audio_engine/manager/src/hpae_capturer_manager.cpp b/services/audio_engine/manager/src/hpae_capturer_manager.cpp index b832723ce2..2e78c1264a 100644 --- a/services/audio_engine/manager/src/hpae_capturer_manager.cpp +++ b/services/audio_engine/manager/src/hpae_capturer_manager.cpp @@ -625,6 +625,7 @@ int32_t HpaeCapturerManager::Init() if (ret == SUCCESS) { AUDIO_INFO_LOG("Init HpaeCapturerManager success"); TriggerCallback(INIT_DEVICE_RESULT, sourceInfo_.deviceName, ret); + CheckIfAnyStreamRunning(); } }; SendRequest(request, true); @@ -640,6 +641,9 @@ int32_t HpaeCapturerManager::DeInit(bool isMoveDefault) hpaeSignalProcessThread_ = nullptr; } hpaeNoLockQueue_.HandleRequests(); + for (auto outputNode : sourceOutputNodeMap_) { + outputNode.second->ResetAll(); + } int32_t ret = CapturerSourceStop(); CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_INVALID_OPERATION, "capturerSource stop error, ret = %{public}d.\n", ret); @@ -784,8 +788,9 @@ void HpaeCapturerManager::AddSingleNodeToSource(const HpaeCaptureMoveInfo &moveI AUDIO_WARNING_LOG("[FinishMove] session :%{public}u,create effect failed.", sessionId); sceneClusterMap_.erase(sceneType); } - ConnectOutputSession(sessionId); + if (moveInfo.sessionInfo.state == HPAE_SESSION_RUNNING) { + ConnectOutputSession(sessionId); CHECK_AND_RETURN_LOG(CapturerSourceStart() == SUCCESS, "CapturerSourceStart error."); hpaeSignalProcessThread_->Notify(); } @@ -894,6 +899,17 @@ void HpaeCapturerManager::DumpSourceInfo() }); } +void HpaeCapturerManager::CheckIfAnyStreamRunning() +{ + CHECK_AND_RETURN_LOG(!sessionNodeMap_.empty(), "no stream need start"); + for (auto &sessionPair : sessionNodeMap_) { + if (sessionPair.second.state == HPAE_SESSION_RUNNING) { + ConnectOutputSession(sessionPair.first); + CHECK_AND_RETURN_LOG(CapturerSourceStart() == SUCCESS, "CapturerSourceStart error."); + } + } +} + } // namespace HPAE } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/services/audio_engine/manager/src/hpae_manager.cpp b/services/audio_engine/manager/src/hpae_manager.cpp index 878f799cb3..f7f1e7c2f1 100644 --- a/services/audio_engine/manager/src/hpae_manager.cpp +++ b/services/audio_engine/manager/src/hpae_manager.cpp @@ -33,23 +33,8 @@ constexpr uint32_t DEFAULT_SUSPEND_TIME_IN_MS = 3000; // 3s to stop hdi static inline const std::unordered_set INNER_SOURCE_TYPE_SET = { SOURCE_TYPE_PLAYBACK_CAPTURE, SOURCE_TYPE_REMOTE_CAST}; } // namespace -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; constexpr int32_t SINK_INVALID_ID = -1; static const std::string DEFAULT_SINK_NAME = "Speaker"; -static std::map 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}, -}; // base + offset * 8 static uint32_t GetRenderId(const std::string &deviceClass) @@ -258,100 +243,6 @@ int32_t HpaeManager::RegisterHpaeDumpCallback(const std::weak_ptr(formatFromParserStrToEnum[format]); -} - -void HpaeManager::AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) -{ - 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 HpaeManager::TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) -{ - if (formatFromParserStrToEnum.find(audioModuleInfo.format) == 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; - AUDIO_INFO_LOG("HpaeManager::deviceNetId: %{public}s, deviceClass: %{public}s", - sinkInfo.deviceNetId.c_str(), - sinkInfo.deviceClass.c_str()); - sinkInfo.adapterName = audioModuleInfo.adapterName; - sinkInfo.lib = audioModuleInfo.lib; - sinkInfo.splitMode = audioModuleInfo.extra; - sinkInfo.filePath = audioModuleInfo.fileName; - - sinkInfo.samplingRate = static_cast(std::atol(audioModuleInfo.rate.c_str())); - sinkInfo.format = static_cast(TransFormatFromStringToEnum(audioModuleInfo.format)); - sinkInfo.channels = static_cast(std::atol(audioModuleInfo.channels.c_str())); - int32_t bufferSize = static_cast(std::atol(audioModuleInfo.bufferSize.c_str())); - sinkInfo.frameLen = bufferSize / (sinkInfo.channels * GetSizeFromFormat(sinkInfo.format)); - sinkInfo.channelLayout = 0ULL; - sinkInfo.deviceType = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); - sinkInfo.volume = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); - sinkInfo.openMicSpeaker = static_cast(std::atol(audioModuleInfo.OpenMicSpeaker.c_str())); - sinkInfo.renderInIdleState = static_cast(std::atol(audioModuleInfo.renderInIdleState.c_str())); - sinkInfo.offloadEnable = static_cast(std::atol(audioModuleInfo.offloadEnable.c_str())); - sinkInfo.sinkLatency = static_cast(std::atol(audioModuleInfo.sinkLatency.c_str())); - sinkInfo.fixedLatency = static_cast(std::atol(audioModuleInfo.fixedLatency.c_str())); - sinkInfo.deviceName = audioModuleInfo.name; - AdjustMchSinkInfo(audioModuleInfo, sinkInfo); - return SUCCESS; -} - -int32_t HpaeManager::TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo) -{ - if (formatFromParserStrToEnum.find(audioModuleInfo.format) == 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(std::atol(audioModuleInfo.sourceType.c_str())); - sourceInfo.filePath = audioModuleInfo.fileName; - int32_t bufferSize = static_cast(std::atol(audioModuleInfo.bufferSize.c_str())); - sourceInfo.channels = static_cast(std::atol(audioModuleInfo.channels.c_str())); - sourceInfo.format = TransFormatFromStringToEnum(audioModuleInfo.format); - sourceInfo.frameLen = bufferSize / (sourceInfo.channels * GetSizeFromFormat(sourceInfo.format)); - sourceInfo.samplingRate = static_cast(std::atol(audioModuleInfo.rate.c_str())); - sourceInfo.channelLayout = 0ULL; - sourceInfo.deviceType = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); - sourceInfo.volume = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); // 1.0f; - - sourceInfo.ecType = static_cast(std::atol(audioModuleInfo.ecType.c_str())); - sourceInfo.ecAdapterName = audioModuleInfo.ecAdapter; - sourceInfo.ecSamplingRate = static_cast(std::atol(audioModuleInfo.ecSamplingRate.c_str())); - sourceInfo.ecFormat = TransFormatFromStringToEnum(audioModuleInfo.ecFormat); - sourceInfo.ecChannels = static_cast(std::atol(audioModuleInfo.ecChannels.c_str())); - sourceInfo.ecFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.ecSamplingRate / MS_PER_SECOND); - - sourceInfo.micRef = static_cast(std::atol(audioModuleInfo.openMicRef.c_str())); - sourceInfo.micRefSamplingRate = static_cast(std::atol(audioModuleInfo.micRefRate.c_str())); - sourceInfo.micRefFormat = TransFormatFromStringToEnum(audioModuleInfo.micRefFormat); - sourceInfo.micRefChannels = static_cast(std::atol(audioModuleInfo.micRefChannels.c_str())); - sourceInfo.openMicSpeaker = static_cast(std::atol(audioModuleInfo.OpenMicSpeaker.c_str())); - sourceInfo.micRefFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.micRefSamplingRate / MS_PER_SECOND); - return SUCCESS; -} - void HpaeManager::PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo) { AUDIO_INFO_LOG("rate: %{public}s ch: %{public}s buffersize: %{public}s ", @@ -434,40 +325,6 @@ int32_t HpaeManager::OpenOutputAudioPort(const AudioModuleInfo &audioModuleInfo, return SUCCESS; } -bool HpaeManager::CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo) -{ - auto getKey = [](const HpaeSourceInfo &sourceInfo) { - return std::tie( - sourceInfo.sourceId, - 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); -} - int32_t HpaeManager::OpenInputAudioPort(const AudioModuleInfo &audioModuleInfo, int32_t sinkSourceIndex) { HpaeSourceInfo sourceInfo; diff --git a/services/audio_engine/node/include/hpae_node_common.h b/services/audio_engine/node/include/hpae_node_common.h index 7d87d91050..ed78fe25a0 100644 --- a/services/audio_engine/node/include/hpae_node_common.h +++ b/services/audio_engine/node/include/hpae_node_common.h @@ -17,6 +17,7 @@ #define HPAE_NODE_COMMON_H #include "hpae_define.h" #include "audio_effect.h" +#include "audio_module_info.h" namespace OHOS { namespace AudioStandard { @@ -33,6 +34,11 @@ 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); } // namespace HPAE } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_engine/node/include/hpae_source_input_node.h b/services/audio_engine/node/include/hpae_source_input_node.h index 7dd27151b7..94b727088e 100644 --- a/services/audio_engine/node/include/hpae_source_input_node.h +++ b/services/audio_engine/node/include/hpae_source_input_node.h @@ -64,6 +64,7 @@ private: const std::string &deviceClass, const SourceType &sourceType, const std::string &info); void SetBufferValid(const HpaeSourceBufferType &bufferType, const uint64_t &replyBytes); std::string GetTraceInfo(); + void DoProcessInner(const HpaeSourceBufferType &bufferType, const uint64_t &replyBytes); private: std::shared_ptr audioCapturerSource_ = nullptr; diff --git a/services/audio_engine/node/src/hpae_node_common.cpp b/services/audio_engine/node/src/hpae_node_common.cpp index d9b209d635..882ae72d13 100644 --- a/services/audio_engine/node/src/hpae_node_common.cpp +++ b/services/audio_engine/node/src/hpae_node_common.cpp @@ -14,11 +14,20 @@ */ #include "hpae_node_common.h" +#include "audio_errors.h" +#include "audio_engine_log.h" +#include "cinttypes" 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; + static std::map g_streamTypeToSceneTypeMap = { {STREAM_MUSIC, HPAE_SCENE_MUSIC}, {STREAM_GAME, HPAE_SCENE_GAME}, @@ -76,6 +85,17 @@ static std::unordered_map g_streamMgrStateToStr {STREAM_MANAGER_RELEASED, "RELEASED"} }; +static std::map 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}, +}; + std::string ConvertSessionState2Str(HpaeSessionState state) { if (g_sessionStateToStrMap.find(state) == g_sessionStateToStrMap.end()) { @@ -184,6 +204,134 @@ uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo) return static_cast(microseconds); } + +AudioSampleFormat TransFormatFromStringToEnum(std::string format) +{ + return static_cast(formatFromParserStrToEnum[format]); +} + +void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo) +{ + 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 (formatFromParserStrToEnum.find(audioModuleInfo.format) == 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; + AUDIO_INFO_LOG("HpaeManager::deviceNetId: %{public}s, deviceClass: %{public}s", + sinkInfo.deviceNetId.c_str(), + sinkInfo.deviceClass.c_str()); + sinkInfo.adapterName = audioModuleInfo.adapterName; + sinkInfo.lib = audioModuleInfo.lib; + sinkInfo.splitMode = audioModuleInfo.extra; + sinkInfo.filePath = audioModuleInfo.fileName; + + sinkInfo.samplingRate = static_cast(std::atol(audioModuleInfo.rate.c_str())); + sinkInfo.format = static_cast(TransFormatFromStringToEnum(audioModuleInfo.format)); + sinkInfo.channels = static_cast(std::atol(audioModuleInfo.channels.c_str())); + int32_t bufferSize = static_cast(std::atol(audioModuleInfo.bufferSize.c_str())); + sinkInfo.frameLen = bufferSize / (sinkInfo.channels * GetSizeFromFormat(sinkInfo.format)); + sinkInfo.channelLayout = 0ULL; + sinkInfo.deviceType = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); + sinkInfo.volume = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); + sinkInfo.openMicSpeaker = static_cast(std::atol(audioModuleInfo.OpenMicSpeaker.c_str())); + sinkInfo.renderInIdleState = static_cast(std::atol(audioModuleInfo.renderInIdleState.c_str())); + sinkInfo.offloadEnable = static_cast(std::atol(audioModuleInfo.offloadEnable.c_str())); + sinkInfo.sinkLatency = static_cast(std::atol(audioModuleInfo.sinkLatency.c_str())); + sinkInfo.fixedLatency = static_cast(std::atol(audioModuleInfo.fixedLatency.c_str())); + sinkInfo.deviceName = audioModuleInfo.name; + AdjustMchSinkInfo(audioModuleInfo, sinkInfo); + return SUCCESS; +} + +int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo) +{ + if (formatFromParserStrToEnum.find(audioModuleInfo.format) == 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(std::atol(audioModuleInfo.sourceType.c_str())); + sourceInfo.filePath = audioModuleInfo.fileName; + int32_t bufferSize = static_cast(std::atol(audioModuleInfo.bufferSize.c_str())); + sourceInfo.channels = static_cast(std::atol(audioModuleInfo.channels.c_str())); + sourceInfo.format = TransFormatFromStringToEnum(audioModuleInfo.format); + sourceInfo.frameLen = bufferSize / (sourceInfo.channels * GetSizeFromFormat(sourceInfo.format)); + sourceInfo.samplingRate = static_cast(std::atol(audioModuleInfo.rate.c_str())); + sourceInfo.channelLayout = 0ULL; + sourceInfo.deviceType = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); + sourceInfo.volume = static_cast(std::atol(audioModuleInfo.deviceType.c_str())); // 1.0f; + + sourceInfo.ecType = static_cast(std::atol(audioModuleInfo.ecType.c_str())); + sourceInfo.ecAdapterName = audioModuleInfo.ecAdapter; + sourceInfo.ecSamplingRate = static_cast(std::atol(audioModuleInfo.ecSamplingRate.c_str())); + sourceInfo.ecFormat = TransFormatFromStringToEnum(audioModuleInfo.ecFormat); + sourceInfo.ecChannels = static_cast(std::atol(audioModuleInfo.ecChannels.c_str())); + sourceInfo.ecFrameLen = DEFAULT_MULTICHANNEL_FRAME_LEN_MS * (sourceInfo.ecSamplingRate / MS_PER_SECOND); + + sourceInfo.micRef = static_cast(std::atol(audioModuleInfo.openMicRef.c_str())); + sourceInfo.micRefSamplingRate = static_cast(std::atol(audioModuleInfo.micRefRate.c_str())); + sourceInfo.micRefFormat = TransFormatFromStringToEnum(audioModuleInfo.micRefFormat); + sourceInfo.micRefChannels = static_cast(std::atol(audioModuleInfo.micRefChannels.c_str())); + sourceInfo.openMicSpeaker = static_cast(std::atol(audioModuleInfo.OpenMicSpeaker.c_str())); + 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); +} + } // namespace HPAE } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/services/audio_engine/node/src/hpae_source_input_node.cpp b/services/audio_engine/node/src/hpae_source_input_node.cpp index 567a8bc20d..0ddfa084f4 100644 --- a/services/audio_engine/node/src/hpae_source_input_node.cpp +++ b/services/audio_engine/node/src/hpae_source_input_node.cpp @@ -118,6 +118,23 @@ void HpaeSourceInputNode::SetBufferValid(const HpaeSourceBufferType &bufferType, } } +void HpaeSourceInputNode::DoProcessInner(const HpaeSourceBufferType &bufferType, const uint64_t &replyBytes) +{ +#ifdef ENABLE_HOOK_PCM + if (inputPcmDumperMap_.find(bufferType) != inputPcmDumperMap_.end() && + inputPcmDumperMap_.at(bufferType)) { + inputPcmDumperMap_.at(bufferType)->Dump( + (int8_t *) capturerFrameDataMap_.at(bufferType).data(), replyBytes); + } +#endif + // todo: do not convert to float in SourceInputNode + ConvertToFloat(nodeInfoMap_.at(bufferType).format, + nodeInfoMap_.at(bufferType).channels * nodeInfoMap_.at(bufferType).frameLen, + capturerFrameDataMap_.at(bufferType).data(), + inputAudioBufferMap_.at(bufferType).GetPcmDataBuffer()); + outputStreamMap_.at(bufferType).WriteDataToOutput(&inputAudioBufferMap_.at(bufferType)); +} + void HpaeSourceInputNode::DoProcess() { Trace trace("[" + std::to_string(GetNodeId()) + "]HpaeSourceInputNode::DoProcess " + GetTraceInfo()); @@ -129,47 +146,14 @@ void HpaeSourceInputNode::DoProcess() audioCapturerSource_->CaptureFrameWithEc(&fdescMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC), replyBytes, &fdescMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC), replyBytesEc); SetBufferValid(HPAE_SOURCE_BUFFER_TYPE_MIC, replyBytes); -#ifdef ENABLE_HOOK_PCM - if (inputPcmDumperMap_.find(HPAE_SOURCE_BUFFER_TYPE_MIC) != inputPcmDumperMap_.end() && - inputPcmDumperMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC)) { - inputPcmDumperMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC)->Dump( - (int8_t *) capturerFrameDataMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC).data(), replyBytes); - } - if (inputPcmDumperMap_.find(HPAE_SOURCE_BUFFER_TYPE_EC) != inputPcmDumperMap_.end() && - inputPcmDumperMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC)) { - inputPcmDumperMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC)->Dump( - (int8_t *) capturerFrameDataMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).data(), replyBytesEc); - } -#endif - // todo: do not convert to float in SourceInputNode - ConvertToFloat(GetBitWidth(), GetChannelCount() * GetFrameLen(), - capturerFrameDataMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC).data(), - inputAudioBufferMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC).GetPcmDataBuffer()); - ConvertToFloat(nodeInfoMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).format, - nodeInfoMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).channels * nodeInfoMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).frameLen, - capturerFrameDataMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).data(), - inputAudioBufferMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).GetPcmDataBuffer()); - outputStreamMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC).WriteDataToOutput( - &inputAudioBufferMap_.at(HPAE_SOURCE_BUFFER_TYPE_MIC)); - outputStreamMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC).WriteDataToOutput( - &inputAudioBufferMap_.at(HPAE_SOURCE_BUFFER_TYPE_EC)); + DoProcessInner(HPAE_SOURCE_BUFFER_TYPE_MIC, replyBytes); + DoProcessInner(HPAE_SOURCE_BUFFER_TYPE_EC, replyBytesEc); } else { HpaeSourceBufferType sourceBufferType = nodeInfoMap_.begin()->second.sourceBufferType; audioCapturerSource_->CaptureFrame(capturerFrameDataMap_.at(sourceBufferType).data(), (uint64_t)frameByteSizeMap_.at(sourceBufferType), replyBytes); SetBufferValid(sourceBufferType, replyBytes); -#ifdef ENABLE_HOOK_PCM - if (inputPcmDumperMap_.find(sourceBufferType) != inputPcmDumperMap_.end() && - inputPcmDumperMap_.at(sourceBufferType)) { - inputPcmDumperMap_.at(sourceBufferType)->Dump( - (int8_t *) capturerFrameDataMap_.at(sourceBufferType).data(), replyBytes); - } -#endif - // todo: do not convert to float in SourceInputNode - ConvertToFloat(GetBitWidth(), GetChannelCount() * GetFrameLen(), - capturerFrameDataMap_.at(sourceBufferType).data(), - inputAudioBufferMap_.at(sourceBufferType).GetPcmDataBuffer()); - outputStreamMap_.at(sourceBufferType).WriteDataToOutput(&inputAudioBufferMap_.at(sourceBufferType)); + DoProcessInner(sourceBufferType, replyBytes); } } -- Gitee From 6a1e01673dafab1245c3a5f6de784dc375a24ec3 Mon Sep 17 00:00:00 2001 From: c00657214 Date: Mon, 12 May 2025 18:10:34 +0800 Subject: [PATCH 2/3] fix gn err Signed-off-by: c00657214 --- frameworks/native/audioadapter/test/unittest/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/audioadapter/test/unittest/BUILD.gn b/frameworks/native/audioadapter/test/unittest/BUILD.gn index 4c7a03b7a3..957180d3a3 100644 --- a/frameworks/native/audioadapter/test/unittest/BUILD.gn +++ b/frameworks/native/audioadapter/test/unittest/BUILD.gn @@ -13,7 +13,7 @@ import("//build/ohos.gni") import("//build/test.gni") -import("../../../../config.gni") +import("../../../../../config.gni") module_output_path = "multimedia_audio_framework/audio_engine" @@ -34,7 +34,7 @@ config("audio_engine_private_config") { } ohos_unittest("pro_audio_service_adapter_unit_test") { - module_out_path = module_out_path + module_out_path = module_output_path testonly = true cflags = [ "-Wall", @@ -63,4 +63,4 @@ ohos_unittest("pro_audio_service_adapter_unit_test") { "safwk:system_ability_fwk", "samgr:samgr_proxy", ] -} \ No newline at end of file +} -- Gitee From 990eca92dad9c9c35c897199e9215f89eefd8f3c Mon Sep 17 00:00:00 2001 From: c00657214 Date: Tue, 13 May 2025 11:50:34 +0800 Subject: [PATCH 3/3] fix gn err Signed-off-by: c00657214 --- services/audio_engine/BUILD.gn | 2 +- services/audio_engine/manager/src/hpae_manager.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/audio_engine/BUILD.gn b/services/audio_engine/BUILD.gn index 0b92360c10..d30b758f0f 100644 --- a/services/audio_engine/BUILD.gn +++ b/services/audio_engine/BUILD.gn @@ -116,7 +116,7 @@ config("audio_engine_node_config") { "../audio_service/common/include", "../audio_service/common/include/limiter", "../audio_service/server/include", - "../audio_policy/server/inlcude/service/common", + "../audio_policy/server/include/service/common", "../audio_policy/util/include", "../../frameworks/native/audioeffect/include", "../../interfaces/inner_api/native/audiocommon/include", diff --git a/services/audio_engine/manager/src/hpae_manager.cpp b/services/audio_engine/manager/src/hpae_manager.cpp index f7f1e7c2f1..8d76d7fc29 100644 --- a/services/audio_engine/manager/src/hpae_manager.cpp +++ b/services/audio_engine/manager/src/hpae_manager.cpp @@ -24,6 +24,7 @@ #include "audio_engine_log.h" #include "audio_utils.h" #include "audio_setting_provider.h" +#include "hpae_node_common.h" #include "system_ability_definition.h" namespace OHOS { namespace AudioStandard { -- Gitee