oqueue.h

Go to the documentation of this file.
00001 // Copyright (C) 2001,2002,2004,2005 Federico Montesino Pouzols <fedemp@altern.org>.
00002 // 
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however    
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.    
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // ccRTP.  If you copy code from other releases into a copy of GNU
00028 // ccRTP, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU ccRTP, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00044 #ifndef CCXX_RTP_OQUEUE_H_
00045 #define CCXX_RTP_OQUEUE_H_
00046 
00047 #include <ccrtp/queuebase.h>
00048 #include <list> // TODO: minimal std::list template
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                 // the packet this link refers to.
00321                 OutgoingRTPPkt* packet;
00322                 // global outgoing packets queue.
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         // outgoing data packets queue
00392         OutgoingRTPPktLink* sendFirst, * sendLast; 
00393         uint32 initialTimestamp;
00394         // transmission scheduling timeout for the service thread
00395         microtimeout_t schedulingTimeout;
00396         // how old a packet can reach in the sending queue before deletetion
00397         microtimeout_t expireTimeout;
00398 
00399         struct {
00400                 // number of packets sent from the beginning
00401                 uint32 packetCount;
00402                 // number of payload octets sent from the beginning
00403                 uint32 octetCount;
00404                 // the sequence number of the next packet to sent
00405                 uint16 sendSeq;
00406                 // contributing sources
00407                 uint32 sendSources[16];
00408                 // how many CSRCs to send.
00409                 uint16 sendCC;
00410                 // pad packets to a paddinglen multiple
00411                 uint8 paddinglen;
00412                 // This flags tells whether to set the bit M in the
00413                 // RTP fixed header of the packet in which the next
00414                 // provided data will be sent.
00415                 bool marked;
00416                 // whether there was not loss.
00417                 bool complete;
00418                 // ramdonly generated offset for the timestamp of sent packets
00419                 uint32 initialTimestamp;
00420                 // elapsed time accumulated through successive overflows of
00421                 // the local timestamp field
00422                 timeval overflowTime;
00423         } sendInfo;
00424 };
00425  // oqueue
00427 
00428 #ifdef  CCXX_NAMESPACES
00429 }
00430 #endif
00431 
00432 #endif  //CCXX_RTP_OQUEUE_H_
00433 

Generated on Fri Dec 9 04:51:17 2005 for ccRTP by  doxygen 1.4.5