summaryrefslogtreecommitdiffstats
path: root/media/jni
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2015-04-01 01:41:59 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-01 01:42:00 +0000
commitc09ccc5631d61f94200df2bb37262364bb598211 (patch)
tree1dfc9338c1c0363de4033fc8e2f92bd9359d1a77 /media/jni
parente1d6333341375217ce645bdbe039901fd6f64226 (diff)
parent32ccb69fdeeeb236d9c5f2a4335b44d1d0c4b042 (diff)
downloadframeworks_base-c09ccc5631d61f94200df2bb37262364bb598211.zip
frameworks_base-c09ccc5631d61f94200df2bb37262364bb598211.tar.gz
frameworks_base-c09ccc5631d61f94200df2bb37262364bb598211.tar.bz2
Merge "Fix SoundPool track recycling for fast tracks"
Diffstat (limited to 'media/jni')
-rw-r--r--media/jni/soundpool/SoundPool.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp
index 10233f3..25c6154 100644
--- a/media/jni/soundpool/SoundPool.cpp
+++ b/media/jni/soundpool/SoundPool.cpp
@@ -716,7 +716,15 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV
}
#endif
- if (!mAudioTrack.get() || mPrevSampleID != sample->sampleID()) {
+ // check if the existing track has the same sample id.
+ if (mAudioTrack != 0 && mPrevSampleID == sample->sampleID()) {
+ // the sample rate may fail to change if the audio track is a fast track.
+ if (mAudioTrack->setSampleRate(sampleRate) == NO_ERROR) {
+ newTrack = mAudioTrack;
+ ALOGV("reusing track %p for sample %d", mAudioTrack.get(), sample->sampleID());
+ }
+ }
+ if (newTrack == 0) {
// mToggle toggles each time a track is started on a given channel.
// The toggle is concatenated with the SoundChannel address and passed to AudioTrack
// as callback user data. This enables the detection of callbacks received from the old
@@ -746,10 +754,6 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV
mToggle = toggle;
mAudioTrack = newTrack;
ALOGV("using new track %p for sample %d", newTrack.get(), sample->sampleID());
- } else {
- newTrack = mAudioTrack;
- newTrack->setSampleRate(sampleRate);
- ALOGV("reusing track %p for sample %d", mAudioTrack.get(), sample->sampleID());
}
newTrack->setVolume(leftVolume, rightVolume);
newTrack->setLoop(0, frameCount, loop);