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

Commit b72b699a authored by Josh Hou's avatar Josh Hou Committed by Automerger Merge Worker
Browse files

Merge "VT: Fix overflow condition in JitterCalc" into sc-qpr1-dev am: d18a2c7d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/15747422

Change-Id: I5a215ac8bfd5c0a859dd9fb3f592a7816f8cd796
parents f6fc53ad d18a2c7d
Loading
Loading
Loading
Loading
+11 −17
Original line number Original line Diff line number Diff line
@@ -38,14 +38,13 @@ void JitterCalc::init(uint32_t rtpTime, int64_t arrivalTimeUs, int32_t base, int
    mInterArrivalJitterUs = inter;
    mInterArrivalJitterUs = inter;
}
}


void JitterCalc::putBaseData(int64_t rtpTime, int64_t arrivalTimeUs) {
void JitterCalc::putBaseData(uint32_t rtpTime, int64_t arrivalTimeUs) {
    // A RTP time wraps around after UINT32_MAX. We must consider this case.
    // A RTP time wraps around after UINT32_MAX. Overflow can present.
    const int64_t UINT32_MSB = 0x80000000;
    uint32_t diff = 0;
    int64_t overflowMask = (mFirstTimeStamp & UINT32_MSB & ~rtpTime) << 1;
    __builtin_usub_overflow(rtpTime, mFirstTimeStamp, &diff);
    int64_t tempRtpTime = overflowMask | rtpTime;


    // Base jitter implementation can be various
    // Base jitter implementation can be various
    int64_t scheduledTimeUs = (tempRtpTime - (int64_t)mFirstTimeStamp) * 1000000ll / mClockRate;
    int64_t scheduledTimeUs = ((int32_t)diff) * 1000000ll / mClockRate;
    int64_t elapsedTimeUs = arrivalTimeUs - mFirstArrivalTimeUs;
    int64_t elapsedTimeUs = arrivalTimeUs - mFirstArrivalTimeUs;
    int64_t correctionTimeUs = elapsedTimeUs - scheduledTimeUs; // additional propagation delay;
    int64_t correctionTimeUs = elapsedTimeUs - scheduledTimeUs; // additional propagation delay;
    mBaseJitterUs = (mBaseJitterUs * 15 + correctionTimeUs) / 16;
    mBaseJitterUs = (mBaseJitterUs * 15 + correctionTimeUs) / 16;
@@ -53,18 +52,13 @@ void JitterCalc::putBaseData(int64_t rtpTime, int64_t arrivalTimeUs) {
            (long long)mBaseJitterUs, (long long)correctionTimeUs);
            (long long)mBaseJitterUs, (long long)correctionTimeUs);
}
}


void JitterCalc::putInterArrivalData(int64_t rtpTime, int64_t arrivalTimeUs) {
void JitterCalc::putInterArrivalData(uint32_t rtpTime, int64_t arrivalTimeUs) {
    const int64_t UINT32_MSB = 0x80000000;
    // A RTP time wraps around after UINT32_MAX. Overflow can present.
    int64_t tempRtpTime = rtpTime;
    uint32_t diff = 0;
    int64_t tempLastTimeStamp = mLastTimeStamp;
    __builtin_usub_overflow(rtpTime, mLastTimeStamp, &diff);

    // A RTP time wraps around after UINT32_MAX. We must consider this case.
    int64_t overflowMask = (mLastTimeStamp ^ rtpTime) & UINT32_MSB;
    tempRtpTime |= ((overflowMask & ~rtpTime) << 1);
    tempLastTimeStamp |= ((overflowMask & ~mLastTimeStamp) << 1);


    // 6.4.1 of RFC3550 defines this interarrival jitter value.
    // 6.4.1 of RFC3550 defines this interarrival jitter value.
    int64_t diffTimeStampUs = abs(tempRtpTime - tempLastTimeStamp) * 1000000ll / mClockRate;
    int64_t diffTimeStampUs = abs((int32_t)diff) * 1000000ll / mClockRate;
    int64_t diffArrivalUs = arrivalTimeUs - mLastArrivalTimeUs; // Can't be minus
    int64_t diffArrivalUs = arrivalTimeUs - mLastArrivalTimeUs; // Can't be minus
    ALOGV("diffTimeStampUs %lld \t\t diffArrivalUs %lld",
    ALOGV("diffTimeStampUs %lld \t\t diffArrivalUs %lld",
            (long long)diffTimeStampUs, (long long)diffArrivalUs);
            (long long)diffTimeStampUs, (long long)diffArrivalUs);
@@ -72,7 +66,7 @@ void JitterCalc::putInterArrivalData(int64_t rtpTime, int64_t arrivalTimeUs) {
    int64_t varianceUs = diffArrivalUs - diffTimeStampUs;
    int64_t varianceUs = diffArrivalUs - diffTimeStampUs;
    mInterArrivalJitterUs = (mInterArrivalJitterUs * 15 + abs(varianceUs)) / 16;
    mInterArrivalJitterUs = (mInterArrivalJitterUs * 15 + abs(varianceUs)) / 16;


    mLastTimeStamp = (uint32_t)rtpTime;
    mLastTimeStamp = rtpTime;
    mLastArrivalTimeUs = arrivalTimeUs;
    mLastArrivalTimeUs = arrivalTimeUs;
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -40,8 +40,8 @@ public:
    JitterCalc(int32_t clockRate);
    JitterCalc(int32_t clockRate);


    void init(uint32_t rtpTime, int64_t arrivalTimeUs, int32_t base, int32_t inter);
    void init(uint32_t rtpTime, int64_t arrivalTimeUs, int32_t base, int32_t inter);
    void putInterArrivalData(int64_t rtpTime, int64_t arrivalTime);
    void putInterArrivalData(uint32_t rtpTime, int64_t arrivalTime);
    void putBaseData(int64_t rtpTime, int64_t arrivalTimeUs);
    void putBaseData(uint32_t rtpTime, int64_t arrivalTimeUs);
    int32_t getBaseJitterMs();
    int32_t getBaseJitterMs();
    int32_t getInterArrivalJitterMs();
    int32_t getInterArrivalJitterMs();
};
};