summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2012-05-30 10:32:06 -0700
committerGlenn Kasten <gkasten@google.com>2012-05-31 14:39:20 -0700
commit893a05479c96f911d02beb0443da3ed6508143a7 (patch)
treeba9fba13c28e13b555313231bfb4cbaba39d81b1 /services
parent83410a85993ad6f5f0c122036ff0bda42bf1d4f7 (diff)
Fix fast track leak if out of normal track names
Bug: 6580402 Change-Id: I3ac7f012062c35833147f47ba822eb4bf532a824
Diffstat (limited to 'services')
-rw-r--r--services/audioflinger/AudioFlinger.cpp17
-rw-r--r--services/audioflinger/AudioFlinger.h3
2 files changed, 11 insertions, 9 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index eea3cd22..7d6b121a 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2841,6 +2841,8 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::MixerThread::prepareTrac
// at the identical fast mixer slot within the same normal mix cycle,
// is impossible because the slot isn't marked available until the end of each cycle.
int j = track->mFastIndex;
+ ALOG_ASSERT(0 < j && j < (int)FastMixerState::kMaxFastTracks);
+ ALOG_ASSERT(!(mFastTrackAvailMask & (1 << j)));
FastTrack *fastTrack = &state->mFastTracks[j];
// Determine whether the track is currently in underrun condition,
@@ -4295,6 +4297,13 @@ AudioFlinger::PlaybackThread::Track::Track(
// NOTE: audio_track_cblk_t::frameSize for 8 bit PCM data is based on a sample size of
// 16 bit because data is converted to 16 bit before being stored in buffer by AudioTrack
mCblk->frameSize = audio_is_linear_pcm(format) ? mChannelCount * sizeof(int16_t) : sizeof(uint8_t);
+ // to avoid leaking a track name, do not allocate one unless there is an mCblk
+ mName = thread->getTrackName_l((audio_channel_mask_t)channelMask);
+ if (mName < 0) {
+ ALOGE("no more track names available");
+ return;
+ }
+ // only allocate a fast track index if we were able to allocate a normal track name
if (flags & IAudioFlinger::TRACK_FAST) {
mCblk->flags |= CBLK_FAST; // atomic op not needed yet
ALOG_ASSERT(thread->mFastTrackAvailMask != 0);
@@ -4309,14 +4318,6 @@ AudioFlinger::PlaybackThread::Track::Track(
mObservedUnderruns = thread->getFastTrackUnderruns(i);
thread->mFastTrackAvailMask &= ~(1 << i);
}
- // to avoid leaking a track name, do not allocate one unless there is an mCblk
- mName = thread->getTrackName_l((audio_channel_mask_t)channelMask);
- if (mName < 0) {
- ALOGE("no more track names available");
- // FIXME bug - if sufficient fast track indices, but insufficient normal mixer names,
- // then we leak a fast track index. Should swap these two sections, or better yet
- // only allocate a normal mixer name for normal tracks.
- }
}
ALOGV("Track constructor name %d, calling pid %d", mName, IPCThreadState::self()->getCallingPid());
}
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 19390b1a..160e4cdb 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -778,6 +778,7 @@ private:
int mName; // track name on the normal mixer,
// allocated statically at track creation time,
// and is even allocated (though unused) for fast tracks
+ // FIXME don't allocate track name for fast tracks
int16_t *mMainBuffer;
int32_t *mAuxBuffer;
int mAuxEffectId;
@@ -789,7 +790,7 @@ private:
// The following fields are only for fast tracks, and should be in a subclass
int mFastIndex; // index within FastMixerState::mFastTracks[];
- // either mFastIndex == -1
+ // either mFastIndex == -1 if not isFastTrack()
// or 0 < mFastIndex < FastMixerState::kMaxFast because
// index 0 is reserved for normal mixer's submix;
// index is allocated statically at track creation time