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;
204 struct _RTPSourceClass {
205 GObjectClass parent_class;
208 GType rtp_source_get_type (void);
210 /* managing lifetime of sources */
211 RTPSource* rtp_source_new (guint32 ssrc);
212 void rtp_source_set_callbacks (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
215 guint32 rtp_source_get_ssrc (RTPSource *src);
217 void rtp_source_set_as_csrc (RTPSource *src);
218 gboolean rtp_source_is_as_csrc (RTPSource *src);
220 gboolean rtp_source_is_active (RTPSource *src);
221 gboolean rtp_source_is_validated (RTPSource *src);
222 gboolean rtp_source_is_sender (RTPSource *src);
224 void rtp_source_mark_bye (RTPSource *src, const gchar *reason);
225 gboolean rtp_source_is_marked_bye (RTPSource *src);
226 gchar * rtp_source_get_bye_reason (RTPSource *src);
228 void rtp_source_update_caps (RTPSource *src, GstCaps *caps);
232 rtp_source_get_sdes_struct (RTPSource * src);
233 gboolean rtp_source_set_sdes_struct (RTPSource * src, GstStructure *sdes);
235 /* handling network address */
236 void rtp_source_set_rtp_from (RTPSource *src, GSocketAddress *address);
237 void rtp_source_set_rtcp_from (RTPSource *src, GSocketAddress *address);
240 GstFlowReturn rtp_source_process_rtp (RTPSource *src, RTPPacketInfo *pinfo);
242 GstFlowReturn rtp_source_send_rtp (RTPSource *src, RTPPacketInfo *pinfo);
245 void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime,
246 guint32 rtptime, guint32 packet_count, guint32 octet_count);
247 void rtp_source_process_rb (RTPSource *src, guint64 ntpnstime, guint8 fractionlost,
248 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
249 guint32 lsr, guint32 dlsr);
251 gboolean rtp_source_get_new_sr (RTPSource *src, guint64 ntpnstime, GstClockTime running_time,
252 guint64 *ntptime, guint32 *rtptime, guint32 *packet_count,
253 guint32 *octet_count);
254 gboolean rtp_source_get_new_rb (RTPSource *src, GstClockTime time, guint8 *fractionlost,
255 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
256 guint32 *lsr, guint32 *dlsr);
258 gboolean rtp_source_get_last_sr (RTPSource *src, GstClockTime *time, guint64 *ntptime,
259 guint32 *rtptime, guint32 *packet_count,
260 guint32 *octet_count);
261 gboolean rtp_source_get_last_rb (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
262 guint32 *exthighestseq, guint32 *jitter,
263 guint32 *lsr, guint32 *dlsr, guint32 *round_trip);
265 void rtp_source_reset (RTPSource * src);
267 gboolean rtp_source_find_conflicting_address (RTPSource * src,
268 GSocketAddress *address,
271 void rtp_source_add_conflicting_address (RTPSource * src,
272 GSocketAddress *address,
275 gboolean find_conflicting_address (GList * conflicting_address,
276 GSocketAddress * address,
279 GList * add_conflicting_address (GList * conflicting_addresses,
280 GSocketAddress * address,
282 GList * timeout_conflicting_addresses (GList * conflicting_addresses,
283 GstClockTime current_time);
285 void rtp_conflicting_address_free (RTPConflictingAddress * addr);
287 void rtp_source_timeout (RTPSource * src,
288 GstClockTime current_time,
289 GstClockTime feedback_retention_window);
291 void rtp_source_retain_rtcp_packet (RTPSource * src,
293 GstClockTime running_time);
294 gboolean rtp_source_has_retained (RTPSource * src,
298 void rtp_source_register_nack (RTPSource * src,
300 guint32 * rtp_source_get_nacks (RTPSource * src, guint *n_nacks);
301 void rtp_source_clear_nacks (RTPSource * src);
303 #endif /* __RTP_SOURCE_H__ */