Merge "Effect AIDL: remove the shared_lib dependency for example binary"

This commit is contained in:
Shunkai Yao
2023-02-02 04:50:07 +00:00
committed by Gerrit Code Review
19 changed files with 48 additions and 25 deletions

View File

@@ -152,23 +152,7 @@ cc_binary {
vintf_fragments: ["android.hardware.audio.effect.service-aidl.xml"],
defaults: ["aidlaudioeffectservice_defaults"],
shared_libs: [
"libaecsw",
"libagcsw",
"libbassboostsw",
"libbundleaidl",
"libdownmixaidl",
"libdynamicsprocessingaidl",
"libenvreverbsw",
"libequalizersw",
"libhapticgeneratoraidl",
"libloudnessenhanceraidl",
"libnssw",
"libpresetreverbsw",
"libreverbaidl",
"libtinyxml2",
"libvirtualizersw",
"libvisualizeraidl",
"libvolumesw",
],
srcs: [
"EffectConfig.cpp",

View File

@@ -79,14 +79,30 @@ std::vector<std::reference_wrapper<const tinyxml2::XMLElement>> EffectConfig::ge
return children;
}
bool EffectConfig::resolveLibrary(const std::string& path, std::string* resolvedPath) {
for (auto* libraryDirectory : kEffectLibPath) {
std::string candidatePath = std::string(libraryDirectory) + '/' + path;
if (access(candidatePath.c_str(), R_OK) == 0) {
*resolvedPath = std::move(candidatePath);
return true;
}
}
return false;
}
bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml) {
const char* name = xml.Attribute("name");
RETURN_VALUE_IF(!name, false, "noNameAttribute");
const char* path = xml.Attribute("path");
RETURN_VALUE_IF(!path, false, "noPathAttribute");
mLibraryMap[name] = path;
LOG(DEBUG) << __func__ << " " << name << " : " << path;
std::string resolvedPath;
if (!resolveLibrary(path, &resolvedPath)) {
LOG(ERROR) << __func__ << " can't find " << path;
return false;
}
mLibraryMap[name] = resolvedPath;
LOG(DEBUG) << __func__ << " " << name << " : " << resolvedPath;
return true;
}

View File

@@ -165,7 +165,7 @@ ndk::ScopedAStatus Factory::destroyEffect(const std::shared_ptr<IEffect>& in_han
return status;
}
bool Factory::openEffectLibrary(const AudioUuid& impl, const std::string& libName) {
bool Factory::openEffectLibrary(const AudioUuid& impl, const std::string& path) {
std::function<void(void*)> dlClose = [](void* handle) -> void {
if (handle && dlclose(handle)) {
LOG(ERROR) << "dlclose failed " << dlerror();
@@ -173,19 +173,19 @@ bool Factory::openEffectLibrary(const AudioUuid& impl, const std::string& libNam
};
auto libHandle =
std::unique_ptr<void, decltype(dlClose)>{dlopen(libName.c_str(), RTLD_LAZY), dlClose};
std::unique_ptr<void, decltype(dlClose)>{dlopen(path.c_str(), RTLD_LAZY), dlClose};
if (!libHandle) {
LOG(ERROR) << __func__ << ": dlopen failed, err: " << dlerror();
return false;
}
LOG(INFO) << __func__ << " dlopen lib:" << libName << "\nimpl:" << impl.toString()
LOG(INFO) << __func__ << " dlopen lib:" << path << "\nimpl:" << impl.toString()
<< "\nhandle:" << libHandle;
auto interface = new effect_dl_interface_s{nullptr, nullptr, nullptr};
mEffectLibMap.insert(
{impl,
std::make_tuple(std::move(libHandle),
std::unique_ptr<struct effect_dl_interface_s>(interface), libName)});
std::unique_ptr<struct effect_dl_interface_s>(interface), path)});
return true;
}
@@ -199,8 +199,8 @@ void Factory::createIdentityWithConfig(const EffectConfig::LibraryUuid& configLi
id.type = typeUuid;
id.uuid = configLib.uuid;
id.proxy = proxyUuid;
LOG(DEBUG) << __func__ << ": typeUuid " << id.type.toString() << "\nimplUuid "
<< id.uuid.toString() << " proxyUuid "
LOG(DEBUG) << __func__ << " loading lib " << path->second << ": typeUuid "
<< id.type.toString() << "\nimplUuid " << id.uuid.toString() << " proxyUuid "
<< (proxyUuid.has_value() ? proxyUuid->toString() : "null");
if (openEffectLibrary(id.uuid, path->second)) {
mIdentitySet.insert(std::move(id));

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"AcousticEchoCancelerSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"AutomaticGainControlSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"BassBoostSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"DownmixSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"DynamicsProcessingSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"EnvReverbSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"EqualizerSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"HapticGeneratorSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -63,6 +63,13 @@ class EffectConfig {
}
private:
static constexpr const char* kEffectLibPath[] =
#ifdef __LP64__
{"/odm/lib64/soundfx", "/vendor/lib64/soundfx", "/system/lib64/soundfx"};
#else
{"/odm/lib/soundfx", "/vendor/lib/soundfx", "/system/lib/soundfx"};
#endif
int mSkippedElements;
/* Parsed Libraries result */
std::unordered_map<std::string, std::string> mLibraryMap;
@@ -91,6 +98,8 @@ class EffectConfig {
const char* dump(const tinyxml2::XMLElement& element,
tinyxml2::XMLPrinter&& printer = {}) const;
bool resolveLibrary(const std::string& path, std::string* resolvedPath);
};
} // namespace aidl::android::hardware::audio::effect

View File

@@ -102,7 +102,7 @@ class Factory : public BnFactory {
ndk::ScopedAStatus destroyEffectImpl(const std::shared_ptr<IEffect>& in_handle);
void cleanupEffectMap();
bool openEffectLibrary(const ::aidl::android::media::audio::common::AudioUuid& impl,
const std::string& libName);
const std::string& path);
void createIdentityWithConfig(
const EffectConfig::LibraryUuid& configLib,
const ::aidl::android::media::audio::common::AudioUuid& typeUuid,

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"LoudnessEnhancerSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"NoiseSuppressionSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"PresetReverbSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"VirtualizerSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"VisualizerSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],

View File

@@ -34,6 +34,7 @@ cc_library_shared {
"VolumeSw.cpp",
":effectCommonFile",
],
relative_install_path: "soundfx",
visibility: [
"//hardware/interfaces/audio/aidl/default",
],