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

Commit 54274035 authored by Andy Hung's avatar Andy Hung
Browse files

AudioTrackShared: Fix wrap condition for stop limit

Test: Photos video playback and repeat accessing info
Bug: 68747620
Change-Id: I8c4afa44c0a0a7f689fbc8797ee815e8ae960979
parent 6b6f4313
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -725,12 +725,13 @@ int32_t AudioTrackServerProxy::getRear() const
        const size_t mask = overflowBit - 1;
        const size_t mask = overflowBit - 1;
        int32_t newRear = (rear & ~mask) | (stop & mask);
        int32_t newRear = (rear & ~mask) | (stop & mask);
        ssize_t filled = newRear - front;
        ssize_t filled = newRear - front;
        if (filled < 0) {
        // overflowBit is unsigned, so cast to signed for comparison.
        if (filled >= (ssize_t)overflowBit) {
            // front and rear offsets span the overflow bit of the p2 mask
            // front and rear offsets span the overflow bit of the p2 mask
            // so rebasing newrear.
            // so rebasing newRear on the rear offset is off by the overflow bit.
            ALOGV("stop wrap: filled %zx >= overflowBit %zx", filled, overflowBit);
            ALOGV("stop wrap: filled %zx >= overflowBit %zx", filled, overflowBit);
            newRear += overflowBit;
            newRear -= overflowBit;
            filled += overflowBit;
            filled -= overflowBit;
        }
        }
        if (0 <= filled && (size_t) filled <= mFrameCount) {
        if (0 <= filled && (size_t) filled <= mFrameCount) {
            // we're stopped, return the stop level as newRear
            // we're stopped, return the stop level as newRear