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

Commit bce6f6c5 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge changes Ia6e2c4f0,I5351b5bd

* changes:
  audio effect: fix registration of default device effects
  audio effect: allow to manage chain of device effects (sw or hw)
parents 43615ef6 163ce833
Loading
Loading
Loading
Loading
+49 −17
Original line number Diff line number Diff line
@@ -40,18 +40,22 @@ void AudioFlinger::DeviceEffectManager::onCreateAudioPatch(audio_patch_handle_t
            __func__, handle, patch.mHalHandle,
            patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0);
    Mutex::Autolock _l(mLock);
    for (auto& effect : mDeviceEffects) {
        status_t status = effect.second->onCreatePatch(handle, &patch); // TODO(b/288339104) void*
    for (auto& effectProxies : mDeviceEffects) {
        for (auto& effect : effectProxies.second) {
            status_t status = effect->onCreatePatch(handle, &patch); // TODO(b/288339104) void*
            ALOGV("%s Effect onCreatePatch status %d", __func__, status);
            ALOGW_IF(status == BAD_VALUE, "%s onCreatePatch error %d", __func__, status);
        }
    }
}

void AudioFlinger::DeviceEffectManager::onReleaseAudioPatch(audio_patch_handle_t handle) {
    ALOGV("%s", __func__);
    Mutex::Autolock _l(mLock);
    for (auto& effect : mDeviceEffects) {
        effect.second->onReleasePatch(handle);
    for (auto& effectProxies : mDeviceEffects) {
        for (auto& effect : effectProxies.second) {
            effect->onReleasePatch(handle);
        }
    }
}

@@ -61,12 +65,15 @@ void AudioFlinger::DeviceEffectManager::onUpdateAudioPatch(audio_patch_handle_t
            __func__, oldHandle, newHandle, patch.mHalHandle,
            patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0);
    Mutex::Autolock _l(mLock);
    for (auto& effect : mDeviceEffects) {
    for (auto& effectProxies : mDeviceEffects) {
        for (auto& effect : effectProxies.second) {
            // TODO(b/288339104) void*
        status_t status = effect.second->onUpdatePatch(oldHandle, newHandle, &patch);
            status_t status = effect->onUpdatePatch(oldHandle, newHandle, &patch);
            ALOGV("%s Effect onUpdatePatch status %d", __func__, status);
            ALOGW_IF(status != NO_ERROR, "%s onUpdatePatch error %d", __func__, status);
        }
    }
}

// DeviceEffectManager::createEffect_l() must be called with AudioFlinger::mLock held
sp<IAfEffectHandle> AudioFlinger::DeviceEffectManager::createEffect_l(
@@ -80,6 +87,7 @@ sp<IAfEffectHandle> AudioFlinger::DeviceEffectManager::createEffect_l(
        bool probe,
        bool notifyFramesProcessed) {
    sp<IAfDeviceEffectProxy> effect;
    std::vector<sp<IAfDeviceEffectProxy>> effectsForDevice = {};
    sp<IAfEffectHandle> handle;
    status_t lStatus;

@@ -93,11 +101,20 @@ sp<IAfEffectHandle> AudioFlinger::DeviceEffectManager::createEffect_l(
        Mutex::Autolock _l(mLock);
        auto iter = mDeviceEffects.find(device);
        if (iter != mDeviceEffects.end()) {
            effect = iter->second;
        } else {
            effectsForDevice = iter->second;
            for (const auto& iterEffect : effectsForDevice) {
                if (memcmp(&iterEffect->desc().uuid, &descriptor->uuid, sizeof(effect_uuid_t)) ==
                    0) {
                    effect = iterEffect;
                    break;
                }
            }
        }
        if (effect == nullptr) {
            effect = IAfDeviceEffectProxy::create(device, mMyCallback,
                    descriptor, mAudioFlinger.nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT),
                    notifyFramesProcessed);
            effectsForDevice.push_back(effect);
        }
        // create effect handle and connect it to effect module
        handle = IAfEffectHandle::create(
@@ -111,7 +128,8 @@ sp<IAfEffectHandle> AudioFlinger::DeviceEffectManager::createEffect_l(
                    lStatus = NO_ERROR;
                }
                if (lStatus == NO_ERROR || lStatus == ALREADY_EXISTS) {
                    mDeviceEffects.emplace(device, effect);
                    mDeviceEffects.erase(device);
                    mDeviceEffects.emplace(device, effectsForDevice);
                }
            }
        }
@@ -177,8 +195,10 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock
        String8 outStr;
        outStr.appendFormat("%*sEffect for device %s address %s:\n", 2, "",
                ::android::toString(iter.first.mType).c_str(), iter.first.getAddress());
        for (const auto& effect : iter.second) {
            write(fd, outStr.string(), outStr.size());
        iter.second->dump2(fd, 4);
            effect->dump2(fd, 4);
        }
    }

    if (locked) {
@@ -186,11 +206,23 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock
    }
}


size_t AudioFlinger::DeviceEffectManager::removeEffect(const sp<IAfDeviceEffectProxy>& effect)
{
    Mutex::Autolock _l(mLock);
    const auto& iter = mDeviceEffects.find(effect->device());
    if (iter != mDeviceEffects.end()) {
        const auto& iterEffect = std::find_if(
                iter->second.begin(), iter->second.end(), [&effect](const auto& effectProxy) {
                    return memcmp(&effectProxy->desc().uuid, &effect->desc().uuid,
                            sizeof(effect_uuid_t)) == 0;
                });
        if (iterEffect != iter->second.end()) {
            iter->second.erase(iterEffect);
            if (iter->second.empty()) {
                mDeviceEffects.erase(effect->device());
            }
        }
    }
    return mDeviceEffects.size();
}

+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ private:
    Mutex mLock;
    AudioFlinger &mAudioFlinger;
    const sp<DeviceEffectManagerCallback> mMyCallback;
    std::map<AudioDeviceTypeAddr, sp<IAfDeviceEffectProxy>> mDeviceEffects;
    std::map<AudioDeviceTypeAddr, std::vector<sp<IAfDeviceEffectProxy>>> mDeviceEffects;
};

public: // TODO(b/288339104) extract inner class.
+6 −5
Original line number Diff line number Diff line
@@ -512,11 +512,12 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock
    if (!locked) {
        result.append("\t\tCould not lock Fx mutex:\n");
    }

    result.append("\t\tSession State Registered Enabled Suspended:\n");
    result.appendFormat("\t\t%05d   %03d   %s          %s       %s\n",
            mSessionId, mState, mPolicyRegistered ? "y" : "n",
            mPolicyEnabled ? "y" : "n", mSuspended ? "y" : "n");
    bool isInternal = isInternal_l();
    result.append("\t\tSession State Registered Internal Enabled Suspended:\n");
    result.appendFormat("\t\t%05d   %03d   %s          %s        %s       %s\n",
            mSessionId, mState, mPolicyRegistered ? "y" : "n", isInternal ? "y" : "n",
            ((isInternal && isEnabled()) || (!isInternal && mPolicyEnabled)) ? "y" : "n",
            mSuspended ? "y" : "n");

    result.append("\t\tDescriptor:\n");
    char uuidStr[64];
+6 −4
Original line number Diff line number Diff line
@@ -44,10 +44,7 @@ using content::AttributionSourceState;
AudioPolicyEffects::AudioPolicyEffects(const sp<EffectsFactoryHalInterface>& effectsFactoryHal) {
    // load xml config with effectsFactoryHal
    status_t loadResult = loadAudioEffectConfig(effectsFactoryHal);
    if (loadResult == NO_ERROR) {
        mDefaultDeviceEffectFuture =
                std::async(std::launch::async, &AudioPolicyEffects::initDefaultDeviceEffects, this);
    } else if (loadResult < 0) {
    if (loadResult < 0) {
        ALOGW("Failed to query effect configuration, fallback to load .conf");
        // load automatic audio effect modules
        if (access(AUDIO_EFFECT_VENDOR_CONFIG_FILE, R_OK) == 0) {
@@ -60,6 +57,11 @@ AudioPolicyEffects::AudioPolicyEffects(const sp<EffectsFactoryHalInterface>& eff
    }
}

void AudioPolicyEffects::setDefaultDeviceEffects() {
    mDefaultDeviceEffectFuture = std::async(
                std::launch::async, &AudioPolicyEffects::initDefaultDeviceEffects, this);
}

AudioPolicyEffects::~AudioPolicyEffects()
{
    size_t i = 0;
+2 −0
Original line number Diff line number Diff line
@@ -117,6 +117,8 @@ public:
    // Remove the default stream effect from wherever it's attached.
    status_t removeStreamDefaultEffect(audio_unique_id_t id);

    void setDefaultDeviceEffects();

private:
    void initDefaultDeviceEffects();

Loading