1 #ifndef ANDROID_AUDIO_POLICY_CONFIGURATION_H
2 #define ANDROID_AUDIO_POLICY_CONFIGURATION_H
3 
4 #include <array>
5 #include <map>
6 #include <optional>
7 #include <string>
8 #include <vector>
9 #include <sstream>
10 
11 #if __has_include(<libxml/parser.h>)
12 #include <libxml/parser.h>
13 #include <libxml/xinclude.h>
14 #else
15 #error Require libxml2 library. Please add libxml2 to shared_libs or static_libs
16 #endif
17 
18 #include "android_audio_policy_configuration_enums.h"
19 
20 namespace android {
21     namespace audio {
22         namespace policy {
23             namespace configuration {
24                 class GlobalConfiguration;
25                 class Modules;
26                 class AttachedDevices;
27                 class MixPorts;
28                 class Profile;
29                 class Gains;
30                 class DevicePorts;
31                 class Routes;
32                 class Volumes;
33                 class Volume;
34                 class Reference;
35                 class SurroundSound;
36                 class SurroundFormats;
37                 class AudioPolicyConfiguration;
38                 std::optional<AudioPolicyConfiguration> read(const char* configFile);
39 
40                 std::optional<AudioPolicyConfiguration> parse(const char* xml);
41 
42                 class GlobalConfiguration {
43                     private:
44                     const bool speaker_drc_enabled_;
45                     const std::optional<bool> call_screen_mode_supported_;
46                     const std::optional<EngineSuffix> engine_library_;
47                     public:
48                     GlobalConfiguration(bool speaker_drc_enabled, std::optional<bool> call_screen_mode_supported, std::optional<EngineSuffix> engine_library);
49                     const bool& getSpeaker_drc_enabled() const;
50                     bool hasSpeaker_drc_enabled() const;
51                     const bool& getCall_screen_mode_supported() const;
52                     bool hasCall_screen_mode_supported() const;
53                     const EngineSuffix& getEngine_library() const;
54                     bool hasEngine_library() const;
55                     static GlobalConfiguration read(xmlNode *root);
56                 };
57 
58                 class Modules {
59                     public:
60                     class Module {
61                         private:
62                         const std::vector<AttachedDevices> attachedDevices_;
63                         const std::optional<std::string> defaultOutputDevice_;
64                         const std::vector<MixPorts> mixPorts_;
65                         const std::vector<DevicePorts> devicePorts_;
66                         const std::vector<Routes> routes_;
67                         const std::string name_;
68                         const HalVersion halVersion_;
69                         public:
70                         Module(std::vector<AttachedDevices> attachedDevices, std::optional<std::string> defaultOutputDevice, std::vector<MixPorts> mixPorts, std::vector<DevicePorts> devicePorts, std::vector<Routes> routes, std::string name, HalVersion halVersion);
71                         const std::vector<AttachedDevices>& getAttachedDevices() const;
72                         bool hasAttachedDevices() const;
73                         const AttachedDevices* getFirstAttachedDevices() const;
74                         const std::string& getDefaultOutputDevice() const;
75                         bool hasDefaultOutputDevice() const;
76                         const std::vector<MixPorts>& getMixPorts() const;
77                         bool hasMixPorts() const;
78                         const MixPorts* getFirstMixPorts() const;
79                         const std::vector<DevicePorts>& getDevicePorts() const;
80                         bool hasDevicePorts() const;
81                         const DevicePorts* getFirstDevicePorts() const;
82                         const std::vector<Routes>& getRoutes() const;
83                         bool hasRoutes() const;
84                         const Routes* getFirstRoutes() const;
85                         const std::string& getName() const;
86                         bool hasName() const;
87                         const HalVersion& getHalVersion() const;
88                         bool hasHalVersion() const;
89                         static Modules::Module read(xmlNode *root);
90                     };
91 
92 
93                     private:
94                     const std::vector<Modules::Module> _module_;
95                     public:
96                     explicit Modules(std::vector<Module> _module);
97                     const std::vector<Modules::Module>& get_module() const;
98                     bool has_module() const;
99                     const Modules::Module* getFirst_module() const;
100                     static Modules read(xmlNode *root);
101                 };
102 
103                 class AttachedDevices {
104                     private:
105                     const std::vector<std::string> item_;
106                     public:
107                     explicit AttachedDevices(std::vector<std::string> item);
108                     const std::vector<std::string>& getItem() const;
109                     bool hasItem() const;
110                     const std::string* getFirstItem() const;
111                     static AttachedDevices read(xmlNode *root);
112                 };
113 
114                 class MixPorts {
115                     public:
116                     class MixPort {
117                         private:
118                         const std::vector<Profile> profile_;
119                         const std::vector<Gains> gains_;
120                         const std::string name_;
121                         const Role role_;
122                         const std::optional<std::vector<AudioInOutFlag>> flags_;
123                         const std::optional<unsigned int> maxOpenCount_;
124                         const std::optional<unsigned int> maxActiveCount_;
125                         const std::optional<unsigned int> recommendedMuteDurationMs_;
126                         public:
127                         MixPort(std::vector<Profile> profile, std::vector<Gains> gains, std::string name, Role role, std::optional<std::vector<AudioInOutFlag>> flags, std::optional<unsigned int> maxOpenCount, std::optional<unsigned int> maxActiveCount, std::optional<unsigned int> recommendedMuteDurationMs);
128                         const std::vector<Profile>& getProfile() const;
129                         bool hasProfile() const;
130                         const Profile* getFirstProfile() const;
131                         const std::vector<Gains>& getGains() const;
132                         bool hasGains() const;
133                         const Gains* getFirstGains() const;
134                         const std::string& getName() const;
135                         bool hasName() const;
136                         const Role& getRole() const;
137                         bool hasRole() const;
138                         const std::vector<AudioInOutFlag>& getFlags() const;
139                         bool hasFlags() const;
140                         const unsigned int& getMaxOpenCount() const;
141                         bool hasMaxOpenCount() const;
142                         const unsigned int& getMaxActiveCount() const;
143                         bool hasMaxActiveCount() const;
144                         const unsigned int& getRecommendedMuteDurationMs() const;
145                         bool hasRecommendedMuteDurationMs() const;
146                         static MixPorts::MixPort read(xmlNode *root);
147                     };
148 
149 
150                     private:
151                     const std::vector<MixPorts::MixPort> mixPort_;
152                     public:
153                     explicit MixPorts(std::vector<MixPort> mixPort);
154                     const std::vector<MixPorts::MixPort>& getMixPort() const;
155                     bool hasMixPort() const;
156                     const MixPorts::MixPort* getFirstMixPort() const;
157                     static MixPorts read(xmlNode *root);
158                 };
159 
160                 class Profile {
161                     private:
162                     const std::optional<std::string> format_;
163                     const std::optional<std::vector<int64_t>> samplingRates_;
164                     const std::optional<std::vector<AudioChannelMask>> channelMasks_;
165                     public:
166                     Profile(std::optional<std::string> format, std::optional<std::vector<int64_t>> samplingRates, std::optional<std::vector<AudioChannelMask>> channelMasks);
167                     const std::string& getFormat() const;
168                     bool hasFormat() const;
169                     const std::vector<int64_t>& getSamplingRates() const;
170                     bool hasSamplingRates() const;
171                     const std::vector<AudioChannelMask>& getChannelMasks() const;
172                     bool hasChannelMasks() const;
173                     static Profile read(xmlNode *root);
174                 };
175 
176                 class Gains {
177                     public:
178                     class Gain {
179                         private:
180                         const std::vector<AudioGainMode> mode_;
181                         const std::optional<AudioChannelMask> channel_mask_;
182                         const std::optional<int> minValueMB_;
183                         const std::optional<int> maxValueMB_;
184                         const std::optional<int> defaultValueMB_;
185                         const std::optional<int> stepValueMB_;
186                         const std::optional<int> minRampMs_;
187                         const std::optional<int> maxRampMs_;
188                         const std::optional<bool> useForVolume_;
189                         public:
190                         Gain(std::vector<AudioGainMode> mode, std::optional<AudioChannelMask> channel_mask, std::optional<int> minValueMB, std::optional<int> maxValueMB, std::optional<int> defaultValueMB, std::optional<int> stepValueMB, std::optional<int> minRampMs, std::optional<int> maxRampMs, std::optional<bool> useForVolume);
191                         const std::vector<AudioGainMode>& getMode() const;
192                         bool hasMode() const;
193                         const AudioChannelMask& getChannel_mask() const;
194                         bool hasChannel_mask() const;
195                         const int& getMinValueMB() const;
196                         bool hasMinValueMB() const;
197                         const int& getMaxValueMB() const;
198                         bool hasMaxValueMB() const;
199                         const int& getDefaultValueMB() const;
200                         bool hasDefaultValueMB() const;
201                         const int& getStepValueMB() const;
202                         bool hasStepValueMB() const;
203                         const int& getMinRampMs() const;
204                         bool hasMinRampMs() const;
205                         const int& getMaxRampMs() const;
206                         bool hasMaxRampMs() const;
207                         const bool& getUseForVolume() const;
208                         bool hasUseForVolume() const;
209                         static Gains::Gain read(xmlNode *root);
210                     };
211 
212 
213                     private:
214                     const std::vector<Gains::Gain> gain_;
215                     public:
216                     explicit Gains(std::vector<Gain> gain);
217                     const std::vector<Gains::Gain>& getGain() const;
218                     bool hasGain() const;
219                     const Gains::Gain* getFirstGain() const;
220                     static Gains read(xmlNode *root);
221                 };
222 
223                 class DevicePorts {
224                     public:
225                     class DevicePort {
226                         private:
227                         const std::vector<Profile> profile_;
228                         const std::vector<Gains> gains_;
229                         const std::string tagName_;
230                         const std::string type_;
231                         const Role role_;
232                         const std::optional<std::string> address_;
233                         const std::optional<bool> _default_;
234                         const std::optional<std::vector<std::string>> encodedFormats_;
235                         public:
236                         DevicePort(std::vector<Profile> profile, std::vector<Gains> gains, std::string tagName, std::string type, Role role, std::optional<std::string> address, std::optional<bool> _default, std::optional<std::vector<std::string>> encodedFormats);
237                         const std::vector<Profile>& getProfile() const;
238                         bool hasProfile() const;
239                         const Profile* getFirstProfile() const;
240                         const std::vector<Gains>& getGains() const;
241                         bool hasGains() const;
242                         const Gains* getFirstGains() const;
243                         const std::string& getTagName() const;
244                         bool hasTagName() const;
245                         const std::string& getType() const;
246                         bool hasType() const;
247                         const Role& getRole() const;
248                         bool hasRole() const;
249                         const std::string& getAddress() const;
250                         bool hasAddress() const;
251                         const bool& get_default() const;
252                         bool has_default() const;
253                         const std::vector<std::string>& getEncodedFormats() const;
254                         bool hasEncodedFormats() const;
255                         static DevicePorts::DevicePort read(xmlNode *root);
256                     };
257 
258 
259                     private:
260                     const std::vector<DevicePorts::DevicePort> devicePort_;
261                     public:
262                     explicit DevicePorts(std::vector<DevicePort> devicePort);
263                     const std::vector<DevicePorts::DevicePort>& getDevicePort() const;
264                     bool hasDevicePort() const;
265                     const DevicePorts::DevicePort* getFirstDevicePort() const;
266                     static DevicePorts read(xmlNode *root);
267                 };
268 
269                 class Routes {
270                     public:
271                     class Route {
272                         private:
273                         const MixType type_;
274                         const std::string sink_;
275                         const std::string sources_;
276                         public:
277                         Route(MixType type, std::string sink, std::string sources);
278                         const MixType& getType() const;
279                         bool hasType() const;
280                         const std::string& getSink() const;
281                         bool hasSink() const;
282                         const std::string& getSources() const;
283                         bool hasSources() const;
284                         static Routes::Route read(xmlNode *root);
285                     };
286 
287 
288                     private:
289                     const std::vector<Routes::Route> route_;
290                     public:
291                     explicit Routes(std::vector<Route> route);
292                     const std::vector<Routes::Route>& getRoute() const;
293                     bool hasRoute() const;
294                     const Routes::Route* getFirstRoute() const;
295                     static Routes read(xmlNode *root);
296                 };
297 
298                 class Volumes {
299                     private:
300                     const std::vector<Volume> volume_;
301                     const std::vector<Reference> reference_;
302                     public:
303                     Volumes(std::vector<Volume> volume, std::vector<Reference> reference);
304                     const std::vector<Volume>& getVolume() const;
305                     bool hasVolume() const;
306                     const Volume* getFirstVolume() const;
307                     const std::vector<Reference>& getReference() const;
308                     bool hasReference() const;
309                     const Reference* getFirstReference() const;
310                     static Volumes read(xmlNode *root);
311                 };
312 
313                 class Volume {
314                     private:
315                     const std::vector<std::string> point_;
316                     const std::optional<AudioStreamType> stream_;
317                     const std::optional<DeviceCategory> deviceCategory_;
318                     const std::optional<std::string> ref_;
319                     public:
320                     Volume(std::vector<std::string> point, std::optional<AudioStreamType> stream, std::optional<DeviceCategory> deviceCategory, std::optional<std::string> ref);
321                     const std::vector<std::string>& getPoint() const;
322                     bool hasPoint() const;
323                     const std::string* getFirstPoint() const;
324                     const AudioStreamType& getStream() const;
325                     bool hasStream() const;
326                     const DeviceCategory& getDeviceCategory() const;
327                     bool hasDeviceCategory() const;
328                     const std::string& getRef() const;
329                     bool hasRef() const;
330                     static Volume read(xmlNode *root);
331                 };
332 
333                 class Reference {
334                     private:
335                     const std::vector<std::string> point_;
336                     const std::string name_;
337                     public:
338                     Reference(std::vector<std::string> point, std::string name);
339                     const std::vector<std::string>& getPoint() const;
340                     bool hasPoint() const;
341                     const std::string* getFirstPoint() const;
342                     const std::string& getName() const;
343                     bool hasName() const;
344                     static Reference read(xmlNode *root);
345                 };
346 
347                 class SurroundSound {
348                     private:
349                     const std::vector<SurroundFormats> formats_;
350                     public:
351                     explicit SurroundSound(std::vector<SurroundFormats> formats);
352                     const std::vector<SurroundFormats>& getFormats() const;
353                     bool hasFormats() const;
354                     const SurroundFormats* getFirstFormats() const;
355                     static SurroundSound read(xmlNode *root);
356                 };
357 
358                 class SurroundFormats {
359                     public:
360                     class Format {
361                         private:
362                         const std::string name_;
363                         const std::optional<std::vector<std::string>> subformats_;
364                         public:
365                         Format(std::string name, std::optional<std::vector<std::string>> subformats);
366                         const std::string& getName() const;
367                         bool hasName() const;
368                         const std::vector<std::string>& getSubformats() const;
369                         bool hasSubformats() const;
370                         static SurroundFormats::Format read(xmlNode *root);
371                     };
372 
373 
374                     private:
375                     const std::vector<SurroundFormats::Format> format_;
376                     public:
377                     explicit SurroundFormats(std::vector<Format> format);
378                     const std::vector<SurroundFormats::Format>& getFormat() const;
379                     bool hasFormat() const;
380                     const SurroundFormats::Format* getFirstFormat() const;
381                     static SurroundFormats read(xmlNode *root);
382                 };
383 
384                 class AudioPolicyConfiguration {
385                     private:
386                     const std::vector<GlobalConfiguration> globalConfiguration_;
387                     const std::vector<Modules> modules_;
388                     const std::vector<Volumes> volumes_;
389                     const std::vector<SurroundSound> surroundSound_;
390                     const std::optional<Version> version_;
391                     public:
392                     AudioPolicyConfiguration(std::vector<GlobalConfiguration> globalConfiguration, std::vector<Modules> modules, std::vector<Volumes> volumes, std::vector<SurroundSound> surroundSound, std::optional<Version> version);
393                     const std::vector<GlobalConfiguration>& getGlobalConfiguration() const;
394                     bool hasGlobalConfiguration() const;
395                     const GlobalConfiguration* getFirstGlobalConfiguration() const;
396                     const std::vector<Modules>& getModules() const;
397                     bool hasModules() const;
398                     const Modules* getFirstModules() const;
399                     const std::vector<Volumes>& getVolumes() const;
400                     bool hasVolumes() const;
401                     const Volumes* getFirstVolumes() const;
402                     const std::vector<SurroundSound>& getSurroundSound() const;
403                     bool hasSurroundSound() const;
404                     const SurroundSound* getFirstSurroundSound() const;
405                     const Version& getVersion() const;
406                     bool hasVersion() const;
407                     static AudioPolicyConfiguration read(xmlNode *root);
408                 };
409 
410             } // configuration
411         } // policy
412     } // audio
413 } // android
414 #endif // ANDROID_AUDIO_POLICY_CONFIGURATION_H
415