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;
39 * rtp_stats_calculate_rtcp_interval:
40 * @stats: an #RTPSessionStats struct
42 * Calculate the RTCP interval. The result of this function is the amount of
43 * time to wait (in seconds) before sender a new RTCP message.
45 * Returns: the RTCP interval.
48 rtp_stats_calculate_rtcp_interval (RTPSessionStats * stats, gboolean sender)
50 gdouble active, senders, receivers, sfraction;
54 active = stats->active_sources;
55 /* Try to avoid division by zero */
56 if (stats->active_sources == 0)
59 senders = (gdouble) stats->sender_sources;
60 receivers = (gdouble) (active - senders);
61 avg_rtcp = (gdouble) stats->avg_rtcp_packet_size;
63 sfraction = senders / active;
65 GST_DEBUG ("senders: %f, receivers %f, avg_rtcp %f, sfraction %f",
66 senders, receivers, avg_rtcp, sfraction);
68 if (sfraction <= stats->sender_fraction) {
71 (avg_rtcp * senders) / (stats->sender_fraction *
72 stats->rtcp_bandwidth);
75 (avg_rtcp * receivers) / ((1.0 -
76 stats->sender_fraction) * stats->rtcp_bandwidth);
79 interval = (avg_rtcp * active) / stats->rtcp_bandwidth;
82 if (interval < stats->min_interval)
83 interval = stats->min_interval;
85 if (!stats->sent_rtcp)
92 * rtp_stats_calculate_rtcp_interval:
93 * @stats: an #RTPSessionStats struct
94 * @interval: an RTCP interval
96 * Apply a random jitter to the @interval. @interval is typically obtained with
97 * rtp_stats_calculate_rtcp_interval().
99 * Returns: the new RTCP interval.
102 rtp_stats_add_rtcp_jitter (RTPSessionStats * stats, gdouble interval)
105 * To compensate for "unconditional reconsideration" converging to a
106 * value below the intended average.
108 #define COMPENSATION (2.71828 - 1.5);
110 return (interval * g_random_double_range (0.5, 1.5)) / COMPENSATION;