ccRTP
oqueue.h
Go to the documentation of this file.
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_OQUEUE_H_
44#define CCXX_RTP_OQUEUE_H_
45
46#include <ccrtp/queuebase.h>
47#include <ccrtp/CryptoContext.h>
48#include <list>
49
50NAMESPACE_COMMONCPP
51
66{
67protected:
68 struct TransportAddress;
69 std::list<TransportAddress*> destList;
70
71public:
73
75
79 inline bool isSingleDestination() const
80 { return (1 == destList.size()); }
81
83 { return destList.front(); }
84
85 inline void lockDestinationList() const
86 { destinationLock.readLock(); }
87
88 inline void unlockDestinationList() const
89 { destinationLock.unlock(); }
90
91protected:
92 inline void writeLockDestinationList() const
93 { destinationLock.writeLock(); }
94
98 bool
99 addDestinationToList(const InetAddress& ia, tpport_t data,
100 tpport_t control);
101
105 bool removeDestinationFromList(const InetAddress& ia,
106 tpport_t dataPort,
107 tpport_t controlPort);
108
110 {
111 TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp) :
112 networkAddress(na), dataTransportPort(dtp),
113 controlTransportPort(ctp)
114 { }
115
116 inline const InetAddress& getNetworkAddress() const
117 { return networkAddress; }
118
119 inline tpport_t getDataTransportPort() const
120 { return dataTransportPort; }
121
122 inline tpport_t getControlTransportPort() const
123 { return controlTransportPort; }
124
125 InetAddress networkAddress;
126 tpport_t dataTransportPort, controlTransportPort;
127 };
128
129private:
130 mutable ThreadLock destinationLock;
131};
132
133#ifdef CCXX_IPV6
142class __EXPORT DestinationListHandlerIPV6
143{
144protected:
145 struct TransportAddressIPV6;
146 std::list<TransportAddressIPV6*> destListIPV6;
147
148public:
149 DestinationListHandlerIPV6();
150
151 ~DestinationListHandlerIPV6();
152
156 inline bool isSingleDestinationIPV6() const
157 { return (1 == destListIPV6.size()); }
158
159 inline TransportAddressIPV6* getFirstDestinationIPV6() const
160 { return destListIPV6.front(); }
161
162 inline void lockDestinationListIPV6() const
163 { destinationLock.readLock(); }
164
165 inline void unlockDestinationListIPV6() const
166 { destinationLock.unlock(); }
167
168protected:
169 inline void writeLockDestinationListIPV6() const
170 { destinationLock.writeLock(); }
171
175 bool
176 addDestinationToListIPV6(const IPV6Address& ia, tpport_t data,
177 tpport_t control);
178
182 bool removeDestinationFromListIPV6(const IPV6Address& ia,
183 tpport_t dataPort,
184 tpport_t controlPort);
185
186 struct TransportAddressIPV6
187 {
188 TransportAddressIPV6(IPV6Address na, tpport_t dtp, tpport_t ctp) :
189 networkAddress(na), dataTransportPort(dtp),
190 controlTransportPort(ctp)
191 { }
192
193 inline const IPV6Address& getNetworkAddress() const
194 { return networkAddress; }
195
196 inline tpport_t getDataTransportPort() const
197 { return dataTransportPort; }
198
199 inline tpport_t getControlTransportPort() const
200 { return controlTransportPort; }
201
202 IPV6Address networkAddress;
203 tpport_t dataTransportPort, controlTransportPort;
204 };
205
206private:
207 mutable ThreadLock destinationLock;
208};
209
210#endif
211
219class __EXPORT OutgoingDataQueue:
221#ifdef CCXX_IPV6
222 protected DestinationListHandlerIPV6,
223#endif
224 protected DestinationListHandler
225{
226public:
227#ifdef CCXX_IPV6
228 bool
229 addDestination(const IPV6Address& ia,
230 tpport_t dataPort = DefaultRTPDataPort,
231 tpport_t controlPort = 0);
232
233 bool
234 forgetDestination(const IPV6Address& ia,
235 tpport_t dataPort = DefaultRTPDataPort,
236 tpport_t controlPort = 0);
237
238#endif
239
240 bool
241 addDestination(const InetHostAddress& ia,
242 tpport_t dataPort = DefaultRTPDataPort,
243 tpport_t controlPort = 0);
244
245 bool
246 addDestination(const InetMcastAddress& ia,
247 tpport_t dataPort = DefaultRTPDataPort,
248 tpport_t controlPort = 0);
249
250 bool
251 forgetDestination(const InetHostAddress& ia,
252 tpport_t dataPort = DefaultRTPDataPort,
253 tpport_t controlPort = 0);
254
255 bool
256 forgetDestination(const InetMcastAddress& ia,
257 tpport_t dataPort = DefaultRTPDataPort,
258 tpport_t controlPort = 0);
259
265 void
266 addContributor(uint32 csrc);
267
271 bool
272 removeContributor(uint32 csrc);
273
279 bool
280 isSending() const;
281
282
295 void
296 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
297
310 void
311 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
312
313
320 void setPadding(uint8 paddinglen)
321 { sendInfo.paddinglen = paddinglen; }
322
331 void setMark(bool mark)
332 { sendInfo.marked = mark; }
333
337 inline bool getMark() const
338 { return sendInfo.marked; }
339
350 size_t
351 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
352
353 inline microtimeout_t
355 { return defaultSchedulingTimeout; }
356
363 inline void
365 { schedulingTimeout = to; }
366
367 inline microtimeout_t
369 { return defaultExpireTimeout; }
370
378 inline void
380 { expireTimeout = to; }
381
383 { return expireTimeout; }
384
390 inline uint32
392 { return sendInfo.packetCount; }
393
399 inline uint32
401 { return sendInfo.octetCount; }
402
408 inline uint16
410 { return sendInfo.sendSeq; }
411
420 void
422
431 void
433
443
444
445protected:
447
449 { }
450
452 {
456 packet(pkt), prev(p), next(n) { }
457
458 ~OutgoingRTPPktLink() { delete packet; }
459
460 inline OutgoingRTPPkt* getPacket() { return packet; }
461
462 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
463
464 inline OutgoingRTPPktLink* getPrev() { return prev; }
465
466 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
467
468 inline OutgoingRTPPktLink* getNext() { return next; }
469
470 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
471
472 // the packet this link refers to.
474 // global outgoing packets queue.
476 };
477
485 void
487
499
506 size_t
508
517 inline void
518 setNextSeqNum(uint32 seqNum)
519 { sendInfo.sendSeq = seqNum; }
520
521 inline uint32
523 { return sendInfo.sendSeq; }
524
527 inline void
529 { initialTimestamp = ts; }
530
533 inline uint32
535 { return initialTimestamp; }
536
538
539 virtual void
540 setControlPeer(const InetAddress &host, tpport_t port) {}
541
542#ifdef CCXX_IPV6
543 virtual void
544 setControlPeerIPV6(const IPV6Address &host, tpport_t port) {}
545#endif
546
547 // The crypto contexts for outgoing SRTP sessions.
548 mutable Mutex cryptoMutex;
549 std::list<CryptoContext *> cryptoContexts;
550
551private:
557 inline virtual void onExpireSend(OutgoingRTPPkt&)
558 { }
559
560 virtual void
561 setDataPeer(const InetAddress &host, tpport_t port) {}
562
563#ifdef CCXX_IPV6
564 virtual void
565 setDataPeerIPV6(const IPV6Address &host, tpport_t port) {}
566#endif
567
577 virtual size_t
578 sendData(const unsigned char* const buffer, size_t len) {return 0;}
579
580#ifdef CCXX_IPV6
581 virtual size_t
582 sendDataIPV6(const unsigned char* const buffer, size_t len) {return 0;}
583#endif
584
585 static const microtimeout_t defaultSchedulingTimeout;
586 static const microtimeout_t defaultExpireTimeout;
587 mutable ThreadLock sendLock;
588 // outgoing data packets queue
589 OutgoingRTPPktLink* sendFirst, * sendLast;
590 uint32 initialTimestamp;
591 // transmission scheduling timeout for the service thread
592 microtimeout_t schedulingTimeout;
593 // how old a packet can reach in the sending queue before deletetion
594 microtimeout_t expireTimeout;
595
596
597 struct {
598 // number of packets sent from the beginning
600 // number of payload octets sent from the beginning
602 // the sequence number of the next packet to sent
603 uint16 sendSeq;
604 // contributing sources
605 uint32 sendSources[16];
606 // how many CSRCs to send.
607 uint16 sendCC;
608 // pad packets to a paddinglen multiple
610 // This flags tells whether to set the bit M in the
611 // RTP fixed header of the packet in which the next
612 // provided data will be sent.
613 bool marked;
614 // whether there was not loss.
616 // ramdonly generated offset for the timestamp of sent packets
617 uint32 initialTimestamp;
618 // elapsed time accumulated through successive overflows of
619 // the local timestamp field
621 } sendInfo;
622};
623 // oqueue
625
626END_NAMESPACE
627
628#endif //CCXX_RTP_OQUEUE_H_
629
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition base.h:67
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition base.h:109
The implementation for a SRTP cryptographic context.
Definition CryptoContext.h:82
This class handles a list of destination addresses.
Definition oqueue.h:66
void writeLockDestinationList() const
Definition oqueue.h:92
void unlockDestinationList() const
Definition oqueue.h:88
void lockDestinationList() const
Definition oqueue.h:85
TransportAddress * getFirstDestination() const
Definition oqueue.h:82
bool addDestinationToList(const InetAddress &ia, tpport_t data, tpport_t control)
Locks the object before modifying it.
std::list< TransportAddress * > destList
Definition oqueue.h:69
bool isSingleDestination() const
Get whether there is only a destination in the list.
Definition oqueue.h:79
bool removeDestinationFromList(const InetAddress &ia, tpport_t dataPort, tpport_t controlPort)
Locks the object before modifying it.
Definition queuebase.h:256
A generic outgoing RTP data queue supporting multiple destinations.
Definition oqueue.h:225
void setInitialTimestamp(uint32 ts)
Definition oqueue.h:528
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:540
void addContributor(uint32 csrc)
Add csrc as the CSRC identifier of a new contributor.
uint32 getCurrentSeqNum(void)
Definition oqueue.h:522
uint32 getInitialTimestamp()
Definition oqueue.h:534
virtual ~OutgoingDataQueue()
Definition oqueue.h:448
uint32 octetCount
Definition oqueue.h:601
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:382
uint32 getSendPacketCount() const
Get the total number of packets sent so far.
Definition oqueue.h:391
void purgeOutgoingQueue()
Mutex cryptoMutex
Definition oqueue.h:548
uint32 getSendOctetCount() const
Get the total number of octets (payload only) sent so far.
Definition oqueue.h:400
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:518
void setPadding(uint8 paddinglen)
Set padding.
Definition oqueue.h:320
uint16 sendSeq
Definition oqueue.h:603
microtimeout_t getDefaultExpireTimeout() const
Definition oqueue.h:368
bool getMark() const
Get wheter the mark bit will be set in the next packet.
Definition oqueue.h:337
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:354
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:364
uint16 getSequenceNumber() const
Get the sequence number of the next outgoing packet.
Definition oqueue.h:409
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:615
uint8 paddinglen
Definition oqueue.h:609
timeval overflowTime
Definition oqueue.h:620
uint32 packetCount
Definition oqueue.h:599
uint16 sendCC
Definition oqueue.h:607
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:331
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:379
bool forgetDestination(const InetMcastAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
bool marked
Definition oqueue.h:613
std::list< CryptoContext * > cryptoContexts
Definition oqueue.h:549
void setOutQueueCryptoContext(CryptoContext *cc)
Set ouput 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:508
Base classes for RTP queues.
InetAddress networkAddress
Definition oqueue.h:125
const InetAddress & getNetworkAddress() const
Definition oqueue.h:116
TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp)
Definition oqueue.h:111
tpport_t controlTransportPort
Definition oqueue.h:126
tpport_t getDataTransportPort() const
Definition oqueue.h:119
tpport_t getControlTransportPort() const
Definition oqueue.h:122