• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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. */
36 constexpr char DEFAULT_PATH[] = "/vendor/etc/audio_effects.xml";
37 
38 /** Directories where the effect libraries will be search for. */
39 constexpr const char* LD_EFFECT_LIBRARY_PATH[] =
40 #ifdef __LP64__
41         {"/odm/lib64/soundfx", "/vendor/lib64/soundfx", "/system/lib64/soundfx"};
42 #else
43         {"/odm/lib/soundfx", "/vendor/lib/soundfx", "/system/lib/soundfx"};
44 #endif
45 
46 struct Library {
47     std::string name;
48     std::string path;
49 };
50 using Libraries = std::vector<Library>;
51 
52 struct EffectImpl {
53     Library* library; //< Only valid as long as the associated library vector is unmodified
54     effect_uuid_t uuid;
55 };
56 
57 struct Effect : public EffectImpl {
58     std::string name;
59     bool isProxy;
60     EffectImpl libSw; //< Only valid if isProxy
61     EffectImpl libHw; //< Only valid if isProxy
62 };
63 
64 using Effects = std::vector<Effect>;
65 
66 template <class Type>
67 struct Stream {
68     Type type;
69     std::vector<std::reference_wrapper<Effect>> effects;
70 };
71 using OutputStream = Stream<audio_stream_type_t>;
72 using InputStream = Stream<audio_source_t>;
73 
74 /** Parsed configuration.
75  * Intended to be a transient structure only used for deserialization.
76  * Note: Everything is copied in the configuration from the xml dom.
77  *       If copies needed to be avoided due to performance issue,
78  *       consider keeping a private handle on the xml dom and replace all strings by dom pointers.
79  *       Or even better, use SAX parsing to avoid the allocations all together.
80  */
81 struct Config {
82     float version;
83     Libraries libraries;
84     Effects effects;
85     std::vector<OutputStream> postprocess;
86     std::vector<InputStream> preprocess;
87 };
88 
89 /** Result of `parse(const char*)` */
90 struct ParsingResult {
91     /** Parsed config, nullptr if the xml lib could not load the file */
92     std::unique_ptr<Config> parsedConfig;
93     size_t nbSkippedElement; //< Number of skipped invalid library, effect or processing chain
94 };
95 
96 /** Parses the provided effect configuration.
97  * Parsing do not stop of first invalid element, but continues to the next.
98  * @see ParsingResult::nbSkippedElement
99  */
100 ParsingResult parse(const char* path = DEFAULT_PATH);
101 
102 } // namespace effectsConfig
103 } // namespace android
104 #endif  // ANDROID_MEDIA_EFFECTSCONFIG_H
105