session: configure sdes with structure only
[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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, 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/net/gstnetaddressmeta.h>
26 #include <gio/gio.h>
27
28 #include "rtpstats.h"
29
30 /* the default number of consecutive RTP packets we need to receive before the
31  * source is considered valid */
32 #define RTP_NO_PROBATION        0
33 #define RTP_DEFAULT_PROBATION   2
34
35 #define RTP_SEQ_MOD          (1 << 16)
36
37 typedef struct _RTPSource RTPSource;
38 typedef struct _RTPSourceClass RTPSourceClass;
39
40 #define RTP_TYPE_SOURCE             (rtp_source_get_type())
41 #define RTP_SOURCE(src)             (G_TYPE_CHECK_INSTANCE_CAST((src),RTP_TYPE_SOURCE,RTPSource))
42 #define RTP_SOURCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),RTP_TYPE_SOURCE,RTPSourceClass))
43 #define RTP_IS_SOURCE(src)          (G_TYPE_CHECK_INSTANCE_TYPE((src),RTP_TYPE_SOURCE))
44 #define RTP_IS_SOURCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),RTP_TYPE_SOURCE))
45 #define RTP_SOURCE_CAST(src)        ((RTPSource *)(src))
46
47 /**
48  * RTP_SOURCE_IS_ACTIVE:
49  * @src: an #RTPSource
50  *
51  * Check if @src is active. A source is active when it has been validated
52  * and has not yet received a BYE packet.
53  */
54 #define RTP_SOURCE_IS_ACTIVE(src)  (src->validated && !src->received_bye)
55
56 /**
57  * RTP_SOURCE_IS_SENDER:
58  * @src: an #RTPSource
59  *
60  * Check if @src is a sender.
61  */
62 #define RTP_SOURCE_IS_SENDER(src)  (src->is_sender)
63
64 /**
65  * RTPSourcePushRTP:
66  * @src: an #RTPSource
67  * @buffer: the RTP buffer ready for processing
68  * @user_data: user data specified when registering
69  *
70  * This callback will be called when @src has @buffer ready for further
71  * processing.
72  *
73  * Returns: a #GstFlowReturn.
74  */
75 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, GstBuffer *buffer,
76         gpointer user_data);
77
78 /**
79  * RTPSourceClockRate:
80  * @src: an #RTPSource
81  * @payload: a payload type
82  * @user_data: user data specified when registering
83  *
84  * This callback will be called when @src needs the clock-rate of the
85  * @payload.
86  *
87  * Returns: a clock-rate for @payload.
88  */
89 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
90
91 /**
92  * RTPSourceCallbacks:
93  * @push_rtp: a packet becomes available for handling
94  * @clock_rate: a clock-rate is requested
95  * @get_time: the current clock time is requested
96  *
97  * Callbacks performed by #RTPSource when actions need to be performed.
98  */
99 typedef struct {
100   RTPSourcePushRTP     push_rtp;
101   RTPSourceClockRate   clock_rate;
102 } RTPSourceCallbacks;
103
104 /**
105  * RTPConflictingAddress:
106  * @address: #GSocketAddress which conflicted
107  * @last_conflict_time: time when the last conflict was seen
108  *
109  * This structure is used to account for addresses that have conflicted to find
110  * loops.
111  */
112 typedef struct {
113   GSocketAddress *address;
114   GstClockTime time;
115 } RTPConflictingAddress;
116
117 /**
118  * RTPSource:
119  *
120  * A source in the #RTPSession
121  *
122  * @conflicting_addresses: GList of conflicting addresses
123  */
124 struct _RTPSource {
125   GObject       object;
126
127   /*< private >*/
128   guint32       ssrc;
129
130   guint         probation;
131   guint         curr_probation;
132   gboolean      validated;
133   gboolean      internal;
134   gboolean      is_csrc;
135   gboolean      is_sender;
136   gboolean      closing;
137
138   GstStructure  *sdes;
139
140   gboolean      received_bye;
141   gchar        *bye_reason;
142
143   GSocketAddress *rtp_from;
144   GSocketAddress *rtcp_from;
145
146   gint          payload;
147   GstCaps      *caps;
148   gint          clock_rate;
149   gint32        seqnum_base;
150
151   GstClockTime  bye_time;
152   GstClockTime  last_activity;
153   GstClockTime  last_rtp_activity;
154
155   GstClockTime  last_rtime;
156   GstClockTime  last_rtptime;
157
158   /* for bitrate estimation */
159   guint64       bitrate;
160   GstClockTime  prev_rtime;
161   guint64       bytes_sent;
162   guint64       bytes_received;
163
164   GQueue       *packets;
165
166   RTPSourceCallbacks callbacks;
167   gpointer           user_data;
168
169   RTPSourceStats stats;
170   RTPReceiverReport last_rr;
171
172   GList         *conflicting_addresses;
173
174   GQueue        *retained_feedback;
175
176   gboolean     send_pli;
177   gboolean     send_fir;
178   guint8       current_send_fir_seqnum;
179   gint         last_fir_count;
180 };
181
182 struct _RTPSourceClass {
183   GObjectClass   parent_class;
184 };
185
186 GType rtp_source_get_type (void);
187
188 /* managing lifetime of sources */
189 RTPSource*      rtp_source_new                 (guint32 ssrc);
190 void            rtp_source_set_callbacks       (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
191
192 /* properties */
193 guint32         rtp_source_get_ssrc            (RTPSource *src);
194
195 void            rtp_source_set_as_csrc         (RTPSource *src);
196 gboolean        rtp_source_is_as_csrc          (RTPSource *src);
197
198 gboolean        rtp_source_is_active           (RTPSource *src);
199 gboolean        rtp_source_is_validated        (RTPSource *src);
200 gboolean        rtp_source_is_sender           (RTPSource *src);
201
202 gboolean        rtp_source_received_bye        (RTPSource *src);
203 gchar *         rtp_source_get_bye_reason      (RTPSource *src);
204
205 void            rtp_source_update_caps         (RTPSource *src, GstCaps *caps);
206
207 /* SDES info */
208 const GstStructure *
209                 rtp_source_get_sdes_struct     (RTPSource * src);
210 gboolean        rtp_source_set_sdes_struct     (RTPSource * src, GstStructure *sdes);
211
212 /* handling network address */
213 void            rtp_source_set_rtp_from        (RTPSource *src, GSocketAddress *address);
214 void            rtp_source_set_rtcp_from       (RTPSource *src, GSocketAddress *address);
215
216 /* handling RTP */
217 GstFlowReturn   rtp_source_process_rtp         (RTPSource *src, GstBuffer *buffer, RTPArrivalStats *arrival);
218
219 GstFlowReturn   rtp_source_send_rtp            (RTPSource *src, gpointer data, gboolean is_list,
220                                                 GstClockTime running_time);
221 /* RTCP messages */
222 void            rtp_source_process_bye         (RTPSource *src, const gchar *reason);
223 void            rtp_source_process_sr          (RTPSource *src, GstClockTime time, guint64 ntptime,
224                                                 guint32 rtptime, guint32 packet_count, guint32 octet_count);
225 void            rtp_source_process_rb          (RTPSource *src, guint64 ntpnstime, guint8 fractionlost,
226                                                 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
227                                                 guint32 lsr, guint32 dlsr);
228
229 gboolean        rtp_source_get_new_sr          (RTPSource *src, guint64 ntpnstime, GstClockTime running_time,
230                                                 guint64 *ntptime, guint32 *rtptime, guint32 *packet_count,
231                                                 guint32 *octet_count);
232 gboolean        rtp_source_get_new_rb          (RTPSource *src, GstClockTime time, guint8 *fractionlost,
233                                                 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
234                                                 guint32 *lsr, guint32 *dlsr);
235
236 gboolean        rtp_source_get_last_sr         (RTPSource *src, GstClockTime *time, guint64 *ntptime,
237                                                 guint32 *rtptime, guint32 *packet_count,
238                                                 guint32 *octet_count);
239 gboolean        rtp_source_get_last_rb         (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
240                                                 guint32 *exthighestseq, guint32 *jitter,
241                                                 guint32 *lsr, guint32 *dlsr, guint32 *round_trip);
242
243 void            rtp_source_reset               (RTPSource * src);
244
245 gboolean        rtp_source_find_conflicting_address (RTPSource * src,
246                                                 GSocketAddress *address,
247                                                 GstClockTime time);
248
249 void            rtp_source_add_conflicting_address (RTPSource * src,
250                                                 GSocketAddress *address,
251                                                 GstClockTime time);
252
253 void            rtp_source_timeout             (RTPSource * src,
254                                                 GstClockTime current_time,
255                                                 GstClockTime collision_timeout,
256                                                 GstClockTime feedback_retention_window);
257
258 void            rtp_source_retain_rtcp_packet  (RTPSource * src,
259                                                 GstRTCPPacket *pkt,
260                                                 GstClockTime running_time);
261
262 gboolean        rtp_source_has_retained        (RTPSource * src,
263                                                 GCompareFunc func,
264                                                 gconstpointer data);
265
266
267 #endif /* __RTP_SOURCE_H__ */