- make jitter calculation closer to RFC
This commit is contained in:
parent
3cd89fe12c
commit
34d963be40
|
|
@ -9,7 +9,38 @@ using namespace MT;
|
|||
|
||||
void JitterStatistics::process(jrtplib::RTPPacket* packet, int rate)
|
||||
{
|
||||
uint32_t arrival = 0;
|
||||
int d = 0;
|
||||
uint32_t transit = 0;
|
||||
|
||||
uint64_t current_time = TimeHelper::getTimestamp();
|
||||
int interarrival_time_ms = current_time - mPrevRxTimestamp;
|
||||
|
||||
// get the 'arrival time' of this packet as measured in 'timestamp units' and offset
|
||||
// to match the timestamp range in this stream
|
||||
arrival = interarrival_time_ms * (rate / 1000);
|
||||
|
||||
if (mPrevArrival == 0)
|
||||
arrival = packet->GetTimestamp();
|
||||
else
|
||||
arrival += mPrevArrival;;
|
||||
|
||||
mPrevArrival = packet->GetTimestamp();
|
||||
|
||||
transit = arrival - packet->GetTimestamp();
|
||||
jrtplib::RTPTime receiveTime = packet->GetReceiveTime();
|
||||
|
||||
d = transit - mPrevTransit;
|
||||
mPrevTransit = transit;
|
||||
if (d < 0)
|
||||
d = -d;
|
||||
mJitter += (1.0/16.0) * ((double)d - mJitter);
|
||||
|
||||
mPrevRxTimestamp = current_time;
|
||||
if (mMaxJitter < mJitter)
|
||||
mMaxJitter = mJitter;
|
||||
|
||||
|
||||
uint32_t timestamp = packet->GetTimestamp();
|
||||
|
||||
if (!mLastJitter.is_initialized())
|
||||
|
|
@ -20,7 +51,14 @@ void JitterStatistics::process(jrtplib::RTPPacket* packet, int rate)
|
|||
}
|
||||
else
|
||||
{
|
||||
double delta = (receiveTime.GetDouble() - mReceiveTime.GetDouble()) - double(timestamp - mReceiveTimestamp) / rate;
|
||||
double receiveDelta = receiveTime.GetDouble() - mReceiveTime.GetDouble();
|
||||
double timestampDelta = double(timestamp - mReceiveTimestamp);
|
||||
|
||||
if (timestampDelta == 0.0)
|
||||
// Skip current packet silently. Most probably it is error in RTP stream like duplicated packet.
|
||||
return;
|
||||
|
||||
double delta = receiveDelta / timestampDelta;
|
||||
if (fabs(delta) > mMaxDelta)
|
||||
mMaxDelta = fabs(delta);
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,9 @@ namespace MT
|
|||
optional<double> mLastJitter;
|
||||
ProbeStats<double> mJitter;
|
||||
double mMaxDelta = 0.0;
|
||||
uint64_t mPrevRxTimestamp = 0;
|
||||
uint64_t mPrevArrival = 0;
|
||||
uint64_t mPrevTransit = 0;
|
||||
};
|
||||
|
||||
class Statistics
|
||||
|
|
|
|||
Loading…
Reference in New Issue