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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef __RTP_SOURCE_H__
21 #define __RTP_SOURCE_H__
24 #include <gst/rtp/gstrtcpbuffer.h>
25 #include <gst/netbuffer/gstnetbuffer.h>
29 /* the default number of consecutive RTP packets we need to receive before the
30 * source is considered valid */
31 #define RTP_NO_PROBATION 0
32 #define RTP_DEFAULT_PROBATION 2
34 #define RTP_SEQ_MOD (1 << 16)
36 typedef struct _RTPSource RTPSource;
37 typedef struct _RTPSourceClass RTPSourceClass;
39 #define RTP_TYPE_SOURCE (rtp_source_get_type())
40 #define RTP_SOURCE(src) (G_TYPE_CHECK_INSTANCE_CAST((src),RTP_TYPE_SOURCE,RTPSource))
41 #define RTP_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SOURCE,RTPSourceClass))
42 #define RTP_IS_SOURCE(src) (G_TYPE_CHECK_INSTANCE_TYPE((src),RTP_TYPE_SOURCE))
43 #define RTP_IS_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SOURCE))
44 #define RTP_SOURCE_CAST(src) ((RTPSource *)(src))
47 * RTP_SOURCE_IS_ACTIVE:
50 * Check if @src is active. A source is active when it has been validated
51 * and has not yet received a BYE packet.
53 #define RTP_SOURCE_IS_ACTIVE(src) (src->validated && !src->received_bye)
56 * RTP_SOURCE_IS_SENDER:
59 * Check if @src is a sender.
61 #define RTP_SOURCE_IS_SENDER(src) (src->is_sender)
66 * @buffer: the RTP buffer ready for processing
67 * @user_data: user data specified when registering
69 * This callback will be called when @src has @buffer ready for further
72 * Returns: a #GstFlowReturn.
74 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, GstBuffer *buffer,
80 * @payload: a payload type
81 * @user_data: user data specified when registering
83 * This callback will be called when @src needs the clock-rate of the
86 * Returns: a clock-rate for @payload.
88 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
92 * @push_rtp: a packet becomes available for handling
93 * @clock_rate: a clock-rate is requested
94 * @get_time: the current clock time is requested
96 * Callbacks performed by #RTPSource when actions need to be performed.
99 RTPSourcePushRTP push_rtp;
100 RTPSourceClockRate clock_rate;
101 } RTPSourceCallbacks;
104 * RTPConflictingAddress:
105 * @address: #GstNetAddress which conflicted
106 * @last_conflict_time: time when the last conflict was seen
108 * This structure is used to account for addresses that have conflicted to find
112 GstNetAddress address;
114 } RTPConflictingAddress;
119 * A source in the #RTPSession
121 * @conflicting_addresses: GList of conflicting addresses
138 gboolean received_bye;
141 gboolean have_rtp_from;
142 GstNetAddress rtp_from;
143 gboolean have_rtcp_from;
144 GstNetAddress rtcp_from;
151 GstClockTime bye_time;
152 GstClockTime last_activity;
153 GstClockTime last_rtp_activity;
155 GstClockTime last_rtime;
156 GstClockTime last_rtptime;
158 /* for bitrate estimation */
160 GstClockTime prev_rtime;
162 guint64 bytes_received;
166 RTPSourceCallbacks callbacks;
169 RTPSourceStats stats;
170 RTPReceiverReport last_rr;
172 GList *conflicting_addresses;
174 GQueue *retained_feedback;
177 struct _RTPSourceClass {
178 GObjectClass parent_class;
181 GType rtp_source_get_type (void);
183 /* managing lifetime of sources */
184 RTPSource* rtp_source_new (guint32 ssrc);
185 void rtp_source_set_callbacks (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
188 guint32 rtp_source_get_ssrc (RTPSource *src);
190 void rtp_source_set_as_csrc (RTPSource *src);
191 gboolean rtp_source_is_as_csrc (RTPSource *src);
193 gboolean rtp_source_is_active (RTPSource *src);
194 gboolean rtp_source_is_validated (RTPSource *src);
195 gboolean rtp_source_is_sender (RTPSource *src);
197 gboolean rtp_source_received_bye (RTPSource *src);
198 gchar * rtp_source_get_bye_reason (RTPSource *src);
200 void rtp_source_update_caps (RTPSource *src, GstCaps *caps);
203 gboolean rtp_source_set_sdes_string (RTPSource *src, GstRTCPSDESType type,
205 gchar* rtp_source_get_sdes_string (RTPSource *src, GstRTCPSDESType type);
207 rtp_source_get_sdes_struct (RTPSource * src);
208 gboolean rtp_source_set_sdes_struct (RTPSource * src, GstStructure *sdes);
210 /* handling network address */
211 void rtp_source_set_rtp_from (RTPSource *src, GstNetAddress *address);
212 void rtp_source_set_rtcp_from (RTPSource *src, GstNetAddress *address);
215 GstFlowReturn rtp_source_process_rtp (RTPSource *src, GstBuffer *buffer, RTPArrivalStats *arrival);
217 GstFlowReturn rtp_source_send_rtp (RTPSource *src, gpointer data, gboolean is_list,
218 GstClockTime running_time);
220 void rtp_source_process_bye (RTPSource *src, const gchar *reason);
221 void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime,
222 guint32 rtptime, guint32 packet_count, guint32 octet_count);
223 void rtp_source_process_rb (RTPSource *src, guint64 ntpnstime, guint8 fractionlost,
224 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
225 guint32 lsr, guint32 dlsr);
227 gboolean rtp_source_get_new_sr (RTPSource *src, guint64 ntpnstime, GstClockTime running_time,
228 guint64 *ntptime, guint32 *rtptime, guint32 *packet_count,
229 guint32 *octet_count);
230 gboolean rtp_source_get_new_rb (RTPSource *src, GstClockTime time, guint8 *fractionlost,
231 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
232 guint32 *lsr, guint32 *dlsr);
234 gboolean rtp_source_get_last_sr (RTPSource *src, GstClockTime *time, guint64 *ntptime,
235 guint32 *rtptime, guint32 *packet_count,
236 guint32 *octet_count);
237 gboolean rtp_source_get_last_rb (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
238 guint32 *exthighestseq, guint32 *jitter,
239 guint32 *lsr, guint32 *dlsr, guint32 *round_trip);
241 void rtp_source_reset (RTPSource * src);
243 gboolean rtp_source_find_conflicting_address (RTPSource * src,
244 GstNetAddress *address,
247 void rtp_source_add_conflicting_address (RTPSource * src,
248 GstNetAddress *address,
251 void rtp_source_timeout (RTPSource * src,
252 GstClockTime current_time,
253 GstClockTime collision_timeout,
254 GstClockTime feedback_retention_window);
256 void rtp_source_retain_rtcp_packet (RTPSource * src,
258 GstClockTime running_time);
260 gboolean rtp_source_has_retained (RTPSource * src,
265 #endif /* __RTP_SOURCE_H__ */