summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2011-09-06 12:36:15 -0700
committerEric Laurent <elaurent@google.com>2011-09-06 14:37:20 -0700
commit408b8dc3c0a364c6f6b4991d15da9e6bcc2b8008 (patch)
treef5f9885d8b86fc8073678962a8d38eec4ebef2a4 /media
parent3a13fad63af40a8364fce796b1a54a8f0a2fbf32 (diff)
downloadframeworks_av-408b8dc3c0a364c6f6b4991d15da9e6bcc2b8008.zip
frameworks_av-408b8dc3c0a364c6f6b4991d15da9e6bcc2b8008.tar.gz
frameworks_av-408b8dc3c0a364c6f6b4991d15da9e6bcc2b8008.tar.bz2
Issue 5247986: Battery drain due to audio wakelock
The problem occurs when activating or deactivating A2DP connection while SoudPool has a channel active. This can happen quite frequently now that the UI sound effects are enabled by default. If PCM data is remaining in the AudioTrack buffer when it is restroyed and re-created on the new AudioFlinger output thread, this data is flushed. As a consequence, no underrun or request for new data callback is sent to SoundPool and the sound channel remains active for ever as the end of the sample is never detected. Change-Id: I13e0c11e4ce3f83bff7f58d347ca814b6a86712b
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioTrack.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 3b6c64d..7509239 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -1182,16 +1182,33 @@ status_t AudioTrack::restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart)
false);
if (result == NO_ERROR) {
+ uint32_t user = cblk->user;
+ uint32_t server = cblk->server;
// restore write index and set other indexes to reflect empty buffer status
- mCblk->user = cblk->user;
- mCblk->server = cblk->user;
- mCblk->userBase = cblk->user;
- mCblk->serverBase = cblk->user;
+ mCblk->user = user;
+ mCblk->server = user;
+ mCblk->userBase = user;
+ mCblk->serverBase = user;
// restore loop: this is not guaranteed to succeed if new frame count is not
// compatible with loop length
setLoop_l(cblk->loopStart, cblk->loopEnd, cblk->loopCount);
if (!fromStart) {
mCblk->bufferTimeoutMs = MAX_RUN_TIMEOUT_MS;
+ // Make sure that a client relying on callback events indicating underrun or
+ // the actual amount of audio frames played (e.g SoundPool) receives them.
+ if (mSharedBuffer == 0) {
+ uint32_t frames = 0;
+ if (user > server) {
+ frames = ((user - server) > mCblk->frameCount) ?
+ mCblk->frameCount : (user - server);
+ memset(mCblk->buffers, 0, frames * mCblk->frameSize);
+ }
+ // restart playback even if buffer is not completely filled.
+ android_atomic_or(CBLK_FORCEREADY_ON, &mCblk->flags);
+ // stepUser() clears CBLK_UNDERRUN_ON flag enabling underrun callbacks to
+ // the client
+ mCblk->stepUser(frames);
+ }
}
if (mActive) {
result = mAudioTrack->start();