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
23 * @see_also: rtpjitterbuffer, rtpsession, rtpptdemux, rtpssrcdemux
25 * RTP bin combines the functions of #GstRtpSession, #GstRtpSsrcDemux,
26 * #GstRtpJitterBuffer and #GstRtpPtDemux in one element. It allows for multiple
27 * RTP sessions that will be synchronized together using RTCP SR packets.
29 * #GstRtpBin is configured with a number of request pads that define the
30 * functionality that is activated, similar to the #GstRtpSession element.
32 * To use #GstRtpBin as an RTP receiver, request a recv_rtp_sink_\%u pad. The session
33 * number must be specified in the pad name.
34 * Data received on the recv_rtp_sink_\%u pad will be processed in the #GstRtpSession
35 * manager and after being validated forwarded on #GstRtpSsrcDemux element. Each
36 * RTP stream is demuxed based on the SSRC and send to a #GstRtpJitterBuffer. After
37 * the packets are released from the jitterbuffer, they will be forwarded to a
38 * #GstRtpPtDemux element. The #GstRtpPtDemux element will demux the packets based
39 * on the payload type and will create a unique pad recv_rtp_src_\%u_\%u_\%u on
40 * rtpbin with the session number, SSRC and payload type respectively as the pad
43 * To also use #GstRtpBin as an RTCP receiver, request a recv_rtcp_sink_\%u pad. The
44 * session number must be specified in the pad name.
46 * If you want the session manager to generate and send RTCP packets, request
47 * the send_rtcp_src_\%u pad with the session number in the pad name. Packet pushed
48 * on this pad contain SR/RR RTCP reports that should be sent to all participants
51 * To use #GstRtpBin as a sender, request a send_rtp_sink_\%u pad, which will
52 * automatically create a send_rtp_src_\%u pad. If the session number is not provided,
53 * the pad from the lowest available session will be returned. The session manager will modify the
54 * SSRC in the RTP packets to its own SSRC and will forward the packets on the
55 * send_rtp_src_\%u pad after updating its internal state.
57 * The session manager needs the clock-rate of the payload types it is handling
58 * and will signal the #GstRtpSession::request-pt-map signal when it needs such a
59 * mapping. One can clear the cached values with the #GstRtpSession::clear-pt-map
62 * Access to the internal statistics of rtpbin is provided with the
63 * get-internal-session property. This action signal gives access to the
64 * RTPSession object which further provides action signals to retrieve the
65 * internal source and other sources.
67 * #GstRtpBin also has signals (#GstRtpBin::request-rtp-encoder,
68 * #GstRtpBin::request-rtp-decoder, #GstRtpBin::request-rtcp-encoder and
69 * #GstRtpBin::request-rtp-decoder) to dynamically request for RTP and RTCP encoders
70 * and decoders in order to support SRTP. The encoders must provide the pads
71 * rtp_sink_\%u and rtp_src_\%u for RTP and rtcp_sink_\%u and rtcp_src_\%u for
72 * RTCP. The session number will be used in the pad name. The decoders must provide
73 * rtp_sink and rtp_src for RTP and rtcp_sink and rtcp_src for RTCP. The decoders will
74 * be placed before the #GstRtpSession element, thus they must support SSRC demuxing
77 * #GstRtpBin has signals (#GstRtpBin::request-aux-sender and
78 * #GstRtpBin::request-aux-receiver to dynamically request an element that can be
79 * used to create or merge additional RTP streams. AUX elements are needed to
80 * implement FEC or retransmission (such as RFC 4588). An AUX sender must have one
81 * sink_\%u pad that matches the sessionid in the signal and it should have 1 or
82 * more src_\%u pads. For each src_%\u pad, a session will be made (if needed)
83 * and the pad will be linked to the session send_rtp_sink pad. Each session will
84 * then expose its source pad as send_rtp_src_\%u on #GstRtpBin.
85 * An AUX receiver has 1 src_\%u pad that much match the sessionid in the signal
86 * and 1 or more sink_\%u pads. A session will be made for each sink_\%u pad
87 * when the corresponding recv_rtp_sink_\%u pad is requested on #GstRtpBin.
88 * The #GstRtpBin::request-jitterbuffer signal can be used to provide a custom
89 * element to perform arrival time smoothing, reordering and optionally packet
90 * loss detection and retransmission requests.
92 * ## Example pipelines
95 * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink_0 \
96 * rtpbin ! rtptheoradepay ! theoradec ! xvimagesink
97 * ]| Receive RTP data from port 5000 and send to the session 0 in rtpbin.
99 * gst-launch-1.0 rtpbin name=rtpbin \
100 * v4l2src ! videoconvert ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \
101 * rtpbin.send_rtp_src_0 ! udpsink port=5000 \
102 * rtpbin.send_rtcp_src_0 ! udpsink port=5001 sync=false async=false \
103 * udpsrc port=5005 ! rtpbin.recv_rtcp_sink_0 \
104 * audiotestsrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_1 \
105 * rtpbin.send_rtp_src_1 ! udpsink port=5002 \
106 * rtpbin.send_rtcp_src_1 ! udpsink port=5003 sync=false async=false \
107 * udpsrc port=5007 ! rtpbin.recv_rtcp_sink_1
108 * ]| Encode and payload H263 video captured from a v4l2src. Encode and payload AMR
109 * audio generated from audiotestsrc. The video is sent to session 0 in rtpbin
110 * and the audio is sent to session 1. Video packets are sent on UDP port 5000
111 * and audio packets on port 5002. The video RTCP packets for session 0 are sent
112 * on port 5001 and the audio RTCP packets for session 0 are sent on port 5003.
113 * RTCP packets for session 0 are received on port 5005 and RTCP for session 1
114 * is received on port 5007. Since RTCP packets from the sender should be sent
115 * as soon as possible and do not participate in preroll, sync=false and
116 * async=false is configured on udpsink
118 * gst-launch-1.0 -v rtpbin name=rtpbin \
119 * udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H263-1998" \
120 * port=5000 ! rtpbin.recv_rtp_sink_0 \
121 * rtpbin. ! rtph263pdepay ! ffdec_h263 ! xvimagesink \
122 * udpsrc port=5001 ! rtpbin.recv_rtcp_sink_0 \
123 * rtpbin.send_rtcp_src_0 ! udpsink port=5005 sync=false async=false \
124 * udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" \
125 * port=5002 ! rtpbin.recv_rtp_sink_1 \
126 * rtpbin. ! rtpamrdepay ! amrnbdec ! alsasink \
127 * udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1 \
128 * rtpbin.send_rtcp_src_1 ! udpsink port=5007 sync=false async=false
129 * ]| Receive H263 on port 5000, send it through rtpbin in session 0, depayload,
130 * decode and display the video.
131 * Receive AMR on port 5002, send it through rtpbin in session 1, depayload,
132 * decode and play the audio.
133 * Receive server RTCP packets for session 0 on port 5001 and RTCP packets for
134 * session 1 on port 5003. These packets will be used for session management and
136 * Send RTCP reports for session 0 on port 5005 and RTCP reports for session 1
147 #include <gst/rtp/gstrtpbuffer.h>
148 #include <gst/rtp/gstrtcpbuffer.h>
150 #include "gstrtpbin.h"
151 #include "rtpsession.h"
152 #include "gstrtpsession.h"
153 #include "gstrtpjitterbuffer.h"
155 #include <gst/glib-compat-private.h>
157 GST_DEBUG_CATEGORY_STATIC (gst_rtp_bin_debug);
158 #define GST_CAT_DEFAULT gst_rtp_bin_debug
161 static GstStaticPadTemplate rtpbin_recv_rtp_sink_template =
162 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%u",
165 GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
169 * GstRtpBin!recv_fec_sink_%u_%u:
171 * Sink template for receiving Forward Error Correction packets,
172 * in the form recv_fec_sink_<session_idx>_<fec_stream_idx>
174 * See #GstRTPST_2022_1_FecDec for example usage
178 static GstStaticPadTemplate rtpbin_recv_fec_sink_template =
179 GST_STATIC_PAD_TEMPLATE ("recv_fec_sink_%u_%u",
182 GST_STATIC_CAPS ("application/x-rtp")
186 * GstRtpBin!send_fec_src_%u_%u:
188 * Src template for sending Forward Error Correction packets,
189 * in the form send_fec_src_<session_idx>_<fec_stream_idx>
191 * See #GstRTPST_2022_1_FecEnc for example usage
195 static GstStaticPadTemplate rtpbin_send_fec_src_template =
196 GST_STATIC_PAD_TEMPLATE ("send_fec_src_%u_%u",
199 GST_STATIC_CAPS ("application/x-rtp")
202 static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
203 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%u",
206 GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
209 static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
210 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink_%u",
213 GST_STATIC_CAPS ("application/x-rtp")
217 static GstStaticPadTemplate rtpbin_recv_rtp_src_template =
218 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%u_%u_%u",
221 GST_STATIC_CAPS ("application/x-rtp")
224 static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
225 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%u",
228 GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
231 static GstStaticPadTemplate rtpbin_send_rtp_src_template =
232 GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%u",
235 GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
238 #define GST_RTP_BIN_LOCK(bin) g_mutex_lock (&(bin)->priv->bin_lock)
239 #define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->bin_lock)
241 /* lock to protect dynamic callbacks, like pad-added and new ssrc. */
242 #define GST_RTP_BIN_DYN_LOCK(bin) g_mutex_lock (&(bin)->priv->dyn_lock)
243 #define GST_RTP_BIN_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->dyn_lock)
245 /* lock for shutdown */
246 #define GST_RTP_BIN_SHUTDOWN_LOCK(bin,label) \
248 if (g_atomic_int_get (&bin->priv->shutdown)) \
250 GST_RTP_BIN_DYN_LOCK (bin); \
251 if (g_atomic_int_get (&bin->priv->shutdown)) { \
252 GST_RTP_BIN_DYN_UNLOCK (bin); \
257 /* unlock for shutdown */
258 #define GST_RTP_BIN_SHUTDOWN_UNLOCK(bin) \
259 GST_RTP_BIN_DYN_UNLOCK (bin); \
261 /* Minimum time offset to apply. This compensates for rounding errors in NTP to
262 * RTP timestamp conversions */
263 #define MIN_TS_OFFSET_ROUND_OFF_COMP (4 * GST_MSECOND)
265 struct _GstRtpBinPrivate
269 /* lock protecting dynamic adding/removing */
272 /* if we are shutting down or not */
277 /* NTP time in ns of last SR sync used */
278 guint64 last_ntpnstime;
280 /* list of extra elements */
284 /* signals and args */
287 SIGNAL_REQUEST_PT_MAP,
288 SIGNAL_PAYLOAD_TYPE_CHANGE,
292 SIGNAL_GET_INTERNAL_SESSION,
294 SIGNAL_GET_INTERNAL_STORAGE,
298 SIGNAL_ON_SSRC_COLLISION,
299 SIGNAL_ON_SSRC_VALIDATED,
300 SIGNAL_ON_SSRC_ACTIVE,
303 SIGNAL_ON_BYE_TIMEOUT,
305 SIGNAL_ON_SENDER_TIMEOUT,
308 SIGNAL_REQUEST_RTP_ENCODER,
309 SIGNAL_REQUEST_RTP_DECODER,
310 SIGNAL_REQUEST_RTCP_ENCODER,
311 SIGNAL_REQUEST_RTCP_DECODER,
313 SIGNAL_REQUEST_FEC_DECODER,
314 SIGNAL_REQUEST_FEC_DECODER_FULL,
315 SIGNAL_REQUEST_FEC_ENCODER,
317 SIGNAL_REQUEST_JITTERBUFFER,
319 SIGNAL_NEW_JITTERBUFFER,
322 SIGNAL_REQUEST_AUX_SENDER,
323 SIGNAL_REQUEST_AUX_RECEIVER,
325 SIGNAL_ON_NEW_SENDER_SSRC,
326 SIGNAL_ON_SENDER_SSRC_ACTIVE,
328 SIGNAL_ON_BUNDLED_SSRC,
333 #define DEFAULT_LATENCY_MS 200
334 #define DEFAULT_DROP_ON_LATENCY FALSE
335 #define DEFAULT_SDES NULL
336 #define DEFAULT_DO_LOST FALSE
337 #define DEFAULT_IGNORE_PT FALSE
338 #define DEFAULT_NTP_SYNC FALSE
339 #define DEFAULT_AUTOREMOVE FALSE
340 #define DEFAULT_BUFFER_MODE RTP_JITTER_BUFFER_MODE_SLAVE
341 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
342 #define DEFAULT_RTCP_SYNC GST_RTP_BIN_RTCP_SYNC_ALWAYS
343 #define DEFAULT_RTCP_SYNC_INTERVAL 0
344 #define DEFAULT_DO_SYNC_EVENT FALSE
345 #define DEFAULT_DO_RETRANSMISSION FALSE
346 #define DEFAULT_RTP_PROFILE GST_RTP_PROFILE_AVP
347 #define DEFAULT_NTP_TIME_SOURCE GST_RTP_NTP_TIME_SOURCE_NTP
348 #define DEFAULT_RTCP_SYNC_SEND_TIME TRUE
349 #define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
350 #define DEFAULT_MAX_DROPOUT_TIME 60000
351 #define DEFAULT_MAX_MISORDER_TIME 2000
352 #define DEFAULT_RFC7273_SYNC FALSE
353 #define DEFAULT_MAX_STREAMS G_MAXUINT
354 #define DEFAULT_MAX_TS_OFFSET_ADJUSTMENT G_GUINT64_CONSTANT(0)
355 #define DEFAULT_MAX_TS_OFFSET G_GINT64_CONSTANT(3000000000)
356 #define DEFAULT_MIN_TS_OFFSET MIN_TS_OFFSET_ROUND_OFF_COMP
357 #define DEFAULT_TS_OFFSET_SMOOTHING_FACTOR 0
363 PROP_DROP_ON_LATENCY,
369 PROP_RTCP_SYNC_INTERVAL,
372 PROP_USE_PIPELINE_CLOCK,
374 PROP_DO_RETRANSMISSION,
376 PROP_NTP_TIME_SOURCE,
377 PROP_RTCP_SYNC_SEND_TIME,
378 PROP_MAX_RTCP_RTP_TIME_DIFF,
379 PROP_MAX_DROPOUT_TIME,
380 PROP_MAX_MISORDER_TIME,
383 PROP_MAX_TS_OFFSET_ADJUSTMENT,
386 PROP_TS_OFFSET_SMOOTHING_FACTOR,
391 #define GST_RTP_BIN_RTCP_SYNC_TYPE (gst_rtp_bin_rtcp_sync_get_type())
393 gst_rtp_bin_rtcp_sync_get_type (void)
395 static GType rtcp_sync_type = 0;
396 static const GEnumValue rtcp_sync_types[] = {
397 {GST_RTP_BIN_RTCP_SYNC_ALWAYS, "always", "always"},
398 {GST_RTP_BIN_RTCP_SYNC_INITIAL, "initial", "initial"},
399 {GST_RTP_BIN_RTCP_SYNC_RTP, "rtp-info", "rtp-info"},
403 if (!rtcp_sync_type) {
404 rtcp_sync_type = g_enum_register_static ("GstRTCPSync", rtcp_sync_types);
406 return rtcp_sync_type;
410 typedef struct _GstRtpBinSession GstRtpBinSession;
411 typedef struct _GstRtpBinStream GstRtpBinStream;
412 typedef struct _GstRtpBinClient GstRtpBinClient;
414 static guint gst_rtp_bin_signals[LAST_SIGNAL] = { 0 };
416 static GstCaps *pt_map_requested (GstElement * element, guint pt,
417 GstRtpBinSession * session);
418 static void payload_type_change (GstElement * element, guint pt,
419 GstRtpBinSession * session);
420 static void remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
421 static void remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
422 static void remove_recv_fec (GstRtpBin * rtpbin, GstRtpBinSession * session);
423 static void remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
424 static void remove_send_fec (GstRtpBin * rtpbin, GstRtpBinSession * session);
425 static void remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
426 static void free_client (GstRtpBinClient * client, GstRtpBin * bin);
427 static void free_stream (GstRtpBinStream * stream, GstRtpBin * bin);
428 static GstRtpBinSession *create_session (GstRtpBin * rtpbin, gint id);
429 static GstPad *complete_session_sink (GstRtpBin * rtpbin,
430 GstRtpBinSession * session);
432 complete_session_receiver (GstRtpBin * rtpbin, GstRtpBinSession * session,
434 static GstPad *complete_session_rtcp (GstRtpBin * rtpbin,
435 GstRtpBinSession * session, guint sessid);
436 static GstElement *session_request_element (GstRtpBinSession * session,
439 /* Manages the RTP stream for one SSRC.
441 * We pipe the stream (coming from the SSRC demuxer) into a jitterbuffer.
442 * If we see an SDES RTCP packet that links multiple SSRCs together based on a
443 * common CNAME, we create a GstRtpBinClient structure to group the SSRCs
444 * together (see below).
446 struct _GstRtpBinStream
448 /* the SSRC of this stream */
454 /* the session this SSRC belongs to */
455 GstRtpBinSession *session;
457 /* the jitterbuffer of the SSRC */
459 gulong buffer_handlesync_sig;
460 gulong buffer_ptreq_sig;
461 gulong buffer_ntpstop_sig;
464 /* the PT demuxer of the SSRC */
466 gulong demux_newpad_sig;
467 gulong demux_padremoved_sig;
468 gulong demux_ptreq_sig;
469 gulong demux_ptchange_sig;
471 /* if we have calculated a valid rt_delta for this stream */
473 /* mapping to local RTP and NTP time */
476 gint64 avg_ts_offset;
477 gboolean is_initialized;
478 /* base rtptime in gst time */
482 #define GST_RTP_SESSION_LOCK(sess) g_mutex_lock (&(sess)->lock)
483 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock (&(sess)->lock)
485 /* Manages the receiving end of the packets.
487 * There is one such structure for each RTP session (audio/video/...).
488 * We get the RTP/RTCP packets and stuff them into the session manager. From
489 * there they are pushed into an SSRC demuxer that splits the stream based on
490 * SSRC. Each of the SSRC streams go into their own jitterbuffer (managed with
491 * the GstRtpBinStream above).
493 * Before the SSRC demuxer, a storage element may be inserted for the purpose
494 * of Forward Error Correction.
496 struct _GstRtpBinSession
502 /* the session element */
504 /* the SSRC demuxer */
506 gulong demux_newpad_sig;
507 gulong demux_padremoved_sig;
514 /* list of GstRtpBinStream */
517 /* list of elements */
520 /* mapping of payload type to caps */
523 /* the pads of the session */
524 GstPad *recv_rtp_sink;
525 GstPad *recv_rtp_sink_ghost;
526 GstPad *recv_rtp_src;
527 GstPad *recv_rtcp_sink;
528 GstPad *recv_rtcp_sink_ghost;
530 GstPad *send_rtp_sink;
531 GstPad *send_rtp_sink_ghost;
532 GstPad *send_rtp_src_ghost;
533 GstPad *send_rtcp_src;
534 GstPad *send_rtcp_src_ghost;
536 GSList *recv_fec_sinks;
537 GSList *recv_fec_sink_ghosts;
538 /* fec decoder placed before the rtpjitterbuffer but after the rtpssrcdemux.
539 * XXX: This does not yet support multiple ssrc's in the same rtp session
541 GstElement *early_fec_decoder;
543 GSList *send_fec_src_ghosts;
546 /* Manages the RTP streams that come from one client and should therefore be
549 struct _GstRtpBinClient
551 /* the common CNAME for the streams */
560 /* find a session with the given id. Must be called with RTP_BIN_LOCK */
561 static GstRtpBinSession *
562 find_session_by_id (GstRtpBin * rtpbin, gint id)
566 for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
567 GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
576 pad_is_recv_fec (GstRtpBinSession * session, GstPad * pad)
578 return g_slist_find (session->recv_fec_sink_ghosts, pad) != NULL;
581 /* find a session with the given request pad. Must be called with RTP_BIN_LOCK */
582 static GstRtpBinSession *
583 find_session_by_pad (GstRtpBin * rtpbin, GstPad * pad)
587 for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
588 GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
590 if ((sess->recv_rtp_sink_ghost == pad) ||
591 (sess->recv_rtcp_sink_ghost == pad) ||
592 (sess->send_rtp_sink_ghost == pad) ||
593 (sess->send_rtcp_src_ghost == pad) || pad_is_recv_fec (sess, pad))
600 on_new_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
602 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC], 0,
607 on_ssrc_collision (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
609 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION], 0,
614 on_ssrc_validated (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
616 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
621 on_ssrc_active (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
623 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
628 on_ssrc_sdes (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
630 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES], 0,
635 on_bye_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
637 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC], 0,
642 on_bye_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
644 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
647 if (sess->bin->priv->autoremove)
648 g_signal_emit_by_name (sess->demux, "clear-ssrc", ssrc, NULL);
652 on_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
654 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT], 0,
657 if (sess->bin->priv->autoremove)
658 g_signal_emit_by_name (sess->demux, "clear-ssrc", ssrc, NULL);
662 on_sender_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
664 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
669 on_npt_stop (GstElement * jbuf, GstRtpBinStream * stream)
671 g_signal_emit (stream->bin, gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP], 0,
672 stream->session->id, stream->ssrc);
676 on_new_sender_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
678 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SENDER_SSRC], 0,
683 on_sender_ssrc_active (GstElement * session, guint32 ssrc,
684 GstRtpBinSession * sess)
686 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE],
690 /* must be called with the SESSION lock */
691 static GstRtpBinStream *
692 find_stream_by_ssrc (GstRtpBinSession * session, guint32 ssrc)
696 for (walk = session->streams; walk; walk = g_slist_next (walk)) {
697 GstRtpBinStream *stream = (GstRtpBinStream *) walk->data;
699 if (stream->ssrc == ssrc)
706 ssrc_demux_pad_removed (GstElement * element, guint ssrc, GstPad * pad,
707 GstRtpBinSession * session)
709 GstRtpBinStream *stream = NULL;
712 rtpbin = session->bin;
714 GST_RTP_BIN_LOCK (rtpbin);
716 GST_RTP_SESSION_LOCK (session);
717 if ((stream = find_stream_by_ssrc (session, ssrc)))
718 session->streams = g_slist_remove (session->streams, stream);
719 GST_RTP_SESSION_UNLOCK (session);
722 free_stream (stream, rtpbin);
724 GST_RTP_BIN_UNLOCK (rtpbin);
727 /* create a session with the given id. Must be called with RTP_BIN_LOCK */
728 static GstRtpBinSession *
729 create_session (GstRtpBin * rtpbin, gint id)
731 GstRtpBinSession *sess;
732 GstElement *session, *demux;
733 GstElement *storage = NULL;
736 if (!(session = gst_element_factory_make ("rtpsession", NULL)))
739 if (!(demux = gst_element_factory_make ("rtpssrcdemux", NULL)))
742 if (!(storage = gst_element_factory_make ("rtpstorage", NULL)))
745 /* need to sink the storage or otherwise signal handlers from bindings will
746 * take ownership of it and we don't own it anymore */
747 gst_object_ref_sink (storage);
748 g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_STORAGE], 0, storage,
751 sess = g_new0 (GstRtpBinSession, 1);
752 g_mutex_init (&sess->lock);
755 sess->session = session;
757 sess->storage = storage;
759 sess->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
760 (GDestroyNotify) gst_caps_unref);
761 rtpbin->sessions = g_slist_prepend (rtpbin->sessions, sess);
763 /* configure SDES items */
764 GST_OBJECT_LOCK (rtpbin);
765 g_object_set (demux, "max-streams", rtpbin->max_streams, NULL);
766 g_object_set (session, "sdes", rtpbin->sdes, "rtp-profile",
767 rtpbin->rtp_profile, "rtcp-sync-send-time", rtpbin->rtcp_sync_send_time,
769 if (rtpbin->use_pipeline_clock)
770 g_object_set (session, "use-pipeline-clock", rtpbin->use_pipeline_clock,
773 g_object_set (session, "ntp-time-source", rtpbin->ntp_time_source, NULL);
775 g_object_set (session, "max-dropout-time", rtpbin->max_dropout_time,
776 "max-misorder-time", rtpbin->max_misorder_time, NULL);
777 GST_OBJECT_UNLOCK (rtpbin);
779 /* provide clock_rate to the session manager when needed */
780 g_signal_connect (session, "request-pt-map",
781 (GCallback) pt_map_requested, sess);
783 g_signal_connect (sess->session, "on-new-ssrc",
784 (GCallback) on_new_ssrc, sess);
785 g_signal_connect (sess->session, "on-ssrc-collision",
786 (GCallback) on_ssrc_collision, sess);
787 g_signal_connect (sess->session, "on-ssrc-validated",
788 (GCallback) on_ssrc_validated, sess);
789 g_signal_connect (sess->session, "on-ssrc-active",
790 (GCallback) on_ssrc_active, sess);
791 g_signal_connect (sess->session, "on-ssrc-sdes",
792 (GCallback) on_ssrc_sdes, sess);
793 g_signal_connect (sess->session, "on-bye-ssrc",
794 (GCallback) on_bye_ssrc, sess);
795 g_signal_connect (sess->session, "on-bye-timeout",
796 (GCallback) on_bye_timeout, sess);
797 g_signal_connect (sess->session, "on-timeout", (GCallback) on_timeout, sess);
798 g_signal_connect (sess->session, "on-sender-timeout",
799 (GCallback) on_sender_timeout, sess);
800 g_signal_connect (sess->session, "on-new-sender-ssrc",
801 (GCallback) on_new_sender_ssrc, sess);
802 g_signal_connect (sess->session, "on-sender-ssrc-active",
803 (GCallback) on_sender_ssrc_active, sess);
805 gst_bin_add (GST_BIN_CAST (rtpbin), session);
806 gst_bin_add (GST_BIN_CAST (rtpbin), demux);
807 gst_bin_add (GST_BIN_CAST (rtpbin), storage);
809 /* unref the storage again, the bin has a reference now and
810 * we don't need it anymore */
811 gst_object_unref (storage);
813 GST_OBJECT_LOCK (rtpbin);
814 target = GST_STATE_TARGET (rtpbin);
815 GST_OBJECT_UNLOCK (rtpbin);
817 /* change state only to what's needed */
818 gst_element_set_state (demux, target);
819 gst_element_set_state (session, target);
820 gst_element_set_state (storage, target);
827 g_warning ("rtpbin: could not create rtpsession element");
832 gst_object_unref (session);
833 g_warning ("rtpbin: could not create rtpssrcdemux element");
838 gst_object_unref (session);
839 gst_object_unref (demux);
840 g_warning ("rtpbin: could not create rtpstorage element");
846 bin_manage_element (GstRtpBin * bin, GstElement * element)
848 GstRtpBinPrivate *priv = bin->priv;
850 if (g_list_find (priv->elements, element)) {
851 GST_DEBUG_OBJECT (bin, "requested element %p already in bin", element);
853 GST_DEBUG_OBJECT (bin, "adding requested element %p", element);
855 if (g_object_is_floating (element))
856 element = gst_object_ref_sink (element);
858 if (!gst_bin_add (GST_BIN_CAST (bin), element))
860 if (!gst_element_sync_state_with_parent (element))
861 GST_WARNING_OBJECT (bin, "unable to sync element state with rtpbin");
863 /* we add the element multiple times, each we need an equal number of
864 * removes to really remove the element from the bin */
865 priv->elements = g_list_prepend (priv->elements, element);
872 GST_WARNING_OBJECT (bin, "unable to add element");
873 gst_object_unref (element);
879 remove_bin_element (GstElement * element, GstRtpBin * bin)
881 GstRtpBinPrivate *priv = bin->priv;
884 find = g_list_find (priv->elements, element);
886 priv->elements = g_list_delete_link (priv->elements, find);
888 if (!g_list_find (priv->elements, element)) {
889 gst_element_set_locked_state (element, TRUE);
890 gst_bin_remove (GST_BIN_CAST (bin), element);
891 gst_element_set_state (element, GST_STATE_NULL);
894 gst_object_unref (element);
898 /* called with RTP_BIN_LOCK */
900 free_session (GstRtpBinSession * sess, GstRtpBin * bin)
902 GST_DEBUG_OBJECT (bin, "freeing session %p", sess);
904 gst_element_set_locked_state (sess->demux, TRUE);
905 gst_element_set_locked_state (sess->session, TRUE);
906 gst_element_set_locked_state (sess->storage, TRUE);
908 gst_element_set_state (sess->demux, GST_STATE_NULL);
909 gst_element_set_state (sess->session, GST_STATE_NULL);
910 gst_element_set_state (sess->storage, GST_STATE_NULL);
912 remove_recv_rtp (bin, sess);
913 remove_recv_rtcp (bin, sess);
914 remove_recv_fec (bin, sess);
915 remove_send_rtp (bin, sess);
916 remove_send_fec (bin, sess);
917 remove_rtcp (bin, sess);
919 gst_bin_remove (GST_BIN_CAST (bin), sess->session);
920 gst_bin_remove (GST_BIN_CAST (bin), sess->demux);
921 gst_bin_remove (GST_BIN_CAST (bin), sess->storage);
923 g_slist_foreach (sess->elements, (GFunc) remove_bin_element, bin);
924 g_slist_free (sess->elements);
925 sess->elements = NULL;
927 g_slist_foreach (sess->streams, (GFunc) free_stream, bin);
928 g_slist_free (sess->streams);
930 g_mutex_clear (&sess->lock);
931 g_hash_table_destroy (sess->ptmap);
936 /* get the payload type caps for the specific payload @pt in @session */
938 get_pt_map (GstRtpBinSession * session, guint pt)
940 GstCaps *caps = NULL;
943 GValue args[3] = { {0}, {0}, {0} };
945 GST_DEBUG ("searching pt %u in cache", pt);
947 GST_RTP_SESSION_LOCK (session);
949 /* first look in the cache */
950 caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
958 GST_DEBUG ("emitting signal for pt %u in session %u", pt, session->id);
960 /* not in cache, send signal to request caps */
961 g_value_init (&args[0], GST_TYPE_ELEMENT);
962 g_value_set_object (&args[0], bin);
963 g_value_init (&args[1], G_TYPE_UINT);
964 g_value_set_uint (&args[1], session->id);
965 g_value_init (&args[2], G_TYPE_UINT);
966 g_value_set_uint (&args[2], pt);
968 g_value_init (&ret, GST_TYPE_CAPS);
969 g_value_set_boxed (&ret, NULL);
971 GST_RTP_SESSION_UNLOCK (session);
973 g_signal_emitv (args, gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP], 0, &ret);
975 GST_RTP_SESSION_LOCK (session);
977 g_value_unset (&args[0]);
978 g_value_unset (&args[1]);
979 g_value_unset (&args[2]);
981 /* look in the cache again because we let the lock go */
982 caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
985 g_value_unset (&ret);
989 caps = (GstCaps *) g_value_dup_boxed (&ret);
990 g_value_unset (&ret);
994 GST_DEBUG ("caching pt %u as %" GST_PTR_FORMAT, pt, caps);
996 /* store in cache, take additional ref */
997 g_hash_table_insert (session->ptmap, GINT_TO_POINTER (pt),
998 gst_caps_ref (caps));
1001 GST_RTP_SESSION_UNLOCK (session);
1008 GST_RTP_SESSION_UNLOCK (session);
1009 GST_DEBUG ("no pt map could be obtained");
1015 return_true (gpointer key, gpointer value, gpointer user_data)
1021 gst_rtp_bin_reset_sync (GstRtpBin * rtpbin)
1023 GSList *clients, *streams;
1025 GST_DEBUG_OBJECT (rtpbin, "Reset sync on all clients");
1027 GST_RTP_BIN_LOCK (rtpbin);
1028 for (clients = rtpbin->clients; clients; clients = g_slist_next (clients)) {
1029 GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
1031 /* reset sync on all streams for this client */
1032 for (streams = client->streams; streams; streams = g_slist_next (streams)) {
1033 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1035 /* make use require a new SR packet for this stream before we attempt new
1037 stream->have_sync = FALSE;
1038 stream->rt_delta = 0;
1039 stream->avg_ts_offset = 0;
1040 stream->is_initialized = FALSE;
1041 stream->rtp_delta = 0;
1042 stream->clock_base = -100 * GST_SECOND;
1045 GST_RTP_BIN_UNLOCK (rtpbin);
1049 gst_rtp_bin_clear_pt_map (GstRtpBin * bin)
1051 GSList *sessions, *streams;
1053 GST_RTP_BIN_LOCK (bin);
1054 GST_DEBUG_OBJECT (bin, "clearing pt map");
1055 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1056 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
1058 GST_DEBUG_OBJECT (bin, "clearing session %p", session);
1059 g_signal_emit_by_name (session->session, "clear-pt-map", NULL);
1061 GST_RTP_SESSION_LOCK (session);
1062 g_hash_table_foreach_remove (session->ptmap, return_true, NULL);
1064 for (streams = session->streams; streams; streams = g_slist_next (streams)) {
1065 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1067 GST_DEBUG_OBJECT (bin, "clearing stream %p", stream);
1068 if (g_signal_lookup ("clear-pt-map", G_OBJECT_TYPE (stream->buffer)) != 0)
1069 g_signal_emit_by_name (stream->buffer, "clear-pt-map", NULL);
1071 g_signal_emit_by_name (stream->demux, "clear-pt-map", NULL);
1073 GST_RTP_SESSION_UNLOCK (session);
1075 GST_RTP_BIN_UNLOCK (bin);
1077 /* reset sync too */
1078 gst_rtp_bin_reset_sync (bin);
1082 gst_rtp_bin_get_session (GstRtpBin * bin, guint session_id)
1084 GstRtpBinSession *session;
1085 GstElement *ret = NULL;
1087 GST_RTP_BIN_LOCK (bin);
1088 GST_DEBUG_OBJECT (bin, "retrieving GstRtpSession, index: %u", session_id);
1089 session = find_session_by_id (bin, (gint) session_id);
1091 ret = gst_object_ref (session->session);
1093 GST_RTP_BIN_UNLOCK (bin);
1099 gst_rtp_bin_get_internal_session (GstRtpBin * bin, guint session_id)
1101 RTPSession *internal_session = NULL;
1102 GstRtpBinSession *session;
1104 GST_RTP_BIN_LOCK (bin);
1105 GST_DEBUG_OBJECT (bin, "retrieving internal RTPSession object, index: %u",
1107 session = find_session_by_id (bin, (gint) session_id);
1109 g_object_get (session->session, "internal-session", &internal_session,
1112 GST_RTP_BIN_UNLOCK (bin);
1114 return internal_session;
1118 gst_rtp_bin_get_storage (GstRtpBin * bin, guint session_id)
1120 GstRtpBinSession *session;
1121 GstElement *res = NULL;
1123 GST_RTP_BIN_LOCK (bin);
1124 GST_DEBUG_OBJECT (bin, "retrieving internal storage object, index: %u",
1126 session = find_session_by_id (bin, (gint) session_id);
1127 if (session && session->storage) {
1128 res = gst_object_ref (session->storage);
1130 GST_RTP_BIN_UNLOCK (bin);
1136 gst_rtp_bin_get_internal_storage (GstRtpBin * bin, guint session_id)
1138 GObject *internal_storage = NULL;
1139 GstRtpBinSession *session;
1141 GST_RTP_BIN_LOCK (bin);
1142 GST_DEBUG_OBJECT (bin, "retrieving internal storage object, index: %u",
1144 session = find_session_by_id (bin, (gint) session_id);
1145 if (session && session->storage) {
1146 g_object_get (session->storage, "internal-storage", &internal_storage,
1149 GST_RTP_BIN_UNLOCK (bin);
1151 return internal_storage;
1155 gst_rtp_bin_clear_ssrc (GstRtpBin * bin, guint session_id, guint32 ssrc)
1157 GstRtpBinSession *session;
1158 GstElement *demux = NULL;
1160 GST_RTP_BIN_LOCK (bin);
1161 GST_DEBUG_OBJECT (bin, "clearing ssrc %u for session %u", ssrc, session_id);
1162 session = find_session_by_id (bin, (gint) session_id);
1164 demux = gst_object_ref (session->demux);
1165 GST_RTP_BIN_UNLOCK (bin);
1168 g_signal_emit_by_name (demux, "clear-ssrc", ssrc, NULL);
1169 gst_object_unref (demux);
1174 gst_rtp_bin_request_encoder (GstRtpBin * bin, guint session_id)
1176 GST_DEBUG_OBJECT (bin, "return NULL encoder");
1181 gst_rtp_bin_request_decoder (GstRtpBin * bin, guint session_id)
1183 GST_DEBUG_OBJECT (bin, "return NULL decoder");
1188 gst_rtp_bin_request_jitterbuffer (GstRtpBin * bin, guint session_id)
1190 return gst_element_factory_make ("rtpjitterbuffer", NULL);
1194 gst_rtp_bin_propagate_property_to_jitterbuffer (GstRtpBin * bin,
1195 const gchar * name, const GValue * value)
1197 GSList *sessions, *streams;
1199 GST_RTP_BIN_LOCK (bin);
1200 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1201 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
1203 GST_RTP_SESSION_LOCK (session);
1204 for (streams = session->streams; streams; streams = g_slist_next (streams)) {
1205 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1206 GObjectClass *jb_class;
1208 jb_class = G_OBJECT_GET_CLASS (G_OBJECT (stream->buffer));
1209 if (g_object_class_find_property (jb_class, name))
1210 g_object_set_property (G_OBJECT (stream->buffer), name, value);
1212 GST_WARNING_OBJECT (bin,
1213 "Stream jitterbuffer does not expose property %s", name);
1215 GST_RTP_SESSION_UNLOCK (session);
1217 GST_RTP_BIN_UNLOCK (bin);
1221 gst_rtp_bin_propagate_property_to_session (GstRtpBin * bin,
1222 const gchar * name, const GValue * value)
1226 GST_RTP_BIN_LOCK (bin);
1227 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1228 GstRtpBinSession *sess = (GstRtpBinSession *) sessions->data;
1230 g_object_set_property (G_OBJECT (sess->session), name, value);
1232 GST_RTP_BIN_UNLOCK (bin);
1235 /* get a client with the given SDES name. Must be called with RTP_BIN_LOCK */
1236 static GstRtpBinClient *
1237 get_client (GstRtpBin * bin, guint8 len, guint8 * data, gboolean * created)
1239 GstRtpBinClient *result = NULL;
1242 for (walk = bin->clients; walk; walk = g_slist_next (walk)) {
1243 GstRtpBinClient *client = (GstRtpBinClient *) walk->data;
1245 if (len != client->cname_len)
1248 if (!strncmp ((gchar *) data, client->cname, client->cname_len)) {
1249 GST_DEBUG_OBJECT (bin, "found existing client %p with CNAME %s", client,
1256 /* nothing found, create one */
1257 if (result == NULL) {
1258 result = g_new0 (GstRtpBinClient, 1);
1259 result->cname = g_strndup ((gchar *) data, len);
1260 result->cname_len = len;
1261 bin->clients = g_slist_prepend (bin->clients, result);
1262 GST_DEBUG_OBJECT (bin, "created new client %p with CNAME %s", result,
1269 free_client (GstRtpBinClient * client, GstRtpBin * bin)
1271 GST_DEBUG_OBJECT (bin, "freeing client %p", client);
1272 g_slist_free (client->streams);
1273 g_free (client->cname);
1278 get_current_times (GstRtpBin * bin, GstClockTime * running_time,
1279 guint64 * ntpnstime)
1283 GstClockTime base_time, rt, clock_time;
1285 GST_OBJECT_LOCK (bin);
1286 if ((clock = GST_ELEMENT_CLOCK (bin))) {
1287 base_time = GST_ELEMENT_CAST (bin)->base_time;
1288 gst_object_ref (clock);
1289 GST_OBJECT_UNLOCK (bin);
1291 /* get current clock time and convert to running time */
1292 clock_time = gst_clock_get_time (clock);
1293 rt = clock_time - base_time;
1295 if (bin->use_pipeline_clock) {
1297 /* add constant to convert from 1970 based time to 1900 based time */
1298 ntpns += (2208988800LL * GST_SECOND);
1300 switch (bin->ntp_time_source) {
1301 case GST_RTP_NTP_TIME_SOURCE_NTP:
1302 case GST_RTP_NTP_TIME_SOURCE_UNIX:{
1303 /* get current NTP time */
1304 ntpns = g_get_real_time () * GST_USECOND;
1306 /* add constant to convert from 1970 based time to 1900 based time */
1307 if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
1308 ntpns += (2208988800LL * GST_SECOND);
1311 case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
1314 case GST_RTP_NTP_TIME_SOURCE_CLOCK_TIME:
1318 ntpns = -1; /* Fix uninited compiler warning */
1319 g_assert_not_reached ();
1324 gst_object_unref (clock);
1326 GST_OBJECT_UNLOCK (bin);
1337 stream_set_ts_offset (GstRtpBin * bin, GstRtpBinStream * stream,
1338 gint64 ts_offset, gint64 max_ts_offset, guint64 min_ts_offset,
1339 gboolean allow_positive_ts_offset)
1341 gint64 prev_ts_offset;
1342 GObjectClass *jb_class;
1344 jb_class = G_OBJECT_GET_CLASS (G_OBJECT (stream->buffer));
1346 if (!g_object_class_find_property (jb_class, "ts-offset")) {
1347 GST_LOG_OBJECT (bin,
1348 "stream's jitterbuffer does not expose ts-offset property");
1352 if (bin->ts_offset_smoothing_factor > 0) {
1353 if (!stream->is_initialized) {
1354 stream->avg_ts_offset = ts_offset;
1355 stream->is_initialized = TRUE;
1357 /* RMA algorithm using smoothing factor is following, but split into
1358 * parts to check for overflows:
1359 * stream->avg_ts_offset =
1360 * ((bin->ts_offset_smoothing_factor - 1) * stream->avg_ts_offset
1361 * + ts_offset) / bin->ts_offset_smoothing_factor
1363 guint64 max_possible_smoothing_factor =
1364 G_MAXINT64 / ABS (stream->avg_ts_offset);
1365 gint64 cur_avg_product =
1366 (bin->ts_offset_smoothing_factor - 1) * stream->avg_ts_offset;
1368 if ((max_possible_smoothing_factor < bin->ts_offset_smoothing_factor) ||
1369 (cur_avg_product > 0 && G_MAXINT64 - cur_avg_product < ts_offset) ||
1370 (cur_avg_product < 0 && G_MININT64 - cur_avg_product > ts_offset)) {
1371 GST_WARNING_OBJECT (bin,
1372 "ts-offset-smoothing-factor calculation overflow, fallback to using ts-offset directly");
1373 stream->avg_ts_offset = ts_offset;
1375 stream->avg_ts_offset =
1376 (cur_avg_product + ts_offset) / bin->ts_offset_smoothing_factor;
1380 stream->avg_ts_offset = ts_offset;
1383 g_object_get (stream->buffer, "ts-offset", &prev_ts_offset, NULL);
1385 /* delta changed, see how much */
1386 if (prev_ts_offset != stream->avg_ts_offset) {
1389 diff = prev_ts_offset - stream->avg_ts_offset;
1391 GST_DEBUG_OBJECT (bin,
1392 "ts-offset %" G_GINT64_FORMAT ", prev %" G_GINT64_FORMAT
1393 ", diff: %" G_GINT64_FORMAT, stream->avg_ts_offset, prev_ts_offset,
1396 /* ignore minor offsets */
1397 if (ABS (diff) < min_ts_offset) {
1398 GST_DEBUG_OBJECT (bin, "offset too small, ignoring");
1402 /* sanity check offset */
1403 if (max_ts_offset > 0) {
1404 if (stream->avg_ts_offset > 0 && !allow_positive_ts_offset) {
1405 GST_DEBUG_OBJECT (bin,
1406 "offset is positive (clocks are out of sync), ignoring");
1409 if (ABS (stream->avg_ts_offset) > max_ts_offset) {
1410 GST_DEBUG_OBJECT (bin, "offset too large, ignoring");
1415 g_object_set (stream->buffer, "ts-offset", stream->avg_ts_offset, NULL);
1417 GST_DEBUG_OBJECT (bin, "stream SSRC %08x, delta %" G_GINT64_FORMAT,
1418 stream->ssrc, stream->avg_ts_offset);
1422 gst_rtp_bin_send_sync_event (GstRtpBinStream * stream)
1424 if (stream->bin->send_sync_event) {
1428 GST_DEBUG_OBJECT (stream->bin,
1429 "sending GstRTCPSRReceived event downstream");
1431 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
1432 gst_structure_new_empty ("GstRTCPSRReceived"));
1434 srcpad = gst_element_get_static_pad (stream->buffer, "src");
1435 gst_pad_push_event (srcpad, event);
1436 gst_object_unref (srcpad);
1440 /* associate a stream to the given CNAME. This will make sure all streams for
1441 * that CNAME are synchronized together.
1442 * Must be called with GST_RTP_BIN_LOCK */
1444 gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len,
1445 guint8 * data, guint64 ntptime, guint64 last_extrtptime,
1446 guint64 base_rtptime, guint64 base_time, guint clock_rate,
1447 gint64 rtp_clock_base)
1449 GstRtpBinClient *client;
1452 GstClockTime running_time, running_time_rtp;
1455 /* first find or create the CNAME */
1456 client = get_client (bin, len, data, &created);
1458 /* find stream in the client */
1459 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1460 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1462 if (ostream == stream)
1465 /* not found, add it to the list */
1467 GST_DEBUG_OBJECT (bin,
1468 "new association of SSRC %08x with client %p with CNAME %s",
1469 stream->ssrc, client, client->cname);
1470 client->streams = g_slist_prepend (client->streams, stream);
1473 GST_DEBUG_OBJECT (bin,
1474 "found association of SSRC %08x with client %p with CNAME %s",
1475 stream->ssrc, client, client->cname);
1478 if (!GST_CLOCK_TIME_IS_VALID (last_extrtptime)) {
1479 GST_DEBUG_OBJECT (bin, "invalidated sync data");
1480 if (bin->rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) {
1481 /* we don't need that data, so carry on,
1482 * but make some values look saner */
1483 last_extrtptime = base_rtptime;
1485 /* nothing we can do with this data in this case */
1486 GST_DEBUG_OBJECT (bin, "bailing out");
1491 /* Take the extended rtptime we found in the SR packet and map it to the
1492 * local rtptime. The local rtp time is used to construct timestamps on the
1493 * buffers so we will calculate what running_time corresponds to the RTP
1494 * timestamp in the SR packet. */
1495 running_time_rtp = last_extrtptime - base_rtptime;
1497 GST_DEBUG_OBJECT (bin,
1498 "base %" G_GUINT64_FORMAT ", extrtptime %" G_GUINT64_FORMAT
1499 ", local RTP %" G_GUINT64_FORMAT ", clock-rate %d, "
1500 "clock-base %" G_GINT64_FORMAT, base_rtptime,
1501 last_extrtptime, running_time_rtp, clock_rate, rtp_clock_base);
1503 /* calculate local RTP time in gstreamer timestamp, we essentially perform the
1504 * same conversion that a jitterbuffer would use to convert an rtp timestamp
1505 * into a corresponding gstreamer timestamp. Note that the base_time also
1506 * contains the drift between sender and receiver. */
1508 gst_util_uint64_scale_int (running_time_rtp, GST_SECOND, clock_rate);
1509 running_time += base_time;
1511 /* convert ntptime to nanoseconds */
1512 ntpnstime = gst_util_uint64_scale (ntptime, GST_SECOND,
1513 (G_GINT64_CONSTANT (1) << 32));
1515 stream->have_sync = TRUE;
1517 GST_DEBUG_OBJECT (bin,
1518 "SR RTP running time %" G_GUINT64_FORMAT ", SR NTP %" G_GUINT64_FORMAT,
1519 running_time, ntpnstime);
1521 /* recalc inter stream playout offset, but only if there is more than one
1522 * stream or we're doing NTP sync. */
1523 if (bin->ntp_sync) {
1524 gint64 ntpdiff, rtdiff;
1525 guint64 local_ntpnstime;
1526 GstClockTime local_running_time;
1528 /* For NTP sync we need to first get a snapshot of running_time and NTP
1529 * time. We know at what running_time we play a certain RTP time, we also
1530 * calculated when we would play the RTP time in the SR packet. Now we need
1531 * to know how the running_time and the NTP time relate to each other. */
1532 get_current_times (bin, &local_running_time, &local_ntpnstime);
1534 /* see how far away the NTP time is. This is the difference between the
1535 * current NTP time and the NTP time in the last SR packet. */
1536 ntpdiff = local_ntpnstime - ntpnstime;
1537 /* see how far away the running_time is. This is the difference between the
1538 * current running_time and the running_time of the RTP timestamp in the
1539 * last SR packet. */
1540 rtdiff = local_running_time - running_time;
1542 GST_DEBUG_OBJECT (bin,
1543 "local NTP time %" G_GUINT64_FORMAT ", SR NTP time %" G_GUINT64_FORMAT,
1544 local_ntpnstime, ntpnstime);
1545 GST_DEBUG_OBJECT (bin,
1546 "local running time %" G_GUINT64_FORMAT ", SR RTP running time %"
1547 G_GUINT64_FORMAT, local_running_time, running_time);
1548 GST_DEBUG_OBJECT (bin,
1549 "NTP diff %" G_GINT64_FORMAT ", RT diff %" G_GINT64_FORMAT, ntpdiff,
1552 /* combine to get the final diff to apply to the running_time */
1553 stream->rt_delta = rtdiff - ntpdiff;
1555 stream_set_ts_offset (bin, stream, stream->rt_delta, bin->max_ts_offset,
1556 bin->min_ts_offset, FALSE);
1558 gint64 min, rtp_min, clock_base = stream->clock_base;
1559 gboolean all_sync, use_rtp;
1560 gboolean rtcp_sync = g_atomic_int_get (&bin->rtcp_sync);
1562 /* calculate delta between server and receiver. ntpnstime is created by
1563 * converting the ntptime in the last SR packet to a gstreamer timestamp. This
1564 * delta expresses the difference to our timeline and the server timeline. The
1565 * difference in itself doesn't mean much but we can combine the delta of
1566 * multiple streams to create a stream specific offset. */
1567 stream->rt_delta = ntpnstime - running_time;
1569 /* calculate the min of all deltas, ignoring streams that did not yet have a
1570 * valid rt_delta because we did not yet receive an SR packet for those
1572 * We calculate the minimum because we would like to only apply positive
1573 * offsets to streams, delaying their playback instead of trying to speed up
1574 * other streams (which might be impossible when we have to create negative
1576 * The stream that has the smallest diff is selected as the reference stream,
1577 * all other streams will have a positive offset to this difference. */
1579 /* some alternative setting allow ignoring RTCP as much as possible,
1580 * for servers generating bogus ntp timeline */
1581 min = rtp_min = G_MAXINT64;
1583 if (rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) {
1587 /* signed version for convenience */
1588 clock_base = base_rtptime;
1589 /* deal with possible wrap-around */
1590 ext_base = base_rtptime;
1591 rtp_clock_base = gst_rtp_buffer_ext_timestamp (&ext_base, rtp_clock_base);
1592 /* sanity check; base rtp and provided clock_base should be close */
1593 if (rtp_clock_base >= clock_base) {
1594 if (rtp_clock_base - clock_base < 10 * clock_rate) {
1595 rtp_clock_base = base_time +
1596 gst_util_uint64_scale_int (rtp_clock_base - clock_base,
1597 GST_SECOND, clock_rate);
1602 if (clock_base - rtp_clock_base < 10 * clock_rate) {
1603 rtp_clock_base = base_time -
1604 gst_util_uint64_scale_int (clock_base - rtp_clock_base,
1605 GST_SECOND, clock_rate);
1610 /* warn and bail for clarity out if no sane values */
1612 GST_WARNING_OBJECT (bin, "unable to sync to provided rtptime");
1615 /* store to track changes */
1616 clock_base = rtp_clock_base;
1617 /* generate a fake as before,
1618 * now equating rtptime obtained from RTP-Info,
1619 * where the large time represent the otherwise irrelevant npt/ntp time */
1620 stream->rtp_delta = (GST_SECOND << 28) - rtp_clock_base;
1622 clock_base = rtp_clock_base;
1626 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1627 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1629 if (!ostream->have_sync) {
1634 /* change in current stream's base from previously init'ed value
1635 * leads to reset of all stream's base */
1636 if (stream != ostream && stream->clock_base >= 0 &&
1637 (stream->clock_base != clock_base)) {
1638 GST_DEBUG_OBJECT (bin, "reset upon clock base change");
1639 ostream->clock_base = -100 * GST_SECOND;
1640 ostream->rtp_delta = 0;
1643 if (ostream->rt_delta < min)
1644 min = ostream->rt_delta;
1645 if (ostream->rtp_delta < rtp_min)
1646 rtp_min = ostream->rtp_delta;
1649 /* arrange to re-sync for each stream upon significant change,
1651 all_sync = all_sync && (stream->clock_base == clock_base);
1652 stream->clock_base = clock_base;
1654 /* may need init performed above later on, but nothing more to do now */
1655 if (client->nstreams <= 1)
1658 GST_DEBUG_OBJECT (bin, "client %p min delta %" G_GINT64_FORMAT
1659 " all sync %d", client, min, all_sync);
1660 GST_DEBUG_OBJECT (bin, "rtcp sync mode %d, use_rtp %d", rtcp_sync, use_rtp);
1662 switch (rtcp_sync) {
1663 case GST_RTP_BIN_RTCP_SYNC_RTP:
1666 GST_DEBUG_OBJECT (bin, "using rtp generated reports; "
1667 "client %p min rtp delta %" G_GINT64_FORMAT, client, rtp_min);
1669 case GST_RTP_BIN_RTCP_SYNC_INITIAL:
1670 /* if all have been synced already, do not bother further */
1672 GST_DEBUG_OBJECT (bin, "all streams already synced; done");
1680 /* bail out if we adjusted recently enough */
1681 if (all_sync && (ntpnstime - bin->priv->last_ntpnstime) <
1682 bin->rtcp_sync_interval * GST_MSECOND) {
1683 GST_DEBUG_OBJECT (bin, "discarding RTCP sender packet for sync; "
1684 "previous sender info too recent "
1685 "(previous NTP %" G_GUINT64_FORMAT ")", bin->priv->last_ntpnstime);
1688 bin->priv->last_ntpnstime = ntpnstime;
1690 /* calculate offsets for each stream */
1691 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1692 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1695 /* ignore streams for which we didn't receive an SR packet yet, we
1696 * can't synchronize them yet. We can however sync other streams just
1698 if (!ostream->have_sync)
1701 /* calculate offset to our reference stream, this should always give a
1702 * positive number. */
1704 ts_offset = ostream->rtp_delta - rtp_min;
1706 ts_offset = ostream->rt_delta - min;
1708 stream_set_ts_offset (bin, ostream, ts_offset, bin->max_ts_offset,
1709 bin->min_ts_offset, TRUE);
1712 gst_rtp_bin_send_sync_event (stream);
1717 #define GST_RTCP_BUFFER_FOR_PACKETS(b,buffer,packet) \
1718 for ((b) = gst_rtcp_buffer_get_first_packet ((buffer), (packet)); (b); \
1719 (b) = gst_rtcp_packet_move_to_next ((packet)))
1721 #define GST_RTCP_SDES_FOR_ITEMS(b,packet) \
1722 for ((b) = gst_rtcp_packet_sdes_first_item ((packet)); (b); \
1723 (b) = gst_rtcp_packet_sdes_next_item ((packet)))
1725 #define GST_RTCP_SDES_FOR_ENTRIES(b,packet) \
1726 for ((b) = gst_rtcp_packet_sdes_first_entry ((packet)); (b); \
1727 (b) = gst_rtcp_packet_sdes_next_entry ((packet)))
1730 gst_rtp_bin_handle_sync (GstElement * jitterbuffer, GstStructure * s,
1731 GstRtpBinStream * stream)
1734 GstRTCPPacket packet;
1737 gboolean have_sr, have_sdes;
1739 guint64 base_rtptime;
1745 GstRTCPBuffer rtcp = { NULL, };
1749 GST_DEBUG_OBJECT (bin, "sync handler called");
1751 /* get the last relation between the rtp timestamps and the gstreamer
1752 * timestamps. We get this info directly from the jitterbuffer which
1753 * constructs gstreamer timestamps from rtp timestamps and so it know exactly
1754 * what the current situation is. */
1756 g_value_get_uint64 (gst_structure_get_value (s, "base-rtptime"));
1757 base_time = g_value_get_uint64 (gst_structure_get_value (s, "base-time"));
1758 clock_rate = g_value_get_uint (gst_structure_get_value (s, "clock-rate"));
1759 clock_base = g_value_get_uint64 (gst_structure_get_value (s, "clock-base"));
1761 g_value_get_uint64 (gst_structure_get_value (s, "sr-ext-rtptime"));
1762 buffer = gst_value_get_buffer (gst_structure_get_value (s, "sr-buffer"));
1767 gst_rtcp_buffer_map (buffer, GST_MAP_READ, &rtcp);
1769 GST_RTCP_BUFFER_FOR_PACKETS (more, &rtcp, &packet) {
1770 /* first packet must be SR or RR or else the validate would have failed */
1771 switch (gst_rtcp_packet_get_type (&packet)) {
1772 case GST_RTCP_TYPE_SR:
1773 /* only parse first. There is only supposed to be one SR in the packet
1774 * but we will deal with malformed packets gracefully */
1777 /* get NTP and RTP times */
1778 gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, NULL,
1781 GST_DEBUG_OBJECT (bin, "received sync packet from SSRC %08x", ssrc);
1782 /* ignore SR that is not ours */
1783 if (ssrc != stream->ssrc)
1788 case GST_RTCP_TYPE_SDES:
1790 gboolean more_items, more_entries;
1792 /* only deal with first SDES, there is only supposed to be one SDES in
1793 * the RTCP packet but we deal with bad packets gracefully. Also bail
1794 * out if we have not seen an SR item yet. */
1795 if (have_sdes || !have_sr)
1798 GST_RTCP_SDES_FOR_ITEMS (more_items, &packet) {
1799 /* skip items that are not about the SSRC of the sender */
1800 if (gst_rtcp_packet_sdes_get_ssrc (&packet) != ssrc)
1803 /* find the CNAME entry */
1804 GST_RTCP_SDES_FOR_ENTRIES (more_entries, &packet) {
1805 GstRTCPSDESType type;
1809 gst_rtcp_packet_sdes_get_entry (&packet, &type, &len, &data);
1811 if (type == GST_RTCP_SDES_CNAME) {
1812 GST_RTP_BIN_LOCK (bin);
1813 /* associate the stream to CNAME */
1814 gst_rtp_bin_associate (bin, stream, len, data,
1815 ntptime, extrtptime, base_rtptime, base_time, clock_rate,
1817 GST_RTP_BIN_UNLOCK (bin);
1825 /* we can ignore these packets */
1829 gst_rtcp_buffer_unmap (&rtcp);
1832 /* create a new stream with @ssrc in @session. Must be called with
1833 * RTP_SESSION_LOCK. */
1834 static GstRtpBinStream *
1835 create_stream (GstRtpBinSession * session, guint32 ssrc)
1837 GstElement *buffer, *demux = NULL;
1838 GstRtpBinStream *stream;
1841 GObjectClass *jb_class;
1843 rtpbin = session->bin;
1845 if (g_slist_length (session->streams) >= rtpbin->max_streams)
1849 session_request_element (session, SIGNAL_REQUEST_JITTERBUFFER)))
1850 goto no_jitterbuffer;
1852 if (!rtpbin->ignore_pt) {
1853 if (!(demux = gst_element_factory_make ("rtpptdemux", NULL)))
1857 stream = g_new0 (GstRtpBinStream, 1);
1858 stream->ssrc = ssrc;
1859 stream->bin = rtpbin;
1860 stream->session = session;
1861 stream->buffer = gst_object_ref (buffer);
1862 stream->demux = demux;
1864 stream->have_sync = FALSE;
1865 stream->rt_delta = 0;
1866 stream->avg_ts_offset = 0;
1867 stream->is_initialized = FALSE;
1868 stream->rtp_delta = 0;
1869 stream->percent = 100;
1870 stream->clock_base = -100 * GST_SECOND;
1871 session->streams = g_slist_prepend (session->streams, stream);
1873 jb_class = G_OBJECT_GET_CLASS (G_OBJECT (buffer));
1875 if (g_signal_lookup ("request-pt-map", G_OBJECT_TYPE (buffer)) != 0) {
1876 /* provide clock_rate to the jitterbuffer when needed */
1877 stream->buffer_ptreq_sig = g_signal_connect (buffer, "request-pt-map",
1878 (GCallback) pt_map_requested, session);
1880 if (g_signal_lookup ("on-npt-stop", G_OBJECT_TYPE (buffer)) != 0) {
1881 stream->buffer_ntpstop_sig = g_signal_connect (buffer, "on-npt-stop",
1882 (GCallback) on_npt_stop, stream);
1885 g_object_set_data (G_OBJECT (buffer), "GstRTPBin.session", session);
1886 g_object_set_data (G_OBJECT (buffer), "GstRTPBin.stream", stream);
1888 /* configure latency and packet lost */
1889 g_object_set (buffer, "latency", rtpbin->latency_ms, NULL);
1891 if (g_object_class_find_property (jb_class, "drop-on-latency"))
1892 g_object_set (buffer, "drop-on-latency", rtpbin->drop_on_latency, NULL);
1893 if (g_object_class_find_property (jb_class, "do-lost"))
1894 g_object_set (buffer, "do-lost", rtpbin->do_lost, NULL);
1895 if (g_object_class_find_property (jb_class, "mode"))
1896 g_object_set (buffer, "mode", rtpbin->buffer_mode, NULL);
1897 if (g_object_class_find_property (jb_class, "do-retransmission"))
1898 g_object_set (buffer, "do-retransmission", rtpbin->do_retransmission, NULL);
1899 if (g_object_class_find_property (jb_class, "max-rtcp-rtp-time-diff"))
1900 g_object_set (buffer, "max-rtcp-rtp-time-diff",
1901 rtpbin->max_rtcp_rtp_time_diff, NULL);
1902 if (g_object_class_find_property (jb_class, "max-dropout-time"))
1903 g_object_set (buffer, "max-dropout-time", rtpbin->max_dropout_time, NULL);
1904 if (g_object_class_find_property (jb_class, "max-misorder-time"))
1905 g_object_set (buffer, "max-misorder-time", rtpbin->max_misorder_time, NULL);
1906 if (g_object_class_find_property (jb_class, "rfc7273-sync"))
1907 g_object_set (buffer, "rfc7273-sync", rtpbin->rfc7273_sync, NULL);
1908 if (g_object_class_find_property (jb_class, "max-ts-offset-adjustment"))
1909 g_object_set (buffer, "max-ts-offset-adjustment",
1910 rtpbin->max_ts_offset_adjustment, NULL);
1912 g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER], 0,
1913 buffer, session->id, ssrc);
1915 if (!rtpbin->ignore_pt)
1916 gst_bin_add (GST_BIN_CAST (rtpbin), demux);
1920 gst_element_link_pads_full (buffer, "src", demux, "sink",
1921 GST_PAD_LINK_CHECK_NOTHING);
1923 if (rtpbin->buffering) {
1926 if (g_signal_lookup ("set-active", G_OBJECT_TYPE (buffer)) != 0) {
1927 GST_INFO_OBJECT (rtpbin,
1928 "bin is buffering, set jitterbuffer as not active");
1929 g_signal_emit_by_name (buffer, "set-active", FALSE, (gint64) 0,
1935 GST_OBJECT_LOCK (rtpbin);
1936 target = GST_STATE_TARGET (rtpbin);
1937 GST_OBJECT_UNLOCK (rtpbin);
1939 /* from sink to source */
1941 gst_element_set_state (demux, target);
1943 gst_element_set_state (buffer, target);
1950 GST_WARNING_OBJECT (rtpbin, "stream exceeds maximum (%d)",
1951 rtpbin->max_streams);
1956 g_warning ("rtpbin: could not create rtpjitterbuffer element");
1961 gst_object_unref (buffer);
1962 g_warning ("rtpbin: could not create rtpptdemux element");
1967 /* called with RTP_BIN_LOCK */
1969 free_stream (GstRtpBinStream * stream, GstRtpBin * bin)
1971 GstRtpBinSession *sess = stream->session;
1972 GSList *clients, *next_client;
1974 GST_DEBUG_OBJECT (bin, "freeing stream %p", stream);
1976 gst_element_set_locked_state (stream->buffer, TRUE);
1978 gst_element_set_locked_state (stream->demux, TRUE);
1980 gst_element_set_state (stream->buffer, GST_STATE_NULL);
1982 gst_element_set_state (stream->demux, GST_STATE_NULL);
1984 if (stream->demux) {
1985 g_signal_handler_disconnect (stream->demux, stream->demux_newpad_sig);
1986 g_signal_handler_disconnect (stream->demux, stream->demux_ptreq_sig);
1987 g_signal_handler_disconnect (stream->demux, stream->demux_ptchange_sig);
1988 g_signal_handler_disconnect (stream->demux, stream->demux_padremoved_sig);
1991 if (stream->buffer_handlesync_sig)
1992 g_signal_handler_disconnect (stream->buffer, stream->buffer_handlesync_sig);
1993 if (stream->buffer_ptreq_sig)
1994 g_signal_handler_disconnect (stream->buffer, stream->buffer_ptreq_sig);
1995 if (stream->buffer_ntpstop_sig)
1996 g_signal_handler_disconnect (stream->buffer, stream->buffer_ntpstop_sig);
1998 sess->elements = g_slist_remove (sess->elements, stream->buffer);
1999 remove_bin_element (stream->buffer, bin);
2000 gst_object_unref (stream->buffer);
2003 gst_bin_remove (GST_BIN_CAST (bin), stream->demux);
2005 for (clients = bin->clients; clients; clients = next_client) {
2006 GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
2007 GSList *streams, *next_stream;
2009 next_client = g_slist_next (clients);
2011 for (streams = client->streams; streams; streams = next_stream) {
2012 GstRtpBinStream *ostream = (GstRtpBinStream *) streams->data;
2014 next_stream = g_slist_next (streams);
2016 if (ostream == stream) {
2017 client->streams = g_slist_delete_link (client->streams, streams);
2018 /* If this was the last stream belonging to this client,
2019 * clean up the client. */
2020 if (--client->nstreams == 0) {
2021 bin->clients = g_slist_delete_link (bin->clients, clients);
2022 free_client (client, bin);
2031 /* GObject vmethods */
2032 static void gst_rtp_bin_dispose (GObject * object);
2033 static void gst_rtp_bin_finalize (GObject * object);
2034 static void gst_rtp_bin_set_property (GObject * object, guint prop_id,
2035 const GValue * value, GParamSpec * pspec);
2036 static void gst_rtp_bin_get_property (GObject * object, guint prop_id,
2037 GValue * value, GParamSpec * pspec);
2039 /* GstElement vmethods */
2040 static GstStateChangeReturn gst_rtp_bin_change_state (GstElement * element,
2041 GstStateChange transition);
2042 static GstPad *gst_rtp_bin_request_new_pad (GstElement * element,
2043 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
2044 static void gst_rtp_bin_release_pad (GstElement * element, GstPad * pad);
2045 static void gst_rtp_bin_handle_message (GstBin * bin, GstMessage * message);
2047 #define gst_rtp_bin_parent_class parent_class
2048 G_DEFINE_TYPE_WITH_PRIVATE (GstRtpBin, gst_rtp_bin, GST_TYPE_BIN);
2049 GST_ELEMENT_REGISTER_DEFINE (rtpbin, "rtpbin", GST_RANK_NONE, GST_TYPE_RTP_BIN);
2052 _gst_element_accumulator (GSignalInvocationHint * ihint,
2053 GValue * return_accu, const GValue * handler_return, gpointer dummy)
2055 GstElement *element;
2057 element = g_value_get_object (handler_return);
2058 GST_DEBUG ("got element %" GST_PTR_FORMAT, element);
2060 g_value_set_object (return_accu, element);
2062 /* stop emission if we have an element */
2063 return (element == NULL);
2067 _gst_caps_accumulator (GSignalInvocationHint * ihint,
2068 GValue * return_accu, const GValue * handler_return, gpointer dummy)
2072 caps = g_value_get_boxed (handler_return);
2073 GST_DEBUG ("got caps %" GST_PTR_FORMAT, caps);
2075 g_value_set_boxed (return_accu, caps);
2077 /* stop emission if we have a caps */
2078 return (caps == NULL);
2082 gst_rtp_bin_class_init (GstRtpBinClass * klass)
2084 GObjectClass *gobject_class;
2085 GstElementClass *gstelement_class;
2086 GstBinClass *gstbin_class;
2088 gobject_class = (GObjectClass *) klass;
2089 gstelement_class = (GstElementClass *) klass;
2090 gstbin_class = (GstBinClass *) klass;
2092 gobject_class->dispose = gst_rtp_bin_dispose;
2093 gobject_class->finalize = gst_rtp_bin_finalize;
2094 gobject_class->set_property = gst_rtp_bin_set_property;
2095 gobject_class->get_property = gst_rtp_bin_get_property;
2097 g_object_class_install_property (gobject_class, PROP_LATENCY,
2098 g_param_spec_uint ("latency", "Buffer latency in ms",
2099 "Default amount of ms to buffer in the jitterbuffers", 0,
2100 G_MAXUINT, DEFAULT_LATENCY_MS,
2101 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2103 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
2104 g_param_spec_boolean ("drop-on-latency",
2105 "Drop buffers when maximum latency is reached",
2106 "Tells the jitterbuffer to never exceed the given latency in size",
2107 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2110 * GstRtpBin::request-pt-map:
2111 * @rtpbin: the object which received the signal
2112 * @session: the session
2115 * Request the payload type as #GstCaps for @pt in @session.
2117 gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP] =
2118 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
2119 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, request_pt_map),
2120 _gst_caps_accumulator, NULL, NULL, GST_TYPE_CAPS, 2, G_TYPE_UINT,
2124 * GstRtpBin::payload-type-change:
2125 * @rtpbin: the object which received the signal
2126 * @session: the session
2129 * Signal that the current payload type changed to @pt in @session.
2131 gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE] =
2132 g_signal_new ("payload-type-change", G_TYPE_FROM_CLASS (klass),
2133 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, payload_type_change),
2134 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2137 * GstRtpBin::clear-pt-map:
2138 * @rtpbin: the object which received the signal
2140 * Clear all previously cached pt-mapping obtained with
2141 * #GstRtpBin::request-pt-map.
2143 gst_rtp_bin_signals[SIGNAL_CLEAR_PT_MAP] =
2144 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
2145 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2146 clear_pt_map), NULL, NULL, NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
2149 * GstRtpBin::reset-sync:
2150 * @rtpbin: the object which received the signal
2152 * Reset all currently configured lip-sync parameters and require new SR
2153 * packets for all streams before lip-sync is attempted again.
2155 gst_rtp_bin_signals[SIGNAL_RESET_SYNC] =
2156 g_signal_new ("reset-sync", G_TYPE_FROM_CLASS (klass),
2157 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2158 reset_sync), NULL, NULL, NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
2161 * GstRtpBin::get-session:
2162 * @rtpbin: the object which received the signal
2163 * @id: the session id
2165 * Request the related GstRtpSession as #GstElement related with session @id.
2169 gst_rtp_bin_signals[SIGNAL_GET_SESSION] =
2170 g_signal_new ("get-session", G_TYPE_FROM_CLASS (klass),
2171 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2172 get_session), NULL, NULL, NULL, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2175 * GstRtpBin::get-internal-session:
2176 * @rtpbin: the object which received the signal
2177 * @id: the session id
2179 * Request the internal RTPSession object as #GObject in session @id.
2181 gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_SESSION] =
2182 g_signal_new ("get-internal-session", G_TYPE_FROM_CLASS (klass),
2183 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2184 get_internal_session), NULL, NULL, NULL, RTP_TYPE_SESSION, 1,
2188 * GstRtpBin::get-internal-storage:
2189 * @rtpbin: the object which received the signal
2190 * @id: the session id
2192 * Request the internal RTPStorage object as #GObject in session @id. This
2193 * is the internal storage used by the RTPStorage element, which is used to
2194 * keep a backlog of received RTP packets for the session @id.
2198 gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_STORAGE] =
2199 g_signal_new ("get-internal-storage", G_TYPE_FROM_CLASS (klass),
2200 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2201 get_internal_storage), NULL, NULL, NULL, G_TYPE_OBJECT, 1,
2205 * GstRtpBin::get-storage:
2206 * @rtpbin: the object which received the signal
2207 * @id: the session id
2209 * Request the RTPStorage element as #GObject in session @id. This element
2210 * is used to keep a backlog of received RTP packets for the session @id.
2214 gst_rtp_bin_signals[SIGNAL_GET_STORAGE] =
2215 g_signal_new ("get-storage", G_TYPE_FROM_CLASS (klass),
2216 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2217 get_storage), NULL, NULL, NULL, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2220 * GstRtpBin::clear-ssrc:
2221 * @rtpbin: the object which received the signal
2222 * @id: the session id
2225 * Remove all pads from rtpssrcdemux element associated with the specified
2226 * ssrc. This delegate the action signal to the rtpssrcdemux element
2227 * associated with the specified session.
2231 gst_rtp_bin_signals[SIGNAL_CLEAR_SSRC] =
2232 g_signal_new ("clear-ssrc", G_TYPE_FROM_CLASS (klass),
2233 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2234 clear_ssrc), NULL, NULL, NULL, G_TYPE_NONE, 2,
2235 G_TYPE_UINT, G_TYPE_UINT);
2238 * GstRtpBin::on-new-ssrc:
2239 * @rtpbin: the object which received the signal
2240 * @session: the session
2243 * Notify of a new SSRC that entered @session.
2245 gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC] =
2246 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
2247 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_ssrc),
2248 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2250 * GstRtpBin::on-ssrc-collision:
2251 * @rtpbin: the object which received the signal
2252 * @session: the session
2255 * Notify when we have an SSRC collision
2257 gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION] =
2258 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
2259 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_collision),
2260 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2262 * GstRtpBin::on-ssrc-validated:
2263 * @rtpbin: the object which received the signal
2264 * @session: the session
2267 * Notify of a new SSRC that became validated.
2269 gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED] =
2270 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
2271 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_validated),
2272 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2274 * GstRtpBin::on-ssrc-active:
2275 * @rtpbin: the object which received the signal
2276 * @session: the session
2279 * Notify of a SSRC that is active, i.e., sending RTCP.
2281 gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE] =
2282 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
2283 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_active),
2284 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2286 * GstRtpBin::on-ssrc-sdes:
2287 * @rtpbin: the object which received the signal
2288 * @session: the session
2291 * Notify of a SSRC that is active, i.e., sending RTCP.
2293 gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES] =
2294 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
2295 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_sdes),
2296 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2299 * GstRtpBin::on-bye-ssrc:
2300 * @rtpbin: the object which received the signal
2301 * @session: the session
2304 * Notify of an SSRC that became inactive because of a BYE packet.
2306 gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC] =
2307 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
2308 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_ssrc),
2309 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2311 * GstRtpBin::on-bye-timeout:
2312 * @rtpbin: the object which received the signal
2313 * @session: the session
2316 * Notify of an SSRC that has timed out because of BYE
2318 gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT] =
2319 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
2320 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_timeout),
2321 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2323 * GstRtpBin::on-timeout:
2324 * @rtpbin: the object which received the signal
2325 * @session: the session
2328 * Notify of an SSRC that has timed out
2330 gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT] =
2331 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
2332 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_timeout),
2333 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2335 * GstRtpBin::on-sender-timeout:
2336 * @rtpbin: the object which received the signal
2337 * @session: the session
2340 * Notify of a sender SSRC that has timed out and became a receiver
2342 gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT] =
2343 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
2344 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_sender_timeout),
2345 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2348 * GstRtpBin::on-npt-stop:
2349 * @rtpbin: the object which received the signal
2350 * @session: the session
2353 * Notify that SSRC sender has sent data up to the configured NPT stop time.
2355 gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP] =
2356 g_signal_new ("on-npt-stop", G_TYPE_FROM_CLASS (klass),
2357 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_npt_stop),
2358 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2361 * GstRtpBin::request-rtp-encoder:
2362 * @rtpbin: the object which received the signal
2363 * @session: the session
2365 * Request an RTP encoder element for the given @session. The encoder
2366 * element will be added to the bin if not previously added.
2368 * If no handler is connected, no encoder will be used.
2372 gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_ENCODER] =
2373 g_signal_new ("request-rtp-encoder", G_TYPE_FROM_CLASS (klass),
2374 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2375 request_rtp_encoder), _gst_element_accumulator, NULL, NULL,
2376 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2379 * GstRtpBin::request-rtp-decoder:
2380 * @rtpbin: the object which received the signal
2381 * @session: the session
2383 * Request an RTP decoder element for the given @session. The decoder
2384 * element will be added to the bin if not previously added.
2386 * If no handler is connected, no encoder will be used.
2390 gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_DECODER] =
2391 g_signal_new ("request-rtp-decoder", G_TYPE_FROM_CLASS (klass),
2392 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2393 request_rtp_decoder), _gst_element_accumulator, NULL,
2394 NULL, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2397 * GstRtpBin::request-rtcp-encoder:
2398 * @rtpbin: the object which received the signal
2399 * @session: the session
2401 * Request an RTCP encoder element for the given @session. The encoder
2402 * element will be added to the bin if not previously added.
2404 * If no handler is connected, no encoder will be used.
2408 gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_ENCODER] =
2409 g_signal_new ("request-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
2410 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2411 request_rtcp_encoder), _gst_element_accumulator, NULL, NULL,
2412 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2415 * GstRtpBin::request-rtcp-decoder:
2416 * @rtpbin: the object which received the signal
2417 * @session: the session
2419 * Request an RTCP decoder element for the given @session. The decoder
2420 * element will be added to the bin if not previously added.
2422 * If no handler is connected, no encoder will be used.
2426 gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_DECODER] =
2427 g_signal_new ("request-rtcp-decoder", G_TYPE_FROM_CLASS (klass),
2428 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2429 request_rtcp_decoder), _gst_element_accumulator, NULL, NULL,
2430 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2433 * GstRtpBin::request-jitterbuffer:
2434 * @rtpbin: the object which received the signal
2435 * @session: the session
2437 * Request a jitterbuffer element for the given @session.
2439 * If no handler is connected, the default jitterbuffer will be used.
2441 * Note: The provided element is expected to conform to the API exposed
2442 * by the standard #GstRtpJitterBuffer. Runtime checks will be made to
2443 * determine whether it exposes properties and signals before attempting
2444 * to set, call or connect to them, and some functionalities of #GstRtpBin
2445 * may not be available when that is not the case.
2447 * This should be considered experimental API, as the standard jitterbuffer
2448 * API is susceptible to change, provided elements will have to update their
2449 * custom jitterbuffer's API to match the API of #GstRtpJitterBuffer if and
2454 gst_rtp_bin_signals[SIGNAL_REQUEST_JITTERBUFFER] =
2455 g_signal_new ("request-jitterbuffer", G_TYPE_FROM_CLASS (klass),
2456 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2457 request_jitterbuffer), _gst_element_accumulator, NULL,
2458 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2461 * GstRtpBin::new-jitterbuffer:
2462 * @rtpbin: the object which received the signal
2463 * @jitterbuffer: the new jitterbuffer
2464 * @session: the session
2467 * Notify that a new @jitterbuffer was created for @session and @ssrc.
2468 * This signal can, for example, be used to configure @jitterbuffer.
2472 gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER] =
2473 g_signal_new ("new-jitterbuffer", G_TYPE_FROM_CLASS (klass),
2474 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2475 new_jitterbuffer), NULL, NULL, NULL,
2476 G_TYPE_NONE, 3, GST_TYPE_ELEMENT, G_TYPE_UINT, G_TYPE_UINT);
2479 * GstRtpBin::new-storage:
2480 * @rtpbin: the object which received the signal
2481 * @storage: the new storage
2482 * @session: the session
2484 * Notify that a new @storage was created for @session.
2485 * This signal can, for example, be used to configure @storage.
2489 gst_rtp_bin_signals[SIGNAL_NEW_STORAGE] =
2490 g_signal_new ("new-storage", G_TYPE_FROM_CLASS (klass),
2491 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2492 new_storage), NULL, NULL, NULL,
2493 G_TYPE_NONE, 2, GST_TYPE_ELEMENT, G_TYPE_UINT);
2496 * GstRtpBin::request-aux-sender:
2497 * @rtpbin: the object which received the signal
2498 * @session: the session
2500 * Request an AUX sender element for the given @session. The AUX
2501 * element will be added to the bin.
2503 * If no handler is connected, no AUX element will be used.
2507 gst_rtp_bin_signals[SIGNAL_REQUEST_AUX_SENDER] =
2508 g_signal_new ("request-aux-sender", G_TYPE_FROM_CLASS (klass),
2509 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2510 request_aux_sender), _gst_element_accumulator, NULL, NULL,
2511 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2514 * GstRtpBin::request-aux-receiver:
2515 * @rtpbin: the object which received the signal
2516 * @session: the session
2518 * Request an AUX receiver element for the given @session. The AUX
2519 * element will be added to the bin.
2521 * If no handler is connected, no AUX element will be used.
2525 gst_rtp_bin_signals[SIGNAL_REQUEST_AUX_RECEIVER] =
2526 g_signal_new ("request-aux-receiver", G_TYPE_FROM_CLASS (klass),
2527 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2528 request_aux_receiver), _gst_element_accumulator, NULL, NULL,
2529 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2532 * GstRtpBin::request-fec-decoder:
2533 * @rtpbin: the object which received the signal
2534 * @session: the session index
2536 * Request a FEC decoder element for the given @session. The element
2537 * will be added to the bin after the pt demuxer. If there are multiple
2538 * ssrc's and pt's in @session, this signal may be called multiple times for
2539 * the same @session each corresponding to a newly discovered ssrc.
2541 * If no handler is connected, no FEC decoder will be used.
2543 * Warning: usage of this signal is not appropriate for the BUNDLE case,
2544 * connect to #GstRtpBin::request-fec-decoder-full instead.
2548 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_DECODER] =
2549 g_signal_new ("request-fec-decoder", G_TYPE_FROM_CLASS (klass),
2550 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2551 request_fec_decoder), _gst_element_accumulator, NULL, NULL,
2552 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2555 * GstRtpBin::request-fec-decoder-full:
2556 * @rtpbin: the object which received the signal
2557 * @session: the session index
2558 * @ssrc: the ssrc of the stream
2559 * @pt: the payload type
2561 * Request a FEC decoder element for the given @session. The element
2562 * will be added to the bin after the pt demuxer. If there are multiple
2563 * ssrc's and pt's in @session, this signal may be called multiple times for
2564 * the same @session each corresponding to a newly discovered ssrc and payload
2565 * type, those are provided as parameters.
2567 * If no handler is connected, no FEC decoder will be used.
2571 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_DECODER_FULL] =
2572 g_signal_new ("request-fec-decoder-full", G_TYPE_FROM_CLASS (klass),
2573 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2574 request_fec_decoder), _gst_element_accumulator, NULL, NULL,
2575 GST_TYPE_ELEMENT, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
2578 * GstRtpBin::request-fec-encoder:
2579 * @rtpbin: the object which received the signal
2580 * @session: the session index
2582 * Request a FEC encoder element for the given @session. The element
2583 * will be added to the bin after the RTPSession.
2585 * If no handler is connected, no FEC encoder will be used.
2589 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_ENCODER] =
2590 g_signal_new ("request-fec-encoder", G_TYPE_FROM_CLASS (klass),
2591 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2592 request_fec_encoder), _gst_element_accumulator, NULL, NULL,
2593 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2596 * GstRtpBin::on-new-sender-ssrc:
2597 * @rtpbin: the object which received the signal
2598 * @session: the session
2599 * @ssrc: the sender SSRC
2601 * Notify of a new sender SSRC that entered @session.
2605 gst_rtp_bin_signals[SIGNAL_ON_NEW_SENDER_SSRC] =
2606 g_signal_new ("on-new-sender-ssrc", G_TYPE_FROM_CLASS (klass),
2607 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_sender_ssrc),
2608 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2610 * GstRtpBin::on-sender-ssrc-active:
2611 * @rtpbin: the object which received the signal
2612 * @session: the session
2613 * @ssrc: the sender SSRC
2615 * Notify of a sender SSRC that is active, i.e., sending RTCP.
2619 gst_rtp_bin_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE] =
2620 g_signal_new ("on-sender-ssrc-active", G_TYPE_FROM_CLASS (klass),
2621 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2622 on_sender_ssrc_active), NULL, NULL, NULL,
2623 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2625 g_object_class_install_property (gobject_class, PROP_SDES,
2626 g_param_spec_boxed ("sdes", "SDES",
2627 "The SDES items of this session",
2628 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
2629 | GST_PARAM_DOC_SHOW_DEFAULT));
2631 g_object_class_install_property (gobject_class, PROP_DO_LOST,
2632 g_param_spec_boolean ("do-lost", "Do Lost",
2633 "Send an event downstream when a packet is lost", DEFAULT_DO_LOST,
2634 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2636 g_object_class_install_property (gobject_class, PROP_AUTOREMOVE,
2637 g_param_spec_boolean ("autoremove", "Auto Remove",
2638 "Automatically remove timed out sources", DEFAULT_AUTOREMOVE,
2639 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2641 g_object_class_install_property (gobject_class, PROP_IGNORE_PT,
2642 g_param_spec_boolean ("ignore-pt", "Ignore PT",
2643 "Do not demultiplex based on PT values", DEFAULT_IGNORE_PT,
2644 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2646 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
2647 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
2648 "Use the pipeline running-time to set the NTP time in the RTCP SR messages "
2649 "(DEPRECATED: Use ntp-time-source property)",
2650 DEFAULT_USE_PIPELINE_CLOCK,
2651 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
2653 * GstRtpBin:buffer-mode:
2655 * Control the buffering and timestamping mode used by the jitterbuffer.
2657 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
2658 g_param_spec_enum ("buffer-mode", "Buffer Mode",
2659 "Control the buffering algorithm in use", RTP_TYPE_JITTER_BUFFER_MODE,
2660 DEFAULT_BUFFER_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2662 * GstRtpBin:ntp-sync:
2664 * Set the NTP time from the sender reports as the running-time on the
2665 * buffers. When both the sender and receiver have sychronized
2666 * running-time, i.e. when the clock and base-time is shared
2667 * between the receivers and the and the senders, this option can be
2668 * used to synchronize receivers on multiple machines.
2670 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
2671 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
2672 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
2673 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2676 * GstRtpBin:rtcp-sync:
2678 * If not synchronizing (directly) to the NTP clock, determines how to sync
2679 * the various streams.
2681 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC,
2682 g_param_spec_enum ("rtcp-sync", "RTCP Sync",
2683 "Use of RTCP SR in synchronization", GST_RTP_BIN_RTCP_SYNC_TYPE,
2684 DEFAULT_RTCP_SYNC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2687 * GstRtpBin:rtcp-sync-interval:
2689 * Determines how often to sync streams using RTCP data.
2691 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_INTERVAL,
2692 g_param_spec_uint ("rtcp-sync-interval", "RTCP Sync Interval",
2693 "RTCP SR interval synchronization (ms) (0 = always)",
2694 0, G_MAXUINT, DEFAULT_RTCP_SYNC_INTERVAL,
2695 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2697 g_object_class_install_property (gobject_class, PROP_DO_SYNC_EVENT,
2698 g_param_spec_boolean ("do-sync-event", "Do Sync Event",
2699 "Send event downstream when a stream is synchronized to the sender",
2700 DEFAULT_DO_SYNC_EVENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2703 * GstRtpBin:do-retransmission:
2705 * Enables RTP retransmission on all streams. To control retransmission on
2706 * a per-SSRC basis, connect to the #GstRtpBin::new-jitterbuffer signal and
2707 * set the #GstRtpJitterBuffer:do-retransmission property on the
2708 * #GstRtpJitterBuffer object instead.
2710 g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
2711 g_param_spec_boolean ("do-retransmission", "Do retransmission",
2712 "Enable retransmission on all streams",
2713 DEFAULT_DO_RETRANSMISSION,
2714 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2717 * GstRtpBin:rtp-profile:
2719 * Sets the default RTP profile of newly created RTP sessions. The
2720 * profile can be changed afterwards on a per-session basis.
2722 g_object_class_install_property (gobject_class, PROP_RTP_PROFILE,
2723 g_param_spec_enum ("rtp-profile", "RTP Profile",
2724 "Default RTP profile of newly created sessions",
2725 GST_TYPE_RTP_PROFILE, DEFAULT_RTP_PROFILE,
2726 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2728 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
2729 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
2730 "NTP time source for RTCP packets",
2731 gst_rtp_ntp_time_source_get_type (), DEFAULT_NTP_TIME_SOURCE,
2732 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2734 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_SEND_TIME,
2735 g_param_spec_boolean ("rtcp-sync-send-time", "RTCP Sync Send Time",
2736 "Use send time or capture time for RTCP sync "
2737 "(TRUE = send time, FALSE = capture time)",
2738 DEFAULT_RTCP_SYNC_SEND_TIME,
2739 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2741 g_object_class_install_property (gobject_class, PROP_MAX_RTCP_RTP_TIME_DIFF,
2742 g_param_spec_int ("max-rtcp-rtp-time-diff", "Max RTCP RTP Time Diff",
2743 "Maximum amount of time in ms that the RTP time in RTCP SRs "
2744 "is allowed to be ahead (-1 disabled)", -1, G_MAXINT,
2745 DEFAULT_MAX_RTCP_RTP_TIME_DIFF,
2746 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2748 g_object_class_install_property (gobject_class, PROP_MAX_DROPOUT_TIME,
2749 g_param_spec_uint ("max-dropout-time", "Max dropout time",
2750 "The maximum time (milliseconds) of missing packets tolerated.",
2751 0, G_MAXUINT, DEFAULT_MAX_DROPOUT_TIME,
2752 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2754 g_object_class_install_property (gobject_class, PROP_MAX_MISORDER_TIME,
2755 g_param_spec_uint ("max-misorder-time", "Max misorder time",
2756 "The maximum time (milliseconds) of misordered packets tolerated.",
2757 0, G_MAXUINT, DEFAULT_MAX_MISORDER_TIME,
2758 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2760 g_object_class_install_property (gobject_class, PROP_RFC7273_SYNC,
2761 g_param_spec_boolean ("rfc7273-sync", "Sync on RFC7273 clock",
2762 "Synchronize received streams to the RFC7273 clock "
2763 "(requires clock and offset to be provided)", DEFAULT_RFC7273_SYNC,
2764 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2766 g_object_class_install_property (gobject_class, PROP_MAX_STREAMS,
2767 g_param_spec_uint ("max-streams", "Max Streams",
2768 "The maximum number of streams to create for one session",
2769 0, G_MAXUINT, DEFAULT_MAX_STREAMS,
2770 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2773 * GstRtpBin:max-ts-offset-adjustment:
2775 * Syncing time stamps to NTP time adds a time offset. This parameter
2776 * specifies the maximum number of nanoseconds per frame that this time offset
2777 * may be adjusted with. This is used to avoid sudden large changes to time
2782 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET_ADJUSTMENT,
2783 g_param_spec_uint64 ("max-ts-offset-adjustment",
2784 "Max Timestamp Offset Adjustment",
2785 "The maximum number of nanoseconds per frame that time stamp offsets "
2786 "may be adjusted (0 = no limit).", 0, G_MAXUINT64,
2787 DEFAULT_MAX_TS_OFFSET_ADJUSTMENT, G_PARAM_READWRITE |
2788 G_PARAM_STATIC_STRINGS));
2791 * GstRtpBin:max-ts-offset:
2793 * Used to set an upper limit of how large a time offset may be. This
2794 * is used to protect against unrealistic values as a result of either
2795 * client,server or clock issues.
2799 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET,
2800 g_param_spec_int64 ("max-ts-offset", "Max TS Offset",
2801 "The maximum absolute value of the time offset in (nanoseconds). "
2802 "Note, if the ntp-sync parameter is set the default value is "
2803 "changed to 0 (no limit)", 0, G_MAXINT64, DEFAULT_MAX_TS_OFFSET,
2804 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2807 * GstRtpBin:min-ts-offset:
2809 * Used to set an lower limit for when a time offset is deemed large enough
2810 * to be useful for sync corrections.
2812 * When streaming for instance audio, even very small ts_offsets cause
2813 * audible glitches. This property is used for controlling how sensitive the
2814 * adjustments should be to small deviations in ts_offset, occurring for
2815 * instance due to jittery network conditions or system load.
2819 g_object_class_install_property (gobject_class, PROP_MIN_TS_OFFSET,
2820 g_param_spec_uint64 ("min-ts-offset", "Min TS Offset",
2821 "The minimum absolute value of the time offset in (nanoseconds). "
2822 "Used to set an lower limit for when a time offset is deemed large "
2823 "enough to be useful for sync corrections."
2824 "Note, if the ntp-sync parameter is set the default value is "
2825 "changed to 0 (no limit)", 0, G_MAXUINT64, DEFAULT_MIN_TS_OFFSET,
2826 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2829 * GstRtpBin:ts-offset-smoothing-factor:
2831 * Controls the weighting between previous and current timestamp offsets in
2832 * a running moving average (RMA):
2833 * ts_offset_average(n) =
2834 * ((ts-offset-smoothing-factor - 1) * ts_offset_average(n - 1) + ts_offset(n)) /
2835 * ts-offset-smoothing-factor
2837 * This can stabilize the timestamp offset and prevent unnecessary skew
2838 * corrections due to jitter introduced by network or system load.
2842 g_object_class_install_property (gobject_class,
2843 PROP_TS_OFFSET_SMOOTHING_FACTOR,
2844 g_param_spec_uint ("ts-offset-smoothing-factor",
2845 "Timestamp Offset Smoothing Factor",
2846 "Sets a smoothing factor for the timestamp offset in number of "
2847 "values for a calculated running moving average. "
2848 "(0 = no smoothing factor)", 0, G_MAXUINT,
2849 DEFAULT_TS_OFFSET_SMOOTHING_FACTOR,
2850 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2853 * GstRtpBin:fec-decoders:
2855 * Used to provide a factory used to build the FEC decoder for a
2856 * given session, as a command line alternative to
2857 * #GstRtpBin::request-fec-decoder.
2859 * Expects a GstStructure in the form session_id (gint) -> factory (string)
2863 g_object_class_install_property (gobject_class, PROP_FEC_DECODERS,
2864 g_param_spec_boxed ("fec-decoders", "Fec Decoders",
2865 "GstStructure mapping from session index to FEC decoder "
2867 "fec-decoders='fec,0=\"rtpst2022-1-fecdec\\ size-time\\=1000000000\";'",
2868 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2871 * GstRtpBin:fec-encoders:
2873 * Used to provide a factory used to build the FEC encoder for a
2874 * given session, as a command line alternative to
2875 * #GstRtpBin::request-fec-encoder.
2877 * Expects a GstStructure in the form session_id (gint) -> factory (string)
2881 g_object_class_install_property (gobject_class, PROP_FEC_ENCODERS,
2882 g_param_spec_boxed ("fec-encoders", "Fec Encoders",
2883 "GstStructure mapping from session index to FEC encoder "
2885 "fec-encoders='fec,0=\"rtpst2022-1-fecenc\\ rows\\=5\\ columns\\=5\";'",
2886 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2888 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
2889 gstelement_class->request_new_pad =
2890 GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
2891 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_bin_release_pad);
2894 gst_element_class_add_static_pad_template (gstelement_class,
2895 &rtpbin_recv_rtp_sink_template);
2896 gst_element_class_add_static_pad_template (gstelement_class,
2897 &rtpbin_recv_fec_sink_template);
2898 gst_element_class_add_static_pad_template (gstelement_class,
2899 &rtpbin_recv_rtcp_sink_template);
2900 gst_element_class_add_static_pad_template (gstelement_class,
2901 &rtpbin_send_rtp_sink_template);
2904 gst_element_class_add_static_pad_template (gstelement_class,
2905 &rtpbin_recv_rtp_src_template);
2906 gst_element_class_add_static_pad_template (gstelement_class,
2907 &rtpbin_send_rtcp_src_template);
2908 gst_element_class_add_static_pad_template (gstelement_class,
2909 &rtpbin_send_rtp_src_template);
2910 gst_element_class_add_static_pad_template (gstelement_class,
2911 &rtpbin_send_fec_src_template);
2913 gst_element_class_set_static_metadata (gstelement_class, "RTP Bin",
2914 "Filter/Network/RTP",
2915 "Real-Time Transport Protocol bin",
2916 "Wim Taymans <wim.taymans@gmail.com>");
2918 gstbin_class->handle_message = GST_DEBUG_FUNCPTR (gst_rtp_bin_handle_message);
2920 klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_bin_clear_pt_map);
2921 klass->reset_sync = GST_DEBUG_FUNCPTR (gst_rtp_bin_reset_sync);
2922 klass->get_session = GST_DEBUG_FUNCPTR (gst_rtp_bin_get_session);
2923 klass->get_internal_session =
2924 GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_session);
2925 klass->get_storage = GST_DEBUG_FUNCPTR (gst_rtp_bin_get_storage);
2926 klass->get_internal_storage =
2927 GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_storage);
2928 klass->clear_ssrc = GST_DEBUG_FUNCPTR (gst_rtp_bin_clear_ssrc);
2929 klass->request_rtp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
2930 klass->request_rtp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
2931 klass->request_rtcp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
2932 klass->request_rtcp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
2933 klass->request_jitterbuffer =
2934 GST_DEBUG_FUNCPTR (gst_rtp_bin_request_jitterbuffer);
2936 GST_DEBUG_CATEGORY_INIT (gst_rtp_bin_debug, "rtpbin", 0, "RTP bin");
2938 gst_type_mark_as_plugin_api (GST_RTP_BIN_RTCP_SYNC_TYPE, 0);
2942 gst_rtp_bin_init (GstRtpBin * rtpbin)
2946 rtpbin->priv = gst_rtp_bin_get_instance_private (rtpbin);
2947 g_mutex_init (&rtpbin->priv->bin_lock);
2948 g_mutex_init (&rtpbin->priv->dyn_lock);
2950 rtpbin->latency_ms = DEFAULT_LATENCY_MS;
2951 rtpbin->latency_ns = DEFAULT_LATENCY_MS * GST_MSECOND;
2952 rtpbin->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
2953 rtpbin->do_lost = DEFAULT_DO_LOST;
2954 rtpbin->ignore_pt = DEFAULT_IGNORE_PT;
2955 rtpbin->ntp_sync = DEFAULT_NTP_SYNC;
2956 rtpbin->rtcp_sync = DEFAULT_RTCP_SYNC;
2957 rtpbin->rtcp_sync_interval = DEFAULT_RTCP_SYNC_INTERVAL;
2958 rtpbin->priv->autoremove = DEFAULT_AUTOREMOVE;
2959 rtpbin->buffer_mode = DEFAULT_BUFFER_MODE;
2960 rtpbin->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
2961 rtpbin->send_sync_event = DEFAULT_DO_SYNC_EVENT;
2962 rtpbin->do_retransmission = DEFAULT_DO_RETRANSMISSION;
2963 rtpbin->rtp_profile = DEFAULT_RTP_PROFILE;
2964 rtpbin->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
2965 rtpbin->rtcp_sync_send_time = DEFAULT_RTCP_SYNC_SEND_TIME;
2966 rtpbin->max_rtcp_rtp_time_diff = DEFAULT_MAX_RTCP_RTP_TIME_DIFF;
2967 rtpbin->max_dropout_time = DEFAULT_MAX_DROPOUT_TIME;
2968 rtpbin->max_misorder_time = DEFAULT_MAX_MISORDER_TIME;
2969 rtpbin->rfc7273_sync = DEFAULT_RFC7273_SYNC;
2970 rtpbin->max_streams = DEFAULT_MAX_STREAMS;
2971 rtpbin->max_ts_offset_adjustment = DEFAULT_MAX_TS_OFFSET_ADJUSTMENT;
2972 rtpbin->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
2973 rtpbin->max_ts_offset_is_set = FALSE;
2974 rtpbin->min_ts_offset = DEFAULT_MIN_TS_OFFSET;
2975 rtpbin->min_ts_offset_is_set = FALSE;
2976 rtpbin->ts_offset_smoothing_factor = DEFAULT_TS_OFFSET_SMOOTHING_FACTOR;
2978 /* some default SDES entries */
2979 cname = g_strdup_printf ("user%u@host-%x", g_random_int (), g_random_int ());
2980 rtpbin->sdes = gst_structure_new ("application/x-rtp-source-sdes",
2981 "cname", G_TYPE_STRING, cname, "tool", G_TYPE_STRING, "GStreamer", NULL);
2982 rtpbin->fec_decoders =
2983 gst_structure_new_empty ("application/x-rtp-fec-decoders");
2984 rtpbin->fec_encoders =
2985 gst_structure_new_empty ("application/x-rtp-fec-encoders");
2990 gst_rtp_bin_dispose (GObject * object)
2994 rtpbin = GST_RTP_BIN (object);
2996 GST_RTP_BIN_LOCK (rtpbin);
2997 GST_DEBUG_OBJECT (object, "freeing sessions");
2998 g_slist_foreach (rtpbin->sessions, (GFunc) free_session, rtpbin);
2999 g_slist_free (rtpbin->sessions);
3000 rtpbin->sessions = NULL;
3001 GST_RTP_BIN_UNLOCK (rtpbin);
3003 G_OBJECT_CLASS (parent_class)->dispose (object);
3007 gst_rtp_bin_finalize (GObject * object)
3011 rtpbin = GST_RTP_BIN (object);
3014 gst_structure_free (rtpbin->sdes);
3016 if (rtpbin->fec_decoders)
3017 gst_structure_free (rtpbin->fec_decoders);
3019 if (rtpbin->fec_encoders)
3020 gst_structure_free (rtpbin->fec_encoders);
3022 g_mutex_clear (&rtpbin->priv->bin_lock);
3023 g_mutex_clear (&rtpbin->priv->dyn_lock);
3025 G_OBJECT_CLASS (parent_class)->finalize (object);
3030 gst_rtp_bin_set_sdes_struct (GstRtpBin * bin, const GstStructure * sdes)
3037 GST_RTP_BIN_LOCK (bin);
3039 GST_OBJECT_LOCK (bin);
3041 gst_structure_free (bin->sdes);
3042 bin->sdes = gst_structure_copy (sdes);
3043 GST_OBJECT_UNLOCK (bin);
3045 /* store in all sessions */
3046 for (item = bin->sessions; item; item = g_slist_next (item)) {
3047 GstRtpBinSession *session = item->data;
3048 g_object_set (session->session, "sdes", sdes, NULL);
3051 GST_RTP_BIN_UNLOCK (bin);
3055 gst_rtp_bin_set_fec_decoders_struct (GstRtpBin * bin,
3056 const GstStructure * decoders)
3058 if (decoders == NULL)
3061 GST_RTP_BIN_LOCK (bin);
3063 GST_OBJECT_LOCK (bin);
3064 if (bin->fec_decoders)
3065 gst_structure_free (bin->fec_decoders);
3066 bin->fec_decoders = gst_structure_copy (decoders);
3068 GST_OBJECT_UNLOCK (bin);
3070 GST_RTP_BIN_UNLOCK (bin);
3074 gst_rtp_bin_set_fec_encoders_struct (GstRtpBin * bin,
3075 const GstStructure * encoders)
3077 if (encoders == NULL)
3080 GST_RTP_BIN_LOCK (bin);
3082 GST_OBJECT_LOCK (bin);
3083 if (bin->fec_encoders)
3084 gst_structure_free (bin->fec_encoders);
3085 bin->fec_encoders = gst_structure_copy (encoders);
3087 GST_OBJECT_UNLOCK (bin);
3089 GST_RTP_BIN_UNLOCK (bin);
3092 static GstStructure *
3093 gst_rtp_bin_get_sdes_struct (GstRtpBin * bin)
3095 GstStructure *result;
3097 GST_OBJECT_LOCK (bin);
3098 result = gst_structure_copy (bin->sdes);
3099 GST_OBJECT_UNLOCK (bin);
3104 static GstStructure *
3105 gst_rtp_bin_get_fec_decoders_struct (GstRtpBin * bin)
3107 GstStructure *result;
3109 GST_OBJECT_LOCK (bin);
3110 result = gst_structure_copy (bin->fec_decoders);
3111 GST_OBJECT_UNLOCK (bin);
3116 static GstStructure *
3117 gst_rtp_bin_get_fec_encoders_struct (GstRtpBin * bin)
3119 GstStructure *result;
3121 GST_OBJECT_LOCK (bin);
3122 result = gst_structure_copy (bin->fec_encoders);
3123 GST_OBJECT_UNLOCK (bin);
3129 gst_rtp_bin_set_property (GObject * object, guint prop_id,
3130 const GValue * value, GParamSpec * pspec)
3134 rtpbin = GST_RTP_BIN (object);
3138 GST_RTP_BIN_LOCK (rtpbin);
3139 rtpbin->latency_ms = g_value_get_uint (value);
3140 rtpbin->latency_ns = rtpbin->latency_ms * GST_MSECOND;
3141 GST_RTP_BIN_UNLOCK (rtpbin);
3142 /* propagate the property down to the jitterbuffer */
3143 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "latency", value);
3145 case PROP_DROP_ON_LATENCY:
3146 GST_RTP_BIN_LOCK (rtpbin);
3147 rtpbin->drop_on_latency = g_value_get_boolean (value);
3148 GST_RTP_BIN_UNLOCK (rtpbin);
3149 /* propagate the property down to the jitterbuffer */
3150 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3151 "drop-on-latency", value);
3154 gst_rtp_bin_set_sdes_struct (rtpbin, g_value_get_boxed (value));
3157 GST_RTP_BIN_LOCK (rtpbin);
3158 rtpbin->do_lost = g_value_get_boolean (value);
3159 GST_RTP_BIN_UNLOCK (rtpbin);
3160 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "do-lost", value);
3163 rtpbin->ntp_sync = g_value_get_boolean (value);
3164 /* The default value of max_ts_offset depends on ntp_sync. If user
3165 * hasn't set it then change default value */
3166 if (!rtpbin->max_ts_offset_is_set) {
3167 if (rtpbin->ntp_sync) {
3168 rtpbin->max_ts_offset = 0;
3170 rtpbin->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
3173 if (!rtpbin->min_ts_offset_is_set) {
3174 if (rtpbin->ntp_sync) {
3175 rtpbin->min_ts_offset = 0;
3177 rtpbin->min_ts_offset = DEFAULT_MIN_TS_OFFSET;
3181 case PROP_RTCP_SYNC:
3182 g_atomic_int_set (&rtpbin->rtcp_sync, g_value_get_enum (value));
3184 case PROP_RTCP_SYNC_INTERVAL:
3185 rtpbin->rtcp_sync_interval = g_value_get_uint (value);
3187 case PROP_IGNORE_PT:
3188 rtpbin->ignore_pt = g_value_get_boolean (value);
3190 case PROP_AUTOREMOVE:
3191 rtpbin->priv->autoremove = g_value_get_boolean (value);
3193 case PROP_USE_PIPELINE_CLOCK:
3196 GST_RTP_BIN_LOCK (rtpbin);
3197 rtpbin->use_pipeline_clock = g_value_get_boolean (value);
3198 for (sessions = rtpbin->sessions; sessions;
3199 sessions = g_slist_next (sessions)) {
3200 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3202 g_object_set (G_OBJECT (session->session),
3203 "use-pipeline-clock", rtpbin->use_pipeline_clock, NULL);
3205 GST_RTP_BIN_UNLOCK (rtpbin);
3208 case PROP_DO_SYNC_EVENT:
3209 rtpbin->send_sync_event = g_value_get_boolean (value);
3211 case PROP_BUFFER_MODE:
3212 GST_RTP_BIN_LOCK (rtpbin);
3213 rtpbin->buffer_mode = g_value_get_enum (value);
3214 GST_RTP_BIN_UNLOCK (rtpbin);
3215 /* propagate the property down to the jitterbuffer */
3216 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "mode", value);
3218 case PROP_DO_RETRANSMISSION:
3219 GST_RTP_BIN_LOCK (rtpbin);
3220 rtpbin->do_retransmission = g_value_get_boolean (value);
3221 GST_RTP_BIN_UNLOCK (rtpbin);
3222 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3223 "do-retransmission", value);
3225 case PROP_RTP_PROFILE:
3226 rtpbin->rtp_profile = g_value_get_enum (value);
3228 case PROP_NTP_TIME_SOURCE:{
3230 GST_RTP_BIN_LOCK (rtpbin);
3231 rtpbin->ntp_time_source = g_value_get_enum (value);
3232 for (sessions = rtpbin->sessions; sessions;
3233 sessions = g_slist_next (sessions)) {
3234 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3236 g_object_set (G_OBJECT (session->session),
3237 "ntp-time-source", rtpbin->ntp_time_source, NULL);
3239 GST_RTP_BIN_UNLOCK (rtpbin);
3242 case PROP_RTCP_SYNC_SEND_TIME:{
3244 GST_RTP_BIN_LOCK (rtpbin);
3245 rtpbin->rtcp_sync_send_time = g_value_get_boolean (value);
3246 for (sessions = rtpbin->sessions; sessions;
3247 sessions = g_slist_next (sessions)) {
3248 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3250 g_object_set (G_OBJECT (session->session),
3251 "rtcp-sync-send-time", rtpbin->rtcp_sync_send_time, NULL);
3253 GST_RTP_BIN_UNLOCK (rtpbin);
3256 case PROP_MAX_RTCP_RTP_TIME_DIFF:
3257 GST_RTP_BIN_LOCK (rtpbin);
3258 rtpbin->max_rtcp_rtp_time_diff = g_value_get_int (value);
3259 GST_RTP_BIN_UNLOCK (rtpbin);
3260 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3261 "max-rtcp-rtp-time-diff", value);
3263 case PROP_MAX_DROPOUT_TIME:
3264 GST_RTP_BIN_LOCK (rtpbin);
3265 rtpbin->max_dropout_time = g_value_get_uint (value);
3266 GST_RTP_BIN_UNLOCK (rtpbin);
3267 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3268 "max-dropout-time", value);
3269 gst_rtp_bin_propagate_property_to_session (rtpbin, "max-dropout-time",
3272 case PROP_MAX_MISORDER_TIME:
3273 GST_RTP_BIN_LOCK (rtpbin);
3274 rtpbin->max_misorder_time = g_value_get_uint (value);
3275 GST_RTP_BIN_UNLOCK (rtpbin);
3276 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3277 "max-misorder-time", value);
3278 gst_rtp_bin_propagate_property_to_session (rtpbin, "max-misorder-time",
3281 case PROP_RFC7273_SYNC:
3282 rtpbin->rfc7273_sync = g_value_get_boolean (value);
3283 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3284 "rfc7273-sync", value);
3286 case PROP_MAX_STREAMS:
3287 rtpbin->max_streams = g_value_get_uint (value);
3289 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
3290 rtpbin->max_ts_offset_adjustment = g_value_get_uint64 (value);
3291 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3292 "max-ts-offset-adjustment", value);
3294 case PROP_MAX_TS_OFFSET:
3295 rtpbin->max_ts_offset = g_value_get_int64 (value);
3296 rtpbin->max_ts_offset_is_set = TRUE;
3298 case PROP_MIN_TS_OFFSET:
3299 rtpbin->min_ts_offset = g_value_get_uint64 (value);
3300 rtpbin->min_ts_offset_is_set = TRUE;
3302 case PROP_TS_OFFSET_SMOOTHING_FACTOR:
3303 rtpbin->ts_offset_smoothing_factor = g_value_get_uint (value);
3305 case PROP_FEC_DECODERS:
3306 gst_rtp_bin_set_fec_decoders_struct (rtpbin, g_value_get_boxed (value));
3308 case PROP_FEC_ENCODERS:
3309 gst_rtp_bin_set_fec_encoders_struct (rtpbin, g_value_get_boxed (value));
3312 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3318 gst_rtp_bin_get_property (GObject * object, guint prop_id,
3319 GValue * value, GParamSpec * pspec)
3323 rtpbin = GST_RTP_BIN (object);
3327 GST_RTP_BIN_LOCK (rtpbin);
3328 g_value_set_uint (value, rtpbin->latency_ms);
3329 GST_RTP_BIN_UNLOCK (rtpbin);
3331 case PROP_DROP_ON_LATENCY:
3332 GST_RTP_BIN_LOCK (rtpbin);
3333 g_value_set_boolean (value, rtpbin->drop_on_latency);
3334 GST_RTP_BIN_UNLOCK (rtpbin);
3337 g_value_take_boxed (value, gst_rtp_bin_get_sdes_struct (rtpbin));
3340 GST_RTP_BIN_LOCK (rtpbin);
3341 g_value_set_boolean (value, rtpbin->do_lost);
3342 GST_RTP_BIN_UNLOCK (rtpbin);
3344 case PROP_IGNORE_PT:
3345 g_value_set_boolean (value, rtpbin->ignore_pt);
3348 g_value_set_boolean (value, rtpbin->ntp_sync);
3350 case PROP_RTCP_SYNC:
3351 g_value_set_enum (value, g_atomic_int_get (&rtpbin->rtcp_sync));
3353 case PROP_RTCP_SYNC_INTERVAL:
3354 g_value_set_uint (value, rtpbin->rtcp_sync_interval);
3356 case PROP_AUTOREMOVE:
3357 g_value_set_boolean (value, rtpbin->priv->autoremove);
3359 case PROP_BUFFER_MODE:
3360 g_value_set_enum (value, rtpbin->buffer_mode);
3362 case PROP_USE_PIPELINE_CLOCK:
3363 g_value_set_boolean (value, rtpbin->use_pipeline_clock);
3365 case PROP_DO_SYNC_EVENT:
3366 g_value_set_boolean (value, rtpbin->send_sync_event);
3368 case PROP_DO_RETRANSMISSION:
3369 GST_RTP_BIN_LOCK (rtpbin);
3370 g_value_set_boolean (value, rtpbin->do_retransmission);
3371 GST_RTP_BIN_UNLOCK (rtpbin);
3373 case PROP_RTP_PROFILE:
3374 g_value_set_enum (value, rtpbin->rtp_profile);
3376 case PROP_NTP_TIME_SOURCE:
3377 g_value_set_enum (value, rtpbin->ntp_time_source);
3379 case PROP_RTCP_SYNC_SEND_TIME:
3380 g_value_set_boolean (value, rtpbin->rtcp_sync_send_time);
3382 case PROP_MAX_RTCP_RTP_TIME_DIFF:
3383 GST_RTP_BIN_LOCK (rtpbin);
3384 g_value_set_int (value, rtpbin->max_rtcp_rtp_time_diff);
3385 GST_RTP_BIN_UNLOCK (rtpbin);
3387 case PROP_MAX_DROPOUT_TIME:
3388 g_value_set_uint (value, rtpbin->max_dropout_time);
3390 case PROP_MAX_MISORDER_TIME:
3391 g_value_set_uint (value, rtpbin->max_misorder_time);
3393 case PROP_RFC7273_SYNC:
3394 g_value_set_boolean (value, rtpbin->rfc7273_sync);
3396 case PROP_MAX_STREAMS:
3397 g_value_set_uint (value, rtpbin->max_streams);
3399 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
3400 g_value_set_uint64 (value, rtpbin->max_ts_offset_adjustment);
3402 case PROP_MAX_TS_OFFSET:
3403 g_value_set_int64 (value, rtpbin->max_ts_offset);
3405 case PROP_MIN_TS_OFFSET:
3406 g_value_set_uint64 (value, rtpbin->min_ts_offset);
3408 case PROP_TS_OFFSET_SMOOTHING_FACTOR:
3409 g_value_set_uint (value, rtpbin->ts_offset_smoothing_factor);
3411 case PROP_FEC_DECODERS:
3412 g_value_take_boxed (value, gst_rtp_bin_get_fec_decoders_struct (rtpbin));
3414 case PROP_FEC_ENCODERS:
3415 g_value_take_boxed (value, gst_rtp_bin_get_fec_encoders_struct (rtpbin));
3418 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3424 gst_rtp_bin_handle_message (GstBin * bin, GstMessage * message)
3428 rtpbin = GST_RTP_BIN (bin);
3430 switch (GST_MESSAGE_TYPE (message)) {
3431 case GST_MESSAGE_ELEMENT:
3433 const GstStructure *s = gst_message_get_structure (message);
3435 /* we change the structure name and add the session ID to it */
3436 if (gst_structure_has_name (s, "application/x-rtp-source-sdes")) {
3437 GstRtpBinSession *sess;
3439 /* find the session we set it as object data */
3440 sess = g_object_get_data (G_OBJECT (GST_MESSAGE_SRC (message)),
3441 "GstRTPBin.session");
3443 if (G_LIKELY (sess)) {
3444 message = gst_message_make_writable (message);
3445 s = gst_message_get_structure (message);
3446 gst_structure_set ((GstStructure *) s, "session", G_TYPE_UINT,
3450 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3453 case GST_MESSAGE_BUFFERING:
3456 gint min_percent = 100;
3457 GSList *sessions, *streams;
3458 GstRtpBinStream *stream;
3459 gboolean change = FALSE, active = FALSE;
3460 GstClockTime min_out_time;
3461 GstBufferingMode mode;
3462 gint avg_in, avg_out;
3463 gint64 buffering_left;
3465 gst_message_parse_buffering (message, &percent);
3466 gst_message_parse_buffering_stats (message, &mode, &avg_in, &avg_out,
3470 g_object_get_data (G_OBJECT (GST_MESSAGE_SRC (message)),
3471 "GstRTPBin.stream");
3473 GST_DEBUG_OBJECT (bin, "got percent %d from stream %p", percent, stream);
3475 /* get the stream */
3476 if (G_LIKELY (stream)) {
3477 GST_RTP_BIN_LOCK (rtpbin);
3478 /* fill in the percent */
3479 stream->percent = percent;
3481 /* calculate the min value for all streams */
3482 for (sessions = rtpbin->sessions; sessions;
3483 sessions = g_slist_next (sessions)) {
3484 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3486 GST_RTP_SESSION_LOCK (session);
3487 if (session->streams) {
3488 for (streams = session->streams; streams;
3489 streams = g_slist_next (streams)) {
3490 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
3492 GST_DEBUG_OBJECT (bin, "stream %p percent %d", stream,
3495 /* find min percent */
3496 if (min_percent > stream->percent)
3497 min_percent = stream->percent;
3500 GST_INFO_OBJECT (bin,
3501 "session has no streams, setting min_percent to 0");
3504 GST_RTP_SESSION_UNLOCK (session);
3506 GST_DEBUG_OBJECT (bin, "min percent %d", min_percent);
3508 if (rtpbin->buffering) {
3509 if (min_percent == 100) {
3510 rtpbin->buffering = FALSE;
3515 if (min_percent < 100) {
3516 /* pause the streams */
3517 rtpbin->buffering = TRUE;
3522 GST_RTP_BIN_UNLOCK (rtpbin);
3524 gst_message_unref (message);
3526 /* make a new buffering message with the min value */
3528 gst_message_new_buffering (GST_OBJECT_CAST (bin), min_percent);
3529 gst_message_set_buffering_stats (message, mode, avg_in, avg_out,
3532 if (G_UNLIKELY (change)) {
3534 guint64 running_time = 0;
3537 /* figure out the running time when we have a clock */
3538 if (G_LIKELY ((clock =
3539 gst_element_get_clock (GST_ELEMENT_CAST (bin))))) {
3540 guint64 now, base_time;
3542 now = gst_clock_get_time (clock);
3543 base_time = gst_element_get_base_time (GST_ELEMENT_CAST (bin));
3544 running_time = now - base_time;
3545 gst_object_unref (clock);
3547 GST_DEBUG_OBJECT (bin,
3548 "running time now %" GST_TIME_FORMAT,
3549 GST_TIME_ARGS (running_time));
3551 GST_RTP_BIN_LOCK (rtpbin);
3553 /* when we reactivate, calculate the offsets so that all streams have
3554 * an output time that is at least as big as the running_time */
3557 if (running_time > rtpbin->buffer_start) {
3558 offset = running_time - rtpbin->buffer_start;
3559 if (offset >= rtpbin->latency_ns)
3560 offset -= rtpbin->latency_ns;
3566 /* pause all streams */
3568 for (sessions = rtpbin->sessions; sessions;
3569 sessions = g_slist_next (sessions)) {
3570 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3572 GST_RTP_SESSION_LOCK (session);
3573 for (streams = session->streams; streams;
3574 streams = g_slist_next (streams)) {
3575 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
3576 GstElement *element = stream->buffer;
3577 guint64 last_out = -1;
3579 if (g_signal_lookup ("set-active", G_OBJECT_TYPE (element)) != 0) {
3580 g_signal_emit_by_name (element, "set-active", active, offset,
3585 g_object_get (element, "percent", &stream->percent, NULL);
3589 if (min_out_time == -1 || last_out < min_out_time)
3590 min_out_time = last_out;
3593 GST_DEBUG_OBJECT (bin,
3594 "setting %p to %d, offset %" GST_TIME_FORMAT ", last %"
3595 GST_TIME_FORMAT ", percent %d", element, active,
3596 GST_TIME_ARGS (offset), GST_TIME_ARGS (last_out),
3599 GST_RTP_SESSION_UNLOCK (session);
3601 GST_DEBUG_OBJECT (bin,
3602 "min out time %" GST_TIME_FORMAT, GST_TIME_ARGS (min_out_time));
3604 /* the buffer_start is the min out time of all paused jitterbuffers */
3606 rtpbin->buffer_start = min_out_time;
3608 GST_RTP_BIN_UNLOCK (rtpbin);
3611 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3616 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3622 static GstStateChangeReturn
3623 gst_rtp_bin_change_state (GstElement * element, GstStateChange transition)
3625 GstStateChangeReturn res;
3627 GstRtpBinPrivate *priv;
3629 rtpbin = GST_RTP_BIN (element);
3630 priv = rtpbin->priv;
3632 switch (transition) {
3633 case GST_STATE_CHANGE_NULL_TO_READY:
3635 case GST_STATE_CHANGE_READY_TO_PAUSED:
3636 priv->last_ntpnstime = 0;
3637 GST_LOG_OBJECT (rtpbin, "clearing shutdown flag");
3638 g_atomic_int_set (&priv->shutdown, 0);
3640 case GST_STATE_CHANGE_PAUSED_TO_READY:
3641 GST_LOG_OBJECT (rtpbin, "setting shutdown flag");
3642 g_atomic_int_set (&priv->shutdown, 1);
3643 /* wait for all callbacks to end by taking the lock. No new callbacks will
3644 * be able to happen as we set the shutdown flag. */
3645 GST_RTP_BIN_DYN_LOCK (rtpbin);
3646 GST_LOG_OBJECT (rtpbin, "dynamic lock taken, we can continue shutdown");
3647 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
3653 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3655 switch (transition) {
3656 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3658 case GST_STATE_CHANGE_PAUSED_TO_READY:
3660 case GST_STATE_CHANGE_READY_TO_NULL:
3669 session_request_element_full (GstRtpBinSession * session, guint signal,
3670 guint ssrc, guint8 pt)
3672 GstElement *element = NULL;
3673 GstRtpBin *bin = session->bin;
3675 g_signal_emit (bin, gst_rtp_bin_signals[signal], 0, session->id, ssrc, pt,
3679 if (!bin_manage_element (bin, element))
3681 session->elements = g_slist_prepend (session->elements, element);
3688 GST_WARNING_OBJECT (bin, "unable to manage element");
3689 gst_object_unref (element);
3695 session_request_element (GstRtpBinSession * session, guint signal)
3697 GstElement *element = NULL;
3698 GstRtpBin *bin = session->bin;
3700 g_signal_emit (bin, gst_rtp_bin_signals[signal], 0, session->id, &element);
3703 if (!bin_manage_element (bin, element))
3705 session->elements = g_slist_prepend (session->elements, element);
3712 GST_WARNING_OBJECT (bin, "unable to manage element");
3713 gst_object_unref (element);
3719 copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
3721 GstPad *gpad = GST_PAD_CAST (user_data);
3723 GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
3724 gst_pad_store_sticky_event (gpad, *event);
3730 ensure_early_fec_decoder (GstRtpBin * rtpbin, GstRtpBinSession * session)
3732 const gchar *factory;
3735 if (session->early_fec_decoder)
3738 sess_id_str = g_strdup_printf ("%u", session->id);
3739 factory = gst_structure_get_string (rtpbin->fec_decoders, sess_id_str);
3740 g_free (sess_id_str);
3742 /* First try the property */
3746 session->early_fec_decoder =
3747 gst_parse_bin_from_description_full (factory, TRUE, NULL,
3748 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_FATAL_ERRORS,
3750 if (!session->early_fec_decoder) {
3751 GST_ERROR_OBJECT (rtpbin, "Failed to build decoder from factory: %s",
3755 bin_manage_element (session->bin, session->early_fec_decoder);
3757 g_slist_prepend (session->elements, session->early_fec_decoder);
3758 GST_INFO_OBJECT (rtpbin, "Built FEC decoder: %" GST_PTR_FORMAT
3759 " for session %u", session->early_fec_decoder, session->id);
3762 /* Do not fallback to the signal as the signal expects a fec decoder to
3763 * be placed at a different place in the pipeline */
3766 return session->early_fec_decoder != NULL;
3770 expose_recv_src_pad (GstRtpBin * rtpbin, GstPad * pad, GstRtpBinStream * stream,
3773 GstElementClass *klass;
3774 GstPadTemplate *templ;
3778 gst_object_ref (pad);
3780 if (stream->session->storage) {
3781 /* First try the legacy signal, with no ssrc and pt as parameters.
3782 * This will likely cause issues for the BUNDLE case. */
3783 GstElement *fec_decoder =
3784 session_request_element (stream->session, SIGNAL_REQUEST_FEC_DECODER);
3786 /* Now try the new signal, where the application can provide a FEC
3787 * decoder according to ssrc and pt. */
3790 session_request_element_full (stream->session,
3791 SIGNAL_REQUEST_FEC_DECODER_FULL, stream->ssrc, pt);
3795 GstPad *sinkpad, *srcpad;
3796 GstPadLinkReturn ret;
3798 sinkpad = gst_element_get_static_pad (fec_decoder, "sink");
3801 goto fec_decoder_sink_failed;
3803 ret = gst_pad_link (pad, sinkpad);
3804 gst_object_unref (sinkpad);
3806 if (ret != GST_PAD_LINK_OK)
3807 goto fec_decoder_link_failed;
3809 srcpad = gst_element_get_static_pad (fec_decoder, "src");
3812 goto fec_decoder_src_failed;
3814 gst_pad_sticky_events_foreach (pad, copy_sticky_events, srcpad);
3815 gst_object_unref (pad);
3820 GST_RTP_BIN_SHUTDOWN_LOCK (rtpbin, shutdown);
3822 /* ghost the pad to the parent */
3823 klass = GST_ELEMENT_GET_CLASS (rtpbin);
3824 templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%u_%u_%u");
3825 padname = g_strdup_printf ("recv_rtp_src_%u_%u_%u",
3826 stream->session->id, stream->ssrc, pt);
3827 gpad = gst_ghost_pad_new_from_template (padname, pad, templ);
3829 g_object_set_data (G_OBJECT (pad), "GstRTPBin.ghostpad", gpad);
3831 gst_pad_set_active (gpad, TRUE);
3832 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3834 gst_pad_sticky_events_foreach (pad, copy_sticky_events, gpad);
3835 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3838 gst_object_unref (pad);
3844 GST_DEBUG ("ignoring, we are shutting down");
3847 fec_decoder_sink_failed:
3849 g_warning ("rtpbin: failed to get fec encoder sink pad for session %u",
3850 stream->session->id);
3853 fec_decoder_src_failed:
3855 g_warning ("rtpbin: failed to get fec encoder src pad for session %u",
3856 stream->session->id);
3859 fec_decoder_link_failed:
3861 g_warning ("rtpbin: failed to link fec decoder for session %u",
3862 stream->session->id);
3867 /* a new pad (SSRC) was created in @session. This signal is emitted from the
3868 * payload demuxer. */
3870 new_payload_found (GstElement * element, guint pt, GstPad * pad,
3871 GstRtpBinStream * stream)
3875 rtpbin = stream->bin;
3877 GST_DEBUG_OBJECT (rtpbin, "new payload pad %u", pt);
3879 expose_recv_src_pad (rtpbin, pad, stream, pt);
3883 payload_pad_removed (GstElement * element, GstPad * pad,
3884 GstRtpBinStream * stream)
3889 rtpbin = stream->bin;
3891 GST_DEBUG ("payload pad removed");
3893 GST_RTP_BIN_DYN_LOCK (rtpbin);
3894 if ((gpad = g_object_get_data (G_OBJECT (pad), "GstRTPBin.ghostpad"))) {
3895 g_object_set_data (G_OBJECT (pad), "GstRTPBin.ghostpad", NULL);
3897 gst_pad_set_active (gpad, FALSE);
3898 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3900 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
3904 pt_map_requested (GstElement * element, guint pt, GstRtpBinSession * session)
3909 rtpbin = session->bin;
3911 GST_DEBUG_OBJECT (rtpbin, "payload map requested for pt %u in session %u", pt,
3914 caps = get_pt_map (session, pt);
3923 GST_DEBUG_OBJECT (rtpbin, "could not get caps");
3929 ptdemux_pt_map_requested (GstElement * element, guint pt,
3930 GstRtpBinSession * session)
3932 GstCaps *ret = pt_map_requested (element, pt, session);
3934 if (ret && gst_caps_get_size (ret) == 1) {
3935 const GstStructure *s = gst_caps_get_structure (ret, 0);
3938 if (gst_structure_get_boolean (s, "is-fec", &is_fec) && is_fec) {
3939 GValue v = G_VALUE_INIT;
3940 GValue v2 = G_VALUE_INIT;
3942 GST_INFO_OBJECT (session->bin, "Will ignore FEC pt %u in session %u", pt,
3944 g_value_init (&v, GST_TYPE_ARRAY);
3945 g_value_init (&v2, G_TYPE_INT);
3946 g_object_get_property (G_OBJECT (element), "ignored-payload-types", &v);
3947 g_value_set_int (&v2, pt);
3948 gst_value_array_append_value (&v, &v2);
3949 g_value_unset (&v2);
3950 g_object_set_property (G_OBJECT (element), "ignored-payload-types", &v);
3959 payload_type_change (GstElement * element, guint pt, GstRtpBinSession * session)
3961 GST_DEBUG_OBJECT (session->bin,
3962 "emitting signal for pt type changed to %u in session %u", pt,
3965 g_signal_emit (session->bin, gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE],
3966 0, session->id, pt);
3969 /* emitted when caps changed for the session */
3971 caps_changed (GstPad * pad, GParamSpec * pspec, GstRtpBinSession * session)
3976 const GstStructure *s;
3980 g_object_get (pad, "caps", &caps, NULL);
3985 GST_DEBUG_OBJECT (bin, "got caps %" GST_PTR_FORMAT, caps);
3987 s = gst_caps_get_structure (caps, 0);
3989 /* get payload, finish when it's not there */
3990 if (!gst_structure_get_int (s, "payload", &payload)) {
3991 gst_caps_unref (caps);
3995 GST_RTP_SESSION_LOCK (session);
3996 GST_DEBUG_OBJECT (bin, "insert caps for payload %d", payload);
3997 g_hash_table_insert (session->ptmap, GINT_TO_POINTER (payload), caps);
3998 GST_RTP_SESSION_UNLOCK (session);
4001 /* a new pad (SSRC) was created in @session */
4003 new_ssrc_pad_found (GstElement * element, guint ssrc, GstPad * pad,
4004 GstRtpBinSession * session)
4007 GstRtpBinStream *stream;
4008 GstPad *sinkpad, *srcpad;
4011 rtpbin = session->bin;
4013 GST_DEBUG_OBJECT (rtpbin, "new SSRC pad %08x, %s:%s", ssrc,
4014 GST_DEBUG_PAD_NAME (pad));
4016 GST_RTP_BIN_SHUTDOWN_LOCK (rtpbin, shutdown);
4018 GST_RTP_SESSION_LOCK (session);
4020 /* create new stream */
4021 stream = create_stream (session, ssrc);
4025 /* get pad and link */
4026 GST_DEBUG_OBJECT (rtpbin, "linking jitterbuffer RTP");
4027 padname = g_strdup_printf ("src_%u", ssrc);
4028 srcpad = gst_element_get_static_pad (element, padname);
4031 if (session->early_fec_decoder) {
4032 GST_DEBUG_OBJECT (rtpbin, "linking fec decoder");
4033 sinkpad = gst_element_get_static_pad (session->early_fec_decoder, "sink");
4034 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
4035 gst_object_unref (sinkpad);
4036 gst_object_unref (srcpad);
4037 srcpad = gst_element_get_static_pad (session->early_fec_decoder, "src");
4040 sinkpad = gst_element_get_static_pad (stream->buffer, "sink");
4041 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
4042 gst_object_unref (sinkpad);
4043 gst_object_unref (srcpad);
4045 sinkpad = gst_element_request_pad_simple (stream->buffer, "sink_rtcp");
4047 GST_DEBUG_OBJECT (rtpbin, "linking jitterbuffer RTCP");
4048 padname = g_strdup_printf ("rtcp_src_%u", ssrc);
4049 srcpad = gst_element_get_static_pad (element, padname);
4051 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
4052 gst_object_unref (sinkpad);
4053 gst_object_unref (srcpad);
4056 if (g_signal_lookup ("handle-sync", G_OBJECT_TYPE (stream->buffer)) != 0) {
4057 /* connect to the RTCP sync signal from the jitterbuffer */
4058 GST_DEBUG_OBJECT (rtpbin, "connecting sync signal");
4059 stream->buffer_handlesync_sig = g_signal_connect (stream->buffer,
4060 "handle-sync", (GCallback) gst_rtp_bin_handle_sync, stream);
4063 if (stream->demux) {
4064 /* connect to the new-pad signal of the payload demuxer, this will expose the
4065 * new pad by ghosting it. */
4066 stream->demux_newpad_sig = g_signal_connect (stream->demux,
4067 "new-payload-type", (GCallback) new_payload_found, stream);
4068 stream->demux_padremoved_sig = g_signal_connect (stream->demux,
4069 "pad-removed", (GCallback) payload_pad_removed, stream);
4071 /* connect to the request-pt-map signal. This signal will be emitted by the
4072 * demuxer so that it can apply a proper caps on the buffers for the
4074 stream->demux_ptreq_sig = g_signal_connect (stream->demux,
4075 "request-pt-map", (GCallback) ptdemux_pt_map_requested, session);
4076 /* connect to the signal so it can be forwarded. */
4077 stream->demux_ptchange_sig = g_signal_connect (stream->demux,
4078 "payload-type-change", (GCallback) payload_type_change, session);
4080 GST_RTP_SESSION_UNLOCK (session);
4081 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
4083 /* add rtpjitterbuffer src pad to pads */
4086 pad = gst_element_get_static_pad (stream->buffer, "src");
4088 GST_RTP_SESSION_UNLOCK (session);
4089 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
4091 expose_recv_src_pad (rtpbin, pad, stream, 255);
4093 gst_object_unref (pad);
4101 GST_DEBUG_OBJECT (rtpbin, "we are shutting down");
4106 GST_RTP_SESSION_UNLOCK (session);
4107 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
4108 GST_DEBUG_OBJECT (rtpbin, "could not create stream");
4114 complete_session_sink (GstRtpBin * rtpbin, GstRtpBinSession * session)
4116 guint sessid = session->id;
4117 GstPad *recv_rtp_sink;
4118 GstElement *decoder;
4120 g_assert (!session->recv_rtp_sink);
4122 /* get recv_rtp pad and store */
4123 session->recv_rtp_sink =
4124 gst_element_request_pad_simple (session->session, "recv_rtp_sink");
4125 if (session->recv_rtp_sink == NULL)
4128 g_signal_connect (session->recv_rtp_sink, "notify::caps",
4129 (GCallback) caps_changed, session);
4131 GST_DEBUG_OBJECT (rtpbin, "requesting RTP decoder");
4132 decoder = session_request_element (session, SIGNAL_REQUEST_RTP_DECODER);
4134 GstPad *decsrc, *decsink;
4135 GstPadLinkReturn ret;
4137 GST_DEBUG_OBJECT (rtpbin, "linking RTP decoder");
4138 decsink = gst_element_get_static_pad (decoder, "rtp_sink");
4139 if (decsink == NULL)
4140 goto dec_sink_failed;
4142 recv_rtp_sink = decsink;
4144 decsrc = gst_element_get_static_pad (decoder, "rtp_src");
4146 goto dec_src_failed;
4148 ret = gst_pad_link (decsrc, session->recv_rtp_sink);
4150 gst_object_unref (decsrc);
4152 if (ret != GST_PAD_LINK_OK)
4153 goto dec_link_failed;
4156 GST_DEBUG_OBJECT (rtpbin, "no RTP decoder given");
4157 recv_rtp_sink = gst_object_ref (session->recv_rtp_sink);
4160 return recv_rtp_sink;
4165 g_warning ("rtpbin: failed to get session recv_rtp_sink pad");
4170 g_warning ("rtpbin: failed to get decoder sink pad for session %u", sessid);
4175 g_warning ("rtpbin: failed to get decoder src pad for session %u", sessid);
4176 gst_object_unref (recv_rtp_sink);
4181 g_warning ("rtpbin: failed to link rtp decoder for session %u", sessid);
4182 gst_object_unref (recv_rtp_sink);
4188 complete_session_receiver (GstRtpBin * rtpbin, GstRtpBinSession * session,
4192 GstPad *recv_rtp_src;
4194 g_assert (!session->recv_rtp_src);
4196 session->recv_rtp_src =
4197 gst_element_get_static_pad (session->session, "recv_rtp_src");
4198 if (session->recv_rtp_src == NULL)
4201 /* find out if we need AUX elements */
4202 aux = session_request_element (session, SIGNAL_REQUEST_AUX_RECEIVER);
4206 GstPadLinkReturn ret;
4208 GST_DEBUG_OBJECT (rtpbin, "linking AUX receiver");
4210 pname = g_strdup_printf ("sink_%u", sessid);
4211 auxsink = gst_element_get_static_pad (aux, pname);
4213 if (auxsink == NULL)
4214 goto aux_sink_failed;
4216 ret = gst_pad_link (session->recv_rtp_src, auxsink);
4217 gst_object_unref (auxsink);
4218 if (ret != GST_PAD_LINK_OK)
4219 goto aux_link_failed;
4221 /* this can be NULL when this AUX element is not to be linked any further */
4222 pname = g_strdup_printf ("src_%u", sessid);
4223 recv_rtp_src = gst_element_get_static_pad (aux, pname);
4226 recv_rtp_src = gst_object_ref (session->recv_rtp_src);
4229 /* Add a storage element if needed */
4230 if (recv_rtp_src && session->storage) {
4231 GstPadLinkReturn ret;
4232 GstPad *sinkpad = gst_element_get_static_pad (session->storage, "sink");
4234 ret = gst_pad_link (recv_rtp_src, sinkpad);
4236 gst_object_unref (sinkpad);
4237 gst_object_unref (recv_rtp_src);
4239 if (ret != GST_PAD_LINK_OK)
4240 goto storage_link_failed;
4242 recv_rtp_src = gst_element_get_static_pad (session->storage, "src");
4248 GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTP sink pad");
4249 sinkdpad = gst_element_get_static_pad (session->demux, "sink");
4250 GST_DEBUG_OBJECT (rtpbin, "linking demuxer RTP sink pad");
4251 gst_pad_link_full (recv_rtp_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
4252 gst_object_unref (sinkdpad);
4253 gst_object_unref (recv_rtp_src);
4255 /* connect to the new-ssrc-pad signal of the SSRC demuxer */
4256 session->demux_newpad_sig = g_signal_connect (session->demux,
4257 "new-ssrc-pad", (GCallback) new_ssrc_pad_found, session);
4258 session->demux_padremoved_sig = g_signal_connect (session->demux,
4259 "removed-ssrc-pad", (GCallback) ssrc_demux_pad_removed, session);
4266 g_warning ("rtpbin: failed to get session recv_rtp_src pad");
4271 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
4276 g_warning ("rtpbin: failed to link AUX pad to session %u", sessid);
4279 storage_link_failed:
4281 g_warning ("rtpbin: failed to link storage");
4286 /* Create a pad for receiving RTP for the session in @name. Must be called with
4290 create_recv_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
4293 GstRtpBinSession *session;
4294 GstPad *recv_rtp_sink;
4296 /* first get the session number */
4297 if (name == NULL || sscanf (name, "recv_rtp_sink_%u", &sessid) != 1)
4300 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
4302 /* get or create session */
4303 session = find_session_by_id (rtpbin, sessid);
4305 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4306 /* create session now */
4307 session = create_session (rtpbin, sessid);
4308 if (session == NULL)
4312 /* check if pad was requested */
4313 if (session->recv_rtp_sink_ghost != NULL)
4314 return session->recv_rtp_sink_ghost;
4316 /* setup the session sink pad */
4317 recv_rtp_sink = complete_session_sink (rtpbin, session);
4319 goto session_sink_failed;
4321 GST_DEBUG_OBJECT (rtpbin, "ghosting session sink pad");
4322 session->recv_rtp_sink_ghost =
4323 gst_ghost_pad_new_from_template (name, recv_rtp_sink, templ);
4324 gst_object_unref (recv_rtp_sink);
4325 gst_pad_set_active (session->recv_rtp_sink_ghost, TRUE);
4326 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->recv_rtp_sink_ghost);
4328 complete_session_receiver (rtpbin, session, sessid);
4330 return session->recv_rtp_sink_ghost;
4335 g_warning ("rtpbin: cannot find session id for pad: %s",
4336 GST_STR_NULL (name));
4341 /* create_session already warned */
4344 session_sink_failed:
4346 /* warning already done */
4352 remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4354 if (session->demux_newpad_sig) {
4355 g_signal_handler_disconnect (session->demux, session->demux_newpad_sig);
4356 session->demux_newpad_sig = 0;
4358 if (session->demux_padremoved_sig) {
4359 g_signal_handler_disconnect (session->demux, session->demux_padremoved_sig);
4360 session->demux_padremoved_sig = 0;
4362 if (session->recv_rtp_src) {
4363 gst_object_unref (session->recv_rtp_src);
4364 session->recv_rtp_src = NULL;
4366 if (session->recv_rtp_sink) {
4367 gst_element_release_request_pad (session->session, session->recv_rtp_sink);
4368 gst_object_unref (session->recv_rtp_sink);
4369 session->recv_rtp_sink = NULL;
4371 if (session->recv_rtp_sink_ghost) {
4372 gst_pad_set_active (session->recv_rtp_sink_ghost, FALSE);
4373 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4374 session->recv_rtp_sink_ghost);
4375 session->recv_rtp_sink_ghost = NULL;
4380 fec_sinkpad_find (const GValue * item, gchar * padname)
4382 GstPad *pad = g_value_get_object (item);
4383 return g_strcmp0 (GST_PAD_NAME (pad), padname);
4387 complete_session_fec (GstRtpBin * rtpbin, GstRtpBinSession * session,
4390 gboolean have_static_pad;
4395 GValue item = { 0, };
4397 if (!ensure_early_fec_decoder (rtpbin, session))
4400 padname = g_strdup_printf ("fec_%u", fec_idx);
4402 GST_DEBUG_OBJECT (rtpbin, "getting FEC sink pad %s", padname);
4404 /* First try to find the decoder static pad that matches the padname */
4405 it = gst_element_iterate_sink_pads (session->early_fec_decoder);
4407 gst_iterator_find_custom (it, (GCompareFunc) fec_sinkpad_find, &item,
4410 if (have_static_pad) {
4411 ret = g_value_get_object (&item);
4412 gst_object_ref (ret);
4413 g_value_unset (&item);
4415 ret = gst_element_request_pad_simple (session->early_fec_decoder, padname);
4419 gst_iterator_free (it);
4424 session->recv_fec_sinks = g_slist_prepend (session->recv_fec_sinks, ret);
4430 g_warning ("rtpbin: failed to get decoder fec pad");
4435 g_warning ("rtpbin: failed to build FEC decoder for session %u",
4442 complete_session_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session,
4445 GstElement *decoder;
4447 GstPad *decsink = NULL;
4449 /* get recv_rtp pad and store */
4450 GST_DEBUG_OBJECT (rtpbin, "getting RTCP sink pad");
4451 session->recv_rtcp_sink =
4452 gst_element_request_pad_simple (session->session, "recv_rtcp_sink");
4453 if (session->recv_rtcp_sink == NULL)
4456 GST_DEBUG_OBJECT (rtpbin, "getting RTCP decoder");
4457 decoder = session_request_element (session, SIGNAL_REQUEST_RTCP_DECODER);
4460 GstPadLinkReturn ret;
4462 GST_DEBUG_OBJECT (rtpbin, "linking RTCP decoder");
4463 decsink = gst_element_get_static_pad (decoder, "rtcp_sink");
4464 decsrc = gst_element_get_static_pad (decoder, "rtcp_src");
4466 if (decsink == NULL)
4467 goto dec_sink_failed;
4470 goto dec_src_failed;
4472 ret = gst_pad_link (decsrc, session->recv_rtcp_sink);
4474 gst_object_unref (decsrc);
4476 if (ret != GST_PAD_LINK_OK)
4477 goto dec_link_failed;
4479 GST_DEBUG_OBJECT (rtpbin, "no RTCP decoder given");
4480 decsink = gst_object_ref (session->recv_rtcp_sink);
4483 /* get srcpad, link to SSRCDemux */
4484 GST_DEBUG_OBJECT (rtpbin, "getting sync src pad");
4485 session->sync_src = gst_element_get_static_pad (session->session, "sync_src");
4486 if (session->sync_src == NULL)
4487 goto src_pad_failed;
4489 GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTCP sink pad");
4490 sinkdpad = gst_element_get_static_pad (session->demux, "rtcp_sink");
4491 gst_pad_link_full (session->sync_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
4492 gst_object_unref (sinkdpad);
4498 g_warning ("rtpbin: failed to get session rtcp_sink pad");
4503 g_warning ("rtpbin: failed to get decoder sink pad for session %u", sessid);
4508 g_warning ("rtpbin: failed to get decoder src pad for session %u", sessid);
4513 g_warning ("rtpbin: failed to link rtcp decoder for session %u", sessid);
4518 g_warning ("rtpbin: failed to get session sync_src pad");
4522 gst_object_unref (decsink);
4526 /* Create a pad for receiving RTCP for the session in @name. Must be called with
4530 create_recv_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
4534 GstRtpBinSession *session;
4535 GstPad *decsink = NULL;
4537 /* first get the session number */
4538 if (name == NULL || sscanf (name, "recv_rtcp_sink_%u", &sessid) != 1)
4541 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
4543 /* get or create the session */
4544 session = find_session_by_id (rtpbin, sessid);
4546 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4547 /* create session now */
4548 session = create_session (rtpbin, sessid);
4549 if (session == NULL)
4553 /* check if pad was requested */
4554 if (session->recv_rtcp_sink_ghost != NULL)
4555 return session->recv_rtcp_sink_ghost;
4557 decsink = complete_session_rtcp (rtpbin, session, sessid);
4561 session->recv_rtcp_sink_ghost =
4562 gst_ghost_pad_new_from_template (name, decsink, templ);
4563 gst_object_unref (decsink);
4564 gst_pad_set_active (session->recv_rtcp_sink_ghost, TRUE);
4565 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin),
4566 session->recv_rtcp_sink_ghost);
4568 return session->recv_rtcp_sink_ghost;
4573 g_warning ("rtpbin: cannot find session id for pad: %s",
4574 GST_STR_NULL (name));
4579 /* create_session already warned */
4585 create_recv_fec (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
4587 guint sessid, fec_idx;
4588 GstRtpBinSession *session;
4589 GstPad *decsink = NULL;
4592 /* first get the session number */
4594 || sscanf (name, "recv_fec_sink_%u_%u", &sessid, &fec_idx) != 2)
4600 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
4602 /* get or create the session */
4603 session = find_session_by_id (rtpbin, sessid);
4605 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4606 /* create session now */
4607 session = create_session (rtpbin, sessid);
4608 if (session == NULL)
4612 decsink = complete_session_fec (rtpbin, session, fec_idx);
4616 ghost = gst_ghost_pad_new_from_template (name, decsink, templ);
4617 session->recv_fec_sink_ghosts =
4618 g_slist_prepend (session->recv_fec_sink_ghosts, ghost);
4619 gst_object_unref (decsink);
4620 gst_pad_set_active (ghost, TRUE);
4621 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), ghost);
4628 g_warning ("rtpbin: cannot find session id for pad: %s",
4629 GST_STR_NULL (name));
4634 g_warning ("rtpbin: invalid FEC index: %s", GST_STR_NULL (name));
4639 /* create_session already warned */
4645 remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4647 if (session->recv_rtcp_sink_ghost) {
4648 gst_pad_set_active (session->recv_rtcp_sink_ghost, FALSE);
4649 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4650 session->recv_rtcp_sink_ghost);
4651 session->recv_rtcp_sink_ghost = NULL;
4653 if (session->sync_src) {
4654 /* releasing the request pad should also unref the sync pad */
4655 gst_object_unref (session->sync_src);
4656 session->sync_src = NULL;
4658 if (session->recv_rtcp_sink) {
4659 gst_element_release_request_pad (session->session, session->recv_rtcp_sink);
4660 gst_object_unref (session->recv_rtcp_sink);
4661 session->recv_rtcp_sink = NULL;
4666 remove_recv_fec_for_pad (GstRtpBin * rtpbin, GstRtpBinSession * session,
4672 target = gst_ghost_pad_get_target (GST_GHOST_PAD (ghost));
4675 item = g_slist_find (session->recv_fec_sinks, target);
4677 GstPadTemplate *templ;
4681 templ = gst_pad_get_pad_template (pad);
4683 if (GST_PAD_TEMPLATE_PRESENCE (templ) == GST_PAD_REQUEST) {
4684 GST_DEBUG_OBJECT (rtpbin,
4685 "Releasing FEC decoder pad %" GST_PTR_FORMAT, pad);
4686 gst_element_release_request_pad (session->early_fec_decoder, pad);
4688 gst_object_unref (pad);
4691 session->recv_fec_sinks =
4692 g_slist_delete_link (session->recv_fec_sinks, item);
4694 gst_object_unref (templ);
4696 gst_object_unref (target);
4699 item = g_slist_find (session->recv_fec_sink_ghosts, ghost);
4701 session->recv_fec_sink_ghosts =
4702 g_slist_delete_link (session->recv_fec_sink_ghosts, item);
4704 gst_pad_set_active (ghost, FALSE);
4705 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin), ghost);
4709 remove_recv_fec (GstRtpBin * rtpbin, GstRtpBinSession * session)
4714 copy = g_slist_copy (session->recv_fec_sink_ghosts);
4716 for (tmp = copy; tmp; tmp = tmp->next) {
4717 remove_recv_fec_for_pad (rtpbin, session, (GstPad *) tmp->data);
4720 g_slist_free (copy);
4724 complete_session_src (GstRtpBin * rtpbin, GstRtpBinSession * session)
4727 guint sessid = session->id;
4728 GstPad *send_rtp_src;
4729 GstElement *encoder;
4730 GstElementClass *klass;
4731 GstPadTemplate *templ;
4732 gboolean ret = FALSE;
4735 send_rtp_src = gst_element_get_static_pad (session->session, "send_rtp_src");
4737 if (send_rtp_src == NULL)
4740 GST_DEBUG_OBJECT (rtpbin, "getting RTP encoder");
4741 encoder = session_request_element (session, SIGNAL_REQUEST_RTP_ENCODER);
4744 GstPad *encsrc, *encsink;
4745 GstPadLinkReturn ret;
4747 GST_DEBUG_OBJECT (rtpbin, "linking RTP encoder");
4748 ename = g_strdup_printf ("rtp_src_%u", sessid);
4749 encsrc = gst_element_get_static_pad (encoder, ename);
4753 goto enc_src_failed;
4755 ename = g_strdup_printf ("rtp_sink_%u", sessid);
4756 encsink = gst_element_get_static_pad (encoder, ename);
4758 if (encsink == NULL)
4759 goto enc_sink_failed;
4761 ret = gst_pad_link (send_rtp_src, encsink);
4762 gst_object_unref (encsink);
4763 gst_object_unref (send_rtp_src);
4765 send_rtp_src = encsrc;
4767 if (ret != GST_PAD_LINK_OK)
4768 goto enc_link_failed;
4770 GST_DEBUG_OBJECT (rtpbin, "no RTP encoder given");
4773 /* ghost the new source pad */
4774 klass = GST_ELEMENT_GET_CLASS (rtpbin);
4775 gname = g_strdup_printf ("send_rtp_src_%u", sessid);
4776 templ = gst_element_class_get_pad_template (klass, "send_rtp_src_%u");
4777 session->send_rtp_src_ghost =
4778 gst_ghost_pad_new_from_template (gname, send_rtp_src, templ);
4779 gst_pad_set_active (session->send_rtp_src_ghost, TRUE);
4780 gst_pad_sticky_events_foreach (send_rtp_src, copy_sticky_events,
4781 session->send_rtp_src_ghost);
4782 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_src_ghost);
4789 gst_object_unref (send_rtp_src);
4796 g_warning ("rtpbin: failed to get rtp source pad for session %u", sessid);
4801 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4802 " src pad for session %u", encoder, sessid);
4807 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4808 " sink pad for session %u", encoder, sessid);
4813 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4820 setup_aux_sender_fold (const GValue * item, GValue * result, gpointer user_data)
4825 GstRtpBinSession *session = user_data, *newsess;
4826 GstRtpBin *rtpbin = session->bin;
4827 GstPadLinkReturn ret;
4829 pad = g_value_get_object (item);
4830 name = gst_pad_get_name (pad);
4832 if (name == NULL || sscanf (name, "src_%u", &sessid) != 1)
4837 newsess = find_session_by_id (rtpbin, sessid);
4838 if (newsess == NULL) {
4839 /* create new session */
4840 newsess = create_session (rtpbin, sessid);
4841 if (newsess == NULL)
4843 } else if (newsess->send_rtp_sink != NULL)
4844 goto existing_session;
4846 /* get send_rtp pad and store */
4847 newsess->send_rtp_sink =
4848 gst_element_request_pad_simple (newsess->session, "send_rtp_sink");
4849 if (newsess->send_rtp_sink == NULL)
4852 ret = gst_pad_link (pad, newsess->send_rtp_sink);
4853 if (ret != GST_PAD_LINK_OK)
4854 goto aux_link_failed;
4856 if (!complete_session_src (rtpbin, newsess))
4857 goto session_src_failed;
4864 GST_WARNING ("ignoring invalid pad name %s", GST_STR_NULL (name));
4870 /* create_session already warned */
4875 GST_DEBUG_OBJECT (rtpbin,
4876 "skipping src_%i setup, since it is already configured.", sessid);
4881 g_warning ("rtpbin: failed to get session pad for session %u", sessid);
4886 g_warning ("rtpbin: failed to link AUX for session %u", sessid);
4891 g_warning ("rtpbin: failed to complete AUX for session %u", sessid);
4897 setup_aux_sender (GstRtpBin * rtpbin, GstRtpBinSession * session,
4901 GValue result = { 0, };
4902 GstIteratorResult res;
4904 it = gst_element_iterate_src_pads (aux);
4905 res = gst_iterator_fold (it, setup_aux_sender_fold, &result, session);
4906 gst_iterator_free (it);
4908 return res == GST_ITERATOR_DONE;
4912 fec_encoder_add_pad_unlocked (GstPad * pad, GstRtpBinSession * session)
4914 GstElementClass *klass;
4916 GstPadTemplate *templ;
4920 if (sscanf (GST_PAD_NAME (pad), "fec_%u", &fec_idx) != 1) {
4921 GST_WARNING_OBJECT (session->bin,
4922 "FEC encoder added pad with name not matching fec_%%u (%s)",
4923 GST_PAD_NAME (pad));
4927 GST_INFO_OBJECT (session->bin, "FEC encoder for session %u exposed new pad",
4930 klass = GST_ELEMENT_GET_CLASS (session->bin);
4931 gname = g_strdup_printf ("send_fec_src_%u_%u", session->id, fec_idx);
4932 templ = gst_element_class_get_pad_template (klass, "send_fec_src_%u_%u");
4933 ghost = gst_ghost_pad_new_from_template (gname, pad, templ);
4934 session->send_fec_src_ghosts =
4935 g_slist_prepend (session->send_fec_src_ghosts, ghost);
4936 gst_pad_set_active (ghost, TRUE);
4937 gst_pad_sticky_events_foreach (pad, copy_sticky_events, ghost);
4938 gst_element_add_pad (GST_ELEMENT (session->bin), ghost);
4946 fec_encoder_add_pad (GstPad * pad, GstRtpBinSession * session)
4948 GST_RTP_BIN_LOCK (session->bin);
4949 fec_encoder_add_pad_unlocked (pad, session);
4950 GST_RTP_BIN_UNLOCK (session->bin);
4954 fec_srcpad_iterator_filter (const GValue * item, GValue * unused)
4957 GstPad *pad = g_value_get_object (item);
4958 GstPadTemplate *templ = gst_pad_get_pad_template (pad);
4960 gint have_static_pad =
4961 (GST_PAD_TEMPLATE_PRESENCE (templ) == GST_PAD_ALWAYS) &&
4962 (sscanf (GST_PAD_NAME (pad), "fec_%u", &fec_idx) == 1);
4964 gst_object_unref (templ);
4966 /* return 0 to retain pad in filtered iterator */
4967 return !have_static_pad;
4971 fec_srcpad_iterator_foreach (const GValue * item, GstRtpBinSession * session)
4973 GstPad *pad = g_value_get_object (item);
4974 fec_encoder_add_pad_unlocked (pad, session);
4978 fec_encoder_pad_added_cb (GstElement * encoder, GstPad * pad,
4979 GstRtpBinSession * session)
4981 fec_encoder_add_pad (pad, session);
4985 request_fec_encoder (GstRtpBin * rtpbin, GstRtpBinSession * session,
4988 GstElement *ret = NULL;
4989 const gchar *factory;
4992 sess_id_str = g_strdup_printf ("%u", sessid);
4993 factory = gst_structure_get_string (rtpbin->fec_encoders, sess_id_str);
4994 g_free (sess_id_str);
4996 /* First try the property */
5001 gst_parse_bin_from_description_full (factory, TRUE, NULL,
5002 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_FATAL_ERRORS,
5005 GST_ERROR_OBJECT (rtpbin, "Failed to build encoder from factory: %s",
5010 bin_manage_element (session->bin, ret);
5011 session->elements = g_slist_prepend (session->elements, ret);
5012 GST_INFO_OBJECT (rtpbin, "Built FEC encoder: %" GST_PTR_FORMAT
5013 " for session %u", ret, sessid);
5016 /* Fallback to the signal */
5018 ret = session_request_element (session, SIGNAL_REQUEST_FEC_ENCODER);
5021 /* First, add encoder pads that match fec_% template and are already present */
5022 GstIterator *it, *filter;
5023 GstIteratorResult it_ret = GST_ITERATOR_OK;
5025 it = gst_element_iterate_src_pads (ret);
5027 gst_iterator_filter (it, (GCompareFunc) fec_srcpad_iterator_filter,
5030 while (it_ret == GST_ITERATOR_OK || it_ret == GST_ITERATOR_RESYNC) {
5032 gst_iterator_foreach (filter,
5033 (GstIteratorForeachFunction) fec_srcpad_iterator_foreach, session);
5035 if (it_ret == GST_ITERATOR_RESYNC)
5036 gst_iterator_resync (filter);
5039 gst_iterator_free (filter);
5041 /* Finally, connect to pad-added signal if any of the encoder pads are
5043 g_signal_connect (ret, "pad-added", G_CALLBACK (fec_encoder_pad_added_cb),
5051 /* Create a pad for sending RTP for the session in @name. Must be called with
5055 create_send_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
5059 GstPad *send_rtp_sink;
5061 GstElement *encoder;
5062 GstElement *prev = NULL;
5063 GstRtpBinSession *session;
5065 /* first get the session number */
5066 if (name == NULL || sscanf (name, "send_rtp_sink_%u", &sessid) != 1)
5069 /* get or create session */
5070 session = find_session_by_id (rtpbin, sessid);
5072 /* create session now */
5073 session = create_session (rtpbin, sessid);
5074 if (session == NULL)
5078 /* check if pad was requested */
5079 if (session->send_rtp_sink_ghost != NULL)
5080 return session->send_rtp_sink_ghost;
5082 /* check if we are already using this session as a sender */
5083 if (session->send_rtp_sink != NULL)
5084 goto existing_session;
5086 encoder = request_fec_encoder (rtpbin, session, sessid);
5089 GST_DEBUG_OBJECT (rtpbin, "Linking FEC encoder");
5091 send_rtp_sink = gst_element_get_static_pad (encoder, "sink");
5094 goto enc_sink_failed;
5099 GST_DEBUG_OBJECT (rtpbin, "getting RTP AUX sender");
5100 aux = session_request_element (session, SIGNAL_REQUEST_AUX_SENDER);
5103 GST_DEBUG_OBJECT (rtpbin, "linking AUX sender");
5104 if (!setup_aux_sender (rtpbin, session, aux))
5105 goto aux_session_failed;
5107 pname = g_strdup_printf ("sink_%u", sessid);
5108 sinkpad = gst_element_get_static_pad (aux, pname);
5111 if (sinkpad == NULL)
5112 goto aux_sink_failed;
5115 send_rtp_sink = sinkpad;
5117 GstPad *srcpad = gst_element_get_static_pad (prev, "src");
5118 GstPadLinkReturn ret;
5120 ret = gst_pad_link (srcpad, sinkpad);
5121 gst_object_unref (srcpad);
5122 if (ret != GST_PAD_LINK_OK) {
5123 goto aux_link_failed;
5125 gst_object_unref (sinkpad);
5129 /* get send_rtp pad and store */
5130 session->send_rtp_sink =
5131 gst_element_request_pad_simple (session->session, "send_rtp_sink");
5132 if (session->send_rtp_sink == NULL)
5135 if (!complete_session_src (rtpbin, session))
5136 goto session_src_failed;
5139 send_rtp_sink = gst_object_ref (session->send_rtp_sink);
5141 GstPad *srcpad = gst_element_get_static_pad (prev, "src");
5142 GstPadLinkReturn ret;
5144 ret = gst_pad_link (srcpad, session->send_rtp_sink);
5145 gst_object_unref (srcpad);
5146 if (ret != GST_PAD_LINK_OK)
5147 goto session_link_failed;
5151 session->send_rtp_sink_ghost =
5152 gst_ghost_pad_new_from_template (name, send_rtp_sink, templ);
5153 gst_object_unref (send_rtp_sink);
5154 gst_pad_set_active (session->send_rtp_sink_ghost, TRUE);
5155 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_sink_ghost);
5157 return session->send_rtp_sink_ghost;
5162 g_warning ("rtpbin: cannot find session id for pad: %s",
5163 GST_STR_NULL (name));
5168 /* create_session already warned */
5173 g_warning ("rtpbin: session %u is already in use", sessid);
5178 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
5183 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
5188 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
5194 g_warning ("rtpbin: failed to get session pad for session %u", sessid);
5199 g_warning ("rtpbin: failed to setup source pads for session %u", sessid);
5202 session_link_failed:
5204 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
5210 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
5211 " sink pad for session %u", encoder, sessid);
5217 remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session)
5219 if (session->send_rtp_src_ghost) {
5220 gst_pad_set_active (session->send_rtp_src_ghost, FALSE);
5221 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
5222 session->send_rtp_src_ghost);
5223 session->send_rtp_src_ghost = NULL;
5225 if (session->send_rtp_sink) {
5226 gst_element_release_request_pad (GST_ELEMENT_CAST (session->session),
5227 session->send_rtp_sink);
5228 gst_object_unref (session->send_rtp_sink);
5229 session->send_rtp_sink = NULL;
5231 if (session->send_rtp_sink_ghost) {
5232 gst_pad_set_active (session->send_rtp_sink_ghost, FALSE);
5233 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
5234 session->send_rtp_sink_ghost);
5235 session->send_rtp_sink_ghost = NULL;
5240 remove_send_fec (GstRtpBin * rtpbin, GstRtpBinSession * session)
5244 for (tmp = session->send_fec_src_ghosts; tmp; tmp = tmp->next) {
5245 GstPad *ghost = GST_PAD (tmp->data);
5246 gst_pad_set_active (ghost, FALSE);
5247 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin), ghost);
5250 g_slist_free (session->send_fec_src_ghosts);
5251 session->send_fec_src_ghosts = NULL;
5254 /* Create a pad for sending RTCP for the session in @name. Must be called with
5258 create_send_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
5263 GstElement *encoder;
5264 GstRtpBinSession *session;
5266 /* first get the session number */
5267 if (name == NULL || sscanf (name, "send_rtcp_src_%u", &sessid) != 1)
5270 /* get or create session */
5271 session = find_session_by_id (rtpbin, sessid);
5273 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
5274 /* create session now */
5275 session = create_session (rtpbin, sessid);
5276 if (session == NULL)
5280 /* check if pad was requested */
5281 if (session->send_rtcp_src_ghost != NULL)
5282 return session->send_rtcp_src_ghost;
5284 /* get rtcp_src pad and store */
5285 session->send_rtcp_src =
5286 gst_element_request_pad_simple (session->session, "send_rtcp_src");
5287 if (session->send_rtcp_src == NULL)
5290 GST_DEBUG_OBJECT (rtpbin, "getting RTCP encoder");
5291 encoder = session_request_element (session, SIGNAL_REQUEST_RTCP_ENCODER);
5295 GstPadLinkReturn ret;
5297 GST_DEBUG_OBJECT (rtpbin, "linking RTCP encoder");
5299 ename = g_strdup_printf ("rtcp_src_%u", sessid);
5300 encsrc = gst_element_get_static_pad (encoder, ename);
5303 goto enc_src_failed;
5305 ename = g_strdup_printf ("rtcp_sink_%u", sessid);
5306 encsink = gst_element_get_static_pad (encoder, ename);
5308 if (encsink == NULL)
5309 goto enc_sink_failed;
5311 ret = gst_pad_link (session->send_rtcp_src, encsink);
5312 gst_object_unref (encsink);
5314 if (ret != GST_PAD_LINK_OK)
5315 goto enc_link_failed;
5317 GST_DEBUG_OBJECT (rtpbin, "no RTCP encoder given");
5318 encsrc = gst_object_ref (session->send_rtcp_src);
5321 session->send_rtcp_src_ghost =
5322 gst_ghost_pad_new_from_template (name, encsrc, templ);
5323 gst_object_unref (encsrc);
5324 gst_pad_set_active (session->send_rtcp_src_ghost, TRUE);
5325 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtcp_src_ghost);
5327 return session->send_rtcp_src_ghost;
5332 g_warning ("rtpbin: cannot find session id for pad: %s",
5333 GST_STR_NULL (name));
5338 /* create_session already warned */
5343 g_warning ("rtpbin: failed to get rtcp pad for session %u", sessid);
5348 g_warning ("rtpbin: failed to get encoder src pad for session %u", sessid);
5353 g_warning ("rtpbin: failed to get encoder sink pad for session %u", sessid);
5354 gst_object_unref (encsrc);
5359 g_warning ("rtpbin: failed to link rtcp encoder for session %u", sessid);
5360 gst_object_unref (encsrc);
5366 remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session)
5368 if (session->send_rtcp_src_ghost) {
5369 gst_pad_set_active (session->send_rtcp_src_ghost, FALSE);
5370 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
5371 session->send_rtcp_src_ghost);
5372 session->send_rtcp_src_ghost = NULL;
5374 if (session->send_rtcp_src) {
5375 gst_element_release_request_pad (session->session, session->send_rtcp_src);
5376 gst_object_unref (session->send_rtcp_src);
5377 session->send_rtcp_src = NULL;
5381 /* If the requested name is NULL we should create a name with
5382 * the session number assuming we want the lowest possible session
5383 * with a free pad like the template */
5385 gst_rtp_bin_get_free_pad_name (GstElement * element, GstPadTemplate * templ)
5387 gboolean name_found = FALSE;
5389 GstIterator *pad_it = NULL;
5390 gchar *pad_name = NULL;
5391 GValue data = { 0, };
5393 GST_DEBUG_OBJECT (element, "find a free pad name for template");
5394 while (!name_found) {
5395 gboolean done = FALSE;
5398 pad_name = g_strdup_printf (templ->name_template, session++);
5399 pad_it = gst_element_iterate_pads (GST_ELEMENT (element));
5402 switch (gst_iterator_next (pad_it, &data)) {
5403 case GST_ITERATOR_OK:
5408 pad = g_value_get_object (&data);
5409 name = gst_pad_get_name (pad);
5411 if (strcmp (name, pad_name) == 0) {
5416 g_value_reset (&data);
5419 case GST_ITERATOR_ERROR:
5420 case GST_ITERATOR_RESYNC:
5421 /* restart iteration */
5426 case GST_ITERATOR_DONE:
5431 g_value_unset (&data);
5432 gst_iterator_free (pad_it);
5435 GST_DEBUG_OBJECT (element, "free pad name found: '%s'", pad_name);
5442 gst_rtp_bin_request_new_pad (GstElement * element,
5443 GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
5446 GstElementClass *klass;
5449 gchar *pad_name = NULL;
5451 g_return_val_if_fail (templ != NULL, NULL);
5452 g_return_val_if_fail (GST_IS_RTP_BIN (element), NULL);
5454 rtpbin = GST_RTP_BIN (element);
5455 klass = GST_ELEMENT_GET_CLASS (element);
5457 GST_RTP_BIN_LOCK (rtpbin);
5460 /* use a free pad name */
5461 pad_name = gst_rtp_bin_get_free_pad_name (element, templ);
5463 /* use the provided name */
5464 pad_name = g_strdup (name);
5467 GST_DEBUG_OBJECT (rtpbin, "Trying to request a pad with name %s", pad_name);
5469 /* figure out the template */
5470 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink_%u")) {
5471 result = create_recv_rtp (rtpbin, templ, pad_name);
5472 } else if (templ == gst_element_class_get_pad_template (klass,
5473 "recv_rtcp_sink_%u")) {
5474 result = create_recv_rtcp (rtpbin, templ, pad_name);
5475 } else if (templ == gst_element_class_get_pad_template (klass,
5476 "send_rtp_sink_%u")) {
5477 result = create_send_rtp (rtpbin, templ, pad_name);
5478 } else if (templ == gst_element_class_get_pad_template (klass,
5479 "send_rtcp_src_%u")) {
5480 result = create_send_rtcp (rtpbin, templ, pad_name);
5481 } else if (templ == gst_element_class_get_pad_template (klass,
5482 "recv_fec_sink_%u_%u")) {
5483 result = create_recv_fec (rtpbin, templ, pad_name);
5485 goto wrong_template;
5488 GST_RTP_BIN_UNLOCK (rtpbin);
5496 GST_RTP_BIN_UNLOCK (rtpbin);
5497 g_warning ("rtpbin: this is not our template");
5503 gst_rtp_bin_release_pad (GstElement * element, GstPad * pad)
5505 GstRtpBinSession *session;
5508 g_return_if_fail (GST_IS_GHOST_PAD (pad));
5509 g_return_if_fail (GST_IS_RTP_BIN (element));
5511 rtpbin = GST_RTP_BIN (element);
5513 GST_RTP_BIN_LOCK (rtpbin);
5514 GST_DEBUG_OBJECT (rtpbin, "Trying to release pad %s:%s",
5515 GST_DEBUG_PAD_NAME (pad));
5517 if (!(session = find_session_by_pad (rtpbin, pad)))
5520 if (session->recv_rtp_sink_ghost == pad) {
5521 remove_recv_rtp (rtpbin, session);
5522 } else if (session->recv_rtcp_sink_ghost == pad) {
5523 remove_recv_rtcp (rtpbin, session);
5524 } else if (session->send_rtp_sink_ghost == pad) {
5525 remove_send_rtp (rtpbin, session);
5526 } else if (session->send_rtcp_src_ghost == pad) {
5527 remove_rtcp (rtpbin, session);
5528 } else if (pad_is_recv_fec (session, pad)) {
5529 remove_recv_fec_for_pad (rtpbin, session, pad);
5532 /* no more request pads, free the complete session */
5533 if (session->recv_rtp_sink_ghost == NULL
5534 && session->recv_rtcp_sink_ghost == NULL
5535 && session->send_rtp_sink_ghost == NULL
5536 && session->send_rtcp_src_ghost == NULL
5537 && session->recv_fec_sink_ghosts == NULL) {
5538 GST_DEBUG_OBJECT (rtpbin, "no more pads for session %p", session);
5539 rtpbin->sessions = g_slist_remove (rtpbin->sessions, session);
5540 free_session (session, rtpbin);
5542 GST_RTP_BIN_UNLOCK (rtpbin);
5549 GST_RTP_BIN_UNLOCK (rtpbin);
5550 g_warning ("rtpbin: %s:%s is not one of our request pads",
5551 GST_DEBUG_PAD_NAME (pad));