From 66262b16fb169676d768a8be52485881ea53da54 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Mon, 18 Nov 2019 13:29:57 -0800 Subject: [PATCH] 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 --- media/jni/soundpool/StreamManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/media/jni/soundpool/StreamManager.cpp b/media/jni/soundpool/StreamManager.cpp index 8928c47cf4bb2..64f81d5c34fbb 100644 --- a/media/jni/soundpool/StreamManager.cpp +++ b/media/jni/soundpool/StreamManager.cpp @@ -38,7 +38,7 @@ static constexpr bool kStealActiveStream_OldestFirst = true; // 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 @@ int32_t StreamManager::queueForPlay(const std::shared_ptr &sound, if (!stream->getPairStream()->hasSound()) { if (stream->getSoundID() == soundID) { newStream = stream; + fromAvailableQueue = false; break; } else if (newStream == nullptr) { newStream = stream;