2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3 * Copyright (C) 2015 Kurento (http://kurento.org/)
4 * @author: Miguel ParĂs <mparisdiaz@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef __RTP_STATS_H__
23 #define __RTP_STATS_H__
26 #include <gst/net/gstnetaddressmeta.h>
27 #include <gst/rtp/rtp.h>
33 * A sender report structure.
47 * A receiver report structure.
51 guint32 ssrc; /* who the report is from */
54 guint32 exthighestseq;
63 * @send: if this is a packet for sending
64 * @rtp: if this info is about an RTP packet
65 * @is_list: if this is a bufferlist
66 * @data: a #GstBuffer or #GstBufferList
67 * @address: address of the sender of the packet
68 * @current_time: current time according to the system clock
69 * @running_time: time of a packet as buffer running_time
70 * @ntpnstime: time of a packet NTP time in nanoseconds
71 * @header_len: number of overhead bytes per packet
72 * @bytes: bytes of the packet including lowlevel overhead
73 * @payload_len: bytes of the RTP payload
74 * @seqnum: the seqnum of the packet
75 * @pt: the payload type of the packet
76 * @rtptime: the RTP time of the packet
78 * Structure holding information about the packet.
85 GSocketAddress *address;
86 GstClockTime current_time;
87 GstClockTime running_time;
103 * @packetsreceived: number of received packets in total
104 * @prevpacketsreceived: number of packets received in previous reporting
106 * @octetsreceived: number of payload bytes received
107 * @bytesreceived: number of total bytes received including headers and lower
108 * protocol level overhead
109 * @max_seqnr: highest sequence number received
110 * @transit: previous transit time used for calculating @jitter
111 * @jitter: current jitter (in clock rate units scaled by 16 for precision)
112 * @prev_rtptime: previous time when an RTP packet was received
113 * @prev_rtcptime: previous time when an RTCP packet was received
114 * @last_rtptime: time when last RTP packet received
115 * @last_rtcptime: time when last RTCP packet received
116 * @curr_rr: index of current @rr block
117 * @rr: previous and current receiver report block
118 * @curr_sr: index of current @sr block
119 * @sr: previous and current sender report block
121 * Stats about a source.
124 guint64 packets_received;
125 guint64 octets_received;
126 guint64 bytes_received;
128 guint32 prev_expected;
129 guint32 prev_received;
138 guint64 packets_sent;
141 guint sent_pli_count;
142 guint recv_pli_count;
143 guint sent_fir_count;
144 guint recv_fir_count;
145 guint sent_nack_count;
146 guint recv_nack_count;
148 /* when we received stuff */
149 GstClockTime prev_rtptime;
150 GstClockTime prev_rtcptime;
151 GstClockTime last_rtptime;
152 GstClockTime last_rtcptime;
154 /* sender and receiver reports */
156 RTPReceiverReport rr[2];
158 RTPSenderReport sr[2];
161 #define RTP_STATS_BANDWIDTH 64000
162 #define RTP_STATS_RTCP_FRACTION 0.05
164 * Minimum average time between RTCP packets from this site (in
165 * seconds). This time prevents the reports from `clumping' when
166 * sessions are small and the law of large numbers isn't helping
167 * to smooth out the traffic. It also keeps the report interval
168 * from becoming ridiculously small during transient outages like
169 * a network partition.
171 #define RTP_STATS_MIN_INTERVAL 5.0
173 * Fraction of the RTCP bandwidth to be shared among active
174 * senders. (This fraction was chosen so that in a typical
175 * session with one or two active senders, the computed report
176 * time would be roughly equal to the minimum report time so that
177 * we don't unnecessarily slow down receiver reports.) The
178 * receiver fraction must be 1 - the sender fraction.
180 #define RTP_STATS_SENDER_FRACTION (0.25)
181 #define RTP_STATS_RECEIVER_FRACTION (1.0 - RTP_STATS_SENDER_FRACTION)
184 * When receiving a BYE from a source, remove the source from the database
185 * after this timeout.
187 #define RTP_STATS_BYE_TIMEOUT (2 * GST_SECOND)
190 * The default and minimum values of the maximum number of missing packets we tolerate.
191 * These are packets with asequence number bigger than the last seen packet.
193 #define RTP_DEF_DROPOUT 3000
194 #define RTP_MIN_DROPOUT 30
197 * The default and minimum values of the maximum number of misordered packets we tolerate.
198 * These are packets with a sequence number smaller than the last seen packet.
200 #define RTP_DEF_MISORDER 100
201 #define RTP_MIN_MISORDER 10
206 * Context to calculate the pseudo-average packet rate.
213 guint32 avg_packet_rate;
216 void gst_rtp_packet_rate_ctx_reset (RTPPacketRateCtx * ctx, gint32 clock_rate);
217 guint32 gst_rtp_packet_rate_ctx_update (RTPPacketRateCtx *ctx, guint16 seqnum, guint32 ts);
218 guint32 gst_rtp_packet_rate_ctx_get (RTPPacketRateCtx *ctx);
219 guint32 gst_rtp_packet_rate_ctx_get_max_dropout (RTPPacketRateCtx *ctx, gint32 time_ms);
220 guint32 gst_rtp_packet_rate_ctx_get_max_misorder (RTPPacketRateCtx *ctx, gint32 time_ms);
225 * Stats kept for a session and used to produce RTCP packet timeouts.
229 guint rtcp_bandwidth;
230 gdouble sender_fraction;
231 gdouble receiver_fraction;
232 gdouble min_interval;
233 GstClockTime bye_timeout;
234 guint internal_sources;
235 guint sender_sources;
236 guint internal_sender_sources;
237 guint active_sources;
238 guint avg_rtcp_packet_size;
242 guint nacks_received;
245 void rtp_stats_init_defaults (RTPSessionStats *stats);
247 void rtp_stats_set_bandwidths (RTPSessionStats *stats,
252 GstClockTime rtp_stats_calculate_rtcp_interval (RTPSessionStats *stats, gboolean sender, GstRTPProfile profile, gboolean ptp, gboolean first);
253 GstClockTime rtp_stats_add_rtcp_jitter (RTPSessionStats *stats, GstClockTime interval);
254 GstClockTime rtp_stats_calculate_bye_interval (RTPSessionStats *stats);
255 gint64 rtp_stats_get_packets_lost (const RTPSourceStats *stats);
257 void rtp_stats_set_min_interval (RTPSessionStats *stats,
258 gdouble min_interval);
261 gboolean __g_socket_address_equal (GSocketAddress *a, GSocketAddress *b);
262 gchar * __g_socket_address_to_string (GSocketAddress * addr);
264 #endif /* __RTP_STATS_H__ */