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 * @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 * @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 * @all_headers: %TRUE if "all-headers" property should be set on the key unit
126 * @user_data: user data specified when registering
128 * Asks the encoder to produce a key unit as soon as possibly within the
129 * bandwidth constraints
131 typedef void (*RTPSessionRequestKeyUnit) (RTPSession *sess,
132 gboolean all_headers, gpointer user_data);
135 * RTPSessionRequestTime:
136 * @sess: an #RTPSession
137 * @user_data: user data specified when registering
139 * This callback will be called when @sess needs the current time. The time
140 * should be returned as a #GstClockTime
142 typedef GstClockTime (*RTPSessionRequestTime) (RTPSession *sess,
146 * RTPSessionNotifyNACK:
147 * @sess: an #RTPSession
148 * @seqnum: the missing seqnum
149 * @blp: other missing seqnums
150 * @ssrc: SSRC of requested stream
151 * @user_data: user data specified when registering
153 * Notifies of NACKed frames.
155 typedef void (*RTPSessionNotifyNACK) (RTPSession *sess,
156 guint16 seqnum, guint16 blp, guint32 ssrc, gpointer user_data);
159 * RTPSessionReconfigure:
160 * @sess: an #RTPSession
161 * @user_data: user data specified when registering
163 * This callback will be called when @sess wants to reconfigure the
164 * negotiated parameters.
166 typedef void (*RTPSessionReconfigure) (RTPSession *sess, gpointer user_data);
169 * RTPSessionCallbacks:
170 * @RTPSessionProcessRTP: callback to process RTP packets
171 * @RTPSessionSendRTP: callback for sending RTP packets
172 * @RTPSessionSendRTCP: callback for sending RTCP packets
173 * @RTPSessionSyncRTCP: callback for handling SR packets
174 * @RTPSessionReconsider: callback for reconsidering the timeout
175 * @RTPSessionRequestKeyUnit: callback for requesting a new key unit
176 * @RTPSessionRequestTime: callback for requesting the current time
177 * @RTPSessionNotifyNACK: callback for notifying NACK
178 * @RTPSessionReconfigure: callback for requesting reconfiguration
180 * These callbacks can be installed on the session manager to get notification
181 * when RTP and RTCP packets are ready for further processing. These callbacks
182 * are not implemented with signals for performance reasons.
185 RTPSessionProcessRTP process_rtp;
186 RTPSessionSendRTP send_rtp;
187 RTPSessionSyncRTCP sync_rtcp;
188 RTPSessionSendRTCP send_rtcp;
189 RTPSessionClockRate clock_rate;
190 RTPSessionReconsider reconsider;
191 RTPSessionRequestKeyUnit request_key_unit;
192 RTPSessionRequestTime request_time;
193 RTPSessionNotifyNACK notify_nack;
194 RTPSessionReconfigure reconfigure;
195 } RTPSessionCallbacks;
199 * @lock: lock to protect the session
200 * @source: the source of this session
201 * @ssrcs: Hashtable of sources indexed by SSRC
202 * @num_sources: the number of sources
203 * @activecount: the number of active sources
204 * @callbacks: callbacks
205 * @user_data: user data passed in callbacks
206 * @stats: session statistics
207 * @conflicting_addresses: GList of conflicting addresses
209 * The RTP session manager object
224 gboolean recalc_bandwidth;
226 gdouble rtcp_bandwidth;
227 guint rtcp_rr_bandwidth;
228 guint rtcp_rs_bandwidth;
230 guint32 suggested_ssrc;
232 /* for sender/receiver counting */
236 GHashTable *ssrcs[32];
240 GstClockTime next_rtcp_check_time;
241 GstClockTime last_rtcp_send_time;
242 GstClockTime start_time;
244 gboolean allow_early;
246 GstClockTime next_early_rtcp_time;
248 gboolean scheduled_bye;
250 RTPSessionCallbacks callbacks;
251 gpointer process_rtp_user_data;
252 gpointer send_rtp_user_data;
253 gpointer send_rtcp_user_data;
254 gpointer sync_rtcp_user_data;
255 gpointer clock_rate_user_data;
256 gpointer reconsider_user_data;
257 gpointer request_key_unit_user_data;
258 gpointer request_time_user_data;
259 gpointer notify_nack_user_data;
260 gpointer reconfigure_user_data;
262 RTPSessionStats stats;
263 RTPSessionStats bye_stats;
266 GstClockTime rtcp_feedback_retention_window;
267 guint rtcp_immediate_feedback_threshold;
269 GstClockTime last_keyframe_request;
270 gboolean last_keyframe_all_headers;
272 gboolean is_doing_ptp;
274 GList *conflicting_addresses;
279 * @on_new_ssrc: emited when a new source is found
280 * @on_bye_ssrc: emited when a source is gone
284 struct _RTPSessionClass {
285 GObjectClass parent_class;
288 RTPSource* (*get_source_by_ssrc) (RTPSession *sess, guint32 ssrc);
291 void (*on_new_ssrc) (RTPSession *sess, RTPSource *source);
292 void (*on_ssrc_collision) (RTPSession *sess, RTPSource *source);
293 void (*on_ssrc_validated) (RTPSession *sess, RTPSource *source);
294 void (*on_ssrc_active) (RTPSession *sess, RTPSource *source);
295 void (*on_ssrc_sdes) (RTPSession *sess, RTPSource *source);
296 void (*on_bye_ssrc) (RTPSession *sess, RTPSource *source);
297 void (*on_bye_timeout) (RTPSession *sess, RTPSource *source);
298 void (*on_timeout) (RTPSession *sess, RTPSource *source);
299 void (*on_sender_timeout) (RTPSession *sess, RTPSource *source);
300 gboolean (*on_sending_rtcp) (RTPSession *sess, GstBuffer *buffer,
302 void (*on_feedback_rtcp) (RTPSession *sess, guint type, guint fbtype,
303 guint sender_ssrc, guint media_ssrc, GstBuffer *fci);
304 gboolean (*send_rtcp) (RTPSession *sess, GstClockTime max_delay);
307 GType rtp_session_get_type (void);
309 /* create and configure */
310 RTPSession* rtp_session_new (void);
311 void rtp_session_set_callbacks (RTPSession *sess,
312 RTPSessionCallbacks *callbacks,
314 void rtp_session_set_process_rtp_callback (RTPSession * sess,
315 RTPSessionProcessRTP callback,
317 void rtp_session_set_send_rtp_callback (RTPSession * sess,
318 RTPSessionSendRTP callback,
320 void rtp_session_set_send_rtcp_callback (RTPSession * sess,
321 RTPSessionSendRTCP callback,
323 void rtp_session_set_sync_rtcp_callback (RTPSession * sess,
324 RTPSessionSyncRTCP callback,
326 void rtp_session_set_clock_rate_callback (RTPSession * sess,
327 RTPSessionClockRate callback,
329 void rtp_session_set_reconsider_callback (RTPSession * sess,
330 RTPSessionReconsider callback,
332 void rtp_session_set_request_time_callback (RTPSession * sess,
333 RTPSessionRequestTime callback,
336 void rtp_session_set_bandwidth (RTPSession *sess, gdouble bandwidth);
337 gdouble rtp_session_get_bandwidth (RTPSession *sess);
338 void rtp_session_set_rtcp_fraction (RTPSession *sess, gdouble fraction);
339 gdouble rtp_session_get_rtcp_fraction (RTPSession *sess);
341 GstStructure * rtp_session_get_sdes_struct (RTPSession *sess);
342 void rtp_session_set_sdes_struct (RTPSession *sess, const GstStructure *sdes);
344 /* handling sources */
345 guint32 rtp_session_suggest_ssrc (RTPSession *sess);
347 gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src);
348 guint rtp_session_get_num_sources (RTPSession *sess);
349 guint rtp_session_get_num_active_sources (RTPSession *sess);
350 RTPSource* rtp_session_get_source_by_ssrc (RTPSession *sess, guint32 ssrc);
351 RTPSource* rtp_session_create_source (RTPSession *sess);
353 /* processing packets from receivers */
354 GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer,
355 GstClockTime current_time,
356 GstClockTime running_time,
358 GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer,
359 GstClockTime current_time,
362 /* processing packets for sending */
363 void rtp_session_update_send_caps (RTPSession *sess, GstCaps *caps);
364 GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list,
365 GstClockTime current_time, GstClockTime running_time);
368 void rtp_session_mark_all_bye (RTPSession *sess, const gchar *reason);
369 GstFlowReturn rtp_session_schedule_bye (RTPSession *sess, GstClockTime current_time);
371 /* get interval for next RTCP interval */
372 GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime current_time);
373 GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime current_time,
374 guint64 ntpnstime, GstClockTime running_time);
376 /* request the transmittion of an early RTCP packet */
377 gboolean rtp_session_request_early_rtcp (RTPSession * sess, GstClockTime current_time,
378 GstClockTime max_delay);
380 /* Notify session of a request for a new key unit */
381 gboolean rtp_session_request_key_unit (RTPSession * sess,
385 gboolean rtp_session_request_nack (RTPSession * sess,
388 GstClockTime max_delay);
391 #endif /* __RTP_SESSION_H__ */