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;
59 /* Very first call at application start-up uses half the min
60 * delay for quicker notification while still allowing some time
61 * before reporting for randomization and to learn about other
62 * sources so the report interval will converge to the correct
63 * interval more quickly.
65 rtcp_min_time = stats->min_interval;
69 /* Dedicate a fraction of the RTCP bandwidth to senders unless
70 * the number of senders is large enough that their share is
71 * more than that fraction.
73 n = members = stats->active_sources;
74 senders = (gdouble) stats->sender_sources;
75 rtcp_bw = stats->rtcp_bandwidth;
77 if (senders <= members * RTP_STATS_SENDER_FRACTION) {
79 rtcp_bw *= RTP_STATS_SENDER_FRACTION;
82 rtcp_bw *= RTP_STATS_RECEIVER_FRACTION;
87 avg_rtcp_size = stats->avg_rtcp_packet_size / 16.0;
89 * The effective number of sites times the average packet size is
90 * the total number of octets sent when each site sends a report.
91 * Dividing this by the effective bandwidth gives the time
92 * interval over which those packets must be sent in order to
93 * meet the bandwidth target, with a minimum enforced. In that
94 * time interval we send one report so this time is also our
95 * average time between reports.
97 interval = avg_rtcp_size * n / rtcp_bw;
98 if (interval < rtcp_min_time)
99 interval = rtcp_min_time;
101 return interval * GST_SECOND;
105 * rtp_stats_add_rtcp_jitter:
106 * @stats: an #RTPSessionStats struct
107 * @interval: an RTCP interval
109 * Apply a random jitter to the @interval. @interval is typically obtained with
110 * rtp_stats_calculate_rtcp_interval().
112 * Returns: the new RTCP interval.
115 rtp_stats_add_rtcp_jitter (RTPSessionStats * stats, GstClockTime interval)
120 * To compensate for "unconditional reconsideration" converging to a
121 * value below the intended average.
123 #define COMPENSATION (2.71828 - 1.5);
125 temp = (interval * g_random_double_range (0.5, 1.5)) / COMPENSATION;
127 return (GstClockTime) temp;
132 * rtp_stats_calculate_bye_interval:
133 * @stats: an #RTPSessionStats struct
135 * Calculate the BYE interval. The result of this function is the amount of
136 * time to wait (in nanoseconds) before sending a BYE message.
138 * Returns: the BYE interval.
141 rtp_stats_calculate_bye_interval (RTPSessionStats * stats)
144 gdouble avg_rtcp_size, rtcp_bw;
146 gdouble rtcp_min_time;
148 rtcp_min_time = (stats->min_interval) / 2.0;
150 /* Dedicate a fraction of the RTCP bandwidth to senders unless
151 * the number of senders is large enough that their share is
152 * more than that fraction.
154 members = stats->bye_members;
155 rtcp_bw = stats->rtcp_bandwidth * RTP_STATS_RECEIVER_FRACTION;
157 avg_rtcp_size = stats->avg_rtcp_packet_size / 16.0;
159 * The effective number of sites times the average packet size is
160 * the total number of octets sent when each site sends a report.
161 * Dividing this by the effective bandwidth gives the time
162 * interval over which those packets must be sent in order to
163 * meet the bandwidth target, with a minimum enforced. In that
164 * time interval we send one report so this time is also our
165 * average time between reports.
167 interval = avg_rtcp_size * members / rtcp_bw;
168 if (interval < rtcp_min_time)
169 interval = rtcp_min_time;
171 return interval * GST_SECOND;