jrtplib  3.8.0
rtcpscheduler.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2010 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31 */
32 
37 #ifndef RTCPSCHEDULER_H
38 
39 #define RTCPSCHEDULER_H
40 
41 #include "rtpconfig.h"
42 #include "rtptimeutilities.h"
43 #include "rtprandom.h"
44 
45 class RTCPCompoundPacket;
46 class RTPPacket;
47 class RTPSources;
48 
51 {
52 public:
55 
57  int SetRTCPBandwidth(double bw);
58 
60  double GetRTCPBandwidth() const { return bandwidth; }
61 
63  int SetSenderBandwidthFraction(double fraction);
64 
66  double GetSenderBandwidthFraction() const { return senderfraction; }
67 
70 
72  RTPTime GetMinimumTransmissionInterval() const { return mininterval; }
73 
75  void SetUseHalfAtStartup(bool usehalf) { usehalfatstartup = usehalf; }
76 
80  bool GetUseHalfAtStartup() const { return usehalfatstartup; }
81 
83  void SetRequestImmediateBYE(bool v) { immediatebye = v; }
84 
88  bool GetRequestImmediateBYE() const { return immediatebye; }
89 private:
90  double bandwidth;
91  double senderfraction;
92  RTPTime mininterval;
93  bool usehalfatstartup;
94  bool immediatebye;
95 };
96 
99 {
100 public:
108  RTCPScheduler(RTPSources &sources, RTPRandom &rtprand);
109  ~RTCPScheduler();
110 
112  void Reset();
113 
115  void SetParameters(const RTCPSchedulerParams &params) { schedparams = params; }
116 
118  RTCPSchedulerParams GetParameters() const { return schedparams; }
119 
121  void SetHeaderOverhead(size_t numbytes) { headeroverhead = numbytes; }
122 
124  size_t GetHeaderOverhead() const { return headeroverhead; }
125 
127  void AnalyseIncoming(RTCPCompoundPacket &rtcpcomppack);
128 
130  void AnalyseOutgoing(RTCPCompoundPacket &rtcpcomppack);
131 
133  void ActiveMemberDecrease();
134 
138  void ScheduleBYEPacket(size_t packetsize);
139 
145 
151  bool IsTime();
152 
157  RTPTime CalculateDeterministicInterval(bool sender = false);
158 private:
159  void CalculateNextRTCPTime();
160  void PerformReverseReconsideration();
161  RTPTime CalculateBYETransmissionInterval();
162  RTPTime CalculateTransmissionInterval(bool sender);
163 
164  RTPSources &sources;
165  RTCPSchedulerParams schedparams;
166  size_t headeroverhead;
167  size_t avgrtcppacksize;
168  bool hassentrtcp;
169  bool firstcall;
170  RTPTime nextrtcptime;
171  RTPTime prevrtcptime;
172  int pmembers;
173 
174  // for BYE packet scheduling
175  bool byescheduled;
176  int byemembers,pbyemembers;
177  size_t avgbyepacketsize;
178  bool sendbyenow;
179 
180  RTPRandom &rtprand;
181 };
182 
183 #endif // RTCPSCHEDULER_H
184 
int SetMinimumTransmissionInterval(const RTPTime &t)
Sets the minimum (deterministic) interval between RTCP compound packets to t.
double GetRTCPBandwidth() const
Returns the used RTCP bandwidth in bytes per second (default is 1000).
Definition: rtcpscheduler.h:60
double GetSenderBandwidthFraction() const
Returns the fraction of the RTCP bandwidth reserved for senders (default is 25%). ...
Definition: rtcpscheduler.h:66
void ScheduleBYEPacket(size_t packetsize)
Asks the scheduler to schedule an RTCP compound packet containing a BYE packetl; the compound packet ...
void AnalyseOutgoing(RTCPCompoundPacket &rtcpcomppack)
For each outgoing RTCP compound packet, this function has to be called for the scheduler to work corr...
Represents an RTP Packet.
Definition: rtppacket.h:53
void SetRequestImmediateBYE(bool v)
If v is true, the scheduler will schedule a BYE packet to be sent immediately if allowed.
Definition: rtcpscheduler.h:83
RTPTime GetTransmissionDelay()
Returns the delay after which an RTCP compound will possibly have to be sent.
Represents a table in which information about the participating sources is kept.
Definition: rtpsources.h:71
int SetRTCPBandwidth(double bw)
Sets the RTCP bandwidth to be used to bw (in bytes per second).
int SetSenderBandwidthFraction(double fraction)
Sets the fraction of the RTCP bandwidth reserved for senders to fraction.
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
Represents an RTCP compound packet.
Definition: rtcpcompoundpacket.h:50
void ActiveMemberDecrease()
This function has to be called each time a member times out or sends a BYE packet.
size_t GetHeaderOverhead() const
Returns the currently used header overhead.
Definition: rtcpscheduler.h:124
bool GetUseHalfAtStartup() const
Returns true if only half the minimum interval should be used before sending the first RTCP compound ...
Definition: rtcpscheduler.h:80
bool IsTime()
This function returns true if it's time to send an RTCP compound packet and false otherwise...
void SetHeaderOverhead(size_t numbytes)
Sets the header overhead from underlying protocols (for example UDP and IP) to numbytes.
Definition: rtcpscheduler.h:121
void AnalyseIncoming(RTCPCompoundPacket &rtcpcomppack)
For each incoming RTCP compound packet, this function has to be called for the scheduler to work corr...
void Reset()
Resets the scheduler.
void SetUseHalfAtStartup(bool usehalf)
If usehalf is true, only use half the minimum interval before sending the first RTCP compound packet...
Definition: rtcpscheduler.h:75
bool GetRequestImmediateBYE() const
Returns if the scheduler will schedule a BYE packet to be sent immediately if allowed (default is tru...
Definition: rtcpscheduler.h:88
void SetParameters(const RTCPSchedulerParams &params)
Sets the scheduler parameters to be used to params.
Definition: rtcpscheduler.h:115
RTCPScheduler(RTPSources &sources, RTPRandom &rtprand)
Creates an instance which will use the source table RTPSources to determine when RTCP compound packet...
Describes parameters used by the RTCPScheduler class.
Definition: rtcpscheduler.h:50
This class determines when RTCP compound packets should be sent.
Definition: rtcpscheduler.h:98
RTPTime GetMinimumTransmissionInterval() const
Returns the minimum RTCP transmission interval (default is 5 seconds).
Definition: rtcpscheduler.h:72
RTPTime CalculateDeterministicInterval(bool sender=false)
Calculates the deterministic interval at this time.
Interface for generating random numbers.
Definition: rtprandom.h:48
RTCPSchedulerParams GetParameters() const
Returns the currently used scheduler parameters.
Definition: rtcpscheduler.h:118