From ed095e62ab24ef68761cc4f1a797fce0095ef040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gaffie?= Date: Thu, 30 May 2024 13:50:50 +0200 Subject: [PATCH] Restore Default Device Effects support with AIDL AudioHAL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 329395147 Test: atest CtsMediaAudioTestCases Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit Change-Id: I0f4f680b4db4eaa69d6c6e9e7b897631ed94928b Signed-off-by: François Gaffie --- .../hardware/audio/effect/Processing.aidl | 1 + .../hardware/audio/effect/Processing.aidl | 2 ++ audio/aidl/default/Android.bp | 2 ++ audio/aidl/default/EffectConfig.cpp | 35 +++++++++++++++++-- audio/aidl/default/audio_effects_config.xml | 33 +++++++++++++++++ .../include/effectFactory-impl/EffectConfig.h | 5 +-- 6 files changed, 74 insertions(+), 4 deletions(-) diff --git a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Processing.aidl b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Processing.aidl index f6d6ee25bf..96d57d8b2f 100644 --- a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Processing.aidl +++ b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Processing.aidl @@ -40,5 +40,6 @@ parcelable Processing { union Type { android.media.audio.common.AudioStreamType streamType = android.media.audio.common.AudioStreamType.INVALID; android.media.audio.common.AudioSource source; + android.media.audio.common.AudioDevice device; } } diff --git a/audio/aidl/android/hardware/audio/effect/Processing.aidl b/audio/aidl/android/hardware/audio/effect/Processing.aidl index cb773501fe..928ce16584 100644 --- a/audio/aidl/android/hardware/audio/effect/Processing.aidl +++ b/audio/aidl/android/hardware/audio/effect/Processing.aidl @@ -17,6 +17,7 @@ package android.hardware.audio.effect; import android.hardware.audio.effect.Descriptor; +import android.media.audio.common.AudioDevice; import android.media.audio.common.AudioSource; import android.media.audio.common.AudioStreamType; import android.media.audio.common.AudioUuid; @@ -30,6 +31,7 @@ parcelable Processing { union Type { AudioStreamType streamType = AudioStreamType.INVALID; AudioSource source; + AudioDevice device; } /** diff --git a/audio/aidl/default/Android.bp b/audio/aidl/default/Android.bp index 844f1e9c09..f5b590bc36 100644 --- a/audio/aidl/default/Android.bp +++ b/audio/aidl/default/Android.bp @@ -203,6 +203,7 @@ cc_defaults { ], vendor: true, shared_libs: [ + "libaudio_aidl_conversion_common_ndk", "libaudioaidlcommon", "libaudioutils", "libbase", @@ -224,6 +225,7 @@ cc_defaults { "-Wextra", "-Werror", "-Wthread-safety", + "-DBACKEND_NDK", ], } diff --git a/audio/aidl/default/EffectConfig.cpp b/audio/aidl/default/EffectConfig.cpp index eb0c0150e1..9c335babac 100644 --- a/audio/aidl/default/EffectConfig.cpp +++ b/audio/aidl/default/EffectConfig.cpp @@ -18,6 +18,8 @@ #include #define LOG_TAG "AHAL_EffectConfig" #include +#include +#include #include #include #include @@ -28,6 +30,10 @@ #include #endif +using aidl::android::media::audio::common::AudioDevice; +using aidl::android::media::audio::common::AudioDeviceAddress; +using aidl::android::media::audio::common::AudioDeviceDescription; +using aidl::android::media::audio::common::AudioDeviceType; using aidl::android::media::audio::common::AudioSource; using aidl::android::media::audio::common::AudioStreamType; using aidl::android::media::audio::common::AudioUuid; @@ -76,6 +82,14 @@ EffectConfig::EffectConfig(const std::string& file) { registerFailure(parseProcessing(Processing::Type::streamType, xmlStream)); } } + + // Parse device effect chains + for (auto& xmlDeviceEffects : getChildren(xmlConfig, "deviceEffects")) { + for (auto& xmlDevice : getChildren(xmlDeviceEffects, "device")) { + // AudioDevice + registerFailure(parseProcessing(Processing::Type::device, xmlDevice)); + } + } } LOG(DEBUG) << __func__ << " successfully parsed " << file << ", skipping " << mSkippedElements << " element(s)"; @@ -195,7 +209,8 @@ bool EffectConfig::parseLibrary(const tinyxml2::XMLElement& xml, struct Library& } std::optional EffectConfig::stringToProcessingType(Processing::Type::Tag typeTag, - const std::string& type) { + const std::string& type, + const std::string& address) { // see list of audio stream types in audio_stream_type_t: // system/media/audio/include/system/audio_effects/audio_effects_conf.h // AUDIO_STREAM_DEFAULT_TAG is not listed here because according to SYS_RESERVED_DEFAULT in @@ -238,6 +253,19 @@ std::optional EffectConfig::stringToProcessingType(Processing: if (typeIter != sAudioSourceTable.end()) { return typeIter->second; } + } else if (typeTag == Processing::Type::device) { + audio_devices_t deviceType; + if (!audio_device_from_string(type.c_str(), &deviceType)) { + LOG(ERROR) << __func__ << "DeviceEffect: invalid type " << type; + return std::nullopt; + } + auto ret = ::aidl::android::legacy2aidl_audio_device_AudioDevice(deviceType, address); + if (!ret.ok()) { + LOG(ERROR) << __func__ << "DeviceEffect: Failed to get AudioDevice from type " + << deviceType << ", address " << address; + return std::nullopt; + } + return ret.value(); } return std::nullopt; @@ -246,7 +274,10 @@ std::optional EffectConfig::stringToProcessingType(Processing: bool EffectConfig::parseProcessing(Processing::Type::Tag typeTag, const tinyxml2::XMLElement& xml) { LOG(VERBOSE) << __func__ << dump(xml); const char* typeStr = xml.Attribute("type"); - auto aidlType = stringToProcessingType(typeTag, typeStr); + const char* addressStr = xml.Attribute("address"); + // For device effect, device address is optional, match will be done for the given device type + // with empty address. + auto aidlType = stringToProcessingType(typeTag, typeStr, addressStr ? addressStr : ""); RETURN_VALUE_IF(!aidlType.has_value(), false, "illegalStreamType"); RETURN_VALUE_IF(0 != mProcessingMap.count(aidlType.value()), false, "duplicateStreamType"); diff --git a/audio/aidl/default/audio_effects_config.xml b/audio/aidl/default/audio_effects_config.xml index 11683d21ee..a54f4db7e6 100644 --- a/audio/aidl/default/audio_effects_config.xml +++ b/audio/aidl/default/audio_effects_config.xml @@ -140,4 +140,37 @@ --> + + diff --git a/audio/aidl/default/include/effectFactory-impl/EffectConfig.h b/audio/aidl/default/include/effectFactory-impl/EffectConfig.h index 7456b99999..60bb9be96f 100644 --- a/audio/aidl/default/include/effectFactory-impl/EffectConfig.h +++ b/audio/aidl/default/include/effectFactory-impl/EffectConfig.h @@ -81,7 +81,7 @@ class EffectConfig { /* Parsed Effects result */ std::unordered_map mEffectsMap; /** - * For parsed pre/post processing result: {key: AudioStreamType/AudioSource, value: + * For parsed pre/post processing result: {key: AudioStreamType/AudioSource/AudioDevice, value: * EffectLibraries} */ ProcessingLibrariesMap mProcessingMap; @@ -110,7 +110,8 @@ class EffectConfig { bool resolveLibrary(const std::string& path, std::string* resolvedPath); std::optional stringToProcessingType(Processing::Type::Tag typeTag, - const std::string& type); + const std::string& type, + const std::string& address); }; } // namespace aidl::android::hardware::audio::effect