diff options
author | Glenn Kasten <gkasten@google.com> | 2014-03-08 06:22:13 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-08 06:22:13 +0000 |
commit | 6950d10077d10757e894d8e125ba5111eb02517a (patch) | |
tree | fd7db5963ce8fa82b6f2590494efbdf61532f642 /media/libmedia | |
parent | 1aeb490d95a32be37a8691827ddc44c99575c411 (diff) | |
parent | 2f55c2c03b17795e94b325d402ac5b409e3ba0e8 (diff) | |
download | frameworks_av-6950d10077d10757e894d8e125ba5111eb02517a.zip frameworks_av-6950d10077d10757e894d8e125ba5111eb02517a.tar.gz frameworks_av-6950d10077d10757e894d8e125ba5111eb02517a.tar.bz2 |
am 2f55c2c0: Merge "Simplify AudioTrack stream end and fix race" into klp-dev
* commit '2f55c2c03b17795e94b325d402ac5b409e3ba0e8':
Simplify AudioTrack stream end and fix race
Diffstat (limited to 'media/libmedia')
-rw-r--r-- | media/libmedia/AudioTrack.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index 772612a..ce835a1 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -1451,6 +1451,7 @@ nsecs_t AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread) } size_t misalignment = mProxy->getMisalignment(); uint32_t sequence = mSequence; + sp<AudioTrackClientProxy> proxy = mProxy; // These fields don't need to be cached, because they are assigned only by set(): // mTransfer, mCbf, mUserData, mFormat, mFrameSize, mFrameSizeAF, mFlags @@ -1459,35 +1460,32 @@ nsecs_t AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread) mLock.unlock(); if (waitStreamEnd) { - AutoMutex lock(mLock); - - sp<AudioTrackClientProxy> proxy = mProxy; - sp<IMemory> iMem = mCblkMemory; - struct timespec timeout; timeout.tv_sec = WAIT_STREAM_END_TIMEOUT_SEC; timeout.tv_nsec = 0; - mLock.unlock(); - status_t status = mProxy->waitStreamEndDone(&timeout); - mLock.lock(); + status_t status = proxy->waitStreamEndDone(&timeout); switch (status) { case NO_ERROR: case DEAD_OBJECT: case TIMED_OUT: - mLock.unlock(); mCbf(EVENT_STREAM_END, mUserData, NULL); - mLock.lock(); - if (mState == STATE_STOPPING) { - mState = STATE_STOPPED; - if (status != DEAD_OBJECT) { - return NS_INACTIVE; + { + AutoMutex lock(mLock); + // The previously assigned value of waitStreamEnd is no longer valid, + // since the mutex has been unlocked and either the callback handler + // or another thread could have re-started the AudioTrack during that time. + waitStreamEnd = mState == STATE_STOPPING; + if (waitStreamEnd) { + mState = STATE_STOPPED; } } - return 0; - default: - return 0; + if (waitStreamEnd && status != DEAD_OBJECT) { + return NS_INACTIVE; + } + break; } + return 0; } // perform callbacks while unlocked |