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

Commit 62dbe93f authored by Eric Laurent's avatar Eric Laurent Committed by Android Git Automerger
Browse files

am 4e141a4f: am 1802399c: Merge "fix deadlock in audioflinger::createEffect()" into klp-dev

* commit '4e141a4f':
  fix deadlock in audioflinger::createEffect()
parents 34a8e85c 4e141a4f
Loading
Loading
Loading
Loading
+18 −21
Original line number Diff line number Diff line
@@ -2104,9 +2104,6 @@ sp<IEffect> AudioFlinger::createEffect(
    }

    {
        Mutex::Autolock _l(mLock);


        if (!EffectIsNullUuid(&pDesc->uuid)) {
            // if uuid is specified, request effect descriptor
            lStatus = EffectGetDescriptor(&pDesc->uuid, &desc);
@@ -2179,6 +2176,15 @@ sp<IEffect> AudioFlinger::createEffect(

        // return effect descriptor
        *pDesc = desc;
        if (io == 0 && sessionId == AUDIO_SESSION_OUTPUT_MIX) {
            // if the output returned by getOutputForEffect() is removed before we lock the
            // mutex below, the call to checkPlaybackThread_l(io) below will detect it
            // and we will exit safely
            io = AudioSystem::getOutputForEffect(&desc);
            ALOGV("createEffect got output %d", io);
        }

        Mutex::Autolock _l(mLock);

        // If output is not specified try to find a matching audio session ID in one of the
        // output threads.
@@ -2192,14 +2198,6 @@ sp<IEffect> AudioFlinger::createEffect(
                lStatus = BAD_VALUE;
                goto Exit;
            }
            if (sessionId == AUDIO_SESSION_OUTPUT_MIX) {
                // if the output returned by getOutputForEffect() is removed before we lock the
                // mutex below, the call to checkPlaybackThread_l(io) below will detect it
                // and we will exit safely
                io = AudioSystem::getOutputForEffect(&desc);
                ALOGV("createEffect got output %d", io);
            }
            if (io == 0) {
            // look for the thread where the specified audio session is present
            for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
                if (mPlaybackThreads.valueAt(i)->hasAudioSession(sessionId) != 0) {
@@ -2215,7 +2213,6 @@ sp<IEffect> AudioFlinger::createEffect(
                    }
                }
            }
            }
            // If no output thread contains the requested session ID, default to
            // first output. The effect chain will be moved to the correct output
            // thread when a track with the same session ID is created
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@
// state changes or resource modifications. Always respect the following order
// if multiple mutexes must be acquired to avoid cross deadlock:
// AudioFlinger -> ThreadBase -> EffectChain -> EffectModule
// In addition, methods that lock the AudioPolicyService mutex (getOutputForEffect(),
// startOutput()...) should never be called with AudioFlinger or Threadbase mutex locked
// to avoid cross deadlock with other clients calling AudioPolicyService methods that in turn
// call AudioFlinger thus locking the same mutexes in the reverse order.

// The EffectModule class is a wrapper object controlling the effect engine implementation
// in the effect library. It prevents concurrent calls to process() and command() functions