RTPReceptionStats Class Reference

#include <RTPSource.hh>


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 (u_int32_t SSRC, u_int16_t initialSeqNum)
 RTPReceptionStats (u_int32_t SSRC)
virtual ~RTPReceptionStats ()

Protected Attributes

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


Detailed Description

Definition at line 175 of file RTPSource.hh.


Constructor & Destructor Documentation

RTPReceptionStats::RTPReceptionStats ( u_int32_t  SSRC,
u_int16_t  initialSeqNum 
) [protected]

Definition at line 187 of file RTPSource.cpp.

References init(), and initSeqNum().

00187                                                                             {
00188   initSeqNum(initialSeqNum);
00189   init(SSRC);
00190 }

RTPReceptionStats::RTPReceptionStats ( u_int32_t  SSRC  )  [protected]

Definition at line 192 of file RTPSource.cpp.

References init().

00192                                                    {
00193   init(SSRC);
00194 }

RTPReceptionStats::~RTPReceptionStats (  )  [protected, virtual]

Definition at line 196 of file RTPSource.cpp.

00196                                       {
00197 }


Member Function Documentation

u_int32_t RTPReceptionStats::SSRC (  )  const [inline]

Definition at line 177 of file RTPSource.hh.

References fSSRC.

Referenced by RTCPInstance::enqueueReportBlock().

00177 { return fSSRC; }

unsigned RTPReceptionStats::numPacketsReceivedSinceLastReset (  )  const [inline]

Definition at line 178 of file RTPSource.hh.

References fNumPacketsReceivedSinceLastReset.

Referenced by RTCPInstance::enqueueReportBlock(), RTPReceptionStatsDB::Iterator::next(), and RTPReceptionStatsDB::noteIncomingPacket().

00178                                                     {
00179     return fNumPacketsReceivedSinceLastReset;
00180   }

unsigned RTPReceptionStats::totNumPacketsReceived (  )  const [inline]

Definition at line 181 of file RTPSource.hh.

References fTotNumPacketsReceived.

Referenced by RTCPInstance::enqueueReportBlock().

00181 { return fTotNumPacketsReceived; }

double RTPReceptionStats::totNumKBytesReceived (  )  const

Definition at line 384 of file RTPSource.cpp.

References fTotBytesReceived_hi, and fTotBytesReceived_lo.

00384                                                      {
00385   double const hiMultiplier = 0x20000000/125.0; // == (2^32)/(10^3)
00386   return fTotBytesReceived_hi*hiMultiplier + fTotBytesReceived_lo/1000.0;
00387 }

unsigned RTPReceptionStats::totNumPacketsExpected (  )  const [inline]

Definition at line 184 of file RTPSource.hh.

References fBaseExtSeqNumReceived, and fHighestExtSeqNumReceived.

00184                                          {
00185     return (fHighestExtSeqNumReceived - fBaseExtSeqNumReceived) + 1;
00186   }

unsigned RTPReceptionStats::baseExtSeqNumReceived (  )  const [inline]

Definition at line 188 of file RTPSource.hh.

References fBaseExtSeqNumReceived.

Referenced by RTCPInstance::enqueueReportBlock().

00188 { return fBaseExtSeqNumReceived; }

unsigned RTPReceptionStats::lastResetExtSeqNumReceived (  )  const [inline]

Definition at line 189 of file RTPSource.hh.

References fLastResetExtSeqNumReceived.

Referenced by RTCPInstance::enqueueReportBlock().

00189                                               {
00190     return fLastResetExtSeqNumReceived;
00191   }

unsigned RTPReceptionStats::highestExtSeqNumReceived (  )  const [inline]

Definition at line 192 of file RTPSource.hh.

References fHighestExtSeqNumReceived.

Referenced by RTCPInstance::enqueueReportBlock().

00192                                             {
00193     return fHighestExtSeqNumReceived;
00194   }

unsigned RTPReceptionStats::jitter (  )  const

Definition at line 389 of file RTPSource.cpp.

References fJitter.

Referenced by RTCPInstance::enqueueReportBlock().

00389                                          {
00390   return (unsigned)fJitter;
00391 }

unsigned RTPReceptionStats::lastReceivedSR_NTPmsw (  )  const [inline]

Definition at line 198 of file RTPSource.hh.

References fLastReceivedSR_NTPmsw.

Referenced by RTCPInstance::enqueueReportBlock().

00198 { return fLastReceivedSR_NTPmsw; }

unsigned RTPReceptionStats::lastReceivedSR_NTPlsw (  )  const [inline]

Definition at line 199 of file RTPSource.hh.

References fLastReceivedSR_NTPlsw.

Referenced by RTCPInstance::enqueueReportBlock().

00199 { return fLastReceivedSR_NTPlsw; }

struct timeval const& RTPReceptionStats::lastReceivedSR_time (  )  const [inline, read]

Definition at line 200 of file RTPSource.hh.

References fLastReceivedSR_time.

Referenced by RTCPInstance::enqueueReportBlock().

00200                                                     {
00201     return fLastReceivedSR_time;
00202   }

unsigned RTPReceptionStats::minInterPacketGapUS (  )  const [inline]

Definition at line 204 of file RTPSource.hh.

References fMinInterPacketGapUS.

00204 { return fMinInterPacketGapUS; }

unsigned RTPReceptionStats::maxInterPacketGapUS (  )  const [inline]

Definition at line 205 of file RTPSource.hh.

References fMaxInterPacketGapUS.

00205 { return fMaxInterPacketGapUS; }

struct timeval const& RTPReceptionStats::totalInterPacketGaps (  )  const [inline, read]

Definition at line 206 of file RTPSource.hh.

References fTotalInterPacketGaps.

00206                                                      {
00207     return fTotalInterPacketGaps;
00208   }

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 231 of file RTPSource.cpp.

References fBaseExtSeqNumReceived, fHasBeenSynchronized, fHaveSeenInitialSequenceNumber, fHighestExtSeqNumReceived, fJitter, fLastPacketReceptionTime, fLastTransit, fMaxInterPacketGapUS, fMinInterPacketGapUS, fNumPacketsReceivedSinceLastReset, fPreviousPacketRTPTimestamp, fSyncTime, fSyncTimestamp, fTotalInterPacketGaps, fTotBytesReceived_hi, fTotBytesReceived_lo, fTotNumPacketsReceived, if(), initSeqNum(), MILLION, NULL, and seqNumLT().

Referenced by RTPReceptionStatsDB::noteIncomingPacket().

00236                                           {
00237   if (!fHaveSeenInitialSequenceNumber) initSeqNum(seqNum);
00238 
00239   ++fNumPacketsReceivedSinceLastReset;
00240   ++fTotNumPacketsReceived;
00241   u_int32_t prevTotBytesReceived_lo = fTotBytesReceived_lo;
00242   fTotBytesReceived_lo += packetSize;
00243   if (fTotBytesReceived_lo < prevTotBytesReceived_lo) { // wrap-around
00244     ++fTotBytesReceived_hi;
00245   }
00246 
00247   // Check whether the new sequence number is the highest yet seen:
00248   unsigned oldSeqNum = (fHighestExtSeqNumReceived&0xFFFF);
00249   unsigned seqNumCycle = (fHighestExtSeqNumReceived&0xFFFF0000);
00250   unsigned seqNumDifference = (unsigned)((int)seqNum-(int)oldSeqNum);
00251   unsigned newSeqNum = 0;
00252   if (seqNumLT((u_int16_t)oldSeqNum, seqNum)) {
00253     // This packet was not an old packet received out of order, so check it:
00254     
00255     if (seqNumDifference >= 0x8000) {
00256       // The sequence number wrapped around, so start a new cycle:
00257       seqNumCycle += 0x10000;
00258     }
00259     
00260     newSeqNum = seqNumCycle|seqNum;
00261     if (newSeqNum > fHighestExtSeqNumReceived) {
00262       fHighestExtSeqNumReceived = newSeqNum;
00263     }
00264   } else if (fTotNumPacketsReceived > 1) {
00265     // This packet was an old packet received out of order
00266     
00267     if ((int)seqNumDifference >= 0x8000) {
00268       // The sequence number wrapped around, so switch to an old cycle:
00269       seqNumCycle -= 0x10000;
00270     }
00271     
00272     newSeqNum = seqNumCycle|seqNum;
00273     if (newSeqNum < fBaseExtSeqNumReceived) {
00274       fBaseExtSeqNumReceived = newSeqNum;
00275     }
00276   }
00277 
00278   // Record the inter-packet delay
00279   struct timeval timeNow;
00280   gettimeofday(&timeNow, NULL);
00281   if (fLastPacketReceptionTime.tv_sec != 0
00282       || fLastPacketReceptionTime.tv_usec != 0) {
00283     unsigned gap
00284       = (timeNow.tv_sec - fLastPacketReceptionTime.tv_sec)*MILLION
00285       + timeNow.tv_usec - fLastPacketReceptionTime.tv_usec; 
00286     if (gap > fMaxInterPacketGapUS) {
00287       fMaxInterPacketGapUS = gap;
00288     }
00289     if (gap < fMinInterPacketGapUS) {
00290       fMinInterPacketGapUS = gap;
00291     }
00292     fTotalInterPacketGaps.tv_usec += gap;
00293     if (fTotalInterPacketGaps.tv_usec >= MILLION) {
00294       ++fTotalInterPacketGaps.tv_sec;
00295       fTotalInterPacketGaps.tv_usec -= MILLION;
00296     }
00297   }
00298   fLastPacketReceptionTime = timeNow;
00299 
00300   // Compute the current 'jitter' using the received packet's RTP timestamp,
00301   // and the RTP timestamp that would correspond to the current time.
00302   // (Use the code from appendix A.8 in the RTP spec.)
00303   // Note, however, that we don't use this packet if its timestamp is
00304   // the same as that of the previous packet (this indicates a multi-packet
00305   // fragment), or if we've been explicitly told not to use this packet.
00306   if (useForJitterCalculation
00307       && rtpTimestamp != fPreviousPacketRTPTimestamp) {
00308     unsigned arrival = (timestampFrequency*timeNow.tv_sec);
00309     arrival += (unsigned)
00310       ((2.0*timestampFrequency*timeNow.tv_usec + 1000000.0)/2000000);
00311             // note: rounding
00312     int transit = arrival - rtpTimestamp;
00313     if (fLastTransit == (~0)) fLastTransit = transit; // hack for first time
00314     int d = transit - fLastTransit;
00315     fLastTransit = transit;
00316     if (d < 0) d = -d;
00317     fJitter += (1.0/16.0) * ((double)d - fJitter);
00318   }
00319 
00320   // Return the 'presentation time' that corresponds to "rtpTimestamp":
00321   if (fSyncTime.tv_sec == 0 && fSyncTime.tv_usec == 0) {
00322     // This is the first timestamp that we've seen, so use the current
00323     // 'wall clock' time as the synchronization time.  (This will be
00324     // corrected later when we receive RTCP SRs.)
00325     fSyncTimestamp = rtpTimestamp;
00326     fSyncTime = timeNow;
00327   }
00328 
00329   int timestampDiff = rtpTimestamp - fSyncTimestamp;
00330       // Note: This works even if the timestamp wraps around
00331       // (as long as "int" is 32 bits)
00332 
00333   // Divide this by the timestamp frequency to get real time:
00334   double timeDiff = timestampDiff/(double)timestampFrequency;
00335 
00336   // Add this to the 'sync time' to get our result:
00337   unsigned const million = 1000000;
00338   unsigned seconds, uSeconds;
00339   if (timeDiff >= 0.0) {
00340     seconds = fSyncTime.tv_sec + (unsigned)(timeDiff);
00341     uSeconds = fSyncTime.tv_usec
00342       + (unsigned)((timeDiff - (unsigned)timeDiff)*million);
00343     if (uSeconds >= million) {
00344       uSeconds -= million;
00345       ++seconds;
00346     }
00347   } else {
00348     timeDiff = -timeDiff;
00349     seconds = fSyncTime.tv_sec - (unsigned)(timeDiff);
00350     uSeconds = fSyncTime.tv_usec
00351       - (unsigned)((timeDiff - (unsigned)timeDiff)*million);
00352     if ((int)uSeconds < 0) {
00353       uSeconds += million;
00354       --seconds;
00355     }
00356   }
00357   resultPresentationTime.tv_sec = seconds;
00358   resultPresentationTime.tv_usec = uSeconds;
00359   resultHasBeenSyncedUsingRTCP = fHasBeenSynchronized;
00360 
00361   // Save these as the new synchronization timestamp & time:
00362   fSyncTimestamp = rtpTimestamp;
00363   fSyncTime = resultPresentationTime;
00364 
00365   fPreviousPacketRTPTimestamp = rtpTimestamp;
00366 }

void RTPReceptionStats::noteIncomingSR ( u_int32_t  ntpTimestampMSW,
u_int32_t  ntpTimestampLSW,
u_int32_t  rtpTimestamp 
) [private]

Definition at line 368 of file RTPSource.cpp.

References fHasBeenSynchronized, fLastReceivedSR_NTPlsw, fLastReceivedSR_NTPmsw, fLastReceivedSR_time, fSyncTime, fSyncTimestamp, NULL, and True.

Referenced by RTPReceptionStatsDB::noteIncomingSR().

00370                                                                {
00371   fLastReceivedSR_NTPmsw = ntpTimestampMSW;
00372   fLastReceivedSR_NTPlsw = ntpTimestampLSW;
00373 
00374   gettimeofday(&fLastReceivedSR_time, NULL);
00375 
00376   // Use this SR to update time synchronization information:
00377   fSyncTimestamp = rtpTimestamp;
00378   fSyncTime.tv_sec = ntpTimestampMSW - 0x83AA7E80; // 1/1/1900 -> 1/1/1970
00379   double microseconds = (ntpTimestampLSW*15625.0)/0x04000000; // 10^6/2^32
00380   fSyncTime.tv_usec = (unsigned)(microseconds+0.5);
00381   fHasBeenSynchronized = True;
00382 }

void RTPReceptionStats::init ( u_int32_t  SSRC  )  [private]

Definition at line 199 of file RTPSource.cpp.

References False, fBaseExtSeqNumReceived, fHasBeenSynchronized, fHaveSeenInitialSequenceNumber, fHighestExtSeqNumReceived, 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().

00199                                            {
00200   fSSRC = SSRC;
00201   fTotNumPacketsReceived = 0;
00202   fTotBytesReceived_hi = fTotBytesReceived_lo = 0;
00203   fBaseExtSeqNumReceived = 0;
00204   fHighestExtSeqNumReceived = 0;
00205   fHaveSeenInitialSequenceNumber = False;
00206   fLastTransit = ~0;
00207   fPreviousPacketRTPTimestamp = 0;
00208   fJitter = 0.0;
00209   fLastReceivedSR_NTPmsw = fLastReceivedSR_NTPlsw = 0;
00210   fLastReceivedSR_time.tv_sec = fLastReceivedSR_time.tv_usec = 0;
00211   fLastPacketReceptionTime.tv_sec = fLastPacketReceptionTime.tv_usec = 0;
00212   fMinInterPacketGapUS = 0x7FFFFFFF;
00213   fMaxInterPacketGapUS = 0;
00214   fTotalInterPacketGaps.tv_sec = fTotalInterPacketGaps.tv_usec = 0;
00215   fHasBeenSynchronized = False;
00216   fSyncTime.tv_sec = fSyncTime.tv_usec = 0;
00217   reset();
00218 }

void RTPReceptionStats::initSeqNum ( u_int16_t  initialSeqNum  )  [private]

Definition at line 220 of file RTPSource.cpp.

References fBaseExtSeqNumReceived, fHaveSeenInitialSequenceNumber, fHighestExtSeqNumReceived, and True.

Referenced by noteIncomingPacket(), and RTPReceptionStats().

00220                                                           {
00221     fBaseExtSeqNumReceived = 0x10000 | initialSeqNum;
00222     fHighestExtSeqNumReceived = 0x10000 | initialSeqNum;
00223     fHaveSeenInitialSequenceNumber = True;
00224 }

void RTPReceptionStats::reset (  )  [private]

Definition at line 393 of file RTPSource.cpp.

References fHighestExtSeqNumReceived, fLastResetExtSeqNumReceived, and fNumPacketsReceivedSinceLastReset.

Referenced by init(), and RTPReceptionStatsDB::reset().


Friends And Related Function Documentation

friend class RTPReceptionStatsDB [friend]

Definition at line 212 of file RTPSource.hh.


Field Documentation

u_int32_t RTPReceptionStats::fSSRC [protected]

Definition at line 233 of file RTPSource.hh.

Referenced by init(), and SSRC().

unsigned RTPReceptionStats::fNumPacketsReceivedSinceLastReset [protected]

Definition at line 234 of file RTPSource.hh.

Referenced by noteIncomingPacket(), numPacketsReceivedSinceLastReset(), and reset().

unsigned RTPReceptionStats::fTotNumPacketsReceived [protected]

Definition at line 235 of file RTPSource.hh.

Referenced by init(), noteIncomingPacket(), and totNumPacketsReceived().

u_int32_t RTPReceptionStats::fTotBytesReceived_hi [protected]

Definition at line 236 of file RTPSource.hh.

Referenced by init(), noteIncomingPacket(), and totNumKBytesReceived().

u_int32_t RTPReceptionStats::fTotBytesReceived_lo [protected]

Definition at line 236 of file RTPSource.hh.

Referenced by init(), noteIncomingPacket(), and totNumKBytesReceived().

Boolean RTPReceptionStats::fHaveSeenInitialSequenceNumber [protected]

Definition at line 237 of file RTPSource.hh.

Referenced by init(), initSeqNum(), and noteIncomingPacket().

unsigned RTPReceptionStats::fBaseExtSeqNumReceived [protected]

Definition at line 238 of file RTPSource.hh.

Referenced by baseExtSeqNumReceived(), init(), initSeqNum(), noteIncomingPacket(), and totNumPacketsExpected().

unsigned RTPReceptionStats::fLastResetExtSeqNumReceived [protected]

Definition at line 239 of file RTPSource.hh.

Referenced by lastResetExtSeqNumReceived(), and reset().

unsigned RTPReceptionStats::fHighestExtSeqNumReceived [protected]

Definition at line 240 of file RTPSource.hh.

Referenced by highestExtSeqNumReceived(), init(), initSeqNum(), noteIncomingPacket(), reset(), and totNumPacketsExpected().

int RTPReceptionStats::fLastTransit [protected]

Definition at line 241 of file RTPSource.hh.

Referenced by init(), and noteIncomingPacket().

u_int32_t RTPReceptionStats::fPreviousPacketRTPTimestamp [protected]

Definition at line 242 of file RTPSource.hh.

Referenced by init(), and noteIncomingPacket().

double RTPReceptionStats::fJitter [protected]

Definition at line 243 of file RTPSource.hh.

Referenced by init(), jitter(), and noteIncomingPacket().

unsigned RTPReceptionStats::fLastReceivedSR_NTPmsw [protected]

Definition at line 245 of file RTPSource.hh.

Referenced by init(), lastReceivedSR_NTPmsw(), and noteIncomingSR().

unsigned RTPReceptionStats::fLastReceivedSR_NTPlsw [protected]

Definition at line 246 of file RTPSource.hh.

Referenced by init(), lastReceivedSR_NTPlsw(), and noteIncomingSR().

struct timeval RTPReceptionStats::fLastReceivedSR_time [read, protected]

Definition at line 247 of file RTPSource.hh.

Referenced by init(), lastReceivedSR_time(), and noteIncomingSR().

struct timeval RTPReceptionStats::fLastPacketReceptionTime [read, protected]

Definition at line 248 of file RTPSource.hh.

Referenced by init(), and noteIncomingPacket().

unsigned RTPReceptionStats::fMinInterPacketGapUS [protected]

Definition at line 249 of file RTPSource.hh.

Referenced by init(), minInterPacketGapUS(), and noteIncomingPacket().

unsigned RTPReceptionStats::fMaxInterPacketGapUS [protected]

Definition at line 249 of file RTPSource.hh.

Referenced by init(), maxInterPacketGapUS(), and noteIncomingPacket().

struct timeval RTPReceptionStats::fTotalInterPacketGaps [read, protected]

Definition at line 250 of file RTPSource.hh.

Referenced by init(), noteIncomingPacket(), and totalInterPacketGaps().

Boolean RTPReceptionStats::fHasBeenSynchronized [private]

Definition at line 254 of file RTPSource.hh.

Referenced by init(), noteIncomingPacket(), and noteIncomingSR().

u_int32_t RTPReceptionStats::fSyncTimestamp [private]

Definition at line 255 of file RTPSource.hh.

Referenced by noteIncomingPacket(), and noteIncomingSR().

struct timeval RTPReceptionStats::fSyncTime [read, private]

Definition at line 256 of file RTPSource.hh.

Referenced by init(), noteIncomingPacket(), and noteIncomingSR().


The documentation for this class was generated from the following files:
Generated on Mon Apr 29 13:32:29 2013 for live by  doxygen 1.5.2