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

Commit b82e6b72 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioFlinger: implement device specific audio effects

Add management of audio effects applied to a specific input
or output audio device.

A new class DeviceEffectProxy derived from Effectbase is added
to represent an effect attached to a particular audio device type and
address. This proxy manages one or more actual EffectModule instances
automatically added to a playback or capture thread or directly to the
audio HAL when the targeted audio device is used by an audio patch.

A new DeviceEffectManager class is added to manage creation and release
of DeviceEffectProxy instances and monitor creation and release of audio
patches and create or release actual effect instances accordingly.

Bug: 136294538
Test: make

Change-Id: I23b9f9db4459136039c5ee327cf3b1aefa7db5af
parent 9ce5404e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -26,6 +26,16 @@ bool AudioDeviceTypeAddr::equals(const AudioDeviceTypeAddr& other) const {
    return mType == other.mType && mAddress == other.mAddress;
}

bool AudioDeviceTypeAddr::operator<(const AudioDeviceTypeAddr& other) const {
    if (mType < other.mType)  return true;
    if (mType > other.mType)  return false;

    if (mAddress < other.mAddress)  return true;
    // if (mAddress > other.mAddress)  return false;

    return false;
}

void AudioDeviceTypeAddr::reset() {
    mType = AUDIO_DEVICE_NONE;
    mAddress = "";
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ struct AudioDeviceTypeAddr : public Parcelable {

    AudioDeviceTypeAddr& operator= (const AudioDeviceTypeAddr&) = default;

    bool operator<(const AudioDeviceTypeAddr& other) const;

    void reset();

    status_t readFromParcel(const Parcel *parcel) override;
+33 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <common/all-versions/VersionUtils.h>

#include "DeviceHalHidl.h"
#include "EffectHalHidl.h"
#include "HidlUtils.h"
#include "StreamHalHidl.h"
#include "VersionUtils.h"
@@ -43,6 +44,8 @@ namespace CPP_VERSION {
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;

using EffectHalHidl = ::android::effect::CPP_VERSION::EffectHalHidl;

namespace {

status_t deviceAddressFromHal(
@@ -417,6 +420,36 @@ status_t DeviceHalHidl::getMicrophones(std::vector<media::MicrophoneInfo> *micro
}
#endif

#if MAJOR_VERSION >= 6
status_t DeviceHalHidl::addDeviceEffect(
        audio_port_handle_t device, sp<EffectHalInterface> effect) {
    if (mDevice == 0) return NO_INIT;
    return processReturn("addDeviceEffect", mDevice->addDeviceEffect(
            static_cast<AudioPortHandle>(device),
            static_cast<EffectHalHidl*>(effect.get())->effectId()));
}
#else
status_t DeviceHalHidl::addDeviceEffect(
        audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
    return INVALID_OPERATION;
}
#endif

#if MAJOR_VERSION >= 6
status_t DeviceHalHidl::removeDeviceEffect(
        audio_port_handle_t device, sp<EffectHalInterface> effect) {
    if (mDevice == 0) return NO_INIT;
    return processReturn("removeDeviceEffect", mDevice->removeDeviceEffect(
            static_cast<AudioPortHandle>(device),
            static_cast<EffectHalHidl*>(effect.get())->effectId()));
}
#else
status_t DeviceHalHidl::removeDeviceEffect(
        audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
    return INVALID_OPERATION;
}
#endif

status_t DeviceHalHidl::dump(int fd) {
    if (mDevice == 0) return NO_INIT;
    native_handle_t* hidlHandle = native_handle_create(1, 0);
+3 −0
Original line number Diff line number Diff line
@@ -113,6 +113,9 @@ class DeviceHalHidl : public DeviceHalInterface, public ConversionHelperHidl
    // List microphones
    virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones);

    status_t addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override;
    status_t removeDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override;

    virtual status_t dump(int fd);

  private:
+11 −0
Original line number Diff line number Diff line
@@ -206,6 +206,17 @@ status_t DeviceHalLocal::getMicrophones(std::vector<media::MicrophoneInfo> *micr
}
#endif

// Local HAL implementation does not support effects
status_t DeviceHalLocal::addDeviceEffect(
        audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
    return INVALID_OPERATION;
}

status_t DeviceHalLocal::removeDeviceEffect(
        audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
    return INVALID_OPERATION;
}

status_t DeviceHalLocal::dump(int fd) {
    return mDev->dump(mDev, fd);
}
Loading