From 2c75ca6b27efa3f1c0baf29c58857caf0bd462ce Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 6 Dec 2019 17:56:32 -0800 Subject: [PATCH] Audio HAL: Add API to attach an effect to a device Add a method to IDevice interface allowing the attachement of an audio effect to an audio device. This is used when an audio effect is implemented below the HAL (e.g by an audio DSP) and is attached/enabled when a particular sink(e.g speaker) or source(e.g mic) device is selected. Bug: 136294538 Test: make Change-Id: I73d78c4f234fd80443a1cb3772c2d65457968652 Merged-In: I73d78c4f234fd80443a1cb3772c2d65457968652 --- audio/6.0/IDevice.hal | 24 +++++++++++++ audio/core/all-versions/default/Device.cpp | 35 +++++++++++++++++++ .../all-versions/default/PrimaryDevice.cpp | 8 +++++ .../default/include/core/default/Device.h | 3 +- .../include/core/default/PrimaryDevice.h | 2 ++ current.txt | 2 +- 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/audio/6.0/IDevice.hal b/audio/6.0/IDevice.hal index 122c550ee7..2347696035 100644 --- a/audio/6.0/IDevice.hal +++ b/audio/6.0/IDevice.hal @@ -295,4 +295,28 @@ interface IDevice { */ @exit close() generates (Result retval); + + /** + * Applies an audio effect to an audio device. + * + * @param device identifies the sink or source device this effect must be applied to. + * "device" is the AudioPortHandle indicated for the device when the audio + * patch connecting that device was created. + * @param effectId effect ID (obtained from IEffectsFactory.createEffect) of + * the effect to add. + * @return retval operation completion status. + */ + addDeviceEffect(AudioPortHandle device, uint64_t effectId) generates (Result retval); + + /** + * Stops applying an audio effect to an audio device. + * + * @param device identifies the sink or source device this effect was applied to. + * "device" is the AudioPortHandle indicated for the device when the audio + * patch is created at the audio HAL. + * @param effectId effect ID (obtained from IEffectsFactory.createEffect) of + * the effect. + * @return retval operation completion status. + */ + removeDeviceEffect(AudioPortHandle device, uint64_t effectId) generates (Result retval); }; diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp index c6c9464656..ad841caf2e 100644 --- a/audio/core/all-versions/default/Device.cpp +++ b/audio/core/all-versions/default/Device.cpp @@ -18,6 +18,7 @@ #include "core/default/Device.h" #include +#include "common/all-versions/default/EffectMap.h" #include "core/default/Conversions.h" #include "core/default/StreamIn.h" #include "core/default/StreamOut.h" @@ -25,6 +26,7 @@ //#define LOG_NDEBUG 0 +#include #include #include #include @@ -403,6 +405,39 @@ Result Device::doClose() { Return Device::close() { return doClose(); } + +Return Device::addDeviceEffect(AudioPortHandle device, uint64_t effectId) { + if (version() < AUDIO_DEVICE_API_VERSION_3_1 || mDevice->add_device_effect == nullptr) { + return Result::NOT_SUPPORTED; + } + + effect_handle_t halEffect = EffectMap::getInstance().get(effectId); + if (halEffect != NULL) { + return analyzeStatus("add_device_effect", + mDevice->add_device_effect( + mDevice, static_cast(device), halEffect)); + } else { + ALOGW("%s Invalid effect ID passed from client: %" PRIu64 "", __func__, effectId); + return Result::INVALID_ARGUMENTS; + } +} + +Return Device::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) { + if (version() < AUDIO_DEVICE_API_VERSION_3_1 || mDevice->remove_device_effect == nullptr) { + return Result::NOT_SUPPORTED; + } + + effect_handle_t halEffect = EffectMap::getInstance().get(effectId); + if (halEffect != NULL) { + return analyzeStatus("remove_device_effect", + mDevice->remove_device_effect( + mDevice, static_cast(device), halEffect)); + } else { + ALOGW("%s Invalid effect ID passed from client: %" PRIu64 "", __func__, effectId); + return Result::INVALID_ARGUMENTS; + } +} + #endif } // namespace implementation diff --git a/audio/core/all-versions/default/PrimaryDevice.cpp b/audio/core/all-versions/default/PrimaryDevice.cpp index 3cf09320aa..0f1aba0f2f 100644 --- a/audio/core/all-versions/default/PrimaryDevice.cpp +++ b/audio/core/all-versions/default/PrimaryDevice.cpp @@ -168,6 +168,14 @@ Return PrimaryDevice::setConnectedState(const DeviceAddress& address, bo Return PrimaryDevice::close() { return mDevice->close(); } + +Return PrimaryDevice::addDeviceEffect(AudioPortHandle device, uint64_t effectId) { + return mDevice->addDeviceEffect(device, effectId); +} + +Return PrimaryDevice::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) { + return mDevice->removeDeviceEffect(device, effectId); +} #endif // Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow. diff --git a/audio/core/all-versions/default/include/core/default/Device.h b/audio/core/all-versions/default/include/core/default/Device.h index 11ab6077ab..80a9638004 100644 --- a/audio/core/all-versions/default/include/core/default/Device.h +++ b/audio/core/all-versions/default/include/core/default/Device.h @@ -116,8 +116,9 @@ struct Device : public IDevice, public ParametersUtil { #endif #if MAJOR_VERSION >= 6 Return close() override; + Return addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; + Return removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; #endif - Return debug(const hidl_handle& fd, const hidl_vec& options) override; // Utility methods for extending interfaces. diff --git a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h index f5f38482ee..9fc90c39fe 100644 --- a/audio/core/all-versions/default/include/core/default/PrimaryDevice.h +++ b/audio/core/all-versions/default/include/core/default/PrimaryDevice.h @@ -98,6 +98,8 @@ struct PrimaryDevice : public IPrimaryDevice { #endif #if MAJOR_VERSION >= 6 Return close() override; + Return addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; + Return removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; #endif Return debug(const hidl_handle& fd, const hidl_vec& options) override; diff --git a/current.txt b/current.txt index 60ee345533..c00371202e 100644 --- a/current.txt +++ b/current.txt @@ -585,7 +585,7 @@ fd65298e1e09e0e3c781ab18305920d757dbe55a3b459ce17814ec5cf6dfee99 android.hardwar # HALs released in Android R e966a3437d6a98d9d9e14e9d672088771716031900c0deb55a0946c751a03a44 android.hardware.audio@6.0::types -2736c59abaccacac407ebe80c5e48d446edf015051d05632fb679ba471779e6e android.hardware.audio@6.0::IDevice +4540d12fe1cea996f21bd1712d4ae0906dcbd58177dac494efc605b004902d43 android.hardware.audio@6.0::IDevice 2402876cbc23c0de3690a665eca84fd3857d1808dba5cad25ce272f81ecef8c9 android.hardware.audio@6.0::IDevicesFactory bca5379d5065e2e08b6ad7308ffc8a71a972fc0698bec678ea32eea786d01cb5 android.hardware.audio@6.0::IPrimaryDevice 7318b521ea12fdd4b6e3f381085c71784c810d1ec7a8d701ec2250f3f86712e4 android.hardware.audio@6.0::IStream