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__
24 #include <gst/netbuffer/gstnetbuffer.h>
26 #include "rtpsource.h"
28 typedef struct _RTPSession RTPSession;
29 typedef struct _RTPSessionClass RTPSessionClass;
31 #define RTP_TYPE_SESSION (rtp_session_get_type())
32 #define RTP_SESSION(sess) (G_TYPE_CHECK_INSTANCE_CAST((sess),RTP_TYPE_SESSION,RTPSession))
33 #define RTP_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SESSION,RTPSessionClass))
34 #define RTP_IS_SESSION(sess) (G_TYPE_CHECK_INSTANCE_TYPE((sess),RTP_TYPE_SESSION))
35 #define RTP_IS_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SESSION))
36 #define RTP_SESSION_CAST(sess) ((RTPSession *)(sess))
38 #define RTP_SESSION_LOCK(sess) (g_mutex_lock ((sess)->lock))
39 #define RTP_SESSION_UNLOCK(sess) (g_mutex_unlock ((sess)->lock))
42 * RTPSessionProcessRTP:
43 * @sess: an #RTPSession
44 * @src: the #RTPSource
45 * @buffer: the RTP buffer ready for processing
46 * @user_data: user data specified when registering
48 * This callback will be called when @sess has @buffer ready for further
49 * processing. Processing the buffer typically includes decoding and displaying
52 * Returns: a #GstFlowReturn.
54 typedef GstFlowReturn (*RTPSessionProcessRTP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
58 * @sess: an #RTPSession
59 * @src: the #RTPSource
60 * @buffer: the RTP buffer ready for sending
61 * @user_data: user data specified when registering
63 * This callback will be called when @sess has @buffer ready for sending to
64 * all listening participants in this session.
66 * Returns: a #GstFlowReturn.
68 typedef GstFlowReturn (*RTPSessionSendRTP) (RTPSession *sess, RTPSource *src, gpointer data, gpointer user_data);
72 * @sess: an #RTPSession
73 * @src: the #RTPSource
74 * @buffer: the RTCP buffer ready for sending
75 * @eos: if an EOS event should be pushed
76 * @user_data: user data specified when registering
78 * This callback will be called when @sess has @buffer ready for sending to
79 * all listening participants in this session.
81 * Returns: a #GstFlowReturn.
83 typedef GstFlowReturn (*RTPSessionSendRTCP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer,
84 gboolean eos, gpointer user_data);
88 * @sess: an #RTPSession
89 * @src: the #RTPSource
90 * @buffer: the RTCP buffer ready for synchronisation
91 * @user_data: user data specified when registering
93 * This callback will be called when @sess has an SR @buffer ready for doing
94 * synchronisation between streams.
96 * Returns: a #GstFlowReturn.
98 typedef GstFlowReturn (*RTPSessionSyncRTCP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
101 * RTPSessionClockRate:
102 * @sess: an #RTPSession
103 * @payload: the payload
104 * @user_data: user data specified when registering
106 * This callback will be called when @sess needs the clock-rate of @payload.
108 * Returns: the clock-rate of @pt.
110 typedef gint (*RTPSessionClockRate) (RTPSession *sess, guint8 payload, gpointer user_data);
113 * RTPSessionReconsider:
114 * @sess: an #RTPSession
115 * @user_data: user data specified when registering
117 * This callback will be called when @sess needs to cancel the current timeout.
118 * The currently running timeout should be canceled and a new reporting interval
119 * should be requested from @sess.
121 typedef void (*RTPSessionReconsider) (RTPSession *sess, gpointer user_data);
124 * RTPSessionCallbacks:
125 * @RTPSessionProcessRTP: callback to process RTP packets
126 * @RTPSessionSendRTP: callback for sending RTP packets
127 * @RTPSessionSendRTCP: callback for sending RTCP packets
128 * @RTPSessionSyncRTCP: callback for handling SR packets
129 * @RTPSessionReconsider: callback for reconsidering the timeout
131 * These callbacks can be installed on the session manager to get notification
132 * when RTP and RTCP packets are ready for further processing. These callbacks
133 * are not implemented with signals for performance reasons.
136 RTPSessionProcessRTP process_rtp;
137 RTPSessionSendRTP send_rtp;
138 RTPSessionSyncRTCP sync_rtcp;
139 RTPSessionSendRTCP send_rtcp;
140 RTPSessionClockRate clock_rate;
141 RTPSessionReconsider reconsider;
142 } RTPSessionCallbacks;
146 * @lock: lock to protect the session
147 * @source: the source of this session
148 * @ssrcs: Hashtable of sources indexed by SSRC
149 * @cnames: Hashtable of sources indexed by CNAME
150 * @num_sources: the number of sources
151 * @activecount: the number of active sources
152 * @callbacks: callbacks
153 * @user_data: user data passed in callbacks
154 * @stats: session statistics
156 * The RTP session manager object
167 gboolean recalc_bandwidth;
169 guint rtcp_bandwidth;
170 guint rtcp_rr_bandwidth;
171 guint rtcp_rs_bandwidth;
175 /* for sender/receiver counting */
179 GHashTable *ssrcs[32];
183 GstClockTime next_rtcp_check_time;
184 GstClockTime last_rtcp_send_time;
190 RTPSessionCallbacks callbacks;
191 gpointer process_rtp_user_data;
192 gpointer send_rtp_user_data;
193 gpointer send_rtcp_user_data;
194 gpointer sync_rtcp_user_data;
195 gpointer clock_rate_user_data;
196 gpointer reconsider_user_data;
198 RTPSessionStats stats;
200 gboolean change_ssrc;
206 * @on_new_ssrc: emited when a new source is found
207 * @on_bye_ssrc: emited when a source is gone
211 struct _RTPSessionClass {
212 GObjectClass parent_class;
215 RTPSource* (*get_source_by_ssrc) (RTPSession *sess, guint32 ssrc);
218 void (*on_new_ssrc) (RTPSession *sess, RTPSource *source);
219 void (*on_ssrc_collision) (RTPSession *sess, RTPSource *source);
220 void (*on_ssrc_validated) (RTPSession *sess, RTPSource *source);
221 void (*on_ssrc_active) (RTPSession *sess, RTPSource *source);
222 void (*on_ssrc_sdes) (RTPSession *sess, RTPSource *source);
223 void (*on_bye_ssrc) (RTPSession *sess, RTPSource *source);
224 void (*on_bye_timeout) (RTPSession *sess, RTPSource *source);
225 void (*on_timeout) (RTPSession *sess, RTPSource *source);
226 void (*on_sender_timeout) (RTPSession *sess, RTPSource *source);
229 GType rtp_session_get_type (void);
231 /* create and configure */
232 RTPSession* rtp_session_new (void);
233 void rtp_session_set_callbacks (RTPSession *sess,
234 RTPSessionCallbacks *callbacks,
236 void rtp_session_set_process_rtp_callback (RTPSession * sess,
237 RTPSessionProcessRTP callback,
239 void rtp_session_set_send_rtp_callback (RTPSession * sess,
240 RTPSessionSendRTP callback,
242 void rtp_session_set_send_rtcp_callback (RTPSession * sess,
243 RTPSessionSendRTCP callback,
245 void rtp_session_set_sync_rtcp_callback (RTPSession * sess,
246 RTPSessionSyncRTCP callback,
248 void rtp_session_set_clock_rate_callback (RTPSession * sess,
249 RTPSessionClockRate callback,
251 void rtp_session_set_reconsider_callback (RTPSession * sess,
252 RTPSessionReconsider callback,
254 void rtp_session_set_bandwidth (RTPSession *sess, gdouble bandwidth);
255 gdouble rtp_session_get_bandwidth (RTPSession *sess);
256 void rtp_session_set_rtcp_fraction (RTPSession *sess, gdouble fraction);
257 gdouble rtp_session_get_rtcp_fraction (RTPSession *sess);
259 gboolean rtp_session_set_sdes_string (RTPSession *sess, GstRTCPSDESType type,
261 gchar* rtp_session_get_sdes_string (RTPSession *sess, GstRTCPSDESType type);
263 GstStructure * rtp_session_get_sdes_struct (RTPSession *sess);
264 void rtp_session_set_sdes_struct (RTPSession *sess, const GstStructure *sdes);
266 /* handling sources */
267 RTPSource* rtp_session_get_internal_source (RTPSession *sess);
269 void rtp_session_set_internal_ssrc (RTPSession *sess, guint32 ssrc);
270 guint32 rtp_session_get_internal_ssrc (RTPSession *sess);
272 gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src);
273 guint rtp_session_get_num_sources (RTPSession *sess);
274 guint rtp_session_get_num_active_sources (RTPSession *sess);
275 RTPSource* rtp_session_get_source_by_ssrc (RTPSession *sess, guint32 ssrc);
276 RTPSource* rtp_session_get_source_by_cname (RTPSession *sess, const gchar *cname);
277 RTPSource* rtp_session_create_source (RTPSession *sess);
279 /* processing packets from receivers */
280 GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer,
281 GstClockTime current_time,
282 GstClockTime running_time);
283 GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer,
284 GstClockTime current_time);
286 /* processing packets for sending */
287 GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list,
288 GstClockTime current_time, GstClockTime running_time);
290 /* stopping the session */
291 GstFlowReturn rtp_session_schedule_bye (RTPSession *sess, const gchar *reason,
292 GstClockTime current_time);
294 /* get interval for next RTCP interval */
295 GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime current_time);
296 GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime current_time,
297 guint64 ntpnstime, GstClockTime running_time);
299 #endif /* __RTP_SESSION_H__ */