Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d325005e authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "Fix AudioTrack loop mode to play audio from buffer start" into lmp-mr1-dev

parents 512dd849 680b7954
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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);
+8 −2
Original line number Diff line number Diff line
@@ -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) {