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
00143 class __EXPORT OutgoingDataQueue:
00144 public OutgoingDataQueueBase,
00145 protected DestinationListHandler
00146 {
00147 public:
00148 bool
00149 addDestination(const InetHostAddress& ia,
00150 tpport_t dataPort = DefaultRTPDataPort,
00151 tpport_t controlPort = 0);
00152
00153 bool
00154 addDestination(const InetMcastAddress& ia,
00155 tpport_t dataPort = DefaultRTPDataPort,
00156 tpport_t controlPort = 0);
00157
00158 bool
00159 forgetDestination(const InetHostAddress& ia,
00160 tpport_t dataPort = DefaultRTPDataPort,
00161 tpport_t controlPort = 0);
00162
00163 bool
00164 forgetDestination(const InetMcastAddress& ia,
00165 tpport_t dataPort = DefaultRTPDataPort,
00166 tpport_t controlPort = 0);
00167
00173 void
00174 addContributor(uint32 csrc);
00175
00179 bool
00180 removeContributor(uint32 csrc);
00181
00187 bool
00188 isSending() const;
00189
00190
00203 void
00204 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00205
00218 void
00219 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00220
00221
00228 void setPadding(uint8 paddinglen)
00229 { sendInfo.paddinglen = paddinglen; }
00230
00239 void setMark(bool mark)
00240 { sendInfo.marked = mark; }
00241
00245 inline bool getMark() const
00246 { return sendInfo.marked; }
00247
00258 size_t
00259 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
00260
00261 inline microtimeout_t
00262 getDefaultSchedulingTimeout() const
00263 { return defaultSchedulingTimeout; }
00264
00271 inline void
00272 setSchedulingTimeout(microtimeout_t to)
00273 { schedulingTimeout = to; }
00274
00275 inline microtimeout_t
00276 getDefaultExpireTimeout() const
00277 { return defaultExpireTimeout; }
00278
00286 inline void
00287 setExpireTimeout(microtimeout_t to)
00288 { expireTimeout = to; }
00289
00290 inline microtimeout_t getExpireTimeout() const
00291 { return expireTimeout; }
00292
00298 inline uint32
00299 getSendPacketCount() const
00300 { return sendInfo.packetCount; }
00301
00307 inline uint32
00308 getSendOctetCount() const
00309 { return sendInfo.octetCount; }
00310
00316 inline uint16
00317 getSequenceNumber() const
00318 { return sendInfo.sendSeq; }
00319
00328 void
00329 setOutQueueCryptoContext(CryptoContext* cc);
00330
00339 void
00340 removeOutQueueCryptoContext(CryptoContext* cc);
00341
00349 CryptoContext*
00350 getOutQueueCryptoContext(uint32 ssrc);
00351
00352
00353 protected:
00354 OutgoingDataQueue();
00355
00356 virtual ~OutgoingDataQueue()
00357 { }
00358
00359 struct OutgoingRTPPktLink
00360 {
00361 OutgoingRTPPktLink(OutgoingRTPPkt* pkt,
00362 OutgoingRTPPktLink* p,
00363 OutgoingRTPPktLink* n) :
00364 packet(pkt), prev(p), next(n) { }
00365
00366 ~OutgoingRTPPktLink() { delete packet; }
00367
00368 inline OutgoingRTPPkt* getPacket() { return packet; }
00369
00370 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
00371
00372 inline OutgoingRTPPktLink* getPrev() { return prev; }
00373
00374 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
00375
00376 inline OutgoingRTPPktLink* getNext() { return next; }
00377
00378 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
00379
00380
00381 OutgoingRTPPkt* packet;
00382
00383 OutgoingRTPPktLink * prev, * next;
00384 };
00385
00393 void
00394 dispatchImmediate(OutgoingRTPPkt *packet);
00395
00405 microtimeout_t
00406 getSchedulingTimeout();
00407
00414 size_t
00415 dispatchDataPacket();
00416
00425 inline void
00426 setNextSeqNum(uint32 seqNum)
00427 { sendInfo.sendSeq = seqNum; }
00428
00429 inline uint32
00430 getCurrentSeqNum(void)
00431 { return sendInfo.sendSeq; }
00432
00435 inline void
00436 setInitialTimestamp(uint32 ts)
00437 { initialTimestamp = ts; }
00438
00441 inline uint32
00442 getInitialTimestamp()
00443 { return initialTimestamp; }
00444
00445 void purgeOutgoingQueue();
00446
00447 virtual void
00448 setControlPeer(const InetAddress &host, tpport_t port) = 0;
00449
00450
00451 mutable Mutex cryptoMutex;
00452 std::list<CryptoContext *> cryptoContexts;
00453
00454 private:
00460 inline virtual void onExpireSend(OutgoingRTPPkt&)
00461 { }
00462
00463 virtual void
00464 setDataPeer(const InetAddress &host, tpport_t port) = 0;
00465
00475 virtual size_t
00476 sendData(const unsigned char* const buffer, size_t len) = 0;
00477
00478 static const microtimeout_t defaultSchedulingTimeout;
00479 static const microtimeout_t defaultExpireTimeout;
00480 mutable ThreadLock sendLock;
00481
00482 OutgoingRTPPktLink* sendFirst, * sendLast;
00483 uint32 initialTimestamp;
00484
00485 microtimeout_t schedulingTimeout;
00486
00487 microtimeout_t expireTimeout;
00488
00489
00490 struct {
00491
00492 uint32 packetCount;
00493
00494 uint32 octetCount;
00495
00496 uint16 sendSeq;
00497
00498 uint32 sendSources[16];
00499
00500 uint16 sendCC;
00501
00502 uint8 paddinglen;
00503
00504
00505
00506 bool marked;
00507
00508 bool complete;
00509
00510 uint32 initialTimestamp;
00511
00512
00513 timeval overflowTime;
00514 } sendInfo;
00515 };
00516
00518
00519 #ifdef CCXX_NAMESPACES
00520 }
00521 #endif
00522
00523 #endif //CCXX_RTP_OQUEUE_H_
00524