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 <list>
00049
00050 #ifdef CCXX_NAMESPACES
00051 namespace ost {
00052 #endif
00053
00067 class __EXPORT DestinationListHandler
00068 {
00069 protected:
00070 struct TransportAddress;
00071 std::list<TransportAddress*> destList;
00072
00073 public:
00074 DestinationListHandler();
00075
00076 ~DestinationListHandler();
00077
00081 inline bool isSingleDestination() const
00082 { return (1 == destList.size()); }
00083
00084 inline TransportAddress* getFirstDestination() const
00085 { return destList.front(); }
00086
00087 inline void lockDestinationList() const
00088 { destinationLock.readLock(); }
00089
00090 inline void unlockDestinationList() const
00091 { destinationLock.unlock(); }
00092
00093 protected:
00094 inline void writeLockDestinationList() const
00095 { destinationLock.writeLock(); }
00096
00100 bool
00101 addDestinationToList(const InetAddress& ia, tpport_t data,
00102 tpport_t control);
00103
00107 bool removeDestinationFromList(const InetAddress& ia,
00108 tpport_t dataPort,
00109 tpport_t controlPort);
00110
00111 struct TransportAddress
00112 {
00113 TransportAddress(InetAddress na, tpport_t dtp, tpport_t ctp) :
00114 networkAddress(na), dataTransportPort(dtp),
00115 controlTransportPort(ctp)
00116 { }
00117
00118 inline const InetAddress& getNetworkAddress() const
00119 { return networkAddress; }
00120
00121 inline tpport_t getDataTransportPort() const
00122 { return dataTransportPort; }
00123
00124 inline tpport_t getControlTransportPort() const
00125 { return controlTransportPort; }
00126
00127 InetAddress networkAddress;
00128 tpport_t dataTransportPort, controlTransportPort;
00129 };
00130
00131 private:
00132 mutable ThreadLock destinationLock;
00133 };
00134
00142 class __EXPORT OutgoingDataQueue:
00143 public OutgoingDataQueueBase,
00144 protected DestinationListHandler
00145 {
00146 public:
00147 bool
00148 addDestination(const InetHostAddress& ia,
00149 tpport_t dataPort = DefaultRTPDataPort,
00150 tpport_t controlPort = 0);
00151
00152 bool
00153 addDestination(const InetMcastAddress& ia,
00154 tpport_t dataPort = DefaultRTPDataPort,
00155 tpport_t controlPort = 0);
00156
00157 bool
00158 forgetDestination(const InetHostAddress& ia,
00159 tpport_t dataPort = DefaultRTPDataPort,
00160 tpport_t controlPort = 0);
00161
00162 bool
00163 forgetDestination(const InetMcastAddress& ia,
00164 tpport_t dataPort = DefaultRTPDataPort,
00165 tpport_t controlPort = 0);
00166
00172 void
00173 addContributor(uint32 csrc);
00174
00178 bool
00179 removeContributor(uint32 csrc);
00180
00186 bool
00187 isSending() const;
00188
00201 void
00202 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00203
00210 void setPadding(uint8 paddinglen)
00211 { sendInfo.paddinglen = paddinglen; }
00212
00221 void setMark(bool mark)
00222 { sendInfo.marked = mark; }
00223
00227 inline bool getMark() const
00228 { return sendInfo.marked; }
00229
00240 size_t
00241 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
00242
00243 inline microtimeout_t
00244 getDefaultSchedulingTimeout() const
00245 { return defaultSchedulingTimeout; }
00246
00253 inline void
00254 setSchedulingTimeout(microtimeout_t to)
00255 { schedulingTimeout = to; }
00256
00257 inline microtimeout_t
00258 getDefaultExpireTimeout() const
00259 { return defaultExpireTimeout; }
00260
00268 inline void
00269 setExpireTimeout(microtimeout_t to)
00270 { expireTimeout = to; }
00271
00272 inline microtimeout_t getExpireTimeout() const
00273 { return expireTimeout; }
00274
00280 inline uint32
00281 getSendPacketCount() const
00282 { return sendInfo.packetCount; }
00283
00289 inline uint32
00290 getSendOctetCount() const
00291 { return sendInfo.octetCount; }
00292
00293 protected:
00294 OutgoingDataQueue();
00295
00296 virtual ~OutgoingDataQueue()
00297 { }
00298
00299 struct OutgoingRTPPktLink
00300 {
00301 OutgoingRTPPktLink(OutgoingRTPPkt* pkt,
00302 OutgoingRTPPktLink* p,
00303 OutgoingRTPPktLink* n) :
00304 packet(pkt), prev(p), next(n) { }
00305
00306 ~OutgoingRTPPktLink() { delete packet; }
00307
00308 inline OutgoingRTPPkt* getPacket() { return packet; }
00309
00310 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
00311
00312 inline OutgoingRTPPktLink* getPrev() { return prev; }
00313
00314 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
00315
00316 inline OutgoingRTPPktLink* getNext() { return next; }
00317
00318 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
00319
00320
00321 OutgoingRTPPkt* packet;
00322
00323 OutgoingRTPPktLink * prev, * next;
00324 };
00325
00335 microtimeout_t
00336 getSchedulingTimeout();
00337
00344 size_t
00345 dispatchDataPacket();
00346
00349 inline void
00350 setInitialTimestamp(uint32 ts)
00351 { initialTimestamp = ts; }
00352
00355 inline uint32
00356 getInitialTimestamp()
00357 { return initialTimestamp; }
00358
00359 void purgeOutgoingQueue();
00360
00361 virtual void
00362 setControlPeer(const InetAddress &host, tpport_t port) = 0;
00363
00364 private:
00370 inline virtual void onExpireSend(OutgoingRTPPkt&)
00371 { }
00372
00373 virtual void
00374 setDataPeer(const InetAddress &host, tpport_t port) = 0;
00375
00385 virtual size_t
00386 sendData(const unsigned char* const buffer, size_t len) = 0;
00387
00388 static const microtimeout_t defaultSchedulingTimeout;
00389 static const microtimeout_t defaultExpireTimeout;
00390 mutable ThreadLock sendLock;
00391
00392 OutgoingRTPPktLink* sendFirst, * sendLast;
00393 uint32 initialTimestamp;
00394
00395 microtimeout_t schedulingTimeout;
00396
00397 microtimeout_t expireTimeout;
00398
00399 struct {
00400
00401 uint32 packetCount;
00402
00403 uint32 octetCount;
00404
00405 uint16 sendSeq;
00406
00407 uint32 sendSources[16];
00408
00409 uint16 sendCC;
00410
00411 uint8 paddinglen;
00412
00413
00414
00415 bool marked;
00416
00417 bool complete;
00418
00419 uint32 initialTimestamp;
00420
00421
00422 timeval overflowTime;
00423 } sendInfo;
00424 };
00425
00427
00428 #ifdef CCXX_NAMESPACES
00429 }
00430 #endif
00431
00432 #endif //CCXX_RTP_OQUEUE_H_
00433