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_SOURCE_H__
21 #define __RTP_SOURCE_H__
24 #include <gst/rtp/gstrtcpbuffer.h>
25 #include <gst/netbuffer/gstnetbuffer.h>
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
34 #define RTP_SEQ_MOD (1 << 16)
35 #define RTP_MAX_DROPOUT 3000
36 #define RTP_MAX_MISORDER 100
38 typedef struct _RTPSource RTPSource;
39 typedef struct _RTPSourceClass RTPSourceClass;
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))
49 * RTP_SOURCE_IS_ACTIVE:
52 * Check if @src is active. A source is active when it has been validated
53 * and has not yet received a BYE packet.
55 #define RTP_SOURCE_IS_ACTIVE(src) (src->validated && !src->received_bye)
58 * RTP_SOURCE_IS_SENDER:
61 * Check if @src is a sender.
63 #define RTP_SOURCE_IS_SENDER(src) (src->is_sender)
68 * @buffer: the RTP buffer ready for processing
69 * @user_data: user data specified when registering
71 * This callback will be called when @src has @buffer ready for further
74 * Returns: a #GstFlowReturn.
76 typedef GstFlowReturn (*RTPSourcePushRTP) (RTPSource *src, GstBuffer *buffer,
82 * @payload: a payload type
83 * @user_data: user data specified when registering
85 * This callback will be called when @src needs the clock-rate of the
88 * Returns: a clock-rate for @payload.
90 typedef gint (*RTPSourceClockRate) (RTPSource *src, guint8 payload, gpointer user_data);
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
98 * Callbacks performed by #RTPSource when actions need to be performed.
101 RTPSourcePushRTP push_rtp;
102 RTPSourceClockRate clock_rate;
103 } RTPSourceCallbacks;
108 * A source in the #RTPSession
128 gboolean received_bye;
131 gboolean have_rtp_from;
132 GstNetAddress rtp_from;
133 gboolean have_rtcp_from;
134 GstNetAddress rtcp_from;
143 /* to calculate the clock skew */
144 guint64 skew_base_ntpnstime;
145 guint64 skew_base_rtptime;
148 guint64 prev_ext_rtptime;
150 GstClockTime bye_time;
151 GstClockTime last_activity;
152 GstClockTime last_rtp_activity;
154 GstClockTime last_rtptime;
155 GstClockTime last_ntpnstime;
159 RTPSourceCallbacks callbacks;
162 RTPSourceStats stats;
165 struct _RTPSourceClass {
166 GObjectClass parent_class;
169 GType rtp_source_get_type (void);
171 /* managing lifetime of sources */
172 RTPSource* rtp_source_new (guint32 ssrc);
173 void rtp_source_update_caps (RTPSource *src, GstCaps *caps);
175 void rtp_source_set_callbacks (RTPSource *src, RTPSourceCallbacks *cb, gpointer data);
176 void rtp_source_set_as_csrc (RTPSource *src);
178 void rtp_source_set_rtp_from (RTPSource *src, GstNetAddress *address);
179 void rtp_source_set_rtcp_from (RTPSource *src, GstNetAddress *address);
182 GstFlowReturn rtp_source_process_rtp (RTPSource *src, GstBuffer *buffer, RTPArrivalStats *arrival);
184 GstFlowReturn rtp_source_send_rtp (RTPSource *src, GstBuffer *buffer, guint64 ntpnstime);
187 void rtp_source_process_bye (RTPSource *src, const gchar *reason);
188 void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime,
189 guint32 rtptime, guint32 packet_count, guint32 octet_count);
190 void rtp_source_process_rb (RTPSource *src, GstClockTime time, guint8 fractionlost,
191 gint32 packetslost, guint32 exthighestseq, guint32 jitter,
192 guint32 lsr, guint32 dlsr);
194 gboolean rtp_source_get_new_sr (RTPSource *src, GstClockTime time, guint64 *ntptime,
195 guint32 *rtptime, guint32 *packet_count, guint32 *octet_count);
196 gboolean rtp_source_get_new_rb (RTPSource *src, GstClockTime time, guint8 *fractionlost,
197 gint32 *packetslost, guint32 *exthighestseq, guint32 *jitter,
198 guint32 *lsr, guint32 *dlsr);
200 gboolean rtp_source_get_last_sr (RTPSource *src, GstClockTime *time, guint64 *ntptime,
201 guint32 *rtptime, guint32 *packet_count, guint32 *octet_count);
202 gboolean rtp_source_get_last_rb (RTPSource *src, guint8 *fractionlost, gint32 *packetslost,
203 guint32 *exthighestseq, guint32 *jitter,
204 guint32 *lsr, guint32 *dlsr);
206 #endif /* __RTP_SOURCE_H__ */