gst/rtpmanager/gstrtpbin.*: Add signal to notify listeners when a sender becomes...
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / rtpstats.h
1 /* GStreamer
2  * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef __RTP_STATS_H__
21 #define __RTP_STATS_H__
22
23 #include <gst/gst.h>
24 #include <gst/netbuffer/gstnetbuffer.h>
25
26 /**
27  * RTPSenderReport:
28  *
29  * A sender report structure.
30  */
31 typedef struct {
32   gboolean is_valid;
33   guint64 ntptime;
34   guint32 rtptime;
35   guint32 packet_count;
36   guint32 octet_count;
37   GstClockTime time;
38 } RTPSenderReport;
39
40 /**
41  * RTPReceiverReport:
42  *
43  * A receiver report structure.
44  */
45 typedef struct {
46   gboolean is_valid;
47   guint32 ssrc; /* who the report is from */
48   guint8  fractionlost;
49   guint32 packetslost;
50   guint32 exthighestseq;
51   guint32 jitter;
52   guint32 lsr;
53   guint32 dlsr;
54   guint32 round_trip;
55 } RTPReceiverReport;
56
57 /**
58  * RTPArrivalStats:
59  * @time: arrival time of a packet according to the system clock
60  * @timestamp: arrival time of a packet as buffer timestamp
61  * @address: address of the sender of the packet
62  * @bytes: bytes of the packet including lowlevel overhead
63  * @payload_len: bytes of the RTP payload
64  *
65  * Structure holding information about the arrival stats of a packet.
66  */
67 typedef struct {
68   GstClockTime  time;
69   GstClockTime  timestamp;
70   guint64       ntpnstime;
71   gboolean      have_address;
72   GstNetAddress address;
73   guint         bytes;
74   guint         payload_len;
75 } RTPArrivalStats;
76
77 /**
78  * RTPSourceStats:
79  * @packetsreceived: number of received packets in total
80  * @prevpacketsreceived: number of packets received in previous reporting
81  *                       interval
82  * @octetsreceived: number of payload bytes received
83  * @bytesreceived: number of total bytes received including headers and lower
84  *                 protocol level overhead
85  * @max_seqnr: highest sequence number received
86  * @transit: previous transit time used for calculating @jitter
87  * @jitter: current jitter
88  * @prev_rtptime: previous time when an RTP packet was received
89  * @prev_rtcptime: previous time when an RTCP packet was received
90  * @last_rtptime: time when last RTP packet received
91  * @last_rtcptime: time when last RTCP packet received
92  * @curr_rr: index of current @rr block
93  * @rr: previous and current receiver report block
94  * @curr_sr: index of current @sr block
95  * @sr: previous and current sender report block
96  *
97  * Stats about a source.
98  */
99 typedef struct {
100   guint64      packets_received;
101   guint64      octets_received;
102   guint64      bytes_received;
103
104   guint32      prev_expected;
105   guint32      prev_received;
106
107   guint16      max_seq;
108   guint64      cycles;
109   guint32      base_seq;
110   guint32      bad_seq;
111   guint32      transit;
112   guint32      jitter;
113
114   guint64      packets_sent;
115   guint64      octets_sent;
116
117   /* when we received stuff */
118   GstClockTime prev_rtptime;
119   GstClockTime prev_rtcptime;
120   GstClockTime last_rtptime;
121   GstClockTime last_rtcptime;
122
123   /* sender and receiver reports */
124   gint              curr_rr;
125   RTPReceiverReport rr[2];
126   gint              curr_sr;
127   RTPSenderReport   sr[2];
128 } RTPSourceStats;
129
130 #define RTP_STATS_BANDWIDTH           64000.0
131 #define RTP_STATS_RTCP_BANDWIDTH      3000.0
132 /*
133  * Minimum average time between RTCP packets from this site (in
134  * seconds).  This time prevents the reports from `clumping' when
135  * sessions are small and the law of large numbers isn't helping
136  * to smooth out the traffic.  It also keeps the report interval
137  * from becoming ridiculously small during transient outages like
138  * a network partition.
139  */
140 #define RTP_STATS_MIN_INTERVAL      5.0
141 /*
142  * Fraction of the RTCP bandwidth to be shared among active
143  * senders.  (This fraction was chosen so that in a typical
144  * session with one or two active senders, the computed report
145  * time would be roughly equal to the minimum report time so that
146  * we don't unnecessarily slow down receiver reports.) The
147  * receiver fraction must be 1 - the sender fraction.
148  */
149 #define RTP_STATS_SENDER_FRACTION       (0.25)
150 #define RTP_STATS_RECEIVER_FRACTION     (1.0 - RTP_STATS_SENDER_FRACTION)
151
152 /*
153  * When receiving a BYE from a source, remove the source from the database
154  * after this timeout.
155  */
156 #define RTP_STATS_BYE_TIMEOUT           (2 * GST_SECOND)
157
158 /*
159  * The maximum number of missing packets we tollerate. These are packets with a
160  * sequence number bigger than the last seen packet.
161  */
162 #define RTP_MAX_DROPOUT      3000
163 /*
164  * The maximum number of misordered packets we tollerate. These are packets with
165  * a sequence number smaller than the last seen packet.
166  */
167 #define RTP_MAX_MISORDER     100
168
169 /**
170  * RTPSessionStats:
171  *
172  * Stats kept for a session and used to produce RTCP packet timeouts.
173  */
174 typedef struct {
175   gdouble       bandwidth;
176   gdouble       sender_fraction;
177   gdouble       receiver_fraction;
178   gdouble       rtcp_bandwidth;
179   gdouble       min_interval;
180   GstClockTime  bye_timeout;
181   guint         sender_sources;
182   guint         active_sources;
183   guint         avg_rtcp_packet_size;
184   guint         bye_members;
185 } RTPSessionStats;
186
187 void           rtp_stats_init_defaults               (RTPSessionStats *stats);
188
189 GstClockTime   rtp_stats_calculate_rtcp_interval    (RTPSessionStats *stats, gboolean sender, gboolean first);
190 GstClockTime   rtp_stats_add_rtcp_jitter            (RTPSessionStats *stats, GstClockTime interval);
191 GstClockTime   rtp_stats_calculate_bye_interval     (RTPSessionStats *stats);
192
193 #endif /* __RTP_STATS_H__ */