2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef __RTP_STATS_H__
21 #define __RTP_STATS_H__
24 #include <gst/net/gstnetaddressmeta.h>
30 * A sender report structure.
44 * A receiver report structure.
48 guint32 ssrc; /* who the report is from */
51 guint32 exthighestseq;
60 * @address: address of the sender of the packet
61 * @current_time: current time according to the system clock
62 * @running_time: time of a packet as buffer running_time
63 * @ntpnstime: time of a packet NTP time in nanoseconds
64 * @bytes: bytes of the packet including lowlevel overhead
65 * @payload_len: bytes of the RTP payload
67 * Structure holding information about the packet.
70 GSocketAddress *address;
71 GstClockTime current_time;
72 GstClockTime running_time;
80 * @packetsreceived: number of received packets in total
81 * @prevpacketsreceived: number of packets received in previous reporting
83 * @octetsreceived: number of payload bytes received
84 * @bytesreceived: number of total bytes received including headers and lower
85 * protocol level overhead
86 * @max_seqnr: highest sequence number received
87 * @transit: previous transit time used for calculating @jitter
88 * @jitter: current jitter
89 * @prev_rtptime: previous time when an RTP packet was received
90 * @prev_rtcptime: previous time when an RTCP packet was received
91 * @last_rtptime: time when last RTP packet received
92 * @last_rtcptime: time when last RTCP packet received
93 * @curr_rr: index of current @rr block
94 * @rr: previous and current receiver report block
95 * @curr_sr: index of current @sr block
96 * @sr: previous and current sender report block
98 * Stats about a source.
101 guint64 packets_received;
102 guint64 octets_received;
103 guint64 bytes_received;
105 guint32 prev_expected;
106 guint32 prev_received;
115 guint64 packets_sent;
118 /* when we received stuff */
119 GstClockTime prev_rtptime;
120 GstClockTime prev_rtcptime;
121 GstClockTime last_rtptime;
122 GstClockTime last_rtcptime;
124 /* sender and receiver reports */
126 RTPReceiverReport rr[2];
128 RTPSenderReport sr[2];
131 #define RTP_STATS_BANDWIDTH 64000
132 #define RTP_STATS_RTCP_FRACTION 0.05
134 * Minimum average time between RTCP packets from this site (in
135 * seconds). This time prevents the reports from `clumping' when
136 * sessions are small and the law of large numbers isn't helping
137 * to smooth out the traffic. It also keeps the report interval
138 * from becoming ridiculously small during transient outages like
139 * a network partition.
141 #define RTP_STATS_MIN_INTERVAL 5.0
143 * Fraction of the RTCP bandwidth to be shared among active
144 * senders. (This fraction was chosen so that in a typical
145 * session with one or two active senders, the computed report
146 * time would be roughly equal to the minimum report time so that
147 * we don't unnecessarily slow down receiver reports.) The
148 * receiver fraction must be 1 - the sender fraction.
150 #define RTP_STATS_SENDER_FRACTION (0.25)
151 #define RTP_STATS_RECEIVER_FRACTION (1.0 - RTP_STATS_SENDER_FRACTION)
154 * When receiving a BYE from a source, remove the source from the database
155 * after this timeout.
157 #define RTP_STATS_BYE_TIMEOUT (2 * GST_SECOND)
160 * The maximum number of missing packets we tollerate. These are packets with a
161 * sequence number bigger than the last seen packet.
163 #define RTP_MAX_DROPOUT 3000
165 * The maximum number of misordered packets we tollerate. These are packets with
166 * a sequence number smaller than the last seen packet.
168 #define RTP_MAX_MISORDER 100
173 * Stats kept for a session and used to produce RTCP packet timeouts.
177 guint rtcp_bandwidth;
178 gdouble sender_fraction;
179 gdouble receiver_fraction;
180 gdouble min_interval;
181 GstClockTime bye_timeout;
182 guint internal_sources;
183 guint sender_sources;
184 guint internal_sender_sources;
185 guint active_sources;
186 guint avg_rtcp_packet_size;
190 void rtp_stats_init_defaults (RTPSessionStats *stats);
192 void rtp_stats_set_bandwidths (RTPSessionStats *stats,
197 GstClockTime rtp_stats_calculate_rtcp_interval (RTPSessionStats *stats, gboolean sender, gboolean first);
198 GstClockTime rtp_stats_add_rtcp_jitter (RTPSessionStats *stats, GstClockTime interval);
199 GstClockTime rtp_stats_calculate_bye_interval (RTPSessionStats *stats);
200 gint64 rtp_stats_get_packets_lost (const RTPSourceStats *stats);
202 void rtp_stats_set_min_interval (RTPSessionStats *stats,
203 gdouble min_interval);
206 gboolean __g_socket_address_equal (GSocketAddress *a, GSocketAddress *b);
207 gchar * __g_socket_address_to_string (GSocketAddress * addr);
209 #endif /* __RTP_STATS_H__ */