Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
51 #ifdef CCXX_NAMESPACES
52 namespace ost {
53 #endif
54 
69 {
70 protected:
72  std::list<TransportAddress*> destList;
73 
74 public:
76 
78 
82  inline bool isSingleDestination() const
83  { return (1 == destList.size()); }
84 
86  { return destList.front(); }
87 
88  inline void lockDestinationList() const
89  { destinationLock.readLock(); }
90 
91  inline void unlockDestinationList() const
92  { destinationLock.unlock(); }
93 
94 protected:
95  inline void writeLockDestinationList() const
96  { destinationLock.writeLock(); }
97 
101  bool
102  addDestinationToList(const InetAddress& ia, tpport_t data,
103  tpport_t control);
104 
108  bool removeDestinationFromList(const InetAddress& ia,
109  tpport_t dataPort,
110  tpport_t controlPort);
111 
113  {
115  networkAddress(na), dataTransportPort(dtp),
116  controlTransportPort(ctp)
117  { }
118 
119  inline const InetAddress& getNetworkAddress() const
120  { return networkAddress; }
121 
123  { return dataTransportPort; }
124 
126  { return controlTransportPort; }
127 
129  tpport_t dataTransportPort, controlTransportPort;
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,
180  tpport_t control);
181 
185  bool removeDestinationFromListIPV6(const IPV6Address& ia,
186  tpport_t dataPort,
187  tpport_t controlPort);
188 
189  struct TransportAddressIPV6
190  {
191  TransportAddressIPV6(IPV6Address na, tpport_t dtp, tpport_t ctp) :
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:
210  mutable ThreadLock destinationLock;
211 };
212 
213 #endif
214 
223  public OutgoingDataQueueBase,
224 #ifdef CCXX_IPV6
225  protected DestinationListHandlerIPV6,
226 #endif
227  protected DestinationListHandler
228 {
229 public:
230 #ifdef CCXX_IPV6
231  bool
232  addDestination(const IPV6Address& ia,
233  tpport_t dataPort = DefaultRTPDataPort,
234  tpport_t controlPort = 0);
235 
236  bool
237  forgetDestination(const IPV6Address& ia,
238  tpport_t dataPort = DefaultRTPDataPort,
239  tpport_t controlPort = 0);
240 
241 #endif
242 
243  bool
244  addDestination(const InetHostAddress& ia,
245  tpport_t dataPort = DefaultRTPDataPort,
246  tpport_t controlPort = 0);
247 
248  bool
249  addDestination(const InetMcastAddress& ia,
250  tpport_t dataPort = DefaultRTPDataPort,
251  tpport_t controlPort = 0);
252 
253  bool
254  forgetDestination(const InetHostAddress& ia,
255  tpport_t dataPort = DefaultRTPDataPort,
256  tpport_t controlPort = 0);
257 
258  bool
259  forgetDestination(const InetMcastAddress& ia,
260  tpport_t dataPort = DefaultRTPDataPort,
261  tpport_t controlPort = 0);
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 
323  void setPadding(uint8 paddinglen)
324  { sendInfo.paddinglen = paddinglen; }
325 
334  void setMark(bool mark)
335  { sendInfo.marked = mark; }
336 
340  inline bool getMark() const
341  { return sendInfo.marked; }
342 
353  size_t
354  setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
355 
356  inline microtimeout_t
358  { return defaultSchedulingTimeout; }
359 
366  inline void
368  { schedulingTimeout = to; }
369 
370  inline microtimeout_t
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
424  setOutQueueCryptoContext(CryptoContext* cc);
425 
434  void
435  removeOutQueueCryptoContext(CryptoContext* cc);
436 
445  getOutQueueCryptoContext(uint32 ssrc);
446 
447 
448 protected:
450 
452  { }
453 
455  {
458  OutgoingRTPPktLink* n) :
459  packet(pkt), prev(p), next(n) { }
460 
461  ~OutgoingRTPPktLink() { delete packet; }
462 
463  inline OutgoingRTPPkt* getPacket() { return packet; }
464 
465  inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
466 
467  inline OutgoingRTPPktLink* getPrev() { return prev; }
468 
469  inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
470 
471  inline OutgoingRTPPktLink* getNext() { return next; }
472 
473  inline void setNext(OutgoingRTPPktLink* n) { next = n; }
474 
475  // the packet this link refers to.
477  // global outgoing packets queue.
479  };
480 
488  void
489  dispatchImmediate(OutgoingRTPPkt *packet);
490 
501  getSchedulingTimeout();
502 
509  size_t
510  dispatchDataPacket();
511 
520  inline void
521  setNextSeqNum(uint32 seqNum)
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
543  setControlPeer(const InetAddress &host, tpport_t port) {}
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.
552  std::list<CryptoContext *> cryptoContexts;
553 
554 private:
560  inline virtual void onExpireSend(OutgoingRTPPkt&)
561  { }
562 
563  virtual void
564  setDataPeer(const InetAddress &host, tpport_t port) {}
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
602  uint32 packetCount;
603  // number of payload octets sent from the beginning
604  uint32 octetCount;
605  // the sequence number of the next packet to sent
606  uint16 sendSeq;
607  // contributing sources
608  uint32 sendSources[16];
609  // how many CSRCs to send.
610  uint16 sendCC;
611  // pad packets to a paddinglen multiple
612  uint8 paddinglen;
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.
616  bool marked;
617  // whether there was not loss.
618  bool complete;
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
623  timeval overflowTime;
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.
Definition: oqueue.h:394
uint32 getSendOctetCount() const
Get the total number of octets (payload only) sent so far.
Definition: oqueue.h:403
void setMark(bool mark)
Set marker bit for the packet in which the next data provided will be send.
Definition: oqueue.h:334
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.
Definition: oqueue.h:581
void setSchedulingTimeout(microtimeout_t to)
Set the default scheduling timeout to use when no data packets are waiting to be sent.
Definition: oqueue.h:367
bool getMark() const
Get wheter the mark bit will be set in the next packet.
Definition: oqueue.h:340
The implementation for a SRTP cryptographic context.
Definition: CryptoContext.h:76
ThreadLock destinationLock
Definition: oqueue.h:133
timeval overflowTime
Definition: oqueue.h:623
void writeLockDestinationList() const
Definition: oqueue.h:95
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:69
uint8 paddinglen
Definition: oqueue.h:612
uint32 getCurrentSeqNum(void)
Definition: oqueue.h:525
unsigned short tpport_t
Transport Protocol Ports.
Definition: address.h:86
std::list< TransportAddress * > destList
Definition: oqueue.h:71
microtimeout_t expireTimeout
Definition: oqueue.h:597
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition: thread.h:186
This class handles a list of destination addresses.
Definition: oqueue.h:68
void lockDestinationList() const
Definition: oqueue.h:88
microtimeout_t getDefaultExpireTimeout() const
Definition: oqueue.h:371
uint32 packetCount
Definition: oqueue.h:602
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:521
std::list< CryptoContext * > cryptoContexts
Definition: oqueue.h:552
TransportAddress * getFirstDestination() const
Definition: oqueue.h:85
uint32 getInitialTimestamp()
Definition: oqueue.h:537
virtual void onExpireSend(OutgoingRTPPkt &)
A hook to filter packets being sent that have been expired.
Definition: oqueue.h:560
void setPadding(uint8 paddinglen)
Set padding.
Definition: oqueue.h:323
#define InetHostAddress
Definition: address.h:76
uint32 initialTimestamp
Definition: oqueue.h:593
OutgoingRTPPktLink * sendLast
Definition: oqueue.h:592
Base classes for RTP queues.
microtimeout_t getDefaultSchedulingTimeout() const
Definition: oqueue.h:357
virtual void setControlPeer(const InetAddress &host, tpport_t port)
Definition: oqueue.h:543
The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have ...
Definition: thread.h:357
static const microtimeout_t defaultSchedulingTimeout
Definition: oqueue.h:588
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition: base.h:111
#define InetAddress
Definition: address.h:75
microtimeout_t schedulingTimeout
Definition: oqueue.h:595
void setInitialTimestamp(uint32 ts)
Definition: oqueue.h:531
tpport_t getControlTransportPort() const
Definition: oqueue.h:125
const InetAddress & getNetworkAddress() const
Definition: oqueue.h:119
#define __EXPORT
Definition: audio2.h:51
uint16 getSequenceNumber() const
Get the sequence number of the next outgoing packet.
Definition: oqueue.h:412
#define InetMcastAddress
Definition: address.h:78
tpport_t getDataTransportPort() const
Definition: oqueue.h:122
uint32 octetCount
Definition: oqueue.h:604
virtual ~OutgoingDataQueue()
Definition: oqueue.h:451
ThreadLock sendLock
Definition: oqueue.h:590
uint16 sendCC
Definition: oqueue.h:610
Mutex cryptoMutex
Definition: oqueue.h:551
static const microtimeout_t defaultExpireTimeout
Definition: oqueue.h:589
TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp)
Definition: oqueue.h:114
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:382
virtual void setDataPeer(const InetAddress &host, tpport_t port)
Definition: oqueue.h:564
bool isSingleDestination() const
Get whether there is only a destination in the list.
Definition: oqueue.h:82
A generic outgoing RTP data queue supporting multiple destinations.
Definition: oqueue.h:222
microtimeout_t getExpireTimeout() const
Definition: oqueue.h:385
RTP packets being sent.
Definition: rtppkt.h:510
void unlockDestinationList() const
Definition: oqueue.h:91
uint16 sendSeq
Definition: oqueue.h:606