1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef HPAE_NODE_COMMON_H
17 #define HPAE_NODE_COMMON_H
18 #include "hpae_define.h"
19 #include "audio_effect.h"
20 #include "audio_module_info.h"
21 #include "audio_service_hpae_dump_callback.h"
22
23 namespace OHOS {
24 namespace AudioStandard {
25 namespace HPAE {
26 bool CheckHpaeNodeInfoIsSame(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &curNodeInfo);
27 HpaeProcessorType TransStreamTypeToSceneType(AudioStreamType streamType);
28 HpaeProcessorType TransEffectSceneToSceneType(AudioEffectScene effectScene);
29 HpaeProcessorType TransSourceTypeToSceneType(SourceType sourceType);
30 bool CheckSceneTypeNeedEc(HpaeProcessorType processorType);
31 bool CheckSceneTypeNeedMicRef(HpaeProcessorType processorType);
32 std::string TransNodeInfoToStringKey(HpaeNodeInfo& nodeInfo);
33 AudioEnhanceScene TransProcessType2EnhanceScene(const HpaeProcessorType &processorType);
34 std::string TransProcessorTypeToSceneType(HpaeProcessorType processorType);
35 uint64_t ConvertDatalenToUs(size_t bufferSize, const HpaeNodeInfo &nodeInfo);
36 size_t ConvertUsToFrameCount(uint64_t usTime, const HpaeNodeInfo &nodeInfo);
37 std::string ConvertSessionState2Str(HpaeSessionState state);
38 std::string ConvertStreamManagerState2Str(StreamManagerState state);
39 void AdjustMchSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo);
40 int32_t TransModuleInfoToHpaeSinkInfo(const AudioModuleInfo &audioModuleInfo, HpaeSinkInfo &sinkInfo);
41 bool CheckSourceInfoIsDifferent(const HpaeSourceInfo &info, const HpaeSourceInfo &oldInfo);
42 int32_t TransModuleInfoToHpaeSourceInfo(const AudioModuleInfo &audioModuleInfo, HpaeSourceInfo &sourceInfo);
43 AudioSampleFormat TransFormatFromStringToEnum(std::string format);
44 void PrintAudioModuleInfo(const AudioModuleInfo &audioModuleInfo);
45 std::string TransFormatFromEnumToString(AudioSampleFormat format);
46 AudioPipeType ConvertDeviceClassToPipe(const std::string &deviceClass);
47 void TransNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo, bool isCollaborationEnabled);
48 void RecoverNodeInfoForCollaboration(HpaeNodeInfo &nodeInfo);
49
50 // for hidumper device / stream info trans, param should be HpaeSinkInfo / HpaeSourceInfo / HpaeStreamInfo
51 template <typename T>
TransDeviceInfoToString(const T & info,std::string & config)52 int32_t TransDeviceInfoToString(const T& info, std::string &config)
53 {
54 if constexpr (std::is_same_v<T, HpaeSinkInfo> || std::is_same_v<T, HpaeSourceInfo> ||
55 std::is_same_v<T, HpaeStreamInfo>) {
56 config += TransFormatFromEnumToString(info.format) + " ";
57 config += std::to_string(info.channels) + "ch ";
58 config += std::to_string(info.samplingRate) + "Hz";
59 return 0;
60 }
61 AUDIO_ERR_LOG("error info type");
62 return ERROR_INVALID_PARAM;
63 }
64 void TransStreamInfoToStreamDumpInfo(const std::unordered_map<uint32_t, HpaeSessionInfo> &streamInfoMap,
65 std::vector<HpaeInputOutputInfo> &dumpInfo);
66 } // namespace HPAE
67 } // namespace AudioStandard
68 } // namespace OHOS
69 #endif