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 <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                 // the packet this link refers to.
00381                 OutgoingRTPPkt* packet;
00382                 // global outgoing packets queue.
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         // The crypto contexts for outgoing SRTP sessions.
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         // outgoing data packets queue
00482         OutgoingRTPPktLink* sendFirst, * sendLast;
00483         uint32 initialTimestamp;
00484         // transmission scheduling timeout for the service thread
00485         microtimeout_t schedulingTimeout;
00486         // how old a packet can reach in the sending queue before deletetion
00487         microtimeout_t expireTimeout;
00488 
00489 
00490         struct {
00491                 // number of packets sent from the beginning
00492                 uint32 packetCount;
00493                 // number of payload octets sent from the beginning
00494                 uint32 octetCount;
00495                 // the sequence number of the next packet to sent
00496                 uint16 sendSeq;
00497                 // contributing sources
00498                 uint32 sendSources[16];
00499                 // how many CSRCs to send.
00500                 uint16 sendCC;
00501                 // pad packets to a paddinglen multiple
00502                 uint8 paddinglen;
00503                 // This flags tells whether to set the bit M in the
00504                 // RTP fixed header of the packet in which the next
00505                 // provided data will be sent.
00506                 bool marked;
00507                 // whether there was not loss.
00508                 bool complete;
00509                 // ramdonly generated offset for the timestamp of sent packets
00510                 uint32 initialTimestamp;
00511                 // elapsed time accumulated through successive overflows of
00512                 // the local timestamp field
00513                 timeval overflowTime;
00514         } sendInfo;
00515 };
00516  // oqueue
00518 
00519 #ifdef  CCXX_NAMESPACES
00520 }
00521 #endif
00522 
00523 #endif  //CCXX_RTP_OQUEUE_H_
00524 

Generated on Fri Jan 12 21:14:33 2007 for ccRTP by  doxygen 1.5.1