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