diff options
author | Andy Hung <hunga@google.com> | 2014-11-12 13:18:52 -0800 |
---|---|---|
committer | Andy Hung <hunga@google.com> | 2014-11-24 17:25:18 -0800 |
commit | 680b795435a5a501a56610258dce5eda40a1725d (patch) | |
tree | db2d003b9b147e5f51e4cf6bf05d497d8ce4acb7 /media/libmedia | |
parent | bc0f452b9a76dd8c8244e775bc9c5aa85cae3ddf (diff) | |
download | frameworks_av-680b795435a5a501a56610258dce5eda40a1725d.zip frameworks_av-680b795435a5a501a56610258dce5eda40a1725d.tar.gz frameworks_av-680b795435a5a501a56610258dce5eda40a1725d.tar.bz2 |
Fix AudioTrack loop mode to play audio from buffer start
Bug: 18217633
Change-Id: Ica77acf0a32832d9b04eb657ef2f4f5329f8fbda
Diffstat (limited to 'media/libmedia')
-rw-r--r-- | media/libmedia/AudioTrack.cpp | 3 | ||||
-rw-r--r-- | media/libmedia/AudioTrackShared.cpp | 10 |
2 files changed, 9 insertions, 4 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index c11050e..bbab2c1 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -742,8 +742,7 @@ status_t AudioTrack::setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount void AudioTrack::setLoop_l(uint32_t loopStart, uint32_t loopEnd, int loopCount) { - // FIXME If setting a loop also sets position to start of loop, then - // this is correct. Otherwise it should be removed. + // Setting the loop will reset next notification update period (like setPosition). mNewPosition = updateAndGetPosition_l() + mUpdatePeriod; mLoopPeriod = loopCount != 0 ? loopEnd - loopStart : 0; mStaticProxy->setLoop(loopStart, loopEnd, loopCount); diff --git a/media/libmedia/AudioTrackShared.cpp b/media/libmedia/AudioTrackShared.cpp index 62362da..4a783b3 100644 --- a/media/libmedia/AudioTrackShared.cpp +++ b/media/libmedia/AudioTrackShared.cpp @@ -503,7 +503,11 @@ void StaticAudioTrackClientProxy::setLoop(size_t loopStart, size_t loopEnd, int newState.mLoopStart = (uint32_t) loopStart; newState.mLoopEnd = (uint32_t) loopEnd; newState.mLoopCount = loopCount; - mBufferPosition = loopStart; + size_t bufferPosition; + if (loopCount == 0 || (bufferPosition = getBufferPosition()) >= loopEnd) { + bufferPosition = loopStart; + } + mBufferPosition = bufferPosition; // snapshot buffer position until loop is acknowledged. (void) mMutator.push(newState); } @@ -776,7 +780,9 @@ ssize_t StaticAudioTrackServerProxy::pollPosition() } else if (state.mLoopCount >= -1) { if (loopStart < loopEnd && loopEnd <= mFrameCount && loopEnd - loopStart >= MIN_LOOP) { - if (!(loopStart <= position && position < loopEnd)) { + // If the current position is greater than the end of the loop + // we "wrap" to the loop start. This might cause an audible pop. + if (position >= loopEnd) { mPosition = position = loopStart; } if (state.mLoopCount == -1) { |