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_SESSION_H__
21 #define __RTP_SESSION_H__
25 #include "rtpsource.h"
27 typedef struct _RTPSession RTPSession;
28 typedef struct _RTPSessionClass RTPSessionClass;
30 #define RTP_TYPE_SESSION (rtp_session_get_type())
31 #define RTP_SESSION(sess) (G_TYPE_CHECK_INSTANCE_CAST((sess),RTP_TYPE_SESSION,RTPSession))
32 #define RTP_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SESSION,RTPSessionClass))
33 #define RTP_IS_SESSION(sess) (G_TYPE_CHECK_INSTANCE_TYPE((sess),RTP_TYPE_SESSION))
34 #define RTP_IS_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SESSION))
35 #define RTP_SESSION_CAST(sess) ((RTPSession *)(sess))
37 #define RTP_SESSION_LOCK(sess) (g_mutex_lock ((sess)->lock))
38 #define RTP_SESSION_UNLOCK(sess) (g_mutex_unlock ((sess)->lock))
41 * RTPSessionProcessRTP:
42 * @sess: an #RTPSession
43 * @src: the #RTPSource
44 * @buffer: the RTP buffer ready for processing
45 * @user_data: user data specified when registering
47 * This callback will be called when @sess has @buffer ready for further
48 * processing. Processing the buffer typically includes decoding and displaying
51 * Returns: a #GstFlowReturn.
53 typedef GstFlowReturn (*RTPSessionProcessRTP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
57 * @sess: an #RTPSession
58 * @src: the #RTPSource
59 * @buffer: the RTP buffer ready for sending
60 * @user_data: user data specified when registering
62 * This callback will be called when @sess has @buffer ready for sending to
63 * all listening participants in this session.
65 * Returns: a #GstFlowReturn.
67 typedef GstFlowReturn (*RTPSessionSendRTP) (RTPSession *sess, RTPSource *src, gpointer data, gpointer user_data);
71 * @sess: an #RTPSession
72 * @src: the #RTPSource
73 * @buffer: the RTCP buffer ready for sending
74 * @eos: if an EOS event should be pushed
75 * @user_data: user data specified when registering
77 * This callback will be called when @sess has @buffer ready for sending to
78 * all listening participants in this session.
80 * Returns: a #GstFlowReturn.
82 typedef GstFlowReturn (*RTPSessionSendRTCP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer,
83 gboolean eos, gpointer user_data);
87 * @sess: an #RTPSession
88 * @src: the #RTPSource
89 * @buffer: the RTCP buffer ready for synchronisation
90 * @user_data: user data specified when registering
92 * This callback will be called when @sess has an SR @buffer ready for doing
93 * synchronisation between streams.
95 * Returns: a #GstFlowReturn.
97 typedef GstFlowReturn (*RTPSessionSyncRTCP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
100 * RTPSessionClockRate:
101 * @sess: an #RTPSession
102 * @payload: the payload
103 * @user_data: user data specified when registering
105 * This callback will be called when @sess needs the clock-rate of @payload.
107 * Returns: the clock-rate of @pt.
109 typedef gint (*RTPSessionClockRate) (RTPSession *sess, guint8 payload, gpointer user_data);
112 * RTPSessionReconsider:
113 * @sess: an #RTPSession
114 * @user_data: user data specified when registering
116 * This callback will be called when @sess needs to cancel the current timeout.
117 * The currently running timeout should be canceled and a new reporting interval
118 * should be requested from @sess.
120 typedef void (*RTPSessionReconsider) (RTPSession *sess, gpointer user_data);
123 * RTPSessionRequestKeyUnit:
124 * @sess: an #RTPSession
125 * @all_headers: %TRUE if "all-headers" property should be set on the key unit
127 * @user_data: user data specified when registering
129 * Asks the encoder to produce a key unit as soon as possibly within the
130 * bandwidth constraints
132 typedef void (*RTPSessionRequestKeyUnit) (RTPSession *sess,
133 gboolean all_headers, gpointer user_data);
136 * RTPSessionRequestTime:
137 * @sess: an #RTPSession
138 * @user_data: user data specified when registering
140 * This callback will be called when @sess needs the current time. The time
141 * should be returned as a #GstClockTime
143 typedef GstClockTime (*RTPSessionRequestTime) (RTPSession *sess,
147 * RTPSessionCallbacks:
148 * @RTPSessionProcessRTP: callback to process RTP packets
149 * @RTPSessionSendRTP: callback for sending RTP packets
150 * @RTPSessionSendRTCP: callback for sending RTCP packets
151 * @RTPSessionSyncRTCP: callback for handling SR packets
152 * @RTPSessionReconsider: callback for reconsidering the timeout
153 * @RTPSessionRequestKeyUnit: callback for requesting a new key unit
155 * These callbacks can be installed on the session manager to get notification
156 * when RTP and RTCP packets are ready for further processing. These callbacks
157 * are not implemented with signals for performance reasons.
160 RTPSessionProcessRTP process_rtp;
161 RTPSessionSendRTP send_rtp;
162 RTPSessionSyncRTCP sync_rtcp;
163 RTPSessionSendRTCP send_rtcp;
164 RTPSessionClockRate clock_rate;
165 RTPSessionReconsider reconsider;
166 RTPSessionRequestKeyUnit request_key_unit;
167 RTPSessionRequestTime request_time;
168 } RTPSessionCallbacks;
172 * @lock: lock to protect the session
173 * @source: the source of this session
174 * @ssrcs: Hashtable of sources indexed by SSRC
175 * @cnames: Hashtable of sources indexed by CNAME
176 * @num_sources: the number of sources
177 * @activecount: the number of active sources
178 * @callbacks: callbacks
179 * @user_data: user data passed in callbacks
180 * @stats: session statistics
182 * The RTP session manager object
193 gboolean recalc_bandwidth;
195 gdouble rtcp_bandwidth;
196 guint rtcp_rr_bandwidth;
197 guint rtcp_rs_bandwidth;
201 /* for sender/receiver counting */
205 GHashTable *ssrcs[32];
209 GstClockTime next_rtcp_check_time;
210 GstClockTime last_rtcp_send_time;
211 GstClockTime start_time;
213 gboolean allow_early;
215 GstClockTime next_early_rtcp_time;
220 RTPSessionCallbacks callbacks;
221 gpointer process_rtp_user_data;
222 gpointer send_rtp_user_data;
223 gpointer send_rtcp_user_data;
224 gpointer sync_rtcp_user_data;
225 gpointer clock_rate_user_data;
226 gpointer reconsider_user_data;
227 gpointer request_key_unit_user_data;
228 gpointer request_time_user_data;
230 RTPSessionStats stats;
232 gboolean change_ssrc;
234 GstClockTime rtcp_feedback_retention_window;
235 guint rtcp_immediate_feedback_threshold;
237 GArray *rtcp_pli_requests;
238 GstClockTime last_keyframe_request;
243 * @on_new_ssrc: emited when a new source is found
244 * @on_bye_ssrc: emited when a source is gone
248 struct _RTPSessionClass {
249 GObjectClass parent_class;
252 RTPSource* (*get_source_by_ssrc) (RTPSession *sess, guint32 ssrc);
255 void (*on_new_ssrc) (RTPSession *sess, RTPSource *source);
256 void (*on_ssrc_collision) (RTPSession *sess, RTPSource *source);
257 void (*on_ssrc_validated) (RTPSession *sess, RTPSource *source);
258 void (*on_ssrc_active) (RTPSession *sess, RTPSource *source);
259 void (*on_ssrc_sdes) (RTPSession *sess, RTPSource *source);
260 void (*on_bye_ssrc) (RTPSession *sess, RTPSource *source);
261 void (*on_bye_timeout) (RTPSession *sess, RTPSource *source);
262 void (*on_timeout) (RTPSession *sess, RTPSource *source);
263 void (*on_sender_timeout) (RTPSession *sess, RTPSource *source);
264 gboolean (*on_sending_rtcp) (RTPSession *sess, GstBuffer *buffer,
266 void (*on_feedback_rtcp) (RTPSession *sess, guint type, guint fbtype,
267 guint sender_ssrc, guint media_ssrc, GstBuffer *fci);
268 void (*send_rtcp) (RTPSession *sess, GstClockTimeDiff max_delay);
271 GType rtp_session_get_type (void);
273 /* create and configure */
274 RTPSession* rtp_session_new (void);
275 void rtp_session_set_callbacks (RTPSession *sess,
276 RTPSessionCallbacks *callbacks,
278 void rtp_session_set_process_rtp_callback (RTPSession * sess,
279 RTPSessionProcessRTP callback,
281 void rtp_session_set_send_rtp_callback (RTPSession * sess,
282 RTPSessionSendRTP callback,
284 void rtp_session_set_send_rtcp_callback (RTPSession * sess,
285 RTPSessionSendRTCP callback,
287 void rtp_session_set_sync_rtcp_callback (RTPSession * sess,
288 RTPSessionSyncRTCP callback,
290 void rtp_session_set_clock_rate_callback (RTPSession * sess,
291 RTPSessionClockRate callback,
293 void rtp_session_set_reconsider_callback (RTPSession * sess,
294 RTPSessionReconsider callback,
296 void rtp_session_set_request_time_callback (RTPSession * sess,
297 RTPSessionRequestTime callback,
300 void rtp_session_set_bandwidth (RTPSession *sess, gdouble bandwidth);
301 gdouble rtp_session_get_bandwidth (RTPSession *sess);
302 void rtp_session_set_rtcp_fraction (RTPSession *sess, gdouble fraction);
303 gdouble rtp_session_get_rtcp_fraction (RTPSession *sess);
305 gboolean rtp_session_set_sdes_string (RTPSession *sess, GstRTCPSDESType type,
307 gchar* rtp_session_get_sdes_string (RTPSession *sess, GstRTCPSDESType type);
309 GstStructure * rtp_session_get_sdes_struct (RTPSession *sess);
310 void rtp_session_set_sdes_struct (RTPSession *sess, const GstStructure *sdes);
312 /* handling sources */
313 RTPSource* rtp_session_get_internal_source (RTPSession *sess);
315 void rtp_session_set_internal_ssrc (RTPSession *sess, guint32 ssrc);
316 guint32 rtp_session_get_internal_ssrc (RTPSession *sess);
318 gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src);
319 guint rtp_session_get_num_sources (RTPSession *sess);
320 guint rtp_session_get_num_active_sources (RTPSession *sess);
321 RTPSource* rtp_session_get_source_by_ssrc (RTPSession *sess, guint32 ssrc);
322 RTPSource* rtp_session_get_source_by_cname (RTPSession *sess, const gchar *cname);
323 RTPSource* rtp_session_create_source (RTPSession *sess);
325 /* processing packets from receivers */
326 GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer,
327 GstClockTime current_time,
328 GstClockTime running_time);
329 GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer,
330 GstClockTime current_time,
333 /* processing packets for sending */
334 GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list,
335 GstClockTime current_time, GstClockTime running_time);
337 /* stopping the session */
338 GstFlowReturn rtp_session_schedule_bye (RTPSession *sess, const gchar *reason,
339 GstClockTime current_time);
341 /* get interval for next RTCP interval */
342 GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime current_time);
343 GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime current_time,
344 guint64 ntpnstime, GstClockTime running_time);
346 /* request the transmittion of an early RTCP packet */
347 void rtp_session_request_early_rtcp (RTPSession * sess, GstClockTime current_time,
348 GstClockTimeDiff max_delay);
350 /* Notify session of a request for a new key unit */
351 void rtp_session_request_key_unit (RTPSession * sess,
354 #endif /* __RTP_SESSION_H__ */