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

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

Fix problem in AudioFlinger closeOutput and closeInput.

There was no garanty that the corresponding thread destructor had been already called when exiting the closeOutput() or closeInput() functions.
This contructor could be called by the thread after the exit condition is signalled. By way of consequence, closeOutputStream() could be called after
we exited closeOutput() function.

To solve the problem, the call to closeOutputStream() or closeInputStream() is moved to closeOutput() or closeInput().
parent 29b9eff4
Loading
Loading
Loading
Loading
+12 −7
Original line number Original line Diff line number Diff line
@@ -829,9 +829,6 @@ AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinge
AudioFlinger::PlaybackThread::~PlaybackThread()
AudioFlinger::PlaybackThread::~PlaybackThread()
{
{
    delete [] mMixBuffer;
    delete [] mMixBuffer;
    if (mType != DUPLICATING) {
        mAudioFlinger->mAudioHardware->closeOutputStream(mOutput);
    }
}
}


status_t AudioFlinger::PlaybackThread::dump(int fd, const Vector<String16>& args)
status_t AudioFlinger::PlaybackThread::dump(int fd, const Vector<String16>& args)
@@ -2855,7 +2852,6 @@ AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger, A


AudioFlinger::RecordThread::~RecordThread()
AudioFlinger::RecordThread::~RecordThread()
{
{
    mAudioFlinger->mAudioHardware->closeInputStream(mInput);
    delete[] mRsmpInBuffer;
    delete[] mRsmpInBuffer;
    if (mResampler != 0) {
    if (mResampler != 0) {
        delete mResampler;
        delete mResampler;
@@ -3326,7 +3322,9 @@ int AudioFlinger::openDuplicateOutput(int output1, int output2)


status_t AudioFlinger::closeOutput(int output)
status_t AudioFlinger::closeOutput(int output)
{
{
    PlaybackThread *thread;
    // keep strong reference on the playback thread so that
    // it is not destroyed while exit() is executed
    sp <PlaybackThread> thread;
    {
    {
        Mutex::Autolock _l(mLock);
        Mutex::Autolock _l(mLock);
        thread = checkPlaybackThread_l(output);
        thread = checkPlaybackThread_l(output);
@@ -3340,7 +3338,7 @@ status_t AudioFlinger::closeOutput(int output)
            for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
            for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
                if (mPlaybackThreads.valueAt(i)->type() == PlaybackThread::DUPLICATING) {
                if (mPlaybackThreads.valueAt(i)->type() == PlaybackThread::DUPLICATING) {
                    DuplicatingThread *dupThread = (DuplicatingThread *)mPlaybackThreads.valueAt(i).get();
                    DuplicatingThread *dupThread = (DuplicatingThread *)mPlaybackThreads.valueAt(i).get();
                    dupThread->removeOutputTrack((MixerThread *)thread);
                    dupThread->removeOutputTrack((MixerThread *)thread.get());
                }
                }
            }
            }
        }
        }
@@ -3348,6 +3346,9 @@ status_t AudioFlinger::closeOutput(int output)
    }
    }
    thread->exit();
    thread->exit();


    if (thread->type() != PlaybackThread::DUPLICATING) {
        mAudioHardware->closeOutputStream(thread->getOutput());
    }
    return NO_ERROR;
    return NO_ERROR;
}
}


@@ -3449,7 +3450,9 @@ int AudioFlinger::openInput(uint32_t *pDevices,


status_t AudioFlinger::closeInput(int input)
status_t AudioFlinger::closeInput(int input)
{
{
    RecordThread *thread;
    // keep strong reference on the record thread so that
    // it is not destroyed while exit() is executed
    sp <RecordThread> thread;
    {
    {
        Mutex::Autolock _l(mLock);
        Mutex::Autolock _l(mLock);
        thread = checkRecordThread_l(input);
        thread = checkRecordThread_l(input);
@@ -3462,6 +3465,8 @@ status_t AudioFlinger::closeInput(int input)
    }
    }
    thread->exit();
    thread->exit();


    mAudioHardware->closeInputStream(thread->getInput());

    return NO_ERROR;
    return NO_ERROR;
}
}