From 5470761fba2cd534b205c1d3dbd09ce398bd1145 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Fri, 1 Feb 2019 18:24:51 -0800 Subject: [PATCH] SoundPool: Ramp volume down when forcibly reclaiming track Test: Soundbar menu scrolling Bug: 119284313 Change-Id: I4e3e1dc616c4e53780dda5492bb755750be794a0 --- media/jni/soundpool/SoundPool.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp index e08dab48ce393..49066950a9fbe 100644 --- a/media/jni/soundpool/SoundPool.cpp +++ b/media/jni/soundpool/SoundPool.cpp @@ -17,8 +17,9 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "SoundPool" +#include #include - +#include #include #define USE_SHARED_MEM_BUFFER @@ -967,6 +968,12 @@ bool SoundChannel::doStop_l() if (mState != IDLE) { setVolume_l(0, 0); ALOGV("stop"); + // Since we're forcibly halting the previously playing content, + // we sleep here to ensure the volume is ramped down before we stop the track. + // Ideally the sleep time is the mixer period, or an approximation thereof + // (Fast vs Normal tracks are different). + // TODO: consider pausing instead of stop here. + std::this_thread::sleep_for(std::chrono::milliseconds(20)); mAudioTrack->stop(); mPrevSampleID = mSample->sampleID(); mSample.clear();