jrtplib  3.6.0
rtpsources.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2006 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the "Expertisecentrum Digitale Media"
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31 */
32 
37 #ifndef RTPSOURCES_H
38 
39 #define RTPSOURCES_H
40 
41 #include "rtpconfig.h"
42 #include "rtpkeyhashtable.h"
43 #include "rtcpsdespacket.h"
44 #include "rtptypes.h"
45 #include "rtpmemoryobject.h"
46 
47 #define RTPSOURCES_HASHSIZE 8317
48 
49 class RTPSources_GetHashIndex
50 {
51 public:
52  static int GetIndex(const uint32_t &ssrc) { return ssrc%RTPSOURCES_HASHSIZE; }
53 };
54 
55 class RTPNTPTime;
56 class RTPTransmitter;
57 class RTCPAPPPacket;
58 class RTPInternalSourceData;
59 class RTPRawPacket;
60 class RTPPacket;
61 class RTPTime;
62 class RTPAddress;
63 class RTPSourceData;
64 
71 class RTPSources : public RTPMemoryObject
72 {
73 public:
76  {
80  };
81 
84  virtual ~RTPSources();
85 
87  void Clear();
88 #ifdef RTP_SUPPORT_PROBATION
89 
90  void SetProbationType(ProbationType probtype) { probationtype = probtype; }
91 #endif // RTP_SUPPORT_PROBATION
92 
94  int CreateOwnSSRC(uint32_t ssrc);
95 
97  int DeleteOwnSSRC();
98 
103  void SentRTPPacket();
104 
110  int ProcessRawPacket(RTPRawPacket *rawpack,RTPTransmitter *trans,bool acceptownpackets);
111 
117  int ProcessRawPacket(RTPRawPacket *rawpack,RTPTransmitter *trans[],int numtrans,bool acceptownpackets);
118 
126  int ProcessRTPPacket(RTPPacket *rtppack,const RTPTime &receivetime,const RTPAddress *senderaddress,bool *stored);
127 
132  int ProcessRTCPCompoundPacket(RTCPCompoundPacket *rtcpcomppack,const RTPTime &receivetime,
133  const RTPAddress *senderaddress);
134 
140  int ProcessRTCPSenderInfo(uint32_t ssrc,const RTPNTPTime &ntptime,uint32_t rtptime,
141  uint32_t packetcount,uint32_t octetcount,const RTPTime &receivetime,
142  const RTPAddress *senderaddress);
143 
149  int ProcessRTCPReportBlock(uint32_t ssrc,uint8_t fractionlost,int32_t lostpackets,
150  uint32_t exthighseqnr,uint32_t jitter,uint32_t lsr,
151  uint32_t dlsr,const RTPTime &receivetime,const RTPAddress *senderaddress);
152 
158  int ProcessSDESNormalItem(uint32_t ssrc,RTCPSDESPacket::ItemType t,size_t itemlength,
159  const void *itemdata,const RTPTime &receivetime,const RTPAddress *senderaddress);
160 #ifdef RTP_SUPPORT_SDESPRIV
161 
166  int ProcessSDESPrivateItem(uint32_t ssrc,size_t prefixlen,const void *prefixdata,
167  size_t valuelen,const void *valuedata,const RTPTime &receivetime,
168  const RTPAddress *senderaddress);
169 #endif //RTP_SUPPORT_SDESPRIV
170 
175  int ProcessBYE(uint32_t ssrc,size_t reasonlength,const void *reasondata,const RTPTime &receivetime,
176  const RTPAddress *senderaddress);
177 
187  int UpdateReceiveTime(uint32_t ssrc,const RTPTime &receivetime,const RTPAddress *senderaddress);
188 
193  bool GotoFirstSource();
194 
199  bool GotoNextSource();
200 
205  bool GotoPreviousSource();
206 
214 
221  bool GotoNextSourceWithData();
222 
230 
233 
237  RTPSourceData *GetSourceInfo(uint32_t ssrc);
238 
241 
243  bool GotEntry(uint32_t ssrc);
244 
246  RTPSourceData *GetOwnSourceInfo() { return (RTPSourceData *)owndata; }
247 
251  void Timeout(const RTPTime &curtime,const RTPTime &timeoutdelay);
252 
256  void SenderTimeout(const RTPTime &curtime,const RTPTime &timeoutdelay);
257 
261  void BYETimeout(const RTPTime &curtime,const RTPTime &timeoutdelay);
262 
266  void NoteTimeout(const RTPTime &curtime,const RTPTime &timeoutdelay);
267 
272  void MultipleTimeouts(const RTPTime &curtime,const RTPTime &sendertimeout,
273  const RTPTime &byetimeout,const RTPTime &generaltimeout,
274  const RTPTime &notetimeout);
275 
277  int GetSenderCount() const { return sendercount; }
278 
280  int GetTotalCount() const { return totalcount; }
281 
283  int GetActiveMemberCount() const { return activecount; }
284 #ifdef RTPDEBUG
285  void Dump();
286  void SafeCountTotal();
287  void SafeCountSenders();
288  void SafeCountActive();
289 #endif // RTPDEBUG
290 protected:
292  virtual void OnRTPPacket(RTPPacket *pack,const RTPTime &receivetime, const RTPAddress *senderaddress) { }
293 
295  virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack,const RTPTime &receivetime,
296  const RTPAddress *senderaddress) { }
297 
303  virtual void OnSSRCCollision(RTPSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp) { }
304 
306  virtual void OnCNAMECollision(RTPSourceData *srcdat,const RTPAddress *senderaddress,
307  const uint8_t *cname,size_t cnamelength) { }
308 
310  virtual void OnNewSource(RTPSourceData *srcdat) { }
311 
313  virtual void OnRemoveSource(RTPSourceData *srcdat) { }
314 
316  virtual void OnTimeout(RTPSourceData *srcdat) { }
317 
319  virtual void OnBYETimeout(RTPSourceData *srcdat) { }
320 
322  virtual void OnBYEPacket(RTPSourceData *srcdat) { }
323 
327  virtual void OnAPPPacket(RTCPAPPPacket *apppacket,const RTPTime &receivetime,
328  const RTPAddress *senderaddress) { }
329 
331  virtual void OnUnknownPacketType(RTCPPacket *rtcppack,const RTPTime &receivetime,
332  const RTPAddress *senderaddress) { }
333 
335  virtual void OnUnknownPacketFormat(RTCPPacket *rtcppack,const RTPTime &receivetime,
336  const RTPAddress *senderaddress) { }
337 
339  virtual void OnNoteTimeout(RTPSourceData *srcdat) { }
340 private:
341  void ClearSourceList();
342  int ObtainSourceDataInstance(uint32_t ssrc,RTPInternalSourceData **srcdat,bool *created);
343  int GetRTCPSourceData(uint32_t ssrc,const RTPAddress *senderaddress,RTPInternalSourceData **srcdat,bool *newsource);
344  bool CheckCollision(RTPInternalSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp);
345 
346  RTPKeyHashTable<const uint32_t,RTPInternalSourceData*,RTPSources_GetHashIndex,RTPSOURCES_HASHSIZE> sourcelist;
347 
348  int sendercount;
349  int totalcount;
350  int activecount;
351 
352 #ifdef RTP_SUPPORT_PROBATION
353  ProbationType probationtype;
354 #endif // RTP_SUPPORT_PROBATION
355 
356  RTPInternalSourceData *owndata;
357 };
358 
359 #endif // RTPSOURCES_H
360 
int ProcessRawPacket(RTPRawPacket *rawpack, RTPTransmitter *trans, bool acceptownpackets)
Processes a raw packet rawpack.
Store incoming RTP packet from a source that's on probation for later retrieval.
Definition: rtpsources.h:79
bool GotoPreviousSource()
Sets the current source to be the previous source in the table.
void Timeout(const RTPTime &curtime, const RTPTime &timeoutdelay)
Assuming that the current time is curtime, time out the members from whom we haven't heard during the...
int ProcessRTPPacket(RTPPacket *rtppack, const RTPTime &receivetime, const RTPAddress *senderaddress, bool *stored)
Processes an RTPPacket instance rtppack which was received at time receivetime and which originated f...
virtual void OnBYETimeout(RTPSourceData *srcdat)
Is called when participant srcdat is timed after having sent a BYE packet.
Definition: rtpsources.h:319
int ProcessSDESNormalItem(uint32_t ssrc, RTCPSDESPacket::ItemType t, size_t itemlength, const void *itemdata, const RTPTime &receivetime, const RTPAddress *senderaddress)
Processes the non-private SDES item from source ssrc into the source table.
bool GotoFirstSource()
Starts the iteration over the participants by going to the first member in the table.
Represents an RTP Packet.
Definition: rtppacket.h:53
virtual void OnNewSource(RTPSourceData *srcdat)
Is called when a new entry srcdat is added to the source table.
Definition: rtpsources.h:310
RTPSourceData * GetCurrentSourceInfo()
Returns the RTPSourceData instance for the currently selected participant.
Don't use the probation algorithm; accept RTP packets immediately.
Definition: rtpsources.h:77
int GetTotalCount() const
Returns the total number of entries in the source table.
Definition: rtpsources.h:280
A memory manager.
Definition: rtpmemorymanager.h:144
void SetProbationType(ProbationType probtype)
Changes the current probation type.
Definition: rtpsources.h:90
Represents a table in which information about the participating sources is kept.
Definition: rtpsources.h:71
virtual void OnBYEPacket(RTPSourceData *srcdat)
Is called when a BYE packet has been processed for source srcdat.
Definition: rtpsources.h:322
bool GotoFirstSourceWithData()
Sets the current source to be the first source in the table which has RTPPacket instances that we hav...
virtual void OnAPPPacket(RTCPAPPPacket *apppacket, const RTPTime &receivetime, const RTPAddress *senderaddress)
Is called when an RTCP APP packet apppacket has been received at time receivetime from address sender...
Definition: rtpsources.h:327
virtual void OnUnknownPacketFormat(RTCPPacket *rtcppack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Is called when an unknown packet format for a known packet type was detected.
Definition: rtpsources.h:335
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
Describes an RTCP APP packet.
Definition: rtcpapppacket.h:51
Base class for specific types of RTCP packets.
Definition: rtcppacket.h:47
virtual void OnUnknownPacketType(RTCPPacket *rtcppack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Is called when an unknown RTCP packet type was detected.
Definition: rtpsources.h:331
virtual void OnTimeout(RTPSourceData *srcdat)
Is called when participant srcdat is timed out.
Definition: rtpsources.h:316
RTPPacket * GetNextPacket()
Extracts the next packet from the received packets queue of the current participant.
void BYETimeout(const RTPTime &curtime, const RTPTime &timeoutdelay)
Assuming that the current time is curtime, remove the members who sent a BYE packet more than the tim...
Represents an RTCP compound packet.
Definition: rtcpcompoundpacket.h:50
RTPSources(ProbationType=ProbationStore, RTPMemoryManager *mgr=0)
In the constructor you can select the probation type you'd like to use and also a memory manager...
bool GotEntry(uint32_t ssrc)
Returns true if an entry for participant ssrc exists and false otherwise.
void Clear()
Clears the source table.
ProbationType
Type of probation to use for new sources.
Definition: rtpsources.h:75
virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Is called when an RTCP compound packet is about to be processed.
Definition: rtpsources.h:295
void MultipleTimeouts(const RTPTime &curtime, const RTPTime &sendertimeout, const RTPTime &byetimeout, const RTPTime &generaltimeout, const RTPTime &notetimeout)
Combines the functions SenderTimeout, BYETimeout, Timeout and NoteTimeout.
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:48
RTPSourceData * GetOwnSourceInfo()
If present, it returns the RTPSourceData instance of the entry which was created by CreateOwnSSRC...
Definition: rtpsources.h:246
int ProcessRTCPSenderInfo(uint32_t ssrc, const RTPNTPTime &ntptime, uint32_t rtptime, uint32_t packetcount, uint32_t octetcount, const RTPTime &receivetime, const RTPAddress *senderaddress)
Process the sender information of SSRC ssrc into the source table.
bool GotoPreviousSourceWithData()
Sets the current source to be the previous source in the table which has RTPPacket instances that we ...
int CreateOwnSSRC(uint32_t ssrc)
Creates an entry for our own SSRC identifier.
bool GotoNextSource()
Sets the current source to be the next source in the table.
virtual void OnSSRCCollision(RTPSourceData *srcdat, const RTPAddress *senderaddress, bool isrtp)
Is called when an SSRC collision was detected.
Definition: rtpsources.h:303
bool GotoNextSourceWithData()
Sets the current source to be the next source in the table which has RTPPacket instances that we have...
virtual void OnCNAMECollision(RTPSourceData *srcdat, const RTPAddress *senderaddress, const uint8_t *cname, size_t cnamelength)
Is called when another CNAME was received than the one already present for source srcdat...
Definition: rtpsources.h:306
int GetActiveMemberCount() const
Returns the number of members which have been validated and which haven't sent a BYE packet yet...
Definition: rtpsources.h:283
int UpdateReceiveTime(uint32_t ssrc, const RTPTime &receivetime, const RTPAddress *senderaddress)
If we heard from source ssrc, but no actual data was added to the source table (for example...
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:57
ItemType
Identifies the type of an SDES item.
Definition: rtcpsdespacket.h:56
int ProcessSDESPrivateItem(uint32_t ssrc, size_t prefixlen, const void *prefixdata, size_t valuelen, const void *valuedata, const RTPTime &receivetime, const RTPAddress *senderaddress)
Processes the SDES private item from source ssrc into the source table.
void SenderTimeout(const RTPTime &curtime, const RTPTime &timeoutdelay)
Assuming that the current time is curtime, remove the sender flag for senders from whom we haven't re...
int ProcessRTCPReportBlock(uint32_t ssrc, uint8_t fractionlost, int32_t lostpackets, uint32_t exthighseqnr, uint32_t jitter, uint32_t lsr, uint32_t dlsr, const RTPTime &receivetime, const RTPAddress *senderaddress)
Processes the report block information which was sent by participant ssrc into the source table...
void SentRTPPacket()
This function should be called if our own session has sent an RTP packet.
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:47
virtual void OnRemoveSource(RTPSourceData *srcdat)
Is called when the entry srcdat is about to be deleted from the source table.
Definition: rtpsources.h:313
int ProcessRTCPCompoundPacket(RTCPCompoundPacket *rtcpcomppack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Processes the RTCP compound packet rtcpcomppack which was received at time receivetime from senderadd...
virtual void OnRTPPacket(RTPPacket *pack, const RTPTime &receivetime, const RTPAddress *senderaddress)
Is called when an RTP packet is about to be processed.
Definition: rtpsources.h:292
RTPSourceData * GetSourceInfo(uint32_t ssrc)
Returns the RTPSourceData instance for the participant identified by ssrc, or NULL if no such entry e...
int GetSenderCount() const
Returns the number of participants which are marked as a sender.
Definition: rtpsources.h:277
Discard incoming RTP packets originating from a source that's on probation.
Definition: rtpsources.h:78
virtual void OnNoteTimeout(RTPSourceData *srcdat)
Is called when the SDES NOTE item for source srcdat has been timed out.
Definition: rtpsources.h:339
void NoteTimeout(const RTPTime &curtime, const RTPTime &timeoutdelay)
Assuming that the current time is curtime, clear the SDES NOTE items which haven't been updated durin...
int ProcessBYE(uint32_t ssrc, size_t reasonlength, const void *reasondata, const RTPTime &receivetime, const RTPAddress *senderaddress)
Processes the BYE message for SSRC ssrc.
This is a simple wrapper for the most significant word (MSW) and least significant word (LSW) of an N...
Definition: rtptimeutilities.h:58
Describes an entry in the RTPSources source table.
Definition: rtpsourcedata.h:164
int DeleteOwnSSRC()
Deletes the entry for our own SSRC identifier.