jrtplib 3.7.1
|
00001 /* 00002 00003 This file is a part of JRTPLIB 00004 Copyright (c) 1999-2007 Jori Liesenborgs 00005 00006 Contact: jori.liesenborgs@gmail.com 00007 00008 This library was developed at the "Expertisecentrum Digitale Media" 00009 (http://www.edm.uhasselt.be), a research center of the Hasselt University 00010 (http://www.uhasselt.be). The library is based upon work done for 00011 my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 00012 00013 Permission is hereby granted, free of charge, to any person obtaining a 00014 copy of this software and associated documentation files (the "Software"), 00015 to deal in the Software without restriction, including without limitation 00016 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00017 and/or sell copies of the Software, and to permit persons to whom the 00018 Software is furnished to do so, subject to the following conditions: 00019 00020 The above copyright notice and this permission notice shall be included 00021 in all copies or substantial portions of the Software. 00022 00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00024 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00026 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00028 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 00029 IN THE SOFTWARE. 00030 00031 */ 00032 00037 #ifndef RTPSOURCES_H 00038 00039 #define RTPSOURCES_H 00040 00041 #include "rtpconfig.h" 00042 #include "rtpkeyhashtable.h" 00043 #include "rtcpsdespacket.h" 00044 #include "rtptypes.h" 00045 #include "rtpmemoryobject.h" 00046 00047 #define RTPSOURCES_HASHSIZE 8317 00048 00049 class RTPSources_GetHashIndex 00050 { 00051 public: 00052 static int GetIndex(const uint32_t &ssrc) { return ssrc%RTPSOURCES_HASHSIZE; } 00053 }; 00054 00055 class RTPNTPTime; 00056 class RTPTransmitter; 00057 class RTCPAPPPacket; 00058 class RTPInternalSourceData; 00059 class RTPRawPacket; 00060 class RTPPacket; 00061 class RTPTime; 00062 class RTPAddress; 00063 class RTPSourceData; 00064 00071 class RTPSources : public RTPMemoryObject 00072 { 00073 public: 00075 enum ProbationType 00076 { 00077 NoProbation, 00078 ProbationDiscard, 00079 ProbationStore 00080 }; 00081 00083 RTPSources(ProbationType = ProbationStore,RTPMemoryManager *mgr = 0); 00084 virtual ~RTPSources(); 00085 00087 void Clear(); 00088 #ifdef RTP_SUPPORT_PROBATION 00089 00090 void SetProbationType(ProbationType probtype) { probationtype = probtype; } 00091 #endif // RTP_SUPPORT_PROBATION 00092 00094 int CreateOwnSSRC(uint32_t ssrc); 00095 00097 int DeleteOwnSSRC(); 00098 00103 void SentRTPPacket(); 00104 00110 int ProcessRawPacket(RTPRawPacket *rawpack,RTPTransmitter *trans,bool acceptownpackets); 00111 00117 int ProcessRawPacket(RTPRawPacket *rawpack,RTPTransmitter *trans[],int numtrans,bool acceptownpackets); 00118 00126 int ProcessRTPPacket(RTPPacket *rtppack,const RTPTime &receivetime,const RTPAddress *senderaddress,bool *stored); 00127 00132 int ProcessRTCPCompoundPacket(RTCPCompoundPacket *rtcpcomppack,const RTPTime &receivetime, 00133 const RTPAddress *senderaddress); 00134 00140 int ProcessRTCPSenderInfo(uint32_t ssrc,const RTPNTPTime &ntptime,uint32_t rtptime, 00141 uint32_t packetcount,uint32_t octetcount,const RTPTime &receivetime, 00142 const RTPAddress *senderaddress); 00143 00149 int ProcessRTCPReportBlock(uint32_t ssrc,uint8_t fractionlost,int32_t lostpackets, 00150 uint32_t exthighseqnr,uint32_t jitter,uint32_t lsr, 00151 uint32_t dlsr,const RTPTime &receivetime,const RTPAddress *senderaddress); 00152 00158 int ProcessSDESNormalItem(uint32_t ssrc,RTCPSDESPacket::ItemType t,size_t itemlength, 00159 const void *itemdata,const RTPTime &receivetime,const RTPAddress *senderaddress); 00160 #ifdef RTP_SUPPORT_SDESPRIV 00161 00166 int ProcessSDESPrivateItem(uint32_t ssrc,size_t prefixlen,const void *prefixdata, 00167 size_t valuelen,const void *valuedata,const RTPTime &receivetime, 00168 const RTPAddress *senderaddress); 00169 #endif //RTP_SUPPORT_SDESPRIV 00170 00175 int ProcessBYE(uint32_t ssrc,size_t reasonlength,const void *reasondata,const RTPTime &receivetime, 00176 const RTPAddress *senderaddress); 00177 00187 int UpdateReceiveTime(uint32_t ssrc,const RTPTime &receivetime,const RTPAddress *senderaddress); 00188 00193 bool GotoFirstSource(); 00194 00199 bool GotoNextSource(); 00200 00205 bool GotoPreviousSource(); 00206 00213 bool GotoFirstSourceWithData(); 00214 00221 bool GotoNextSourceWithData(); 00222 00229 bool GotoPreviousSourceWithData(); 00230 00232 RTPSourceData *GetCurrentSourceInfo(); 00233 00237 RTPSourceData *GetSourceInfo(uint32_t ssrc); 00238 00240 RTPPacket *GetNextPacket(); 00241 00243 bool GotEntry(uint32_t ssrc); 00244 00246 RTPSourceData *GetOwnSourceInfo() { return (RTPSourceData *)owndata; } 00247 00251 void Timeout(const RTPTime &curtime,const RTPTime &timeoutdelay); 00252 00256 void SenderTimeout(const RTPTime &curtime,const RTPTime &timeoutdelay); 00257 00261 void BYETimeout(const RTPTime &curtime,const RTPTime &timeoutdelay); 00262 00266 void NoteTimeout(const RTPTime &curtime,const RTPTime &timeoutdelay); 00267 00272 void MultipleTimeouts(const RTPTime &curtime,const RTPTime &sendertimeout, 00273 const RTPTime &byetimeout,const RTPTime &generaltimeout, 00274 const RTPTime ¬etimeout); 00275 00277 int GetSenderCount() const { return sendercount; } 00278 00280 int GetTotalCount() const { return totalcount; } 00281 00283 int GetActiveMemberCount() const { return activecount; } 00284 #ifdef RTPDEBUG 00285 void Dump(); 00286 void SafeCountTotal(); 00287 void SafeCountSenders(); 00288 void SafeCountActive(); 00289 #endif // RTPDEBUG 00290 protected: 00292 virtual void OnRTPPacket(RTPPacket *pack,const RTPTime &receivetime, const RTPAddress *senderaddress) { } 00293 00295 virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack,const RTPTime &receivetime, 00296 const RTPAddress *senderaddress) { } 00297 00303 virtual void OnSSRCCollision(RTPSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp) { } 00304 00306 virtual void OnCNAMECollision(RTPSourceData *srcdat,const RTPAddress *senderaddress, 00307 const uint8_t *cname,size_t cnamelength) { } 00308 00310 virtual void OnNewSource(RTPSourceData *srcdat) { } 00311 00313 virtual void OnRemoveSource(RTPSourceData *srcdat) { } 00314 00316 virtual void OnTimeout(RTPSourceData *srcdat) { } 00317 00319 virtual void OnBYETimeout(RTPSourceData *srcdat) { } 00320 00322 virtual void OnBYEPacket(RTPSourceData *srcdat) { } 00323 00327 virtual void OnAPPPacket(RTCPAPPPacket *apppacket,const RTPTime &receivetime, 00328 const RTPAddress *senderaddress) { } 00329 00331 virtual void OnUnknownPacketType(RTCPPacket *rtcppack,const RTPTime &receivetime, 00332 const RTPAddress *senderaddress) { } 00333 00335 virtual void OnUnknownPacketFormat(RTCPPacket *rtcppack,const RTPTime &receivetime, 00336 const RTPAddress *senderaddress) { } 00337 00339 virtual void OnNoteTimeout(RTPSourceData *srcdat) { } 00340 private: 00341 void ClearSourceList(); 00342 int ObtainSourceDataInstance(uint32_t ssrc,RTPInternalSourceData **srcdat,bool *created); 00343 int GetRTCPSourceData(uint32_t ssrc,const RTPAddress *senderaddress,RTPInternalSourceData **srcdat,bool *newsource); 00344 bool CheckCollision(RTPInternalSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp); 00345 00346 RTPKeyHashTable<const uint32_t,RTPInternalSourceData*,RTPSources_GetHashIndex,RTPSOURCES_HASHSIZE> sourcelist; 00347 00348 int sendercount; 00349 int totalcount; 00350 int activecount; 00351 00352 #ifdef RTP_SUPPORT_PROBATION 00353 ProbationType probationtype; 00354 #endif // RTP_SUPPORT_PROBATION 00355 00356 RTPInternalSourceData *owndata; 00357 }; 00358 00359 #endif // RTPSOURCES_H 00360