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_SOURCE_H__
23 #define __RTP_SOURCE_H__
26 #include <gst/rtp/rtp.h>
27 #include <gst/net/gstnetaddressmeta.h>
32 /* the default number of consecutive RTP packets we need to receive before the
33 * source is considered valid */
34 #define RTP_NO_PROBATION 0
35 #define RTP_DEFAULT_PROBATION 2
37 #define RTP_SEQ_MOD (1 << 16)
39 typedef struct _RTPSource RTPSource;
40 typedef struct _RTPSourceClass RTPSourceClass;
42 #define RTP_TYPE_SOURCE (rtp_source_get_type())
43 #define RTP_SOURCE(src) (G_TYPE_CHECK_INSTANCE_CAST((src),RTP_TYPE_SOURCE,RTPSource))
44 #define RTP_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SOURCE,RTPSourceClass))
45 #define RTP_IS_SOURCE(src) (G_TYPE_CHECK_INSTANCE_TYPE((src),RTP_TYPE_SOURCE))
46 #define RTP_IS_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SOURCE))
47 #define RTP_SOURCE_CAST(src) ((RTPSource *)(src))
50 * RTP_SOURCE_IS_ACTIVE:
53 * Check if @src is active. A source is active when it has been validated
54 * and has not yet received a BYE packet.
56 #define RTP_SOURCE_IS_ACTIVE(src) (src->validated && !src->marked_bye)
59 * RTP_SOURCE_IS_SENDER:
62 * Check if @src is a sender.
64 #define RTP_SOURCE_IS_SENDER(src) (src->is_sender)
66 * RTP_SOURCE_IS_MARKED_BYE:
69 * Check if @src is a marked as BYE.
71 #define RTP_SOURCE_IS_MARKED_BYE(src) (src->marked_bye)
77 * @data: the RTP buffer or buffer list ready for processing
78 * @user_data: user data specified when registering
80 * This callback will be called when @src has @buffer ready for further
83 * Returns: a #GstFlowReturn.
85 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, gpointer data,
91 * @payload: a payload type
92 * @user_data: user data specified when registering
94 * This callback will be called when @src needs the clock-rate of the
97 * Returns: a clock-rate for @payload.
99 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
102 * RTPSourceCallbacks:
103 * @push_rtp: a packet becomes available for handling
104 * @clock_rate: a clock-rate is requested
105 * @get_time: the current clock time is requested
107 * Callbacks performed by #RTPSource when actions need to be performed.
110 RTPSourcePushRTP push_rtp;
111 RTPSourceClockRate clock_rate;
112 } RTPSourceCallbacks;
115 * RTPConflictingAddress:
116 * @address: #GSocketAddress which conflicted
117 * @last_conflict_time: time when the last conflict was seen
119 * This structure is used to account for addresses that have conflicted to find
123 GSocketAddress *address;
125 } RTPConflictingAddress;
130 * A source in the #RTPSession
132 * @conflicting_addresses: GList of conflicting addresses
141 GHashTable *reported_in_sr_of; /* set of SSRCs */
144 guint curr_probation;
157 GSocketAddress *rtp_from;
158 GSocketAddress *rtcp_from;
163 gint32 seqnum_offset;
165 GstClockTime bye_time;
166 GstClockTime last_activity;
167 GstClockTime last_rtp_activity;
169 GstClockTime last_rtime;
170 GstClockTime last_rtptime;
172 /* for bitrate estimation */
174 GstClockTime prev_rtime;
176 guint64 bytes_received;
179 RTPPacketRateCtx packet_rate_ctx;
180 guint32 max_dropout_time;
181 guint32 max_misorder_time;
183 RTPSourceCallbacks callbacks;
186 RTPSourceStats stats;
187 RTPReceiverReport last_rr;
189 GList *conflicting_addresses;
191 GQueue *retained_feedback;
195 guint8 current_send_fir_seqnum;
197 GstClockTime last_keyframe_request;
201 GArray *nack_deadlines;
206 gboolean disable_rtcp;
209 struct _RTPSourceClass {
210 GObjectClass parent_class;
213 GType rtp_source_get_type (void);
215 /* managing lifetime of sources */
216 RTPSource* rtp_source_new (guint32 ssrc);
217 void rtp_source_set_callbacks (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
220 guint32 rtp_source_get_ssrc (RTPSource *src);
222 void rtp_source_set_as_csrc (RTPSource *src);
223 gboolean rtp_source_is_as_csrc (RTPSource *src);
225 gboolean rtp_source_is_active (RTPSource *src);
226 gboolean rtp_source_is_validated (RTPSource *src);
227 gboolean rtp_source_is_sender (RTPSource *src);
229 void rtp_source_mark_bye (RTPSource *src, const gchar *reason);
230 gboolean rtp_source_is_marked_bye (RTPSource *src);
231 gchar * rtp_source_get_bye_reason (RTPSource *src);
233 void rtp_source_update_caps (RTPSource *src, GstCaps *caps);
237 rtp_source_get_sdes_struct (RTPSource * src);
238 gboolean rtp_source_set_sdes_struct (RTPSource * src, GstStructure *sdes);
240 /* handling network address */
241 void rtp_source_set_rtp_from (RTPSource *src, GSocketAddress *address);
242 void rtp_source_set_rtcp_from (RTPSource *src, GSocketAddress *address);
245 GstFlowReturn rtp_source_process_rtp (RTPSource *src, RTPPacketInfo *pinfo);
247 GstFlowReturn rtp_source_send_rtp (RTPSource *src, RTPPacketInfo *pinfo);
250 void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime,
251 guint32 rtptime, guint32 packet_count, guint32 octet_count);
252 void rtp_source_process_rb (RTPSource *src, guint64 ntpnstime, guint8 fractionlost,
253 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
254 guint32 lsr, guint32 dlsr);
256 gboolean rtp_source_get_new_sr (RTPSource *src, guint64 ntpnstime, GstClockTime running_time,
257 guint64 *ntptime, guint32 *rtptime, guint32 *packet_count,
258 guint32 *octet_count);
259 gboolean rtp_source_get_new_rb (RTPSource *src, GstClockTime time, guint8 *fractionlost,
260 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
261 guint32 *lsr, guint32 *dlsr);
263 gboolean rtp_source_get_last_sr (RTPSource *src, GstClockTime *time, guint64 *ntptime,
264 guint32 *rtptime, guint32 *packet_count,
265 guint32 *octet_count);
266 gboolean rtp_source_get_last_rb (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
267 guint32 *exthighestseq, guint32 *jitter,
268 guint32 *lsr, guint32 *dlsr, guint32 *round_trip);
270 void rtp_source_reset (RTPSource * src);
272 gboolean rtp_source_find_conflicting_address (RTPSource * src,
273 GSocketAddress *address,
276 void rtp_source_add_conflicting_address (RTPSource * src,
277 GSocketAddress *address,
280 gboolean find_conflicting_address (GList * conflicting_address,
281 GSocketAddress * address,
284 GList * add_conflicting_address (GList * conflicting_addresses,
285 GSocketAddress * address,
287 GList * timeout_conflicting_addresses (GList * conflicting_addresses,
288 GstClockTime current_time);
290 void rtp_conflicting_address_free (RTPConflictingAddress * addr);
292 void rtp_source_timeout (RTPSource * src,
293 GstClockTime current_time,
294 GstClockTime running_time,
295 GstClockTime feedback_retention_window);
297 void rtp_source_retain_rtcp_packet (RTPSource * src,
299 GstClockTime running_time);
300 gboolean rtp_source_has_retained (RTPSource * src,
304 void rtp_source_register_nack (RTPSource * src,
306 GstClockTime deadline);
307 guint16 * rtp_source_get_nacks (RTPSource * src, guint *n_nacks);
308 GstClockTime * rtp_source_get_nack_deadlines (RTPSource * src, guint *n_nacks);
309 void rtp_source_clear_nacks (RTPSource * src, guint n_nacks);
311 #endif /* __RTP_SOURCE_H__ */