00001 /* 00002 00003 This file is a part of JRTPLIB 00004 Copyright (c) 1999-2007 Jori Liesenborgs 00005 00006 Contact: jori.liesenborgs@gmail.com 00007 00008 This library was developed at the "Expertisecentrum Digitale Media" 00009 (http://www.edm.uhasselt.be), a research center of the Hasselt University 00010 (http://www.uhasselt.be). The library is based upon work done for 00011 my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 00012 00013 Permission is hereby granted, free of charge, to any person obtaining a 00014 copy of this software and associated documentation files (the "Software"), 00015 to deal in the Software without restriction, including without limitation 00016 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00017 and/or sell copies of the Software, and to permit persons to whom the 00018 Software is furnished to do so, subject to the following conditions: 00019 00020 The above copyright notice and this permission notice shall be included 00021 in all copies or substantial portions of the Software. 00022 00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00024 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00026 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00028 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 00029 IN THE SOFTWARE. 00030 00031 */ 00032 00037 #ifndef RTCPSCHEDULER_H 00038 00039 #define RTCPSCHEDULER_H 00040 00041 #include "rtpconfig.h" 00042 #include "rtptimeutilities.h" 00043 #include "rtprandom.h" 00044 00045 class RTCPCompoundPacket; 00046 class RTPPacket; 00047 class RTPSources; 00048 00050 class RTCPSchedulerParams 00051 { 00052 public: 00053 RTCPSchedulerParams(); 00054 ~RTCPSchedulerParams(); 00055 00057 int SetRTCPBandwidth(double bw); 00058 00060 double GetRTCPBandwidth() const { return bandwidth; } 00061 00063 int SetSenderBandwidthFraction(double fraction); 00064 00066 double GetSenderBandwidthFraction() const { return senderfraction; } 00067 00069 int SetMinimumTransmissionInterval(const RTPTime &t); 00070 00072 RTPTime GetMinimumTransmissionInterval() const { return mininterval; } 00073 00075 void SetUseHalfAtStartup(bool usehalf) { usehalfatstartup = usehalf; } 00076 00080 bool GetUseHalfAtStartup() const { return usehalfatstartup; } 00081 00083 void SetRequestImmediateBYE(bool v) { immediatebye = v; } 00084 00088 bool GetRequestImmediateBYE() const { return immediatebye; } 00089 private: 00090 double bandwidth; 00091 double senderfraction; 00092 RTPTime mininterval; 00093 bool usehalfatstartup; 00094 bool immediatebye; 00095 }; 00096 00098 class RTCPScheduler 00099 { 00100 public: 00107 RTCPScheduler(RTPSources &sources); 00108 ~RTCPScheduler(); 00109 00111 void Reset(); 00112 00114 void SetParameters(const RTCPSchedulerParams ¶ms) { schedparams = params; } 00115 00117 RTCPSchedulerParams GetParameters() const { return schedparams; } 00118 00120 void SetHeaderOverhead(size_t numbytes) { headeroverhead = numbytes; } 00121 00123 size_t GetHeaderOverhead() const { return headeroverhead; } 00124 00126 void AnalyseIncoming(RTCPCompoundPacket &rtcpcomppack); 00127 00129 void AnalyseOutgoing(RTCPCompoundPacket &rtcpcomppack); 00130 00132 void ActiveMemberDecrease(); 00133 00137 void ScheduleBYEPacket(size_t packetsize); 00138 00143 RTPTime GetTransmissionDelay(); 00144 00150 bool IsTime(); 00151 00156 RTPTime CalculateDeterministicInterval(bool sender = false); 00157 private: 00158 void CalculateNextRTCPTime(); 00159 void PerformReverseReconsideration(); 00160 RTPTime CalculateBYETransmissionInterval(); 00161 RTPTime CalculateTransmissionInterval(bool sender); 00162 00163 RTPSources &sources; 00164 RTCPSchedulerParams schedparams; 00165 size_t headeroverhead; 00166 size_t avgrtcppacksize; 00167 bool hassentrtcp; 00168 bool firstcall; 00169 RTPTime nextrtcptime; 00170 RTPTime prevrtcptime; 00171 int pmembers; 00172 00173 // for BYE packet scheduling 00174 bool byescheduled; 00175 int byemembers,pbyemembers; 00176 size_t avgbyepacketsize; 00177 bool sendbyenow; 00178 00179 RTPRandom rtprand; 00180 }; 00181 00182 #endif // RTCPSCHEDULER_H 00183