SoundPool: Use caller thread for sound playback
A worker playback thread may be starved under high usage situations
such as screenshots or camera snapshots.
Also fix issue with caller thread playback when reusing stream on restart queue.
Test: camera snapshot, screenshot
Test: native soundpool_stress
Test: android.media.cts.SoundPool*Test
Bug: 143448491
Bug: 144540753
Change-Id: I126c3efffc1f1dfb0fcde7a71cdea64afbe0af0a
diff --git a/media/jni/soundpool/StreamManager.cpp b/media/jni/soundpool/StreamManager.cpp
index 8928c47..64f81d5 100644
--- a/media/jni/soundpool/StreamManager.cpp
+++ b/media/jni/soundpool/StreamManager.cpp
@@ -38,7 +38,7 @@
// kPlayOnCallingThread = true prior to R.
// Changing to false means calls to play() are almost instantaneous instead of taking around
// ~10ms to launch the AudioTrack. It is perhaps 100x faster.
-static constexpr bool kPlayOnCallingThread = false;
+static constexpr bool kPlayOnCallingThread = true;
// Amount of time for a StreamManager thread to wait before closing.
static constexpr int64_t kWaitTimeBeforeCloseNs = 9 * NANOS_PER_SECOND;
@@ -167,6 +167,7 @@
if (!stream->getPairStream()->hasSound()) {
if (stream->getSoundID() == soundID) {
newStream = stream;
+ fromAvailableQueue = false;
break;
} else if (newStream == nullptr) {
newStream = stream;