1 /* 2 * Copyright (c) 2024-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 ST_AUDIO_POLICY_CONFIG_H 17 #define ST_AUDIO_POLICY_CONFIG_H 18 19 #include <list> 20 #include <set> 21 #include <unordered_map> 22 #include <string> 23 24 #include "audio_module_info.h" 25 #include "audio_policy_log.h" 26 27 namespace OHOS { 28 namespace AudioStandard { 29 namespace { 30 static const char* STR_INIT = ""; 31 32 static const char* ADAPTER_PRIMARY_TYPE = "primary"; 33 static const char* ADAPTER_A2DP_TYPE = "a2dp"; 34 static const char* ADAPTER_HEARING_AID_TYPE = "hearing_aid"; 35 static const char* ADAPTER_REMOTE_TYPE = "remote"; 36 static const char* ADAPTER_FILE_TYPE = "file"; 37 static const char* ADAPTER_USB_TYPE = "usb"; 38 static const char* ADAPTER_DP_TYPE = "dp"; 39 static const char* ADAPTER_ACCESSORY_TYPE = "accessory"; 40 41 static const char* ADAPTER_DEVICE_PRIMARY_SPEAKER = "Speaker"; 42 static const char* ADAPTER_DEVICE_PRIMARY_EARPIECE = "Earpicece"; 43 static const char* ADAPTER_DEVICE_PRIMARY_MIC = "Built-In Mic"; 44 static const char* ADAPTER_DEVICE_PRIMARY_WIRE_HEADSET = "Wired Headset"; 45 static const char* ADAPTER_DEVICE_PRIMARY_WIRE_HEADPHONE = "Wired Headphones"; 46 static const char* ADAPTER_DEVICE_PRIMARY_BT_SCO = "Bt Sco"; 47 static const char* ADAPTER_DEVICE_PRIMARY_BT_OFFLOAD = "Bt Offload"; 48 static const char* ADAPTER_DEVICE_PRIMARY_BT_HEADSET_HIFI = "Usb Headset Hifi"; 49 static const char* ADAPTER_DEVICE_A2DP_BT_A2DP = "Bt A2dp"; 50 static const char* ADAPTER_DEVICE_HEARING_AID = "Hearing Aid"; 51 static const char* ADAPTER_DEVICE_REMOTE_SINK = "Remote Sink"; 52 static const char* ADAPTER_DEVICE_REMOTE_SOURCE = "Remote Source"; 53 static const char* ADAPTER_DEVICE_FILE_SINK = "File Sink"; 54 static const char* ADAPTER_DEVICE_FILE_SOURCE = "File Source"; 55 static const char* ADAPTER_DEVICE_USB_HEADSET_ARM = "Usb Headset Arm"; 56 static const char* ADAPTER_DEVICE_USB_SPEAKER = "Usb_arm_speaker"; 57 static const char* ADAPTER_DEVICE_USB_MIC = "Usb_arm_mic"; 58 static const char* ADAPTER_DEVICE_PIPE_SINK = "fifo_output"; 59 static const char* ADAPTER_DEVICE_PIPE_SOURCE = "fifo_input"; 60 static const char* ADAPTER_DEVICE_WAKEUP = "Built_in_wakeup"; 61 static const char* ADAPTER_DEVICE_NONE = "none"; 62 static const char* ADAPTER_DEVICE_DP = "DP Sink"; 63 static const char* ADAPTER_DEVICE_ACCESSORY = "accessory source"; 64 65 static const char* MODULE_TYPE_SINK = "sink"; 66 static const char* MODULE_TYPE_SOURCE = "source"; 67 static const char* MODULE_SINK_OFFLOAD = "offload"; 68 static const char* MODULE_SINK_LIB = "libmodule-hdi-sink.z.so"; 69 static const char* MODULE_SOURCE_LIB = "libmodule-hdi-source.z.so"; 70 static const char* MODULE_FILE_SINK_FILE = "/data/data/.pulse_dir/file_sink.pcm"; 71 static const char* MODULE_FILE_SOURCE_FILE = "/data/data/.pulse_dir/file_source.pcm"; 72 73 static const char* CONFIG_TYPE_PRELOAD = "preload"; 74 static const char* CONFIG_TYPE_MAXINSTANCES = "maxinstances"; 75 76 static const uint32_t DEFAULT_PERIOD_IN_MS = 20; // 20ms 77 } 78 79 enum class XmlNodeType { 80 ADAPTERS, 81 VOLUME_GROUPS, 82 INTERRUPT_GROUPS, 83 GLOBAL_CONFIGS, 84 XML_UNKNOWN 85 }; 86 87 enum class AdaptersType { 88 TYPE_PRIMARY, 89 TYPE_A2DP, 90 TYPE_USB, 91 TYPE_FILE_IO, 92 TYPE_REMOTE_AUDIO, 93 TYPE_DP, 94 TYPE_ACCESSORY, 95 TYPE_INVALID 96 }; 97 98 enum class AdapterType { 99 PIPES, 100 DEVICES, 101 UNKNOWN 102 }; 103 104 enum class PipeType { 105 PA_PROP, 106 STREAM_PROP, 107 CONFIGS, 108 UNKNOWN 109 }; 110 111 enum class GlobalConfigType { 112 DEFAULT_OUTPUT, 113 COMMON_CONFIGS, 114 PA_CONFIGS, 115 DEFAULT_MAX_CON_CURRENT_INSTANCE, 116 UNKNOWN 117 }; 118 119 enum class PAConfigType { 120 AUDIO_LATENCY, 121 SINK_LATENCY, 122 UNKNOWN 123 }; 124 125 enum class DefaultMaxInstanceType { 126 OUTPUT, 127 INPUT, 128 UNKNOWN 129 }; 130 131 enum class StreamType { 132 NORMAL, 133 FAST, 134 UNKNOWN 135 }; 136 137 struct ConfigInfo { 138 std::string name_ = STR_INIT; 139 std::string value_ = STR_INIT; 140 std::string type_ = STR_INIT; 141 }; 142 143 struct ProfileInfo { 144 std::string rate_ = STR_INIT; 145 std::string channels_ = STR_INIT; 146 std::string format_ = STR_INIT; 147 std::string bufferSize_ = STR_INIT; 148 }; 149 150 struct AudioAdapterDeviceInfo { 151 std::string name_ = STR_INIT; 152 std::string type_ = STR_INIT; 153 std::string role_ = STR_INIT; 154 }; 155 156 struct StreamPropInfo { 157 std::string format_ = STR_INIT; 158 uint32_t sampleRate_ = 0; 159 uint32_t periodInMs_ = DEFAULT_PERIOD_IN_MS; 160 uint32_t channelLayout_ = 0; 161 uint32_t bufferSize_ = 0; 162 }; 163 164 struct PipeInfo { 165 std::string name_ = STR_INIT; 166 std::string pipeRole_ = STR_INIT; 167 std::string pipeFlags_ = STR_INIT; 168 std::string moduleName_ = STR_INIT; 169 170 std::string lib_ = STR_INIT; 171 std::string paPropRole_ = STR_INIT; 172 std::string fixedLatency_ = STR_INIT; 173 std::string renderInIdleState_ = STR_INIT; 174 175 int32_t audioFlag_ = AUDIO_FLAG_NORMAL; 176 int32_t audioUsage_ = AUDIO_USAGE_NORMAL; 177 178 std::list<StreamPropInfo> streamPropInfos_ {}; 179 std::list<uint32_t> sampleRates_ {}; 180 std::list<uint32_t> channelLayouts_ {}; 181 std::list<ConfigInfo> configInfos_ {}; 182 }; 183 184 struct AudioPipeDeviceInfo { 185 std::string name_ = STR_INIT; 186 std::string type_ = STR_INIT; 187 std::string pin_ = STR_INIT; 188 std::string role_ = STR_INIT; 189 std::list<std::string> supportPipes_ {}; 190 }; 191 192 struct ModuleInfo { 193 std::string moduleType_ = STR_INIT; 194 195 std::string name_ = STR_INIT; 196 std::string lib_ = STR_INIT; 197 std::string role_ = STR_INIT; 198 std::string fixedLatency_ = STR_INIT; 199 std::string renderInIdleState_ = STR_INIT; 200 std::string profile_ = STR_INIT; 201 std::string file_ = STR_INIT; 202 203 std::list<ConfigInfo> configInfos_ {}; 204 std::list<ProfileInfo> profileInfos_ {}; 205 std::list<std::string> devices_ {}; 206 }; 207 208 struct AudioAdapterInfo { 209 PipeInfo *GetPipeByName(const std::string &pipeName); 210 AudioPipeDeviceInfo *GetDeviceInfoByDeviceType(DeviceType deviceType); 211 212 std::string adapterName_ = STR_INIT; 213 std::string adaptersupportScene_ = STR_INIT; 214 std::list<AudioPipeDeviceInfo> deviceInfos_ {}; 215 std::list<PipeInfo> pipeInfos_ {}; 216 }; 217 218 struct GlobalPaConfigs { 219 std::string audioLatency_ = STR_INIT; 220 std::string sinkLatency_ = STR_INIT; 221 }; 222 223 struct GlobalConfigs { 224 std::string adapter_ = STR_INIT; 225 std::string pipe_ = STR_INIT; 226 std::string device_ = STR_INIT; 227 std::list<ConfigInfo> commonConfigs_ {}; 228 bool updateRouteSupport_ = false; 229 GlobalPaConfigs globalPaConfigs_; 230 std::list<ConfigInfo> outputConfigInfos_ {}; 231 std::list<ConfigInfo> inputConfigInfos_ {}; 232 }; 233 } // namespace AudioStandard 234 } // namespace OHOS 235 236 #endif // ST_AUDIO_POLICY_CONFIG_H 237