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

Commit 7eb61b87 authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Put orphan effect chain back if orphan effect creation failed

Bug: 309578734
Test: atest CtsMediaAudioTestCases
Test: atest audioeffect_tests
Change-Id: I9b6d6c350106b233d3ea856bfa4df81ce35a54ec
parent 29d10579
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -4417,6 +4417,10 @@ sp<IAfEffectHandle> AudioFlinger::createOrphanEffect_l(
                chain->createEffect(effect, desc, effectId, sessionId, pinned);
        if (llStatus != NO_ERROR) {
            *status = llStatus;
            // if the effect chain was not created here, put it back
            if (!chainCreated) {
                putOrphanEffectChain_l(chain);
            }
            return nullptr;
        }
        effect->setMode(getMode());
@@ -4441,18 +4445,21 @@ sp<IAfEffectHandle> AudioFlinger::createOrphanEffect_l(
    if (lStatus == OK) {
        lStatus = effect->addHandle(handle.get());
    }
    // in case of lStatus error, EffectHandle will still return and caller should do the clear
    if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) {
        if (effectCreated) {
            chain->removeEffect(effect);
        }
        // if the effect chain was not created here, put it back
        if (!chainCreated) {
            putOrphanEffectChain_l(chain);
        }
    } else {
        if (enabled != NULL) {
            *enabled = (int)effect->isEnabled();
        }
        if (chainCreated) {
        putOrphanEffectChain_l(chain);
    }
    }
    *status = lStatus;
    return handle;
}