2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * SECTION:element-rtpbin
22 * @see_also: rtpjitterbuffer, rtpsession, rtpptdemux, rtpssrcdemux
24 * RTP bin combines the functions of #GstRtpSession, #GstRtpSsrcDemux,
25 * #GstRtpJitterBuffer and #GstRtpPtDemux in one element. It allows for multiple
26 * RTP sessions that will be synchronized together using RTCP SR packets.
28 * #GstRtpBin is configured with a number of request pads that define the
29 * functionality that is activated, similar to the #GstRtpSession element.
31 * To use #GstRtpBin as an RTP receiver, request a recv_rtp_sink_\%u pad. The session
32 * number must be specified in the pad name.
33 * Data received on the recv_rtp_sink_\%u pad will be processed in the #GstRtpSession
34 * manager and after being validated forwarded on #GstRtpSsrcDemux element. Each
35 * RTP stream is demuxed based on the SSRC and send to a #GstRtpJitterBuffer. After
36 * the packets are released from the jitterbuffer, they will be forwarded to a
37 * #GstRtpPtDemux element. The #GstRtpPtDemux element will demux the packets based
38 * on the payload type and will create a unique pad recv_rtp_src_\%u_\%u_\%u on
39 * rtpbin with the session number, SSRC and payload type respectively as the pad
42 * To also use #GstRtpBin as an RTCP receiver, request a recv_rtcp_sink_\%u pad. The
43 * session number must be specified in the pad name.
45 * If you want the session manager to generate and send RTCP packets, request
46 * the send_rtcp_src_\%u pad with the session number in the pad name. Packet pushed
47 * on this pad contain SR/RR RTCP reports that should be sent to all participants
50 * To use #GstRtpBin as a sender, request a send_rtp_sink_\%u pad, which will
51 * automatically create a send_rtp_src_\%u pad. If the session number is not provided,
52 * the pad from the lowest available session will be returned. The session manager will modify the
53 * SSRC in the RTP packets to its own SSRC and wil forward the packets on the
54 * send_rtp_src_\%u pad after updating its internal state.
56 * #GstRtpBin can also demultiplex incoming bundled streams. The first
57 * #GstRtpSession will have a #GstRtpSsrcDemux element splitting the streams
58 * based on their SSRC and potentially dispatched to a different #GstRtpSession.
59 * Because retransmission SSRCs need to be merged with the corresponding media
60 * stream the #GstRtpBin::on-bundled-ssrc signal is emitted so that the
61 * application can find out to which session the SSRC belongs.
63 * The session manager needs the clock-rate of the payload types it is handling
64 * and will signal the #GstRtpSession::request-pt-map signal when it needs such a
65 * mapping. One can clear the cached values with the #GstRtpSession::clear-pt-map
68 * Access to the internal statistics of rtpbin is provided with the
69 * get-internal-session property. This action signal gives access to the
70 * RTPSession object which further provides action signals to retrieve the
71 * internal source and other sources.
73 * #GstRtpBin also has signals (#GstRtpBin::request-rtp-encoder,
74 * #GstRtpBin::request-rtp-decoder, #GstRtpBin::request-rtcp-encoder and
75 * #GstRtpBin::request-rtp-decoder) to dynamically request for RTP and RTCP encoders
76 * and decoders in order to support SRTP. The encoders must provide the pads
77 * rtp_sink_\%u and rtp_src_\%u for RTP and rtcp_sink_\%u and rtcp_src_\%u for
78 * RTCP. The session number will be used in the pad name. The decoders must provide
79 * rtp_sink and rtp_src for RTP and rtcp_sink and rtcp_src for RTCP. The decoders will
80 * be placed before the #GstRtpSession element, thus they must support SSRC demuxing
83 * #GstRtpBin has signals (#GstRtpBin::request-aux-sender and
84 * #GstRtpBin::request-aux-receiver to dynamically request an element that can be
85 * used to create or merge additional RTP streams. AUX elements are needed to
86 * implement FEC or retransmission (such as RFC 4588). An AUX sender must have one
87 * sink_\%u pad that matches the sessionid in the signal and it should have 1 or
88 * more src_\%u pads. For each src_%\u pad, a session will be made (if needed)
89 * and the pad will be linked to the session send_rtp_sink pad. Each session will
90 * then expose its source pad as send_rtp_src_\%u on #GstRtpBin.
91 * An AUX receiver has 1 src_\%u pad that much match the sessionid in the signal
92 * and 1 or more sink_\%u pads. A session will be made for each sink_\%u pad
93 * when the corresponding recv_rtp_sink_\%u pad is requested on #GstRtpBin.
96 * <title>Example pipelines</title>
98 * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink_0 \
99 * rtpbin ! rtptheoradepay ! theoradec ! xvimagesink
100 * ]| Receive RTP data from port 5000 and send to the session 0 in rtpbin.
102 * gst-launch-1.0 rtpbin name=rtpbin \
103 * v4l2src ! videoconvert ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \
104 * rtpbin.send_rtp_src_0 ! udpsink port=5000 \
105 * rtpbin.send_rtcp_src_0 ! udpsink port=5001 sync=false async=false \
106 * udpsrc port=5005 ! rtpbin.recv_rtcp_sink_0 \
107 * audiotestsrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_1 \
108 * rtpbin.send_rtp_src_1 ! udpsink port=5002 \
109 * rtpbin.send_rtcp_src_1 ! udpsink port=5003 sync=false async=false \
110 * udpsrc port=5007 ! rtpbin.recv_rtcp_sink_1
111 * ]| Encode and payload H263 video captured from a v4l2src. Encode and payload AMR
112 * audio generated from audiotestsrc. The video is sent to session 0 in rtpbin
113 * and the audio is sent to session 1. Video packets are sent on UDP port 5000
114 * and audio packets on port 5002. The video RTCP packets for session 0 are sent
115 * on port 5001 and the audio RTCP packets for session 0 are sent on port 5003.
116 * RTCP packets for session 0 are received on port 5005 and RTCP for session 1
117 * is received on port 5007. Since RTCP packets from the sender should be sent
118 * as soon as possible and do not participate in preroll, sync=false and
119 * async=false is configured on udpsink
121 * gst-launch-1.0 -v rtpbin name=rtpbin \
122 * udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H263-1998" \
123 * port=5000 ! rtpbin.recv_rtp_sink_0 \
124 * rtpbin. ! rtph263pdepay ! ffdec_h263 ! xvimagesink \
125 * udpsrc port=5001 ! rtpbin.recv_rtcp_sink_0 \
126 * rtpbin.send_rtcp_src_0 ! udpsink port=5005 sync=false async=false \
127 * udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" \
128 * port=5002 ! rtpbin.recv_rtp_sink_1 \
129 * rtpbin. ! rtpamrdepay ! amrnbdec ! alsasink \
130 * udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1 \
131 * rtpbin.send_rtcp_src_1 ! udpsink port=5007 sync=false async=false
132 * ]| Receive H263 on port 5000, send it through rtpbin in session 0, depayload,
133 * decode and display the video.
134 * Receive AMR on port 5002, send it through rtpbin in session 1, depayload,
135 * decode and play the audio.
136 * Receive server RTCP packets for session 0 on port 5001 and RTCP packets for
137 * session 1 on port 5003. These packets will be used for session management and
139 * Send RTCP reports for session 0 on port 5005 and RTCP reports for session 1
150 #include <gst/rtp/gstrtpbuffer.h>
151 #include <gst/rtp/gstrtcpbuffer.h>
153 #include "gstrtpbin.h"
154 #include "rtpsession.h"
155 #include "gstrtpsession.h"
156 #include "gstrtpjitterbuffer.h"
158 #include <gst/glib-compat-private.h>
160 GST_DEBUG_CATEGORY_STATIC (gst_rtp_bin_debug);
161 #define GST_CAT_DEFAULT gst_rtp_bin_debug
164 static GstStaticPadTemplate rtpbin_recv_rtp_sink_template =
165 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%u",
168 GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
171 static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
172 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%u",
175 GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
178 static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
179 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink_%u",
182 GST_STATIC_CAPS ("application/x-rtp")
186 static GstStaticPadTemplate rtpbin_recv_rtp_src_template =
187 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%u_%u_%u",
190 GST_STATIC_CAPS ("application/x-rtp")
193 static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
194 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%u",
197 GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
200 static GstStaticPadTemplate rtpbin_send_rtp_src_template =
201 GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%u",
204 GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
207 #define GST_RTP_BIN_LOCK(bin) g_mutex_lock (&(bin)->priv->bin_lock)
208 #define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->bin_lock)
210 /* lock to protect dynamic callbacks, like pad-added and new ssrc. */
211 #define GST_RTP_BIN_DYN_LOCK(bin) g_mutex_lock (&(bin)->priv->dyn_lock)
212 #define GST_RTP_BIN_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->dyn_lock)
214 /* lock for shutdown */
215 #define GST_RTP_BIN_SHUTDOWN_LOCK(bin,label) \
217 if (g_atomic_int_get (&bin->priv->shutdown)) \
219 GST_RTP_BIN_DYN_LOCK (bin); \
220 if (g_atomic_int_get (&bin->priv->shutdown)) { \
221 GST_RTP_BIN_DYN_UNLOCK (bin); \
226 /* unlock for shutdown */
227 #define GST_RTP_BIN_SHUTDOWN_UNLOCK(bin) \
228 GST_RTP_BIN_DYN_UNLOCK (bin); \
230 /* Minimum time offset to apply. This compensates for rounding errors in NTP to
231 * RTP timestamp conversions */
232 #define MIN_TS_OFFSET (4 * GST_MSECOND)
234 struct _GstRtpBinPrivate
238 /* lock protecting dynamic adding/removing */
241 /* if we are shutting down or not */
246 /* NTP time in ns of last SR sync used */
247 guint64 last_ntpnstime;
249 /* list of extra elements */
253 /* signals and args */
256 SIGNAL_REQUEST_PT_MAP,
257 SIGNAL_PAYLOAD_TYPE_CHANGE,
261 SIGNAL_GET_INTERNAL_SESSION,
263 SIGNAL_GET_INTERNAL_STORAGE,
266 SIGNAL_ON_SSRC_COLLISION,
267 SIGNAL_ON_SSRC_VALIDATED,
268 SIGNAL_ON_SSRC_ACTIVE,
271 SIGNAL_ON_BYE_TIMEOUT,
273 SIGNAL_ON_SENDER_TIMEOUT,
276 SIGNAL_REQUEST_RTP_ENCODER,
277 SIGNAL_REQUEST_RTP_DECODER,
278 SIGNAL_REQUEST_RTCP_ENCODER,
279 SIGNAL_REQUEST_RTCP_DECODER,
281 SIGNAL_REQUEST_FEC_DECODER,
282 SIGNAL_REQUEST_FEC_ENCODER,
284 SIGNAL_NEW_JITTERBUFFER,
287 SIGNAL_REQUEST_AUX_SENDER,
288 SIGNAL_REQUEST_AUX_RECEIVER,
290 SIGNAL_ON_NEW_SENDER_SSRC,
291 SIGNAL_ON_SENDER_SSRC_ACTIVE,
293 SIGNAL_ON_BUNDLED_SSRC,
298 #define DEFAULT_LATENCY_MS 200
299 #define DEFAULT_DROP_ON_LATENCY FALSE
300 #define DEFAULT_SDES NULL
301 #define DEFAULT_DO_LOST FALSE
302 #define DEFAULT_IGNORE_PT FALSE
303 #define DEFAULT_NTP_SYNC FALSE
304 #define DEFAULT_AUTOREMOVE FALSE
305 #define DEFAULT_BUFFER_MODE RTP_JITTER_BUFFER_MODE_SLAVE
306 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
307 #define DEFAULT_RTCP_SYNC GST_RTP_BIN_RTCP_SYNC_ALWAYS
308 #define DEFAULT_RTCP_SYNC_INTERVAL 0
309 #define DEFAULT_DO_SYNC_EVENT FALSE
310 #define DEFAULT_DO_RETRANSMISSION FALSE
311 #define DEFAULT_RTP_PROFILE GST_RTP_PROFILE_AVP
312 #define DEFAULT_NTP_TIME_SOURCE GST_RTP_NTP_TIME_SOURCE_NTP
313 #define DEFAULT_RTCP_SYNC_SEND_TIME TRUE
314 #define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
315 #define DEFAULT_MAX_DROPOUT_TIME 60000
316 #define DEFAULT_MAX_MISORDER_TIME 2000
317 #define DEFAULT_RFC7273_SYNC FALSE
318 #define DEFAULT_MAX_STREAMS G_MAXUINT
319 #define DEFAULT_MAX_TS_OFFSET_ADJUSTMENT G_GUINT64_CONSTANT(0)
320 #define DEFAULT_MAX_TS_OFFSET G_GINT64_CONSTANT(3000000000)
326 PROP_DROP_ON_LATENCY,
332 PROP_RTCP_SYNC_INTERVAL,
335 PROP_USE_PIPELINE_CLOCK,
337 PROP_DO_RETRANSMISSION,
339 PROP_NTP_TIME_SOURCE,
340 PROP_RTCP_SYNC_SEND_TIME,
341 PROP_MAX_RTCP_RTP_TIME_DIFF,
342 PROP_MAX_DROPOUT_TIME,
343 PROP_MAX_MISORDER_TIME,
346 PROP_MAX_TS_OFFSET_ADJUSTMENT,
350 #define GST_RTP_BIN_RTCP_SYNC_TYPE (gst_rtp_bin_rtcp_sync_get_type())
352 gst_rtp_bin_rtcp_sync_get_type (void)
354 static GType rtcp_sync_type = 0;
355 static const GEnumValue rtcp_sync_types[] = {
356 {GST_RTP_BIN_RTCP_SYNC_ALWAYS, "always", "always"},
357 {GST_RTP_BIN_RTCP_SYNC_INITIAL, "initial", "initial"},
358 {GST_RTP_BIN_RTCP_SYNC_RTP, "rtp-info", "rtp-info"},
362 if (!rtcp_sync_type) {
363 rtcp_sync_type = g_enum_register_static ("GstRTCPSync", rtcp_sync_types);
365 return rtcp_sync_type;
369 typedef struct _GstRtpBinSession GstRtpBinSession;
370 typedef struct _GstRtpBinStream GstRtpBinStream;
371 typedef struct _GstRtpBinClient GstRtpBinClient;
373 static guint gst_rtp_bin_signals[LAST_SIGNAL] = { 0 };
375 static GstCaps *pt_map_requested (GstElement * element, guint pt,
376 GstRtpBinSession * session);
377 static void payload_type_change (GstElement * element, guint pt,
378 GstRtpBinSession * session);
379 static void remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
380 static void remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
381 static void remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
382 static void remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
383 static void free_client (GstRtpBinClient * client, GstRtpBin * bin);
384 static void free_stream (GstRtpBinStream * stream, GstRtpBin * bin);
385 static GstRtpBinSession *create_session (GstRtpBin * rtpbin, gint id);
386 static GstPad *complete_session_sink (GstRtpBin * rtpbin,
387 GstRtpBinSession * session, gboolean bundle_demuxer_needed);
389 complete_session_receiver (GstRtpBin * rtpbin, GstRtpBinSession * session,
391 static GstPad *complete_session_rtcp (GstRtpBin * rtpbin,
392 GstRtpBinSession * session, guint sessid, gboolean bundle_demuxer_needed);
394 /* Manages the RTP stream for one SSRC.
396 * We pipe the stream (comming from the SSRC demuxer) into a jitterbuffer.
397 * If we see an SDES RTCP packet that links multiple SSRCs together based on a
398 * common CNAME, we create a GstRtpBinClient structure to group the SSRCs
399 * together (see below).
401 struct _GstRtpBinStream
403 /* the SSRC of this stream */
409 /* the session this SSRC belongs to */
410 GstRtpBinSession *session;
412 /* the jitterbuffer of the SSRC */
414 gulong buffer_handlesync_sig;
415 gulong buffer_ptreq_sig;
416 gulong buffer_ntpstop_sig;
419 /* the PT demuxer of the SSRC */
421 gulong demux_newpad_sig;
422 gulong demux_padremoved_sig;
423 gulong demux_ptreq_sig;
424 gulong demux_ptchange_sig;
426 /* if we have calculated a valid rt_delta for this stream */
428 /* mapping to local RTP and NTP time */
431 /* base rtptime in gst time */
435 #define GST_RTP_SESSION_LOCK(sess) g_mutex_lock (&(sess)->lock)
436 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock (&(sess)->lock)
438 /* Manages the receiving end of the packets.
440 * There is one such structure for each RTP session (audio/video/...).
441 * We get the RTP/RTCP packets and stuff them into the session manager. From
442 * there they are pushed into an SSRC demuxer that splits the stream based on
443 * SSRC. Each of the SSRC streams go into their own jitterbuffer (managed with
444 * the GstRtpBinStream above).
446 * Before the SSRC demuxer, a storage element may be inserted for the purpose
447 * of Forward Error Correction.
449 struct _GstRtpBinSession
455 /* the session element */
457 /* the SSRC demuxer */
459 gulong demux_newpad_sig;
460 gulong demux_padremoved_sig;
465 /* Bundling support */
466 GstElement *rtp_funnel;
467 GstElement *rtcp_funnel;
468 GstElement *bundle_demux;
469 gulong bundle_demux_newpad_sig;
473 /* list of GstRtpBinStream */
476 /* list of elements */
479 /* mapping of payload type to caps */
482 /* the pads of the session */
483 GstPad *recv_rtp_sink;
484 GstPad *recv_rtp_sink_ghost;
485 GstPad *recv_rtp_src;
486 GstPad *recv_rtcp_sink;
487 GstPad *recv_rtcp_sink_ghost;
489 GstPad *send_rtp_sink;
490 GstPad *send_rtp_sink_ghost;
491 GstPad *send_rtp_src_ghost;
492 GstPad *send_rtcp_src;
493 GstPad *send_rtcp_src_ghost;
496 /* Manages the RTP streams that come from one client and should therefore be
499 struct _GstRtpBinClient
501 /* the common CNAME for the streams */
510 /* find a session with the given id. Must be called with RTP_BIN_LOCK */
511 static GstRtpBinSession *
512 find_session_by_id (GstRtpBin * rtpbin, gint id)
516 for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
517 GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
525 /* find a session with the given request pad. Must be called with RTP_BIN_LOCK */
526 static GstRtpBinSession *
527 find_session_by_pad (GstRtpBin * rtpbin, GstPad * pad)
531 for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
532 GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
534 if ((sess->recv_rtp_sink_ghost == pad) ||
535 (sess->recv_rtcp_sink_ghost == pad) ||
536 (sess->send_rtp_sink_ghost == pad)
537 || (sess->send_rtcp_src_ghost == pad))
544 on_new_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
546 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC], 0,
551 on_ssrc_collision (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
553 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION], 0,
558 on_ssrc_validated (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
560 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
565 on_ssrc_active (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
567 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
572 on_ssrc_sdes (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
574 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES], 0,
579 on_bye_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
581 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC], 0,
586 on_bye_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
588 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
591 if (sess->bin->priv->autoremove)
592 g_signal_emit_by_name (sess->demux, "clear-ssrc", ssrc, NULL);
596 on_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
598 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT], 0,
601 if (sess->bin->priv->autoremove)
602 g_signal_emit_by_name (sess->demux, "clear-ssrc", ssrc, NULL);
606 on_sender_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
608 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
613 on_npt_stop (GstElement * jbuf, GstRtpBinStream * stream)
615 g_signal_emit (stream->bin, gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP], 0,
616 stream->session->id, stream->ssrc);
620 on_new_sender_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
622 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SENDER_SSRC], 0,
627 on_sender_ssrc_active (GstElement * session, guint32 ssrc,
628 GstRtpBinSession * sess)
630 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE],
634 /* must be called with the SESSION lock */
635 static GstRtpBinStream *
636 find_stream_by_ssrc (GstRtpBinSession * session, guint32 ssrc)
640 for (walk = session->streams; walk; walk = g_slist_next (walk)) {
641 GstRtpBinStream *stream = (GstRtpBinStream *) walk->data;
643 if (stream->ssrc == ssrc)
650 ssrc_demux_pad_removed (GstElement * element, guint ssrc, GstPad * pad,
651 GstRtpBinSession * session)
653 GstRtpBinStream *stream = NULL;
656 rtpbin = session->bin;
658 GST_RTP_BIN_LOCK (rtpbin);
660 GST_RTP_SESSION_LOCK (session);
661 if ((stream = find_stream_by_ssrc (session, ssrc)))
662 session->streams = g_slist_remove (session->streams, stream);
663 GST_RTP_SESSION_UNLOCK (session);
666 free_stream (stream, rtpbin);
668 GST_RTP_BIN_UNLOCK (rtpbin);
672 new_bundled_ssrc_pad_found (GstElement * element, guint ssrc, GstPad * pad,
673 GstRtpBinSession * session)
675 GValue result = G_VALUE_INIT;
676 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
677 guint session_id = 0;
678 GstRtpBinSession *target_session = NULL;
679 GstRtpBin *rtpbin = session->bin;
682 GstPad *recv_rtp_sink = NULL;
683 GstPad *recv_rtcp_sink = NULL;
684 GstPadLinkReturn ret;
686 GST_RTP_BIN_DYN_LOCK (rtpbin);
687 GST_DEBUG_OBJECT (rtpbin, "new bundled SSRC pad %08x, %s:%s", ssrc,
688 GST_DEBUG_PAD_NAME (pad));
690 g_value_init (&result, G_TYPE_UINT);
691 g_value_init (¶ms[0], GST_TYPE_ELEMENT);
692 g_value_set_object (¶ms[0], rtpbin);
693 g_value_init (¶ms[1], G_TYPE_UINT);
694 g_value_set_uint (¶ms[1], ssrc);
696 g_signal_emitv (params,
697 gst_rtp_bin_signals[SIGNAL_ON_BUNDLED_SSRC], 0, &result);
698 g_value_unset (¶ms[0]);
700 session_id = g_value_get_uint (&result);
701 if (session_id == 0) {
702 target_session = session;
704 target_session = find_session_by_id (rtpbin, (gint) session_id);
705 if (!target_session) {
706 target_session = create_session (rtpbin, session_id);
708 if (!target_session) {
709 /* create_session() warned already */
710 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
714 if (!target_session->recv_rtp_sink) {
715 recv_rtp_sink = complete_session_sink (rtpbin, target_session, FALSE);
718 if (!target_session->recv_rtp_src)
719 complete_session_receiver (rtpbin, target_session, session_id);
721 if (!target_session->recv_rtcp_sink) {
723 complete_session_rtcp (rtpbin, target_session, session_id, FALSE);
727 GST_DEBUG_OBJECT (rtpbin, "Assigning bundled ssrc %u to session %u", ssrc,
730 if (!recv_rtp_sink) {
732 gst_element_get_request_pad (target_session->rtp_funnel, "sink_%u");
735 if (!recv_rtcp_sink) {
737 gst_element_get_request_pad (target_session->rtcp_funnel, "sink_%u");
740 name = g_strdup_printf ("src_%u", ssrc);
741 src_pad = gst_element_get_static_pad (element, name);
742 ret = gst_pad_link (src_pad, recv_rtp_sink);
744 gst_object_unref (src_pad);
745 gst_object_unref (recv_rtp_sink);
746 if (ret != GST_PAD_LINK_OK) {
748 ("rtpbin: failed to link bundle demuxer to receive rtp funnel for session %u",
752 name = g_strdup_printf ("rtcp_src_%u", ssrc);
753 src_pad = gst_element_get_static_pad (element, name);
754 gst_pad_link (src_pad, recv_rtcp_sink);
756 gst_object_unref (src_pad);
757 gst_object_unref (recv_rtcp_sink);
758 if (ret != GST_PAD_LINK_OK) {
760 ("rtpbin: failed to link bundle demuxer to receive rtcp sink pad for session %u",
764 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
767 /* create a session with the given id. Must be called with RTP_BIN_LOCK */
768 static GstRtpBinSession *
769 create_session (GstRtpBin * rtpbin, gint id)
771 GstRtpBinSession *sess;
772 GstElement *session, *demux;
773 GstElement *storage = NULL;
776 if (!(session = gst_element_factory_make ("rtpsession", NULL)))
779 if (!(demux = gst_element_factory_make ("rtpssrcdemux", NULL)))
782 if (!(storage = gst_element_factory_make ("rtpstorage", NULL)))
785 g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_STORAGE], 0, storage,
788 sess = g_new0 (GstRtpBinSession, 1);
789 g_mutex_init (&sess->lock);
792 sess->session = session;
794 sess->storage = storage;
796 sess->rtp_funnel = gst_element_factory_make ("funnel", NULL);
797 sess->rtcp_funnel = gst_element_factory_make ("funnel", NULL);
799 sess->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
800 (GDestroyNotify) gst_caps_unref);
801 rtpbin->sessions = g_slist_prepend (rtpbin->sessions, sess);
803 /* configure SDES items */
804 GST_OBJECT_LOCK (rtpbin);
805 g_object_set (session, "sdes", rtpbin->sdes, "rtp-profile",
806 rtpbin->rtp_profile, "rtcp-sync-send-time", rtpbin->rtcp_sync_send_time,
808 if (rtpbin->use_pipeline_clock)
809 g_object_set (session, "use-pipeline-clock", rtpbin->use_pipeline_clock,
812 g_object_set (session, "ntp-time-source", rtpbin->ntp_time_source, NULL);
814 g_object_set (session, "max-dropout-time", rtpbin->max_dropout_time,
815 "max-misorder-time", rtpbin->max_misorder_time, NULL);
816 GST_OBJECT_UNLOCK (rtpbin);
818 /* provide clock_rate to the session manager when needed */
819 g_signal_connect (session, "request-pt-map",
820 (GCallback) pt_map_requested, sess);
822 g_signal_connect (sess->session, "on-new-ssrc",
823 (GCallback) on_new_ssrc, sess);
824 g_signal_connect (sess->session, "on-ssrc-collision",
825 (GCallback) on_ssrc_collision, sess);
826 g_signal_connect (sess->session, "on-ssrc-validated",
827 (GCallback) on_ssrc_validated, sess);
828 g_signal_connect (sess->session, "on-ssrc-active",
829 (GCallback) on_ssrc_active, sess);
830 g_signal_connect (sess->session, "on-ssrc-sdes",
831 (GCallback) on_ssrc_sdes, sess);
832 g_signal_connect (sess->session, "on-bye-ssrc",
833 (GCallback) on_bye_ssrc, sess);
834 g_signal_connect (sess->session, "on-bye-timeout",
835 (GCallback) on_bye_timeout, sess);
836 g_signal_connect (sess->session, "on-timeout", (GCallback) on_timeout, sess);
837 g_signal_connect (sess->session, "on-sender-timeout",
838 (GCallback) on_sender_timeout, sess);
839 g_signal_connect (sess->session, "on-new-sender-ssrc",
840 (GCallback) on_new_sender_ssrc, sess);
841 g_signal_connect (sess->session, "on-sender-ssrc-active",
842 (GCallback) on_sender_ssrc_active, sess);
844 gst_bin_add (GST_BIN_CAST (rtpbin), session);
845 gst_bin_add (GST_BIN_CAST (rtpbin), demux);
846 gst_bin_add (GST_BIN_CAST (rtpbin), sess->rtp_funnel);
847 gst_bin_add (GST_BIN_CAST (rtpbin), sess->rtcp_funnel);
848 gst_bin_add (GST_BIN_CAST (rtpbin), storage);
850 GST_OBJECT_LOCK (rtpbin);
851 target = GST_STATE_TARGET (rtpbin);
852 GST_OBJECT_UNLOCK (rtpbin);
854 /* change state only to what's needed */
855 gst_element_set_state (demux, target);
856 gst_element_set_state (session, target);
857 gst_element_set_state (sess->rtp_funnel, target);
858 gst_element_set_state (sess->rtcp_funnel, target);
859 gst_element_set_state (storage, target);
866 g_warning ("rtpbin: could not create rtpsession element");
871 gst_object_unref (session);
872 g_warning ("rtpbin: could not create rtpssrcdemux element");
877 gst_object_unref (session);
878 gst_object_unref (demux);
879 g_warning ("rtpbin: could not create rtpstorage element");
885 bin_manage_element (GstRtpBin * bin, GstElement * element)
887 GstRtpBinPrivate *priv = bin->priv;
889 if (g_list_find (priv->elements, element)) {
890 GST_DEBUG_OBJECT (bin, "requested element %p already in bin", element);
892 GST_DEBUG_OBJECT (bin, "adding requested element %p", element);
894 if (g_object_is_floating (element))
895 element = gst_object_ref_sink (element);
897 if (!gst_bin_add (GST_BIN_CAST (bin), element))
899 if (!gst_element_sync_state_with_parent (element))
900 GST_WARNING_OBJECT (bin, "unable to sync element state with rtpbin");
902 /* we add the element multiple times, each we need an equal number of
903 * removes to really remove the element from the bin */
904 priv->elements = g_list_prepend (priv->elements, element);
911 GST_WARNING_OBJECT (bin, "unable to add element");
912 gst_object_unref (element);
918 remove_bin_element (GstElement * element, GstRtpBin * bin)
920 GstRtpBinPrivate *priv = bin->priv;
923 find = g_list_find (priv->elements, element);
925 priv->elements = g_list_delete_link (priv->elements, find);
927 if (!g_list_find (priv->elements, element)) {
928 gst_element_set_locked_state (element, TRUE);
929 gst_bin_remove (GST_BIN_CAST (bin), element);
930 gst_element_set_state (element, GST_STATE_NULL);
933 gst_object_unref (element);
937 /* called with RTP_BIN_LOCK */
939 free_session (GstRtpBinSession * sess, GstRtpBin * bin)
941 GST_DEBUG_OBJECT (bin, "freeing session %p", sess);
943 gst_element_set_locked_state (sess->demux, TRUE);
944 gst_element_set_locked_state (sess->session, TRUE);
946 gst_element_set_state (sess->demux, GST_STATE_NULL);
947 gst_element_set_state (sess->session, GST_STATE_NULL);
949 remove_recv_rtp (bin, sess);
950 remove_recv_rtcp (bin, sess);
951 remove_send_rtp (bin, sess);
952 remove_rtcp (bin, sess);
954 gst_bin_remove (GST_BIN_CAST (bin), sess->session);
955 gst_bin_remove (GST_BIN_CAST (bin), sess->demux);
957 g_slist_foreach (sess->elements, (GFunc) remove_bin_element, bin);
958 g_slist_free (sess->elements);
960 g_slist_foreach (sess->streams, (GFunc) free_stream, bin);
961 g_slist_free (sess->streams);
963 g_mutex_clear (&sess->lock);
964 g_hash_table_destroy (sess->ptmap);
969 /* get the payload type caps for the specific payload @pt in @session */
971 get_pt_map (GstRtpBinSession * session, guint pt)
973 GstCaps *caps = NULL;
976 GValue args[3] = { {0}, {0}, {0} };
978 GST_DEBUG ("searching pt %u in cache", pt);
980 GST_RTP_SESSION_LOCK (session);
982 /* first look in the cache */
983 caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
991 GST_DEBUG ("emiting signal for pt %u in session %u", pt, session->id);
993 /* not in cache, send signal to request caps */
994 g_value_init (&args[0], GST_TYPE_ELEMENT);
995 g_value_set_object (&args[0], bin);
996 g_value_init (&args[1], G_TYPE_UINT);
997 g_value_set_uint (&args[1], session->id);
998 g_value_init (&args[2], G_TYPE_UINT);
999 g_value_set_uint (&args[2], pt);
1001 g_value_init (&ret, GST_TYPE_CAPS);
1002 g_value_set_boxed (&ret, NULL);
1004 GST_RTP_SESSION_UNLOCK (session);
1006 g_signal_emitv (args, gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP], 0, &ret);
1008 GST_RTP_SESSION_LOCK (session);
1010 g_value_unset (&args[0]);
1011 g_value_unset (&args[1]);
1012 g_value_unset (&args[2]);
1014 /* look in the cache again because we let the lock go */
1015 caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
1017 gst_caps_ref (caps);
1018 g_value_unset (&ret);
1022 caps = (GstCaps *) g_value_dup_boxed (&ret);
1023 g_value_unset (&ret);
1027 GST_DEBUG ("caching pt %u as %" GST_PTR_FORMAT, pt, caps);
1029 /* store in cache, take additional ref */
1030 g_hash_table_insert (session->ptmap, GINT_TO_POINTER (pt),
1031 gst_caps_ref (caps));
1034 GST_RTP_SESSION_UNLOCK (session);
1041 GST_RTP_SESSION_UNLOCK (session);
1042 GST_DEBUG ("no pt map could be obtained");
1048 return_true (gpointer key, gpointer value, gpointer user_data)
1054 gst_rtp_bin_reset_sync (GstRtpBin * rtpbin)
1056 GSList *clients, *streams;
1058 GST_DEBUG_OBJECT (rtpbin, "Reset sync on all clients");
1060 GST_RTP_BIN_LOCK (rtpbin);
1061 for (clients = rtpbin->clients; clients; clients = g_slist_next (clients)) {
1062 GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
1064 /* reset sync on all streams for this client */
1065 for (streams = client->streams; streams; streams = g_slist_next (streams)) {
1066 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1068 /* make use require a new SR packet for this stream before we attempt new
1070 stream->have_sync = FALSE;
1071 stream->rt_delta = 0;
1072 stream->rtp_delta = 0;
1073 stream->clock_base = -100 * GST_SECOND;
1076 GST_RTP_BIN_UNLOCK (rtpbin);
1080 gst_rtp_bin_clear_pt_map (GstRtpBin * bin)
1082 GSList *sessions, *streams;
1084 GST_RTP_BIN_LOCK (bin);
1085 GST_DEBUG_OBJECT (bin, "clearing pt map");
1086 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1087 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
1089 GST_DEBUG_OBJECT (bin, "clearing session %p", session);
1090 g_signal_emit_by_name (session->session, "clear-pt-map", NULL);
1092 GST_RTP_SESSION_LOCK (session);
1093 g_hash_table_foreach_remove (session->ptmap, return_true, NULL);
1095 for (streams = session->streams; streams; streams = g_slist_next (streams)) {
1096 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1098 GST_DEBUG_OBJECT (bin, "clearing stream %p", stream);
1099 g_signal_emit_by_name (stream->buffer, "clear-pt-map", NULL);
1101 g_signal_emit_by_name (stream->demux, "clear-pt-map", NULL);
1103 GST_RTP_SESSION_UNLOCK (session);
1105 GST_RTP_BIN_UNLOCK (bin);
1107 /* reset sync too */
1108 gst_rtp_bin_reset_sync (bin);
1112 gst_rtp_bin_get_session (GstRtpBin * bin, guint session_id)
1114 GstRtpBinSession *session;
1115 GstElement *ret = NULL;
1117 GST_RTP_BIN_LOCK (bin);
1118 GST_DEBUG_OBJECT (bin, "retrieving GstRtpSession, index: %u", session_id);
1119 session = find_session_by_id (bin, (gint) session_id);
1121 ret = gst_object_ref (session->session);
1123 GST_RTP_BIN_UNLOCK (bin);
1129 gst_rtp_bin_get_internal_session (GstRtpBin * bin, guint session_id)
1131 RTPSession *internal_session = NULL;
1132 GstRtpBinSession *session;
1134 GST_RTP_BIN_LOCK (bin);
1135 GST_DEBUG_OBJECT (bin, "retrieving internal RTPSession object, index: %u",
1137 session = find_session_by_id (bin, (gint) session_id);
1139 g_object_get (session->session, "internal-session", &internal_session,
1142 GST_RTP_BIN_UNLOCK (bin);
1144 return internal_session;
1148 gst_rtp_bin_get_storage (GstRtpBin * bin, guint session_id)
1150 GstRtpBinSession *session;
1151 GstElement *res = NULL;
1153 GST_RTP_BIN_LOCK (bin);
1154 GST_DEBUG_OBJECT (bin, "retrieving internal storage object, index: %u",
1156 session = find_session_by_id (bin, (gint) session_id);
1157 if (session && session->storage) {
1158 res = gst_object_ref (session->storage);
1160 GST_RTP_BIN_UNLOCK (bin);
1166 gst_rtp_bin_get_internal_storage (GstRtpBin * bin, guint session_id)
1168 GObject *internal_storage = NULL;
1169 GstRtpBinSession *session;
1171 GST_RTP_BIN_LOCK (bin);
1172 GST_DEBUG_OBJECT (bin, "retrieving internal storage object, index: %u",
1174 session = find_session_by_id (bin, (gint) session_id);
1175 if (session && session->storage) {
1176 g_object_get (session->storage, "internal-storage", &internal_storage,
1179 GST_RTP_BIN_UNLOCK (bin);
1181 return internal_storage;
1185 gst_rtp_bin_request_encoder (GstRtpBin * bin, guint session_id)
1187 GST_DEBUG_OBJECT (bin, "return NULL encoder");
1192 gst_rtp_bin_request_decoder (GstRtpBin * bin, guint session_id)
1194 GST_DEBUG_OBJECT (bin, "return NULL decoder");
1199 gst_rtp_bin_propagate_property_to_jitterbuffer (GstRtpBin * bin,
1200 const gchar * name, const GValue * value)
1202 GSList *sessions, *streams;
1204 GST_RTP_BIN_LOCK (bin);
1205 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1206 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
1208 GST_RTP_SESSION_LOCK (session);
1209 for (streams = session->streams; streams; streams = g_slist_next (streams)) {
1210 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1212 g_object_set_property (G_OBJECT (stream->buffer), name, value);
1214 GST_RTP_SESSION_UNLOCK (session);
1216 GST_RTP_BIN_UNLOCK (bin);
1220 gst_rtp_bin_propagate_property_to_session (GstRtpBin * bin,
1221 const gchar * name, const GValue * value)
1225 GST_RTP_BIN_LOCK (bin);
1226 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1227 GstRtpBinSession *sess = (GstRtpBinSession *) sessions->data;
1229 g_object_set_property (G_OBJECT (sess->session), name, value);
1231 GST_RTP_BIN_UNLOCK (bin);
1234 /* get a client with the given SDES name. Must be called with RTP_BIN_LOCK */
1235 static GstRtpBinClient *
1236 get_client (GstRtpBin * bin, guint8 len, guint8 * data, gboolean * created)
1238 GstRtpBinClient *result = NULL;
1241 for (walk = bin->clients; walk; walk = g_slist_next (walk)) {
1242 GstRtpBinClient *client = (GstRtpBinClient *) walk->data;
1244 if (len != client->cname_len)
1247 if (!strncmp ((gchar *) data, client->cname, client->cname_len)) {
1248 GST_DEBUG_OBJECT (bin, "found existing client %p with CNAME %s", client,
1255 /* nothing found, create one */
1256 if (result == NULL) {
1257 result = g_new0 (GstRtpBinClient, 1);
1258 result->cname = g_strndup ((gchar *) data, len);
1259 result->cname_len = len;
1260 bin->clients = g_slist_prepend (bin->clients, result);
1261 GST_DEBUG_OBJECT (bin, "created new client %p with CNAME %s", result,
1268 free_client (GstRtpBinClient * client, GstRtpBin * bin)
1270 GST_DEBUG_OBJECT (bin, "freeing client %p", client);
1271 g_slist_free (client->streams);
1272 g_free (client->cname);
1277 get_current_times (GstRtpBin * bin, GstClockTime * running_time,
1278 guint64 * ntpnstime)
1282 GstClockTime base_time, rt, clock_time;
1284 GST_OBJECT_LOCK (bin);
1285 if ((clock = GST_ELEMENT_CLOCK (bin))) {
1286 base_time = GST_ELEMENT_CAST (bin)->base_time;
1287 gst_object_ref (clock);
1288 GST_OBJECT_UNLOCK (bin);
1290 /* get current clock time and convert to running time */
1291 clock_time = gst_clock_get_time (clock);
1292 rt = clock_time - base_time;
1294 if (bin->use_pipeline_clock) {
1296 /* add constant to convert from 1970 based time to 1900 based time */
1297 ntpns += (2208988800LL * GST_SECOND);
1299 switch (bin->ntp_time_source) {
1300 case GST_RTP_NTP_TIME_SOURCE_NTP:
1301 case GST_RTP_NTP_TIME_SOURCE_UNIX:{
1304 /* get current NTP time */
1305 g_get_current_time (¤t);
1306 ntpns = GST_TIMEVAL_TO_TIME (current);
1308 /* add constant to convert from 1970 based time to 1900 based time */
1309 if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
1310 ntpns += (2208988800LL * GST_SECOND);
1313 case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
1316 case GST_RTP_NTP_TIME_SOURCE_CLOCK_TIME:
1320 ntpns = -1; /* Fix uninited compiler warning */
1321 g_assert_not_reached ();
1326 gst_object_unref (clock);
1328 GST_OBJECT_UNLOCK (bin);
1339 stream_set_ts_offset (GstRtpBin * bin, GstRtpBinStream * stream,
1340 gint64 ts_offset, gint64 max_ts_offset, gint64 min_ts_offset,
1341 gboolean allow_positive_ts_offset)
1343 gint64 prev_ts_offset;
1345 g_object_get (stream->buffer, "ts-offset", &prev_ts_offset, NULL);
1347 /* delta changed, see how much */
1348 if (prev_ts_offset != ts_offset) {
1351 diff = prev_ts_offset - ts_offset;
1353 GST_DEBUG_OBJECT (bin,
1354 "ts-offset %" G_GINT64_FORMAT ", prev %" G_GINT64_FORMAT
1355 ", diff: %" G_GINT64_FORMAT, ts_offset, prev_ts_offset, diff);
1357 /* ignore minor offsets */
1358 if (ABS (diff) < min_ts_offset) {
1359 GST_DEBUG_OBJECT (bin, "offset too small, ignoring");
1363 /* sanity check offset */
1364 if (max_ts_offset > 0) {
1365 if (ts_offset > 0 && !allow_positive_ts_offset) {
1366 GST_DEBUG_OBJECT (bin,
1367 "offset is positive (clocks are out of sync), ignoring");
1370 if (ABS (ts_offset) > max_ts_offset) {
1371 GST_DEBUG_OBJECT (bin, "offset too large, ignoring");
1376 g_object_set (stream->buffer, "ts-offset", ts_offset, NULL);
1378 GST_DEBUG_OBJECT (bin, "stream SSRC %08x, delta %" G_GINT64_FORMAT,
1379 stream->ssrc, ts_offset);
1383 gst_rtp_bin_send_sync_event (GstRtpBinStream * stream)
1385 if (stream->bin->send_sync_event) {
1389 GST_DEBUG_OBJECT (stream->bin,
1390 "sending GstRTCPSRReceived event downstream");
1392 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
1393 gst_structure_new_empty ("GstRTCPSRReceived"));
1395 srcpad = gst_element_get_static_pad (stream->buffer, "src");
1396 gst_pad_push_event (srcpad, event);
1397 gst_object_unref (srcpad);
1401 /* associate a stream to the given CNAME. This will make sure all streams for
1402 * that CNAME are synchronized together.
1403 * Must be called with GST_RTP_BIN_LOCK */
1405 gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len,
1406 guint8 * data, guint64 ntptime, guint64 last_extrtptime,
1407 guint64 base_rtptime, guint64 base_time, guint clock_rate,
1408 gint64 rtp_clock_base)
1410 GstRtpBinClient *client;
1413 GstClockTime running_time, running_time_rtp;
1416 /* first find or create the CNAME */
1417 client = get_client (bin, len, data, &created);
1419 /* find stream in the client */
1420 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1421 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1423 if (ostream == stream)
1426 /* not found, add it to the list */
1428 GST_DEBUG_OBJECT (bin,
1429 "new association of SSRC %08x with client %p with CNAME %s",
1430 stream->ssrc, client, client->cname);
1431 client->streams = g_slist_prepend (client->streams, stream);
1434 GST_DEBUG_OBJECT (bin,
1435 "found association of SSRC %08x with client %p with CNAME %s",
1436 stream->ssrc, client, client->cname);
1439 if (!GST_CLOCK_TIME_IS_VALID (last_extrtptime)) {
1440 GST_DEBUG_OBJECT (bin, "invalidated sync data");
1441 if (bin->rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) {
1442 /* we don't need that data, so carry on,
1443 * but make some values look saner */
1444 last_extrtptime = base_rtptime;
1446 /* nothing we can do with this data in this case */
1447 GST_DEBUG_OBJECT (bin, "bailing out");
1452 /* Take the extended rtptime we found in the SR packet and map it to the
1453 * local rtptime. The local rtp time is used to construct timestamps on the
1454 * buffers so we will calculate what running_time corresponds to the RTP
1455 * timestamp in the SR packet. */
1456 running_time_rtp = last_extrtptime - base_rtptime;
1458 GST_DEBUG_OBJECT (bin,
1459 "base %" G_GUINT64_FORMAT ", extrtptime %" G_GUINT64_FORMAT
1460 ", local RTP %" G_GUINT64_FORMAT ", clock-rate %d, "
1461 "clock-base %" G_GINT64_FORMAT, base_rtptime,
1462 last_extrtptime, running_time_rtp, clock_rate, rtp_clock_base);
1464 /* calculate local RTP time in gstreamer timestamp, we essentially perform the
1465 * same conversion that a jitterbuffer would use to convert an rtp timestamp
1466 * into a corresponding gstreamer timestamp. Note that the base_time also
1467 * contains the drift between sender and receiver. */
1469 gst_util_uint64_scale_int (running_time_rtp, GST_SECOND, clock_rate);
1470 running_time += base_time;
1472 /* convert ntptime to nanoseconds */
1473 ntpnstime = gst_util_uint64_scale (ntptime, GST_SECOND,
1474 (G_GINT64_CONSTANT (1) << 32));
1476 stream->have_sync = TRUE;
1478 GST_DEBUG_OBJECT (bin,
1479 "SR RTP running time %" G_GUINT64_FORMAT ", SR NTP %" G_GUINT64_FORMAT,
1480 running_time, ntpnstime);
1482 /* recalc inter stream playout offset, but only if there is more than one
1483 * stream or we're doing NTP sync. */
1484 if (bin->ntp_sync) {
1485 gint64 ntpdiff, rtdiff;
1486 guint64 local_ntpnstime;
1487 GstClockTime local_running_time;
1489 /* For NTP sync we need to first get a snapshot of running_time and NTP
1490 * time. We know at what running_time we play a certain RTP time, we also
1491 * calculated when we would play the RTP time in the SR packet. Now we need
1492 * to know how the running_time and the NTP time relate to eachother. */
1493 get_current_times (bin, &local_running_time, &local_ntpnstime);
1495 /* see how far away the NTP time is. This is the difference between the
1496 * current NTP time and the NTP time in the last SR packet. */
1497 ntpdiff = local_ntpnstime - ntpnstime;
1498 /* see how far away the running_time is. This is the difference between the
1499 * current running_time and the running_time of the RTP timestamp in the
1500 * last SR packet. */
1501 rtdiff = local_running_time - running_time;
1503 GST_DEBUG_OBJECT (bin,
1504 "local NTP time %" G_GUINT64_FORMAT ", SR NTP time %" G_GUINT64_FORMAT,
1505 local_ntpnstime, ntpnstime);
1506 GST_DEBUG_OBJECT (bin,
1507 "local running time %" G_GUINT64_FORMAT ", SR RTP running time %"
1508 G_GUINT64_FORMAT, local_running_time, running_time);
1509 GST_DEBUG_OBJECT (bin,
1510 "NTP diff %" G_GINT64_FORMAT ", RT diff %" G_GINT64_FORMAT, ntpdiff,
1513 /* combine to get the final diff to apply to the running_time */
1514 stream->rt_delta = rtdiff - ntpdiff;
1516 stream_set_ts_offset (bin, stream, stream->rt_delta, bin->max_ts_offset,
1519 gint64 min, rtp_min, clock_base = stream->clock_base;
1520 gboolean all_sync, use_rtp;
1521 gboolean rtcp_sync = g_atomic_int_get (&bin->rtcp_sync);
1523 /* calculate delta between server and receiver. ntpnstime is created by
1524 * converting the ntptime in the last SR packet to a gstreamer timestamp. This
1525 * delta expresses the difference to our timeline and the server timeline. The
1526 * difference in itself doesn't mean much but we can combine the delta of
1527 * multiple streams to create a stream specific offset. */
1528 stream->rt_delta = ntpnstime - running_time;
1530 /* calculate the min of all deltas, ignoring streams that did not yet have a
1531 * valid rt_delta because we did not yet receive an SR packet for those
1533 * We calculate the mininum because we would like to only apply positive
1534 * offsets to streams, delaying their playback instead of trying to speed up
1535 * other streams (which might be imposible when we have to create negative
1537 * The stream that has the smallest diff is selected as the reference stream,
1538 * all other streams will have a positive offset to this difference. */
1540 /* some alternative setting allow ignoring RTCP as much as possible,
1541 * for servers generating bogus ntp timeline */
1542 min = rtp_min = G_MAXINT64;
1544 if (rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) {
1548 /* signed version for convienience */
1549 clock_base = base_rtptime;
1550 /* deal with possible wrap-around */
1551 ext_base = base_rtptime;
1552 rtp_clock_base = gst_rtp_buffer_ext_timestamp (&ext_base, rtp_clock_base);
1553 /* sanity check; base rtp and provided clock_base should be close */
1554 if (rtp_clock_base >= clock_base) {
1555 if (rtp_clock_base - clock_base < 10 * clock_rate) {
1556 rtp_clock_base = base_time +
1557 gst_util_uint64_scale_int (rtp_clock_base - clock_base,
1558 GST_SECOND, clock_rate);
1563 if (clock_base - rtp_clock_base < 10 * clock_rate) {
1564 rtp_clock_base = base_time -
1565 gst_util_uint64_scale_int (clock_base - rtp_clock_base,
1566 GST_SECOND, clock_rate);
1571 /* warn and bail for clarity out if no sane values */
1573 GST_WARNING_OBJECT (bin, "unable to sync to provided rtptime");
1576 /* store to track changes */
1577 clock_base = rtp_clock_base;
1578 /* generate a fake as before,
1579 * now equating rtptime obtained from RTP-Info,
1580 * where the large time represent the otherwise irrelevant npt/ntp time */
1581 stream->rtp_delta = (GST_SECOND << 28) - rtp_clock_base;
1583 clock_base = rtp_clock_base;
1587 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1588 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1590 if (!ostream->have_sync) {
1595 /* change in current stream's base from previously init'ed value
1596 * leads to reset of all stream's base */
1597 if (stream != ostream && stream->clock_base >= 0 &&
1598 (stream->clock_base != clock_base)) {
1599 GST_DEBUG_OBJECT (bin, "reset upon clock base change");
1600 ostream->clock_base = -100 * GST_SECOND;
1601 ostream->rtp_delta = 0;
1604 if (ostream->rt_delta < min)
1605 min = ostream->rt_delta;
1606 if (ostream->rtp_delta < rtp_min)
1607 rtp_min = ostream->rtp_delta;
1610 /* arrange to re-sync for each stream upon significant change,
1612 all_sync = all_sync && (stream->clock_base == clock_base);
1613 stream->clock_base = clock_base;
1615 /* may need init performed above later on, but nothing more to do now */
1616 if (client->nstreams <= 1)
1619 GST_DEBUG_OBJECT (bin, "client %p min delta %" G_GINT64_FORMAT
1620 " all sync %d", client, min, all_sync);
1621 GST_DEBUG_OBJECT (bin, "rtcp sync mode %d, use_rtp %d", rtcp_sync, use_rtp);
1623 switch (rtcp_sync) {
1624 case GST_RTP_BIN_RTCP_SYNC_RTP:
1627 GST_DEBUG_OBJECT (bin, "using rtp generated reports; "
1628 "client %p min rtp delta %" G_GINT64_FORMAT, client, rtp_min);
1630 case GST_RTP_BIN_RTCP_SYNC_INITIAL:
1631 /* if all have been synced already, do not bother further */
1633 GST_DEBUG_OBJECT (bin, "all streams already synced; done");
1641 /* bail out if we adjusted recently enough */
1642 if (all_sync && (ntpnstime - bin->priv->last_ntpnstime) <
1643 bin->rtcp_sync_interval * GST_MSECOND) {
1644 GST_DEBUG_OBJECT (bin, "discarding RTCP sender packet for sync; "
1645 "previous sender info too recent "
1646 "(previous NTP %" G_GUINT64_FORMAT ")", bin->priv->last_ntpnstime);
1649 bin->priv->last_ntpnstime = ntpnstime;
1651 /* calculate offsets for each stream */
1652 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1653 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1656 /* ignore streams for which we didn't receive an SR packet yet, we
1657 * can't synchronize them yet. We can however sync other streams just
1659 if (!ostream->have_sync)
1662 /* calculate offset to our reference stream, this should always give a
1663 * positive number. */
1665 ts_offset = ostream->rtp_delta - rtp_min;
1667 ts_offset = ostream->rt_delta - min;
1669 stream_set_ts_offset (bin, ostream, ts_offset, bin->max_ts_offset,
1670 MIN_TS_OFFSET, TRUE);
1673 gst_rtp_bin_send_sync_event (stream);
1678 #define GST_RTCP_BUFFER_FOR_PACKETS(b,buffer,packet) \
1679 for ((b) = gst_rtcp_buffer_get_first_packet ((buffer), (packet)); (b); \
1680 (b) = gst_rtcp_packet_move_to_next ((packet)))
1682 #define GST_RTCP_SDES_FOR_ITEMS(b,packet) \
1683 for ((b) = gst_rtcp_packet_sdes_first_item ((packet)); (b); \
1684 (b) = gst_rtcp_packet_sdes_next_item ((packet)))
1686 #define GST_RTCP_SDES_FOR_ENTRIES(b,packet) \
1687 for ((b) = gst_rtcp_packet_sdes_first_entry ((packet)); (b); \
1688 (b) = gst_rtcp_packet_sdes_next_entry ((packet)))
1691 gst_rtp_bin_handle_sync (GstElement * jitterbuffer, GstStructure * s,
1692 GstRtpBinStream * stream)
1695 GstRTCPPacket packet;
1698 gboolean have_sr, have_sdes;
1700 guint64 base_rtptime;
1706 GstRTCPBuffer rtcp = { NULL, };
1710 GST_DEBUG_OBJECT (bin, "sync handler called");
1712 /* get the last relation between the rtp timestamps and the gstreamer
1713 * timestamps. We get this info directly from the jitterbuffer which
1714 * constructs gstreamer timestamps from rtp timestamps and so it know exactly
1715 * what the current situation is. */
1717 g_value_get_uint64 (gst_structure_get_value (s, "base-rtptime"));
1718 base_time = g_value_get_uint64 (gst_structure_get_value (s, "base-time"));
1719 clock_rate = g_value_get_uint (gst_structure_get_value (s, "clock-rate"));
1720 clock_base = g_value_get_uint64 (gst_structure_get_value (s, "clock-base"));
1722 g_value_get_uint64 (gst_structure_get_value (s, "sr-ext-rtptime"));
1723 buffer = gst_value_get_buffer (gst_structure_get_value (s, "sr-buffer"));
1728 gst_rtcp_buffer_map (buffer, GST_MAP_READ, &rtcp);
1730 GST_RTCP_BUFFER_FOR_PACKETS (more, &rtcp, &packet) {
1731 /* first packet must be SR or RR or else the validate would have failed */
1732 switch (gst_rtcp_packet_get_type (&packet)) {
1733 case GST_RTCP_TYPE_SR:
1734 /* only parse first. There is only supposed to be one SR in the packet
1735 * but we will deal with malformed packets gracefully */
1738 /* get NTP and RTP times */
1739 gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, NULL,
1742 GST_DEBUG_OBJECT (bin, "received sync packet from SSRC %08x", ssrc);
1743 /* ignore SR that is not ours */
1744 if (ssrc != stream->ssrc)
1749 case GST_RTCP_TYPE_SDES:
1751 gboolean more_items, more_entries;
1753 /* only deal with first SDES, there is only supposed to be one SDES in
1754 * the RTCP packet but we deal with bad packets gracefully. Also bail
1755 * out if we have not seen an SR item yet. */
1756 if (have_sdes || !have_sr)
1759 GST_RTCP_SDES_FOR_ITEMS (more_items, &packet) {
1760 /* skip items that are not about the SSRC of the sender */
1761 if (gst_rtcp_packet_sdes_get_ssrc (&packet) != ssrc)
1764 /* find the CNAME entry */
1765 GST_RTCP_SDES_FOR_ENTRIES (more_entries, &packet) {
1766 GstRTCPSDESType type;
1770 gst_rtcp_packet_sdes_get_entry (&packet, &type, &len, &data);
1772 if (type == GST_RTCP_SDES_CNAME) {
1773 GST_RTP_BIN_LOCK (bin);
1774 /* associate the stream to CNAME */
1775 gst_rtp_bin_associate (bin, stream, len, data,
1776 ntptime, extrtptime, base_rtptime, base_time, clock_rate,
1778 GST_RTP_BIN_UNLOCK (bin);
1786 /* we can ignore these packets */
1790 gst_rtcp_buffer_unmap (&rtcp);
1793 /* create a new stream with @ssrc in @session. Must be called with
1794 * RTP_SESSION_LOCK. */
1795 static GstRtpBinStream *
1796 create_stream (GstRtpBinSession * session, guint32 ssrc)
1798 GstElement *buffer, *demux = NULL;
1799 GstRtpBinStream *stream;
1803 rtpbin = session->bin;
1805 if (g_slist_length (session->streams) >= rtpbin->max_streams)
1808 if (!(buffer = gst_element_factory_make ("rtpjitterbuffer", NULL)))
1809 goto no_jitterbuffer;
1811 if (!rtpbin->ignore_pt) {
1812 if (!(demux = gst_element_factory_make ("rtpptdemux", NULL)))
1816 stream = g_new0 (GstRtpBinStream, 1);
1817 stream->ssrc = ssrc;
1818 stream->bin = rtpbin;
1819 stream->session = session;
1820 stream->buffer = buffer;
1821 stream->demux = demux;
1823 stream->have_sync = FALSE;
1824 stream->rt_delta = 0;
1825 stream->rtp_delta = 0;
1826 stream->percent = 100;
1827 stream->clock_base = -100 * GST_SECOND;
1828 session->streams = g_slist_prepend (session->streams, stream);
1830 /* provide clock_rate to the jitterbuffer when needed */
1831 stream->buffer_ptreq_sig = g_signal_connect (buffer, "request-pt-map",
1832 (GCallback) pt_map_requested, session);
1833 stream->buffer_ntpstop_sig = g_signal_connect (buffer, "on-npt-stop",
1834 (GCallback) on_npt_stop, stream);
1836 g_object_set_data (G_OBJECT (buffer), "GstRTPBin.session", session);
1837 g_object_set_data (G_OBJECT (buffer), "GstRTPBin.stream", stream);
1839 /* configure latency and packet lost */
1840 g_object_set (buffer, "latency", rtpbin->latency_ms, NULL);
1841 g_object_set (buffer, "drop-on-latency", rtpbin->drop_on_latency, NULL);
1842 g_object_set (buffer, "do-lost", rtpbin->do_lost, NULL);
1843 g_object_set (buffer, "mode", rtpbin->buffer_mode, NULL);
1844 g_object_set (buffer, "do-retransmission", rtpbin->do_retransmission, NULL);
1845 g_object_set (buffer, "max-rtcp-rtp-time-diff",
1846 rtpbin->max_rtcp_rtp_time_diff, NULL);
1847 g_object_set (buffer, "max-dropout-time", rtpbin->max_dropout_time,
1848 "max-misorder-time", rtpbin->max_misorder_time, NULL);
1849 g_object_set (buffer, "rfc7273-sync", rtpbin->rfc7273_sync, NULL);
1850 g_object_set (buffer, "max-ts-offset-adjustment",
1851 rtpbin->max_ts_offset_adjustment, NULL);
1853 g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER], 0,
1854 buffer, session->id, ssrc);
1856 if (!rtpbin->ignore_pt)
1857 gst_bin_add (GST_BIN_CAST (rtpbin), demux);
1858 gst_bin_add (GST_BIN_CAST (rtpbin), buffer);
1862 gst_element_link_pads_full (buffer, "src", demux, "sink",
1863 GST_PAD_LINK_CHECK_NOTHING);
1865 if (rtpbin->buffering) {
1868 GST_INFO_OBJECT (rtpbin,
1869 "bin is buffering, set jitterbuffer as not active");
1870 g_signal_emit_by_name (buffer, "set-active", FALSE, (gint64) 0, &last_out);
1874 GST_OBJECT_LOCK (rtpbin);
1875 target = GST_STATE_TARGET (rtpbin);
1876 GST_OBJECT_UNLOCK (rtpbin);
1878 /* from sink to source */
1880 gst_element_set_state (demux, target);
1882 gst_element_set_state (buffer, target);
1889 GST_WARNING_OBJECT (rtpbin, "stream exeeds maximum (%d)",
1890 rtpbin->max_streams);
1895 g_warning ("rtpbin: could not create rtpjitterbuffer element");
1900 gst_object_unref (buffer);
1901 g_warning ("rtpbin: could not create rtpptdemux element");
1906 /* called with RTP_BIN_LOCK */
1908 free_stream (GstRtpBinStream * stream, GstRtpBin * bin)
1910 GSList *clients, *next_client;
1912 GST_DEBUG_OBJECT (bin, "freeing stream %p", stream);
1914 if (stream->demux) {
1915 g_signal_handler_disconnect (stream->demux, stream->demux_newpad_sig);
1916 g_signal_handler_disconnect (stream->demux, stream->demux_ptreq_sig);
1917 g_signal_handler_disconnect (stream->demux, stream->demux_ptchange_sig);
1919 g_signal_handler_disconnect (stream->buffer, stream->buffer_handlesync_sig);
1920 g_signal_handler_disconnect (stream->buffer, stream->buffer_ptreq_sig);
1921 g_signal_handler_disconnect (stream->buffer, stream->buffer_ntpstop_sig);
1924 gst_element_set_locked_state (stream->demux, TRUE);
1925 gst_element_set_locked_state (stream->buffer, TRUE);
1928 gst_element_set_state (stream->demux, GST_STATE_NULL);
1929 gst_element_set_state (stream->buffer, GST_STATE_NULL);
1931 /* now remove this signal, we need this while going to NULL because it to
1932 * do some cleanups */
1934 g_signal_handler_disconnect (stream->demux, stream->demux_padremoved_sig);
1936 gst_bin_remove (GST_BIN_CAST (bin), stream->buffer);
1938 gst_bin_remove (GST_BIN_CAST (bin), stream->demux);
1940 for (clients = bin->clients; clients; clients = next_client) {
1941 GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
1942 GSList *streams, *next_stream;
1944 next_client = g_slist_next (clients);
1946 for (streams = client->streams; streams; streams = next_stream) {
1947 GstRtpBinStream *ostream = (GstRtpBinStream *) streams->data;
1949 next_stream = g_slist_next (streams);
1951 if (ostream == stream) {
1952 client->streams = g_slist_delete_link (client->streams, streams);
1953 /* If this was the last stream belonging to this client,
1954 * clean up the client. */
1955 if (--client->nstreams == 0) {
1956 bin->clients = g_slist_delete_link (bin->clients, clients);
1957 free_client (client, bin);
1966 /* GObject vmethods */
1967 static void gst_rtp_bin_dispose (GObject * object);
1968 static void gst_rtp_bin_finalize (GObject * object);
1969 static void gst_rtp_bin_set_property (GObject * object, guint prop_id,
1970 const GValue * value, GParamSpec * pspec);
1971 static void gst_rtp_bin_get_property (GObject * object, guint prop_id,
1972 GValue * value, GParamSpec * pspec);
1974 /* GstElement vmethods */
1975 static GstStateChangeReturn gst_rtp_bin_change_state (GstElement * element,
1976 GstStateChange transition);
1977 static GstPad *gst_rtp_bin_request_new_pad (GstElement * element,
1978 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
1979 static void gst_rtp_bin_release_pad (GstElement * element, GstPad * pad);
1980 static void gst_rtp_bin_handle_message (GstBin * bin, GstMessage * message);
1982 #define gst_rtp_bin_parent_class parent_class
1983 G_DEFINE_TYPE_WITH_PRIVATE (GstRtpBin, gst_rtp_bin, GST_TYPE_BIN);
1986 _gst_element_accumulator (GSignalInvocationHint * ihint,
1987 GValue * return_accu, const GValue * handler_return, gpointer dummy)
1989 GstElement *element;
1991 element = g_value_get_object (handler_return);
1992 GST_DEBUG ("got element %" GST_PTR_FORMAT, element);
1994 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
1995 g_value_set_object (return_accu, element);
1997 /* stop emission if we have an element */
1998 return (element == NULL);
2002 _gst_caps_accumulator (GSignalInvocationHint * ihint,
2003 GValue * return_accu, const GValue * handler_return, gpointer dummy)
2007 caps = g_value_get_boxed (handler_return);
2008 GST_DEBUG ("got caps %" GST_PTR_FORMAT, caps);
2010 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
2011 g_value_set_boxed (return_accu, caps);
2013 /* stop emission if we have a caps */
2014 return (caps == NULL);
2018 gst_rtp_bin_class_init (GstRtpBinClass * klass)
2020 GObjectClass *gobject_class;
2021 GstElementClass *gstelement_class;
2022 GstBinClass *gstbin_class;
2024 gobject_class = (GObjectClass *) klass;
2025 gstelement_class = (GstElementClass *) klass;
2026 gstbin_class = (GstBinClass *) klass;
2028 gobject_class->dispose = gst_rtp_bin_dispose;
2029 gobject_class->finalize = gst_rtp_bin_finalize;
2030 gobject_class->set_property = gst_rtp_bin_set_property;
2031 gobject_class->get_property = gst_rtp_bin_get_property;
2033 g_object_class_install_property (gobject_class, PROP_LATENCY,
2034 g_param_spec_uint ("latency", "Buffer latency in ms",
2035 "Default amount of ms to buffer in the jitterbuffers", 0,
2036 G_MAXUINT, DEFAULT_LATENCY_MS,
2037 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2039 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
2040 g_param_spec_boolean ("drop-on-latency",
2041 "Drop buffers when maximum latency is reached",
2042 "Tells the jitterbuffer to never exceed the given latency in size",
2043 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2046 * GstRtpBin::request-pt-map:
2047 * @rtpbin: the object which received the signal
2048 * @session: the session
2051 * Request the payload type as #GstCaps for @pt in @session.
2053 gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP] =
2054 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
2055 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, request_pt_map),
2056 _gst_caps_accumulator, NULL, g_cclosure_marshal_generic, GST_TYPE_CAPS,
2057 2, G_TYPE_UINT, G_TYPE_UINT);
2060 * GstRtpBin::payload-type-change:
2061 * @rtpbin: the object which received the signal
2062 * @session: the session
2065 * Signal that the current payload type changed to @pt in @session.
2067 gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE] =
2068 g_signal_new ("payload-type-change", G_TYPE_FROM_CLASS (klass),
2069 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, payload_type_change),
2070 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2074 * GstRtpBin::clear-pt-map:
2075 * @rtpbin: the object which received the signal
2077 * Clear all previously cached pt-mapping obtained with
2078 * #GstRtpBin::request-pt-map.
2080 gst_rtp_bin_signals[SIGNAL_CLEAR_PT_MAP] =
2081 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
2082 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2083 clear_pt_map), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
2087 * GstRtpBin::reset-sync:
2088 * @rtpbin: the object which received the signal
2090 * Reset all currently configured lip-sync parameters and require new SR
2091 * packets for all streams before lip-sync is attempted again.
2093 gst_rtp_bin_signals[SIGNAL_RESET_SYNC] =
2094 g_signal_new ("reset-sync", G_TYPE_FROM_CLASS (klass),
2095 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2096 reset_sync), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
2100 * GstRtpBin::get-session:
2101 * @rtpbin: the object which received the signal
2102 * @id: the session id
2104 * Request the related GstRtpSession as #GstElement related with session @id.
2108 gst_rtp_bin_signals[SIGNAL_GET_SESSION] =
2109 g_signal_new ("get-session", G_TYPE_FROM_CLASS (klass),
2110 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2111 get_session), NULL, NULL, g_cclosure_marshal_generic,
2112 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2115 * GstRtpBin::get-internal-session:
2116 * @rtpbin: the object which received the signal
2117 * @id: the session id
2119 * Request the internal RTPSession object as #GObject in session @id.
2121 gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_SESSION] =
2122 g_signal_new ("get-internal-session", G_TYPE_FROM_CLASS (klass),
2123 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2124 get_internal_session), NULL, NULL, g_cclosure_marshal_generic,
2125 RTP_TYPE_SESSION, 1, G_TYPE_UINT);
2128 * GstRtpBin::get-internal-storage:
2129 * @rtpbin: the object which received the signal
2130 * @id: the session id
2132 * Request the internal RTPStorage object as #GObject in session @id.
2136 gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_STORAGE] =
2137 g_signal_new ("get-internal-storage", G_TYPE_FROM_CLASS (klass),
2138 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2139 get_internal_storage), NULL, NULL, g_cclosure_marshal_generic,
2140 G_TYPE_OBJECT, 1, G_TYPE_UINT);
2143 * GstRtpBin::get-storage:
2144 * @rtpbin: the object which received the signal
2145 * @id: the session id
2147 * Request the RTPStorage element as #GObject in session @id.
2151 gst_rtp_bin_signals[SIGNAL_GET_STORAGE] =
2152 g_signal_new ("get-storage", G_TYPE_FROM_CLASS (klass),
2153 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2154 get_storage), NULL, NULL, g_cclosure_marshal_generic,
2155 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2158 * GstRtpBin::on-new-ssrc:
2159 * @rtpbin: the object which received the signal
2160 * @session: the session
2163 * Notify of a new SSRC that entered @session.
2165 gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC] =
2166 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
2167 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_ssrc),
2168 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2171 * GstRtpBin::on-ssrc-collision:
2172 * @rtpbin: the object which received the signal
2173 * @session: the session
2176 * Notify when we have an SSRC collision
2178 gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION] =
2179 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
2180 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_collision),
2181 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2184 * GstRtpBin::on-ssrc-validated:
2185 * @rtpbin: the object which received the signal
2186 * @session: the session
2189 * Notify of a new SSRC that became validated.
2191 gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED] =
2192 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
2193 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_validated),
2194 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2197 * GstRtpBin::on-ssrc-active:
2198 * @rtpbin: the object which received the signal
2199 * @session: the session
2202 * Notify of a SSRC that is active, i.e., sending RTCP.
2204 gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE] =
2205 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
2206 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_active),
2207 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2210 * GstRtpBin::on-ssrc-sdes:
2211 * @rtpbin: the object which received the signal
2212 * @session: the session
2215 * Notify of a SSRC that is active, i.e., sending RTCP.
2217 gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES] =
2218 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
2219 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_sdes),
2220 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2224 * GstRtpBin::on-bye-ssrc:
2225 * @rtpbin: the object which received the signal
2226 * @session: the session
2229 * Notify of an SSRC that became inactive because of a BYE packet.
2231 gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC] =
2232 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
2233 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_ssrc),
2234 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2237 * GstRtpBin::on-bye-timeout:
2238 * @rtpbin: the object which received the signal
2239 * @session: the session
2242 * Notify of an SSRC that has timed out because of BYE
2244 gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT] =
2245 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
2246 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_timeout),
2247 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2250 * GstRtpBin::on-timeout:
2251 * @rtpbin: the object which received the signal
2252 * @session: the session
2255 * Notify of an SSRC that has timed out
2257 gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT] =
2258 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
2259 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_timeout),
2260 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2263 * GstRtpBin::on-sender-timeout:
2264 * @rtpbin: the object which received the signal
2265 * @session: the session
2268 * Notify of a sender SSRC that has timed out and became a receiver
2270 gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT] =
2271 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
2272 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_sender_timeout),
2273 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2277 * GstRtpBin::on-npt-stop:
2278 * @rtpbin: the object which received the signal
2279 * @session: the session
2282 * Notify that SSRC sender has sent data up to the configured NPT stop time.
2284 gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP] =
2285 g_signal_new ("on-npt-stop", G_TYPE_FROM_CLASS (klass),
2286 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_npt_stop),
2287 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2291 * GstRtpBin::request-rtp-encoder:
2292 * @rtpbin: the object which received the signal
2293 * @session: the session
2295 * Request an RTP encoder element for the given @session. The encoder
2296 * element will be added to the bin if not previously added.
2298 * If no handler is connected, no encoder will be used.
2302 gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_ENCODER] =
2303 g_signal_new ("request-rtp-encoder", G_TYPE_FROM_CLASS (klass),
2304 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2305 request_rtp_encoder), _gst_element_accumulator, NULL,
2306 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2309 * GstRtpBin::request-rtp-decoder:
2310 * @rtpbin: the object which received the signal
2311 * @session: the session
2313 * Request an RTP decoder element for the given @session. The decoder
2314 * element will be added to the bin if not previously added.
2316 * If no handler is connected, no encoder will be used.
2320 gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_DECODER] =
2321 g_signal_new ("request-rtp-decoder", G_TYPE_FROM_CLASS (klass),
2322 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2323 request_rtp_decoder), _gst_element_accumulator, NULL,
2324 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2327 * GstRtpBin::request-rtcp-encoder:
2328 * @rtpbin: the object which received the signal
2329 * @session: the session
2331 * Request an RTCP encoder element for the given @session. The encoder
2332 * element will be added to the bin if not previously added.
2334 * If no handler is connected, no encoder will be used.
2338 gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_ENCODER] =
2339 g_signal_new ("request-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
2340 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2341 request_rtcp_encoder), _gst_element_accumulator, NULL,
2342 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2345 * GstRtpBin::request-rtcp-decoder:
2346 * @rtpbin: the object which received the signal
2347 * @session: the session
2349 * Request an RTCP decoder element for the given @session. The decoder
2350 * element will be added to the bin if not previously added.
2352 * If no handler is connected, no encoder will be used.
2356 gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_DECODER] =
2357 g_signal_new ("request-rtcp-decoder", G_TYPE_FROM_CLASS (klass),
2358 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2359 request_rtcp_decoder), _gst_element_accumulator, NULL,
2360 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2363 * GstRtpBin::new-jitterbuffer:
2364 * @rtpbin: the object which received the signal
2365 * @jitterbuffer: the new jitterbuffer
2366 * @session: the session
2369 * Notify that a new @jitterbuffer was created for @session and @ssrc.
2370 * This signal can, for example, be used to configure @jitterbuffer.
2374 gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER] =
2375 g_signal_new ("new-jitterbuffer", G_TYPE_FROM_CLASS (klass),
2376 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2377 new_jitterbuffer), NULL, NULL, g_cclosure_marshal_generic,
2378 G_TYPE_NONE, 3, GST_TYPE_ELEMENT, G_TYPE_UINT, G_TYPE_UINT);
2381 * GstRtpBin::new-storage:
2382 * @rtpbin: the object which received the signal
2383 * @storage: the new storage
2384 * @session: the session
2386 * Notify that a new @storage was created for @session.
2387 * This signal can, for example, be used to configure @storage.
2391 gst_rtp_bin_signals[SIGNAL_NEW_STORAGE] =
2392 g_signal_new ("new-storage", G_TYPE_FROM_CLASS (klass),
2393 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2394 new_storage), NULL, NULL, g_cclosure_marshal_generic,
2395 G_TYPE_NONE, 2, GST_TYPE_ELEMENT, G_TYPE_UINT);
2398 * GstRtpBin::request-aux-sender:
2399 * @rtpbin: the object which received the signal
2400 * @session: the session
2402 * Request an AUX sender element for the given @session. The AUX
2403 * element will be added to the bin.
2405 * If no handler is connected, no AUX element will be used.
2409 gst_rtp_bin_signals[SIGNAL_REQUEST_AUX_SENDER] =
2410 g_signal_new ("request-aux-sender", G_TYPE_FROM_CLASS (klass),
2411 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2412 request_aux_sender), _gst_element_accumulator, NULL,
2413 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2416 * GstRtpBin::request-aux-receiver:
2417 * @rtpbin: the object which received the signal
2418 * @session: the session
2420 * Request an AUX receiver element for the given @session. The AUX
2421 * element will be added to the bin.
2423 * If no handler is connected, no AUX element will be used.
2427 gst_rtp_bin_signals[SIGNAL_REQUEST_AUX_RECEIVER] =
2428 g_signal_new ("request-aux-receiver", G_TYPE_FROM_CLASS (klass),
2429 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2430 request_aux_receiver), _gst_element_accumulator, NULL,
2431 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2434 * GstRtpBin::request-fec-decoder:
2435 * @rtpbin: the object which received the signal
2436 * @session: the session index
2438 * Request a FEC decoder element for the given @session. The element
2439 * will be added to the bin after the pt demuxer.
2441 * If no handler is connected, no FEC decoder will be used.
2445 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_DECODER] =
2446 g_signal_new ("request-fec-decoder", G_TYPE_FROM_CLASS (klass),
2447 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2448 request_fec_decoder), _gst_element_accumulator, NULL,
2449 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2452 * GstRtpBin::request-fec-encoder:
2453 * @rtpbin: the object which received the signal
2454 * @session: the session index
2456 * Request a FEC encoder element for the given @session. The element
2457 * will be added to the bin after the RTPSession.
2459 * If no handler is connected, no FEC encoder will be used.
2463 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_ENCODER] =
2464 g_signal_new ("request-fec-encoder", G_TYPE_FROM_CLASS (klass),
2465 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2466 request_fec_encoder), _gst_element_accumulator, NULL,
2467 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2470 * GstRtpBin::on-new-sender-ssrc:
2471 * @rtpbin: the object which received the signal
2472 * @session: the session
2473 * @ssrc: the sender SSRC
2475 * Notify of a new sender SSRC that entered @session.
2479 gst_rtp_bin_signals[SIGNAL_ON_NEW_SENDER_SSRC] =
2480 g_signal_new ("on-new-sender-ssrc", G_TYPE_FROM_CLASS (klass),
2481 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_sender_ssrc),
2482 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
2485 * GstRtpBin::on-sender-ssrc-active:
2486 * @rtpbin: the object which received the signal
2487 * @session: the session
2488 * @ssrc: the sender SSRC
2490 * Notify of a sender SSRC that is active, i.e., sending RTCP.
2494 gst_rtp_bin_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE] =
2495 g_signal_new ("on-sender-ssrc-active", G_TYPE_FROM_CLASS (klass),
2496 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2497 on_sender_ssrc_active), NULL, NULL, g_cclosure_marshal_generic,
2498 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2502 * GstRtpBin::on-bundled-ssrc:
2503 * @rtpbin: the object which received the signal
2504 * @ssrc: the bundled SSRC
2506 * Notify of a new incoming bundled SSRC. If no handler is connected to the
2507 * signal then the #GstRtpSession created for the recv_rtp_sink_\%u
2508 * request pad will be managing this new SSRC. However if there is a handler
2509 * connected then the application can decided to dispatch this new stream to
2510 * another session by providing its ID as return value of the handler. This
2511 * can be particularly useful to keep retransmission SSRCs grouped with the
2512 * session for which they handle retransmission.
2516 gst_rtp_bin_signals[SIGNAL_ON_BUNDLED_SSRC] =
2517 g_signal_new ("on-bundled-ssrc", G_TYPE_FROM_CLASS (klass),
2518 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2519 on_bundled_ssrc), NULL, NULL,
2520 g_cclosure_marshal_generic, G_TYPE_UINT, 1, G_TYPE_UINT);
2523 g_object_class_install_property (gobject_class, PROP_SDES,
2524 g_param_spec_boxed ("sdes", "SDES",
2525 "The SDES items of this session",
2526 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2528 g_object_class_install_property (gobject_class, PROP_DO_LOST,
2529 g_param_spec_boolean ("do-lost", "Do Lost",
2530 "Send an event downstream when a packet is lost", DEFAULT_DO_LOST,
2531 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2533 g_object_class_install_property (gobject_class, PROP_AUTOREMOVE,
2534 g_param_spec_boolean ("autoremove", "Auto Remove",
2535 "Automatically remove timed out sources", DEFAULT_AUTOREMOVE,
2536 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2538 g_object_class_install_property (gobject_class, PROP_IGNORE_PT,
2539 g_param_spec_boolean ("ignore-pt", "Ignore PT",
2540 "Do not demultiplex based on PT values", DEFAULT_IGNORE_PT,
2541 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2543 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
2544 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
2545 "Use the pipeline running-time to set the NTP time in the RTCP SR messages "
2546 "(DEPRECATED: Use ntp-time-source property)",
2547 DEFAULT_USE_PIPELINE_CLOCK,
2548 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
2550 * GstRtpBin:buffer-mode:
2552 * Control the buffering and timestamping mode used by the jitterbuffer.
2554 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
2555 g_param_spec_enum ("buffer-mode", "Buffer Mode",
2556 "Control the buffering algorithm in use", RTP_TYPE_JITTER_BUFFER_MODE,
2557 DEFAULT_BUFFER_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2559 * GstRtpBin:ntp-sync:
2561 * Set the NTP time from the sender reports as the running-time on the
2562 * buffers. When both the sender and receiver have sychronized
2563 * running-time, i.e. when the clock and base-time is shared
2564 * between the receivers and the and the senders, this option can be
2565 * used to synchronize receivers on multiple machines.
2567 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
2568 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
2569 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
2570 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2573 * GstRtpBin:rtcp-sync:
2575 * If not synchronizing (directly) to the NTP clock, determines how to sync
2576 * the various streams.
2578 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC,
2579 g_param_spec_enum ("rtcp-sync", "RTCP Sync",
2580 "Use of RTCP SR in synchronization", GST_RTP_BIN_RTCP_SYNC_TYPE,
2581 DEFAULT_RTCP_SYNC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2584 * GstRtpBin:rtcp-sync-interval:
2586 * Determines how often to sync streams using RTCP data.
2588 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_INTERVAL,
2589 g_param_spec_uint ("rtcp-sync-interval", "RTCP Sync Interval",
2590 "RTCP SR interval synchronization (ms) (0 = always)",
2591 0, G_MAXUINT, DEFAULT_RTCP_SYNC_INTERVAL,
2592 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2594 g_object_class_install_property (gobject_class, PROP_DO_SYNC_EVENT,
2595 g_param_spec_boolean ("do-sync-event", "Do Sync Event",
2596 "Send event downstream when a stream is synchronized to the sender",
2597 DEFAULT_DO_SYNC_EVENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2600 * GstRtpBin:do-retransmission:
2602 * Enables RTP retransmission on all streams. To control retransmission on
2603 * a per-SSRC basis, connect to the #GstRtpBin::new-jitterbuffer signal and
2604 * set the #GstRtpJitterBuffer::do-retransmission property on the
2605 * #GstRtpJitterBuffer object instead.
2607 g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
2608 g_param_spec_boolean ("do-retransmission", "Do retransmission",
2609 "Enable retransmission on all streams",
2610 DEFAULT_DO_RETRANSMISSION,
2611 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2614 * GstRtpBin:rtp-profile:
2616 * Sets the default RTP profile of newly created RTP sessions. The
2617 * profile can be changed afterwards on a per-session basis.
2619 g_object_class_install_property (gobject_class, PROP_RTP_PROFILE,
2620 g_param_spec_enum ("rtp-profile", "RTP Profile",
2621 "Default RTP profile of newly created sessions",
2622 GST_TYPE_RTP_PROFILE, DEFAULT_RTP_PROFILE,
2623 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2625 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
2626 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
2627 "NTP time source for RTCP packets",
2628 gst_rtp_ntp_time_source_get_type (), DEFAULT_NTP_TIME_SOURCE,
2629 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2631 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_SEND_TIME,
2632 g_param_spec_boolean ("rtcp-sync-send-time", "RTCP Sync Send Time",
2633 "Use send time or capture time for RTCP sync "
2634 "(TRUE = send time, FALSE = capture time)",
2635 DEFAULT_RTCP_SYNC_SEND_TIME,
2636 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2638 g_object_class_install_property (gobject_class, PROP_MAX_RTCP_RTP_TIME_DIFF,
2639 g_param_spec_int ("max-rtcp-rtp-time-diff", "Max RTCP RTP Time Diff",
2640 "Maximum amount of time in ms that the RTP time in RTCP SRs "
2641 "is allowed to be ahead (-1 disabled)", -1, G_MAXINT,
2642 DEFAULT_MAX_RTCP_RTP_TIME_DIFF,
2643 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2645 g_object_class_install_property (gobject_class, PROP_MAX_DROPOUT_TIME,
2646 g_param_spec_uint ("max-dropout-time", "Max dropout time",
2647 "The maximum time (milliseconds) of missing packets tolerated.",
2648 0, G_MAXUINT, DEFAULT_MAX_DROPOUT_TIME,
2649 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2651 g_object_class_install_property (gobject_class, PROP_MAX_MISORDER_TIME,
2652 g_param_spec_uint ("max-misorder-time", "Max misorder time",
2653 "The maximum time (milliseconds) of misordered packets tolerated.",
2654 0, G_MAXUINT, DEFAULT_MAX_MISORDER_TIME,
2655 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2657 g_object_class_install_property (gobject_class, PROP_RFC7273_SYNC,
2658 g_param_spec_boolean ("rfc7273-sync", "Sync on RFC7273 clock",
2659 "Synchronize received streams to the RFC7273 clock "
2660 "(requires clock and offset to be provided)", DEFAULT_RFC7273_SYNC,
2661 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2663 g_object_class_install_property (gobject_class, PROP_MAX_STREAMS,
2664 g_param_spec_uint ("max-streams", "Max Streams",
2665 "The maximum number of streams to create for one session",
2666 0, G_MAXUINT, DEFAULT_MAX_STREAMS,
2667 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2670 * GstRtpBin:max-ts-offset-adjustment:
2672 * Syncing time stamps to NTP time adds a time offset. This parameter
2673 * specifies the maximum number of nanoseconds per frame that this time offset
2674 * may be adjusted with. This is used to avoid sudden large changes to time
2679 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET_ADJUSTMENT,
2680 g_param_spec_uint64 ("max-ts-offset-adjustment",
2681 "Max Timestamp Offset Adjustment",
2682 "The maximum number of nanoseconds per frame that time stamp offsets "
2683 "may be adjusted (0 = no limit).", 0, G_MAXUINT64,
2684 DEFAULT_MAX_TS_OFFSET_ADJUSTMENT, G_PARAM_READWRITE |
2685 G_PARAM_STATIC_STRINGS));
2688 * GstRtpBin:max-ts-offset:
2690 * Used to set an upper limit of how large a time offset may be. This
2691 * is used to protect against unrealistic values as a result of either
2692 * client,server or clock issues.
2696 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET,
2697 g_param_spec_int64 ("max-ts-offset", "Max TS Offset",
2698 "The maximum absolute value of the time offset in (nanoseconds). "
2699 "Note, if the ntp-sync parameter is set the default value is "
2700 "changed to 0 (no limit)", 0, G_MAXINT64, DEFAULT_MAX_TS_OFFSET,
2701 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2703 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
2704 gstelement_class->request_new_pad =
2705 GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
2706 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_bin_release_pad);
2709 gst_element_class_add_static_pad_template (gstelement_class,
2710 &rtpbin_recv_rtp_sink_template);
2711 gst_element_class_add_static_pad_template (gstelement_class,
2712 &rtpbin_recv_rtcp_sink_template);
2713 gst_element_class_add_static_pad_template (gstelement_class,
2714 &rtpbin_send_rtp_sink_template);
2717 gst_element_class_add_static_pad_template (gstelement_class,
2718 &rtpbin_recv_rtp_src_template);
2719 gst_element_class_add_static_pad_template (gstelement_class,
2720 &rtpbin_send_rtcp_src_template);
2721 gst_element_class_add_static_pad_template (gstelement_class,
2722 &rtpbin_send_rtp_src_template);
2724 gst_element_class_set_static_metadata (gstelement_class, "RTP Bin",
2725 "Filter/Network/RTP",
2726 "Real-Time Transport Protocol bin",
2727 "Wim Taymans <wim.taymans@gmail.com>");
2729 gstbin_class->handle_message = GST_DEBUG_FUNCPTR (gst_rtp_bin_handle_message);
2731 klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_bin_clear_pt_map);
2732 klass->reset_sync = GST_DEBUG_FUNCPTR (gst_rtp_bin_reset_sync);
2733 klass->get_session = GST_DEBUG_FUNCPTR (gst_rtp_bin_get_session);
2734 klass->get_internal_session =
2735 GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_session);
2736 klass->get_storage = GST_DEBUG_FUNCPTR (gst_rtp_bin_get_storage);
2737 klass->get_internal_storage =
2738 GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_storage);
2739 klass->request_rtp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
2740 klass->request_rtp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
2741 klass->request_rtcp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
2742 klass->request_rtcp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
2744 GST_DEBUG_CATEGORY_INIT (gst_rtp_bin_debug, "rtpbin", 0, "RTP bin");
2748 gst_rtp_bin_init (GstRtpBin * rtpbin)
2752 rtpbin->priv = gst_rtp_bin_get_instance_private (rtpbin);
2753 g_mutex_init (&rtpbin->priv->bin_lock);
2754 g_mutex_init (&rtpbin->priv->dyn_lock);
2756 rtpbin->latency_ms = DEFAULT_LATENCY_MS;
2757 rtpbin->latency_ns = DEFAULT_LATENCY_MS * GST_MSECOND;
2758 rtpbin->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
2759 rtpbin->do_lost = DEFAULT_DO_LOST;
2760 rtpbin->ignore_pt = DEFAULT_IGNORE_PT;
2761 rtpbin->ntp_sync = DEFAULT_NTP_SYNC;
2762 rtpbin->rtcp_sync = DEFAULT_RTCP_SYNC;
2763 rtpbin->rtcp_sync_interval = DEFAULT_RTCP_SYNC_INTERVAL;
2764 rtpbin->priv->autoremove = DEFAULT_AUTOREMOVE;
2765 rtpbin->buffer_mode = DEFAULT_BUFFER_MODE;
2766 rtpbin->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
2767 rtpbin->send_sync_event = DEFAULT_DO_SYNC_EVENT;
2768 rtpbin->do_retransmission = DEFAULT_DO_RETRANSMISSION;
2769 rtpbin->rtp_profile = DEFAULT_RTP_PROFILE;
2770 rtpbin->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
2771 rtpbin->rtcp_sync_send_time = DEFAULT_RTCP_SYNC_SEND_TIME;
2772 rtpbin->max_rtcp_rtp_time_diff = DEFAULT_MAX_RTCP_RTP_TIME_DIFF;
2773 rtpbin->max_dropout_time = DEFAULT_MAX_DROPOUT_TIME;
2774 rtpbin->max_misorder_time = DEFAULT_MAX_MISORDER_TIME;
2775 rtpbin->rfc7273_sync = DEFAULT_RFC7273_SYNC;
2776 rtpbin->max_streams = DEFAULT_MAX_STREAMS;
2777 rtpbin->max_ts_offset_adjustment = DEFAULT_MAX_TS_OFFSET_ADJUSTMENT;
2778 rtpbin->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
2779 rtpbin->max_ts_offset_is_set = FALSE;
2781 /* some default SDES entries */
2782 cname = g_strdup_printf ("user%u@host-%x", g_random_int (), g_random_int ());
2783 rtpbin->sdes = gst_structure_new ("application/x-rtp-source-sdes",
2784 "cname", G_TYPE_STRING, cname, "tool", G_TYPE_STRING, "GStreamer", NULL);
2789 gst_rtp_bin_dispose (GObject * object)
2793 rtpbin = GST_RTP_BIN (object);
2795 GST_RTP_BIN_LOCK (rtpbin);
2796 GST_DEBUG_OBJECT (object, "freeing sessions");
2797 g_slist_foreach (rtpbin->sessions, (GFunc) free_session, rtpbin);
2798 g_slist_free (rtpbin->sessions);
2799 rtpbin->sessions = NULL;
2800 GST_RTP_BIN_UNLOCK (rtpbin);
2802 G_OBJECT_CLASS (parent_class)->dispose (object);
2806 gst_rtp_bin_finalize (GObject * object)
2810 rtpbin = GST_RTP_BIN (object);
2813 gst_structure_free (rtpbin->sdes);
2815 g_mutex_clear (&rtpbin->priv->bin_lock);
2816 g_mutex_clear (&rtpbin->priv->dyn_lock);
2818 G_OBJECT_CLASS (parent_class)->finalize (object);
2823 gst_rtp_bin_set_sdes_struct (GstRtpBin * bin, const GstStructure * sdes)
2830 GST_RTP_BIN_LOCK (bin);
2832 GST_OBJECT_LOCK (bin);
2834 gst_structure_free (bin->sdes);
2835 bin->sdes = gst_structure_copy (sdes);
2836 GST_OBJECT_UNLOCK (bin);
2838 /* store in all sessions */
2839 for (item = bin->sessions; item; item = g_slist_next (item)) {
2840 GstRtpBinSession *session = item->data;
2841 g_object_set (session->session, "sdes", sdes, NULL);
2844 GST_RTP_BIN_UNLOCK (bin);
2847 static GstStructure *
2848 gst_rtp_bin_get_sdes_struct (GstRtpBin * bin)
2850 GstStructure *result;
2852 GST_OBJECT_LOCK (bin);
2853 result = gst_structure_copy (bin->sdes);
2854 GST_OBJECT_UNLOCK (bin);
2860 gst_rtp_bin_set_property (GObject * object, guint prop_id,
2861 const GValue * value, GParamSpec * pspec)
2865 rtpbin = GST_RTP_BIN (object);
2869 GST_RTP_BIN_LOCK (rtpbin);
2870 rtpbin->latency_ms = g_value_get_uint (value);
2871 rtpbin->latency_ns = rtpbin->latency_ms * GST_MSECOND;
2872 GST_RTP_BIN_UNLOCK (rtpbin);
2873 /* propagate the property down to the jitterbuffer */
2874 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "latency", value);
2876 case PROP_DROP_ON_LATENCY:
2877 GST_RTP_BIN_LOCK (rtpbin);
2878 rtpbin->drop_on_latency = g_value_get_boolean (value);
2879 GST_RTP_BIN_UNLOCK (rtpbin);
2880 /* propagate the property down to the jitterbuffer */
2881 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
2882 "drop-on-latency", value);
2885 gst_rtp_bin_set_sdes_struct (rtpbin, g_value_get_boxed (value));
2888 GST_RTP_BIN_LOCK (rtpbin);
2889 rtpbin->do_lost = g_value_get_boolean (value);
2890 GST_RTP_BIN_UNLOCK (rtpbin);
2891 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "do-lost", value);
2894 rtpbin->ntp_sync = g_value_get_boolean (value);
2895 /* The default value of max_ts_offset depends on ntp_sync. If user
2896 * hasn't set it then change default value */
2897 if (!rtpbin->max_ts_offset_is_set) {
2898 if (rtpbin->ntp_sync) {
2899 rtpbin->max_ts_offset = 0;
2901 rtpbin->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
2905 case PROP_RTCP_SYNC:
2906 g_atomic_int_set (&rtpbin->rtcp_sync, g_value_get_enum (value));
2908 case PROP_RTCP_SYNC_INTERVAL:
2909 rtpbin->rtcp_sync_interval = g_value_get_uint (value);
2911 case PROP_IGNORE_PT:
2912 rtpbin->ignore_pt = g_value_get_boolean (value);
2914 case PROP_AUTOREMOVE:
2915 rtpbin->priv->autoremove = g_value_get_boolean (value);
2917 case PROP_USE_PIPELINE_CLOCK:
2920 GST_RTP_BIN_LOCK (rtpbin);
2921 rtpbin->use_pipeline_clock = g_value_get_boolean (value);
2922 for (sessions = rtpbin->sessions; sessions;
2923 sessions = g_slist_next (sessions)) {
2924 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
2926 g_object_set (G_OBJECT (session->session),
2927 "use-pipeline-clock", rtpbin->use_pipeline_clock, NULL);
2929 GST_RTP_BIN_UNLOCK (rtpbin);
2932 case PROP_DO_SYNC_EVENT:
2933 rtpbin->send_sync_event = g_value_get_boolean (value);
2935 case PROP_BUFFER_MODE:
2936 GST_RTP_BIN_LOCK (rtpbin);
2937 rtpbin->buffer_mode = g_value_get_enum (value);
2938 GST_RTP_BIN_UNLOCK (rtpbin);
2939 /* propagate the property down to the jitterbuffer */
2940 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "mode", value);
2942 case PROP_DO_RETRANSMISSION:
2943 GST_RTP_BIN_LOCK (rtpbin);
2944 rtpbin->do_retransmission = g_value_get_boolean (value);
2945 GST_RTP_BIN_UNLOCK (rtpbin);
2946 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
2947 "do-retransmission", value);
2949 case PROP_RTP_PROFILE:
2950 rtpbin->rtp_profile = g_value_get_enum (value);
2952 case PROP_NTP_TIME_SOURCE:{
2954 GST_RTP_BIN_LOCK (rtpbin);
2955 rtpbin->ntp_time_source = g_value_get_enum (value);
2956 for (sessions = rtpbin->sessions; sessions;
2957 sessions = g_slist_next (sessions)) {
2958 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
2960 g_object_set (G_OBJECT (session->session),
2961 "ntp-time-source", rtpbin->ntp_time_source, NULL);
2963 GST_RTP_BIN_UNLOCK (rtpbin);
2966 case PROP_RTCP_SYNC_SEND_TIME:{
2968 GST_RTP_BIN_LOCK (rtpbin);
2969 rtpbin->rtcp_sync_send_time = g_value_get_boolean (value);
2970 for (sessions = rtpbin->sessions; sessions;
2971 sessions = g_slist_next (sessions)) {
2972 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
2974 g_object_set (G_OBJECT (session->session),
2975 "rtcp-sync-send-time", rtpbin->rtcp_sync_send_time, NULL);
2977 GST_RTP_BIN_UNLOCK (rtpbin);
2980 case PROP_MAX_RTCP_RTP_TIME_DIFF:
2981 GST_RTP_BIN_LOCK (rtpbin);
2982 rtpbin->max_rtcp_rtp_time_diff = g_value_get_int (value);
2983 GST_RTP_BIN_UNLOCK (rtpbin);
2984 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
2985 "max-rtcp-rtp-time-diff", value);
2987 case PROP_MAX_DROPOUT_TIME:
2988 GST_RTP_BIN_LOCK (rtpbin);
2989 rtpbin->max_dropout_time = g_value_get_uint (value);
2990 GST_RTP_BIN_UNLOCK (rtpbin);
2991 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
2992 "max-dropout-time", value);
2993 gst_rtp_bin_propagate_property_to_session (rtpbin, "max-dropout-time",
2996 case PROP_MAX_MISORDER_TIME:
2997 GST_RTP_BIN_LOCK (rtpbin);
2998 rtpbin->max_misorder_time = g_value_get_uint (value);
2999 GST_RTP_BIN_UNLOCK (rtpbin);
3000 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3001 "max-misorder-time", value);
3002 gst_rtp_bin_propagate_property_to_session (rtpbin, "max-misorder-time",
3005 case PROP_RFC7273_SYNC:
3006 rtpbin->rfc7273_sync = g_value_get_boolean (value);
3007 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3008 "rfc7273-sync", value);
3010 case PROP_MAX_STREAMS:
3011 rtpbin->max_streams = g_value_get_uint (value);
3013 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
3014 rtpbin->max_ts_offset_adjustment = g_value_get_uint64 (value);
3015 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3016 "max-ts-offset-adjustment", value);
3018 case PROP_MAX_TS_OFFSET:
3019 rtpbin->max_ts_offset = g_value_get_int64 (value);
3020 rtpbin->max_ts_offset_is_set = TRUE;
3023 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3029 gst_rtp_bin_get_property (GObject * object, guint prop_id,
3030 GValue * value, GParamSpec * pspec)
3034 rtpbin = GST_RTP_BIN (object);
3038 GST_RTP_BIN_LOCK (rtpbin);
3039 g_value_set_uint (value, rtpbin->latency_ms);
3040 GST_RTP_BIN_UNLOCK (rtpbin);
3042 case PROP_DROP_ON_LATENCY:
3043 GST_RTP_BIN_LOCK (rtpbin);
3044 g_value_set_boolean (value, rtpbin->drop_on_latency);
3045 GST_RTP_BIN_UNLOCK (rtpbin);
3048 g_value_take_boxed (value, gst_rtp_bin_get_sdes_struct (rtpbin));
3051 GST_RTP_BIN_LOCK (rtpbin);
3052 g_value_set_boolean (value, rtpbin->do_lost);
3053 GST_RTP_BIN_UNLOCK (rtpbin);
3055 case PROP_IGNORE_PT:
3056 g_value_set_boolean (value, rtpbin->ignore_pt);
3059 g_value_set_boolean (value, rtpbin->ntp_sync);
3061 case PROP_RTCP_SYNC:
3062 g_value_set_enum (value, g_atomic_int_get (&rtpbin->rtcp_sync));
3064 case PROP_RTCP_SYNC_INTERVAL:
3065 g_value_set_uint (value, rtpbin->rtcp_sync_interval);
3067 case PROP_AUTOREMOVE:
3068 g_value_set_boolean (value, rtpbin->priv->autoremove);
3070 case PROP_BUFFER_MODE:
3071 g_value_set_enum (value, rtpbin->buffer_mode);
3073 case PROP_USE_PIPELINE_CLOCK:
3074 g_value_set_boolean (value, rtpbin->use_pipeline_clock);
3076 case PROP_DO_SYNC_EVENT:
3077 g_value_set_boolean (value, rtpbin->send_sync_event);
3079 case PROP_DO_RETRANSMISSION:
3080 GST_RTP_BIN_LOCK (rtpbin);
3081 g_value_set_boolean (value, rtpbin->do_retransmission);
3082 GST_RTP_BIN_UNLOCK (rtpbin);
3084 case PROP_RTP_PROFILE:
3085 g_value_set_enum (value, rtpbin->rtp_profile);
3087 case PROP_NTP_TIME_SOURCE:
3088 g_value_set_enum (value, rtpbin->ntp_time_source);
3090 case PROP_RTCP_SYNC_SEND_TIME:
3091 g_value_set_boolean (value, rtpbin->rtcp_sync_send_time);
3093 case PROP_MAX_RTCP_RTP_TIME_DIFF:
3094 GST_RTP_BIN_LOCK (rtpbin);
3095 g_value_set_int (value, rtpbin->max_rtcp_rtp_time_diff);
3096 GST_RTP_BIN_UNLOCK (rtpbin);
3098 case PROP_MAX_DROPOUT_TIME:
3099 g_value_set_uint (value, rtpbin->max_dropout_time);
3101 case PROP_MAX_MISORDER_TIME:
3102 g_value_set_uint (value, rtpbin->max_misorder_time);
3104 case PROP_RFC7273_SYNC:
3105 g_value_set_boolean (value, rtpbin->rfc7273_sync);
3107 case PROP_MAX_STREAMS:
3108 g_value_set_uint (value, rtpbin->max_streams);
3110 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
3111 g_value_set_uint64 (value, rtpbin->max_ts_offset_adjustment);
3113 case PROP_MAX_TS_OFFSET:
3114 g_value_set_int64 (value, rtpbin->max_ts_offset);
3117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3123 gst_rtp_bin_handle_message (GstBin * bin, GstMessage * message)
3127 rtpbin = GST_RTP_BIN (bin);
3129 switch (GST_MESSAGE_TYPE (message)) {
3130 case GST_MESSAGE_ELEMENT:
3132 const GstStructure *s = gst_message_get_structure (message);
3134 /* we change the structure name and add the session ID to it */
3135 if (gst_structure_has_name (s, "application/x-rtp-source-sdes")) {
3136 GstRtpBinSession *sess;
3138 /* find the session we set it as object data */
3139 sess = g_object_get_data (G_OBJECT (GST_MESSAGE_SRC (message)),
3140 "GstRTPBin.session");
3142 if (G_LIKELY (sess)) {
3143 message = gst_message_make_writable (message);
3144 s = gst_message_get_structure (message);
3145 gst_structure_set ((GstStructure *) s, "session", G_TYPE_UINT,
3149 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3152 case GST_MESSAGE_BUFFERING:
3155 gint min_percent = 100;
3156 GSList *sessions, *streams;
3157 GstRtpBinStream *stream;
3158 gboolean change = FALSE, active = FALSE;
3159 GstClockTime min_out_time;
3160 GstBufferingMode mode;
3161 gint avg_in, avg_out;
3162 gint64 buffering_left;
3164 gst_message_parse_buffering (message, &percent);
3165 gst_message_parse_buffering_stats (message, &mode, &avg_in, &avg_out,
3169 g_object_get_data (G_OBJECT (GST_MESSAGE_SRC (message)),
3170 "GstRTPBin.stream");
3172 GST_DEBUG_OBJECT (bin, "got percent %d from stream %p", percent, stream);
3174 /* get the stream */
3175 if (G_LIKELY (stream)) {
3176 GST_RTP_BIN_LOCK (rtpbin);
3177 /* fill in the percent */
3178 stream->percent = percent;
3180 /* calculate the min value for all streams */
3181 for (sessions = rtpbin->sessions; sessions;
3182 sessions = g_slist_next (sessions)) {
3183 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3185 GST_RTP_SESSION_LOCK (session);
3186 if (session->streams) {
3187 for (streams = session->streams; streams;
3188 streams = g_slist_next (streams)) {
3189 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
3191 GST_DEBUG_OBJECT (bin, "stream %p percent %d", stream,
3194 /* find min percent */
3195 if (min_percent > stream->percent)
3196 min_percent = stream->percent;
3199 GST_INFO_OBJECT (bin,
3200 "session has no streams, setting min_percent to 0");
3203 GST_RTP_SESSION_UNLOCK (session);
3205 GST_DEBUG_OBJECT (bin, "min percent %d", min_percent);
3207 if (rtpbin->buffering) {
3208 if (min_percent == 100) {
3209 rtpbin->buffering = FALSE;
3214 if (min_percent < 100) {
3215 /* pause the streams */
3216 rtpbin->buffering = TRUE;
3221 GST_RTP_BIN_UNLOCK (rtpbin);
3223 gst_message_unref (message);
3225 /* make a new buffering message with the min value */
3227 gst_message_new_buffering (GST_OBJECT_CAST (bin), min_percent);
3228 gst_message_set_buffering_stats (message, mode, avg_in, avg_out,
3231 if (G_UNLIKELY (change)) {
3233 guint64 running_time = 0;
3236 /* figure out the running time when we have a clock */
3237 if (G_LIKELY ((clock =
3238 gst_element_get_clock (GST_ELEMENT_CAST (bin))))) {
3239 guint64 now, base_time;
3241 now = gst_clock_get_time (clock);
3242 base_time = gst_element_get_base_time (GST_ELEMENT_CAST (bin));
3243 running_time = now - base_time;
3244 gst_object_unref (clock);
3246 GST_DEBUG_OBJECT (bin,
3247 "running time now %" GST_TIME_FORMAT,
3248 GST_TIME_ARGS (running_time));
3250 GST_RTP_BIN_LOCK (rtpbin);
3252 /* when we reactivate, calculate the offsets so that all streams have
3253 * an output time that is at least as big as the running_time */
3256 if (running_time > rtpbin->buffer_start) {
3257 offset = running_time - rtpbin->buffer_start;
3258 if (offset >= rtpbin->latency_ns)
3259 offset -= rtpbin->latency_ns;
3265 /* pause all streams */
3267 for (sessions = rtpbin->sessions; sessions;
3268 sessions = g_slist_next (sessions)) {
3269 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3271 GST_RTP_SESSION_LOCK (session);
3272 for (streams = session->streams; streams;
3273 streams = g_slist_next (streams)) {
3274 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
3275 GstElement *element = stream->buffer;
3278 g_signal_emit_by_name (element, "set-active", active, offset,
3282 g_object_get (element, "percent", &stream->percent, NULL);
3286 if (min_out_time == -1 || last_out < min_out_time)
3287 min_out_time = last_out;
3290 GST_DEBUG_OBJECT (bin,
3291 "setting %p to %d, offset %" GST_TIME_FORMAT ", last %"
3292 GST_TIME_FORMAT ", percent %d", element, active,
3293 GST_TIME_ARGS (offset), GST_TIME_ARGS (last_out),
3296 GST_RTP_SESSION_UNLOCK (session);
3298 GST_DEBUG_OBJECT (bin,
3299 "min out time %" GST_TIME_FORMAT, GST_TIME_ARGS (min_out_time));
3301 /* the buffer_start is the min out time of all paused jitterbuffers */
3303 rtpbin->buffer_start = min_out_time;
3305 GST_RTP_BIN_UNLOCK (rtpbin);
3308 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3313 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3319 static GstStateChangeReturn
3320 gst_rtp_bin_change_state (GstElement * element, GstStateChange transition)
3322 GstStateChangeReturn res;
3324 GstRtpBinPrivate *priv;
3326 rtpbin = GST_RTP_BIN (element);
3327 priv = rtpbin->priv;
3329 switch (transition) {
3330 case GST_STATE_CHANGE_NULL_TO_READY:
3332 case GST_STATE_CHANGE_READY_TO_PAUSED:
3333 priv->last_ntpnstime = 0;
3334 GST_LOG_OBJECT (rtpbin, "clearing shutdown flag");
3335 g_atomic_int_set (&priv->shutdown, 0);
3337 case GST_STATE_CHANGE_PAUSED_TO_READY:
3338 GST_LOG_OBJECT (rtpbin, "setting shutdown flag");
3339 g_atomic_int_set (&priv->shutdown, 1);
3340 /* wait for all callbacks to end by taking the lock. No new callbacks will
3341 * be able to happen as we set the shutdown flag. */
3342 GST_RTP_BIN_DYN_LOCK (rtpbin);
3343 GST_LOG_OBJECT (rtpbin, "dynamic lock taken, we can continue shutdown");
3344 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
3350 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3352 switch (transition) {
3353 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3355 case GST_STATE_CHANGE_PAUSED_TO_READY:
3357 case GST_STATE_CHANGE_READY_TO_NULL:
3366 session_request_element (GstRtpBinSession * session, guint signal)
3368 GstElement *element = NULL;
3369 GstRtpBin *bin = session->bin;
3371 g_signal_emit (bin, gst_rtp_bin_signals[signal], 0, session->id, &element);
3374 if (!bin_manage_element (bin, element))
3376 session->elements = g_slist_prepend (session->elements, element);
3383 GST_WARNING_OBJECT (bin, "unable to manage element");
3384 gst_object_unref (element);
3390 copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
3392 GstPad *gpad = GST_PAD_CAST (user_data);
3394 GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
3395 gst_pad_store_sticky_event (gpad, *event);
3400 /* a new pad (SSRC) was created in @session. This signal is emitted from the
3401 * payload demuxer. */
3403 new_payload_found (GstElement * element, guint pt, GstPad * pad,
3404 GstRtpBinStream * stream)
3407 GstElementClass *klass;
3408 GstPadTemplate *templ;
3412 rtpbin = stream->bin;
3414 GST_DEBUG_OBJECT (rtpbin, "new payload pad %u", pt);
3416 pad = gst_object_ref (pad);
3418 if (stream->session->storage) {
3419 GstElement *fec_decoder =
3420 session_request_element (stream->session, SIGNAL_REQUEST_FEC_DECODER);
3423 GstPad *sinkpad, *srcpad;
3424 GstPadLinkReturn ret;
3426 sinkpad = gst_element_get_static_pad (fec_decoder, "sink");
3429 goto fec_decoder_sink_failed;
3431 ret = gst_pad_link (pad, sinkpad);
3432 gst_object_unref (sinkpad);
3434 if (ret != GST_PAD_LINK_OK)
3435 goto fec_decoder_link_failed;
3437 srcpad = gst_element_get_static_pad (fec_decoder, "src");
3440 goto fec_decoder_src_failed;
3442 gst_pad_sticky_events_foreach (pad, copy_sticky_events, srcpad);
3443 gst_object_unref (pad);
3448 GST_RTP_BIN_SHUTDOWN_LOCK (rtpbin, shutdown);
3450 /* ghost the pad to the parent */
3451 klass = GST_ELEMENT_GET_CLASS (rtpbin);
3452 templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%u_%u_%u");
3453 padname = g_strdup_printf ("recv_rtp_src_%u_%u_%u",
3454 stream->session->id, stream->ssrc, pt);
3455 gpad = gst_ghost_pad_new_from_template (padname, pad, templ);
3457 g_object_set_data (G_OBJECT (pad), "GstRTPBin.ghostpad", gpad);
3459 gst_pad_set_active (gpad, TRUE);
3460 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3462 gst_pad_sticky_events_foreach (pad, copy_sticky_events, gpad);
3463 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3466 gst_object_unref (pad);
3472 GST_DEBUG ("ignoring, we are shutting down");
3475 fec_decoder_sink_failed:
3477 g_warning ("rtpbin: failed to get fec encoder sink pad for session %u",
3478 stream->session->id);
3481 fec_decoder_src_failed:
3483 g_warning ("rtpbin: failed to get fec encoder src pad for session %u",
3484 stream->session->id);
3487 fec_decoder_link_failed:
3489 g_warning ("rtpbin: failed to link fec decoder for session %u",
3490 stream->session->id);
3496 payload_pad_removed (GstElement * element, GstPad * pad,
3497 GstRtpBinStream * stream)
3502 rtpbin = stream->bin;
3504 GST_DEBUG ("payload pad removed");
3506 GST_RTP_BIN_DYN_LOCK (rtpbin);
3507 if ((gpad = g_object_get_data (G_OBJECT (pad), "GstRTPBin.ghostpad"))) {
3508 g_object_set_data (G_OBJECT (pad), "GstRTPBin.ghostpad", NULL);
3510 gst_pad_set_active (gpad, FALSE);
3511 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3513 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
3517 pt_map_requested (GstElement * element, guint pt, GstRtpBinSession * session)
3522 rtpbin = session->bin;
3524 GST_DEBUG_OBJECT (rtpbin, "payload map requested for pt %u in session %u", pt,
3527 caps = get_pt_map (session, pt);
3536 GST_DEBUG_OBJECT (rtpbin, "could not get caps");
3542 ptdemux_pt_map_requested (GstElement * element, guint pt,
3543 GstRtpBinSession * session)
3545 GstCaps *ret = pt_map_requested (element, pt, session);
3547 if (ret && gst_caps_get_size (ret) == 1) {
3548 const GstStructure *s = gst_caps_get_structure (ret, 0);
3551 if (gst_structure_get_boolean (s, "is-fec", &is_fec) && is_fec) {
3552 GValue v = G_VALUE_INIT;
3553 GValue v2 = G_VALUE_INIT;
3555 GST_INFO_OBJECT (session->bin, "Will ignore FEC pt %u in session %u", pt,
3557 g_value_init (&v, GST_TYPE_ARRAY);
3558 g_value_init (&v2, G_TYPE_INT);
3559 g_object_get_property (G_OBJECT (element), "ignored-payload-types", &v);
3560 g_value_set_int (&v2, pt);
3561 gst_value_array_append_value (&v, &v2);
3562 g_value_unset (&v2);
3563 g_object_set_property (G_OBJECT (element), "ignored-payload-types", &v);
3572 payload_type_change (GstElement * element, guint pt, GstRtpBinSession * session)
3574 GST_DEBUG_OBJECT (session->bin,
3575 "emiting signal for pt type changed to %u in session %u", pt,
3578 g_signal_emit (session->bin, gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE],
3579 0, session->id, pt);
3582 /* emitted when caps changed for the session */
3584 caps_changed (GstPad * pad, GParamSpec * pspec, GstRtpBinSession * session)
3589 const GstStructure *s;
3593 g_object_get (pad, "caps", &caps, NULL);
3598 GST_DEBUG_OBJECT (bin, "got caps %" GST_PTR_FORMAT, caps);
3600 s = gst_caps_get_structure (caps, 0);
3602 /* get payload, finish when it's not there */
3603 if (!gst_structure_get_int (s, "payload", &payload)) {
3604 gst_caps_unref (caps);
3608 GST_RTP_SESSION_LOCK (session);
3609 GST_DEBUG_OBJECT (bin, "insert caps for payload %d", payload);
3610 g_hash_table_insert (session->ptmap, GINT_TO_POINTER (payload), caps);
3611 GST_RTP_SESSION_UNLOCK (session);
3614 /* a new pad (SSRC) was created in @session */
3616 new_ssrc_pad_found (GstElement * element, guint ssrc, GstPad * pad,
3617 GstRtpBinSession * session)
3620 GstRtpBinStream *stream;
3621 GstPad *sinkpad, *srcpad;
3624 rtpbin = session->bin;
3626 GST_DEBUG_OBJECT (rtpbin, "new SSRC pad %08x, %s:%s", ssrc,
3627 GST_DEBUG_PAD_NAME (pad));
3629 GST_RTP_BIN_SHUTDOWN_LOCK (rtpbin, shutdown);
3631 GST_RTP_SESSION_LOCK (session);
3633 /* create new stream */
3634 stream = create_stream (session, ssrc);
3638 /* get pad and link */
3639 GST_DEBUG_OBJECT (rtpbin, "linking jitterbuffer RTP");
3640 padname = g_strdup_printf ("src_%u", ssrc);
3641 srcpad = gst_element_get_static_pad (element, padname);
3643 sinkpad = gst_element_get_static_pad (stream->buffer, "sink");
3644 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
3645 gst_object_unref (sinkpad);
3646 gst_object_unref (srcpad);
3648 GST_DEBUG_OBJECT (rtpbin, "linking jitterbuffer RTCP");
3649 padname = g_strdup_printf ("rtcp_src_%u", ssrc);
3650 srcpad = gst_element_get_static_pad (element, padname);
3652 sinkpad = gst_element_get_request_pad (stream->buffer, "sink_rtcp");
3653 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
3654 gst_object_unref (sinkpad);
3655 gst_object_unref (srcpad);
3657 /* connect to the RTCP sync signal from the jitterbuffer */
3658 GST_DEBUG_OBJECT (rtpbin, "connecting sync signal");
3659 stream->buffer_handlesync_sig = g_signal_connect (stream->buffer,
3660 "handle-sync", (GCallback) gst_rtp_bin_handle_sync, stream);
3662 if (stream->demux) {
3663 /* connect to the new-pad signal of the payload demuxer, this will expose the
3664 * new pad by ghosting it. */
3665 stream->demux_newpad_sig = g_signal_connect (stream->demux,
3666 "new-payload-type", (GCallback) new_payload_found, stream);
3667 stream->demux_padremoved_sig = g_signal_connect (stream->demux,
3668 "pad-removed", (GCallback) payload_pad_removed, stream);
3670 /* connect to the request-pt-map signal. This signal will be emitted by the
3671 * demuxer so that it can apply a proper caps on the buffers for the
3673 stream->demux_ptreq_sig = g_signal_connect (stream->demux,
3674 "request-pt-map", (GCallback) ptdemux_pt_map_requested, session);
3675 /* connect to the signal so it can be forwarded. */
3676 stream->demux_ptchange_sig = g_signal_connect (stream->demux,
3677 "payload-type-change", (GCallback) payload_type_change, session);
3679 /* add rtpjitterbuffer src pad to pads */
3680 GstElementClass *klass;
3681 GstPadTemplate *templ;
3685 pad = gst_element_get_static_pad (stream->buffer, "src");
3687 /* ghost the pad to the parent */
3688 klass = GST_ELEMENT_GET_CLASS (rtpbin);
3689 templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%u_%u_%u");
3690 padname = g_strdup_printf ("recv_rtp_src_%u_%u_%u",
3691 stream->session->id, stream->ssrc, 255);
3692 gpad = gst_ghost_pad_new_from_template (padname, pad, templ);
3695 gst_pad_set_active (gpad, TRUE);
3696 gst_pad_sticky_events_foreach (pad, copy_sticky_events, gpad);
3697 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3699 gst_object_unref (pad);
3702 GST_RTP_SESSION_UNLOCK (session);
3703 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3710 GST_DEBUG_OBJECT (rtpbin, "we are shutting down");
3715 GST_RTP_SESSION_UNLOCK (session);
3716 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3717 GST_DEBUG_OBJECT (rtpbin, "could not create stream");
3723 session_maybe_create_bundle_demuxer (GstRtpBinSession * session)
3727 if (session->bundle_demux)
3730 rtpbin = session->bin;
3731 if (g_signal_has_handler_pending (rtpbin,
3732 gst_rtp_bin_signals[SIGNAL_ON_BUNDLED_SSRC], 0, TRUE)) {
3733 GST_DEBUG_OBJECT (rtpbin, "Adding a bundle SSRC demuxer to session %u",
3735 session->bundle_demux = gst_element_factory_make ("rtpssrcdemux", NULL);
3736 session->bundle_demux_newpad_sig = g_signal_connect (session->bundle_demux,
3737 "new-ssrc-pad", (GCallback) new_bundled_ssrc_pad_found, session);
3739 gst_bin_add (GST_BIN_CAST (rtpbin), session->bundle_demux);
3740 gst_element_sync_state_with_parent (session->bundle_demux);
3742 GST_DEBUG_OBJECT (rtpbin,
3743 "No handler for the on-bundled-ssrc signal so no need for a bundle SSRC demuxer in session %u",
3749 complete_session_sink (GstRtpBin * rtpbin, GstRtpBinSession * session,
3750 gboolean bundle_demuxer_needed)
3752 guint sessid = session->id;
3753 GstPad *recv_rtp_sink;
3755 GstElement *decoder;
3757 g_assert (!session->recv_rtp_sink);
3759 /* get recv_rtp pad and store */
3760 session->recv_rtp_sink =
3761 gst_element_get_request_pad (session->session, "recv_rtp_sink");
3762 if (session->recv_rtp_sink == NULL)
3765 g_signal_connect (session->recv_rtp_sink, "notify::caps",
3766 (GCallback) caps_changed, session);
3768 if (bundle_demuxer_needed)
3769 session_maybe_create_bundle_demuxer (session);
3771 GST_DEBUG_OBJECT (rtpbin, "requesting RTP decoder");
3772 decoder = session_request_element (session, SIGNAL_REQUEST_RTP_DECODER);
3774 GstPad *decsrc, *decsink;
3775 GstPadLinkReturn ret;
3777 GST_DEBUG_OBJECT (rtpbin, "linking RTP decoder");
3778 decsink = gst_element_get_static_pad (decoder, "rtp_sink");
3779 if (decsink == NULL)
3780 goto dec_sink_failed;
3782 recv_rtp_sink = decsink;
3784 decsrc = gst_element_get_static_pad (decoder, "rtp_src");
3786 goto dec_src_failed;
3788 if (session->bundle_demux) {
3790 demux_sink = gst_element_get_static_pad (session->bundle_demux, "sink");
3791 ret = gst_pad_link (decsrc, demux_sink);
3792 gst_object_unref (demux_sink);
3794 ret = gst_pad_link (decsrc, session->recv_rtp_sink);
3796 gst_object_unref (decsrc);
3798 if (ret != GST_PAD_LINK_OK)
3799 goto dec_link_failed;
3802 GST_DEBUG_OBJECT (rtpbin, "no RTP decoder given");
3803 if (session->bundle_demux) {
3805 gst_element_get_static_pad (session->bundle_demux, "sink");
3808 gst_element_get_request_pad (session->rtp_funnel, "sink_%u");
3812 funnel_src = gst_element_get_static_pad (session->rtp_funnel, "src");
3813 gst_pad_link (funnel_src, session->recv_rtp_sink);
3814 gst_object_unref (funnel_src);
3816 return recv_rtp_sink;
3821 g_warning ("rtpbin: failed to get session recv_rtp_sink pad");
3826 g_warning ("rtpbin: failed to get decoder sink pad for session %u", sessid);
3831 g_warning ("rtpbin: failed to get decoder src pad for session %u", sessid);
3832 gst_object_unref (recv_rtp_sink);
3837 g_warning ("rtpbin: failed to link rtp decoder for session %u", sessid);
3838 gst_object_unref (recv_rtp_sink);
3844 complete_session_receiver (GstRtpBin * rtpbin, GstRtpBinSession * session,
3848 GstPad *recv_rtp_src;
3850 g_assert (!session->recv_rtp_src);
3852 session->recv_rtp_src =
3853 gst_element_get_static_pad (session->session, "recv_rtp_src");
3854 if (session->recv_rtp_src == NULL)
3857 /* find out if we need AUX elements */
3858 aux = session_request_element (session, SIGNAL_REQUEST_AUX_RECEIVER);
3862 GstPadLinkReturn ret;
3864 GST_DEBUG_OBJECT (rtpbin, "linking AUX receiver");
3866 pname = g_strdup_printf ("sink_%u", sessid);
3867 auxsink = gst_element_get_static_pad (aux, pname);
3869 if (auxsink == NULL)
3870 goto aux_sink_failed;
3872 ret = gst_pad_link (session->recv_rtp_src, auxsink);
3873 gst_object_unref (auxsink);
3874 if (ret != GST_PAD_LINK_OK)
3875 goto aux_link_failed;
3877 /* this can be NULL when this AUX element is not to be linked any further */
3878 pname = g_strdup_printf ("src_%u", sessid);
3879 recv_rtp_src = gst_element_get_static_pad (aux, pname);
3882 recv_rtp_src = gst_object_ref (session->recv_rtp_src);
3885 /* Add a storage element if needed */
3886 if (recv_rtp_src && session->storage) {
3887 GstPadLinkReturn ret;
3888 GstPad *sinkpad = gst_element_get_static_pad (session->storage, "sink");
3890 ret = gst_pad_link (recv_rtp_src, sinkpad);
3892 gst_object_unref (sinkpad);
3893 gst_object_unref (recv_rtp_src);
3895 if (ret != GST_PAD_LINK_OK)
3896 goto storage_link_failed;
3898 recv_rtp_src = gst_element_get_static_pad (session->storage, "src");
3904 GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTP sink pad");
3905 sinkdpad = gst_element_get_static_pad (session->demux, "sink");
3906 GST_DEBUG_OBJECT (rtpbin, "linking demuxer RTP sink pad");
3907 gst_pad_link_full (recv_rtp_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
3908 gst_object_unref (sinkdpad);
3909 gst_object_unref (recv_rtp_src);
3911 /* connect to the new-ssrc-pad signal of the SSRC demuxer */
3912 session->demux_newpad_sig = g_signal_connect (session->demux,
3913 "new-ssrc-pad", (GCallback) new_ssrc_pad_found, session);
3914 session->demux_padremoved_sig = g_signal_connect (session->demux,
3915 "removed-ssrc-pad", (GCallback) ssrc_demux_pad_removed, session);
3922 g_warning ("rtpbin: failed to get session recv_rtp_src pad");
3927 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
3932 g_warning ("rtpbin: failed to link AUX pad to session %u", sessid);
3935 storage_link_failed:
3937 g_warning ("rtpbin: failed to link storage");
3942 /* Create a pad for receiving RTP for the session in @name. Must be called with
3946 create_recv_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
3949 GstRtpBinSession *session;
3950 GstPad *recv_rtp_sink;
3952 /* first get the session number */
3953 if (name == NULL || sscanf (name, "recv_rtp_sink_%u", &sessid) != 1)
3956 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
3958 /* get or create session */
3959 session = find_session_by_id (rtpbin, sessid);
3961 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
3962 /* create session now */
3963 session = create_session (rtpbin, sessid);
3964 if (session == NULL)
3968 /* check if pad was requested */
3969 if (session->recv_rtp_sink_ghost != NULL)
3970 return session->recv_rtp_sink_ghost;
3972 /* setup the session sink pad */
3973 recv_rtp_sink = complete_session_sink (rtpbin, session, TRUE);
3975 goto session_sink_failed;
3978 GST_DEBUG_OBJECT (rtpbin, "ghosting session sink pad");
3979 session->recv_rtp_sink_ghost =
3980 gst_ghost_pad_new_from_template (name, recv_rtp_sink, templ);
3981 gst_object_unref (recv_rtp_sink);
3982 gst_pad_set_active (session->recv_rtp_sink_ghost, TRUE);
3983 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->recv_rtp_sink_ghost);
3985 complete_session_receiver (rtpbin, session, sessid);
3987 return session->recv_rtp_sink_ghost;
3992 g_warning ("rtpbin: invalid name given");
3997 /* create_session already warned */
4000 session_sink_failed:
4002 /* warning already done */
4008 remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4010 if (session->demux_newpad_sig) {
4011 g_signal_handler_disconnect (session->demux, session->demux_newpad_sig);
4012 session->demux_newpad_sig = 0;
4014 if (session->demux_padremoved_sig) {
4015 g_signal_handler_disconnect (session->demux, session->demux_padremoved_sig);
4016 session->demux_padremoved_sig = 0;
4018 if (session->bundle_demux_newpad_sig) {
4019 g_signal_handler_disconnect (session->bundle_demux,
4020 session->bundle_demux_newpad_sig);
4021 session->bundle_demux_newpad_sig = 0;
4023 if (session->recv_rtp_src) {
4024 gst_object_unref (session->recv_rtp_src);
4025 session->recv_rtp_src = NULL;
4027 if (session->recv_rtp_sink) {
4028 gst_element_release_request_pad (session->session, session->recv_rtp_sink);
4029 gst_object_unref (session->recv_rtp_sink);
4030 session->recv_rtp_sink = NULL;
4032 if (session->recv_rtp_sink_ghost) {
4033 gst_pad_set_active (session->recv_rtp_sink_ghost, FALSE);
4034 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4035 session->recv_rtp_sink_ghost);
4036 session->recv_rtp_sink_ghost = NULL;
4041 complete_session_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session,
4042 guint sessid, gboolean bundle_demuxer_needed)
4044 GstElement *decoder;
4046 GstPad *decsink = NULL;
4049 /* get recv_rtp pad and store */
4050 GST_DEBUG_OBJECT (rtpbin, "getting RTCP sink pad");
4051 session->recv_rtcp_sink =
4052 gst_element_get_request_pad (session->session, "recv_rtcp_sink");
4053 if (session->recv_rtcp_sink == NULL)
4056 if (bundle_demuxer_needed)
4057 session_maybe_create_bundle_demuxer (session);
4059 GST_DEBUG_OBJECT (rtpbin, "getting RTCP decoder");
4060 decoder = session_request_element (session, SIGNAL_REQUEST_RTCP_DECODER);
4063 GstPadLinkReturn ret;
4065 GST_DEBUG_OBJECT (rtpbin, "linking RTCP decoder");
4066 decsink = gst_element_get_static_pad (decoder, "rtcp_sink");
4067 decsrc = gst_element_get_static_pad (decoder, "rtcp_src");
4069 if (decsink == NULL)
4070 goto dec_sink_failed;
4073 goto dec_src_failed;
4075 if (session->bundle_demux) {
4078 gst_element_get_static_pad (session->bundle_demux, "rtcp_sink");
4079 ret = gst_pad_link (decsrc, demux_sink);
4080 gst_object_unref (demux_sink);
4082 ret = gst_pad_link (decsrc, session->recv_rtcp_sink);
4084 gst_object_unref (decsrc);
4086 if (ret != GST_PAD_LINK_OK)
4087 goto dec_link_failed;
4089 GST_DEBUG_OBJECT (rtpbin, "no RTCP decoder given");
4090 if (session->bundle_demux) {
4091 decsink = gst_element_get_static_pad (session->bundle_demux, "rtcp_sink");
4093 decsink = gst_element_get_request_pad (session->rtcp_funnel, "sink_%u");
4097 /* get srcpad, link to SSRCDemux */
4098 GST_DEBUG_OBJECT (rtpbin, "getting sync src pad");
4099 session->sync_src = gst_element_get_static_pad (session->session, "sync_src");
4100 if (session->sync_src == NULL)
4101 goto src_pad_failed;
4103 GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTCP sink pad");
4104 sinkdpad = gst_element_get_static_pad (session->demux, "rtcp_sink");
4105 gst_pad_link_full (session->sync_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
4106 gst_object_unref (sinkdpad);
4108 funnel_src = gst_element_get_static_pad (session->rtcp_funnel, "src");
4109 gst_pad_link (funnel_src, session->recv_rtcp_sink);
4110 gst_object_unref (funnel_src);
4116 g_warning ("rtpbin: failed to get session rtcp_sink pad");
4121 g_warning ("rtpbin: failed to get decoder sink pad for session %u", sessid);
4126 g_warning ("rtpbin: failed to get decoder src pad for session %u", sessid);
4131 g_warning ("rtpbin: failed to link rtcp decoder for session %u", sessid);
4136 g_warning ("rtpbin: failed to get session sync_src pad");
4140 gst_object_unref (decsink);
4144 /* Create a pad for receiving RTCP for the session in @name. Must be called with
4148 create_recv_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
4152 GstRtpBinSession *session;
4153 GstPad *decsink = NULL;
4155 /* first get the session number */
4156 if (name == NULL || sscanf (name, "recv_rtcp_sink_%u", &sessid) != 1)
4159 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
4161 /* get or create the session */
4162 session = find_session_by_id (rtpbin, sessid);
4164 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4165 /* create session now */
4166 session = create_session (rtpbin, sessid);
4167 if (session == NULL)
4171 /* check if pad was requested */
4172 if (session->recv_rtcp_sink_ghost != NULL)
4173 return session->recv_rtcp_sink_ghost;
4175 decsink = complete_session_rtcp (rtpbin, session, sessid, TRUE);
4179 session->recv_rtcp_sink_ghost =
4180 gst_ghost_pad_new_from_template (name, decsink, templ);
4181 gst_object_unref (decsink);
4182 gst_pad_set_active (session->recv_rtcp_sink_ghost, TRUE);
4183 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin),
4184 session->recv_rtcp_sink_ghost);
4186 return session->recv_rtcp_sink_ghost;
4191 g_warning ("rtpbin: invalid name given");
4196 /* create_session already warned */
4202 remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4204 if (session->recv_rtcp_sink_ghost) {
4205 gst_pad_set_active (session->recv_rtcp_sink_ghost, FALSE);
4206 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4207 session->recv_rtcp_sink_ghost);
4208 session->recv_rtcp_sink_ghost = NULL;
4210 if (session->sync_src) {
4211 /* releasing the request pad should also unref the sync pad */
4212 gst_object_unref (session->sync_src);
4213 session->sync_src = NULL;
4215 if (session->recv_rtcp_sink) {
4216 gst_element_release_request_pad (session->session, session->recv_rtcp_sink);
4217 gst_object_unref (session->recv_rtcp_sink);
4218 session->recv_rtcp_sink = NULL;
4223 complete_session_src (GstRtpBin * rtpbin, GstRtpBinSession * session)
4226 guint sessid = session->id;
4227 GstPad *send_rtp_src;
4228 GstElement *encoder;
4229 GstElementClass *klass;
4230 GstPadTemplate *templ;
4231 gboolean ret = FALSE;
4234 send_rtp_src = gst_element_get_static_pad (session->session, "send_rtp_src");
4236 if (send_rtp_src == NULL)
4239 GST_DEBUG_OBJECT (rtpbin, "getting RTP encoder");
4240 encoder = session_request_element (session, SIGNAL_REQUEST_RTP_ENCODER);
4243 GstPad *encsrc, *encsink;
4244 GstPadLinkReturn ret;
4246 GST_DEBUG_OBJECT (rtpbin, "linking RTP encoder");
4247 ename = g_strdup_printf ("rtp_src_%u", sessid);
4248 encsrc = gst_element_get_static_pad (encoder, ename);
4252 goto enc_src_failed;
4254 ename = g_strdup_printf ("rtp_sink_%u", sessid);
4255 encsink = gst_element_get_static_pad (encoder, ename);
4257 if (encsink == NULL)
4258 goto enc_sink_failed;
4260 ret = gst_pad_link (send_rtp_src, encsink);
4261 gst_object_unref (encsink);
4262 gst_object_unref (send_rtp_src);
4264 send_rtp_src = encsrc;
4266 if (ret != GST_PAD_LINK_OK)
4267 goto enc_link_failed;
4269 GST_DEBUG_OBJECT (rtpbin, "no RTP encoder given");
4272 /* ghost the new source pad */
4273 klass = GST_ELEMENT_GET_CLASS (rtpbin);
4274 gname = g_strdup_printf ("send_rtp_src_%u", sessid);
4275 templ = gst_element_class_get_pad_template (klass, "send_rtp_src_%u");
4276 session->send_rtp_src_ghost =
4277 gst_ghost_pad_new_from_template (gname, send_rtp_src, templ);
4278 gst_pad_set_active (session->send_rtp_src_ghost, TRUE);
4279 gst_pad_sticky_events_foreach (send_rtp_src, copy_sticky_events,
4280 session->send_rtp_src_ghost);
4281 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_src_ghost);
4288 gst_object_unref (send_rtp_src);
4295 g_warning ("rtpbin: failed to get rtp source pad for session %u", sessid);
4300 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4301 " src pad for session %u", encoder, sessid);
4306 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4307 " sink pad for session %u", encoder, sessid);
4312 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4319 setup_aux_sender_fold (const GValue * item, GValue * result, gpointer user_data)
4324 GstRtpBinSession *session = user_data, *newsess;
4325 GstRtpBin *rtpbin = session->bin;
4326 GstPadLinkReturn ret;
4328 pad = g_value_get_object (item);
4329 name = gst_pad_get_name (pad);
4331 if (name == NULL || sscanf (name, "src_%u", &sessid) != 1)
4336 newsess = find_session_by_id (rtpbin, sessid);
4337 if (newsess == NULL) {
4338 /* create new session */
4339 newsess = create_session (rtpbin, sessid);
4340 if (newsess == NULL)
4342 } else if (newsess->send_rtp_sink != NULL)
4343 goto existing_session;
4345 /* get send_rtp pad and store */
4346 newsess->send_rtp_sink =
4347 gst_element_get_request_pad (newsess->session, "send_rtp_sink");
4348 if (newsess->send_rtp_sink == NULL)
4351 ret = gst_pad_link (pad, newsess->send_rtp_sink);
4352 if (ret != GST_PAD_LINK_OK)
4353 goto aux_link_failed;
4355 if (!complete_session_src (rtpbin, newsess))
4356 goto session_src_failed;
4363 GST_WARNING ("ignoring invalid pad name %s", GST_STR_NULL (name));
4369 /* create_session already warned */
4374 g_warning ("rtpbin: session %u is already a sender", sessid);
4379 g_warning ("rtpbin: failed to get session pad for session %u", sessid);
4384 g_warning ("rtpbin: failed to link AUX for session %u", sessid);
4389 g_warning ("rtpbin: failed to complete AUX for session %u", sessid);
4395 setup_aux_sender (GstRtpBin * rtpbin, GstRtpBinSession * session,
4399 GValue result = { 0, };
4400 GstIteratorResult res;
4402 it = gst_element_iterate_src_pads (aux);
4403 res = gst_iterator_fold (it, setup_aux_sender_fold, &result, session);
4404 gst_iterator_free (it);
4406 return res == GST_ITERATOR_DONE;
4409 /* Create a pad for sending RTP for the session in @name. Must be called with
4413 create_send_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
4417 GstPad *send_rtp_sink;
4419 GstElement *encoder;
4420 GstElement *prev = NULL;
4421 GstRtpBinSession *session;
4423 /* first get the session number */
4424 if (name == NULL || sscanf (name, "send_rtp_sink_%u", &sessid) != 1)
4427 /* get or create session */
4428 session = find_session_by_id (rtpbin, sessid);
4430 /* create session now */
4431 session = create_session (rtpbin, sessid);
4432 if (session == NULL)
4436 /* check if pad was requested */
4437 if (session->send_rtp_sink_ghost != NULL)
4438 return session->send_rtp_sink_ghost;
4440 /* check if we are already using this session as a sender */
4441 if (session->send_rtp_sink != NULL)
4442 goto existing_session;
4444 encoder = session_request_element (session, SIGNAL_REQUEST_FEC_ENCODER);
4447 GST_DEBUG_OBJECT (rtpbin, "Linking FEC encoder");
4449 send_rtp_sink = gst_element_get_static_pad (encoder, "sink");
4452 goto enc_sink_failed;
4457 GST_DEBUG_OBJECT (rtpbin, "getting RTP AUX sender");
4458 aux = session_request_element (session, SIGNAL_REQUEST_AUX_SENDER);
4461 GST_DEBUG_OBJECT (rtpbin, "linking AUX sender");
4462 if (!setup_aux_sender (rtpbin, session, aux))
4463 goto aux_session_failed;
4465 pname = g_strdup_printf ("sink_%u", sessid);
4466 sinkpad = gst_element_get_static_pad (aux, pname);
4469 if (sinkpad == NULL)
4470 goto aux_sink_failed;
4473 send_rtp_sink = sinkpad;
4475 GstPad *srcpad = gst_element_get_static_pad (prev, "src");
4476 GstPadLinkReturn ret;
4478 ret = gst_pad_link (srcpad, sinkpad);
4479 gst_object_unref (srcpad);
4480 if (ret != GST_PAD_LINK_OK) {
4481 goto aux_link_failed;
4486 /* get send_rtp pad and store */
4487 session->send_rtp_sink =
4488 gst_element_get_request_pad (session->session, "send_rtp_sink");
4489 if (session->send_rtp_sink == NULL)
4492 if (!complete_session_src (rtpbin, session))
4493 goto session_src_failed;
4496 send_rtp_sink = gst_object_ref (session->send_rtp_sink);
4498 GstPad *srcpad = gst_element_get_static_pad (prev, "src");
4499 GstPadLinkReturn ret;
4501 ret = gst_pad_link (srcpad, session->send_rtp_sink);
4502 gst_object_unref (srcpad);
4503 if (ret != GST_PAD_LINK_OK)
4504 goto session_link_failed;
4508 session->send_rtp_sink_ghost =
4509 gst_ghost_pad_new_from_template (name, send_rtp_sink, templ);
4510 gst_object_unref (send_rtp_sink);
4511 gst_pad_set_active (session->send_rtp_sink_ghost, TRUE);
4512 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_sink_ghost);
4514 return session->send_rtp_sink_ghost;
4519 g_warning ("rtpbin: invalid name given");
4524 /* create_session already warned */
4529 g_warning ("rtpbin: session %u is already in use", sessid);
4534 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
4539 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
4544 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4550 g_warning ("rtpbin: failed to get session pad for session %u", sessid);
4555 g_warning ("rtpbin: failed to setup source pads for session %u", sessid);
4558 session_link_failed:
4560 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4566 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4567 " sink pad for session %u", encoder, sessid);
4573 remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4575 if (session->send_rtp_src_ghost) {
4576 gst_pad_set_active (session->send_rtp_src_ghost, FALSE);
4577 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4578 session->send_rtp_src_ghost);
4579 session->send_rtp_src_ghost = NULL;
4581 if (session->send_rtp_sink) {
4582 gst_element_release_request_pad (GST_ELEMENT_CAST (session->session),
4583 session->send_rtp_sink);
4584 gst_object_unref (session->send_rtp_sink);
4585 session->send_rtp_sink = NULL;
4587 if (session->send_rtp_sink_ghost) {
4588 gst_pad_set_active (session->send_rtp_sink_ghost, FALSE);
4589 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4590 session->send_rtp_sink_ghost);
4591 session->send_rtp_sink_ghost = NULL;
4595 /* Create a pad for sending RTCP for the session in @name. Must be called with
4599 create_send_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
4604 GstElement *encoder;
4605 GstRtpBinSession *session;
4607 /* first get the session number */
4608 if (name == NULL || sscanf (name, "send_rtcp_src_%u", &sessid) != 1)
4611 /* get or create session */
4612 session = find_session_by_id (rtpbin, sessid);
4614 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4615 /* create session now */
4616 session = create_session (rtpbin, sessid);
4617 if (session == NULL)
4621 /* check if pad was requested */
4622 if (session->send_rtcp_src_ghost != NULL)
4623 return session->send_rtcp_src_ghost;
4625 /* get rtcp_src pad and store */
4626 session->send_rtcp_src =
4627 gst_element_get_request_pad (session->session, "send_rtcp_src");
4628 if (session->send_rtcp_src == NULL)
4631 GST_DEBUG_OBJECT (rtpbin, "getting RTCP encoder");
4632 encoder = session_request_element (session, SIGNAL_REQUEST_RTCP_ENCODER);
4636 GstPadLinkReturn ret;
4638 GST_DEBUG_OBJECT (rtpbin, "linking RTCP encoder");
4640 ename = g_strdup_printf ("rtcp_src_%u", sessid);
4641 encsrc = gst_element_get_static_pad (encoder, ename);
4644 goto enc_src_failed;
4646 ename = g_strdup_printf ("rtcp_sink_%u", sessid);
4647 encsink = gst_element_get_static_pad (encoder, ename);
4649 if (encsink == NULL)
4650 goto enc_sink_failed;
4652 ret = gst_pad_link (session->send_rtcp_src, encsink);
4653 gst_object_unref (encsink);
4655 if (ret != GST_PAD_LINK_OK)
4656 goto enc_link_failed;
4658 GST_DEBUG_OBJECT (rtpbin, "no RTCP encoder given");
4659 encsrc = gst_object_ref (session->send_rtcp_src);
4662 session->send_rtcp_src_ghost =
4663 gst_ghost_pad_new_from_template (name, encsrc, templ);
4664 gst_object_unref (encsrc);
4665 gst_pad_set_active (session->send_rtcp_src_ghost, TRUE);
4666 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtcp_src_ghost);
4668 return session->send_rtcp_src_ghost;
4673 g_warning ("rtpbin: invalid name given");
4678 /* create_session already warned */
4683 g_warning ("rtpbin: failed to get rtcp pad for session %u", sessid);
4688 g_warning ("rtpbin: failed to get encoder src pad for session %u", sessid);
4693 g_warning ("rtpbin: failed to get encoder sink pad for session %u", sessid);
4694 gst_object_unref (encsrc);
4699 g_warning ("rtpbin: failed to link rtcp encoder for session %u", sessid);
4700 gst_object_unref (encsrc);
4706 remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4708 if (session->send_rtcp_src_ghost) {
4709 gst_pad_set_active (session->send_rtcp_src_ghost, FALSE);
4710 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4711 session->send_rtcp_src_ghost);
4712 session->send_rtcp_src_ghost = NULL;
4714 if (session->send_rtcp_src) {
4715 gst_element_release_request_pad (session->session, session->send_rtcp_src);
4716 gst_object_unref (session->send_rtcp_src);
4717 session->send_rtcp_src = NULL;
4721 /* If the requested name is NULL we should create a name with
4722 * the session number assuming we want the lowest posible session
4723 * with a free pad like the template */
4725 gst_rtp_bin_get_free_pad_name (GstElement * element, GstPadTemplate * templ)
4727 gboolean name_found = FALSE;
4729 GstIterator *pad_it = NULL;
4730 gchar *pad_name = NULL;
4731 GValue data = { 0, };
4733 GST_DEBUG_OBJECT (element, "find a free pad name for template");
4734 while (!name_found) {
4735 gboolean done = FALSE;
4738 pad_name = g_strdup_printf (templ->name_template, session++);
4739 pad_it = gst_element_iterate_pads (GST_ELEMENT (element));
4742 switch (gst_iterator_next (pad_it, &data)) {
4743 case GST_ITERATOR_OK:
4748 pad = g_value_get_object (&data);
4749 name = gst_pad_get_name (pad);
4751 if (strcmp (name, pad_name) == 0) {
4756 g_value_reset (&data);
4759 case GST_ITERATOR_ERROR:
4760 case GST_ITERATOR_RESYNC:
4761 /* restart iteration */
4766 case GST_ITERATOR_DONE:
4771 g_value_unset (&data);
4772 gst_iterator_free (pad_it);
4775 GST_DEBUG_OBJECT (element, "free pad name found: '%s'", pad_name);
4782 gst_rtp_bin_request_new_pad (GstElement * element,
4783 GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
4786 GstElementClass *klass;
4789 gchar *pad_name = NULL;
4791 g_return_val_if_fail (templ != NULL, NULL);
4792 g_return_val_if_fail (GST_IS_RTP_BIN (element), NULL);
4794 rtpbin = GST_RTP_BIN (element);
4795 klass = GST_ELEMENT_GET_CLASS (element);
4797 GST_RTP_BIN_LOCK (rtpbin);
4800 /* use a free pad name */
4801 pad_name = gst_rtp_bin_get_free_pad_name (element, templ);
4803 /* use the provided name */
4804 pad_name = g_strdup (name);
4807 GST_DEBUG_OBJECT (rtpbin, "Trying to request a pad with name %s", pad_name);
4809 /* figure out the template */
4810 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink_%u")) {
4811 result = create_recv_rtp (rtpbin, templ, pad_name);
4812 } else if (templ == gst_element_class_get_pad_template (klass,
4813 "recv_rtcp_sink_%u")) {
4814 result = create_recv_rtcp (rtpbin, templ, pad_name);
4815 } else if (templ == gst_element_class_get_pad_template (klass,
4816 "send_rtp_sink_%u")) {
4817 result = create_send_rtp (rtpbin, templ, pad_name);
4818 } else if (templ == gst_element_class_get_pad_template (klass,
4819 "send_rtcp_src_%u")) {
4820 result = create_send_rtcp (rtpbin, templ, pad_name);
4822 goto wrong_template;
4825 GST_RTP_BIN_UNLOCK (rtpbin);
4833 GST_RTP_BIN_UNLOCK (rtpbin);
4834 g_warning ("rtpbin: this is not our template");
4840 gst_rtp_bin_release_pad (GstElement * element, GstPad * pad)
4842 GstRtpBinSession *session;
4845 g_return_if_fail (GST_IS_GHOST_PAD (pad));
4846 g_return_if_fail (GST_IS_RTP_BIN (element));
4848 rtpbin = GST_RTP_BIN (element);
4850 GST_RTP_BIN_LOCK (rtpbin);
4851 GST_DEBUG_OBJECT (rtpbin, "Trying to release pad %s:%s",
4852 GST_DEBUG_PAD_NAME (pad));
4854 if (!(session = find_session_by_pad (rtpbin, pad)))
4857 if (session->recv_rtp_sink_ghost == pad) {
4858 remove_recv_rtp (rtpbin, session);
4859 } else if (session->recv_rtcp_sink_ghost == pad) {
4860 remove_recv_rtcp (rtpbin, session);
4861 } else if (session->send_rtp_sink_ghost == pad) {
4862 remove_send_rtp (rtpbin, session);
4863 } else if (session->send_rtcp_src_ghost == pad) {
4864 remove_rtcp (rtpbin, session);
4867 /* no more request pads, free the complete session */
4868 if (session->recv_rtp_sink_ghost == NULL
4869 && session->recv_rtcp_sink_ghost == NULL
4870 && session->send_rtp_sink_ghost == NULL
4871 && session->send_rtcp_src_ghost == NULL) {
4872 GST_DEBUG_OBJECT (rtpbin, "no more pads for session %p", session);
4873 rtpbin->sessions = g_slist_remove (rtpbin->sessions, session);
4874 free_session (session, rtpbin);
4876 GST_RTP_BIN_UNLOCK (rtpbin);
4883 GST_RTP_BIN_UNLOCK (rtpbin);
4884 g_warning ("rtpbin: %s:%s is not one of our request pads",
4885 GST_DEBUG_PAD_NAME (pad));