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

Commit d2071871 authored by Lajos Molnar's avatar Lajos Molnar Committed by Hsiaoan Hsu
Browse files

stagefright: rtsp: handle overflow in jitter calculation

Handle scenario when base jitter is fully 32-bit long.

Bug: 301990510
Test: Video long call / VT generic test
Change-Id: Ic0a4807885429da5354f0b3fc83c6198a20d9c44
Merged-In: Ic0a4807885429da5354f0b3fc83c6198a20d9c44
parent b30345a6
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -47,7 +47,14 @@ void JitterCalc::putBaseData(uint32_t rtpTime, int64_t arrivalTimeUs) {
    int64_t scheduledTimeUs = ((int32_t)diff) * 1000000ll / mClockRate;
    int64_t elapsedTimeUs = arrivalTimeUs - mFirstArrivalTimeUs;
    int64_t correctionTimeUs = elapsedTimeUs - scheduledTimeUs; // additional propagation delay;
    mBaseJitterUs = (mBaseJitterUs * 15 + correctionTimeUs) / 16;

    // We want to approximate correctionTimeUs by slowly (1:15) averaging into jitter base, but
    // both correction time and base jitter can roll over. Adjust correctionTime to be close to
    // base jitter. Accomplish this by calculating the closest 32-bit delta (positive or
    // negative) and applying 1/16th of it to the base jitter.
    int32_t correctionDiff;
    (void)__builtin_sub_overflow(correctionTimeUs, mBaseJitterUs, &correctionDiff);
    mBaseJitterUs = int32_t(int64_t(mBaseJitterUs) + correctionDiff / 16);
    ALOGV("BaseJitterUs : %lld \t\t correctionTimeUs : %lld",
            (long long)mBaseJitterUs, (long long)correctionTimeUs);
}