diff options
| author | Eric Laurent <elaurent@google.com> | 2012-05-31 19:59:12 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2012-05-31 19:59:12 -0700 |
| commit | 721e18b75824eae3f3e79c915f4800ecad5dac80 (patch) | |
| tree | 37035a80c39e676fefac4b65e3d26f37e9682a20 /media/libmedia | |
| parent | 386f04ea89f858ae1a1865b6d92ae30a87930151 (diff) | |
| parent | 27d33134130379cc91d936cdc742700311901a9d (diff) | |
| download | frameworks_av-721e18b75824eae3f3e79c915f4800ecad5dac80.zip frameworks_av-721e18b75824eae3f3e79c915f4800ecad5dac80.tar.gz frameworks_av-721e18b75824eae3f3e79c915f4800ecad5dac80.tar.bz2 | |
am 27d33134: Merge "Do not keep audio wake lock when apps underrun." into jb-dev
* commit '27d33134130379cc91d936cdc742700311901a9d':
Do not keep audio wake lock when apps underrun.
Diffstat (limited to 'media/libmedia')
| -rw-r--r-- | media/libmedia/AudioTrack.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index 5e6cd51..e234532 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -1019,13 +1019,6 @@ create_new_track: cblk->lock.unlock(); } - // restart track if it was disabled by audioflinger due to previous underrun - if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) { - android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags); - ALOGW("obtainBuffer() track %p disabled, restarting", this); - mAudioTrack->start(); - } - cblk->waitTimeMs = 0; if (framesReq > framesAvail) { @@ -1057,6 +1050,14 @@ void AudioTrack::releaseBuffer(Buffer* audioBuffer) { AutoMutex lock(mLock); mCblk->stepUser(audioBuffer->frameCount); + if (audioBuffer->frameCount > 0) { + // restart track if it was disabled by audioflinger due to previous underrun + if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { + android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); + ALOGW("releaseBuffer() track %p disabled, restarting", this); + mAudioTrack->start(); + } + } } // ------------------------------------------------------------------------- @@ -1077,6 +1078,10 @@ ssize_t AudioTrack::write(const void* buffer, size_t userSize) ALOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); + if (userSize == 0) { + return 0; + } + // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // while we are accessing the cblk mLock.lock(); @@ -1157,14 +1162,18 @@ status_t TimedAudioTrack::allocateTimedBuffer(size_t size, sp<IMemory>* buffer) status_t TimedAudioTrack::queueTimedBuffer(const sp<IMemory>& buffer, int64_t pts) { - // restart track if it was disabled by audioflinger due to previous underrun - if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { - android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); - ALOGW("queueTimedBuffer() track %p disabled, restarting", this); - mAudioTrack->start(); + status_t status = mAudioTrack->queueTimedBuffer(buffer, pts); + { + AutoMutex lock(mLock); + // restart track if it was disabled by audioflinger due to previous underrun + if (buffer->size() != 0 && status == NO_ERROR && + mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { + android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); + ALOGW("queueTimedBuffer() track %p disabled, restarting", this); + mAudioTrack->start(); + } } - - return mAudioTrack->queueTimedBuffer(buffer, pts); + return status; } status_t TimedAudioTrack::setMediaTimeTransform(const LinearTransform& xform, @@ -1276,6 +1285,7 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread) usleep(WAIT_PERIOD_MS*1000); break; } + if (writtenSize > reqSize) writtenSize = reqSize; if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { |
