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