ccRTP
oqueue.h
Go to the documentation of this file.
1// Copyright (C) 2001,2002,2004,2005 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_OQUEUE_H_
45#define CCXX_RTP_OQUEUE_H_
46
47#include <ccrtp/queuebase.h>
48#include <ccrtp/CryptoContext.h>
49#include <list>
50
51NAMESPACE_COMMONCPP
52
67{
68protected:
69 struct TransportAddress;
70 std::list<TransportAddress*> destList;
71
72public:
74
76
80 inline bool isSingleDestination() const
81 { return (1 == destList.size()); }
82
84 { return destList.front(); }
85
86 inline void lockDestinationList() const
87 { destinationLock.readLock(); }
88
89 inline void unlockDestinationList() const
90 { destinationLock.unlock(); }
91
92protected:
93 inline void writeLockDestinationList() const
94 { destinationLock.writeLock(); }
95
99 bool
100 addDestinationToList(const InetAddress& ia, tpport_t data,
101 tpport_t control);
102
106 bool removeDestinationFromList(const InetAddress& ia,
107 tpport_t dataPort,
108 tpport_t controlPort);
109
111 {
112 TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp) :
113 networkAddress(na), dataTransportPort(dtp),
114 controlTransportPort(ctp)
115 { }
116
117 inline const InetAddress& getNetworkAddress() const
118 { return networkAddress; }
119
120 inline tpport_t getDataTransportPort() const
121 { return dataTransportPort; }
122
123 inline tpport_t getControlTransportPort() const
124 { return controlTransportPort; }
125
126 InetAddress networkAddress;
127 tpport_t dataTransportPort, controlTransportPort;
128 };
129
130private:
131 mutable ThreadLock destinationLock;
132};
133
134#ifdef CCXX_IPV6
143class __EXPORT DestinationListHandlerIPV6
144{
145protected:
146 struct TransportAddressIPV6;
147 std::list<TransportAddressIPV6*> destListIPV6;
148
149public:
150 DestinationListHandlerIPV6();
151
152 ~DestinationListHandlerIPV6();
153
157 inline bool isSingleDestinationIPV6() const
158 { return (1 == destListIPV6.size()); }
159
160 inline TransportAddressIPV6* getFirstDestinationIPV6() const
161 { return destListIPV6.front(); }
162
163 inline void lockDestinationListIPV6() const
164 { destinationLock.readLock(); }
165
166 inline void unlockDestinationListIPV6() const
167 { destinationLock.unlock(); }
168
169protected:
170 inline void writeLockDestinationListIPV6() const
171 { destinationLock.writeLock(); }
172
176 bool
177 addDestinationToListIPV6(const IPV6Address& ia, tpport_t data,
178 tpport_t control);
179
183 bool removeDestinationFromListIPV6(const IPV6Address& ia,
184 tpport_t dataPort,
185 tpport_t controlPort);
186
187 struct TransportAddressIPV6
188 {
189 TransportAddressIPV6(IPV6Address na, tpport_t dtp, tpport_t ctp) :
190 networkAddress(na), dataTransportPort(dtp),
191 controlTransportPort(ctp)
192 { }
193
194 inline const IPV6Address& getNetworkAddress() const
195 { return networkAddress; }
196
197 inline tpport_t getDataTransportPort() const
198 { return dataTransportPort; }
199
200 inline tpport_t getControlTransportPort() const
201 { return controlTransportPort; }
202
203 IPV6Address networkAddress;
204 tpport_t dataTransportPort, controlTransportPort;
205 };
206
207private:
208 mutable ThreadLock destinationLock;
209};
210
211#endif
212
220class __EXPORT OutgoingDataQueue:
222#ifdef CCXX_IPV6
223 protected DestinationListHandlerIPV6,
224#endif
225 protected DestinationListHandler
226{
227public:
228#ifdef CCXX_IPV6
229 bool
230 addDestination(const IPV6Address& ia,
231 tpport_t dataPort = DefaultRTPDataPort,
232 tpport_t controlPort = 0);
233
234 bool
235 forgetDestination(const IPV6Address& ia,
236 tpport_t dataPort = DefaultRTPDataPort,
237 tpport_t controlPort = 0);
238
239#endif
240
241 bool
242 addDestination(const InetHostAddress& ia,
243 tpport_t dataPort = DefaultRTPDataPort,
244 tpport_t controlPort = 0);
245
246 bool
247 addDestination(const InetMcastAddress& ia,
248 tpport_t dataPort = DefaultRTPDataPort,
249 tpport_t controlPort = 0);
250
251 bool
252 forgetDestination(const InetHostAddress& ia,
253 tpport_t dataPort = DefaultRTPDataPort,
254 tpport_t controlPort = 0);
255
256 bool
257 forgetDestination(const InetMcastAddress& ia,
258 tpport_t dataPort = DefaultRTPDataPort,
259 tpport_t controlPort = 0);
260
266 void
267 addContributor(uint32 csrc);
268
272 bool
273 removeContributor(uint32 csrc);
274
280 bool
281 isSending() const;
282
283
296 void
297 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
298
311 void
312 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
313
314
321 void setPadding(uint8 paddinglen)
322 { sendInfo.paddinglen = paddinglen; }
323
332 void setMark(bool mark)
333 { sendInfo.marked = mark; }
334
338 inline bool getMark() const
339 { return sendInfo.marked; }
340
351 size_t
352 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
353
354 inline microtimeout_t
356 { return defaultSchedulingTimeout; }
357
364 inline void
366 { schedulingTimeout = to; }
367
368 inline microtimeout_t
370 { return defaultExpireTimeout; }
371
379 inline void
381 { expireTimeout = to; }
382
384 { return expireTimeout; }
385
391 inline uint32
393 { return sendInfo.packetCount; }
394
400 inline uint32
402 { return sendInfo.octetCount; }
403
409 inline uint16
411 { return sendInfo.sendSeq; }
412
421 void
423
432 void
434
444
445
446protected:
448
450 { }
451
453 {
457 packet(pkt), prev(p), next(n) { }
458
459 ~OutgoingRTPPktLink() { delete packet; }
460
461 inline OutgoingRTPPkt* getPacket() { return packet; }
462
463 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
464
465 inline OutgoingRTPPktLink* getPrev() { return prev; }
466
467 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
468
469 inline OutgoingRTPPktLink* getNext() { return next; }
470
471 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
472
473 // the packet this link refers to.
475 // global outgoing packets queue.
477 };
478
486 void
488
500
507 size_t
509
518 inline void
519 setNextSeqNum(uint32 seqNum)
520 { sendInfo.sendSeq = seqNum; }
521
522 inline uint32
524 { return sendInfo.sendSeq; }
525
528 inline void
530 { initialTimestamp = ts; }
531
534 inline uint32
536 { return initialTimestamp; }
537
539
540 virtual void
541 setControlPeer(const InetAddress &host, tpport_t port) {}
542
543#ifdef CCXX_IPV6
544 virtual void
545 setControlPeerIPV6(const IPV6Address &host, tpport_t port) {}
546#endif
547
548 // The crypto contexts for outgoing SRTP sessions.
549 mutable Mutex cryptoMutex;
550 std::list<CryptoContext *> cryptoContexts;
551
552private:
558 inline virtual void onExpireSend(OutgoingRTPPkt&)
559 { }
560
561 virtual void
562 setDataPeer(const InetAddress &host, tpport_t port) {}
563
564#ifdef CCXX_IPV6
565 virtual void
566 setDataPeerIPV6(const IPV6Address &host, tpport_t port) {}
567#endif
568
578 virtual size_t
579 sendData(const unsigned char* const buffer, size_t len) {return 0;}
580
581#ifdef CCXX_IPV6
582 virtual size_t
583 sendDataIPV6(const unsigned char* const buffer, size_t len) {return 0;}
584#endif
585
586 static const microtimeout_t defaultSchedulingTimeout;
587 static const microtimeout_t defaultExpireTimeout;
588 mutable ThreadLock sendLock;
589 // outgoing data packets queue
590 OutgoingRTPPktLink* sendFirst, * sendLast;
591 uint32 initialTimestamp;
592 // transmission scheduling timeout for the service thread
593 microtimeout_t schedulingTimeout;
594 // how old a packet can reach in the sending queue before deletetion
595 microtimeout_t expireTimeout;
596
597
598 struct {
599 // number of packets sent from the beginning
601 // number of payload octets sent from the beginning
603 // the sequence number of the next packet to sent
604 uint16 sendSeq;
605 // contributing sources
606 uint32 sendSources[16];
607 // how many CSRCs to send.
608 uint16 sendCC;
609 // pad packets to a paddinglen multiple
611 // This flags tells whether to set the bit M in the
612 // RTP fixed header of the packet in which the next
613 // provided data will be sent.
614 bool marked;
615 // whether there was not loss.
617 // ramdonly generated offset for the timestamp of sent packets
618 uint32 initialTimestamp;
619 // elapsed time accumulated through successive overflows of
620 // the local timestamp field
622 } sendInfo;
623};
624
// oqueue
626
627END_NAMESPACE
628
629#endif //CCXX_RTP_OQUEUE_H_
630
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition base.h:68
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition base.h:110
The implementation for a SRTP cryptographic context.
Definition CryptoContext.h:83
This class handles a list of destination addresses.
Definition oqueue.h:67
void writeLockDestinationList() const
Definition oqueue.h:93
void unlockDestinationList() const
Definition oqueue.h:89
void lockDestinationList() const
Definition oqueue.h:86
TransportAddress * getFirstDestination() const
Definition oqueue.h:83
bool addDestinationToList(const InetAddress &ia, tpport_t data, tpport_t control)
Locks the object before modifying it.
std::list< TransportAddress * > destList
Definition oqueue.h:70
bool isSingleDestination() const
Get whether there is only a destination in the list.
Definition oqueue.h:80
bool removeDestinationFromList(const InetAddress &ia, tpport_t dataPort, tpport_t controlPort)
Locks the object before modifying it.
Definition queuebase.h:257
A generic outgoing RTP data queue supporting multiple destinations.
Definition oqueue.h:226
void setInitialTimestamp(uint32 ts)
Definition oqueue.h:529
bool isSending() const
Determine if outgoing packets are waiting to send.
microtimeout_t getSchedulingTimeout()
This computes the timeout period for scheduling transmission of the next packet at the "head" of the ...
virtual void setControlPeer(const InetAddress &host, tpport_t port)
Definition oqueue.h:541
void addContributor(uint32 csrc)
Add csrc as the CSRC identifier of a new contributor.
uint32 getCurrentSeqNum(void)
Definition oqueue.h:523
uint32 getInitialTimestamp()
Definition oqueue.h:535
virtual ~OutgoingDataQueue()
Definition oqueue.h:449
uint32 octetCount
Definition oqueue.h:602
bool forgetDestination(const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
bool removeContributor(uint32 csrc)
Remove CSRC from the list of contributors.
microtimeout_t getExpireTimeout() const
Definition oqueue.h:383
uint32 getSendPacketCount() const
Get the total number of packets sent so far.
Definition oqueue.h:392
void purgeOutgoingQueue()
Mutex cryptoMutex
Definition oqueue.h:549
uint32 getSendOctetCount() const
Get the total number of octets (payload only) sent so far.
Definition oqueue.h:401
void dispatchImmediate(OutgoingRTPPkt *packet)
This is used to write the RTP data packet to one or more destinations.
void setNextSeqNum(uint32 seqNum)
For thoses cases in which the application requires a method to set the sequence number for the outgoi...
Definition oqueue.h:519
void setPadding(uint8 paddinglen)
Set padding.
Definition oqueue.h:321
uint16 sendSeq
Definition oqueue.h:604
microtimeout_t getDefaultExpireTimeout() const
Definition oqueue.h:369
bool getMark() const
Get whether the mark bit will be set in the next packet.
Definition oqueue.h:338
CryptoContext * getOutQueueCryptoContext(uint32 ssrc)
Get an output queue CryptoContext identified by SSRC.
size_t dispatchDataPacket()
This function is used by the service thread to process the next outgoing packet pending in the sendin...
microtimeout_t getDefaultSchedulingTimeout() const
Definition oqueue.h:355
bool addDestination(const InetMcastAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
void setSchedulingTimeout(microtimeout_t to)
Set the default scheduling timeout to use when no data packets are waiting to be sent.
Definition oqueue.h:365
uint16 getSequenceNumber() const
Get the sequence number of the next outgoing packet.
Definition oqueue.h:410
size_t setPartial(uint32 timestamp, unsigned char *data, size_t offset, size_t max)
Set partial data for an already queued packet.
bool complete
Definition oqueue.h:616
uint8 paddinglen
Definition oqueue.h:610
timeval overflowTime
Definition oqueue.h:621
uint32 packetCount
Definition oqueue.h:600
uint16 sendCC
Definition oqueue.h:608
bool addDestination(const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
void putData(uint32 stamp, const unsigned char *data=NULL, size_t len=0)
This is used to create a data packet in the send queue.
void removeOutQueueCryptoContext(CryptoContext *cc)
Remove output queue CryptoContext.
void setMark(bool mark)
Set marker bit for the packet in which the next data provided will be send.
Definition oqueue.h:332
void setExpireTimeout(microtimeout_t to)
Set the "expired" timer for expiring packets pending in the send queue which have gone unsent and are...
Definition oqueue.h:380
bool forgetDestination(const InetMcastAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
bool marked
Definition oqueue.h:614
std::list< CryptoContext * > cryptoContexts
Definition oqueue.h:550
void setOutQueueCryptoContext(CryptoContext *cc)
Set output queue CryptoContext.
void sendImmediate(uint32 stamp, const unsigned char *data=NULL, size_t len=0)
This is used to create a data packet and send it immediately.
RTP packets being sent.
Definition rtppkt.h:509
Base classes for RTP queues.
InetAddress networkAddress
Definition oqueue.h:126
const InetAddress & getNetworkAddress() const
Definition oqueue.h:117
TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp)
Definition oqueue.h:112
tpport_t controlTransportPort
Definition oqueue.h:127
tpport_t getDataTransportPort() const
Definition oqueue.h:120
tpport_t getControlTransportPort() const
Definition oqueue.h:123