#include <RTPSource.hh>
Collaboration diagram for RTPReceptionStats:

Public Member Functions | |
| u_int32_t | SSRC () const |
| unsigned | numPacketsReceivedSinceLastReset () const |
| unsigned | totNumPacketsReceived () const |
| double | totNumKBytesReceived () const |
| unsigned | totNumPacketsExpected () const |
| unsigned | baseExtSeqNumReceived () const |
| unsigned | lastResetExtSeqNumReceived () const |
| unsigned | highestExtSeqNumReceived () const |
| unsigned | jitter () const |
| unsigned | lastReceivedSR_NTPmsw () const |
| unsigned | lastReceivedSR_NTPlsw () const |
| timeval const & | lastReceivedSR_time () const |
| unsigned | minInterPacketGapUS () const |
| unsigned | maxInterPacketGapUS () const |
| timeval const & | totalInterPacketGaps () const |
Protected Member Functions | |
| RTPReceptionStats (RTPSource &rtpSource, u_int32_t SSRC, u_int16_t initialSeqNum) | |
| RTPReceptionStats (RTPSource &rtpSource, u_int32_t SSRC) | |
| virtual | ~RTPReceptionStats () |
Protected Attributes | |
| RTPSource & | fOurRTPSource |
| u_int32_t | fSSRC |
| unsigned | fNumPacketsReceivedSinceLastReset |
| unsigned | fTotNumPacketsReceived |
| u_int32_t | fTotBytesReceived_hi |
| u_int32_t | fTotBytesReceived_lo |
| Boolean | fHaveSeenInitialSequenceNumber |
| unsigned | fBaseExtSeqNumReceived |
| unsigned | fLastResetExtSeqNumReceived |
| unsigned | fHighestExtSeqNumReceived |
| int | fLastTransit |
| u_int32_t | fPreviousPacketRTPTimestamp |
| double | fJitter |
| unsigned | fLastReceivedSR_NTPmsw |
| unsigned | fLastReceivedSR_NTPlsw |
| timeval | fLastReceivedSR_time |
| timeval | fLastPacketReceptionTime |
| unsigned | fMinInterPacketGapUS |
| unsigned | fMaxInterPacketGapUS |
| timeval | fTotalInterPacketGaps |
Private Member Functions | |
| void | noteIncomingPacket (u_int16_t seqNum, u_int32_t rtpTimestamp, unsigned timestampFrequency, Boolean useForJitterCalculation, struct timeval &resultPresentationTime, Boolean &resultHasBeenSyncedUsingRTCP, unsigned packetSize) |
| void | noteIncomingSR (u_int32_t ntpTimestampMSW, u_int32_t ntpTimestampLSW, u_int32_t rtpTimestamp) |
| void | init (u_int32_t SSRC) |
| void | initSeqNum (u_int16_t initialSeqNum) |
| void | reset () |
Private Attributes | |
| Boolean | fHasBeenSynchronized |
| u_int32_t | fSyncTimestamp |
| timeval | fSyncTime |
Friends | |
| class | RTPReceptionStatsDB |
Definition at line 169 of file RTPSource.hh.
| RTPReceptionStats::RTPReceptionStats | ( | RTPSource & | rtpSource, | |
| u_int32_t | SSRC, | |||
| u_int16_t | initialSeqNum | |||
| ) | [protected] |
Definition at line 189 of file RTPSource.cpp.
References init(), and initSeqNum().
00191 : fOurRTPSource(rtpSource) { 00192 initSeqNum(initialSeqNum); 00193 init(SSRC); 00194 }
| RTPReceptionStats::RTPReceptionStats | ( | RTPSource & | rtpSource, | |
| u_int32_t | SSRC | |||
| ) | [protected] |
Definition at line 196 of file RTPSource.cpp.
References init().
00197 : fOurRTPSource(rtpSource) { 00198 init(SSRC); 00199 }
| RTPReceptionStats::~RTPReceptionStats | ( | ) | [protected, virtual] |
| u_int32_t RTPReceptionStats::SSRC | ( | ) | const [inline] |
Definition at line 171 of file RTPSource.hh.
References fSSRC.
Referenced by RTCPInstance::enqueueReportBlock().
00171 { return fSSRC; }
| unsigned RTPReceptionStats::numPacketsReceivedSinceLastReset | ( | ) | const [inline] |
Definition at line 172 of file RTPSource.hh.
References fNumPacketsReceivedSinceLastReset.
Referenced by RTCPInstance::enqueueReportBlock(), RTPReceptionStatsDB::Iterator::next(), and RTPReceptionStatsDB::noteIncomingPacket().
00172 { 00173 return fNumPacketsReceivedSinceLastReset; 00174 }
| unsigned RTPReceptionStats::totNumPacketsReceived | ( | ) | const [inline] |
Definition at line 175 of file RTPSource.hh.
References fTotNumPacketsReceived.
Referenced by RTCPInstance::enqueueReportBlock().
00175 { return fTotNumPacketsReceived; }
| double RTPReceptionStats::totNumKBytesReceived | ( | ) | const |
Definition at line 374 of file RTPSource.cpp.
References fTotBytesReceived_hi, and fTotBytesReceived_lo.
00374 { 00375 double const hiMultiplier = 0x20000000/125.0; // == (2^32)/(10^3) 00376 return fTotBytesReceived_hi*hiMultiplier + fTotBytesReceived_lo/1000.0; 00377 }
| unsigned RTPReceptionStats::totNumPacketsExpected | ( | ) | const [inline] |
Definition at line 178 of file RTPSource.hh.
References fBaseExtSeqNumReceived, and fHighestExtSeqNumReceived.
00178 { 00179 return fHighestExtSeqNumReceived - fBaseExtSeqNumReceived; 00180 }
| unsigned RTPReceptionStats::baseExtSeqNumReceived | ( | ) | const [inline] |
Definition at line 182 of file RTPSource.hh.
References fBaseExtSeqNumReceived.
Referenced by RTCPInstance::enqueueReportBlock().
00182 { return fBaseExtSeqNumReceived; }
| unsigned RTPReceptionStats::lastResetExtSeqNumReceived | ( | ) | const [inline] |
Definition at line 183 of file RTPSource.hh.
References fLastResetExtSeqNumReceived.
Referenced by RTCPInstance::enqueueReportBlock().
00183 { 00184 return fLastResetExtSeqNumReceived; 00185 }
| unsigned RTPReceptionStats::highestExtSeqNumReceived | ( | ) | const [inline] |
Definition at line 186 of file RTPSource.hh.
References fHighestExtSeqNumReceived.
Referenced by RTCPInstance::enqueueReportBlock().
00186 { 00187 return fHighestExtSeqNumReceived; 00188 }
| unsigned RTPReceptionStats::jitter | ( | ) | const |
Definition at line 379 of file RTPSource.cpp.
References fJitter.
Referenced by RTCPInstance::enqueueReportBlock().
00379 { 00380 return (unsigned)fJitter; 00381 }
| unsigned RTPReceptionStats::lastReceivedSR_NTPmsw | ( | ) | const [inline] |
Definition at line 192 of file RTPSource.hh.
References fLastReceivedSR_NTPmsw.
Referenced by RTCPInstance::enqueueReportBlock().
00192 { return fLastReceivedSR_NTPmsw; }
| unsigned RTPReceptionStats::lastReceivedSR_NTPlsw | ( | ) | const [inline] |
Definition at line 193 of file RTPSource.hh.
References fLastReceivedSR_NTPlsw.
Referenced by RTCPInstance::enqueueReportBlock().
00193 { return fLastReceivedSR_NTPlsw; }
| struct timeval const& RTPReceptionStats::lastReceivedSR_time | ( | ) | const [inline, read] |
Definition at line 194 of file RTPSource.hh.
References fLastReceivedSR_time.
Referenced by RTCPInstance::enqueueReportBlock().
00194 { 00195 return fLastReceivedSR_time; 00196 }
| unsigned RTPReceptionStats::minInterPacketGapUS | ( | ) | const [inline] |
Definition at line 198 of file RTPSource.hh.
References fMinInterPacketGapUS.
00198 { return fMinInterPacketGapUS; }
| unsigned RTPReceptionStats::maxInterPacketGapUS | ( | ) | const [inline] |
Definition at line 199 of file RTPSource.hh.
References fMaxInterPacketGapUS.
00199 { return fMaxInterPacketGapUS; }
| struct timeval const& RTPReceptionStats::totalInterPacketGaps | ( | ) | const [inline, read] |
Definition at line 200 of file RTPSource.hh.
References fTotalInterPacketGaps.
00200 { 00201 return fTotalInterPacketGaps; 00202 }
| void RTPReceptionStats::noteIncomingPacket | ( | u_int16_t | seqNum, | |
| u_int32_t | rtpTimestamp, | |||
| unsigned | timestampFrequency, | |||
| Boolean | useForJitterCalculation, | |||
| struct timeval & | resultPresentationTime, | |||
| Boolean & | resultHasBeenSyncedUsingRTCP, | |||
| unsigned | packetSize | |||
| ) | [private] |
Definition at line 234 of file RTPSource.cpp.
References fHasBeenSynchronized, fHaveSeenInitialSequenceNumber, fHighestExtSeqNumReceived, fJitter, fLastPacketReceptionTime, fLastTransit, fMaxInterPacketGapUS, fMinInterPacketGapUS, fNumPacketsReceivedSinceLastReset, fOurRTPSource, fPreviousPacketRTPTimestamp, fSyncTime, fSyncTimestamp, fTotalInterPacketGaps, fTotBytesReceived_hi, fTotBytesReceived_lo, fTotNumPacketsReceived, if(), initSeqNum(), MILLION, NULL, seqNumLT(), and RTPSource::timestampFrequency().
Referenced by RTPReceptionStatsDB::noteIncomingPacket().
00239 { 00240 if (!fHaveSeenInitialSequenceNumber) initSeqNum(seqNum); 00241 00242 ++fNumPacketsReceivedSinceLastReset; 00243 ++fTotNumPacketsReceived; 00244 u_int32_t prevTotBytesReceived_lo = fTotBytesReceived_lo; 00245 fTotBytesReceived_lo += packetSize; 00246 if (fTotBytesReceived_lo < prevTotBytesReceived_lo) { // wrap-around 00247 ++fTotBytesReceived_hi; 00248 } 00249 00250 // Check whether the new sequence number is the highest yet seen: 00251 unsigned oldSeqNum = (fHighestExtSeqNumReceived&0xFFFF); 00252 if (seqNumLT((u_int16_t)oldSeqNum, seqNum)) { 00253 // This packet was not an old packet received out of order, so check it: 00254 unsigned seqNumCycle = (fHighestExtSeqNumReceived&0xFFFF0000); 00255 unsigned seqNumDifference = (unsigned)((int)seqNum-(int)oldSeqNum); 00256 if (seqNumDifference >= 0x8000) { 00257 // The sequence number wrapped around, so start a new cycle: 00258 seqNumCycle += 0x10000; 00259 } 00260 00261 unsigned newSeqNum = seqNumCycle|seqNum; 00262 if (newSeqNum > fHighestExtSeqNumReceived) { 00263 fHighestExtSeqNumReceived = newSeqNum; 00264 } 00265 } 00266 00267 // Record the inter-packet delay 00268 struct timeval timeNow; 00269 gettimeofday(&timeNow, NULL); 00270 if (fLastPacketReceptionTime.tv_sec != 0 00271 || fLastPacketReceptionTime.tv_usec != 0) { 00272 unsigned gap 00273 = (timeNow.tv_sec - fLastPacketReceptionTime.tv_sec)*MILLION 00274 + timeNow.tv_usec - fLastPacketReceptionTime.tv_usec; 00275 if (gap > fMaxInterPacketGapUS) { 00276 fMaxInterPacketGapUS = gap; 00277 } 00278 if (gap < fMinInterPacketGapUS) { 00279 fMinInterPacketGapUS = gap; 00280 } 00281 fTotalInterPacketGaps.tv_usec += gap; 00282 if (fTotalInterPacketGaps.tv_usec >= MILLION) { 00283 ++fTotalInterPacketGaps.tv_sec; 00284 fTotalInterPacketGaps.tv_usec -= MILLION; 00285 } 00286 } 00287 fLastPacketReceptionTime = timeNow; 00288 00289 // Compute the current 'jitter' using the received packet's RTP timestamp, 00290 // and the RTP timestamp that would correspond to the current time. 00291 // (Use the code from appendix A.8 in the RTP spec.) 00292 // Note, however, that we don't use this packet if its timestamp is 00293 // the same as that of the previous packet (this indicates a multi-packet 00294 // fragment), or if we've been explicitly told not to use this packet. 00295 if (useForJitterCalculation 00296 && rtpTimestamp != fPreviousPacketRTPTimestamp) { 00297 unsigned arrival = (timestampFrequency*timeNow.tv_sec); 00298 arrival += (unsigned) 00299 ((2.0*timestampFrequency*timeNow.tv_usec + 1000000.0)/2000000); 00300 // note: rounding 00301 int transit = arrival - rtpTimestamp; 00302 if (fLastTransit == (~0)) fLastTransit = transit; // hack for first time 00303 int d = transit - fLastTransit; 00304 fLastTransit = transit; 00305 if (d < 0) d = -d; 00306 fJitter += (1.0/16.0) * ((double)d - fJitter); 00307 } 00308 00309 // Return the 'presentation time' that corresponds to "rtpTimestamp": 00310 if (fSyncTime.tv_sec == 0 && fSyncTime.tv_usec == 0) { 00311 // This is the first timestamp that we've seen, so use the current 00312 // 'wall clock' time as the synchronization time. (This will be 00313 // corrected later when we receive RTCP SRs.) 00314 fSyncTimestamp = rtpTimestamp; 00315 fSyncTime = timeNow; 00316 } 00317 00318 int timestampDiff = rtpTimestamp - fSyncTimestamp; 00319 // Note: This works even if the timestamp wraps around 00320 // (as long as "int" is 32 bits) 00321 00322 // Divide this by the timestamp frequency to get real time: 00323 double timeDiff 00324 = timestampDiff/(double)(fOurRTPSource.timestampFrequency()); 00325 00326 // Add this to the 'sync time' to get our result: 00327 unsigned const million = 1000000; 00328 unsigned seconds, uSeconds; 00329 if (timeDiff >= 0.0) { 00330 seconds = fSyncTime.tv_sec + (unsigned)(timeDiff); 00331 uSeconds = fSyncTime.tv_usec 00332 + (unsigned)((timeDiff - (unsigned)timeDiff)*million); 00333 if (uSeconds >= million) { 00334 uSeconds -= million; 00335 ++seconds; 00336 } 00337 } else { 00338 timeDiff = -timeDiff; 00339 seconds = fSyncTime.tv_sec - (unsigned)(timeDiff); 00340 uSeconds = fSyncTime.tv_usec 00341 - (unsigned)((timeDiff - (unsigned)timeDiff)*million); 00342 if ((int)uSeconds < 0) { 00343 uSeconds += million; 00344 --seconds; 00345 } 00346 } 00347 resultPresentationTime.tv_sec = seconds; 00348 resultPresentationTime.tv_usec = uSeconds; 00349 resultHasBeenSyncedUsingRTCP = fHasBeenSynchronized; 00350 00351 // Save these as the new synchronization timestamp & time: 00352 fSyncTimestamp = rtpTimestamp; 00353 fSyncTime = resultPresentationTime; 00354 00355 fPreviousPacketRTPTimestamp = rtpTimestamp; 00356 }
| void RTPReceptionStats::noteIncomingSR | ( | u_int32_t | ntpTimestampMSW, | |
| u_int32_t | ntpTimestampLSW, | |||
| u_int32_t | rtpTimestamp | |||
| ) | [private] |
Definition at line 358 of file RTPSource.cpp.
References fHasBeenSynchronized, fLastReceivedSR_NTPlsw, fLastReceivedSR_NTPmsw, fLastReceivedSR_time, fSyncTime, fSyncTimestamp, NULL, and True.
Referenced by RTPReceptionStatsDB::noteIncomingSR().
00360 { 00361 fLastReceivedSR_NTPmsw = ntpTimestampMSW; 00362 fLastReceivedSR_NTPlsw = ntpTimestampLSW; 00363 00364 gettimeofday(&fLastReceivedSR_time, NULL); 00365 00366 // Use this SR to update time synchronization information: 00367 fSyncTimestamp = rtpTimestamp; 00368 fSyncTime.tv_sec = ntpTimestampMSW - 0x83AA7E80; // 1/1/1900 -> 1/1/1970 00369 double microseconds = (ntpTimestampLSW*15625.0)/0x04000000; // 10^6/2^32 00370 fSyncTime.tv_usec = (unsigned)(microseconds+0.5); 00371 fHasBeenSynchronized = True; 00372 }
| void RTPReceptionStats::init | ( | u_int32_t | SSRC | ) | [private] |
Definition at line 204 of file RTPSource.cpp.
References False, fHasBeenSynchronized, fHaveSeenInitialSequenceNumber, fJitter, fLastPacketReceptionTime, fLastReceivedSR_NTPlsw, fLastReceivedSR_NTPmsw, fLastReceivedSR_time, fLastTransit, fMaxInterPacketGapUS, fMinInterPacketGapUS, fPreviousPacketRTPTimestamp, fSSRC, fSyncTime, fTotalInterPacketGaps, fTotBytesReceived_hi, fTotBytesReceived_lo, fTotNumPacketsReceived, and reset().
Referenced by RTPReceptionStats().
00204 { 00205 fSSRC = SSRC; 00206 fTotNumPacketsReceived = 0; 00207 fTotBytesReceived_hi = fTotBytesReceived_lo = 0; 00208 fHaveSeenInitialSequenceNumber = False; 00209 fLastTransit = ~0; 00210 fPreviousPacketRTPTimestamp = 0; 00211 fJitter = 0.0; 00212 fLastReceivedSR_NTPmsw = fLastReceivedSR_NTPlsw = 0; 00213 fLastReceivedSR_time.tv_sec = fLastReceivedSR_time.tv_usec = 0; 00214 fLastPacketReceptionTime.tv_sec = fLastPacketReceptionTime.tv_usec = 0; 00215 fMinInterPacketGapUS = 0x7FFFFFFF; 00216 fMaxInterPacketGapUS = 0; 00217 fTotalInterPacketGaps.tv_sec = fTotalInterPacketGaps.tv_usec = 0; 00218 fHasBeenSynchronized = False; 00219 fSyncTime.tv_sec = fSyncTime.tv_usec = 0; 00220 reset(); 00221 }
| void RTPReceptionStats::initSeqNum | ( | u_int16_t | initialSeqNum | ) | [private] |
Definition at line 223 of file RTPSource.cpp.
References fBaseExtSeqNumReceived, fHaveSeenInitialSequenceNumber, fHighestExtSeqNumReceived, and True.
Referenced by noteIncomingPacket(), and RTPReceptionStats().
00223 { 00224 fBaseExtSeqNumReceived = initialSeqNum-1; 00225 fHighestExtSeqNumReceived = initialSeqNum; 00226 fHaveSeenInitialSequenceNumber = True; 00227 }
| void RTPReceptionStats::reset | ( | ) | [private] |
Definition at line 383 of file RTPSource.cpp.
References fHighestExtSeqNumReceived, fLastResetExtSeqNumReceived, and fNumPacketsReceivedSinceLastReset.
Referenced by init(), and RTPReceptionStatsDB::reset().
00383 { 00384 fNumPacketsReceivedSinceLastReset = 0; 00385 fLastResetExtSeqNumReceived = fHighestExtSeqNumReceived; 00386 }
friend class RTPReceptionStatsDB [friend] |
Definition at line 206 of file RTPSource.hh.
RTPSource& RTPReceptionStats::fOurRTPSource [protected] |
u_int32_t RTPReceptionStats::fSSRC [protected] |
unsigned RTPReceptionStats::fNumPacketsReceivedSinceLastReset [protected] |
Definition at line 230 of file RTPSource.hh.
Referenced by noteIncomingPacket(), numPacketsReceivedSinceLastReset(), and reset().
unsigned RTPReceptionStats::fTotNumPacketsReceived [protected] |
Definition at line 231 of file RTPSource.hh.
Referenced by init(), noteIncomingPacket(), and totNumPacketsReceived().
u_int32_t RTPReceptionStats::fTotBytesReceived_hi [protected] |
Definition at line 232 of file RTPSource.hh.
Referenced by init(), noteIncomingPacket(), and totNumKBytesReceived().
u_int32_t RTPReceptionStats::fTotBytesReceived_lo [protected] |
Definition at line 232 of file RTPSource.hh.
Referenced by init(), noteIncomingPacket(), and totNumKBytesReceived().
Definition at line 233 of file RTPSource.hh.
Referenced by init(), initSeqNum(), and noteIncomingPacket().
unsigned RTPReceptionStats::fBaseExtSeqNumReceived [protected] |
Definition at line 234 of file RTPSource.hh.
Referenced by baseExtSeqNumReceived(), initSeqNum(), and totNumPacketsExpected().
unsigned RTPReceptionStats::fLastResetExtSeqNumReceived [protected] |
Definition at line 235 of file RTPSource.hh.
Referenced by lastResetExtSeqNumReceived(), and reset().
unsigned RTPReceptionStats::fHighestExtSeqNumReceived [protected] |
Definition at line 236 of file RTPSource.hh.
Referenced by highestExtSeqNumReceived(), initSeqNum(), noteIncomingPacket(), reset(), and totNumPacketsExpected().
int RTPReceptionStats::fLastTransit [protected] |
u_int32_t RTPReceptionStats::fPreviousPacketRTPTimestamp [protected] |
double RTPReceptionStats::fJitter [protected] |
Definition at line 239 of file RTPSource.hh.
Referenced by init(), jitter(), and noteIncomingPacket().
unsigned RTPReceptionStats::fLastReceivedSR_NTPmsw [protected] |
Definition at line 241 of file RTPSource.hh.
Referenced by init(), lastReceivedSR_NTPmsw(), and noteIncomingSR().
unsigned RTPReceptionStats::fLastReceivedSR_NTPlsw [protected] |
Definition at line 242 of file RTPSource.hh.
Referenced by init(), lastReceivedSR_NTPlsw(), and noteIncomingSR().
struct timeval RTPReceptionStats::fLastReceivedSR_time [read, protected] |
Definition at line 243 of file RTPSource.hh.
Referenced by init(), lastReceivedSR_time(), and noteIncomingSR().
struct timeval RTPReceptionStats::fLastPacketReceptionTime [read, protected] |
unsigned RTPReceptionStats::fMinInterPacketGapUS [protected] |
Definition at line 245 of file RTPSource.hh.
Referenced by init(), minInterPacketGapUS(), and noteIncomingPacket().
unsigned RTPReceptionStats::fMaxInterPacketGapUS [protected] |
Definition at line 245 of file RTPSource.hh.
Referenced by init(), maxInterPacketGapUS(), and noteIncomingPacket().
struct timeval RTPReceptionStats::fTotalInterPacketGaps [read, protected] |
Definition at line 246 of file RTPSource.hh.
Referenced by init(), noteIncomingPacket(), and totalInterPacketGaps().
Definition at line 250 of file RTPSource.hh.
Referenced by init(), noteIncomingPacket(), and noteIncomingSR().
u_int32_t RTPReceptionStats::fSyncTimestamp [private] |
Definition at line 251 of file RTPSource.hh.
Referenced by noteIncomingPacket(), and noteIncomingSR().
struct timeval RTPReceptionStats::fSyncTime [read, private] |
Definition at line 252 of file RTPSource.hh.
Referenced by init(), noteIncomingPacket(), and noteIncomingSR().
1.5.2