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
00189
00202 void
00203 putData(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00204
00217 void
00218 sendImmediate(uint32 stamp, const unsigned char* data = NULL, size_t len = 0);
00219
00220
00227 void setPadding(uint8 paddinglen)
00228 { sendInfo.paddinglen = paddinglen; }
00229
00238 void setMark(bool mark)
00239 { sendInfo.marked = mark; }
00240
00244 inline bool getMark() const
00245 { return sendInfo.marked; }
00246
00257 size_t
00258 setPartial(uint32 timestamp, unsigned char* data, size_t offset, size_t max);
00259
00260 inline microtimeout_t
00261 getDefaultSchedulingTimeout() const
00262 { return defaultSchedulingTimeout; }
00263
00270 inline void
00271 setSchedulingTimeout(microtimeout_t to)
00272 { schedulingTimeout = to; }
00273
00274 inline microtimeout_t
00275 getDefaultExpireTimeout() const
00276 { return defaultExpireTimeout; }
00277
00285 inline void
00286 setExpireTimeout(microtimeout_t to)
00287 { expireTimeout = to; }
00288
00289 inline microtimeout_t getExpireTimeout() const
00290 { return expireTimeout; }
00291
00297 inline uint32
00298 getSendPacketCount() const
00299 { return sendInfo.packetCount; }
00300
00306 inline uint32
00307 getSendOctetCount() const
00308 { return sendInfo.octetCount; }
00309
00310 protected:
00311 OutgoingDataQueue();
00312
00313 virtual ~OutgoingDataQueue()
00314 { }
00315
00316 struct OutgoingRTPPktLink
00317 {
00318 OutgoingRTPPktLink(OutgoingRTPPkt* pkt,
00319 OutgoingRTPPktLink* p,
00320 OutgoingRTPPktLink* n) :
00321 packet(pkt), prev(p), next(n) { }
00322
00323 ~OutgoingRTPPktLink() { delete packet; }
00324
00325 inline OutgoingRTPPkt* getPacket() { return packet; }
00326
00327 inline void setPacket(OutgoingRTPPkt* pkt) { packet = pkt; }
00328
00329 inline OutgoingRTPPktLink* getPrev() { return prev; }
00330
00331 inline void setPrev(OutgoingRTPPktLink* p) { prev = p; }
00332
00333 inline OutgoingRTPPktLink* getNext() { return next; }
00334
00335 inline void setNext(OutgoingRTPPktLink* n) { next = n; }
00336
00337
00338 OutgoingRTPPkt* packet;
00339
00340 OutgoingRTPPktLink * prev, * next;
00341 };
00342
00350 void
00351 dispatchImmediate(OutgoingRTPPkt *packet);
00352
00362 microtimeout_t
00363 getSchedulingTimeout();
00364
00371 size_t
00372 dispatchDataPacket();
00373
00376 inline void
00377 setInitialTimestamp(uint32 ts)
00378 { initialTimestamp = ts; }
00379
00382 inline uint32
00383 getInitialTimestamp()
00384 { return initialTimestamp; }
00385
00386 void purgeOutgoingQueue();
00387
00388 virtual void
00389 setControlPeer(const InetAddress &host, tpport_t port) = 0;
00390
00391 private:
00397 inline virtual void onExpireSend(OutgoingRTPPkt&)
00398 { }
00399
00400 virtual void
00401 setDataPeer(const InetAddress &host, tpport_t port) = 0;
00402
00412 virtual size_t
00413 sendData(const unsigned char* const buffer, size_t len) = 0;
00414
00415 static const microtimeout_t defaultSchedulingTimeout;
00416 static const microtimeout_t defaultExpireTimeout;
00417 mutable ThreadLock sendLock;
00418
00419 OutgoingRTPPktLink* sendFirst, * sendLast;
00420 uint32 initialTimestamp;
00421
00422 microtimeout_t schedulingTimeout;
00423
00424 microtimeout_t expireTimeout;
00425
00426 struct {
00427
00428 uint32 packetCount;
00429
00430 uint32 octetCount;
00431
00432 uint16 sendSeq;
00433
00434 uint32 sendSources[16];
00435
00436 uint16 sendCC;
00437
00438 uint8 paddinglen;
00439
00440
00441
00442 bool marked;
00443
00444 bool complete;
00445
00446 uint32 initialTimestamp;
00447
00448
00449 timeval overflowTime;
00450 } sendInfo;
00451 };
00452
00454
00455 #ifdef CCXX_NAMESPACES
00456 }
00457 #endif
00458
00459 #endif //CCXX_RTP_OQUEUE_H_
00460