Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 17 | #include <optional> |
| 18 | #include <string> |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 19 | #define LOG_TAG "AHAL_EffectConfig" |
| 20 | #include <android-base/logging.h> |
François Gaffie | ed095e6 | 2024-05-30 13:50:50 +0200 | [diff] [blame] | 21 | #include <media/AidlConversionCppNdk.h> |
| 22 | #include <system/audio.h> |
Shunkai Yao | beef909 | 2023-06-29 18:18:20 +0000 | [diff] [blame] | 23 | #include <system/audio_aidl_utils.h> |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 24 | #include <system/audio_effects/audio_effects_conf.h> |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 25 | #include <system/audio_effects/effect_uuid.h> |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 26 | |
| 27 | #include "effectFactory-impl/EffectConfig.h" |
| 28 | |
Deyao Ren | 0874626 | 2023-12-07 20:08:17 +0000 | [diff] [blame] | 29 | #ifdef __ANDROID_APEX__ |
| 30 | #include <android/apexsupport.h> |
| 31 | #endif |
| 32 | |
François Gaffie | ed095e6 | 2024-05-30 13:50:50 +0200 | [diff] [blame] | 33 | using aidl::android::media::audio::common::AudioDevice; |
| 34 | using aidl::android::media::audio::common::AudioDeviceAddress; |
| 35 | using aidl::android::media::audio::common::AudioDeviceDescription; |
| 36 | using aidl::android::media::audio::common::AudioDeviceType; |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 37 | using aidl::android::media::audio::common::AudioSource; |
| 38 | using aidl::android::media::audio::common::AudioStreamType; |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 39 | using aidl::android::media::audio::common::AudioUuid; |
| 40 | |
| 41 | namespace aidl::android::hardware::audio::effect { |
| 42 | |
| 43 | EffectConfig::EffectConfig(const std::string& file) { |
| 44 | tinyxml2::XMLDocument doc; |
| 45 | doc.LoadFile(file.c_str()); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 46 | // parse the xml file into maps |
| 47 | if (doc.Error()) { |
| 48 | LOG(ERROR) << __func__ << " tinyxml2 failed to load " << file |
| 49 | << " error: " << doc.ErrorStr(); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | auto registerFailure = [&](bool result) { mSkippedElements += result ? 0 : 1; }; |
| 54 | |
| 55 | for (auto& xmlConfig : getChildren(doc, "audio_effects_conf")) { |
| 56 | // Parse library |
| 57 | for (auto& xmlLibraries : getChildren(xmlConfig, "libraries")) { |
| 58 | for (auto& xmlLibrary : getChildren(xmlLibraries, "library")) { |
| 59 | registerFailure(parseLibrary(xmlLibrary)); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Parse effects |
| 64 | for (auto& xmlEffects : getChildren(xmlConfig, "effects")) { |
| 65 | for (auto& xmlEffect : getChildren(xmlEffects)) { |
| 66 | registerFailure(parseEffect(xmlEffect)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Parse pre processing chains |
| 71 | for (auto& xmlPreprocess : getChildren(xmlConfig, "preprocess")) { |
| 72 | for (auto& xmlStream : getChildren(xmlPreprocess, "stream")) { |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 73 | // AudioSource |
| 74 | registerFailure(parseProcessing(Processing::Type::source, xmlStream)); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | // Parse post processing chains |
| 79 | for (auto& xmlPostprocess : getChildren(xmlConfig, "postprocess")) { |
| 80 | for (auto& xmlStream : getChildren(xmlPostprocess, "stream")) { |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 81 | // AudioStreamType |
| 82 | registerFailure(parseProcessing(Processing::Type::streamType, xmlStream)); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
François Gaffie | ed095e6 | 2024-05-30 13:50:50 +0200 | [diff] [blame] | 85 | |
| 86 | // Parse device effect chains |
| 87 | for (auto& xmlDeviceEffects : getChildren(xmlConfig, "deviceEffects")) { |
| 88 | for (auto& xmlDevice : getChildren(xmlDeviceEffects, "device")) { |
| 89 | // AudioDevice |
| 90 | registerFailure(parseProcessing(Processing::Type::device, xmlDevice)); |
| 91 | } |
| 92 | } |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 93 | } |
| 94 | LOG(DEBUG) << __func__ << " successfully parsed " << file << ", skipping " << mSkippedElements |
| 95 | << " element(s)"; |
| 96 | } |
| 97 | |
| 98 | std::vector<std::reference_wrapper<const tinyxml2::XMLElement>> EffectConfig::getChildren( |
| 99 | const tinyxml2::XMLNode& node, const char* childTag) { |
| 100 | std::vector<std::reference_wrapper<const tinyxml2::XMLElement>> children; |
| 101 | for (auto* child = node.FirstChildElement(childTag); child != nullptr; |
| 102 | child = child->NextSiblingElement(childTag)) { |
| 103 | children.emplace_back(*child); |
| 104 | } |
| 105 | return children; |
| 106 | } |
| 107 | |
Shunkai Yao | 52ba4dc | 2023-02-01 21:57:20 +0000 | [diff] [blame] | 108 | bool EffectConfig::resolveLibrary(const std::string& path, std::string* resolvedPath) { |
Shunkai Yao | 6190a96 | 2024-12-11 19:19:39 +0000 | [diff] [blame] | 109 | #ifdef __ANDROID_APEX__ |
Jooyung Han | 23e5bf2 | 2024-02-01 12:49:35 +0900 | [diff] [blame] | 110 | if constexpr (__ANDROID_VENDOR_API__ >= 202404) { |
Deyao Ren | 0874626 | 2023-12-07 20:08:17 +0000 | [diff] [blame] | 111 | AApexInfo *apexInfo; |
| 112 | if (AApexInfo_create(&apexInfo) == AAPEXINFO_OK) { |
| 113 | std::string apexName(AApexInfo_getName(apexInfo)); |
| 114 | AApexInfo_destroy(apexInfo); |
| 115 | std::string candidatePath("/apex/"); |
| 116 | candidatePath.append(apexName).append(kEffectLibApexPath).append(path); |
| 117 | LOG(DEBUG) << __func__ << " effect lib path " << candidatePath; |
| 118 | if (access(candidatePath.c_str(), R_OK) == 0) { |
| 119 | *resolvedPath = std::move(candidatePath); |
| 120 | return true; |
| 121 | } |
| 122 | } |
| 123 | } else { |
| 124 | LOG(DEBUG) << __func__ << " libapexsupport is not supported"; |
| 125 | } |
Shunkai Yao | 6190a96 | 2024-12-11 19:19:39 +0000 | [diff] [blame] | 126 | #endif |
Deyao Ren | 0874626 | 2023-12-07 20:08:17 +0000 | [diff] [blame] | 127 | |
| 128 | // If audio effects libs are not in vendor apex, locate them in kEffectLibPath |
Shunkai Yao | 52ba4dc | 2023-02-01 21:57:20 +0000 | [diff] [blame] | 129 | for (auto* libraryDirectory : kEffectLibPath) { |
| 130 | std::string candidatePath = std::string(libraryDirectory) + '/' + path; |
| 131 | if (access(candidatePath.c_str(), R_OK) == 0) { |
| 132 | *resolvedPath = std::move(candidatePath); |
| 133 | return true; |
| 134 | } |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 139 | bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml) { |
| 140 | const char* name = xml.Attribute("name"); |
| 141 | RETURN_VALUE_IF(!name, false, "noNameAttribute"); |
| 142 | const char* path = xml.Attribute("path"); |
| 143 | RETURN_VALUE_IF(!path, false, "noPathAttribute"); |
| 144 | |
Shunkai Yao | 52ba4dc | 2023-02-01 21:57:20 +0000 | [diff] [blame] | 145 | std::string resolvedPath; |
| 146 | if (!resolveLibrary(path, &resolvedPath)) { |
| 147 | LOG(ERROR) << __func__ << " can't find " << path; |
| 148 | return false; |
| 149 | } |
| 150 | mLibraryMap[name] = resolvedPath; |
| 151 | LOG(DEBUG) << __func__ << " " << name << " : " << resolvedPath; |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 152 | return true; |
| 153 | } |
| 154 | |
| 155 | bool EffectConfig::parseEffect(const tinyxml2::XMLElement& xml) { |
| 156 | struct EffectLibraries effectLibraries; |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 157 | std::vector<Library> libraries; |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 158 | std::string name = xml.Attribute("name"); |
| 159 | RETURN_VALUE_IF(name == "", false, "effectsNoName"); |
| 160 | |
Shunkai Yao | bb35eff | 2024-03-14 22:04:02 +0000 | [diff] [blame] | 161 | LOG(VERBOSE) << __func__ << dump(xml); |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 162 | struct Library library; |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 163 | if (std::strcmp(xml.Name(), "effectProxy") == 0) { |
| 164 | // proxy lib and uuid |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 165 | RETURN_VALUE_IF(!parseLibrary(xml, library, true), false, "parseProxyLibFailed"); |
| 166 | effectLibraries.proxyLibrary = library; |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 167 | // proxy effect libs and UUID |
| 168 | auto xmlProxyLib = xml.FirstChildElement(); |
| 169 | RETURN_VALUE_IF(!xmlProxyLib, false, "noLibForProxy"); |
| 170 | while (xmlProxyLib) { |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 171 | struct Library tempLibrary; |
| 172 | RETURN_VALUE_IF(!parseLibrary(*xmlProxyLib, tempLibrary), false, |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 173 | "parseEffectLibFailed"); |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 174 | libraries.push_back(std::move(tempLibrary)); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 175 | xmlProxyLib = xmlProxyLib->NextSiblingElement(); |
| 176 | } |
| 177 | } else { |
| 178 | // expect only one library if not proxy |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 179 | RETURN_VALUE_IF(!parseLibrary(xml, library), false, "parseEffectLibFailed"); |
| 180 | libraries.push_back(std::move(library)); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 183 | effectLibraries.libraries = std::move(libraries); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 184 | mEffectsMap[name] = std::move(effectLibraries); |
| 185 | return true; |
| 186 | } |
| 187 | |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 188 | bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml, struct Library& library, |
| 189 | bool isProxy) { |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 190 | // Retrieve library name only if not effectProxy element |
| 191 | if (!isProxy) { |
| 192 | const char* name = xml.Attribute("library"); |
| 193 | RETURN_VALUE_IF(!name, false, "noLibraryAttribute"); |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 194 | library.name = name; |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 197 | const char* uuidStr = xml.Attribute("uuid"); |
| 198 | RETURN_VALUE_IF(!uuidStr, false, "noUuidAttribute"); |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 199 | library.uuid = stringToUuid(uuidStr); |
| 200 | if (const char* typeUuidStr = xml.Attribute("type")) { |
| 201 | library.type = stringToUuid(typeUuidStr); |
| 202 | } |
| 203 | RETURN_VALUE_IF((library.uuid == getEffectUuidZero()), false, "invalidUuidAttribute"); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 204 | |
Shunkai Yao | bb35eff | 2024-03-14 22:04:02 +0000 | [diff] [blame] | 205 | LOG(VERBOSE) << __func__ << (isProxy ? " proxy " : library.name) << " : uuid " |
| 206 | << ::android::audio::utils::toString(library.uuid) |
| 207 | << (library.type.has_value() |
| 208 | ? ::android::audio::utils::toString(library.type.value()) |
| 209 | : ""); |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 210 | return true; |
| 211 | } |
| 212 | |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 213 | std::optional<Processing::Type> EffectConfig::stringToProcessingType(Processing::Type::Tag typeTag, |
François Gaffie | ed095e6 | 2024-05-30 13:50:50 +0200 | [diff] [blame] | 214 | const std::string& type, |
| 215 | const std::string& address) { |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 216 | // see list of audio stream types in audio_stream_type_t: |
| 217 | // system/media/audio/include/system/audio_effects/audio_effects_conf.h |
| 218 | // AUDIO_STREAM_DEFAULT_TAG is not listed here because according to SYS_RESERVED_DEFAULT in |
| 219 | // AudioStreamType.aidl: "Value reserved for system use only. HALs must never return this value |
| 220 | // to the system or accept it from the system". |
| 221 | static const std::map<const std::string, AudioStreamType> sAudioStreamTypeTable = { |
| 222 | {AUDIO_STREAM_VOICE_CALL_TAG, AudioStreamType::VOICE_CALL}, |
| 223 | {AUDIO_STREAM_SYSTEM_TAG, AudioStreamType::SYSTEM}, |
| 224 | {AUDIO_STREAM_RING_TAG, AudioStreamType::RING}, |
| 225 | {AUDIO_STREAM_MUSIC_TAG, AudioStreamType::MUSIC}, |
| 226 | {AUDIO_STREAM_ALARM_TAG, AudioStreamType::ALARM}, |
| 227 | {AUDIO_STREAM_NOTIFICATION_TAG, AudioStreamType::NOTIFICATION}, |
| 228 | {AUDIO_STREAM_BLUETOOTH_SCO_TAG, AudioStreamType::BLUETOOTH_SCO}, |
| 229 | {AUDIO_STREAM_ENFORCED_AUDIBLE_TAG, AudioStreamType::ENFORCED_AUDIBLE}, |
| 230 | {AUDIO_STREAM_DTMF_TAG, AudioStreamType::DTMF}, |
| 231 | {AUDIO_STREAM_TTS_TAG, AudioStreamType::TTS}, |
| 232 | {AUDIO_STREAM_ASSISTANT_TAG, AudioStreamType::ASSISTANT}}; |
| 233 | |
| 234 | // see list of audio sources in audio_source_t: |
| 235 | // system/media/audio/include/system/audio_effects/audio_effects_conf.h |
| 236 | static const std::map<const std::string, AudioSource> sAudioSourceTable = { |
Shunkai Yao | c105694 | 2023-08-23 16:53:57 +0000 | [diff] [blame] | 237 | {MIC_SRC_TAG, AudioSource::MIC}, |
| 238 | {VOICE_UL_SRC_TAG, AudioSource::VOICE_UPLINK}, |
| 239 | {VOICE_DL_SRC_TAG, AudioSource::VOICE_DOWNLINK}, |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 240 | {VOICE_CALL_SRC_TAG, AudioSource::VOICE_CALL}, |
Shunkai Yao | c105694 | 2023-08-23 16:53:57 +0000 | [diff] [blame] | 241 | {CAMCORDER_SRC_TAG, AudioSource::CAMCORDER}, |
| 242 | {VOICE_REC_SRC_TAG, AudioSource::VOICE_RECOGNITION}, |
| 243 | {VOICE_COMM_SRC_TAG, AudioSource::VOICE_COMMUNICATION}, |
| 244 | {REMOTE_SUBMIX_SRC_TAG, AudioSource::REMOTE_SUBMIX}, |
| 245 | {UNPROCESSED_SRC_TAG, AudioSource::UNPROCESSED}, |
| 246 | {VOICE_PERFORMANCE_SRC_TAG, AudioSource::VOICE_PERFORMANCE}}; |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 247 | |
| 248 | if (typeTag == Processing::Type::streamType) { |
| 249 | auto typeIter = sAudioStreamTypeTable.find(type); |
| 250 | if (typeIter != sAudioStreamTypeTable.end()) { |
| 251 | return typeIter->second; |
| 252 | } |
| 253 | } else if (typeTag == Processing::Type::source) { |
| 254 | auto typeIter = sAudioSourceTable.find(type); |
| 255 | if (typeIter != sAudioSourceTable.end()) { |
| 256 | return typeIter->second; |
| 257 | } |
François Gaffie | ed095e6 | 2024-05-30 13:50:50 +0200 | [diff] [blame] | 258 | } else if (typeTag == Processing::Type::device) { |
| 259 | audio_devices_t deviceType; |
| 260 | if (!audio_device_from_string(type.c_str(), &deviceType)) { |
| 261 | LOG(ERROR) << __func__ << "DeviceEffect: invalid type " << type; |
| 262 | return std::nullopt; |
| 263 | } |
| 264 | auto ret = ::aidl::android::legacy2aidl_audio_device_AudioDevice(deviceType, address); |
| 265 | if (!ret.ok()) { |
| 266 | LOG(ERROR) << __func__ << "DeviceEffect: Failed to get AudioDevice from type " |
| 267 | << deviceType << ", address " << address; |
| 268 | return std::nullopt; |
| 269 | } |
| 270 | return ret.value(); |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | return std::nullopt; |
| 274 | } |
| 275 | |
| 276 | bool EffectConfig::parseProcessing(Processing::Type::Tag typeTag, const tinyxml2::XMLElement& xml) { |
Shunkai Yao | bb35eff | 2024-03-14 22:04:02 +0000 | [diff] [blame] | 277 | LOG(VERBOSE) << __func__ << dump(xml); |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 278 | const char* typeStr = xml.Attribute("type"); |
François Gaffie | ed095e6 | 2024-05-30 13:50:50 +0200 | [diff] [blame] | 279 | const char* addressStr = xml.Attribute("address"); |
| 280 | // For device effect, device address is optional, match will be done for the given device type |
| 281 | // with empty address. |
| 282 | auto aidlType = stringToProcessingType(typeTag, typeStr, addressStr ? addressStr : ""); |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 283 | RETURN_VALUE_IF(!aidlType.has_value(), false, "illegalStreamType"); |
| 284 | RETURN_VALUE_IF(0 != mProcessingMap.count(aidlType.value()), false, "duplicateStreamType"); |
| 285 | |
| 286 | for (auto& apply : getChildren(xml, "apply")) { |
| 287 | const char* name = apply.get().Attribute("effect"); |
| 288 | if (mEffectsMap.find(name) == mEffectsMap.end()) { |
| 289 | LOG(ERROR) << __func__ << " effect " << name << " doesn't exist, skipping"; |
| 290 | continue; |
| 291 | } |
| 292 | RETURN_VALUE_IF(!name, false, "noEffectAttribute"); |
| 293 | mProcessingMap[aidlType.value()].emplace_back(mEffectsMap[name]); |
Shunkai Yao | 5824efb | 2023-05-08 21:16:13 +0000 | [diff] [blame] | 294 | } |
| 295 | return true; |
| 296 | } |
| 297 | |
| 298 | const std::map<Processing::Type, std::vector<EffectConfig::EffectLibraries>>& |
| 299 | EffectConfig::getProcessingMap() const { |
| 300 | return mProcessingMap; |
| 301 | } |
| 302 | |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 303 | bool EffectConfig::findUuid(const std::pair<std::string, struct EffectLibraries>& effectElem, |
| 304 | AudioUuid* uuid) { |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 305 | // Difference from EFFECT_TYPE_LIST_DEF, there could be multiple name mapping to same Effect Type |
| 306 | #define EFFECT_XML_TYPE_LIST_DEF(V) \ |
| 307 | V("acoustic_echo_canceler", AcousticEchoCanceler) \ |
| 308 | V("automatic_gain_control_v1", AutomaticGainControlV1) \ |
| 309 | V("automatic_gain_control_v2", AutomaticGainControlV2) \ |
| 310 | V("bassboost", BassBoost) \ |
| 311 | V("downmix", Downmix) \ |
| 312 | V("dynamics_processing", DynamicsProcessing) \ |
| 313 | V("equalizer", Equalizer) \ |
Shunkai Yao | beef909 | 2023-06-29 18:18:20 +0000 | [diff] [blame] | 314 | V("extensioneffect", Extension) \ |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 315 | V("haptic_generator", HapticGenerator) \ |
| 316 | V("loudness_enhancer", LoudnessEnhancer) \ |
| 317 | V("env_reverb", EnvReverb) \ |
| 318 | V("reverb_env_aux", EnvReverb) \ |
| 319 | V("reverb_env_ins", EnvReverb) \ |
| 320 | V("preset_reverb", PresetReverb) \ |
| 321 | V("reverb_pre_aux", PresetReverb) \ |
| 322 | V("reverb_pre_ins", PresetReverb) \ |
| 323 | V("noise_suppression", NoiseSuppression) \ |
| 324 | V("spatializer", Spatializer) \ |
| 325 | V("virtualizer", Virtualizer) \ |
| 326 | V("visualizer", Visualizer) \ |
| 327 | V("volume", Volume) |
| 328 | |
| 329 | #define GENERATE_MAP_ENTRY_V(s, symbol) {s, &getEffectTypeUuid##symbol}, |
| 330 | |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 331 | const std::string xmlEffectName = effectElem.first; |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 332 | typedef const AudioUuid& (*UuidGetter)(void); |
| 333 | static const std::map<std::string, UuidGetter> uuidMap{ |
| 334 | // std::make_pair("s", &getEffectTypeUuidExtension)}; |
| 335 | {EFFECT_XML_TYPE_LIST_DEF(GENERATE_MAP_ENTRY_V)}}; |
| 336 | if (auto it = uuidMap.find(xmlEffectName); it != uuidMap.end()) { |
| 337 | *uuid = (*it->second)(); |
| 338 | return true; |
| 339 | } |
Shunkai Yao | 80e5850 | 2023-07-14 22:10:46 +0000 | [diff] [blame] | 340 | |
| 341 | const auto& libs = effectElem.second.libraries; |
| 342 | for (const auto& lib : libs) { |
| 343 | if (lib.type.has_value()) { |
| 344 | *uuid = lib.type.value(); |
| 345 | return true; |
| 346 | } |
| 347 | } |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 348 | return false; |
| 349 | } |
| 350 | |
Shunkai Yao | 52abf0a | 2022-11-08 02:44:03 +0000 | [diff] [blame] | 351 | const char* EffectConfig::dump(const tinyxml2::XMLElement& element, |
| 352 | tinyxml2::XMLPrinter&& printer) const { |
| 353 | element.Accept(&printer); |
| 354 | return printer.CStr(); |
| 355 | } |
| 356 | |
| 357 | } // namespace aidl::android::hardware::audio::effect |