summaryrefslogtreecommitdiffstats
path: root/media/libmedia
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-09-19 09:30:09 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-09-19 09:30:09 -0700
commit88e0f302bf700a7b4d2b6e6a83838c1793508809 (patch)
tree1ffa6271f6599813bdebdc7074c8bb06ee82cbf4 /media/libmedia
parent87fb4f30077e7bcf78e65cf25fe95bd58238bad1 (diff)
parentfeb6d27bf61cd266cf753215e9cae16b9bc9dbbd (diff)
downloadframeworks_av-88e0f302bf700a7b4d2b6e6a83838c1793508809.zip
frameworks_av-88e0f302bf700a7b4d2b6e6a83838c1793508809.tar.gz
frameworks_av-88e0f302bf700a7b4d2b6e6a83838c1793508809.tar.bz2
am feb6d27b: Merge "Workaround slow AudioTrack destruction" into klp-dev
* commit 'feb6d27bf61cd266cf753215e9cae16b9bc9dbbd': Workaround slow AudioTrack destruction
Diffstat (limited to 'media/libmedia')
-rw-r--r--media/libmedia/SoundPool.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/media/libmedia/SoundPool.cpp b/media/libmedia/SoundPool.cpp
index 5239b2f..37b400c 100644
--- a/media/libmedia/SoundPool.cpp
+++ b/media/libmedia/SoundPool.cpp
@@ -537,6 +537,18 @@ void SoundChannel::init(SoundPool* soundPool)
mSoundPool = soundPool;
}
+// This class is used to destroy a RefBase asynchronously
+class AsyncDestructThread : public Thread
+{
+public:
+ AsyncDestructThread(sp<RefBase> refBase) : mRefBase(refBase) { }
+protected:
+ virtual ~AsyncDestructThread() { }
+private:
+ virtual bool threadLoop() { return false; }
+ const sp<RefBase> mRefBase;
+};
+
// call with sound pool lock held
void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftVolume,
float rightVolume, int priority, int loop, float rate)
@@ -641,6 +653,17 @@ exit:
if (status != NO_ERROR) {
mAudioTrack.clear();
}
+ // FIXME AudioTrack destruction should not be slow
+ if (oldTrack != 0) {
+ // must be a raw reference to avoid a race after run()
+ AsyncDestructThread *adt = new AsyncDestructThread(oldTrack);
+ // guaranteed to not run destructor
+ oldTrack.clear();
+ // after the run(), adt thread will hold a strong reference to oldTrack,
+ // and the only strong reference to itself
+ adt->run("AsyncDestruct");
+ // do not delete adt here: adt thread destroys itself, and oldTrack if needed
+ }
}
void SoundChannel::nextEvent()