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
49 #include <list>
50
51 #ifdef CCXX_NAMESPACES
52 namespace ost {
53 #endif
54
69 {
70 protected:
72 std::list<TransportAddress*>
destList;
73
74 public:
76
78
83 { return (1 == destList.size()); }
84
86 { return destList.front(); }
87
89 { destinationLock.readLock(); }
90
92 { destinationLock.unlock(); }
93
94 protected:
96 { destinationLock.writeLock(); }
97
101 bool
104
108 bool removeDestinationFromList(
const InetAddress& ia,
111
113 {
115 networkAddress(na), dataTransportPort(dtp),
116 controlTransportPort(ctp)
117 { }
118
120 { return networkAddress; }
121
123 { return dataTransportPort; }
124
126 { return controlTransportPort; }
127
130 };
131
132 private:
134 };
135
136 #ifdef CCXX_IPV6
137
145 class __EXPORT DestinationListHandlerIPV6
146 {
147 protected:
148 struct TransportAddressIPV6;
149 std::list<TransportAddressIPV6*> destListIPV6;
150
151 public:
152 DestinationListHandlerIPV6();
153
154 ~DestinationListHandlerIPV6();
155
159 inline bool isSingleDestinationIPV6() const
160 { return (1 == destListIPV6.size()); }
161
162 inline TransportAddressIPV6* getFirstDestinationIPV6() const
163 { return destListIPV6.front(); }
164
165 inline void lockDestinationListIPV6() const
166 { destinationLock.readLock(); }
167
168 inline void unlockDestinationListIPV6() const
169 { destinationLock.unlock(); }
170
171 protected:
172 inline void writeLockDestinationListIPV6() const
173 { destinationLock.writeLock(); }
174
178 bool
179 addDestinationToListIPV6(
const IPV6Address& ia,
tpport_t data,
181
185 bool removeDestinationFromListIPV6(const IPV6Address& ia,
188
189 struct TransportAddressIPV6
190 {
192 networkAddress(na), dataTransportPort(dtp),
193 controlTransportPort(ctp)
194 { }
195
196 inline const IPV6Address& getNetworkAddress() const
197 { return networkAddress; }
198
199 inline tpport_t getDataTransportPort()
const
200 { return dataTransportPort; }
201
202 inline tpport_t getControlTransportPort()
const
203 { return controlTransportPort; }
204
205 IPV6Address networkAddress;
206 tpport_t dataTransportPort, controlTransportPort;
207 };
208
209 private:
211 };
212
213 #endif
214
224 #ifdef CCXX_IPV6
225 protected DestinationListHandlerIPV6,
226 #endif
228 {
229 public:
230 #ifdef CCXX_IPV6
231 bool
232 addDestination(const IPV6Address& ia,
235
236 bool
237 forgetDestination(const IPV6Address& ia,
240
241 #endif
242
243 bool
247
248 bool
252
253 bool
257
258 bool
262
268 void
269 addContributor(uint32 csrc);
270
274 bool
275 removeContributor(uint32 csrc);
276
282 bool
283 isSending() const;
284
285
298 void
299 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
300
313 void
314 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
315
316
324 { sendInfo.paddinglen = paddinglen; }
325
335 { sendInfo.marked = mark; }
336
341 { return sendInfo.marked; }
342
353 size_t
354 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
355
358 { return defaultSchedulingTimeout; }
359
366 inline void
368 { schedulingTimeout = to; }
369
372 { return defaultExpireTimeout; }
373
381 inline void
383 { expireTimeout = to; }
384
386 { return expireTimeout; }
387
393 inline uint32
395 { return sendInfo.packetCount; }
396
402 inline uint32
404 { return sendInfo.octetCount; }
405
411 inline uint16
413 { return sendInfo.sendSeq; }
414
423 void
425
434 void
436
445 getOutQueueCryptoContext(uint32 ssrc);
446
447
448 protected:
450
452 { }
453
455 {
459 packet(pkt), prev(p), next(n) { }
460
462
464
466
468
470
472
474
475 // the packet this link refers to.
477 // global outgoing packets queue.
479 };
480
488 void
490
501 getSchedulingTimeout();
502
509 size_t
510 dispatchDataPacket();
511
520 inline void
522 { sendInfo.sendSeq = seqNum; }
523
524 inline uint32
526 { return sendInfo.sendSeq; }
527
530 inline void
532 { initialTimestamp = ts; }
533
536 inline uint32
538 { return initialTimestamp; }
539
540 void purgeOutgoingQueue();
541
542 virtual void
544
545 #ifdef CCXX_IPV6
546 virtual void
547 setControlPeerIPV6(
const IPV6Address &host,
tpport_t port) {}
548 #endif
549
550 // The crypto contexts for outgoing SRTP sessions.
553
554 private:
561 { }
562
563 virtual void
565
566 #ifdef CCXX_IPV6
567 virtual void
568 setDataPeerIPV6(
const IPV6Address &host,
tpport_t port) {}
569 #endif
570
580 virtual size_t
581 sendData(
const unsigned char*
const buffer,
size_t len) {
return 0;}
582
583 #ifdef CCXX_IPV6
584 virtual size_t
585 sendDataIPV6(const unsigned char* const buffer, size_t len) {return 0;}
586 #endif
587
591 // outgoing data packets queue
594 // transmission scheduling timeout for the service thread
596 // how old a packet can reach in the sending queue before deletetion
598
599
600 struct {
601 // number of packets sent from the beginning
603 // number of payload octets sent from the beginning
605 // the sequence number of the next packet to sent
607 // contributing sources
608 uint32 sendSources[16];
609 // how many CSRCs to send.
611 // pad packets to a paddinglen multiple
613 // This flags tells whether to set the bit M in the
614 // RTP fixed header of the packet in which the next
615 // provided data will be sent.
617 // whether there was not loss.
619 // ramdonly generated offset for the timestamp of sent packets
620 uint32 initialTimestamp;
621 // elapsed time accumulated through successive overflows of
622 // the local timestamp field
624 } sendInfo;
625 };
626 // oqueue
628
629 #ifdef CCXX_NAMESPACES
630 }
631 #endif
632
633 #endif //CCXX_RTP_OQUEUE_H_
634
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)
unsigned short tpport_t
Transport Protocol Ports.
tpport_t dataTransportPort
std::list< TransportAddress * > destList
microtimeout_t expireTimeout
OutgoingRTPPkt * getPacket()
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
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)
The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have ...
static const microtimeout_t defaultSchedulingTimeout
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
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