xref: /aosp_15_r20/frameworks/av/services/audiopolicy/engine/config/include/EngineConfig.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string>
20 #include <vector>
21 
22 #include <android/media/audio/common/AudioHalEngineConfig.h>
23 #include <system/audio.h>
24 #include <utils/Errors.h>
25 
26 struct _xmlNode;
27 struct _xmlDoc;
28 
29 /**
30  * AudioAttributes custom tag to identify internal strategies, whose volumes are exclusively
31  * controlled by AudioPolicyManager
32  */
33 #define AUDIO_TAG_APM_RESERVED_INTERNAL "reserved_internal_strategy"
34 
35 namespace android {
36 namespace engineConfig {
37 
38 /** Default path of audio policy usages configuration file. */
39 constexpr char DEFAULT_PATH[] = "/vendor/etc/audio_policy_engine_configuration.xml";
40 
41 using AttributesVector = std::vector<audio_attributes_t>;
42 using StreamVector = std::vector<audio_stream_type_t>;
43 
44 struct AttributesGroup {
45     audio_stream_type_t stream;
46     std::string volumeGroup;
47     AttributesVector attributesVect;
48 };
49 
50 using AttributesGroups = std::vector<AttributesGroup>;
51 
52 struct CurvePoint {
53     int index;
54     int attenuationInMb;
55 };
56 using CurvePoints = std::vector<CurvePoint>;
57 
58 struct VolumeCurve {
59     std::string deviceCategory;
60     CurvePoints curvePoints;
61 };
62 using VolumeCurves = std::vector<VolumeCurve>;
63 
64 struct VolumeGroup {
65     std::string name;
66     int indexMin;
67     int indexMax;
68     VolumeCurves volumeCurves;
69 };
70 using VolumeGroups = std::vector<VolumeGroup>;
71 
72 struct ProductStrategy {
73     std::string name;
74     int id;
75     AttributesGroups attributesGroups;
76 };
77 
78 using ProductStrategies = std::vector<ProductStrategy>;
79 
80 using ValuePair = std::tuple<uint64_t, uint32_t, std::string>;
81 using ValuePairs = std::vector<ValuePair>;
82 
83 struct CriterionType
84 {
85     std::string name;
86     bool isInclusive;
87     ValuePairs valuePairs;
88 };
89 
90 using CriterionTypes = std::vector<CriterionType>;
91 
92 struct Criterion
93 {
94     std::string name;
95     std::string typeName;
96     std::string defaultLiteralValue;
97 };
98 
99 using Criteria = std::vector<Criterion>;
100 
101 struct Config {
102     float version;
103     ProductStrategies productStrategies;
104     Criteria criteria;
105     CriterionTypes criterionTypes;
106     VolumeGroups volumeGroups;
107 };
108 
109 /** Result of `parse(const char*)` */
110 struct ParsingResult {
111     /** Parsed config, nullptr if the xml lib could not load the file */
112     std::unique_ptr<Config> parsedConfig;
113     size_t nbSkippedElement; //< Number of skipped invalid product strategies
114 };
115 
116 /** Parses the provided audio policy usage configuration.
117  * @return audio policy usage @see Config
118  */
119 ParsingResult parse(const char* path = DEFAULT_PATH, bool isConfigurable = false);
120 android::status_t parseLegacyVolumes(VolumeGroups &volumeGroups);
121 ParsingResult convert(const ::android::media::audio::common::AudioHalEngineConfig& aidlConfig);
122 // Exposed for testing.
123 android::status_t parseLegacyVolumeFile(const char* path, VolumeGroups &volumeGroups);
124 
125 } // namespace engineConfig
126 } // namespace android
127