From 6e8bf981aca33625e133ab8f9daafd1652b0eced Mon Sep 17 00:00:00 2001 From: Tomoharu Kasahara Date: Fri, 9 Jun 2017 16:17:33 +0900 Subject: [PATCH] Prevent old callback events when track is recycled When a track is reused from SoundPool and started again, the previous callback events could be done after track started, then the new playback will be stopped unintentionally. Clear the old cblk flags when recycled track is started again to avoid triggering unexpected callback events. Bug: 112269355 Test: Playback with SoundPool frequently Change-Id: I111b085d08b73c333fbb0fc2896efe1c013c584c --- media/libaudioclient/AudioTrack.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp index c6622cd043..0edb04b856 100644 --- a/media/libaudioclient/AudioTrack.cpp +++ b/media/libaudioclient/AudioTrack.cpp @@ -631,6 +631,13 @@ status_t AudioTrack::start() // force refresh of remaining frames by processAudioBuffer() as last // write before stop could be partial. mRefreshRemaining = true; + + // for static track, clear the old flags when starting from stopped state + if (mSharedBuffer != 0) { + android_atomic_and( + ~(CBLK_LOOP_CYCLE | CBLK_LOOP_FINAL | CBLK_BUFFER_END), + &mCblk->mFlags); + } } mNewPosition = mPosition + mUpdatePeriod; int32_t flags = android_atomic_and(~(CBLK_STREAM_END_DONE | CBLK_DISABLED), &mCblk->mFlags);