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 Boolean& enableRTCPReports() { return fEnableRTCPReports; }
00063
00064 void setStreamSocket(int sockNum, unsigned char streamChannelId) {
00065
00066 fRTPInterface.setStreamSocket(sockNum, streamChannelId);
00067 }
00068 void setServerRequestAlternativeByteHandler(int socketNum, ServerRequestAlternativeByteHandler* handler, void* clientData) {
00069 fRTPInterface.setServerRequestAlternativeByteHandler(socketNum, handler, clientData);
00070 }
00071
00072 void setAuxilliaryReadHandler(AuxHandlerFunc* handlerFunc,
00073 void* handlerClientData) {
00074 fRTPInterface.setAuxilliaryReadHandler(handlerFunc,
00075 handlerClientData);
00076 }
00077
00078
00079
00080
00081 u_int16_t curPacketRTPSeqNum() const { return fCurPacketRTPSeqNum; }
00082 private: friend class MediaSubsession;
00083 u_int32_t curPacketRTPTimestamp() const { return fCurPacketRTPTimestamp; }
00084
00085 protected:
00086 RTPSource(UsageEnvironment& env, Groupsock* RTPgs,
00087 unsigned char rtpPayloadFormat, u_int32_t rtpTimestampFrequency);
00088
00089 virtual ~RTPSource();
00090
00091 protected:
00092 RTPInterface fRTPInterface;
00093 u_int16_t fCurPacketRTPSeqNum;
00094 u_int32_t fCurPacketRTPTimestamp;
00095 Boolean fCurPacketMarkerBit;
00096 Boolean fCurPacketHasBeenSynchronizedUsingRTCP;
00097 u_int32_t fLastReceivedSSRC;
00098
00099 private:
00100
00101 virtual Boolean isRTPSource() const;
00102 virtual void getAttributes() const;
00103
00104 private:
00105 unsigned char fRTPPayloadFormat;
00106 unsigned fTimestampFrequency;
00107 u_int32_t fSSRC;
00108 Boolean fEnableRTCPReports;
00109
00110 RTPReceptionStatsDB* fReceptionStatsDB;
00111 };
00112
00113
00114 class RTPReceptionStats;
00115
00116 class RTPReceptionStatsDB {
00117 public:
00118 unsigned totNumPacketsReceived() const { return fTotNumPacketsReceived; }
00119 unsigned numActiveSourcesSinceLastReset() const {
00120 return fNumActiveSourcesSinceLastReset;
00121 }
00122
00123 void reset();
00124
00125
00126
00127 class Iterator {
00128 public:
00129 Iterator(RTPReceptionStatsDB& receptionStatsDB);
00130 virtual ~Iterator();
00131
00132 RTPReceptionStats* next(Boolean includeInactiveSources = False);
00133
00134
00135 private:
00136 HashTable::Iterator* fIter;
00137 };
00138
00139
00140 void noteIncomingPacket(u_int32_t SSRC, u_int16_t seqNum,
00141 u_int32_t rtpTimestamp,
00142 unsigned timestampFrequency,
00143 Boolean useForJitterCalculation,
00144 struct timeval& resultPresentationTime,
00145 Boolean& resultHasBeenSyncedUsingRTCP,
00146 unsigned packetSize );
00147
00148
00149 void noteIncomingSR(u_int32_t SSRC,
00150 u_int32_t ntpTimestampMSW, u_int32_t ntpTimestampLSW,
00151 u_int32_t rtpTimestamp);
00152
00153
00154 void removeRecord(u_int32_t SSRC);
00155
00156 RTPReceptionStats* lookup(u_int32_t SSRC) const;
00157
00158 protected:
00159 friend class RTPSource;
00160 RTPReceptionStatsDB();
00161 virtual ~RTPReceptionStatsDB();
00162
00163 protected:
00164 void add(u_int32_t SSRC, RTPReceptionStats* stats);
00165
00166 protected:
00167 friend class Iterator;
00168 unsigned fNumActiveSourcesSinceLastReset;
00169
00170 private:
00171 HashTable* fTable;
00172 unsigned fTotNumPacketsReceived;
00173 };
00174
00175 class RTPReceptionStats {
00176 public:
00177 u_int32_t SSRC() const { return fSSRC; }
00178 unsigned numPacketsReceivedSinceLastReset() const {
00179 return fNumPacketsReceivedSinceLastReset;
00180 }
00181 unsigned totNumPacketsReceived() const { return fTotNumPacketsReceived; }
00182 double totNumKBytesReceived() const;
00183
00184 unsigned totNumPacketsExpected() const {
00185 return (fHighestExtSeqNumReceived - fBaseExtSeqNumReceived) + 1;
00186 }
00187
00188 unsigned baseExtSeqNumReceived() const { return fBaseExtSeqNumReceived; }
00189 unsigned lastResetExtSeqNumReceived() const {
00190 return fLastResetExtSeqNumReceived;
00191 }
00192 unsigned highestExtSeqNumReceived() const {
00193 return fHighestExtSeqNumReceived;
00194 }
00195
00196 unsigned jitter() const;
00197
00198 unsigned lastReceivedSR_NTPmsw() const { return fLastReceivedSR_NTPmsw; }
00199 unsigned lastReceivedSR_NTPlsw() const { return fLastReceivedSR_NTPlsw; }
00200 struct timeval const& lastReceivedSR_time() const {
00201 return fLastReceivedSR_time;
00202 }
00203
00204 unsigned minInterPacketGapUS() const { return fMinInterPacketGapUS; }
00205 unsigned maxInterPacketGapUS() const { return fMaxInterPacketGapUS; }
00206 struct timeval const& totalInterPacketGaps() const {
00207 return fTotalInterPacketGaps;
00208 }
00209
00210 protected:
00211
00212 friend class RTPReceptionStatsDB;
00213 RTPReceptionStats(u_int32_t SSRC, u_int16_t initialSeqNum);
00214 RTPReceptionStats(u_int32_t SSRC);
00215 virtual ~RTPReceptionStats();
00216
00217 private:
00218 void noteIncomingPacket(u_int16_t seqNum, u_int32_t rtpTimestamp,
00219 unsigned timestampFrequency,
00220 Boolean useForJitterCalculation,
00221 struct timeval& resultPresentationTime,
00222 Boolean& resultHasBeenSyncedUsingRTCP,
00223 unsigned packetSize );
00224 void noteIncomingSR(u_int32_t ntpTimestampMSW, u_int32_t ntpTimestampLSW,
00225 u_int32_t rtpTimestamp);
00226 void init(u_int32_t SSRC);
00227 void initSeqNum(u_int16_t initialSeqNum);
00228 void reset();
00229
00230
00231
00232 protected:
00233 u_int32_t fSSRC;
00234 unsigned fNumPacketsReceivedSinceLastReset;
00235 unsigned fTotNumPacketsReceived;
00236 u_int32_t fTotBytesReceived_hi, fTotBytesReceived_lo;
00237 Boolean fHaveSeenInitialSequenceNumber;
00238 unsigned fBaseExtSeqNumReceived;
00239 unsigned fLastResetExtSeqNumReceived;
00240 unsigned fHighestExtSeqNumReceived;
00241 int fLastTransit;
00242 u_int32_t fPreviousPacketRTPTimestamp;
00243 double fJitter;
00244
00245 unsigned fLastReceivedSR_NTPmsw;
00246 unsigned fLastReceivedSR_NTPlsw;
00247 struct timeval fLastReceivedSR_time;
00248 struct timeval fLastPacketReceptionTime;
00249 unsigned fMinInterPacketGapUS, fMaxInterPacketGapUS;
00250 struct timeval fTotalInterPacketGaps;
00251
00252 private:
00253
00254 Boolean fHasBeenSynchronized;
00255 u_int32_t fSyncTimestamp;
00256 struct timeval fSyncTime;
00257 };
00258
00259
00260 Boolean seqNumLT(u_int16_t s1, u_int16_t s2);
00261
00262
00263 #endif