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 #ifdef CCXX_NAMESPACES
00052 namespace ost {
00053 #endif
00054
00068 class __EXPORT DestinationListHandler
00069 {
00070 protected:
00071 struct TransportAddress;
00072 std::list<TransportAddress*> destList;
00073
00074 public:
00075 DestinationListHandler();
00076
00077 ~DestinationListHandler();
00078
00082 inline bool isSingleDestination() const
00083 { return (1 == destList.size()); }
00084
00085 inline TransportAddress* getFirstDestination() const
00086 { return destList.front(); }
00087
00088 inline void lockDestinationList() const
00089 { destinationLock.readLock(); }
00090
00091 inline void unlockDestinationList() const
00092 { destinationLock.unlock(); }
00093
00094 protected:
00095 inline void writeLockDestinationList() const
00096 { destinationLock.writeLock(); }
00097
00101 bool
00102 addDestinationToList(const InetAddress& ia, tpport_t data,
00103 tpport_t control);
00104
00108 bool removeDestinationFromList(const InetAddress& ia,
00109 tpport_t dataPort,
00110 tpport_t controlPort);
00111
00112 struct TransportAddress
00113 {
00114 TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp) :
00115 networkAddress(na), dataTransportPort(dtp),
00116 controlTransportPort(ctp)
00117 { }
00118
00119 inline const InetAddress& getNetworkAddress() const
00120 { return networkAddress; }
00121
00122 inline tpport_t getDataTransportPort() const
00123 { return dataTransportPort; }
00124
00125 inline tpport_t getControlTransportPort() const
00126 { return controlTransportPort; }
00127
00128 InetAddress networkAddress;
00129 tpport_t dataTransportPort, controlTransportPort;
00130 };
00131
00132 private:
00133 mutable ThreadLock destinationLock;
00134 };
00135
00136 #ifdef CCXX_IPV6
00137
00145 class __EXPORT DestinationListHandlerIPV6
00146 {
00147 protected:
00148 struct TransportAddressIPV6;
00149 std::list<TransportAddressIPV6*> destListIPV6;
00150
00151 public:
00152 DestinationListHandlerIPV6();
00153
00154 ~DestinationListHandlerIPV6();
00155
00159 inline bool isSingleDestinationIPV6() const
00160 { return (1 == destListIPV6.size()); }
00161
00162 inline TransportAddressIPV6* getFirstDestinationIPV6() const
00163 { return destListIPV6.front(); }
00164
00165 inline void lockDestinationListIPV6() const
00166 { destinationLock.readLock(); }
00167
00168 inline void unlockDestinationListIPV6() const
00169 { destinationLock.unlock(); }
00170
00171 protected:
00172 inline void writeLockDestinationListIPV6() const
00173 { destinationLock.writeLock(); }
00174
00178 bool
00179 addDestinationToListIPV6(const IPV6Address& ia, tpport_t data,
00180 tpport_t control);
00181
00185 bool removeDestinationFromListIPV6(const IPV6Address& ia,
00186 tpport_t dataPort,
00187 tpport_t controlPort);
00188
00189 struct TransportAddressIPV6
00190 {
00191 TransportAddressIPV6(IPV6Address na, tpport_t dtp, tpport_t ctp) :
00192 networkAddress(na), dataTransportPort(dtp),
00193 controlTransportPort(ctp)
00194 { }
00195
00196 inline const IPV6Address& getNetworkAddress() const
00197 { return networkAddress; }
00198
00199 inline tpport_t getDataTransportPort() const
00200 { return dataTransportPort; }
00201
00202 inline tpport_t getControlTransportPort() const
00203 { return controlTransportPort; }
00204
00205 IPV6Address networkAddress;
00206 tpport_t dataTransportPort, controlTransportPort;
00207 };
00208
00209 private:
00210 mutable ThreadLock destinationLock;
00211 };
00212
00213 #endif
00214
00222 class __EXPORT OutgoingDataQueue:
00223 public OutgoingDataQueueBase,
00224 #ifdef CCXX_IPV6
00225 protected DestinationListHandlerIPV6,
00226 #endif
00227 protected DestinationListHandler
00228 {
00229 public:
00230 #ifdef CCXX_IPV6
00231 bool
00232 addDestination(const IPV6Address& ia,
00233 tpport_t dataPort = DefaultRTPDataPort,
00234 tpport_t controlPort = 0);
00235
00236 bool
00237 forgetDestination(const IPV6Address& ia,
00238 tpport_t dataPort = DefaultRTPDataPort,
00239 tpport_t controlPort = 0);
00240
00241 #endif
00242
00243 bool
00244 addDestination(const InetHostAddress& ia,
00245 tpport_t dataPort = DefaultRTPDataPort,
00246 tpport_t controlPort = 0);
00247
00248 bool
00249 addDestination(const InetMcastAddress& ia,
00250 tpport_t dataPort = DefaultRTPDataPort,
00251 tpport_t controlPort = 0);
00252
00253 bool
00254 forgetDestination(const InetHostAddress& ia,
00255 tpport_t dataPort = DefaultRTPDataPort,
00256 tpport_t controlPort = 0);
00257
00258 bool
00259 forgetDestination(const InetMcastAddress& ia,
00260 tpport_t dataPort = DefaultRTPDataPort,
00261 tpport_t controlPort = 0);
00262
00268 void
00269 addContributor(uint32 csrc);
00270
00274 bool
00275 removeContributor(uint32 csrc);
00276
00282 bool
00283 isSending() const;
00284
00285
00298 void
00299 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00300
00313 void
00314 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00315
00316
00323 void setPadding(uint8 paddinglen)
00324 { sendInfo.paddinglen = paddinglen; }
00325
00334 void setMark(bool mark)
00335 { sendInfo.marked = mark; }
00336
00340 inline bool getMark() const
00341 { return sendInfo.marked; }
00342
00353 size_t
00354 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
00355
00356 inline microtimeout_t
00357 getDefaultSchedulingTimeout() const
00358 { return defaultSchedulingTimeout; }
00359
00366 inline void
00367 setSchedulingTimeout(microtimeout_t to)
00368 { schedulingTimeout = to; }
00369
00370 inline microtimeout_t
00371 getDefaultExpireTimeout() const
00372 { return defaultExpireTimeout; }
00373
00381 inline void
00382 setExpireTimeout(microtimeout_t to)
00383 { expireTimeout = to; }
00384
00385 inline microtimeout_t getExpireTimeout() const
00386 { return expireTimeout; }
00387
00393 inline uint32
00394 getSendPacketCount() const
00395 { return sendInfo.packetCount; }
00396
00402 inline uint32
00403 getSendOctetCount() const
00404 { return sendInfo.octetCount; }
00405
00411 inline uint16
00412 getSequenceNumber() const
00413 { return sendInfo.sendSeq; }
00414
00423 void
00424 setOutQueueCryptoContext(CryptoContext* cc);
00425
00434 void
00435 removeOutQueueCryptoContext(CryptoContext* cc);
00436
00444 CryptoContext*
00445 getOutQueueCryptoContext(uint32 ssrc);
00446
00447
00448 protected:
00449 OutgoingDataQueue();
00450
00451 virtual ~OutgoingDataQueue()
00452 { }
00453
00454 struct OutgoingRTPPktLink
00455 {
00456 OutgoingRTPPktLink(OutgoingRTPPkt* pkt,
00457 OutgoingRTPPktLink* p,
00458 OutgoingRTPPktLink* n) :
00459 packet(pkt), prev(p), next(n) { }
00460
00461 ~OutgoingRTPPktLink() { delete packet; }
00462
00463 inline OutgoingRTPPkt* getPacket() { return packet; }
00464
00465 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
00466
00467 inline OutgoingRTPPktLink* getPrev() { return prev; }
00468
00469 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
00470
00471 inline OutgoingRTPPktLink* getNext() { return next; }
00472
00473 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
00474
00475
00476 OutgoingRTPPkt* packet;
00477
00478 OutgoingRTPPktLink * prev, * next;
00479 };
00480
00488 void
00489 dispatchImmediate(OutgoingRTPPkt *packet);
00490
00500 microtimeout_t
00501 getSchedulingTimeout();
00502
00509 size_t
00510 dispatchDataPacket();
00511
00520 inline void
00521 setNextSeqNum(uint32 seqNum)
00522 { sendInfo.sendSeq = seqNum; }
00523
00524 inline uint32
00525 getCurrentSeqNum(void)
00526 { return sendInfo.sendSeq; }
00527
00530 inline void
00531 setInitialTimestamp(uint32 ts)
00532 { initialTimestamp = ts; }
00533
00536 inline uint32
00537 getInitialTimestamp()
00538 { return initialTimestamp; }
00539
00540 void purgeOutgoingQueue();
00541
00542 virtual void
00543 setControlPeer(const InetAddress &host, tpport_t port) {}
00544
00545 #ifdef CCXX_IPV6
00546 virtual void
00547 setControlPeerIPV6(const IPV6Address &host, tpport_t port) {}
00548 #endif
00549
00550
00551 mutable Mutex cryptoMutex;
00552 std::list<CryptoContext *> cryptoContexts;
00553
00554 private:
00560 inline virtual void onExpireSend(OutgoingRTPPkt&)
00561 { }
00562
00563 virtual void
00564 setDataPeer(const InetAddress &host, tpport_t port) {}
00565
00566 #ifdef CCXX_IPV6
00567 virtual void
00568 setDataPeerIPV6(const IPV6Address &host, tpport_t port) {}
00569 #endif
00570
00580 virtual size_t
00581 sendData(const unsigned char* const buffer, size_t len) {return 0;}
00582
00583 #ifdef CCXX_IPV6
00584 virtual size_t
00585 sendDataIPV6(const unsigned char* const buffer, size_t len) {return 0;}
00586 #endif
00587
00588 static const microtimeout_t defaultSchedulingTimeout;
00589 static const microtimeout_t defaultExpireTimeout;
00590 mutable ThreadLock sendLock;
00591
00592 OutgoingRTPPktLink* sendFirst, * sendLast;
00593 uint32 initialTimestamp;
00594
00595 microtimeout_t schedulingTimeout;
00596
00597 microtimeout_t expireTimeout;
00598
00599
00600 struct {
00601
00602 uint32 packetCount;
00603
00604 uint32 octetCount;
00605
00606 uint16 sendSeq;
00607
00608 uint32 sendSources[16];
00609
00610 uint16 sendCC;
00611
00612 uint8 paddinglen;
00613
00614
00615
00616 bool marked;
00617
00618 bool complete;
00619
00620 uint32 initialTimestamp;
00621
00622
00623 timeval overflowTime;
00624 } sendInfo;
00625 };
00626
00628
00629 #ifdef CCXX_NAMESPACES
00630 }
00631 #endif
00632
00633 #endif //CCXX_RTP_OQUEUE_H_
00634