00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00044 #ifndef CCXX_RTP_OQUEUE_H_
00045 #define CCXX_RTP_OQUEUE_H_
00046
00047 #include <ccrtp/queuebase.h>
00048 #include <ccrtp/CryptoContext.h>
00049 #include <list>
00050
00051 NAMESPACE_COMMONCPP
00052
00066 class __EXPORT DestinationListHandler
00067 {
00068 protected:
00069 struct TransportAddress;
00070 std::list<TransportAddress*> destList;
00071
00072 public:
00073 DestinationListHandler();
00074
00075 ~DestinationListHandler();
00076
00080 inline bool isSingleDestination() const
00081 { return (1 == destList.size()); }
00082
00083 inline TransportAddress* getFirstDestination() const
00084 { return destList.front(); }
00085
00086 inline void lockDestinationList() const
00087 { destinationLock.readLock(); }
00088
00089 inline void unlockDestinationList() const
00090 { destinationLock.unlock(); }
00091
00092 protected:
00093 inline void writeLockDestinationList() const
00094 { destinationLock.writeLock(); }
00095
00099 bool
00100 addDestinationToList(const InetAddress& ia, tpport_t data,
00101 tpport_t control);
00102
00106 bool removeDestinationFromList(const InetAddress& ia,
00107 tpport_t dataPort,
00108 tpport_t controlPort);
00109
00110 struct TransportAddress
00111 {
00112 TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp) :
00113 networkAddress(na), dataTransportPort(dtp),
00114 controlTransportPort(ctp)
00115 { }
00116
00117 inline const InetAddress& getNetworkAddress() const
00118 { return networkAddress; }
00119
00120 inline tpport_t getDataTransportPort() const
00121 { return dataTransportPort; }
00122
00123 inline tpport_t getControlTransportPort() const
00124 { return controlTransportPort; }
00125
00126 InetAddress networkAddress;
00127 tpport_t dataTransportPort, controlTransportPort;
00128 };
00129
00130 private:
00131 mutable ThreadLock destinationLock;
00132 };
00133
00134 #ifdef CCXX_IPV6
00135
00143 class __EXPORT DestinationListHandlerIPV6
00144 {
00145 protected:
00146 struct TransportAddressIPV6;
00147 std::list<TransportAddressIPV6*> destListIPV6;
00148
00149 public:
00150 DestinationListHandlerIPV6();
00151
00152 ~DestinationListHandlerIPV6();
00153
00157 inline bool isSingleDestinationIPV6() const
00158 { return (1 == destListIPV6.size()); }
00159
00160 inline TransportAddressIPV6* getFirstDestinationIPV6() const
00161 { return destListIPV6.front(); }
00162
00163 inline void lockDestinationListIPV6() const
00164 { destinationLock.readLock(); }
00165
00166 inline void unlockDestinationListIPV6() const
00167 { destinationLock.unlock(); }
00168
00169 protected:
00170 inline void writeLockDestinationListIPV6() const
00171 { destinationLock.writeLock(); }
00172
00176 bool
00177 addDestinationToListIPV6(const IPV6Address& ia, tpport_t data,
00178 tpport_t control);
00179
00183 bool removeDestinationFromListIPV6(const IPV6Address& ia,
00184 tpport_t dataPort,
00185 tpport_t controlPort);
00186
00187 struct TransportAddressIPV6
00188 {
00189 TransportAddressIPV6(IPV6Address na, tpport_t dtp, tpport_t ctp) :
00190 networkAddress(na), dataTransportPort(dtp),
00191 controlTransportPort(ctp)
00192 { }
00193
00194 inline const IPV6Address& getNetworkAddress() const
00195 { return networkAddress; }
00196
00197 inline tpport_t getDataTransportPort() const
00198 { return dataTransportPort; }
00199
00200 inline tpport_t getControlTransportPort() const
00201 { return controlTransportPort; }
00202
00203 IPV6Address networkAddress;
00204 tpport_t dataTransportPort, controlTransportPort;
00205 };
00206
00207 private:
00208 mutable ThreadLock destinationLock;
00209 };
00210
00211 #endif
00212
00220 class __EXPORT OutgoingDataQueue:
00221 public OutgoingDataQueueBase,
00222 #ifdef CCXX_IPV6
00223 protected DestinationListHandlerIPV6,
00224 #endif
00225 protected DestinationListHandler
00226 {
00227 public:
00228 #ifdef CCXX_IPV6
00229 bool
00230 addDestination(const IPV6Address& ia,
00231 tpport_t dataPort = DefaultRTPDataPort,
00232 tpport_t controlPort = 0);
00233
00234 bool
00235 forgetDestination(const IPV6Address& ia,
00236 tpport_t dataPort = DefaultRTPDataPort,
00237 tpport_t controlPort = 0);
00238
00239 #endif
00240
00241 bool
00242 addDestination(const InetHostAddress& ia,
00243 tpport_t dataPort = DefaultRTPDataPort,
00244 tpport_t controlPort = 0);
00245
00246 bool
00247 addDestination(const InetMcastAddress& ia,
00248 tpport_t dataPort = DefaultRTPDataPort,
00249 tpport_t controlPort = 0);
00250
00251 bool
00252 forgetDestination(const InetHostAddress& ia,
00253 tpport_t dataPort = DefaultRTPDataPort,
00254 tpport_t controlPort = 0);
00255
00256 bool
00257 forgetDestination(const InetMcastAddress& ia,
00258 tpport_t dataPort = DefaultRTPDataPort,
00259 tpport_t controlPort = 0);
00260
00266 void
00267 addContributor(uint32 csrc);
00268
00272 bool
00273 removeContributor(uint32 csrc);
00274
00280 bool
00281 isSending() const;
00282
00283
00296 void
00297 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00298
00311 void
00312 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00313
00314
00321 void setPadding(uint8 paddinglen)
00322 { sendInfo.paddinglen = paddinglen; }
00323
00332 void setMark(bool mark)
00333 { sendInfo.marked = mark; }
00334
00338 inline bool getMark() const
00339 { return sendInfo.marked; }
00340
00351 size_t
00352 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
00353
00354 inline microtimeout_t
00355 getDefaultSchedulingTimeout() const
00356 { return defaultSchedulingTimeout; }
00357
00364 inline void
00365 setSchedulingTimeout(microtimeout_t to)
00366 { schedulingTimeout = to; }
00367
00368 inline microtimeout_t
00369 getDefaultExpireTimeout() const
00370 { return defaultExpireTimeout; }
00371
00379 inline void
00380 setExpireTimeout(microtimeout_t to)
00381 { expireTimeout = to; }
00382
00383 inline microtimeout_t getExpireTimeout() const
00384 { return expireTimeout; }
00385
00391 inline uint32
00392 getSendPacketCount() const
00393 { return sendInfo.packetCount; }
00394
00400 inline uint32
00401 getSendOctetCount() const
00402 { return sendInfo.octetCount; }
00403
00409 inline uint16
00410 getSequenceNumber() const
00411 { return sendInfo.sendSeq; }
00412
00421 void
00422 setOutQueueCryptoContext(CryptoContext* cc);
00423
00432 void
00433 removeOutQueueCryptoContext(CryptoContext* cc);
00434
00442 CryptoContext*
00443 getOutQueueCryptoContext(uint32 ssrc);
00444
00445
00446 protected:
00447 OutgoingDataQueue();
00448
00449 virtual ~OutgoingDataQueue()
00450 { }
00451
00452 struct OutgoingRTPPktLink
00453 {
00454 OutgoingRTPPktLink(OutgoingRTPPkt* pkt,
00455 OutgoingRTPPktLink* p,
00456 OutgoingRTPPktLink* n) :
00457 packet(pkt), prev(p), next(n) { }
00458
00459 ~OutgoingRTPPktLink() { delete packet; }
00460
00461 inline OutgoingRTPPkt* getPacket() { return packet; }
00462
00463 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
00464
00465 inline OutgoingRTPPktLink* getPrev() { return prev; }
00466
00467 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
00468
00469 inline OutgoingRTPPktLink* getNext() { return next; }
00470
00471 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
00472
00473
00474 OutgoingRTPPkt* packet;
00475
00476 OutgoingRTPPktLink * prev, * next;
00477 };
00478
00486 void
00487 dispatchImmediate(OutgoingRTPPkt *packet);
00488
00498 microtimeout_t
00499 getSchedulingTimeout();
00500
00507 size_t
00508 dispatchDataPacket();
00509
00518 inline void
00519 setNextSeqNum(uint32 seqNum)
00520 { sendInfo.sendSeq = seqNum; }
00521
00522 inline uint32
00523 getCurrentSeqNum(void)
00524 { return sendInfo.sendSeq; }
00525
00528 inline void
00529 setInitialTimestamp(uint32 ts)
00530 { initialTimestamp = ts; }
00531
00534 inline uint32
00535 getInitialTimestamp()
00536 { return initialTimestamp; }
00537
00538 void purgeOutgoingQueue();
00539
00540 virtual void
00541 setControlPeer(const InetAddress &host, tpport_t port) {}
00542
00543 #ifdef CCXX_IPV6
00544 virtual void
00545 setControlPeerIPV6(const IPV6Address &host, tpport_t port) {}
00546 #endif
00547
00548
00549 mutable Mutex cryptoMutex;
00550 std::list<CryptoContext *> cryptoContexts;
00551
00552 private:
00558 inline virtual void onExpireSend(OutgoingRTPPkt&)
00559 { }
00560
00561 virtual void
00562 setDataPeer(const InetAddress &host, tpport_t port) {}
00563
00564 #ifdef CCXX_IPV6
00565 virtual void
00566 setDataPeerIPV6(const IPV6Address &host, tpport_t port) {}
00567 #endif
00568
00578 virtual size_t
00579 sendData(const unsigned char* const buffer, size_t len) {return 0;}
00580
00581 #ifdef CCXX_IPV6
00582 virtual size_t
00583 sendDataIPV6(const unsigned char* const buffer, size_t len) {return 0;}
00584 #endif
00585
00586 static const microtimeout_t defaultSchedulingTimeout;
00587 static const microtimeout_t defaultExpireTimeout;
00588 mutable ThreadLock sendLock;
00589
00590 OutgoingRTPPktLink* sendFirst, * sendLast;
00591 uint32 initialTimestamp;
00592
00593 microtimeout_t schedulingTimeout;
00594
00595 microtimeout_t expireTimeout;
00596
00597
00598 struct {
00599
00600 uint32 packetCount;
00601
00602 uint32 octetCount;
00603
00604 uint16 sendSeq;
00605
00606 uint32 sendSources[16];
00607
00608 uint16 sendCC;
00609
00610 uint8 paddinglen;
00611
00612
00613
00614 bool marked;
00615
00616 bool complete;
00617
00618 uint32 initialTimestamp;
00619
00620
00621 timeval overflowTime;
00622 } sendInfo;
00623 };
00624
00626
00627 END_NAMESPACE
00628
00629 #endif //CCXX_RTP_OQUEUE_H_
00630