a2ba2d611b23512715baa36e692c02d8ce8b435a
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / rtpsource.h
1 /* GStreamer
2  * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.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_SOURCE_H__
21 #define __RTP_SOURCE_H__
22
23 #include <gst/gst.h>
24 #include <gst/rtp/gstrtcpbuffer.h>
25 #include <gst/netbuffer/gstnetbuffer.h>
26
27 #include "rtpstats.h"
28
29 /* the default number of consecutive RTP packets we need to receive before the
30  * source is considered valid */
31 #define RTP_NO_PROBATION        0
32 #define RTP_DEFAULT_PROBATION   2
33
34 #define RTP_SEQ_MOD          (1 << 16)
35 #define RTP_MAX_DROPOUT      3000
36 #define RTP_MAX_MISORDER     100
37
38 typedef struct _RTPSource RTPSource;
39 typedef struct _RTPSourceClass RTPSourceClass;
40
41 #define RTP_TYPE_SOURCE             (rtp_source_get_type())
42 #define RTP_SOURCE(src)             (G_TYPE_CHECK_INSTANCE_CAST((src),RTP_TYPE_SOURCE,RTPSource))
43 #define RTP_SOURCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SOURCE,RTPSourceClass))
44 #define RTP_IS_SOURCE(src)          (G_TYPE_CHECK_INSTANCE_TYPE((src),RTP_TYPE_SOURCE))
45 #define RTP_IS_SOURCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SOURCE))
46 #define RTP_SOURCE_CAST(src)        ((RTPSource *)(src))
47
48 /**
49  * RTP_SOURCE_IS_ACTIVE:
50  * @src: an #RTPSource
51  *
52  * Check if @src is active. A source is active when it has been validated
53  * and has not yet received a BYE packet.
54  */
55 #define RTP_SOURCE_IS_ACTIVE(src)  (src->validated && !src->received_bye)
56
57 /**
58  * RTP_SOURCE_IS_SENDER:
59  * @src: an #RTPSource
60  *
61  * Check if @src is a sender.
62  */
63 #define RTP_SOURCE_IS_SENDER(src)  (src->is_sender)
64
65 /**
66  * RTPSourcePushRTP:
67  * @src: an #RTPSource
68  * @buffer: the RTP buffer ready for processing
69  * @user_data: user data specified when registering
70  *
71  * This callback will be called when @src has @buffer ready for further
72  * processing.
73  *
74  * Returns: a #GstFlowReturn.
75  */
76 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, GstBuffer *buffer, 
77         gpointer user_data);
78
79 /**
80  * RTPSourceClockRate:
81  * @src: an #RTPSource
82  * @payload: a payload type
83  * @user_data: user data specified when registering
84  *
85  * This callback will be called when @src needs the clock-rate of the
86  * @payload.
87  *
88  * Returns: a clock-rate for @payload.
89  */
90 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
91
92 /**
93  * RTPSourceCallbacks:
94  * @push_rtp: a packet becomes available for handling
95  * @clock_rate: a clock-rate is requested
96  * @get_time: the current clock time is requested
97  *
98  * Callbacks performed by #RTPSource when actions need to be performed.
99  */
100 typedef struct {
101   RTPSourcePushRTP     push_rtp;
102   RTPSourceClockRate   clock_rate;
103 } RTPSourceCallbacks;
104
105 /**
106  * RTPSource:
107  *
108  * A source in the #RTPSession
109  */
110 struct _RTPSource {
111   GObject       object;
112
113   /*< private >*/
114   guint32       ssrc;
115
116   gint          probation;
117   gboolean      validated;
118   gboolean      is_csrc;
119   gboolean      is_sender;
120
121   guint8       *sdes[9];
122   guint         sdes_len[9];
123
124   gboolean      received_bye;
125   gchar        *bye_reason;
126
127   gboolean      have_rtp_from;
128   GstNetAddress rtp_from;
129   gboolean      have_rtcp_from;
130   GstNetAddress rtcp_from;
131
132   guint8        payload;
133   GstCaps      *caps;
134   gint          clock_rate;
135   gint32        seqnum_base;
136   gint64        clock_base;
137   guint64       clock_base_time;
138
139   GstClockTime  bye_time;
140   GstClockTime  last_activity;
141   GstClockTime  last_rtp_activity;
142
143   GstClockTime  last_rtptime;
144   GstClockTime  last_ntpnstime;
145
146   GQueue       *packets;
147
148   RTPSourceCallbacks callbacks;
149   gpointer           user_data;
150
151   RTPSourceStats stats;
152 };
153
154 struct _RTPSourceClass {
155   GObjectClass   parent_class;
156 };
157
158 GType rtp_source_get_type (void);
159
160 /* managing lifetime of sources */
161 RTPSource*      rtp_source_new                 (guint32 ssrc);
162 void            rtp_source_set_callbacks       (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
163
164 /* properties */
165 guint32         rtp_source_get_ssrc            (RTPSource *src);
166
167 void            rtp_source_set_as_csrc         (RTPSource *src);
168 gboolean        rtp_source_is_as_csrc          (RTPSource *src);
169
170 gboolean        rtp_source_is_active           (RTPSource *src);
171 gboolean        rtp_source_is_validated        (RTPSource *src);
172 gboolean        rtp_source_is_sender           (RTPSource *src);
173
174 gboolean        rtp_source_received_bye        (RTPSource *src);
175 gchar *         rtp_source_get_bye_reason      (RTPSource *src);
176
177 void            rtp_source_update_caps         (RTPSource *src, GstCaps *caps);
178
179 /* SDES info */
180 gboolean        rtp_source_set_sdes            (RTPSource *src, GstRTCPSDESType type, 
181                                                 const guint8 *data, guint len);
182 gboolean        rtp_source_set_sdes_string     (RTPSource *src, GstRTCPSDESType type,
183                                                 const gchar *data);
184 gboolean        rtp_source_get_sdes            (RTPSource *src, GstRTCPSDESType type,
185                                                 guint8 **data, guint *len);
186 gchar*          rtp_source_get_sdes_string     (RTPSource *src, GstRTCPSDESType type);
187
188 /* handling network address */
189 void            rtp_source_set_rtp_from        (RTPSource *src, GstNetAddress *address);
190 void            rtp_source_set_rtcp_from       (RTPSource *src, GstNetAddress *address);
191
192 /* handling RTP */
193 GstFlowReturn   rtp_source_process_rtp         (RTPSource *src, GstBuffer *buffer, RTPArrivalStats *arrival);
194
195 GstFlowReturn   rtp_source_send_rtp            (RTPSource *src, GstBuffer *buffer, guint64 ntpnstime);
196
197 /* RTCP messages */
198 void            rtp_source_process_bye         (RTPSource *src, const gchar *reason);
199 void            rtp_source_process_sr          (RTPSource *src, GstClockTime time, guint64 ntptime,
200                                                 guint32 rtptime, guint32 packet_count, guint32 octet_count);
201 void            rtp_source_process_rb          (RTPSource *src, GstClockTime time, guint8 fractionlost,
202                                                 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
203                                                 guint32 lsr, guint32 dlsr);
204
205 gboolean        rtp_source_get_new_sr          (RTPSource *src, GstClockTime time, guint64 *ntptime,
206                                                 guint32 *rtptime, guint32 *packet_count,
207                                                 guint32 *octet_count);
208 gboolean        rtp_source_get_new_rb          (RTPSource *src, GstClockTime time, guint8 *fractionlost,
209                                                 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
210                                                 guint32 *lsr, guint32 *dlsr);
211
212 gboolean        rtp_source_get_last_sr         (RTPSource *src, GstClockTime *time, guint64 *ntptime,
213                                                 guint32 *rtptime, guint32 *packet_count,
214                                                 guint32 *octet_count);
215 gboolean        rtp_source_get_last_rb         (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
216                                                 guint32 *exthighestseq, guint32 *jitter,
217                                                 guint32 *lsr, guint32 *dlsr);
218
219 void            rtp_source_reset               (RTPSource * src);
220
221 #endif /* __RTP_SOURCE_H__ */