2 * Copyright (C) <2007> Wim Taymans <wim@fluendo.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 * rtp_stats_init_defaults:
24 * @stats: an #RTPSessionStats struct
26 * Initialize @stats with its default values.
29 rtp_stats_init_defaults (RTPSessionStats * stats)
31 stats->bandwidth = RTP_STATS_BANDWIDTH;
32 stats->sender_fraction = RTP_STATS_SENDER_FRACTION;
33 stats->receiver_fraction = RTP_STATS_RECEIVER_FRACTION;
34 stats->rtcp_bandwidth = RTP_STATS_RTCP_BANDWIDTH;
35 stats->min_interval = RTP_STATS_MIN_INTERVAL;
36 stats->bye_timeout = RTP_STATS_BYE_TIMEOUT;
40 * rtp_stats_calculate_rtcp_interval:
41 * @stats: an #RTPSessionStats struct
42 * @sender: if we are a sender
43 * @first: if this is the first time
45 * Calculate the RTCP interval. The result of this function is the amount of
46 * time to wait (in nanoseconds) before sending a new RTCP message.
48 * Returns: the RTCP interval.
51 rtp_stats_calculate_rtcp_interval (RTPSessionStats * stats, gboolean we_send,
54 gdouble members, senders, n;
55 gdouble avg_rtcp_size, rtcp_bw;
57 gdouble rtcp_min_time;
60 /* Very first call at application start-up uses half the min
61 * delay for quicker notification while still allowing some time
62 * before reporting for randomization and to learn about other
63 * sources so the report interval will converge to the correct
64 * interval more quickly.
66 rtcp_min_time = stats->min_interval;
70 /* Dedicate a fraction of the RTCP bandwidth to senders unless
71 * the number of senders is large enough that their share is
72 * more than that fraction.
74 n = members = stats->active_sources;
75 senders = (gdouble) stats->sender_sources;
76 rtcp_bw = stats->rtcp_bandwidth;
78 if (senders <= members * RTP_STATS_SENDER_FRACTION) {
80 rtcp_bw *= RTP_STATS_SENDER_FRACTION;
83 rtcp_bw *= RTP_STATS_RECEIVER_FRACTION;
88 avg_rtcp_size = stats->avg_rtcp_packet_size / 16.0;
90 * The effective number of sites times the average packet size is
91 * the total number of octets sent when each site sends a report.
92 * Dividing this by the effective bandwidth gives the time
93 * interval over which those packets must be sent in order to
94 * meet the bandwidth target, with a minimum enforced. In that
95 * time interval we send one report so this time is also our
96 * average time between reports.
98 interval = avg_rtcp_size * n / rtcp_bw;
99 if (interval < rtcp_min_time)
100 interval = rtcp_min_time;
102 return interval * GST_SECOND;
106 * rtp_stats_add_rtcp_jitter:
107 * @stats: an #RTPSessionStats struct
108 * @interval: an RTCP interval
110 * Apply a random jitter to the @interval. @interval is typically obtained with
111 * rtp_stats_calculate_rtcp_interval().
113 * Returns: the new RTCP interval.
116 rtp_stats_add_rtcp_jitter (RTPSessionStats * stats, GstClockTime interval)
121 * To compensate for "unconditional reconsideration" converging to a
122 * value below the intended average.
124 #define COMPENSATION (2.71828 - 1.5);
126 temp = (interval * g_random_double_range (0.5, 1.5)) / COMPENSATION;
128 return (GstClockTime) temp;
133 * rtp_stats_calculate_bye_interval:
134 * @stats: an #RTPSessionStats struct
136 * Calculate the BYE interval. The result of this function is the amount of
137 * time to wait (in nanoseconds) before sending a BYE message.
139 * Returns: the BYE interval.
142 rtp_stats_calculate_bye_interval (RTPSessionStats * stats)
145 gdouble avg_rtcp_size, rtcp_bw;
147 gdouble rtcp_min_time;
149 rtcp_min_time = (stats->min_interval) / 2.0;
151 /* Dedicate a fraction of the RTCP bandwidth to senders unless
152 * the number of senders is large enough that their share is
153 * more than that fraction.
155 members = stats->bye_members;
156 rtcp_bw = stats->rtcp_bandwidth * RTP_STATS_RECEIVER_FRACTION;
158 avg_rtcp_size = stats->avg_rtcp_packet_size / 16.0;
160 * The effective number of sites times the average packet size is
161 * the total number of octets sent when each site sends a report.
162 * Dividing this by the effective bandwidth gives the time
163 * interval over which those packets must be sent in order to
164 * meet the bandwidth target, with a minimum enforced. In that
165 * time interval we send one report so this time is also our
166 * average time between reports.
168 interval = avg_rtcp_size * members / rtcp_bw;
169 if (interval < rtcp_min_time)
170 interval = rtcp_min_time;
172 return interval * GST_SECOND;