diff options
author | Glenn Kasten <gkasten@google.com> | 2015-03-10 01:07:31 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-10 01:07:32 +0000 |
commit | a080050e4209cab9c81ae2144eed9c7c67e87f17 (patch) | |
tree | d9c0810dfa36a25df9cc41edbf2a67229ee2cf9f /media | |
parent | 01771a9f7d9a76dd9bf8adb14717c9bea288ff97 (diff) | |
parent | 18c225d05480e7b80b312ef90d15789b34ce6bbc (diff) | |
download | frameworks_base-a080050e4209cab9c81ae2144eed9c7c67e87f17.zip frameworks_base-a080050e4209cab9c81ae2144eed9c7c67e87f17.tar.gz frameworks_base-a080050e4209cab9c81ae2144eed9c7c67e87f17.tar.bz2 |
Merge "Revert "soundpool: reuse channel for same sample if available""
Diffstat (limited to 'media')
-rw-r--r-- | media/jni/soundpool/SoundPool.cpp | 83 | ||||
-rw-r--r-- | media/jni/soundpool/SoundPool.h | 4 |
2 files changed, 34 insertions, 53 deletions
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp index 80b438b..1205f9d 100644 --- a/media/jni/soundpool/SoundPool.cpp +++ b/media/jni/soundpool/SoundPool.cpp @@ -256,7 +256,7 @@ int SoundPool::play(int sampleID, float leftVolume, float rightVolume, dump(); // allocate a channel - channel = allocateChannel_l(priority, sampleID); + channel = allocateChannel_l(priority); // no channel allocated - return 0 if (!channel) { @@ -271,25 +271,13 @@ int SoundPool::play(int sampleID, float leftVolume, float rightVolume, return channelID; } -SoundChannel* SoundPool::allocateChannel_l(int priority, int sampleID) +SoundChannel* SoundPool::allocateChannel_l(int priority) { List<SoundChannel*>::iterator iter; SoundChannel* channel = NULL; - // check if channel for given sampleID still available + // allocate a channel if (!mChannels.empty()) { - for (iter = mChannels.begin(); iter != mChannels.end(); ++iter) { - if (sampleID == (*iter)->getPrevSampleID() && (*iter)->state() == SoundChannel::IDLE) { - channel = *iter; - mChannels.erase(iter); - ALOGV("Allocated recycled channel for same sampleID"); - break; - } - } - } - - // allocate any channel - if (!channel && !mChannels.empty()) { iter = mChannels.begin(); if (priority >= (*iter)->priority()) { channel = *iter; @@ -660,7 +648,6 @@ error: void SoundChannel::init(SoundPool* soundPool) { mSoundPool = soundPool; - mPrevSampleID = -1; } // call with sound pool lock held @@ -669,7 +656,7 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV { sp<AudioTrack> oldTrack; sp<AudioTrack> newTrack; - status_t status = NO_ERROR; + status_t status; { // scope for the lock Mutex::Autolock lock(&mLock); @@ -716,41 +703,38 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV } #endif - if (!mAudioTrack.get() || mPrevSampleID != sample->sampleID()) { - // 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 - // audio track while the new one is being started and avoids processing them with - // wrong audio audio buffer size (mAudioBufferSize) - unsigned long toggle = mToggle ^ 1; - void *userData = (void *)((unsigned long)this | toggle); - audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(numChannels); - - // do not create a new audio track if current track is compatible with sample parameters - #ifdef USE_SHARED_MEM_BUFFER - newTrack = new AudioTrack(streamType, sampleRate, sample->format(), - channelMask, sample->getIMemory(), AUDIO_OUTPUT_FLAG_FAST, callback, userData); - #else - uint32_t bufferFrames = (totalFrames + (kDefaultBufferCount - 1)) / kDefaultBufferCount; - newTrack = new AudioTrack(streamType, sampleRate, sample->format(), - channelMask, frameCount, AUDIO_OUTPUT_FLAG_FAST, callback, userData, - bufferFrames); - #endif - oldTrack = mAudioTrack; - status = newTrack->initCheck(); - if (status != NO_ERROR) { - ALOGE("Error creating AudioTrack"); - goto exit; - } - // From now on, AudioTrack callbacks received with previous toggle value will be ignored. - mToggle = toggle; - mAudioTrack = newTrack; - } else { - newTrack = mAudioTrack; - ALOGV("reusing track %p for sample %d", mAudioTrack.get(), sample->sampleID()); + // 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 + // audio track while the new one is being started and avoids processing them with + // wrong audio audio buffer size (mAudioBufferSize) + unsigned long toggle = mToggle ^ 1; + void *userData = (void *)((unsigned long)this | toggle); + audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(numChannels); + + // do not create a new audio track if current track is compatible with sample parameters +#ifdef USE_SHARED_MEM_BUFFER + newTrack = new AudioTrack(streamType, sampleRate, sample->format(), + channelMask, sample->getIMemory(), AUDIO_OUTPUT_FLAG_FAST, callback, userData); +#else + uint32_t bufferFrames = (totalFrames + (kDefaultBufferCount - 1)) / kDefaultBufferCount; + newTrack = new AudioTrack(streamType, sampleRate, sample->format(), + channelMask, frameCount, AUDIO_OUTPUT_FLAG_FAST, callback, userData, + bufferFrames); +#endif + oldTrack = mAudioTrack; + status = newTrack->initCheck(); + if (status != NO_ERROR) { + ALOGE("Error creating AudioTrack"); + goto exit; } + ALOGV("setVolume %p", newTrack.get()); newTrack->setVolume(leftVolume, rightVolume); newTrack->setLoop(0, frameCount, loop); + + // From now on, AudioTrack callbacks received with previous toggle value will be ignored. + mToggle = toggle; + mAudioTrack = newTrack; mPos = 0; mSample = sample; mChannelID = nextChannelID; @@ -893,7 +877,6 @@ bool SoundChannel::doStop_l() setVolume_l(0, 0); ALOGV("stop"); mAudioTrack->stop(); - mPrevSampleID = mSample->sampleID(); mSample.clear(); mState = IDLE; mPriority = IDLE_PRIORITY; diff --git a/media/jni/soundpool/SoundPool.h b/media/jni/soundpool/SoundPool.h index 4aacf53..d19cd91 100644 --- a/media/jni/soundpool/SoundPool.h +++ b/media/jni/soundpool/SoundPool.h @@ -136,7 +136,6 @@ public: void nextEvent(); int nextChannelID() { return mNextEvent.channelID(); } void dump(); - int getPrevSampleID(void) { return mPrevSampleID; } private: static void callback(int event, void* user, void *info); @@ -153,7 +152,6 @@ private: int mAudioBufferSize; unsigned long mToggle; bool mAutoPaused; - int mPrevSampleID; }; // application object for managing a pool of sounds @@ -195,7 +193,7 @@ private: sp<Sample> findSample(int sampleID) { return mSamples.valueFor(sampleID); } SoundChannel* findChannel (int channelID); SoundChannel* findNextChannel (int channelID); - SoundChannel* allocateChannel_l(int priority, int sampleID); + SoundChannel* allocateChannel_l(int priority); void moveToFront_l(SoundChannel* channel); void notify(SoundPoolEvent event); void dump(); |