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_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 * @data: the RTP buffer or buffer list ready for sending
60 * @user_data: user data specified when registering
62 * This callback will be called when @sess has @data (a buffer or buffer list)
63 * ready for sending to 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 * @buffer: the RTCP buffer ready for synchronisation
89 * @user_data: user data specified when registering
91 * This callback will be called when @sess has an SR @buffer ready for doing
92 * synchronisation between streams.
94 * Returns: a #GstFlowReturn.
96 typedef GstFlowReturn (*RTPSessionSyncRTCP) (RTPSession *sess, GstBuffer *buffer, gpointer user_data);
99 * RTPSessionClockRate:
100 * @sess: an #RTPSession
101 * @payload: the payload
102 * @user_data: user data specified when registering
104 * This callback will be called when @sess needs the clock-rate of @payload.
106 * Returns: the clock-rate of @pt.
108 typedef gint (*RTPSessionClockRate) (RTPSession *sess, guint8 payload, gpointer user_data);
111 * RTPSessionReconsider:
112 * @sess: an #RTPSession
113 * @user_data: user data specified when registering
115 * This callback will be called when @sess needs to cancel the current timeout.
116 * The currently running timeout should be canceled and a new reporting interval
117 * should be requested from @sess.
119 typedef void (*RTPSessionReconsider) (RTPSession *sess, gpointer user_data);
122 * RTPSessionRequestKeyUnit:
123 * @sess: an #RTPSession
124 * @ssrc: SSRC of the source related to the key unit request
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, guint32 ssrc,
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 * RTPSessionNotifyNACK:
148 * @sess: an #RTPSession
149 * @seqnum: the missing seqnum
150 * @blp: other missing seqnums
151 * @ssrc: SSRC of requested stream
152 * @user_data: user data specified when registering
154 * Notifies of NACKed frames.
156 typedef void (*RTPSessionNotifyNACK) (RTPSession *sess,
157 guint16 seqnum, guint16 blp, guint32 ssrc, gpointer user_data);
160 * RTPSessionReconfigure:
161 * @sess: an #RTPSession
162 * @user_data: user data specified when registering
164 * This callback will be called when @sess wants to reconfigure the
165 * negotiated parameters.
167 typedef void (*RTPSessionReconfigure) (RTPSession *sess, gpointer user_data);
170 * RTPSessionNotifyEarlyRTCP:
171 * @sess: an #RTPSession
172 * @user_data: user data specified when registering
174 * Notifies of early RTCP being requested
176 typedef void (*RTPSessionNotifyEarlyRTCP) (RTPSession *sess,
180 * RTPSessionCallbacks:
181 * @RTPSessionProcessRTP: callback to process RTP packets
182 * @RTPSessionSendRTP: callback for sending RTP packets
183 * @RTPSessionSendRTCP: callback for sending RTCP packets
184 * @RTPSessionSyncRTCP: callback for handling SR packets
185 * @RTPSessionReconsider: callback for reconsidering the timeout
186 * @RTPSessionRequestKeyUnit: callback for requesting a new key unit
187 * @RTPSessionRequestTime: callback for requesting the current time
188 * @RTPSessionNotifyNACK: callback for notifying NACK
189 * @RTPSessionReconfigure: callback for requesting reconfiguration
190 * @RTPSessionNotifyEarlyRTCP: callback for notifying early RTCP
192 * These callbacks can be installed on the session manager to get notification
193 * when RTP and RTCP packets are ready for further processing. These callbacks
194 * are not implemented with signals for performance reasons.
197 RTPSessionProcessRTP process_rtp;
198 RTPSessionSendRTP send_rtp;
199 RTPSessionSyncRTCP sync_rtcp;
200 RTPSessionSendRTCP send_rtcp;
201 RTPSessionClockRate clock_rate;
202 RTPSessionReconsider reconsider;
203 RTPSessionRequestKeyUnit request_key_unit;
204 RTPSessionRequestTime request_time;
205 RTPSessionNotifyNACK notify_nack;
206 RTPSessionReconfigure reconfigure;
207 RTPSessionNotifyEarlyRTCP notify_early_rtcp;
208 } RTPSessionCallbacks;
212 * @lock: lock to protect the session
213 * @source: the source of this session
214 * @ssrcs: Hashtable of sources indexed by SSRC
215 * @num_sources: the number of sources
216 * @activecount: the number of active sources
217 * @callbacks: callbacks
218 * @user_data: user data passed in callbacks
219 * @stats: session statistics
220 * @conflicting_addresses: GList of conflicting addresses
222 * The RTP session manager object
235 guint32 max_dropout_time;
236 guint32 max_misorder_time;
238 GstRTPProfile rtp_profile;
240 gboolean reduced_size_rtcp;
243 gboolean recalc_bandwidth;
245 gdouble rtcp_bandwidth;
246 guint rtcp_rr_bandwidth;
247 guint rtcp_rs_bandwidth;
249 guint32 suggested_ssrc;
250 gboolean internal_ssrc_set;
251 gboolean internal_ssrc_from_caps_or_property;
253 /* for sender/receiver counting */
257 GHashTable *ssrcs[32];
261 GstClockTime next_rtcp_check_time; /* tn */
262 GstClockTime last_rtcp_check_time; /* tp */
263 GstClockTime last_rtcp_send_time; /* t_rr_last */
264 GstClockTime last_rtcp_interval; /* T_rr */
265 GstClockTime start_time;
267 gboolean allow_early;
269 GstClockTime next_early_rtcp_time;
271 gboolean scheduled_bye;
273 RTPSessionCallbacks callbacks;
274 gpointer process_rtp_user_data;
275 gpointer send_rtp_user_data;
276 gpointer send_rtcp_user_data;
277 gpointer sync_rtcp_user_data;
278 gpointer clock_rate_user_data;
279 gpointer reconsider_user_data;
280 gpointer request_key_unit_user_data;
281 gpointer request_time_user_data;
282 gpointer notify_nack_user_data;
283 gpointer reconfigure_user_data;
284 gpointer notify_early_rtcp_user_data;
286 RTPSessionStats stats;
287 RTPSessionStats bye_stats;
290 GstClockTime rtcp_feedback_retention_window;
291 guint rtcp_immediate_feedback_threshold;
293 gboolean is_doing_ptp;
295 GList *conflicting_addresses;
300 * @on_new_ssrc: emitted when a new source is found
301 * @on_bye_ssrc: emitted when a source is gone
305 struct _RTPSessionClass {
306 GObjectClass parent_class;
309 RTPSource* (*get_source_by_ssrc) (RTPSession *sess, guint32 ssrc);
312 void (*on_new_ssrc) (RTPSession *sess, RTPSource *source);
313 void (*on_ssrc_collision) (RTPSession *sess, RTPSource *source);
314 void (*on_ssrc_validated) (RTPSession *sess, RTPSource *source);
315 void (*on_ssrc_active) (RTPSession *sess, RTPSource *source);
316 void (*on_ssrc_sdes) (RTPSession *sess, RTPSource *source);
317 void (*on_bye_ssrc) (RTPSession *sess, RTPSource *source);
318 void (*on_bye_timeout) (RTPSession *sess, RTPSource *source);
319 void (*on_timeout) (RTPSession *sess, RTPSource *source);
320 void (*on_sender_timeout) (RTPSession *sess, RTPSource *source);
321 gboolean (*on_sending_rtcp) (RTPSession *sess, GstBuffer *buffer,
323 void (*on_app_rtcp) (RTPSession *sess, guint subtype, guint ssrc,
324 const gchar *name, GstBuffer *data);
325 void (*on_feedback_rtcp) (RTPSession *sess, guint type, guint fbtype,
326 guint sender_ssrc, guint media_ssrc, GstBuffer *fci);
327 gboolean (*send_rtcp) (RTPSession *sess, GstClockTime max_delay);
328 void (*on_receiving_rtcp) (RTPSession *sess, GstBuffer *buffer);
329 void (*on_new_sender_ssrc) (RTPSession *sess, RTPSource *source);
330 void (*on_sender_ssrc_active) (RTPSession *sess, RTPSource *source);
333 GType rtp_session_get_type (void);
335 /* create and configure */
336 RTPSession* rtp_session_new (void);
337 void rtp_session_reset (RTPSession *sess);
338 void rtp_session_set_callbacks (RTPSession *sess,
339 RTPSessionCallbacks *callbacks,
341 void rtp_session_set_process_rtp_callback (RTPSession * sess,
342 RTPSessionProcessRTP callback,
344 void rtp_session_set_send_rtp_callback (RTPSession * sess,
345 RTPSessionSendRTP callback,
347 void rtp_session_set_send_rtcp_callback (RTPSession * sess,
348 RTPSessionSendRTCP callback,
350 void rtp_session_set_sync_rtcp_callback (RTPSession * sess,
351 RTPSessionSyncRTCP callback,
353 void rtp_session_set_clock_rate_callback (RTPSession * sess,
354 RTPSessionClockRate callback,
356 void rtp_session_set_reconsider_callback (RTPSession * sess,
357 RTPSessionReconsider callback,
359 void rtp_session_set_request_time_callback (RTPSession * sess,
360 RTPSessionRequestTime callback,
363 void rtp_session_set_bandwidth (RTPSession *sess, gdouble bandwidth);
364 gdouble rtp_session_get_bandwidth (RTPSession *sess);
365 void rtp_session_set_rtcp_fraction (RTPSession *sess, gdouble fraction);
366 gdouble rtp_session_get_rtcp_fraction (RTPSession *sess);
368 GstStructure * rtp_session_get_sdes_struct (RTPSession *sess);
369 void rtp_session_set_sdes_struct (RTPSession *sess, const GstStructure *sdes);
371 /* handling sources */
372 guint32 rtp_session_suggest_ssrc (RTPSession *sess, gboolean *is_random);
374 gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src);
375 guint rtp_session_get_num_sources (RTPSession *sess);
376 guint rtp_session_get_num_active_sources (RTPSession *sess);
377 RTPSource* rtp_session_get_source_by_ssrc (RTPSession *sess, guint32 ssrc);
378 RTPSource* rtp_session_create_source (RTPSession *sess);
380 /* processing packets from receivers */
381 GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer,
382 GstClockTime current_time,
383 GstClockTime running_time,
385 GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer,
386 GstClockTime current_time,
387 GstClockTime running_time,
390 /* processing packets for sending */
391 void rtp_session_update_send_caps (RTPSession *sess, GstCaps *caps);
392 GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list,
393 GstClockTime current_time, GstClockTime running_time);
396 void rtp_session_mark_all_bye (RTPSession *sess, const gchar *reason);
397 GstFlowReturn rtp_session_schedule_bye (RTPSession *sess, GstClockTime current_time);
399 /* get interval for next RTCP interval */
400 GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime current_time);
401 GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime current_time,
402 guint64 ntpnstime, GstClockTime running_time);
404 /* request the transmittion of an early RTCP packet */
405 gboolean rtp_session_request_early_rtcp (RTPSession * sess, GstClockTime current_time,
406 GstClockTime max_delay);
408 /* Notify session of a request for a new key unit */
409 gboolean rtp_session_request_key_unit (RTPSession * sess,
413 gboolean rtp_session_request_nack (RTPSession * sess,
416 GstClockTime max_delay);
419 #endif /* __RTP_SESSION_H__ */