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
48 #include <list>
49
50 NAMESPACE_COMMONCPP
51
66 {
67 protected:
69 std::list<TransportAddress*>
destList;
70
71 public:
73
75
80 { return (1 == destList.size()); }
81
83 { return destList.front(); }
84
86 { destinationLock.readLock(); }
87
89 { destinationLock.unlock(); }
90
91 protected:
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 {
112 networkAddress(na), dataTransportPort(dtp),
113 controlTransportPort(ctp)
114 { }
115
117 { return networkAddress; }
118
120 { return dataTransportPort; }
121
123 { return controlTransportPort; }
124
127 };
128
129 private:
131 };
132
133 #ifdef CCXX_IPV6
134
142 class __EXPORT DestinationListHandlerIPV6
143 {
144 protected:
145 struct TransportAddressIPV6;
146 std::list<TransportAddressIPV6*> destListIPV6;
147
148 public:
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
168 protected:
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
206 private:
207 mutable ThreadLock destinationLock;
208 };
209
210 #endif
211
221 #ifdef CCXX_IPV6
222 protected DestinationListHandlerIPV6,
223 #endif
225 {
226 public:
227 #ifdef CCXX_IPV6
228 bool
229 addDestination(const IPV6Address& ia,
231 tpport_t controlPort = 0);
232
233 bool
234 forgetDestination(const IPV6Address& ia,
236 tpport_t controlPort = 0);
237
238 #endif
239
240 bool
241 addDestination(const InetHostAddress& ia,
243 tpport_t controlPort = 0);
244
245 bool
246 addDestination(const InetMcastAddress& ia,
248 tpport_t controlPort = 0);
249
250 bool
251 forgetDestination(const InetHostAddress& ia,
253 tpport_t controlPort = 0);
254
255 bool
256 forgetDestination(const InetMcastAddress& ia,
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
321 { sendInfo.paddinglen = paddinglen; }
322
332 { sendInfo.marked = mark; }
333
338 { return sendInfo.marked; }
339
350 size_t
351 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
352
355 { return defaultSchedulingTimeout; }
356
363 inline void
365 { schedulingTimeout = to; }
366
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
442 getOutQueueCryptoContext(uint32 ssrc);
443
444
445 protected:
447
449 { }
450
452 {
456 packet(pkt), prev(p), next(n) { }
457
459
461
463
465
467
469
471
472 // the packet this link refers to.
474 // global outgoing packets queue.
476 };
477
485 void
487
498 getSchedulingTimeout();
499
506 size_t
507 dispatchDataPacket();
508
517 inline void
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
537 void purgeOutgoingQueue();
538
539 virtual void
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.
550
551 private:
558 { }
559
560 virtual void
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
588 // outgoing data packets queue
591 // transmission scheduling timeout for the service thread
593 // how old a packet can reach in the sending queue before deletetion
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
604 // contributing sources
605 uint32 sendSources[16];
606 // how many CSRCs to send.
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.
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
626 END_NAMESPACE
627
628 #endif //CCXX_RTP_OQUEUE_H_
629
uint32 getSendPacketCount() const
Get the total number of packets sent so far.
uint32 getSendOctetCount() const
Get the total number of octets (payload only) sent so far.
void setPrev(OutgoingRTPPktLink *p)
void setMark(bool mark)
Set marker bit for the packet in which the next data provided will be send.
virtual size_t sendData(const unsigned char *const buffer, size_t len)
This function performs the physical I/O for writing a packet to the destination.
void setSchedulingTimeout(microtimeout_t to)
Set the default scheduling timeout to use when no data packets are waiting to be sent.
void setNext(OutgoingRTPPktLink *n)
bool getMark() const
Get wheter the mark bit will be set in the next packet.
The implementation for a SRTP cryptographic context.
ThreadLock destinationLock
void writeLockDestinationList() const
uint32 microtimeout_t
Time interval expressed in microseconds.
uint32 getCurrentSeqNum(void)
tpport_t dataTransportPort
std::list< TransportAddress * > destList
microtimeout_t expireTimeout
OutgoingRTPPkt * getPacket()
This class handles a list of destination addresses.
void lockDestinationList() const
microtimeout_t getDefaultExpireTimeout() const
void setNextSeqNum(uint32 seqNum)
For thoses cases in which the application requires a method to set the sequence number for the outgoi...
std::list< CryptoContext * > cryptoContexts
OutgoingRTPPktLink * getPrev()
TransportAddress * getFirstDestination() const
uint32 getInitialTimestamp()
virtual void onExpireSend(OutgoingRTPPkt &)
A hook to filter packets being sent that have been expired.
OutgoingRTPPktLink(OutgoingRTPPkt *pkt, OutgoingRTPPktLink *p, OutgoingRTPPktLink *n)
void setPadding(uint8 paddinglen)
Set padding.
OutgoingRTPPktLink * sendLast
Base classes for RTP queues.
microtimeout_t getDefaultSchedulingTimeout() const
InetAddress networkAddress
virtual void setControlPeer(const InetAddress &host, tpport_t port)
static const microtimeout_t defaultSchedulingTimeout
Schedule at 8 ms.
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
microtimeout_t schedulingTimeout
void setInitialTimestamp(uint32 ts)
tpport_t getControlTransportPort() const
const InetAddress & getNetworkAddress() const
uint16 getSequenceNumber() const
Get the sequence number of the next outgoing packet.
tpport_t getDataTransportPort() const
virtual ~OutgoingDataQueue()
static const microtimeout_t defaultExpireTimeout
Packets unsent will expire after 40 ms.
TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp)
void setExpireTimeout(microtimeout_t to)
Set the "expired" timer for expiring packets pending in the send queue which have gone unsent and are...
virtual void setDataPeer(const InetAddress &host, tpport_t port)
bool isSingleDestination() const
Get whether there is only a destination in the list.
OutgoingRTPPktLink * prev
void setPacket(OutgoingRTPPkt *pkt)
A generic outgoing RTP data queue supporting multiple destinations.
OutgoingRTPPktLink * getNext()
microtimeout_t getExpireTimeout() const
void unlockDestinationList() const