rtpmanager: add "max-dropout-time" and "max-misorder-time" props
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / rtpsource.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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __RTP_SOURCE_H__
21 #define __RTP_SOURCE_H__
22
23 #include <gst/gst.h>
24 #include <gst/rtp/rtp.h>
25 #include <gst/net/gstnetaddressmeta.h>
26 #include <gio/gio.h>
27
28 #include "rtpstats.h"
29
30 /* the default number of consecutive RTP packets we need to receive before the
31  * source is considered valid */
32 #define RTP_NO_PROBATION        0
33 #define RTP_DEFAULT_PROBATION   2
34
35 #define RTP_SEQ_MOD          (1 << 16)
36
37 typedef struct _RTPSource RTPSource;
38 typedef struct _RTPSourceClass RTPSourceClass;
39
40 #define RTP_TYPE_SOURCE             (rtp_source_get_type())
41 #define RTP_SOURCE(src)             (G_TYPE_CHECK_INSTANCE_CAST((src),RTP_TYPE_SOURCE,RTPSource))
42 #define RTP_SOURCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SOURCE,RTPSourceClass))
43 #define RTP_IS_SOURCE(src)          (G_TYPE_CHECK_INSTANCE_TYPE((src),RTP_TYPE_SOURCE))
44 #define RTP_IS_SOURCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SOURCE))
45 #define RTP_SOURCE_CAST(src)        ((RTPSource *)(src))
46
47 /**
48  * RTP_SOURCE_IS_ACTIVE:
49  * @src: an #RTPSource
50  *
51  * Check if @src is active. A source is active when it has been validated
52  * and has not yet received a BYE packet.
53  */
54 #define RTP_SOURCE_IS_ACTIVE(src)  (src->validated && !src->marked_bye)
55
56 /**
57  * RTP_SOURCE_IS_SENDER:
58  * @src: an #RTPSource
59  *
60  * Check if @src is a sender.
61  */
62 #define RTP_SOURCE_IS_SENDER(src)  (src->is_sender)
63 /**
64  * RTP_SOURCE_IS_MARKED_BYE:
65  * @src: an #RTPSource
66  *
67  * Check if @src is a marked as BYE.
68  */
69 #define RTP_SOURCE_IS_MARKED_BYE(src)  (src->marked_bye)
70
71
72 /**
73  * RTPSourcePushRTP:
74  * @src: an #RTPSource
75  * @data: the RTP buffer or buffer list ready for processing
76  * @user_data: user data specified when registering
77  *
78  * This callback will be called when @src has @buffer ready for further
79  * processing.
80  *
81  * Returns: a #GstFlowReturn.
82  */
83 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, gpointer data,
84         gpointer user_data);
85
86 /**
87  * RTPSourceClockRate:
88  * @src: an #RTPSource
89  * @payload: a payload type
90  * @user_data: user data specified when registering
91  *
92  * This callback will be called when @src needs the clock-rate of the
93  * @payload.
94  *
95  * Returns: a clock-rate for @payload.
96  */
97 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
98
99 /**
100  * RTPSourceCallbacks:
101  * @push_rtp: a packet becomes available for handling
102  * @clock_rate: a clock-rate is requested
103  * @get_time: the current clock time is requested
104  *
105  * Callbacks performed by #RTPSource when actions need to be performed.
106  */
107 typedef struct {
108   RTPSourcePushRTP     push_rtp;
109   RTPSourceClockRate   clock_rate;
110 } RTPSourceCallbacks;
111
112 /**
113  * RTPConflictingAddress:
114  * @address: #GSocketAddress which conflicted
115  * @last_conflict_time: time when the last conflict was seen
116  *
117  * This structure is used to account for addresses that have conflicted to find
118  * loops.
119  */
120 typedef struct {
121   GSocketAddress *address;
122   GstClockTime time;
123 } RTPConflictingAddress;
124
125 /**
126  * RTPSource:
127  *
128  * A source in the #RTPSession
129  *
130  * @conflicting_addresses: GList of conflicting addresses
131  */
132 struct _RTPSource {
133   GObject       object;
134
135   /*< private >*/
136   guint32       ssrc;
137
138   guint16       generation;
139   GHashTable    *reported_in_sr_of;     /* set of SSRCs */
140
141   guint         probation;
142   guint         curr_probation;
143   gboolean      validated;
144   gboolean      internal;
145   gboolean      is_csrc;
146   gboolean      is_sender;
147   gboolean      closing;
148
149   GstStructure  *sdes;
150
151   gboolean      marked_bye;
152   gchar        *bye_reason;
153   gboolean      sent_bye;
154
155   GSocketAddress *rtp_from;
156   GSocketAddress *rtcp_from;
157
158   gint          payload;
159   GstCaps      *caps;
160   gint          clock_rate;
161   gint32        seqnum_offset;
162
163   GstClockTime  bye_time;
164   GstClockTime  last_activity;
165   GstClockTime  last_rtp_activity;
166
167   GstClockTime  last_rtime;
168   GstClockTime  last_rtptime;
169
170   /* for bitrate estimation */
171   guint64       bitrate;
172   GstClockTime  prev_rtime;
173   guint64       bytes_sent;
174   guint64       bytes_received;
175
176   GQueue       *packets;
177   guint32       max_dropout_time;
178   guint32       max_misorder_time;
179
180   RTPSourceCallbacks callbacks;
181   gpointer           user_data;
182
183   RTPSourceStats stats;
184   RTPReceiverReport last_rr;
185
186   GList         *conflicting_addresses;
187
188   GQueue        *retained_feedback;
189
190   gboolean     send_pli;
191   gboolean     send_fir;
192   guint8       current_send_fir_seqnum;
193   gint         last_fir_count;
194
195   gboolean     send_nack;
196   GArray      *nacks;
197
198 };
199
200 struct _RTPSourceClass {
201   GObjectClass   parent_class;
202 };
203
204 GType rtp_source_get_type (void);
205
206 /* managing lifetime of sources */
207 RTPSource*      rtp_source_new                 (guint32 ssrc);
208 void            rtp_source_set_callbacks       (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
209
210 /* properties */
211 guint32         rtp_source_get_ssrc            (RTPSource *src);
212
213 void            rtp_source_set_as_csrc         (RTPSource *src);
214 gboolean        rtp_source_is_as_csrc          (RTPSource *src);
215
216 gboolean        rtp_source_is_active           (RTPSource *src);
217 gboolean        rtp_source_is_validated        (RTPSource *src);
218 gboolean        rtp_source_is_sender           (RTPSource *src);
219
220 void            rtp_source_mark_bye            (RTPSource *src, const gchar *reason);
221 gboolean        rtp_source_is_marked_bye       (RTPSource *src);
222 gchar *         rtp_source_get_bye_reason      (RTPSource *src);
223
224 void            rtp_source_update_caps         (RTPSource *src, GstCaps *caps);
225
226 /* SDES info */
227 const GstStructure *
228                 rtp_source_get_sdes_struct     (RTPSource * src);
229 gboolean        rtp_source_set_sdes_struct     (RTPSource * src, GstStructure *sdes);
230
231 /* handling network address */
232 void            rtp_source_set_rtp_from        (RTPSource *src, GSocketAddress *address);
233 void            rtp_source_set_rtcp_from       (RTPSource *src, GSocketAddress *address);
234
235 /* handling RTP */
236 GstFlowReturn   rtp_source_process_rtp         (RTPSource *src, RTPPacketInfo *pinfo);
237
238 GstFlowReturn   rtp_source_send_rtp            (RTPSource *src, RTPPacketInfo *pinfo);
239
240 /* RTCP messages */
241 void            rtp_source_process_sr          (RTPSource *src, GstClockTime time, guint64 ntptime,
242                                                 guint32 rtptime, guint32 packet_count, guint32 octet_count);
243 void            rtp_source_process_rb          (RTPSource *src, guint64 ntpnstime, guint8 fractionlost,
244                                                 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
245                                                 guint32 lsr, guint32 dlsr);
246
247 gboolean        rtp_source_get_new_sr          (RTPSource *src, guint64 ntpnstime, GstClockTime running_time,
248                                                 guint64 *ntptime, guint32 *rtptime, guint32 *packet_count,
249                                                 guint32 *octet_count);
250 gboolean        rtp_source_get_new_rb          (RTPSource *src, GstClockTime time, guint8 *fractionlost,
251                                                 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
252                                                 guint32 *lsr, guint32 *dlsr);
253
254 gboolean        rtp_source_get_last_sr         (RTPSource *src, GstClockTime *time, guint64 *ntptime,
255                                                 guint32 *rtptime, guint32 *packet_count,
256                                                 guint32 *octet_count);
257 gboolean        rtp_source_get_last_rb         (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
258                                                 guint32 *exthighestseq, guint32 *jitter,
259                                                 guint32 *lsr, guint32 *dlsr, guint32 *round_trip);
260
261 void            rtp_source_reset               (RTPSource * src);
262
263 gboolean        rtp_source_find_conflicting_address (RTPSource * src,
264                                                 GSocketAddress *address,
265                                                 GstClockTime time);
266
267 void            rtp_source_add_conflicting_address (RTPSource * src,
268                                                 GSocketAddress *address,
269                                                 GstClockTime time);
270
271 gboolean        find_conflicting_address       (GList * conflicting_address,
272                                                 GSocketAddress * address,
273                                                 GstClockTime time);
274
275 GList *         add_conflicting_address        (GList * conflicting_addresses,
276                                                 GSocketAddress * address,
277                                                 GstClockTime time);
278 GList *         timeout_conflicting_addresses  (GList * conflicting_addresses,
279                                                 GstClockTime current_time);
280
281 void            rtp_conflicting_address_free   (RTPConflictingAddress * addr);
282
283 void            rtp_source_timeout             (RTPSource * src,
284                                                 GstClockTime current_time,
285                                                 GstClockTime feedback_retention_window);
286
287 void            rtp_source_retain_rtcp_packet  (RTPSource * src,
288                                                 GstRTCPPacket *pkt,
289                                                 GstClockTime running_time);
290 gboolean        rtp_source_has_retained        (RTPSource * src,
291                                                 GCompareFunc func,
292                                                 gconstpointer data);
293
294 void            rtp_source_register_nack       (RTPSource * src,
295                                                 guint16 seqnum);
296 guint32 *       rtp_source_get_nacks           (RTPSource * src, guint *n_nacks);
297 void            rtp_source_clear_nacks         (RTPSource * src);
298
299 #endif /* __RTP_SOURCE_H__ */