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

Commit 88a6078c authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "AudioFlinger: createEffect always look for same session effect chain."

parents ef9d3a69 e778c425
Loading
Loading
Loading
Loading
+3 −22
Original line number Diff line number Diff line
@@ -3286,31 +3286,12 @@ sp<IEffect> AudioFlinger::createEffect(
                goto Exit;
            }
            // look for the thread where the specified audio session is present
            for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
                uint32_t sessionType = mPlaybackThreads.valueAt(i)->hasAudioSession(sessionId);
                if (sessionType != 0) {
                    io = mPlaybackThreads.keyAt(i);
                    // thread with same effect session is preferable
                    if ((sessionType & ThreadBase::EFFECT_SESSION) != 0) {
                        break;
                    }
                }
            }
            io = findIoHandleBySessionId_l(sessionId, mPlaybackThreads);
            if (io == AUDIO_IO_HANDLE_NONE) {
                for (size_t i = 0; i < mRecordThreads.size(); i++) {
                    if (mRecordThreads.valueAt(i)->hasAudioSession(sessionId) != 0) {
                        io = mRecordThreads.keyAt(i);
                        break;
                    }
                }
                io = findIoHandleBySessionId_l(sessionId, mRecordThreads);
            }
            if (io == AUDIO_IO_HANDLE_NONE) {
                for (size_t i = 0; i < mMmapThreads.size(); i++) {
                    if (mMmapThreads.valueAt(i)->hasAudioSession(sessionId) != 0) {
                        io = mMmapThreads.keyAt(i);
                        break;
                    }
                }
                io = findIoHandleBySessionId_l(sessionId, mMmapThreads);
            }
            // If no output thread contains the requested session ID, default to
            // first output. The effect chain will be moved to the correct output
+20 −0
Original line number Diff line number Diff line
@@ -558,6 +558,26 @@ using effect_buffer_t = int16_t;

#include "PatchPanel.h"

    // Find io handle by session id.
    // Preference is given to an io handle with a matching effect chain to session id.
    // If none found, AUDIO_IO_HANDLE_NONE is returned.
    template <typename T>
    static audio_io_handle_t findIoHandleBySessionId_l(
            audio_session_t sessionId, const T& threads) {
        audio_io_handle_t io = AUDIO_IO_HANDLE_NONE;

        for (size_t i = 0; i < threads.size(); i++) {
            const uint32_t sessionType = threads.valueAt(i)->hasAudioSession(sessionId);
            if (sessionType != 0) {
                io = threads.keyAt(i);
                if ((sessionType & AudioFlinger::ThreadBase::EFFECT_SESSION) != 0) {
                    break; // effect chain here.
                }
            }
        }
        return io;
    }

    // server side of the client's IAudioTrack
    class TrackHandle : public android::BnAudioTrack {
    public: