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