diff options
| author | 2009-08-04 08:37:05 -0700 | |
|---|---|---|
| committer | 2009-08-07 10:19:09 -0700 | |
| commit | dae20d9b7f1af8607dfbf3540d041bee7b286ae9 (patch) | |
| tree | 2177b85ee37c9257d5f0d32dba8b46e8311893de /libs/audioflinger/AudioFlinger.cpp | |
| parent | 29b9eff418b065ec2232360fc2af5913902074c1 (diff) | |
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().
Diffstat (limited to 'libs/audioflinger/AudioFlinger.cpp')
| -rw-r--r-- | libs/audioflinger/AudioFlinger.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index 3276cdf76c..fcf8a79449 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -829,9 +829,6 @@ AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinge AudioFlinger::PlaybackThread::~PlaybackThread() { delete [] mMixBuffer; - if (mType != DUPLICATING) { - mAudioFlinger->mAudioHardware->closeOutputStream(mOutput); - } } 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() { - mAudioFlinger->mAudioHardware->closeInputStream(mInput); delete[] mRsmpInBuffer; if (mResampler != 0) { delete mResampler; @@ -3326,7 +3322,9 @@ int AudioFlinger::openDuplicateOutput(int output1, int output2) 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); thread = checkPlaybackThread_l(output); @@ -3340,7 +3338,7 @@ status_t AudioFlinger::closeOutput(int output) for (size_t i = 0; i < mPlaybackThreads.size(); i++) { if (mPlaybackThreads.valueAt(i)->type() == PlaybackThread::DUPLICATING) { 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(); + if (thread->type() != PlaybackThread::DUPLICATING) { + mAudioHardware->closeOutputStream(thread->getOutput()); + } return NO_ERROR; } @@ -3449,7 +3450,9 @@ int AudioFlinger::openInput(uint32_t *pDevices, 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); thread = checkRecordThread_l(input); @@ -3462,6 +3465,8 @@ status_t AudioFlinger::closeInput(int input) } thread->exit(); + mAudioHardware->closeInputStream(thread->getInput()); + return NO_ERROR; } |