2 * Copyright (C) <2007> Wim Taymans <wim@fluendo.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, GstBuffer *buffer, gpointer user_data);
72 * @sess: an #RTPSession
73 * @src: the #RTPSource
74 * @buffer: the RTCP buffer ready for sending
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, gpointer user_data);
85 * RTPSessionClockRate:
86 * @sess: an #RTPSession
87 * @payload: the payload
88 * @user_data: user data specified when registering
90 * This callback will be called when @sess needs the clock-rate of @payload.
92 * Returns: the clock-rate of @pt.
94 typedef gint (*RTPSessionClockRate) (RTPSession *sess, guint8 payload, gpointer user_data);
98 * @sess: an #RTPSession
99 * @user_data: user data specified when registering
101 * This callback will be called when @sess needs the current time in
104 * Returns: a #GstClockTime with the current time in nanoseconds.
106 typedef GstClockTime (*RTPSessionGetTime) (RTPSession *sess, gpointer user_data);
109 * RTPSessionReconsider:
110 * @sess: an #RTPSession
111 * @user_data: user data specified when registering
113 * This callback will be called when @sess needs to cancel the current timeout.
114 * The currently running timeout should be canceled and a new reporting interval
115 * should be requested from @sess.
117 typedef void (*RTPSessionReconsider) (RTPSession *sess, gpointer user_data);
120 * RTPSessionCallbacks:
121 * @RTPSessionProcessRTP: callback to process RTP packets
122 * @RTPSessionSendRTP: callback for sending RTP packets
123 * @RTPSessionSendRTCP: callback for sending RTCP packets
124 * @RTPSessionGetTime: callback for returning the current time
125 * @RTPSessionReconsider: callback for reconsidering the timeout
127 * These callbacks can be installed on the session manager to get notification
128 * when RTP and RTCP packets are ready for further processing. These callbacks
129 * are not implemented with signals for performance reasons.
132 RTPSessionProcessRTP process_rtp;
133 RTPSessionSendRTP send_rtp;
134 RTPSessionSendRTCP send_rtcp;
135 RTPSessionClockRate clock_rate;
136 RTPSessionGetTime get_time;
137 RTPSessionReconsider reconsider;
138 } RTPSessionCallbacks;
142 * @lock: lock to protect the session
143 * @source: the source of this session
144 * @ssrcs: Hashtable of sources indexed by SSRC
145 * @cnames: Hashtable of sources indexed by CNAME
146 * @num_sources: the number of sources
147 * @activecount: the number of active sources
148 * @callbacks: callbacks
149 * @user_data: user data passed in callbacks
151 * The RTP session manager object
163 /* info for creating reports */
172 /* for sender/receiver counting */
176 GHashTable *ssrcs[32];
180 GstClockTime next_rtcp_check_time;
181 GstClockTime last_rtcp_send_time;
184 GstBuffer *bye_packet;
188 RTPSessionCallbacks callbacks;
191 RTPSessionStats stats;
196 * @on_new_ssrc: emited when a new source is found
197 * @on_bye_ssrc: emited when a source is gone
201 struct _RTPSessionClass {
202 GObjectClass parent_class;
205 void (*on_new_ssrc) (RTPSession *sess, RTPSource *source);
206 void (*on_ssrc_collision) (RTPSession *sess, RTPSource *source);
207 void (*on_ssrc_validated) (RTPSession *sess, RTPSource *source);
208 void (*on_bye_ssrc) (RTPSession *sess, RTPSource *source);
209 void (*on_bye_timeout) (RTPSession *sess, RTPSource *source);
210 void (*on_timeout) (RTPSession *sess, RTPSource *source);
213 GType rtp_session_get_type (void);
215 /* create and configure */
216 RTPSession* rtp_session_new (void);
217 void rtp_session_set_callbacks (RTPSession *sess,
218 RTPSessionCallbacks *callbacks,
220 void rtp_session_set_bandwidth (RTPSession *sess, gdouble bandwidth);
221 gdouble rtp_session_get_bandwidth (RTPSession *sess);
222 void rtp_session_set_rtcp_fraction (RTPSession *sess, gdouble fraction);
223 gdouble rtp_session_get_rtcp_fraction (RTPSession *sess);
225 void rtp_session_set_cname (RTPSession *sess, const gchar *cname);
226 gchar* rtp_session_get_cname (RTPSession *sess);
227 void rtp_session_set_name (RTPSession *sess, const gchar *name);
228 gchar* rtp_session_get_name (RTPSession *sess);
229 void rtp_session_set_email (RTPSession *sess, const gchar *email);
230 gchar* rtp_session_get_email (RTPSession *sess);
231 void rtp_session_set_phone (RTPSession *sess, const gchar *phone);
232 gchar* rtp_session_get_phone (RTPSession *sess);
233 void rtp_session_set_location (RTPSession *sess, const gchar *location);
234 gchar* rtp_session_get_location (RTPSession *sess);
235 void rtp_session_set_tool (RTPSession *sess, const gchar *tool);
236 gchar* rtp_session_get_tool (RTPSession *sess);
237 void rtp_session_set_note (RTPSession *sess, const gchar *note);
238 gchar* rtp_session_get_note (RTPSession *sess);
240 /* handling sources */
241 gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src);
242 guint rtp_session_get_num_sources (RTPSession *sess);
243 guint rtp_session_get_num_active_sources (RTPSession *sess);
244 RTPSource* rtp_session_get_source_by_ssrc (RTPSession *sess, guint32 ssrc);
245 RTPSource* rtp_session_get_source_by_cname (RTPSession *sess, const gchar *cname);
246 RTPSource* rtp_session_create_source (RTPSession *sess);
248 /* processing packets from receivers */
249 GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer);
250 GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer);
252 /* processing packets for sending */
253 GstFlowReturn rtp_session_send_rtp (RTPSession *sess, GstBuffer *buffer);
255 /* stopping the session */
256 GstFlowReturn rtp_session_send_bye (RTPSession *sess, const gchar *reason);
258 /* get interval for next RTCP interval */
259 GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime time);
260 GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime time);
262 #endif /* __RTP_SESSION_H__ */