1 /* 2 * Copyright (C) 2017 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 18 #ifndef ANDROID_MEDIA_EFFECTSCONFIG_H 19 #define ANDROID_MEDIA_EFFECTSCONFIG_H 20 21 /** @file Parses audio effects configuration file to C and C++ structure. 22 * @see audio_effects_conf_V2_0.xsd for documentation on each structure 23 */ 24 25 #include <system/audio_effect.h> 26 27 #include <map> 28 #include <memory> 29 #include <string> 30 #include <vector> 31 32 namespace android { 33 namespace effectsConfig { 34 35 /** Default path of effect configuration file. Relative to DEFAULT_LOCATIONS. */ 36 constexpr const char* DEFAULT_NAME = "audio_effects.xml"; 37 38 /** Default path of effect configuration file. 39 * The /vendor partition is the recommended one, the others are deprecated. 40 */ 41 constexpr const char* DEFAULT_LOCATIONS[] = {"/odm/etc", "/vendor/etc", "/system/etc"}; 42 43 /** Directories where the effect libraries will be search for. */ 44 constexpr const char* LD_EFFECT_LIBRARY_PATH[] = 45 #ifdef __LP64__ 46 {"/odm/lib64/soundfx", "/vendor/lib64/soundfx", "/system/lib64/soundfx"}; 47 #else 48 {"/odm/lib/soundfx", "/vendor/lib/soundfx", "/system/lib/soundfx"}; 49 #endif 50 51 struct Library { 52 std::string name; 53 std::string path; 54 }; 55 using Libraries = std::vector<Library>; 56 57 struct EffectImpl { 58 Library* library; //< Only valid as long as the associated library vector is unmodified 59 effect_uuid_t uuid; 60 }; 61 62 struct Effect : public EffectImpl { 63 std::string name; 64 bool isProxy; 65 EffectImpl libSw; //< Only valid if isProxy 66 EffectImpl libHw; //< Only valid if isProxy 67 }; 68 69 using Effects = std::vector<Effect>; 70 71 template <class Type> 72 struct Stream { 73 Type type; 74 std::vector<std::reference_wrapper<Effect>> effects; 75 }; 76 using OutputStream = Stream<audio_stream_type_t>; 77 using InputStream = Stream<audio_source_t>; 78 79 /** Parsed configuration. 80 * Intended to be a transient structure only used for deserialization. 81 * Note: Everything is copied in the configuration from the xml dom. 82 * If copies needed to be avoided due to performance issue, 83 * consider keeping a private handle on the xml dom and replace all strings by dom pointers. 84 * Or even better, use SAX parsing to avoid the allocations all together. 85 */ 86 struct Config { 87 float version; 88 Libraries libraries; 89 Effects effects; 90 std::vector<OutputStream> postprocess; 91 std::vector<InputStream> preprocess; 92 }; 93 94 /** Result of `parse(const char*)` */ 95 struct ParsingResult { 96 /** Parsed config, nullptr if the xml lib could not load the file */ 97 std::unique_ptr<Config> parsedConfig; 98 size_t nbSkippedElement; //< Number of skipped invalid library, effect or processing chain 99 const std::string configPath; //< Path to the loaded configuration 100 }; 101 102 /** Parses the provided effect configuration. 103 * Parsing do not stop of first invalid element, but continues to the next. 104 * @param[in] path of the configuration file do load 105 * if nullptr, look for DEFAULT_NAME in DEFAULT_LOCATIONS. 106 * @see ParsingResult::nbSkippedElement 107 */ 108 ParsingResult parse(const char* path = nullptr); 109 110 } // namespace effectsConfig 111 } // namespace android 112 #endif // ANDROID_MEDIA_EFFECTSCONFIG_H 113