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 <system/audio.h> 20 21 #include <string> 22 #include <vector> 23 #include <utils/Errors.h> 24 25 struct _xmlNode; 26 struct _xmlDoc; 27 28 namespace android { 29 namespace engineConfig { 30 31 /** Default path of audio policy usages configuration file. */ 32 constexpr char DEFAULT_PATH[] = "/vendor/etc/audio_policy_engine_configuration.xml"; 33 34 /** Directories where the effect libraries will be search for. */ 35 constexpr const char* POLICY_USAGE_LIBRARY_PATH[] = {"/odm/etc/", "/vendor/etc/", "/system/etc/"}; 36 37 using AttributesVector = std::vector<audio_attributes_t>; 38 using StreamVector = std::vector<audio_stream_type_t>; 39 40 struct AttributesGroup { 41 std::string name; 42 audio_stream_type_t stream; 43 std::string volumeGroup; 44 AttributesVector attributesVect; 45 }; 46 47 using AttributesGroups = std::vector<AttributesGroup>; 48 49 struct CurvePoint { 50 int index; 51 int attenuationInMb; 52 }; 53 using CurvePoints = std::vector<CurvePoint>; 54 55 struct VolumeCurve { 56 std::string deviceCategory; 57 CurvePoints curvePoints; 58 }; 59 using VolumeCurves = std::vector<VolumeCurve>; 60 61 struct VolumeGroup { 62 std::string name; 63 int indexMin; 64 int indexMax; 65 VolumeCurves volumeCurves; 66 }; 67 using VolumeGroups = std::vector<VolumeGroup>; 68 69 struct ProductStrategy { 70 std::string name; 71 AttributesGroups attributesGroups; 72 }; 73 74 using ProductStrategies = std::vector<ProductStrategy>; 75 76 using ValuePair = std::pair<uint32_t, std::string>; 77 using ValuePairs = std::vector<ValuePair>; 78 79 struct CriterionType 80 { 81 std::string name; 82 bool isInclusive; 83 ValuePairs valuePairs; 84 }; 85 86 using CriterionTypes = std::vector<CriterionType>; 87 88 struct Criterion 89 { 90 std::string name; 91 std::string typeName; 92 std::string defaultLiteralValue; 93 }; 94 95 using Criteria = std::vector<Criterion>; 96 97 struct Config { 98 float version; 99 ProductStrategies productStrategies; 100 Criteria criteria; 101 CriterionTypes criterionTypes; 102 VolumeGroups volumeGroups; 103 }; 104 105 /** Result of `parse(const char*)` */ 106 struct ParsingResult { 107 /** Parsed config, nullptr if the xml lib could not load the file */ 108 std::unique_ptr<Config> parsedConfig; 109 size_t nbSkippedElement; //< Number of skipped invalid product strategies 110 }; 111 112 /** Parses the provided audio policy usage configuration. 113 * @return audio policy usage @see Config 114 */ 115 ParsingResult parse(const char* path = DEFAULT_PATH); 116 android::status_t parseLegacyVolumes(VolumeGroups &volumeGroups); 117 118 } // namespace engineConfig 119 } // namespace android 120