Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c29bf20 authored by Eric Laurent's avatar Eric Laurent
Browse files

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
parent ad84668d
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -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);
};
+35 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "core/default/Device.h"
#include <HidlUtils.h>
#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 <inttypes.h>
#include <memory.h>
#include <string.h>
#include <algorithm>
@@ -398,6 +400,39 @@ Result Device::doClose() {
Return<Result> Device::close() {
    return doClose();
}

Return<Result> 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<audio_port_handle_t>(device), halEffect));
    } else {
        ALOGW("%s Invalid effect ID passed from client: %" PRIu64 "", __func__, effectId);
        return Result::INVALID_ARGUMENTS;
    }
}

Return<Result> 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<audio_port_handle_t>(device), halEffect));
    } else {
        ALOGW("%s Invalid effect ID passed from client: %" PRIu64 "", __func__, effectId);
        return Result::INVALID_ARGUMENTS;
    }
}

#endif

}  // namespace implementation
+8 −0
Original line number Diff line number Diff line
@@ -168,6 +168,14 @@ Return<Result> PrimaryDevice::setConnectedState(const DeviceAddress& address, bo
Return<Result> PrimaryDevice::close() {
    return mDevice->close();
}

Return<Result> PrimaryDevice::addDeviceEffect(AudioPortHandle device, uint64_t effectId) {
    return mDevice->addDeviceEffect(device, effectId);
}

Return<Result> PrimaryDevice::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) {
    return mDevice->removeDeviceEffect(device, effectId);
}
#endif

// Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow.
+2 −1
Original line number Diff line number Diff line
@@ -116,8 +116,9 @@ struct Device : public IDevice, public ParametersUtil {
#endif
#if MAJOR_VERSION >= 6
    Return<Result> close() override;
    Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
    Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
#endif

    Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;

    // Utility methods for extending interfaces.
+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ struct PrimaryDevice : public IPrimaryDevice {
#endif
#if MAJOR_VERSION >= 6
    Return<Result> close() override;
    Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
    Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
#endif

    Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
Loading