1 // Copyright (C) 2001,2002,2004 Federico Montesino Pouzols <fedemp@altern.org>.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37
44 #ifndef CCXX_RTP_IQUEUE_H_
45 #define CCXX_RTP_IQUEUE_H_
46
49
50 #include <list>
51
52 #ifdef CCXX_NAMESPACES
53 namespace ost {
54 #endif
55
71 {
72 public:
73 inline void
75 { members = n; }
76
77 inline void
79 { members++; }
80
81 inline void
83 { members--; }
84
85 inline uint32
87 { return members; }
88
89 inline void
91 { activeSenders = n; }
92
93 inline void
95 { activeSenders++; }
96
97 inline void
99 { activeSenders--; }
100
101 inline uint32
103 { return activeSenders; }
104
105 protected:
107 members(0),
108 activeSenders(0)
109 { }
110
112 { }
113
114 private:
119 };
120
128 {
129 public:
136 inline void*
139
140 inline void
143
144 inline void
147
148 inline void
151
152 inline void
155
156 inline void
159
160 inline void
163
164 inline void
167
168 protected:
170 { }
171
173 { }
174 };
175
183 {
184 public:
185 inline void
187 const std::string& val)
189
190 inline void
193
194 protected:
196 { }
197
199 { }
200 };
201
209 {
210 public:
211 inline void
214
215 inline void
219
220 protected:
222 { }
223
225 { }
226 };
227
236 {
237 public:
239 {
242
244 { next = nc; }
245
247 { return networkAddress; }
248
250 { return dataTransportPort; }
251
253 { return controlTransportPort; }
254
259 // arrival time of last data or control packet.
261 };
262
275
278
280
281 protected:
283 { firstConflict = lastConflict = NULL; }
284
286 { }
287
289 };
290
307 {
308 public:
310 { return defaultMembersHashSize; }
311
312 protected:
313
328
333 inline virtual
335 { endMembers(); }
336
337 struct SyncSourceLink;
338
346 { return getLink(source)->getMembership() == this; }
347
355 {
357 struct timeval& recv_ts,
358 uint32 shifted_ts,
363 packet(pkt),
364 sourceLink(sLink),
365 prev(p), next(n),
366 srcPrev(sp), srcNext(sn),
367 receptionTime(recv_ts),
368 shiftedTimestamp(shifted_ts)
369 { }
370
372 { }
373
375 { return sourceLink; }
376
378 { sourceLink = src; }
379
381 { return next; }
382
384 { next = nl; }
385
387 { return prev; }
388
390 { prev = pl; }
391
393 { return srcNext; }
394
396 { srcNext = sn; }
397
399 { return srcPrev; }
400
402 { srcPrev = sp; }
403
405 { return packet; }
406
408 { packet = pkt; }
409
418 { receptionTime = t; }
419
424 { return receptionTime; }
425
435 { return shiftedTimestamp; }
436
438 { shiftedTimestamp = ts;}
439
440 // the packet this link refers to.
442 // the synchronization source this packet comes from.
444 // global incoming packet queue links.
446 // source specific incoming packet queue links.
448 // time this packet was received at
449 struct timeval receptionTime;
450 // timestamp of the packet in host order and after
451 // substracting the initial timestamp for its source
452 // (it is an increment from the initial timestamp).
454 };
455
473 {
474 // 2^16
476
484 membership(m), source(s), first(fp), last(lp),
485 prev(ps), next(ns), nextCollis(ncollis),
486 prevConflict(NULL)
487 { m->
setLink(*s,
this);
// record that the source is associated
488 initStats(); // to this link.
489 }
490
495
497 { return membership; }
498
504
510 { return first; }
511
513 { first = fp; }
514
520 { return last; }
521
523 { last = lp; }
524
529 { return prev; }
530
532 { prev = ps; }
533
538 { return next; }
539
541 { next = ns; }
542
550 { return nextCollis; }
551
553 { nextCollis = ns; }
554
556 { return prevConflict; }
557
563
565 { return senderInfo; }
566
567 void setSenderInfo(unsigned char* si);
568
570 { return receiverInfo; }
571
572 void setReceiverInfo(unsigned char* ri);
573
575 { return lastPacketTime; }
576
578 { return lastRTCPPacketTime; }
579
581 { return lastRTCPSRTime; }
582
588 { return obsPacketCount; }
589
591 { obsPacketCount++; }
592
598 { return obsOctetCount; }
599
601 { obsOctetCount += n; }
602
606 uint16
608 { return maxSeqNum; }
609
614 void
616 { maxSeqNum = max; }
617
618 inline uint32
620 { return extendedMaxSeqNum; }
621
622 inline void
624 { extendedMaxSeqNum = seq; }
625
627 { return cumulativePacketLost; }
628
630 { cumulativePacketLost = pl; }
631
633 { return fractionLost; }
634
636 { fractionLost = fl; }
637
639 { return lastPacketTransitTime; }
640
642 { lastPacketTransitTime = time; }
643
645 { return jitter; }
646
648 { jitter = j; }
649
651 { return initialDataTimestamp; }
652
654 { initialDataTimestamp = ts; }
655
657 { return initialDataTime; }
658
660 { initialDataTime = it; }
661
670 {
671 if(!flag)
672 return false;
673 flag = false;
674 return true;
675 }
676
684 if(flag)
685 return false;
686 flag = true;
687 return true;
688 }
689
691 { return badSeqNum; }
692
694 { badSeqNum = seq; }
695
697 { return probation; }
698
700 { probation = p; }
701
703 { --probation; }
704
706 { return 0 == probation; }
707
709 { return baseSeqNum; }
710
712 { return seqNumAccum; }
713
715 { seqNumAccum += SEQNUMMOD; }
716
721 { maxSeqNum = seqNumAccum = seqnum; }
722
734
735 void initStats();
736
741 void computeStats();
742
744 // The source this link object refers to.
746 // first/last packets from this source in the queue.
748 // Links for synchronization sources located before
749 // and after this one in the list of sources.
751 // Prev and next inside the hash table collision list.
756 // time the last RTP packet from this source was
757 // received at.
759 // time the last RTCP packet was received.
761 // time the lasrt RTCP SR was received. Required for
762 // DLSR computation.
764
765 // for outgoing RR reports.
766 // number of packets received from this source.
768 // number of octets received from this source.
770 // the higher sequence number seen from this source
775 // for interarrivel jitter computation
777 // interarrival jitter of packets from this source.
781
782 // this flag assures we only call one gotHello and one
783 // gotGoodbye for this src.
785
786 // for source validation:
793 };
794
799 bool
800 isRegistered(uint32 ssrc);
801
811 getSourceBySSRC(uint32 ssrc, bool& created);
812
823 bool
824 BYESource(uint32 ssrc);
825
833 bool
834 removeSource(uint32 ssrc);
835
837 { return first; }
838
840 { return last; }
841
842 inline uint32
845
846 inline void
849
850 inline uint32
853
856
857 private:
859
862
867 void
868 endMembers();
869
870 // Hash table with sources of RTP and RTCP packets
873 // List of sources, ordered from older to newer
875 };
876
885 {
886 public:
893 {
894 public:
900
902 link(l)
903 { }
904
906 link(si.link)
907 { }
908
910 { return *(link->getSource()); }
911
913 { return link->getSource(); }
914
916 link = link->getNext();
917 return *this;
918 }
919
922 ++(*this);
923 return result;
924 }
925
929
933
934 private:
936 };
937
940
943
954 getData(uint32 stamp,
const SyncSource* src = NULL);
955
956
963 bool
964 isWaiting(
const SyncSource* src = NULL)
const;
965
972 uint32
973 getFirstTimestamp(
const SyncSource* src = NULL)
const;
974
997 void
999 { minValidPacketSequence = packets; }
1000
1001 uint8
1003 { return defaultMinValidPacketSequence; }
1004
1009 uint8
1011 { return minValidPacketSequence; }
1012
1013 void
1015 { maxPacketMisorder = packets; }
1016
1017 uint16
1019 { return defaultMaxPacketMisorder; }
1020
1021 uint16
1023 { return maxPacketMisorder; }
1024
1030 void
1032 { maxPacketDropout = packets; }
1033
1034 uint16
1036 { return defaultMaxPacketDropout; }
1037
1038 uint16
1040 { return maxPacketDropout; }
1041
1042 // default value for constructors that allow to specify
1043 // members table s\ize
1044 inline static size_t
1046 { return defaultMembersSize; }
1047
1056 void
1058
1069 void
1071
1080 getInQueueCryptoContext(uint32 ssrc);
1081
1082 protected:
1087
1089 { }
1090
1103 bool checkSSRCInIncomingRTPPkt(SyncSourceLink& sourceLink,
1106
1123 { sourceExpirationPeriod = intervals; }
1124
1131 virtual size_t
1132 takeInDataPacket();
1133
1134 void renewLocalSSRC();
1135
1146 getWaiting(uint32 timestamp,
const SyncSource *src = NULL);
1147
1163 bool
1164 recordReception(SyncSourceLink& srcLink,
const IncomingRTPPkt& pkt,
1165 const timeval recvtime);
1166
1173 void
1175
1176 void purgeIncomingQueue();
1177
1184 inline virtual void
1186 { }
1187
1188 protected:
1205 inline virtual bool
1207 { return true; }
1208
1218 { return; }
1219
1233 inline virtual bool
1235 { return false; }
1236
1237 inline virtual bool
1239 { return false; }
1240
1256 bool
1257 insertRecvPacket(IncomingRTPPktLink* packetLink);
1258
1270 virtual size_t
1271 recvData(unsigned char* buffer, size_t length,
1273
1274 virtual size_t
1275 getNextDataPacketSize() const = 0;
1276
1278 // reception queue
1280 // values for packet validation.
1291 };
1292 // iqueue
1294
1295 #ifdef CCXX_NAMESPACES
1296 }
1297 #endif
1298
1299 #endif //CCXX_RTP_IQUEUE_H_
1300
void setFirst(IncomingRTPPktLink *fp)
virtual bool onRTPPacketRecv(IncomingRTPPkt &)
A virtual function to support parsing of arriving packets to determine if they should be kept in the ...
ConflictingTransportAddress * next
static const uint16 defaultMaxPacketDropout
void addParticipant(RTPApplication &app, Participant &part)
static const uint32 SEQNUMMOD
virtual ~ParticipantHandler()
void setSourceExpirationPeriod(uint8 intervals)
Set the number of RTCP intervals that the stack will wait to change the state of a source from stateA...
An RTP application, holding identifying RTCP SDES item values.
uint16 getBaseSeqNum() const
void setMembersCount(uint32 n)
std::forward_iterator_tag iterator_category
Synchronization source in an RTP session.
void incObservedPacketCount()
virtual ~MembershipBookkeeping()
Purges all RTPSource structures created during the session, as well as the hash table and the list of...
void setParticipant(Participant &p)
void setPRIVPrefix(Participant *part, const std::string val)
unsigned char * getSenderInfo()
SyncSourceLink * getNextCollis()
Get the link object for the next RTP source in the hash table entry collision list.
IncomingRTPPkt * getPacket() const
Interface (envelope) to data received over RTP packets.
The implementation for a SRTP cryptographic context.
void setMinValidPacketSequence(uint8 packets)
When receiving packets from a new source, it may be convenient to reject a first few packets before w...
void setControlTransportPort(tpport_t p)
uint8 getProbation() const
void setSender(SyncSource &source, bool active)
ConflictingTransportAddress * getPrevConflict() const
void removeParticipant(RTPApplication &app, RTPApplication::ParticipantLink *pl)
const SyncSource * pointer
void setProbation(uint8 p)
RTP packets received from other participants.
uint32 lastPacketTransitTime
unsigned char * getReceiverInfo()
uint32 getInitialDataTimestamp() const
static const size_t defaultMembersSize
timeval getRecvTime() const
Get the time this packet was received at.
void setState(SyncSource &source, SyncSource::State ns)
virtual bool end2EndDelayed(IncomingRTPPktLink &)
void setNext(IncomingRTPPktLink *nl)
unsigned short tpport_t
Transport Protocol Ports.
SyncSourceLink * getNext()
Get the link object for the next RTP source.
unsigned char * receiverInfo
SyncSourceLink(MembershipBookkeeping *m, SyncSource *s, IncomingRTPPktLink *fp=NULL, IncomingRTPPktLink *lp=NULL, SyncSourceLink *ps=NULL, SyncSourceLink *ns=NULL, SyncSourceLink *ncollis=NULL)
SyncSourcesIterator operator++(int)
static size_t getDefaultMembersSize()
uint32 getExtendedMaxSeqNum() const
const SyncSource & reference
bool getGoodbye()
Mark this source as having sent a BYE control packet.
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
virtual void onNewSyncSource(const SyncSource &)
Virtual called when a new synchronization source has joined the session.
Queue for incoming RTP data packets in an RTP session.
ConflictingTransportAddress * prevConflict
uint8 minValidPacketSequence
void setExtendedMaxSeqNum(uint32 seq)
void increaseMembersCount()
uint8 getMinValidPacketSequence() const
Get the minimun number of consecutive packets that must be received from a source before accepting it...
IncomingRTPPktLink * prev
tpport_t controlTransportPort
void setMaxPacketMisorder(uint16 packets)
Participant objects modification methods.
uint32 getObservedPacketCount() const
Get the total number of RTP packets received from this source.
void incObservedOctetCount(uint32 n)
void setPacket(IncomingRTPPkt *pkt)
void setNextCollis(SyncSourceLink *ns)
IncomingRTPPktLink * getLast()
Get last RTP (data) packet in the queue of packets received from this socket.
uint16 getMaxPacketMisorder() const
void increaseSendersCount()
SyncSourceLink ** sourceLinks
static const uint16 defaultMaxPacketMisorder
Synchronization Source internal handler within the incoming packets queue.
uint16 getDefaultMaxPacketMisorder() const
IncomingRTPPktLink * getPrev() const
reference operator*() const
members and senders accounting
SyncSource * getSource()
Get the synchronization source object this link objet holds information for.
uint32 getMembersCount() const
void * getLink(const SyncSource &source) const
This requires SyncSource - SyncSourceHandler friendship.
To track addresses of sources conflicting with the local one.
IncomingRTPPktLink * getNext() const
State
Synchronization source states during an RTP session.
Application objects modification methods.
A class of objects representing remote participants (RTP applications) in a multimedia session...
uint8 sourceExpirationPeriod
uint32 getLastPacketTransitTime()
IncomingRTPPktLink * getSrcNext() const
void setNext(ConflictingTransportAddress *nc)
pointer operator->() const
size_t getDefaultMembersHashSize()
timeval getLastRTCPPacketTime() const
void setNext(SyncSourceLink *ns)
uint32 getSendersCount() const
void setNetworkAddress(SyncSource &source, InetAddress addr)
timeval lastRTCPPacketTime
SyncSourcesIterator & operator++()
Base classes for RTP queues.
SyncSourceLink * nextCollis
IncomingRTPPktLink * getFirst()
Get first RTP (data) packet in the queue of packets received from this socket.
MembershipBookkeeping * getMembership()
bool isMine(const SyncSource &source) const
Get whether a synchronization source is recorded in this membership controller.
void setSDESItem(Participant *part, SDESItemType item, const std::string &val)
static const size_t defaultMembersHashSize
void setParticipant(SyncSource &source, Participant &p)
void setDataTransportPort(SyncSource &source, tpport_t p)
ptrdiff_t difference_type
IncomingRTPPktLink * getSrcPrev() const
The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have ...
SyncSourceLink * getLast()
unsigned char * senderInfo
void addParticipant(Participant &part)
timeval getLastRTCPSRTime() const
void removeParticipant(ParticipantLink *part)
void setSender(bool active)
Mark this source as an active sender.
uint32 initialDataTimestamp
SyncSourceLink * getSourceLink() const
void setInitialDataTimestamp(uint32 ts)
const InetAddress & getNetworkAddress() const
SyncSourceLink * sourceLink
timeval getInitialDataTime() const
uint32 getBadSeqNum() const
InetAddress networkAddress
virtual ~ApplicationHandler()
static const uint8 defaultMinValidPacketSequence
void setPrev(SyncSourceLink *ps)
void setMembersCount(uint32 n)
virtual ~IncomingDataQueue()
MembershipBookkeeping * membership
uint16 getMaxPacketDropout() const
void setBadSeqNum(uint32 seq)
void setSrcPrev(IncomingRTPPktLink *sp)
uint16 getDefaultMaxPacketDropout() const
uint8 getFractionLost() const
friend bool operator!=(const SyncSourcesIterator &l, const SyncSourcesIterator &r)
uint32 getSeqNumAccum() const
void setCumulativePacketLost(uint32 pl)
Controls the group membership in the current session.
void setSrcNext(IncomingRTPPktLink *sn)
IncomingRTPPktLink * recvLast
virtual ~ConflictHandler()
SyncSourceLink * getFirst()
SyncSourcesIterator begin()
SyncSourcesIterator(SyncSourceLink *l=NULL)
ConflictingTransportAddress * lastConflict
IncomingRTPPktLink * srcPrev
tpport_t dataTransportPort
virtual void onExpireRecv(IncomingRTPPkt &)
A hook to filter packets in the receive queue that are being expired.
void decreaseSendersCount()
void decreaseMembersCount()
void setLink(SyncSource &source, void *link)
uint16 getMaxSeqNum() const
Get the highest valid sequence number received.
void setSendersCount(uint32 n)
void setMaxSeqNum(uint16 max)
Set the highest valid sequence number recived.
SyncSourcesIterator(const SyncSourcesIterator &si)
SyncSourceLink * getPrev()
Get the link object for the previous RTP source.
void setDataTransportPort(tpport_t p)
SyncSourceLink * getLink(const SyncSource &source) const
void initSequence(uint16 seqnum)
Start a new sequence of received packets.
void setPrev(IncomingRTPPktLink *pl)
Incoming RTP data packets control structure within the incoming packet queue class.
virtual bool onSRTPPacketError(IncomingRTPPkt &pkt, int32 errorCode)
A hook that gets called if the decoding of an incoming SRTP was erroneous.
uint32 getObservedOctetCount() const
Get the total number of payload octets received from this source.
timeval getLastPacketTime() const
SyncSource objects modification methods.
SyncSourcesIterator end()
void updateConflict(ConflictingTransportAddress &ca)
void setMaxPacketDropout(uint16 packets)
It also prevents packets sent after a restart of the source being immediately accepted.
uint8 getDefaultMinValidPacketSequence() const
friend bool operator==(const SyncSourcesIterator &l, const SyncSourcesIterator &r)
tpport_t getDataTransportPort() const
void setPRIVPrefix(const std::string val)
Set prefix value for the PRIV SDES item.
void setLast(IncomingRTPPktLink *lp)
void setFractionLost(uint8 fl)
virtual ~SyncSourceHandler()
IncomingRTPPktLink * last
uint32 getTimestamp() const
Get timestamp of this packet.
std::list< CryptoContext * > cryptoContexts
void setLastPacketTransitTime(uint32 time)
void setTimestamp(uint32 ts)
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
bool getHello()
Mark this source as having sent some packet.
uint32 getCumulativePacketLost() const
tpport_t getControlTransportPort() const
uint32 cumulativePacketLost
void setSDESItem(SDESItemType item, const std::string &val)
Set the value of a SDES item.
uint32 members
number of identified members
uint32 activeSenders
number of identified members that currently are active senders
IncomingRTPPktLink(IncomingRTPPkt *pkt, SyncSourceLink *sLink, struct timeval &recv_ts, uint32 shifted_ts, IncomingRTPPktLink *sp, IncomingRTPPktLink *sn, IncomingRTPPktLink *p, IncomingRTPPktLink *n)
void setInitialDataTime(timeval it)
void setSourceLink(SyncSourceLink *src)
void setControlTransportPort(SyncSource &source, tpport_t p)
iterator through the list of synchronizations sources in this session
void setNetworkAddress(InetAddress addr)
static const uint32 SEQNUMMOD
void setRecvTime(const timeval &t)
Set the time this packet was received at.