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 
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                 // the packet this link refers to.
00338                 OutgoingRTPPkt* packet;
00339                 // global outgoing packets queue.
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         // outgoing data packets queue
00419         OutgoingRTPPktLink* sendFirst, * sendLast; 
00420         uint32 initialTimestamp;
00421         // transmission scheduling timeout for the service thread
00422         microtimeout_t schedulingTimeout;
00423         // how old a packet can reach in the sending queue before deletetion
00424         microtimeout_t expireTimeout;
00425 
00426         struct {
00427                 // number of packets sent from the beginning
00428                 uint32 packetCount;
00429                 // number of payload octets sent from the beginning
00430                 uint32 octetCount;
00431                 // the sequence number of the next packet to sent
00432                 uint16 sendSeq;
00433                 // contributing sources
00434                 uint32 sendSources[16];
00435                 // how many CSRCs to send.
00436                 uint16 sendCC;
00437                 // pad packets to a paddinglen multiple
00438                 uint8 paddinglen;
00439                 // This flags tells whether to set the bit M in the
00440                 // RTP fixed header of the packet in which the next
00441                 // provided data will be sent.
00442                 bool marked;
00443                 // whether there was not loss.
00444                 bool complete;
00445                 // ramdonly generated offset for the timestamp of sent packets
00446                 uint32 initialTimestamp;
00447                 // elapsed time accumulated through successive overflows of
00448                 // the local timestamp field
00449                 timeval overflowTime;
00450         } sendInfo;
00451 };
00452  // oqueue
00454 
00455 #ifdef  CCXX_NAMESPACES
00456 }
00457 #endif
00458 
00459 #endif  //CCXX_RTP_OQUEUE_H_
00460 

Generated on Wed Oct 4 23:50:31 2006 for ccRTP by  doxygen 1.4.7