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

Commit 702ca6fa authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

VideoFrameScheduler: Fixed integer underflow due to mismatched

signedness.

Action: Added explicit unsigned->signed conversions in
schedule() and addSample() to prevent automatic signed->unsigned
conversion. (nsecs_t is signed.)

Bug: 26962365
Change-Id: I090aecce2c729af9bc10de32bf5e74d282d02e8c
parent 5a898236
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -156,12 +156,12 @@ bool VideoFrameScheduler::PLL::fit(
        lastTime = time;
    }

    int64_t div   = numSamplesToUse * sumXX - sumX * sumX;
    int64_t div   = (int64_t)numSamplesToUse * sumXX - sumX * sumX;
    if (div == 0) {
        return false;
    }

    int64_t a_nom = numSamplesToUse * sumXY - sumX * sumY;
    int64_t a_nom = (int64_t)numSamplesToUse * sumXY - sumX * sumY;
    int64_t b_nom = sumXX * sumY            - sumX * sumXY;
    *a = divRound(a_nom, div);
    *b = divRound(b_nom, div);
@@ -437,10 +437,10 @@ nsecs_t VideoFrameScheduler::schedule(nsecs_t renderTime) {
                (renderTime + mTimeCorrection + videoPeriod * i - mVsyncTime) % mVsyncPeriod;
            edgeRemainder += (videoPeriod * i) % mVsyncPeriod;
        }
        mTimeCorrection += mVsyncPeriod / 2 - offset / N;
        mTimeCorrection += mVsyncPeriod / 2 - offset / (nsecs_t)N;
        renderTime += mTimeCorrection;
        nsecs_t correctionLimit = mVsyncPeriod * 3 / 5;
        edgeRemainder = abs(edgeRemainder / N - mVsyncPeriod / 2);
        edgeRemainder = abs(edgeRemainder / (nsecs_t)N - mVsyncPeriod / 2);
        if (edgeRemainder <= mVsyncPeriod / 3) {
            correctionLimit /= 2;
        }