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 
00049 #ifdef  CCXX_NAMESPACES
00050 namespace ost {
00051 #endif
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 
00161         void
00162         setMinRTCPInterval(microtimeout_t);
00163 
00167         inline uint32
00168         getSendRTCPPacketCount() const
00169         { return ctrlSendCount; }
00170 
00171 protected:
00172         QueueRTCPManager(uint32 size = RTPDataQueue::defaultMembersHashSize, 
00173                          RTPApplication& app = defaultApplication());
00174 
00175         QueueRTCPManager(uint32 ssrc,
00176                          uint32 size = RTPDataQueue::defaultMembersHashSize, 
00177                          RTPApplication& app = defaultApplication());
00178 
00179         virtual 
00180         ~QueueRTCPManager();
00181 
00182         const RTPApplication&
00183         getApplication()
00184         { return queueApplication; }
00185 
00186         inline void
00187         setControlBandwidth(float fraction)
00188         { controlBwFract = fraction; }
00189         
00190         float 
00191         getControlBandwidth() const
00192         { return controlBwFract; }
00193 
00198         void 
00199         controlTransmissionService();
00200 
00205         void 
00206         controlReceptionService();
00207 
00220         bool checkSSRCInRTCPPkt(SyncSourceLink& sourceLink, bool is_new,
00221                                 InetAddress& na, tpport_t tp);
00222 
00223         void
00224         endQueueRTCPManager();
00225 
00236         virtual void
00237         onGotSR(SyncSource& source, SendReport& SR, uint8 blocks);
00238         
00249         virtual void
00250         onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks);
00251         
00256         bool
00257         onGotSDES(SyncSource& source, RTCPPacket& pkt);
00258 
00268         virtual bool
00269         onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len);
00270 
00280         inline virtual void
00281         onGotAPP(SyncSource&, RTCPCompoundHandler::APPPacket&,
00282                  size_t)
00283         { return; }
00284 
00285         inline timeval
00286         getRTCPCheckInterval()
00287         { return rtcpCheckInterval; }
00288 
00293         uint32
00294         getLastSendPacketCount() const
00295         { return lastSendPacketCount; }
00296         
00300         inline void
00301         setPrevMembersNum(uint32 n)
00302         { reconsInfo.rtcpPMembers = n; };
00303 
00304         inline uint32 
00305         getPrevMembersCount() const
00306         { return reconsInfo.rtcpPMembers; };
00307 
00326         size_t
00327         dispatchBYE(const std::string& reason);
00328 
00329         size_t
00330         sendControlToDestinations(unsigned char* buffer, size_t len);
00331 
00332 private:
00333         QueueRTCPManager(const QueueRTCPManager &o);
00334         
00335         QueueRTCPManager&
00336         operator=(const QueueRTCPManager &o);
00337         
00343         size_t
00344         dispatchControlPacket();
00345 
00357         void
00358         takeInControlPacket();
00359 
00373         virtual timeval 
00374         computeRTCPInterval();
00375 
00383         virtual SDESItemType
00384         scheduleSDESItem();
00385 
00391         inline virtual void
00392         onSSRCCollision(const SyncSource&)
00393         { }
00394 
00398         virtual bool
00399         end2EndDelayed(IncomingRTPPktLink& p);
00400 
00409         inline virtual void
00410         onGotRRSRExtension(unsigned char*, size_t)
00411         { return; }
00412 
00422         inline virtual void
00423         onGotGoodbye(const SyncSource&, const std::string&)
00424         { return; }
00425 
00438         bool
00439         getBYE(RTCPPacket &pkt, size_t &pointer, size_t len);
00440 
00444         uint8
00445         packReportBlocks(RRBlock* blocks, uint16& len, uint16& available);
00446         
00455         void 
00456         packSDES(uint16& len);
00457 
00469         void
00470         updateAvgRTCPSize(size_t len);
00471         
00477         void
00478         reverseReconsideration();
00479         
00480         bool
00481         timerReconsideration();
00482         
00491         void 
00492         expireSSRCs();
00493         
00497         void
00498         getOnlyBye();
00499 
00504         void 
00505         setSDESItem(Participant* part, SDESItemType type,
00506                     const char* const value, size_t len);
00507 
00512         void 
00513         setPRIVPrefix(Participant* part, const char* const value, size_t len);
00514         
00526         inline virtual uint16
00527         networkHeaderSize()
00528         { return 20; }
00529 
00541         inline virtual uint16
00542         transportHeaderSize()
00543         { return 8; }
00544 
00545         SDESItemType
00546         nextSDESType(SDESItemType t);
00547         
00548         virtual size_t
00549         sendControl(const unsigned char* const buffer, size_t len) = 0;
00550 
00551         virtual size_t 
00552         recvControl(unsigned char* buffer, size_t len,
00553                     InetHostAddress& na, tpport_t& tp) = 0;
00554 
00555         virtual bool 
00556         isPendingControl(microtimeout_t timeout) = 0;
00557         
00558         // whether the RTCP service is active
00559         volatile bool controlServiceActive;
00560         float controlBwFract, sendControlBwFract, recvControlBwFract;
00561         // number of RTCP packets sent since the beginning
00562         uint32 ctrlSendCount;
00563 
00564         // Network + transport headers size, typically size of IP +
00565         // UDP headers
00566         uint16 lowerHeadersSize;
00567 
00568         SDESItemType nextScheduledSDESItem;
00569         static const SDESItemType firstSchedulable;
00570         static const SDESItemType lastSchedulable;
00571 
00572         // state for rtcp timing. Its meaning is defined in
00573         // draft-ietf-avt-rtp-new, 6.3.
00574 
00575         // Parameters for timer reconsideration algorithm
00576         struct {
00577                 timeval rtcpTp, rtcpTc, rtcpTn;
00578                 uint32 rtcpPMembers;
00579         } reconsInfo;
00580         bool rtcpWeSent;
00581         uint16 rtcpAvgSize;
00582         bool rtcpInitial;
00583         // last time we checked if there were incoming RTCP packets
00584         timeval rtcpLastCheck;
00585         // interval to check if there are incoming RTCP packets
00586         timeval rtcpCheckInterval;
00587         // next time to check if there are incoming RTCP packets
00588         timeval rtcpNextCheck;
00589 
00590         // number of RTP data packets sent at the time of the last
00591         // RTCP packet transmission.
00592         uint32 lastSendPacketCount;
00593         
00594         // minimum interval for transmission of RTCP packets. The
00595         // result of computeRTCPInterval will always be >= (times a
00596         // random number between 0.5 and 1.5).
00597         microtimeout_t rtcpMinInterval;
00598 
00599         microtimeout_t leavingDelay;
00600         static const microtimeout_t defaultEnd2EndDelay;
00601         // Maximum delay allowed between packet timestamping and
00602         // packet availability for the application.
00603         microtimeout_t end2EndDelay;
00604         // Application this queue is bound to.
00605         RTPApplication& queueApplication;
00606 
00607         // an empty RTPData
00608         static const uint16 TIMEOUT_MULTIPLIER;
00609         static const double RECONSIDERATION_COMPENSATION;
00610 };
00611 
00619 class AVPQueue : public QueueRTCPManager
00620 {
00621 public:
00637         inline void
00638         setControlBandwidth(float fraction)
00639         { QueueRTCPManager::setControlBandwidth(fraction); }
00640         
00641         float 
00642         getControlBandwidth() const
00643         { return QueueRTCPManager::getControlBandwidth(); }
00644         
00645 protected: 
00646         AVPQueue(uint32 size = RTPDataQueue::defaultMembersHashSize, 
00647                  RTPApplication& app = defaultApplication()) :
00648                 QueueRTCPManager(size,app)
00649         { }
00650 
00654         AVPQueue(uint32 ssrc, uint32 size = 
00655                  RTPDataQueue::defaultMembersHashSize, 
00656                  RTPApplication& app = defaultApplication()) : 
00657                 QueueRTCPManager(ssrc,size,app)
00658         { }
00659         inline virtual ~AVPQueue() 
00660         { }
00661 };
00662  // cqueue
00664 
00665 #ifdef  CCXX_NAMESPACES
00666 }
00667 #endif
00668 
00669 #endif  //CCXX_RTP_CQUEUE_H_
00670 

Generated on Fri Dec 9 04:53:19 2005 for ccRTP by  doxygen 1.4.5