Merge "Support custom effect type UUID in audio effect AIDL example service" into main am: 03a07174dd am: 24bfa18a1a

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2657141

Change-Id: Ia27872ab1b98b86d3a9918005ca89a7056a15c8e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2023-07-15 02:54:02 +00:00 committed by Automerger Merge Worker
commit 1087c40f5d
5 changed files with 52 additions and 35 deletions

View file

@ -117,53 +117,59 @@ bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml) {
bool EffectConfig::parseEffect(const tinyxml2::XMLElement& xml) {
struct EffectLibraries effectLibraries;
std::vector<LibraryUuid> libraryUuids;
std::vector<Library> libraries;
std::string name = xml.Attribute("name");
RETURN_VALUE_IF(name == "", false, "effectsNoName");
LOG(DEBUG) << __func__ << dump(xml);
struct LibraryUuid libraryUuid;
struct Library library;
if (std::strcmp(xml.Name(), "effectProxy") == 0) {
// proxy lib and uuid
RETURN_VALUE_IF(!parseLibraryUuid(xml, libraryUuid, true), false, "parseProxyLibFailed");
effectLibraries.proxyLibrary = libraryUuid;
RETURN_VALUE_IF(!parseLibrary(xml, library, true), false, "parseProxyLibFailed");
effectLibraries.proxyLibrary = library;
// proxy effect libs and UUID
auto xmlProxyLib = xml.FirstChildElement();
RETURN_VALUE_IF(!xmlProxyLib, false, "noLibForProxy");
while (xmlProxyLib) {
struct LibraryUuid tempLibraryUuid;
RETURN_VALUE_IF(!parseLibraryUuid(*xmlProxyLib, tempLibraryUuid), false,
struct Library tempLibrary;
RETURN_VALUE_IF(!parseLibrary(*xmlProxyLib, tempLibrary), false,
"parseEffectLibFailed");
libraryUuids.push_back(std::move(tempLibraryUuid));
libraries.push_back(std::move(tempLibrary));
xmlProxyLib = xmlProxyLib->NextSiblingElement();
}
} else {
// expect only one library if not proxy
RETURN_VALUE_IF(!parseLibraryUuid(xml, libraryUuid), false, "parseEffectLibFailed");
libraryUuids.push_back(std::move(libraryUuid));
RETURN_VALUE_IF(!parseLibrary(xml, library), false, "parseEffectLibFailed");
libraries.push_back(std::move(library));
}
effectLibraries.libraries = std::move(libraryUuids);
effectLibraries.libraries = std::move(libraries);
mEffectsMap[name] = std::move(effectLibraries);
return true;
}
bool EffectConfig::parseLibraryUuid(const tinyxml2::XMLElement& xml,
struct LibraryUuid& libraryUuid, bool isProxy) {
bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml, struct Library& library,
bool isProxy) {
// Retrieve library name only if not effectProxy element
if (!isProxy) {
const char* name = xml.Attribute("library");
RETURN_VALUE_IF(!name, false, "noLibraryAttribute");
libraryUuid.name = name;
library.name = name;
}
const char* uuidStr = xml.Attribute("uuid");
RETURN_VALUE_IF(!uuidStr, false, "noUuidAttribute");
libraryUuid.uuid = stringToUuid(uuidStr);
RETURN_VALUE_IF((libraryUuid.uuid == getEffectUuidZero()), false, "invalidUuidAttribute");
library.uuid = stringToUuid(uuidStr);
if (const char* typeUuidStr = xml.Attribute("type")) {
library.type = stringToUuid(typeUuidStr);
}
RETURN_VALUE_IF((library.uuid == getEffectUuidZero()), false, "invalidUuidAttribute");
LOG(DEBUG) << __func__ << (isProxy ? " proxy " : libraryUuid.name) << " : "
<< ::android::audio::utils::toString(libraryUuid.uuid);
LOG(DEBUG) << __func__ << (isProxy ? " proxy " : library.name) << " : uuid "
<< ::android::audio::utils::toString(library.uuid)
<< (library.type.has_value()
? ::android::audio::utils::toString(library.type.value())
: "");
return true;
}
@ -241,7 +247,8 @@ EffectConfig::getProcessingMap() const {
return mProcessingMap;
}
bool EffectConfig::findUuid(const std::string& xmlEffectName, AudioUuid* uuid) {
bool EffectConfig::findUuid(const std::pair<std::string, struct EffectLibraries>& effectElem,
AudioUuid* uuid) {
// Difference from EFFECT_TYPE_LIST_DEF, there could be multiple name mapping to same Effect Type
#define EFFECT_XML_TYPE_LIST_DEF(V) \
V("acoustic_echo_canceler", AcousticEchoCanceler) \
@ -268,6 +275,7 @@ bool EffectConfig::findUuid(const std::string& xmlEffectName, AudioUuid* uuid) {
#define GENERATE_MAP_ENTRY_V(s, symbol) {s, &getEffectTypeUuid##symbol},
const std::string xmlEffectName = effectElem.first;
typedef const AudioUuid& (*UuidGetter)(void);
static const std::map<std::string, UuidGetter> uuidMap{
// std::make_pair("s", &getEffectTypeUuidExtension)};
@ -276,6 +284,14 @@ bool EffectConfig::findUuid(const std::string& xmlEffectName, AudioUuid* uuid) {
*uuid = (*it->second)();
return true;
}
const auto& libs = effectElem.second.libraries;
for (const auto& lib : libs) {
if (lib.type.has_value()) {
*uuid = lib.type.value();
return true;
}
}
return false;
}

View file

@ -105,7 +105,7 @@ ndk::ScopedAStatus Factory::queryProcessing(const std::optional<Processing::Type
if (!in_type.has_value() || in_type.value() == procIter.first) {
Processing process = {.type = procIter.first /* Processing::Type */};
for (const auto& libs : procIter.second /* std::vector<struct EffectLibraries> */) {
for (const auto& lib : libs.libraries /* std::vector<struct LibraryUuid> */) {
for (const auto& lib : libs.libraries /* std::vector<struct Library> */) {
Descriptor desc;
if (libs.proxyLibrary.has_value()) {
desc.common.id.proxy = libs.proxyLibrary.value().uuid;
@ -219,7 +219,7 @@ bool Factory::openEffectLibrary(const AudioUuid& impl, const std::string& path)
return true;
}
void Factory::createIdentityWithConfig(const EffectConfig::LibraryUuid& configLib,
void Factory::createIdentityWithConfig(const EffectConfig::Library& configLib,
const AudioUuid& typeUuid,
const std::optional<AudioUuid> proxyUuid) {
static const auto& libMap = mConfig.getLibraryMap();
@ -246,8 +246,7 @@ void Factory::createIdentityWithConfig(const EffectConfig::LibraryUuid& configLi
void Factory::loadEffectLibs() {
const auto& configEffectsMap = mConfig.getEffectsMap();
for (const auto& configEffects : configEffectsMap) {
if (AudioUuid uuid;
EffectConfig::findUuid(configEffects.first /* xml effect name */, &uuid)) {
if (AudioUuid type; EffectConfig::findUuid(configEffects /* xml effect */, &type)) {
const auto& configLibs = configEffects.second;
std::optional<AudioUuid> proxyUuid;
if (configLibs.proxyLibrary.has_value()) {
@ -255,7 +254,7 @@ void Factory::loadEffectLibs() {
proxyUuid = proxyLib.uuid;
}
for (const auto& configLib : configLibs.libraries) {
createIdentityWithConfig(configLib, uuid, proxyUuid);
createIdentityWithConfig(configLib, type, proxyUuid);
}
} else {
LOG(ERROR) << __func__ << ": can not find type UUID for effect " << configEffects.first

View file

@ -50,7 +50,8 @@
</libraries>
<!-- list of effects to load.
Each "effect" element must contain a "name", "library" and a "uuid" attribute.
Each "effect" element must contain a "name", "library" and a "uuid" attribute, an optional
"type" attribute can be used to add any customized effect type.
The value of the "library" attribute must correspond to the name of one library element in
the "libraries" element.
The "name" attribute used to specific effect type, and should be mapping to a key of
@ -62,8 +63,8 @@
result of IFactory.queryEffects() to decide which effect implementation should be part of
proxy and which not.
Only "name", "library", and "uuid" attributes in "effects" element are meaningful and
parsed out by EffectConfig class, all other attributes are ignored.
Only "name", "library", "uuid", and "type" attributes in "effects" element are meaningful
and parsed out by EffectConfig class, all other attributes are ignored.
Only "name" and "uuid" attributes in "effectProxy" element are meaningful and parsed out
by EffectConfig class, all other attributes are ignored.
-->
@ -94,7 +95,7 @@
<libsw library="equalizersw" uuid="0bed4300-847d-11df-bb17-0002a5d5c51b"/>
<libsw library="bundle" uuid="ce772f20-847d-11df-bb17-0002a5d5c51b"/>
</effectProxy>
<effect name="extensioneffect" library="extensioneffect" uuid="fa81dd00-588b-11ed-9b6a-0242ac120002"/>
<effect name="extension_effect" library="extensioneffect" uuid="fa81dd00-588b-11ed-9b6a-0242ac120002" type="fa81de0e-588b-11ed-9b6a-0242ac120002"/>
<effect name="acoustic_echo_canceler" library="aecsw" uuid="bb392ec0-8d4d-11e0-a896-0002a5d5c51b"/>
<effect name="noise_suppression" library="nssw" uuid="c06c8400-8e06-11e0-9cb6-0002a5d5c51b"/>
</effects>

View file

@ -40,14 +40,15 @@ class EffectConfig {
public:
explicit EffectConfig(const std::string& file);
struct LibraryUuid {
struct Library {
std::string name; // library name
::aidl::android::media::audio::common::AudioUuid uuid;
::aidl::android::media::audio::common::AudioUuid uuid; // implementation UUID
std::optional<::aidl::android::media::audio::common::AudioUuid> type; // optional type UUID
};
// <effects>
struct EffectLibraries {
std::optional<struct LibraryUuid> proxyLibrary;
std::vector<struct LibraryUuid> libraries;
std::optional<struct Library> proxyLibrary;
std::vector<struct Library> libraries;
};
int getSkippedElements() const { return mSkippedElements; }
@ -56,7 +57,7 @@ class EffectConfig {
return mEffectsMap;
}
static bool findUuid(const std::string& xmlEffectName,
static bool findUuid(const std::pair<std::string, struct EffectLibraries>& effectElem,
::aidl::android::media::audio::common::AudioUuid* uuid);
using ProcessingLibrariesMap = std::map<Processing::Type, std::vector<struct EffectLibraries>>;
@ -96,8 +97,8 @@ class EffectConfig {
bool parseProcessing(Processing::Type::Tag typeTag, const tinyxml2::XMLElement& xml);
// Function to parse effect.library name and effect.uuid from xml
bool parseLibraryUuid(const tinyxml2::XMLElement& xml, struct LibraryUuid& libraryUuid,
bool isProxy = false);
bool parseLibrary(const tinyxml2::XMLElement& xml, struct Library& library,
bool isProxy = false);
const char* dump(const tinyxml2::XMLElement& element,
tinyxml2::XMLPrinter&& printer = {}) const;

View file

@ -104,7 +104,7 @@ class Factory : public BnFactory {
bool openEffectLibrary(const ::aidl::android::media::audio::common::AudioUuid& impl,
const std::string& path);
void createIdentityWithConfig(
const EffectConfig::LibraryUuid& configLib,
const EffectConfig::Library& configLib,
const ::aidl::android::media::audio::common::AudioUuid& typeUuidStr,
const std::optional<::aidl::android::media::audio::common::AudioUuid> proxyUuid);