00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _RTP_SOURCE_HH
00022 #define _RTP_SOURCE_HH
00023
00024 #ifndef _FRAMED_SOURCE_HH
00025 #include "FramedSource.hh"
00026 #endif
00027 #ifndef _RTP_INTERFACE_HH
00028 #include "RTPInterface.hh"
00029 #endif
00030
00031 class RTPReceptionStatsDB;
00032
00033 class RTPSource: public FramedSource {
00034 public:
00035 static Boolean lookupByName(UsageEnvironment& env, char const* sourceName,
00036 RTPSource*& resultSource);
00037
00038 Boolean curPacketMarkerBit() const { return fCurPacketMarkerBit; }
00039
00040 unsigned char rtpPayloadFormat() const { return fRTPPayloadFormat; }
00041
00042 virtual Boolean hasBeenSynchronizedUsingRTCP();
00043
00044 Groupsock* RTPgs() const { return fRTPInterface.gs(); }
00045
00046 virtual void setPacketReorderingThresholdTime(unsigned uSeconds) = 0;
00047
00048
00049 u_int32_t SSRC() const { return fSSRC; }
00050
00051
00052
00053 unsigned timestampFrequency() const {return fTimestampFrequency;}
00054
00055 RTPReceptionStatsDB& receptionStatsDB() const {
00056 return *fReceptionStatsDB;
00057 }
00058
00059 u_int32_t lastReceivedSSRC() const { return fLastReceivedSSRC; }
00060
00061
00062 void setStreamSocket(int sockNum, unsigned char streamChannelId) {
00063
00064 fRTPInterface.setStreamSocket(sockNum, streamChannelId);
00065 }
00066
00067 void setAuxilliaryReadHandler(AuxHandlerFunc* handlerFunc,
00068 void* handlerClientData) {
00069 fRTPInterface.setAuxilliaryReadHandler(handlerFunc,
00070 handlerClientData);
00071 }
00072
00073
00074
00075
00076 u_int16_t curPacketRTPSeqNum() const { return fCurPacketRTPSeqNum; }
00077 u_int32_t curPacketRTPTimestamp() const { return fCurPacketRTPTimestamp; }
00078
00079 protected:
00080 RTPSource(UsageEnvironment& env, Groupsock* RTPgs,
00081 unsigned char rtpPayloadFormat, u_int32_t rtpTimestampFrequency);
00082
00083 virtual ~RTPSource();
00084
00085 protected:
00086 RTPInterface fRTPInterface;
00087 u_int16_t fCurPacketRTPSeqNum;
00088 u_int32_t fCurPacketRTPTimestamp;
00089 Boolean fCurPacketMarkerBit;
00090 Boolean fCurPacketHasBeenSynchronizedUsingRTCP;
00091 u_int32_t fLastReceivedSSRC;
00092
00093 private:
00094
00095 virtual Boolean isRTPSource() const;
00096 virtual void getAttributes() const;
00097
00098 private:
00099 unsigned char fRTPPayloadFormat;
00100 unsigned fTimestampFrequency;
00101 u_int32_t fSSRC;
00102
00103 RTPReceptionStatsDB* fReceptionStatsDB;
00104 };
00105
00106
00107 class RTPReceptionStats;
00108
00109 class RTPReceptionStatsDB {
00110 public:
00111 unsigned totNumPacketsReceived() const { return fTotNumPacketsReceived; }
00112 unsigned numActiveSourcesSinceLastReset() const {
00113 return fNumActiveSourcesSinceLastReset;
00114 }
00115
00116 void reset();
00117
00118
00119
00120 class Iterator {
00121 public:
00122 Iterator(RTPReceptionStatsDB& receptionStatsDB);
00123 virtual ~Iterator();
00124
00125 RTPReceptionStats* next(Boolean includeInactiveSources = False);
00126
00127
00128 private:
00129 HashTable::Iterator* fIter;
00130 };
00131
00132
00133 void noteIncomingPacket(u_int32_t SSRC, u_int16_t seqNum,
00134 u_int32_t rtpTimestamp,
00135 unsigned timestampFrequency,
00136 Boolean useForJitterCalculation,
00137 struct timeval& resultPresentationTime,
00138 Boolean& resultHasBeenSyncedUsingRTCP,
00139 unsigned packetSize );
00140
00141
00142 void noteIncomingSR(u_int32_t SSRC,
00143 u_int32_t ntpTimestampMSW, u_int32_t ntpTimestampLSW,
00144 u_int32_t rtpTimestamp);
00145
00146
00147 void removeRecord(u_int32_t SSRC);
00148
00149 RTPReceptionStats* lookup(u_int32_t SSRC) const;
00150
00151 protected:
00152 friend class RTPSource;
00153 RTPReceptionStatsDB(RTPSource& rtpSource);
00154 virtual ~RTPReceptionStatsDB();
00155
00156 protected:
00157 void add(u_int32_t SSRC, RTPReceptionStats* stats);
00158
00159 protected:
00160 friend class Iterator;
00161 RTPSource& fOurRTPSource;
00162 unsigned fNumActiveSourcesSinceLastReset;
00163
00164 private:
00165 HashTable* fTable;
00166 unsigned fTotNumPacketsReceived;
00167 };
00168
00169 class RTPReceptionStats {
00170 public:
00171 u_int32_t SSRC() const { return fSSRC; }
00172 unsigned numPacketsReceivedSinceLastReset() const {
00173 return fNumPacketsReceivedSinceLastReset;
00174 }
00175 unsigned totNumPacketsReceived() const { return fTotNumPacketsReceived; }
00176 double totNumKBytesReceived() const;
00177
00178 unsigned totNumPacketsExpected() const {
00179 return fHighestExtSeqNumReceived - fBaseExtSeqNumReceived;
00180 }
00181
00182 unsigned baseExtSeqNumReceived() const { return fBaseExtSeqNumReceived; }
00183 unsigned lastResetExtSeqNumReceived() const {
00184 return fLastResetExtSeqNumReceived;
00185 }
00186 unsigned highestExtSeqNumReceived() const {
00187 return fHighestExtSeqNumReceived;
00188 }
00189
00190 unsigned jitter() const;
00191
00192 unsigned lastReceivedSR_NTPmsw() const { return fLastReceivedSR_NTPmsw; }
00193 unsigned lastReceivedSR_NTPlsw() const { return fLastReceivedSR_NTPlsw; }
00194 struct timeval const& lastReceivedSR_time() const {
00195 return fLastReceivedSR_time;
00196 }
00197
00198 unsigned minInterPacketGapUS() const { return fMinInterPacketGapUS; }
00199 unsigned maxInterPacketGapUS() const { return fMaxInterPacketGapUS; }
00200 struct timeval const& totalInterPacketGaps() const {
00201 return fTotalInterPacketGaps;
00202 }
00203
00204 protected:
00205
00206 friend class RTPReceptionStatsDB;
00207 RTPReceptionStats(RTPSource& rtpSource, u_int32_t SSRC,
00208 u_int16_t initialSeqNum);
00209 RTPReceptionStats(RTPSource& rtpSource, u_int32_t SSRC);
00210 virtual ~RTPReceptionStats();
00211
00212 private:
00213 void noteIncomingPacket(u_int16_t seqNum, u_int32_t rtpTimestamp,
00214 unsigned timestampFrequency,
00215 Boolean useForJitterCalculation,
00216 struct timeval& resultPresentationTime,
00217 Boolean& resultHasBeenSyncedUsingRTCP,
00218 unsigned packetSize );
00219 void noteIncomingSR(u_int32_t ntpTimestampMSW, u_int32_t ntpTimestampLSW,
00220 u_int32_t rtpTimestamp);
00221 void init(u_int32_t SSRC);
00222 void initSeqNum(u_int16_t initialSeqNum);
00223 void reset();
00224
00225
00226
00227 protected:
00228 RTPSource& fOurRTPSource;
00229 u_int32_t fSSRC;
00230 unsigned fNumPacketsReceivedSinceLastReset;
00231 unsigned fTotNumPacketsReceived;
00232 u_int32_t fTotBytesReceived_hi, fTotBytesReceived_lo;
00233 Boolean fHaveSeenInitialSequenceNumber;
00234 unsigned fBaseExtSeqNumReceived;
00235 unsigned fLastResetExtSeqNumReceived;
00236 unsigned fHighestExtSeqNumReceived;
00237 int fLastTransit;
00238 u_int32_t fPreviousPacketRTPTimestamp;
00239 double fJitter;
00240
00241 unsigned fLastReceivedSR_NTPmsw;
00242 unsigned fLastReceivedSR_NTPlsw;
00243 struct timeval fLastReceivedSR_time;
00244 struct timeval fLastPacketReceptionTime;
00245 unsigned fMinInterPacketGapUS, fMaxInterPacketGapUS;
00246 struct timeval fTotalInterPacketGaps;
00247
00248 private:
00249
00250 Boolean fHasBeenSynchronized;
00251 u_int32_t fSyncTimestamp;
00252 struct timeval fSyncTime;
00253 };
00254
00255
00256 Boolean seqNumLT(u_int16_t s1, u_int16_t s2);
00257
00258
00259 #endif