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

Commit 114a92e9 authored by Ray Essick's avatar Ray Essick Committed by Android (Google) Code Review
Browse files

Merge "Avoid overflows in MediaClock calculations"

parents 469454a2 73f21de1
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -110,8 +110,12 @@ void MediaClock::updateAnchor(
    if (mAnchorTimeRealUs != -1) {
        int64_t oldNowMediaUs =
            mAnchorTimeMediaUs + (nowUs - mAnchorTimeRealUs) * (double)mPlaybackRate;
        if (nowMediaUs < oldNowMediaUs + kAnchorFluctuationAllowedUs
                && nowMediaUs > oldNowMediaUs - kAnchorFluctuationAllowedUs) {
        // earlier, we ensured that the anchor times are non-negative and the
        // math to calculate the now/oldNow times stays non-negative.
        // by casting into uint64_t, we gain headroom to avoid any overflows at the upper end
        // when adding the fluctuation allowance.
        if ((uint64_t)nowMediaUs < (uint64_t)oldNowMediaUs + kAnchorFluctuationAllowedUs
                && (uint64_t)nowMediaUs + kAnchorFluctuationAllowedUs > (uint64_t)oldNowMediaUs) {
            return;
        }
    }