summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2014-11-25 23:49:04 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-11-25 23:49:05 +0000
commitd325005e4a3be45c57e950f8c18b329c968602ce (patch)
tree4673f354af652344295bc5fd2b2d37d0e6b2f16b /media
parent512dd849d0ef9e9988fedfbaf951b4b82523957c (diff)
parent680b795435a5a501a56610258dce5eda40a1725d (diff)
downloadframeworks_av-d325005e4a3be45c57e950f8c18b329c968602ce.zip
frameworks_av-d325005e4a3be45c57e950f8c18b329c968602ce.tar.gz
frameworks_av-d325005e4a3be45c57e950f8c18b329c968602ce.tar.bz2
Merge "Fix AudioTrack loop mode to play audio from buffer start" into lmp-mr1-dev
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioTrack.cpp3
-rw-r--r--media/libmedia/AudioTrackShared.cpp10
2 files changed, 9 insertions, 4 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index d6c3bc5..39e3c3d 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) {