1 // Copyright (C) 2001-2015 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 Lesser General Public License
14 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction. Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License. This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // ccRTP. If you copy code from other releases into a copy of GNU
27 // ccRTP, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way. To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU ccRTP, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36
43 #ifndef CCXX_RTP_IQUEUE_H_
44 #define CCXX_RTP_IQUEUE_H_
45
48
49 #include <list>
50
51 NAMESPACE_COMMONCPP
52
68 {
69 public:
70 inline void
72 { members = n; }
73
74 inline void
76 { members++; }
77
78 inline void
80 { members--; }
81
82 inline uint32
84 { return members; }
85
86 inline void
88 { activeSenders = n; }
89
90 inline void
92 { activeSenders++; }
93
94 inline void
96 { activeSenders--; }
97
98 inline uint32
100 { return activeSenders; }
101
102 protected:
104 members(0),
105 activeSenders(0)
106 { }
107
109 { }
110
111 private:
116 };
117
125 {
126 public:
133 inline void*
136
137 inline void
140
141 inline void
144
145 inline void
148
149 inline void
152
153 inline void
156
157 inline void
160
161 inline void
164
165 protected:
167 { }
168
170 { }
171 };
172
180 {
181 public:
182 inline void
184 const std::string& val)
186
187 inline void
190
191 protected:
193 { }
194
196 { }
197 };
198
206 {
207 public:
208 inline void
211
212 inline void
216
217 protected:
219 { }
220
222 { }
223 };
224
233 {
234 public:
236 {
238 tpport_t dtp, tpport_t ctp);
239
241 { next = nc; }
242
244 { return networkAddress; }
245
247 { return dataTransportPort; }
248
250 { return controlTransportPort; }
251
256 // arrival time of last data or control packet.
258 };
259
265 tpport_t dtp);
271 tpport_t ctp);
272
275
276 void addConflict(const InetAddress& na, tpport_t dtp, tpport_t ctp);
277
278 protected:
280 { firstConflict = lastConflict = NULL; }
281
283 { }
284
286 };
287
304 {
305 public:
307 { return defaultMembersHashSize; }
308
309 protected:
310
325
330 inline virtual
332 { endMembers(); }
333
334 struct SyncSourceLink;
335
343 {
return getLink(source)->getMembership() ==
this; }
344
352 {
354 struct timeval& recv_ts,
355 uint32 shifted_ts,
360 packet(pkt),
361 sourceLink(sLink),
362 prev(p), next(n),
363 srcPrev(sp), srcNext(sn),
364 receptionTime(recv_ts),
365 shiftedTimestamp(shifted_ts)
366 { }
367
369 { }
370
372 { return sourceLink; }
373
375 { sourceLink = src; }
376
378 { return next; }
379
381 { next = nl; }
382
384 { return prev; }
385
387 { prev = pl; }
388
390 { return srcNext; }
391
393 { srcNext = sn; }
394
396 { return srcPrev; }
397
399 { srcPrev = sp; }
400
402 { return packet; }
403
405 { packet = pkt; }
406
415 { receptionTime = t; }
416
421 { return receptionTime; }
422
432 { return shiftedTimestamp; }
433
435 { shiftedTimestamp = ts;}
436
437 // the packet this link refers to.
439 // the synchronization source this packet comes from.
441 // global incoming packet queue links.
443 // source specific incoming packet queue links.
445 // time this packet was received at
446 struct timeval receptionTime;
447 // timestamp of the packet in host order and after
448 // substracting the initial timestamp for its source
449 // (it is an increment from the initial timestamp).
451 };
452
470 {
471 // 2^16
473
481 membership(m), source(s), first(fp), last(lp),
482 prev(ps), next(ns), nextCollis(ncollis),
483 prevConflict(NULL)
484 { m->
setLink(*s,
this);
// record that the source is associated
485 initStats(); // to this link.
486 }
487
492
494 { return membership; }
495
501
507 { return first; }
508
510 { first = fp; }
511
517 { return last; }
518
520 { last = lp; }
521
526 { return prev; }
527
529 { prev = ps; }
530
535 { return next; }
536
538 { next = ns; }
539
547 { return nextCollis; }
548
550 { nextCollis = ns; }
551
553 { return prevConflict; }
554
558 void setPrevConflict(InetAddress& addr, tpport_t dataPort,
559 tpport_t controlPort);
560
562 { return senderInfo; }
563
564 void setSenderInfo(unsigned char* si);
565
567 { return receiverInfo; }
568
569 void setReceiverInfo(unsigned char* ri);
570
572 { return lastPacketTime; }
573
575 { return lastRTCPPacketTime; }
576
578 { return lastRTCPSRTime; }
579
585 { return obsPacketCount; }
586
588 { obsPacketCount++; }
589
595 { return obsOctetCount; }
596
598 { obsOctetCount += n; }
599
603 uint16
605 { return maxSeqNum; }
606
611 void
613 { maxSeqNum = max; }
614
615 inline uint32
617 { return extendedMaxSeqNum; }
618
619 inline void
621 { extendedMaxSeqNum = seq; }
622
624 { return cumulativePacketLost; }
625
627 { cumulativePacketLost = pl; }
628
630 { return fractionLost; }
631
633 { fractionLost = fl; }
634
636 { return lastPacketTransitTime; }
637
639 { lastPacketTransitTime = time; }
640
642 { return jitter; }
643
645 { jitter = j; }
646
648 { return initialDataTimestamp; }
649
651 { initialDataTimestamp = ts; }
652
654 { return initialDataTime; }
655
657 { initialDataTime = it; }
658
667 {
668 if(!flag)
669 return false;
670 flag = false;
671 return true;
672 }
673
681 if(flag)
682 return false;
683 flag = true;
684 return true;
685 }
686
688 { return badSeqNum; }
689
691 { badSeqNum = seq; }
692
694 { return probation; }
695
697 { probation = p; }
698
700 { --probation; }
701
703 { return 0 == probation; }
704
706 { return baseSeqNum; }
707
709 { baseSeqNum = seqnum; }
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,
1104 bool is_new, InetAddress& na,
1105 tpport_t tp);
1106
1123 { sourceExpirationPeriod = intervals; }
1124
1131 virtual size_t
1132 takeInDataPacket();
1133
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,
1272 InetHostAddress& host, tpport_t& port) = 0;
1273
1274 virtual size_t
1275 getNextDataPacketSize() const = 0;
1276
1278 // reception queue
1280 // values for packet validation.
1291 };
1292 // iqueue
1294
1295 END_NAMESPACE
1296
1297 #endif //CCXX_RTP_IQUEUE_H_
1298
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
void setBaseSeqNum(uint16 seqnum)
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)
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.
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
virtual void renewLocalSSRC()
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)
std::ptrdiff_t difference_type
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)
IncomingRTPPktLink * getSrcPrev() const
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)
static const uint32 SEQNUMMOD
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)
void setRecvTime(const timeval &t)
Set the time this packet was received at.