cqueue.h

Go to the documentation of this file.
00001 // Copyright (C) 2001,2002,2004 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_CQUEUE_H_
00045 #define CCXX_RTP_CQUEUE_H_
00046 
00047 #include <ccrtp/ioqueue.h>
00048 #include <ccrtp/CryptoContextCtrl.h>
00049 #include <list>
00050 
00051 NAMESPACE_COMMONCPP
00052 
00080 class __EXPORT QueueRTCPManager : public RTPDataQueue,
00081     protected RTCPCompoundHandler
00082 {
00083 public:
00093     RTCPSenderInfo* getMRSenderInfo(SyncSource& src);
00094 
00105     RTCPReceiverInfo* getMRReceiverInfo(SyncSource& srcFrom);
00106 
00115     void setLeavingDelay(microtimeout_t delay)
00116     { leavingDelay = delay; }
00117 
00132     inline void
00133     setEnd2EndDelay(microtimeout_t t)
00134         { end2EndDelay = t; }
00135 
00136     inline microtimeout_t
00137     getDefaultEnd2EndDelay() const
00138     { return defaultEnd2EndDelay; }
00139 
00140     inline microtimeout_t
00141     getEnd2EndDelay() const
00142     { return end2EndDelay; }
00143 
00157     inline void
00158     setSendersControlFraction(float fraction)
00159     { sendControlBwFract = fraction; recvControlBwFract = 1 - fraction;}
00160 
00170     void
00171     setMinRTCPInterval(microtimeout_t interval)
00172     { rtcpMinInterval = interval; }
00173 
00177     inline uint32
00178     getSendRTCPPacketCount() const
00179     { return ctrlSendCount; }
00180 
00189     void
00190     setOutQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00191 
00200     void
00201     removeOutQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00202 
00210     CryptoContextCtrl*
00211     getOutQueueCryptoContextCtrl(uint32 ssrc);
00212 
00213 
00222     void
00223     setInQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00224 
00235     void
00236     removeInQueueCryptoContextCtrl(CryptoContextCtrl* cc);
00237 
00245     CryptoContextCtrl*
00246     getInQueueCryptoContextCtrl(uint32 ssrc);
00247 
00248 protected:
00249     QueueRTCPManager(uint32 size = RTPDataQueue::defaultMembersHashSize,
00250              RTPApplication& app = defaultApplication());
00251 
00252     QueueRTCPManager(uint32 ssrc,
00253              uint32 size = RTPDataQueue::defaultMembersHashSize,
00254              RTPApplication& app = defaultApplication());
00255 
00256     virtual
00257     ~QueueRTCPManager();
00258 
00259     const RTPApplication&
00260     getApplication()
00261     { return queueApplication; }
00262 
00263     inline void
00264     setControlBandwidth(float fraction)
00265     { controlBwFract = fraction; }
00266 
00267     float
00268     getControlBandwidth() const
00269     { return controlBwFract; }
00270 
00275     void
00276     controlTransmissionService();
00277 
00282     void
00283     controlReceptionService();
00284 
00297     bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
00298                 InetAddress& na, tpport_t tp);
00299 
00300     void
00301     endQueueRTCPManager();
00302 
00313     virtual void
00314     onGotSR(SyncSource& source, SendReport& SR, uint8 blocks);
00315 
00326     virtual void
00327     onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks);
00328 
00333     bool
00334     onGotSDES(SyncSource& source, RTCPPacket& pkt);
00335 
00345     virtual bool
00346     onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len);
00347 
00357     inline virtual void
00358     onGotAPP(SyncSource&, RTCPCompoundHandler::APPPacket&,
00359          size_t)
00360     { return; }
00361 
00362     inline timeval
00363     getRTCPCheckInterval()
00364     { return rtcpCheckInterval; }
00365 
00370     uint32
00371     getLastSendPacketCount() const
00372     { return lastSendPacketCount; }
00373 
00377     inline void
00378     setPrevMembersNum(uint32 n)
00379     { reconsInfo.rtcpPMembers = n; }
00380 
00381     inline uint32
00382     getPrevMembersCount() const
00383     { return reconsInfo.rtcpPMembers; }
00384 
00403     size_t
00404     dispatchBYE(const std::string& reason);
00405 
00406     size_t
00407     sendControlToDestinations(unsigned char* buffer, size_t len);
00408 
00409 private:
00410     QueueRTCPManager(const QueueRTCPManager &o);
00411 
00412     QueueRTCPManager&
00413     operator=(const QueueRTCPManager &o);
00414 
00420     size_t
00421     dispatchControlPacket();
00422 
00434     void
00435     takeInControlPacket();
00436 
00450     virtual timeval
00451     computeRTCPInterval();
00452 
00460     virtual SDESItemType
00461     scheduleSDESItem();
00462 
00468     inline virtual void
00469     onSSRCCollision(const SyncSource&)
00470     { }
00471 
00475     virtual bool
00476     end2EndDelayed(IncomingRTPPktLink& p);
00477 
00486     inline virtual void
00487     onGotRRSRExtension(unsigned char*, size_t)
00488     { return; }
00489 
00499     inline virtual void
00500     onGotGoodbye(const SyncSource&, const std::string&)
00501     { return; }
00502 
00515     bool
00516     getBYE(RTCPPacket &pkt, size_t &pointer, size_t len);
00517 
00521     uint8
00522     packReportBlocks(RRBlock* blocks, uint16& len, uint16& available);
00523 
00532     void
00533     packSDES(uint16& len);
00534 
00546     void
00547     updateAvgRTCPSize(size_t len);
00548 
00554     void
00555     reverseReconsideration();
00556 
00557     bool
00558     timerReconsideration();
00559 
00568     void
00569     expireSSRCs();
00570 
00574     void
00575     getOnlyBye();
00576 
00581     void
00582     setSDESItem(Participant* part, SDESItemType type,
00583             const char* const value, size_t len);
00584 
00589     void
00590     setPRIVPrefix(Participant* part, const char* const value, size_t len);
00591 
00603     inline virtual uint16
00604     networkHeaderSize()
00605     { return 20; }
00606 
00618     inline virtual uint16
00619     transportHeaderSize()
00620     { return 8; }
00621 
00622 
00623     int32 protect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
00624     int32 unprotect(uint8* pkt, size_t len, CryptoContextCtrl* cc);
00625     
00626     
00627     SDESItemType
00628     nextSDESType(SDESItemType t);
00629 
00630     virtual size_t
00631     sendControl(const unsigned char* const buffer, size_t len) = 0;
00632 
00633     virtual size_t
00634     recvControl(unsigned char* buffer, size_t len,
00635             InetHostAddress& na, tpport_t& tp) = 0;
00636 
00637     virtual bool
00638     isPendingControl(microtimeout_t timeout) = 0;
00639 
00640     // whether the RTCP service is active
00641     volatile bool controlServiceActive;
00642     float controlBwFract, sendControlBwFract, recvControlBwFract;
00643     // number of RTCP packets sent since the beginning
00644     uint32 ctrlSendCount;
00645 
00646     // Network + transport headers size, typically size of IP +
00647     // UDP headers
00648     uint16 lowerHeadersSize;
00649 
00650     SDESItemType nextScheduledSDESItem;
00651     static const SDESItemType firstSchedulable;
00652     static const SDESItemType lastSchedulable;
00653 
00654     // state for rtcp timing. Its meaning is defined in
00655     // draft-ietf-avt-rtp-new, 6.3.
00656 
00657     // Parameters for timer reconsideration algorithm
00658     struct {
00659         timeval rtcpTp, rtcpTc, rtcpTn;
00660         uint32 rtcpPMembers;
00661     } reconsInfo;
00662     bool rtcpWeSent;
00663     uint16 rtcpAvgSize;
00664     bool rtcpInitial;
00665     // last time we checked if there were incoming RTCP packets
00666     timeval rtcpLastCheck;
00667     // interval to check if there are incoming RTCP packets
00668     timeval rtcpCheckInterval;
00669     // next time to check if there are incoming RTCP packets
00670     timeval rtcpNextCheck;
00671 
00672     // number of RTP data packets sent at the time of the last
00673     // RTCP packet transmission.
00674     uint32 lastSendPacketCount;
00675 
00676     // minimum interval for transmission of RTCP packets. The
00677     // result of computeRTCPInterval will always be >= (times a
00678     // random number between 0.5 and 1.5).
00679     microtimeout_t rtcpMinInterval;
00680 
00681     microtimeout_t leavingDelay;
00682     static const microtimeout_t defaultEnd2EndDelay;
00683     // Maximum delay allowed between packet timestamping and
00684     // packet availability for the application.
00685     microtimeout_t end2EndDelay;
00686     // Application this queue is bound to.
00687     RTPApplication& queueApplication;
00688 
00689     // an empty RTPData
00690     static const uint16 TIMEOUT_MULTIPLIER;
00691     static const double RECONSIDERATION_COMPENSATION;
00692     
00693     mutable Mutex outCryptoMutex;
00694     std::list<CryptoContextCtrl *> outCryptoContexts;
00695     uint32 srtcpIndex;
00696 
00697     mutable Mutex inCryptoMutex;
00698     std::list<CryptoContextCtrl *> inCryptoContexts;
00699 
00700 };
00701 
00709 class __EXPORT AVPQueue : public QueueRTCPManager
00710 {
00711 public:
00727     inline void
00728     setControlBandwidth(float fraction)
00729     { QueueRTCPManager::setControlBandwidth(fraction); }
00730 
00731     float
00732     getControlBandwidth() const
00733     { return QueueRTCPManager::getControlBandwidth(); }
00734 
00735 protected:
00736     AVPQueue(uint32 size = RTPDataQueue::defaultMembersHashSize,
00737          RTPApplication& app = defaultApplication()) :
00738         QueueRTCPManager(size,app)
00739     { }
00740 
00744     AVPQueue(uint32 ssrc, uint32 size =
00745          RTPDataQueue::defaultMembersHashSize,
00746          RTPApplication& app = defaultApplication()) :
00747         QueueRTCPManager(ssrc,size,app)
00748     { }
00749     inline virtual ~AVPQueue()
00750     { }
00751 };
00752  // cqueue
00754 
00755 END_NAMESPACE
00756 
00757 #endif  //CCXX_RTP_CQUEUE_H_
00758 

Generated on 14 Aug 2013 for ccRTP by  doxygen 1.4.7