2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
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.
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.
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.
20 #ifndef __RTP_SOURCE_H__
21 #define __RTP_SOURCE_H__
24 #include <gst/rtp/rtp.h>
25 #include <gst/net/gstnetaddressmeta.h>
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
35 #define RTP_SEQ_MOD (1 << 16)
37 typedef struct _RTPSource RTPSource;
38 typedef struct _RTPSourceClass RTPSourceClass;
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))
48 * RTP_SOURCE_IS_ACTIVE:
51 * Check if @src is active. A source is active when it has been validated
52 * and has not yet received a BYE packet.
54 #define RTP_SOURCE_IS_ACTIVE(src) (src->validated && !src->marked_bye)
57 * RTP_SOURCE_IS_SENDER:
60 * Check if @src is a sender.
62 #define RTP_SOURCE_IS_SENDER(src) (src->is_sender)
64 * RTP_SOURCE_IS_MARKED_BYE:
67 * Check if @src is a marked as BYE.
69 #define RTP_SOURCE_IS_MARKED_BYE(src) (src->marked_bye)
75 * @data: the RTP buffer or buffer list ready for processing
76 * @user_data: user data specified when registering
78 * This callback will be called when @src has @buffer ready for further
81 * Returns: a #GstFlowReturn.
83 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, gpointer data,
89 * @payload: a payload type
90 * @user_data: user data specified when registering
92 * This callback will be called when @src needs the clock-rate of the
95 * Returns: a clock-rate for @payload.
97 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
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
105 * Callbacks performed by #RTPSource when actions need to be performed.
108 RTPSourcePushRTP push_rtp;
109 RTPSourceClockRate clock_rate;
110 } RTPSourceCallbacks;
113 * RTPConflictingAddress:
114 * @address: #GSocketAddress which conflicted
115 * @last_conflict_time: time when the last conflict was seen
117 * This structure is used to account for addresses that have conflicted to find
121 GSocketAddress *address;
123 } RTPConflictingAddress;
128 * A source in the #RTPSession
130 * @conflicting_addresses: GList of conflicting addresses
139 GHashTable *reported_in_sr_of; /* set of SSRCs */
142 guint curr_probation;
155 GSocketAddress *rtp_from;
156 GSocketAddress *rtcp_from;
161 gint32 seqnum_offset;
163 GstClockTime bye_time;
164 GstClockTime last_activity;
165 GstClockTime last_rtp_activity;
167 GstClockTime last_rtime;
168 GstClockTime last_rtptime;
170 /* for bitrate estimation */
172 GstClockTime prev_rtime;
174 guint64 bytes_received;
177 guint32 max_dropout_time;
178 guint32 max_misorder_time;
180 RTPSourceCallbacks callbacks;
183 RTPSourceStats stats;
184 RTPReceiverReport last_rr;
186 GList *conflicting_addresses;
188 GQueue *retained_feedback;
192 guint8 current_send_fir_seqnum;
200 struct _RTPSourceClass {
201 GObjectClass parent_class;
204 GType rtp_source_get_type (void);
206 /* managing lifetime of sources */
207 RTPSource* rtp_source_new (guint32 ssrc);
208 void rtp_source_set_callbacks (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
211 guint32 rtp_source_get_ssrc (RTPSource *src);
213 void rtp_source_set_as_csrc (RTPSource *src);
214 gboolean rtp_source_is_as_csrc (RTPSource *src);
216 gboolean rtp_source_is_active (RTPSource *src);
217 gboolean rtp_source_is_validated (RTPSource *src);
218 gboolean rtp_source_is_sender (RTPSource *src);
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);
224 void rtp_source_update_caps (RTPSource *src, GstCaps *caps);
228 rtp_source_get_sdes_struct (RTPSource * src);
229 gboolean rtp_source_set_sdes_struct (RTPSource * src, GstStructure *sdes);
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);
236 GstFlowReturn rtp_source_process_rtp (RTPSource *src, RTPPacketInfo *pinfo);
238 GstFlowReturn rtp_source_send_rtp (RTPSource *src, RTPPacketInfo *pinfo);
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);
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);
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);
261 void rtp_source_reset (RTPSource * src);
263 gboolean rtp_source_find_conflicting_address (RTPSource * src,
264 GSocketAddress *address,
267 void rtp_source_add_conflicting_address (RTPSource * src,
268 GSocketAddress *address,
271 gboolean find_conflicting_address (GList * conflicting_address,
272 GSocketAddress * address,
275 GList * add_conflicting_address (GList * conflicting_addresses,
276 GSocketAddress * address,
278 GList * timeout_conflicting_addresses (GList * conflicting_addresses,
279 GstClockTime current_time);
281 void rtp_conflicting_address_free (RTPConflictingAddress * addr);
283 void rtp_source_timeout (RTPSource * src,
284 GstClockTime current_time,
285 GstClockTime feedback_retention_window);
287 void rtp_source_retain_rtcp_packet (RTPSource * src,
289 GstClockTime running_time);
290 gboolean rtp_source_has_retained (RTPSource * src,
294 void rtp_source_register_nack (RTPSource * src,
296 guint32 * rtp_source_get_nacks (RTPSource * src, guint *n_nacks);
297 void rtp_source_clear_nacks (RTPSource * src);
299 #endif /* __RTP_SOURCE_H__ */