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 AttributesGroups attributesGroups; 75 }; 76 77 using ProductStrategies = std::vector<ProductStrategy>; 78 79 using ValuePair = std::tuple<uint64_t, uint32_t, std::string>; 80 using ValuePairs = std::vector<ValuePair>; 81 82 struct CriterionType 83 { 84 std::string name; 85 bool isInclusive; 86 ValuePairs valuePairs; 87 }; 88 89 using CriterionTypes = std::vector<CriterionType>; 90 91 struct Criterion 92 { 93 std::string name; 94 std::string typeName; 95 std::string defaultLiteralValue; 96 }; 97 98 using Criteria = std::vector<Criterion>; 99 100 struct Config { 101 float version; 102 ProductStrategies productStrategies; 103 Criteria criteria; 104 CriterionTypes criterionTypes; 105 VolumeGroups volumeGroups; 106 }; 107 108 /** Result of `parse(const char*)` */ 109 struct ParsingResult { 110 /** Parsed config, nullptr if the xml lib could not load the file */ 111 std::unique_ptr<Config> parsedConfig; 112 size_t nbSkippedElement; //< Number of skipped invalid product strategies 113 }; 114 115 /** Parses the provided audio policy usage configuration. 116 * @return audio policy usage @see Config 117 */ 118 ParsingResult parse(const char* path = DEFAULT_PATH); 119 android::status_t parseLegacyVolumes(VolumeGroups &volumeGroups); 120 ParsingResult convert(const ::android::media::audio::common::AudioHalEngineConfig& aidlConfig); 121 // Exposed for testing. 122 android::status_t parseLegacyVolumeFile(const char* path, VolumeGroups &volumeGroups); 123 124 } // namespace engineConfig 125 } // namespace android 126