gst/rtpmanager/gstrtpbin.c: fix for pad name change
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / rtpsession.h
1 /* GStreamer
2  * Copyright (C) <2007> Wim Taymans <wim@fluendo.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef __RTP_SESSION_H__
21 #define __RTP_SESSION_H__
22
23 #include <gst/gst.h>
24 #include <gst/netbuffer/gstnetbuffer.h>
25
26 #include "rtpsource.h"
27
28 typedef struct _RTPSession RTPSession;
29 typedef struct _RTPSessionClass RTPSessionClass;
30
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))
37
38 #define RTP_SESSION_LOCK(sess)     (g_mutex_lock ((sess)->lock))
39 #define RTP_SESSION_UNLOCK(sess)   (g_mutex_unlock ((sess)->lock))
40
41 /**
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
47  *
48  * This callback will be called when @sess has @buffer ready for further
49  * processing. Processing the buffer typically includes decoding and displaying
50  * the buffer.
51  *
52  * Returns: a #GstFlowReturn.
53  */
54 typedef GstFlowReturn (*RTPSessionProcessRTP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
55
56 /**
57  * RTPSessionSendRTP:
58  * @sess: an #RTPSession
59  * @src: the #RTPSource
60  * @buffer: the RTP buffer ready for sending
61  * @user_data: user data specified when registering
62  *
63  * This callback will be called when @sess has @buffer ready for sending to
64  * all listening participants in this session.
65  *
66  * Returns: a #GstFlowReturn.
67  */
68 typedef GstFlowReturn (*RTPSessionSendRTP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
69
70 /**
71  * RTPSessionSendRTCP:
72  * @sess: an #RTPSession
73  * @src: the #RTPSource
74  * @buffer: the RTCP buffer ready for sending
75  * @user_data: user data specified when registering
76  *
77  * This callback will be called when @sess has @buffer ready for sending to
78  * all listening participants in this session.
79  *
80  * Returns: a #GstFlowReturn.
81  */
82 typedef GstFlowReturn (*RTPSessionSendRTCP) (RTPSession *sess, RTPSource *src, GstBuffer *buffer, gpointer user_data);
83
84 /**
85  * RTPSessionClockRate:
86  * @sess: an #RTPSession
87  * @payload: the payload
88  * @user_data: user data specified when registering
89  *
90  * This callback will be called when @sess needs the clock-rate of @payload.
91  *
92  * Returns: the clock-rate of @pt.
93  */
94 typedef gint (*RTPSessionClockRate) (RTPSession *sess, guint8 payload, gpointer user_data);
95
96 /**
97  * RTPSessionGetTime:
98  * @sess: an #RTPSession
99  * @user_data: user data specified when registering
100  *
101  * This callback will be called when @sess needs the current time in
102  * nanoseconds.
103  *
104  * Returns: a #GstClockTime with the current time in nanoseconds.
105  */
106 typedef GstClockTime (*RTPSessionGetTime) (RTPSession *sess, gpointer user_data);
107
108 /**
109  * RTPSessionCallbacks:
110  * @RTPSessionProcessRTP: callback to process RTP packets
111  * @RTPSessionSendRTP: callback for sending RTP packets
112  * @RTPSessionSendRTCP: callback for sending RTCP packets
113  * @RTPSessionGetTime: callback for returning the current time
114  *
115  * These callbacks can be installed on the session manager to get notification
116  * when RTP and RTCP packets are ready for further processing. These callbacks
117  * are not implemented with signals for performance reasons.
118  */
119 typedef struct {
120   RTPSessionProcessRTP  process_rtp;
121   RTPSessionSendRTP     send_rtp;
122   RTPSessionSendRTCP    send_rtcp;
123   RTPSessionClockRate   clock_rate;
124   RTPSessionGetTime     get_time;
125 } RTPSessionCallbacks;
126
127 /**
128  * RTPSession:
129  * @lock: lock to protect the session
130  * @source: the source of this session
131  * @ssrcs: Hashtable of sources indexed by SSRC
132  * @cnames: Hashtable of sources indexed by CNAME
133  * @num_sources: the number of sources
134  * @activecount: the number of active sources
135  * @callbacks: callbacks
136  * @user_data: user data passed in callbacks
137  *
138  * The RTP session manager object
139  */
140 struct _RTPSession {
141   GObject       object;
142
143   GMutex       *lock;
144
145   guint         header_len;
146   guint         mtu;
147
148   RTPSource    *source;
149
150   /* info for creating reports */
151   gchar        *cname;
152   gchar        *name;
153   gchar        *email;
154   gchar        *phone;
155   gchar        *location;
156   gchar        *tool;
157   gchar        *note;
158
159   /* for sender/receiver counting */
160   guint32       key;
161   guint32       mask_idx;
162   guint32       mask;
163   GHashTable   *ssrcs[32];
164   GHashTable   *cnames;
165   guint         total_sources;
166
167   RTPSessionCallbacks callbacks;
168   gpointer            user_data;
169
170   RTPSessionStats stats;
171 };
172
173 /**
174  * RTPSessionClass:
175  * @on_new_ssrc: emited when a new source is found
176  * @on_bye_ssrc: emited when a source is gone
177  *
178  * The session class.
179  */
180 struct _RTPSessionClass {
181   GObjectClass   parent_class;
182
183   /* signals */
184   void (*on_new_ssrc)       (RTPSession *sess, RTPSource *source);
185   void (*on_ssrc_collision) (RTPSession *sess, RTPSource *source);
186   void (*on_ssrc_validated) (RTPSession *sess, RTPSource *source);
187   void (*on_bye_ssrc)       (RTPSession *sess, RTPSource *source);
188 };
189
190 GType rtp_session_get_type (void);
191
192 /* create and configure */
193 RTPSession*     rtp_session_new           (void);
194 void            rtp_session_set_callbacks          (RTPSession *sess, 
195                                                     RTPSessionCallbacks *callbacks,
196                                                     gpointer user_data);
197 void            rtp_session_set_bandwidth          (RTPSession *sess, gdouble bandwidth);
198 gdouble         rtp_session_get_bandwidth          (RTPSession *sess);
199 void            rtp_session_set_rtcp_fraction      (RTPSession *sess, gdouble fraction);
200 gdouble         rtp_session_get_rtcp_fraction      (RTPSession *sess);
201
202 void            rtp_session_set_cname              (RTPSession *sess, const gchar *cname);
203 gchar*          rtp_session_get_cname              (RTPSession *sess);
204 void            rtp_session_set_name               (RTPSession *sess, const gchar *name);
205 gchar*          rtp_session_get_name               (RTPSession *sess);
206 void            rtp_session_set_email              (RTPSession *sess, const gchar *email);
207 gchar*          rtp_session_get_email              (RTPSession *sess);
208 void            rtp_session_set_phone              (RTPSession *sess, const gchar *phone);
209 gchar*          rtp_session_get_phone              (RTPSession *sess);
210 void            rtp_session_set_location           (RTPSession *sess, const gchar *location);
211 gchar*          rtp_session_get_location           (RTPSession *sess);
212 void            rtp_session_set_tool               (RTPSession *sess, const gchar *tool);
213 gchar*          rtp_session_get_tool               (RTPSession *sess);
214 void            rtp_session_set_note               (RTPSession *sess, const gchar *note);
215 gchar*          rtp_session_get_note               (RTPSession *sess);
216
217 /* handling sources */
218 gboolean        rtp_session_add_source             (RTPSession *sess, RTPSource *src);
219 gint            rtp_session_get_num_sources        (RTPSession *sess);
220 gint            rtp_session_get_num_active_sources (RTPSession *sess);
221 RTPSource*      rtp_session_get_source_by_ssrc     (RTPSession *sess, guint32 ssrc);
222 RTPSource*      rtp_session_get_source_by_cname    (RTPSession *sess, const gchar *cname);
223 RTPSource*      rtp_session_create_source          (RTPSession *sess);
224
225 /* processing packets from receivers */
226 GstFlowReturn   rtp_session_process_rtp            (RTPSession *sess, GstBuffer *buffer);
227 GstFlowReturn   rtp_session_process_rtcp           (RTPSession *sess, GstBuffer *buffer);
228
229 /* processing packets for sending */
230 GstFlowReturn   rtp_session_send_rtp               (RTPSession *sess, GstBuffer *buffer);
231
232 /* get interval for next RTCP interval */
233 gdouble         rtp_session_get_reporting_interval (RTPSession *sess);
234 GstFlowReturn   rtp_session_perform_reporting      (RTPSession *sess);
235
236 #endif /* __RTP_SESSION_H__ */