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")
168 static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
169 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%u",
172 GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
175 static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
176 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink_%u",
179 GST_STATIC_CAPS ("application/x-rtp")
183 static GstStaticPadTemplate rtpbin_recv_rtp_src_template =
184 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%u_%u_%u",
187 GST_STATIC_CAPS ("application/x-rtp")
190 static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
191 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%u",
194 GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
197 static GstStaticPadTemplate rtpbin_send_rtp_src_template =
198 GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%u",
201 GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
204 #define GST_RTP_BIN_LOCK(bin) g_mutex_lock (&(bin)->priv->bin_lock)
205 #define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->bin_lock)
207 /* lock to protect dynamic callbacks, like pad-added and new ssrc. */
208 #define GST_RTP_BIN_DYN_LOCK(bin) g_mutex_lock (&(bin)->priv->dyn_lock)
209 #define GST_RTP_BIN_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->dyn_lock)
211 /* lock for shutdown */
212 #define GST_RTP_BIN_SHUTDOWN_LOCK(bin,label) \
214 if (g_atomic_int_get (&bin->priv->shutdown)) \
216 GST_RTP_BIN_DYN_LOCK (bin); \
217 if (g_atomic_int_get (&bin->priv->shutdown)) { \
218 GST_RTP_BIN_DYN_UNLOCK (bin); \
223 /* unlock for shutdown */
224 #define GST_RTP_BIN_SHUTDOWN_UNLOCK(bin) \
225 GST_RTP_BIN_DYN_UNLOCK (bin); \
227 /* Minimum time offset to apply. This compensates for rounding errors in NTP to
228 * RTP timestamp conversions */
229 #define MIN_TS_OFFSET (4 * GST_MSECOND)
231 struct _GstRtpBinPrivate
235 /* lock protecting dynamic adding/removing */
238 /* if we are shutting down or not */
243 /* NTP time in ns of last SR sync used */
244 guint64 last_ntpnstime;
246 /* list of extra elements */
250 /* signals and args */
253 SIGNAL_REQUEST_PT_MAP,
254 SIGNAL_PAYLOAD_TYPE_CHANGE,
258 SIGNAL_GET_INTERNAL_SESSION,
260 SIGNAL_GET_INTERNAL_STORAGE,
263 SIGNAL_ON_SSRC_COLLISION,
264 SIGNAL_ON_SSRC_VALIDATED,
265 SIGNAL_ON_SSRC_ACTIVE,
268 SIGNAL_ON_BYE_TIMEOUT,
270 SIGNAL_ON_SENDER_TIMEOUT,
273 SIGNAL_REQUEST_RTP_ENCODER,
274 SIGNAL_REQUEST_RTP_DECODER,
275 SIGNAL_REQUEST_RTCP_ENCODER,
276 SIGNAL_REQUEST_RTCP_DECODER,
278 SIGNAL_REQUEST_FEC_DECODER,
279 SIGNAL_REQUEST_FEC_ENCODER,
281 SIGNAL_REQUEST_JITTERBUFFER,
283 SIGNAL_NEW_JITTERBUFFER,
286 SIGNAL_REQUEST_AUX_SENDER,
287 SIGNAL_REQUEST_AUX_RECEIVER,
289 SIGNAL_ON_NEW_SENDER_SSRC,
290 SIGNAL_ON_SENDER_SSRC_ACTIVE,
292 SIGNAL_ON_BUNDLED_SSRC,
297 #define DEFAULT_LATENCY_MS 200
298 #define DEFAULT_DROP_ON_LATENCY FALSE
299 #define DEFAULT_SDES NULL
300 #define DEFAULT_DO_LOST FALSE
301 #define DEFAULT_IGNORE_PT FALSE
302 #define DEFAULT_NTP_SYNC FALSE
303 #define DEFAULT_AUTOREMOVE FALSE
304 #define DEFAULT_BUFFER_MODE RTP_JITTER_BUFFER_MODE_SLAVE
305 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
306 #define DEFAULT_RTCP_SYNC GST_RTP_BIN_RTCP_SYNC_ALWAYS
307 #define DEFAULT_RTCP_SYNC_INTERVAL 0
308 #define DEFAULT_DO_SYNC_EVENT FALSE
309 #define DEFAULT_DO_RETRANSMISSION FALSE
310 #define DEFAULT_RTP_PROFILE GST_RTP_PROFILE_AVP
311 #define DEFAULT_NTP_TIME_SOURCE GST_RTP_NTP_TIME_SOURCE_NTP
312 #define DEFAULT_RTCP_SYNC_SEND_TIME TRUE
313 #define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
314 #define DEFAULT_MAX_DROPOUT_TIME 60000
315 #define DEFAULT_MAX_MISORDER_TIME 2000
316 #define DEFAULT_RFC7273_SYNC FALSE
317 #define DEFAULT_MAX_STREAMS G_MAXUINT
318 #define DEFAULT_MAX_TS_OFFSET_ADJUSTMENT G_GUINT64_CONSTANT(0)
319 #define DEFAULT_MAX_TS_OFFSET G_GINT64_CONSTANT(3000000000)
320 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
321 #define DEFAULT_RTSP_USE_BUFFERING FALSE
328 PROP_DROP_ON_LATENCY,
334 PROP_RTCP_SYNC_INTERVAL,
337 PROP_USE_PIPELINE_CLOCK,
339 PROP_DO_RETRANSMISSION,
341 PROP_NTP_TIME_SOURCE,
342 PROP_RTCP_SYNC_SEND_TIME,
343 PROP_MAX_RTCP_RTP_TIME_DIFF,
344 PROP_MAX_DROPOUT_TIME,
345 PROP_MAX_MISORDER_TIME,
348 PROP_MAX_TS_OFFSET_ADJUSTMENT,
350 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
351 PROP_USE_RTSP_BUFFERING /* use for player RTSP buffering */
355 #define GST_RTP_BIN_RTCP_SYNC_TYPE (gst_rtp_bin_rtcp_sync_get_type())
357 gst_rtp_bin_rtcp_sync_get_type (void)
359 static GType rtcp_sync_type = 0;
360 static const GEnumValue rtcp_sync_types[] = {
361 {GST_RTP_BIN_RTCP_SYNC_ALWAYS, "always", "always"},
362 {GST_RTP_BIN_RTCP_SYNC_INITIAL, "initial", "initial"},
363 {GST_RTP_BIN_RTCP_SYNC_RTP, "rtp-info", "rtp-info"},
367 if (!rtcp_sync_type) {
368 rtcp_sync_type = g_enum_register_static ("GstRTCPSync", rtcp_sync_types);
370 return rtcp_sync_type;
374 typedef struct _GstRtpBinSession GstRtpBinSession;
375 typedef struct _GstRtpBinStream GstRtpBinStream;
376 typedef struct _GstRtpBinClient GstRtpBinClient;
378 static guint gst_rtp_bin_signals[LAST_SIGNAL] = { 0 };
380 static GstCaps *pt_map_requested (GstElement * element, guint pt,
381 GstRtpBinSession * session);
382 static void payload_type_change (GstElement * element, guint pt,
383 GstRtpBinSession * session);
384 static void remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
385 static void remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
386 static void remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
387 static void remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
388 static void free_client (GstRtpBinClient * client, GstRtpBin * bin);
389 static void free_stream (GstRtpBinStream * stream, GstRtpBin * bin);
390 static GstRtpBinSession *create_session (GstRtpBin * rtpbin, gint id);
391 static GstPad *complete_session_sink (GstRtpBin * rtpbin,
392 GstRtpBinSession * session);
394 complete_session_receiver (GstRtpBin * rtpbin, GstRtpBinSession * session,
396 static GstPad *complete_session_rtcp (GstRtpBin * rtpbin,
397 GstRtpBinSession * session, guint sessid);
398 static GstElement *session_request_element (GstRtpBinSession * session,
401 /* Manages the RTP stream for one SSRC.
403 * We pipe the stream (coming from the SSRC demuxer) into a jitterbuffer.
404 * If we see an SDES RTCP packet that links multiple SSRCs together based on a
405 * common CNAME, we create a GstRtpBinClient structure to group the SSRCs
406 * together (see below).
408 struct _GstRtpBinStream
410 /* the SSRC of this stream */
416 /* the session this SSRC belongs to */
417 GstRtpBinSession *session;
419 /* the jitterbuffer of the SSRC */
421 gulong buffer_handlesync_sig;
422 gulong buffer_ptreq_sig;
423 gulong buffer_ntpstop_sig;
425 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
428 /* the PT demuxer of the SSRC */
430 gulong demux_newpad_sig;
431 gulong demux_padremoved_sig;
432 gulong demux_ptreq_sig;
433 gulong demux_ptchange_sig;
435 /* if we have calculated a valid rt_delta for this stream */
437 /* mapping to local RTP and NTP time */
440 /* base rtptime in gst time */
444 #define GST_RTP_SESSION_LOCK(sess) g_mutex_lock (&(sess)->lock)
445 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock (&(sess)->lock)
447 /* Manages the receiving end of the packets.
449 * There is one such structure for each RTP session (audio/video/...).
450 * We get the RTP/RTCP packets and stuff them into the session manager. From
451 * there they are pushed into an SSRC demuxer that splits the stream based on
452 * SSRC. Each of the SSRC streams go into their own jitterbuffer (managed with
453 * the GstRtpBinStream above).
455 * Before the SSRC demuxer, a storage element may be inserted for the purpose
456 * of Forward Error Correction.
458 struct _GstRtpBinSession
464 /* the session element */
466 /* the SSRC demuxer */
468 gulong demux_newpad_sig;
469 gulong demux_padremoved_sig;
476 /* list of GstRtpBinStream */
479 /* list of elements */
482 /* mapping of payload type to caps */
485 /* the pads of the session */
486 GstPad *recv_rtp_sink;
487 GstPad *recv_rtp_sink_ghost;
488 GstPad *recv_rtp_src;
489 GstPad *recv_rtcp_sink;
490 GstPad *recv_rtcp_sink_ghost;
492 GstPad *send_rtp_sink;
493 GstPad *send_rtp_sink_ghost;
494 GstPad *send_rtp_src_ghost;
495 GstPad *send_rtcp_src;
496 GstPad *send_rtcp_src_ghost;
499 /* Manages the RTP streams that come from one client and should therefore be
502 struct _GstRtpBinClient
504 /* the common CNAME for the streams */
513 /* find a session with the given id. Must be called with RTP_BIN_LOCK */
514 static GstRtpBinSession *
515 find_session_by_id (GstRtpBin * rtpbin, gint id)
519 for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
520 GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
528 /* find a session with the given request pad. Must be called with RTP_BIN_LOCK */
529 static GstRtpBinSession *
530 find_session_by_pad (GstRtpBin * rtpbin, GstPad * pad)
534 for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
535 GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
537 if ((sess->recv_rtp_sink_ghost == pad) ||
538 (sess->recv_rtcp_sink_ghost == pad) ||
539 (sess->send_rtp_sink_ghost == pad)
540 || (sess->send_rtcp_src_ghost == pad))
547 on_new_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
549 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC], 0,
554 on_ssrc_collision (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
556 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION], 0,
561 on_ssrc_validated (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
563 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
568 on_ssrc_active (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
570 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
575 on_ssrc_sdes (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
577 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES], 0,
582 on_bye_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
584 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC], 0,
589 on_bye_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
591 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
594 if (sess->bin->priv->autoremove)
595 g_signal_emit_by_name (sess->demux, "clear-ssrc", ssrc, NULL);
599 on_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
601 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT], 0,
604 if (sess->bin->priv->autoremove)
605 g_signal_emit_by_name (sess->demux, "clear-ssrc", ssrc, NULL);
609 on_sender_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
611 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
616 on_npt_stop (GstElement * jbuf, GstRtpBinStream * stream)
618 g_signal_emit (stream->bin, gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP], 0,
619 stream->session->id, stream->ssrc);
623 on_new_sender_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
625 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SENDER_SSRC], 0,
630 on_sender_ssrc_active (GstElement * session, guint32 ssrc,
631 GstRtpBinSession * sess)
633 g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE],
637 /* must be called with the SESSION lock */
638 static GstRtpBinStream *
639 find_stream_by_ssrc (GstRtpBinSession * session, guint32 ssrc)
643 for (walk = session->streams; walk; walk = g_slist_next (walk)) {
644 GstRtpBinStream *stream = (GstRtpBinStream *) walk->data;
646 if (stream->ssrc == ssrc)
653 ssrc_demux_pad_removed (GstElement * element, guint ssrc, GstPad * pad,
654 GstRtpBinSession * session)
656 GstRtpBinStream *stream = NULL;
659 rtpbin = session->bin;
661 GST_RTP_BIN_LOCK (rtpbin);
663 GST_RTP_SESSION_LOCK (session);
664 if ((stream = find_stream_by_ssrc (session, ssrc)))
665 session->streams = g_slist_remove (session->streams, stream);
666 GST_RTP_SESSION_UNLOCK (session);
669 free_stream (stream, rtpbin);
671 GST_RTP_BIN_UNLOCK (rtpbin);
674 /* create a session with the given id. Must be called with RTP_BIN_LOCK */
675 static GstRtpBinSession *
676 create_session (GstRtpBin * rtpbin, gint id)
678 GstRtpBinSession *sess;
679 GstElement *session, *demux;
680 GstElement *storage = NULL;
683 if (!(session = gst_element_factory_make ("rtpsession", NULL)))
686 if (!(demux = gst_element_factory_make ("rtpssrcdemux", NULL)))
689 if (!(storage = gst_element_factory_make ("rtpstorage", NULL)))
692 /* need to sink the storage or otherwise signal handlers from bindings will
693 * take ownership of it and we don't own it anymore */
694 gst_object_ref_sink (storage);
695 g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_STORAGE], 0, storage,
698 sess = g_new0 (GstRtpBinSession, 1);
699 g_mutex_init (&sess->lock);
702 sess->session = session;
704 sess->storage = storage;
706 sess->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
707 (GDestroyNotify) gst_caps_unref);
708 rtpbin->sessions = g_slist_prepend (rtpbin->sessions, sess);
710 /* configure SDES items */
711 GST_OBJECT_LOCK (rtpbin);
712 g_object_set (demux, "max-streams", rtpbin->max_streams, NULL);
713 g_object_set (session, "sdes", rtpbin->sdes, "rtp-profile",
714 rtpbin->rtp_profile, "rtcp-sync-send-time", rtpbin->rtcp_sync_send_time,
716 if (rtpbin->use_pipeline_clock)
717 g_object_set (session, "use-pipeline-clock", rtpbin->use_pipeline_clock,
720 g_object_set (session, "ntp-time-source", rtpbin->ntp_time_source, NULL);
722 g_object_set (session, "max-dropout-time", rtpbin->max_dropout_time,
723 "max-misorder-time", rtpbin->max_misorder_time, NULL);
724 GST_OBJECT_UNLOCK (rtpbin);
726 /* provide clock_rate to the session manager when needed */
727 g_signal_connect (session, "request-pt-map",
728 (GCallback) pt_map_requested, sess);
730 g_signal_connect (sess->session, "on-new-ssrc",
731 (GCallback) on_new_ssrc, sess);
732 g_signal_connect (sess->session, "on-ssrc-collision",
733 (GCallback) on_ssrc_collision, sess);
734 g_signal_connect (sess->session, "on-ssrc-validated",
735 (GCallback) on_ssrc_validated, sess);
736 g_signal_connect (sess->session, "on-ssrc-active",
737 (GCallback) on_ssrc_active, sess);
738 g_signal_connect (sess->session, "on-ssrc-sdes",
739 (GCallback) on_ssrc_sdes, sess);
740 g_signal_connect (sess->session, "on-bye-ssrc",
741 (GCallback) on_bye_ssrc, sess);
742 g_signal_connect (sess->session, "on-bye-timeout",
743 (GCallback) on_bye_timeout, sess);
744 g_signal_connect (sess->session, "on-timeout", (GCallback) on_timeout, sess);
745 g_signal_connect (sess->session, "on-sender-timeout",
746 (GCallback) on_sender_timeout, sess);
747 g_signal_connect (sess->session, "on-new-sender-ssrc",
748 (GCallback) on_new_sender_ssrc, sess);
749 g_signal_connect (sess->session, "on-sender-ssrc-active",
750 (GCallback) on_sender_ssrc_active, sess);
752 gst_bin_add (GST_BIN_CAST (rtpbin), session);
753 gst_bin_add (GST_BIN_CAST (rtpbin), demux);
754 gst_bin_add (GST_BIN_CAST (rtpbin), storage);
756 /* unref the storage again, the bin has a reference now and
757 * we don't need it anymore */
758 gst_object_unref (storage);
760 GST_OBJECT_LOCK (rtpbin);
761 target = GST_STATE_TARGET (rtpbin);
762 GST_OBJECT_UNLOCK (rtpbin);
764 /* change state only to what's needed */
765 gst_element_set_state (demux, target);
766 gst_element_set_state (session, target);
767 gst_element_set_state (storage, target);
774 g_warning ("rtpbin: could not create rtpsession element");
779 gst_object_unref (session);
780 g_warning ("rtpbin: could not create rtpssrcdemux element");
785 gst_object_unref (session);
786 gst_object_unref (demux);
787 g_warning ("rtpbin: could not create rtpstorage element");
793 bin_manage_element (GstRtpBin * bin, GstElement * element)
795 GstRtpBinPrivate *priv = bin->priv;
797 if (g_list_find (priv->elements, element)) {
798 GST_DEBUG_OBJECT (bin, "requested element %p already in bin", element);
800 GST_DEBUG_OBJECT (bin, "adding requested element %p", element);
802 if (g_object_is_floating (element))
803 element = gst_object_ref_sink (element);
805 if (!gst_bin_add (GST_BIN_CAST (bin), element))
807 if (!gst_element_sync_state_with_parent (element))
808 GST_WARNING_OBJECT (bin, "unable to sync element state with rtpbin");
810 /* we add the element multiple times, each we need an equal number of
811 * removes to really remove the element from the bin */
812 priv->elements = g_list_prepend (priv->elements, element);
819 GST_WARNING_OBJECT (bin, "unable to add element");
820 gst_object_unref (element);
826 remove_bin_element (GstElement * element, GstRtpBin * bin)
828 GstRtpBinPrivate *priv = bin->priv;
831 find = g_list_find (priv->elements, element);
833 priv->elements = g_list_delete_link (priv->elements, find);
835 if (!g_list_find (priv->elements, element)) {
836 gst_element_set_locked_state (element, TRUE);
837 gst_bin_remove (GST_BIN_CAST (bin), element);
838 gst_element_set_state (element, GST_STATE_NULL);
841 gst_object_unref (element);
845 /* called with RTP_BIN_LOCK */
847 free_session (GstRtpBinSession * sess, GstRtpBin * bin)
849 GST_DEBUG_OBJECT (bin, "freeing session %p", sess);
851 gst_element_set_locked_state (sess->demux, TRUE);
852 gst_element_set_locked_state (sess->session, TRUE);
853 gst_element_set_locked_state (sess->storage, TRUE);
855 gst_element_set_state (sess->demux, GST_STATE_NULL);
856 gst_element_set_state (sess->session, GST_STATE_NULL);
857 gst_element_set_state (sess->storage, GST_STATE_NULL);
859 remove_recv_rtp (bin, sess);
860 remove_recv_rtcp (bin, sess);
861 remove_send_rtp (bin, sess);
862 remove_rtcp (bin, sess);
864 gst_bin_remove (GST_BIN_CAST (bin), sess->session);
865 gst_bin_remove (GST_BIN_CAST (bin), sess->demux);
866 gst_bin_remove (GST_BIN_CAST (bin), sess->storage);
868 g_slist_foreach (sess->elements, (GFunc) remove_bin_element, bin);
869 g_slist_free (sess->elements);
870 sess->elements = NULL;
872 g_slist_foreach (sess->streams, (GFunc) free_stream, bin);
873 g_slist_free (sess->streams);
875 g_mutex_clear (&sess->lock);
876 g_hash_table_destroy (sess->ptmap);
881 /* get the payload type caps for the specific payload @pt in @session */
883 get_pt_map (GstRtpBinSession * session, guint pt)
885 GstCaps *caps = NULL;
888 GValue args[3] = { {0}, {0}, {0} };
890 GST_DEBUG ("searching pt %u in cache", pt);
892 GST_RTP_SESSION_LOCK (session);
894 /* first look in the cache */
895 caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
903 GST_DEBUG ("emitting signal for pt %u in session %u", pt, session->id);
905 /* not in cache, send signal to request caps */
906 g_value_init (&args[0], GST_TYPE_ELEMENT);
907 g_value_set_object (&args[0], bin);
908 g_value_init (&args[1], G_TYPE_UINT);
909 g_value_set_uint (&args[1], session->id);
910 g_value_init (&args[2], G_TYPE_UINT);
911 g_value_set_uint (&args[2], pt);
913 g_value_init (&ret, GST_TYPE_CAPS);
914 g_value_set_boxed (&ret, NULL);
916 GST_RTP_SESSION_UNLOCK (session);
918 g_signal_emitv (args, gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP], 0, &ret);
920 GST_RTP_SESSION_LOCK (session);
922 g_value_unset (&args[0]);
923 g_value_unset (&args[1]);
924 g_value_unset (&args[2]);
926 /* look in the cache again because we let the lock go */
927 caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
930 g_value_unset (&ret);
934 caps = (GstCaps *) g_value_dup_boxed (&ret);
935 g_value_unset (&ret);
939 GST_DEBUG ("caching pt %u as %" GST_PTR_FORMAT, pt, caps);
941 /* store in cache, take additional ref */
942 g_hash_table_insert (session->ptmap, GINT_TO_POINTER (pt),
943 gst_caps_ref (caps));
946 GST_RTP_SESSION_UNLOCK (session);
953 GST_RTP_SESSION_UNLOCK (session);
954 GST_DEBUG ("no pt map could be obtained");
960 return_true (gpointer key, gpointer value, gpointer user_data)
966 gst_rtp_bin_reset_sync (GstRtpBin * rtpbin)
968 GSList *clients, *streams;
970 GST_DEBUG_OBJECT (rtpbin, "Reset sync on all clients");
972 GST_RTP_BIN_LOCK (rtpbin);
973 for (clients = rtpbin->clients; clients; clients = g_slist_next (clients)) {
974 GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
976 /* reset sync on all streams for this client */
977 for (streams = client->streams; streams; streams = g_slist_next (streams)) {
978 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
980 /* make use require a new SR packet for this stream before we attempt new
982 stream->have_sync = FALSE;
983 stream->rt_delta = 0;
984 stream->rtp_delta = 0;
985 stream->clock_base = -100 * GST_SECOND;
988 GST_RTP_BIN_UNLOCK (rtpbin);
992 gst_rtp_bin_clear_pt_map (GstRtpBin * bin)
994 GSList *sessions, *streams;
996 GST_RTP_BIN_LOCK (bin);
997 GST_DEBUG_OBJECT (bin, "clearing pt map");
998 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
999 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
1001 GST_DEBUG_OBJECT (bin, "clearing session %p", session);
1002 g_signal_emit_by_name (session->session, "clear-pt-map", NULL);
1004 GST_RTP_SESSION_LOCK (session);
1005 g_hash_table_foreach_remove (session->ptmap, return_true, NULL);
1007 for (streams = session->streams; streams; streams = g_slist_next (streams)) {
1008 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1010 GST_DEBUG_OBJECT (bin, "clearing stream %p", stream);
1011 if (g_signal_lookup ("clear-pt-map", G_OBJECT_TYPE (stream->buffer)) != 0)
1012 g_signal_emit_by_name (stream->buffer, "clear-pt-map", NULL);
1014 g_signal_emit_by_name (stream->demux, "clear-pt-map", NULL);
1016 GST_RTP_SESSION_UNLOCK (session);
1018 GST_RTP_BIN_UNLOCK (bin);
1020 /* reset sync too */
1021 gst_rtp_bin_reset_sync (bin);
1025 gst_rtp_bin_get_session (GstRtpBin * bin, guint session_id)
1027 GstRtpBinSession *session;
1028 GstElement *ret = NULL;
1030 GST_RTP_BIN_LOCK (bin);
1031 GST_DEBUG_OBJECT (bin, "retrieving GstRtpSession, index: %u", session_id);
1032 session = find_session_by_id (bin, (gint) session_id);
1034 ret = gst_object_ref (session->session);
1036 GST_RTP_BIN_UNLOCK (bin);
1042 gst_rtp_bin_get_internal_session (GstRtpBin * bin, guint session_id)
1044 RTPSession *internal_session = NULL;
1045 GstRtpBinSession *session;
1047 GST_RTP_BIN_LOCK (bin);
1048 GST_DEBUG_OBJECT (bin, "retrieving internal RTPSession object, index: %u",
1050 session = find_session_by_id (bin, (gint) session_id);
1052 g_object_get (session->session, "internal-session", &internal_session,
1055 GST_RTP_BIN_UNLOCK (bin);
1057 return internal_session;
1061 gst_rtp_bin_get_storage (GstRtpBin * bin, guint session_id)
1063 GstRtpBinSession *session;
1064 GstElement *res = NULL;
1066 GST_RTP_BIN_LOCK (bin);
1067 GST_DEBUG_OBJECT (bin, "retrieving internal storage object, index: %u",
1069 session = find_session_by_id (bin, (gint) session_id);
1070 if (session && session->storage) {
1071 res = gst_object_ref (session->storage);
1073 GST_RTP_BIN_UNLOCK (bin);
1079 gst_rtp_bin_get_internal_storage (GstRtpBin * bin, guint session_id)
1081 GObject *internal_storage = NULL;
1082 GstRtpBinSession *session;
1084 GST_RTP_BIN_LOCK (bin);
1085 GST_DEBUG_OBJECT (bin, "retrieving internal storage object, index: %u",
1087 session = find_session_by_id (bin, (gint) session_id);
1088 if (session && session->storage) {
1089 g_object_get (session->storage, "internal-storage", &internal_storage,
1092 GST_RTP_BIN_UNLOCK (bin);
1094 return internal_storage;
1098 gst_rtp_bin_request_encoder (GstRtpBin * bin, guint session_id)
1100 GST_DEBUG_OBJECT (bin, "return NULL encoder");
1105 gst_rtp_bin_request_decoder (GstRtpBin * bin, guint session_id)
1107 GST_DEBUG_OBJECT (bin, "return NULL decoder");
1112 gst_rtp_bin_request_jitterbuffer (GstRtpBin * bin, guint session_id)
1114 return gst_element_factory_make ("rtpjitterbuffer", NULL);
1118 gst_rtp_bin_propagate_property_to_jitterbuffer (GstRtpBin * bin,
1119 const gchar * name, const GValue * value)
1121 GSList *sessions, *streams;
1123 GST_RTP_BIN_LOCK (bin);
1124 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1125 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
1127 GST_RTP_SESSION_LOCK (session);
1128 for (streams = session->streams; streams; streams = g_slist_next (streams)) {
1129 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
1130 GObjectClass *jb_class;
1132 jb_class = G_OBJECT_GET_CLASS (G_OBJECT (stream->buffer));
1133 if (g_object_class_find_property (jb_class, name))
1134 g_object_set_property (G_OBJECT (stream->buffer), name, value);
1136 GST_WARNING_OBJECT (bin,
1137 "Stream jitterbuffer does not expose property %s", name);
1139 GST_RTP_SESSION_UNLOCK (session);
1141 GST_RTP_BIN_UNLOCK (bin);
1145 gst_rtp_bin_propagate_property_to_session (GstRtpBin * bin,
1146 const gchar * name, const GValue * value)
1150 GST_RTP_BIN_LOCK (bin);
1151 for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
1152 GstRtpBinSession *sess = (GstRtpBinSession *) sessions->data;
1154 g_object_set_property (G_OBJECT (sess->session), name, value);
1156 GST_RTP_BIN_UNLOCK (bin);
1159 /* get a client with the given SDES name. Must be called with RTP_BIN_LOCK */
1160 static GstRtpBinClient *
1161 get_client (GstRtpBin * bin, guint8 len, guint8 * data, gboolean * created)
1163 GstRtpBinClient *result = NULL;
1166 for (walk = bin->clients; walk; walk = g_slist_next (walk)) {
1167 GstRtpBinClient *client = (GstRtpBinClient *) walk->data;
1169 if (len != client->cname_len)
1172 if (!strncmp ((gchar *) data, client->cname, client->cname_len)) {
1173 GST_DEBUG_OBJECT (bin, "found existing client %p with CNAME %s", client,
1180 /* nothing found, create one */
1181 if (result == NULL) {
1182 result = g_new0 (GstRtpBinClient, 1);
1183 result->cname = g_strndup ((gchar *) data, len);
1184 result->cname_len = len;
1185 bin->clients = g_slist_prepend (bin->clients, result);
1186 GST_DEBUG_OBJECT (bin, "created new client %p with CNAME %s", result,
1193 free_client (GstRtpBinClient * client, GstRtpBin * bin)
1195 GST_DEBUG_OBJECT (bin, "freeing client %p", client);
1196 g_slist_free (client->streams);
1197 g_free (client->cname);
1202 get_current_times (GstRtpBin * bin, GstClockTime * running_time,
1203 guint64 * ntpnstime)
1207 GstClockTime base_time, rt, clock_time;
1209 GST_OBJECT_LOCK (bin);
1210 if ((clock = GST_ELEMENT_CLOCK (bin))) {
1211 base_time = GST_ELEMENT_CAST (bin)->base_time;
1212 gst_object_ref (clock);
1213 GST_OBJECT_UNLOCK (bin);
1215 /* get current clock time and convert to running time */
1216 clock_time = gst_clock_get_time (clock);
1217 rt = clock_time - base_time;
1219 if (bin->use_pipeline_clock) {
1221 /* add constant to convert from 1970 based time to 1900 based time */
1222 ntpns += (2208988800LL * GST_SECOND);
1224 switch (bin->ntp_time_source) {
1225 case GST_RTP_NTP_TIME_SOURCE_NTP:
1226 case GST_RTP_NTP_TIME_SOURCE_UNIX:{
1227 /* get current NTP time */
1228 ntpns = g_get_real_time () * GST_USECOND;
1230 /* add constant to convert from 1970 based time to 1900 based time */
1231 if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
1232 ntpns += (2208988800LL * GST_SECOND);
1235 case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
1238 case GST_RTP_NTP_TIME_SOURCE_CLOCK_TIME:
1242 ntpns = -1; /* Fix uninited compiler warning */
1243 g_assert_not_reached ();
1248 gst_object_unref (clock);
1250 GST_OBJECT_UNLOCK (bin);
1261 stream_set_ts_offset (GstRtpBin * bin, GstRtpBinStream * stream,
1262 gint64 ts_offset, gint64 max_ts_offset, gint64 min_ts_offset,
1263 gboolean allow_positive_ts_offset)
1265 gint64 prev_ts_offset;
1266 GObjectClass *jb_class;
1268 jb_class = G_OBJECT_GET_CLASS (G_OBJECT (stream->buffer));
1270 if (!g_object_class_find_property (jb_class, "ts-offset")) {
1271 GST_LOG_OBJECT (bin,
1272 "stream's jitterbuffer does not expose ts-offset property");
1276 g_object_get (stream->buffer, "ts-offset", &prev_ts_offset, NULL);
1278 /* delta changed, see how much */
1279 if (prev_ts_offset != ts_offset) {
1282 diff = prev_ts_offset - ts_offset;
1284 GST_DEBUG_OBJECT (bin,
1285 "ts-offset %" G_GINT64_FORMAT ", prev %" G_GINT64_FORMAT
1286 ", diff: %" G_GINT64_FORMAT, ts_offset, prev_ts_offset, diff);
1288 /* ignore minor offsets */
1289 if (ABS (diff) < min_ts_offset) {
1290 GST_DEBUG_OBJECT (bin, "offset too small, ignoring");
1294 /* sanity check offset */
1295 if (max_ts_offset > 0) {
1296 if (ts_offset > 0 && !allow_positive_ts_offset) {
1297 GST_DEBUG_OBJECT (bin,
1298 "offset is positive (clocks are out of sync), ignoring");
1301 if (ABS (ts_offset) > max_ts_offset) {
1302 GST_DEBUG_OBJECT (bin, "offset too large, ignoring");
1307 g_object_set (stream->buffer, "ts-offset", ts_offset, NULL);
1309 GST_DEBUG_OBJECT (bin, "stream SSRC %08x, delta %" G_GINT64_FORMAT,
1310 stream->ssrc, ts_offset);
1314 gst_rtp_bin_send_sync_event (GstRtpBinStream * stream)
1316 if (stream->bin->send_sync_event) {
1320 GST_DEBUG_OBJECT (stream->bin,
1321 "sending GstRTCPSRReceived event downstream");
1323 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
1324 gst_structure_new_empty ("GstRTCPSRReceived"));
1326 srcpad = gst_element_get_static_pad (stream->buffer, "src");
1327 gst_pad_push_event (srcpad, event);
1328 gst_object_unref (srcpad);
1332 /* associate a stream to the given CNAME. This will make sure all streams for
1333 * that CNAME are synchronized together.
1334 * Must be called with GST_RTP_BIN_LOCK */
1336 gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len,
1337 guint8 * data, guint64 ntptime, guint64 last_extrtptime,
1338 guint64 base_rtptime, guint64 base_time, guint clock_rate,
1339 gint64 rtp_clock_base)
1341 GstRtpBinClient *client;
1344 GstClockTime running_time, running_time_rtp;
1347 /* first find or create the CNAME */
1348 client = get_client (bin, len, data, &created);
1350 /* find stream in the client */
1351 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1352 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1354 if (ostream == stream)
1357 /* not found, add it to the list */
1359 GST_DEBUG_OBJECT (bin,
1360 "new association of SSRC %08x with client %p with CNAME %s",
1361 stream->ssrc, client, client->cname);
1362 client->streams = g_slist_prepend (client->streams, stream);
1365 GST_DEBUG_OBJECT (bin,
1366 "found association of SSRC %08x with client %p with CNAME %s",
1367 stream->ssrc, client, client->cname);
1370 if (!GST_CLOCK_TIME_IS_VALID (last_extrtptime)) {
1371 GST_DEBUG_OBJECT (bin, "invalidated sync data");
1372 if (bin->rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) {
1373 /* we don't need that data, so carry on,
1374 * but make some values look saner */
1375 last_extrtptime = base_rtptime;
1377 /* nothing we can do with this data in this case */
1378 GST_DEBUG_OBJECT (bin, "bailing out");
1383 /* Take the extended rtptime we found in the SR packet and map it to the
1384 * local rtptime. The local rtp time is used to construct timestamps on the
1385 * buffers so we will calculate what running_time corresponds to the RTP
1386 * timestamp in the SR packet. */
1387 running_time_rtp = last_extrtptime - base_rtptime;
1389 GST_DEBUG_OBJECT (bin,
1390 "base %" G_GUINT64_FORMAT ", extrtptime %" G_GUINT64_FORMAT
1391 ", local RTP %" G_GUINT64_FORMAT ", clock-rate %d, "
1392 "clock-base %" G_GINT64_FORMAT, base_rtptime,
1393 last_extrtptime, running_time_rtp, clock_rate, rtp_clock_base);
1395 /* calculate local RTP time in gstreamer timestamp, we essentially perform the
1396 * same conversion that a jitterbuffer would use to convert an rtp timestamp
1397 * into a corresponding gstreamer timestamp. Note that the base_time also
1398 * contains the drift between sender and receiver. */
1400 gst_util_uint64_scale_int (running_time_rtp, GST_SECOND, clock_rate);
1401 running_time += base_time;
1403 /* convert ntptime to nanoseconds */
1404 ntpnstime = gst_util_uint64_scale (ntptime, GST_SECOND,
1405 (G_GINT64_CONSTANT (1) << 32));
1407 stream->have_sync = TRUE;
1409 GST_DEBUG_OBJECT (bin,
1410 "SR RTP running time %" G_GUINT64_FORMAT ", SR NTP %" G_GUINT64_FORMAT,
1411 running_time, ntpnstime);
1413 /* recalc inter stream playout offset, but only if there is more than one
1414 * stream or we're doing NTP sync. */
1415 if (bin->ntp_sync) {
1416 gint64 ntpdiff, rtdiff;
1417 guint64 local_ntpnstime;
1418 GstClockTime local_running_time;
1420 /* For NTP sync we need to first get a snapshot of running_time and NTP
1421 * time. We know at what running_time we play a certain RTP time, we also
1422 * calculated when we would play the RTP time in the SR packet. Now we need
1423 * to know how the running_time and the NTP time relate to each other. */
1424 get_current_times (bin, &local_running_time, &local_ntpnstime);
1426 /* see how far away the NTP time is. This is the difference between the
1427 * current NTP time and the NTP time in the last SR packet. */
1428 ntpdiff = local_ntpnstime - ntpnstime;
1429 /* see how far away the running_time is. This is the difference between the
1430 * current running_time and the running_time of the RTP timestamp in the
1431 * last SR packet. */
1432 rtdiff = local_running_time - running_time;
1434 GST_DEBUG_OBJECT (bin,
1435 "local NTP time %" G_GUINT64_FORMAT ", SR NTP time %" G_GUINT64_FORMAT,
1436 local_ntpnstime, ntpnstime);
1437 GST_DEBUG_OBJECT (bin,
1438 "local running time %" G_GUINT64_FORMAT ", SR RTP running time %"
1439 G_GUINT64_FORMAT, local_running_time, running_time);
1440 GST_DEBUG_OBJECT (bin,
1441 "NTP diff %" G_GINT64_FORMAT ", RT diff %" G_GINT64_FORMAT, ntpdiff,
1444 /* combine to get the final diff to apply to the running_time */
1445 stream->rt_delta = rtdiff - ntpdiff;
1447 stream_set_ts_offset (bin, stream, stream->rt_delta, bin->max_ts_offset,
1450 gint64 min, rtp_min, clock_base = stream->clock_base;
1451 gboolean all_sync, use_rtp;
1452 gboolean rtcp_sync = g_atomic_int_get (&bin->rtcp_sync);
1454 /* calculate delta between server and receiver. ntpnstime is created by
1455 * converting the ntptime in the last SR packet to a gstreamer timestamp. This
1456 * delta expresses the difference to our timeline and the server timeline. The
1457 * difference in itself doesn't mean much but we can combine the delta of
1458 * multiple streams to create a stream specific offset. */
1459 stream->rt_delta = ntpnstime - running_time;
1461 /* calculate the min of all deltas, ignoring streams that did not yet have a
1462 * valid rt_delta because we did not yet receive an SR packet for those
1464 * We calculate the minimum because we would like to only apply positive
1465 * offsets to streams, delaying their playback instead of trying to speed up
1466 * other streams (which might be impossible when we have to create negative
1468 * The stream that has the smallest diff is selected as the reference stream,
1469 * all other streams will have a positive offset to this difference. */
1471 /* some alternative setting allow ignoring RTCP as much as possible,
1472 * for servers generating bogus ntp timeline */
1473 min = rtp_min = G_MAXINT64;
1475 if (rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) {
1479 /* signed version for convenience */
1480 clock_base = base_rtptime;
1481 /* deal with possible wrap-around */
1482 ext_base = base_rtptime;
1483 rtp_clock_base = gst_rtp_buffer_ext_timestamp (&ext_base, rtp_clock_base);
1484 /* sanity check; base rtp and provided clock_base should be close */
1485 if (rtp_clock_base >= clock_base) {
1486 if (rtp_clock_base - clock_base < 10 * clock_rate) {
1487 rtp_clock_base = base_time +
1488 gst_util_uint64_scale_int (rtp_clock_base - clock_base,
1489 GST_SECOND, clock_rate);
1494 if (clock_base - rtp_clock_base < 10 * clock_rate) {
1495 rtp_clock_base = base_time -
1496 gst_util_uint64_scale_int (clock_base - rtp_clock_base,
1497 GST_SECOND, clock_rate);
1502 /* warn and bail for clarity out if no sane values */
1504 GST_WARNING_OBJECT (bin, "unable to sync to provided rtptime");
1507 /* store to track changes */
1508 clock_base = rtp_clock_base;
1509 /* generate a fake as before,
1510 * now equating rtptime obtained from RTP-Info,
1511 * where the large time represent the otherwise irrelevant npt/ntp time */
1512 stream->rtp_delta = (GST_SECOND << 28) - rtp_clock_base;
1514 clock_base = rtp_clock_base;
1518 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1519 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1521 if (!ostream->have_sync) {
1526 /* change in current stream's base from previously init'ed value
1527 * leads to reset of all stream's base */
1528 if (stream != ostream && stream->clock_base >= 0 &&
1529 (stream->clock_base != clock_base)) {
1530 GST_DEBUG_OBJECT (bin, "reset upon clock base change");
1531 ostream->clock_base = -100 * GST_SECOND;
1532 ostream->rtp_delta = 0;
1535 if (ostream->rt_delta < min)
1536 min = ostream->rt_delta;
1537 if (ostream->rtp_delta < rtp_min)
1538 rtp_min = ostream->rtp_delta;
1541 /* arrange to re-sync for each stream upon significant change,
1543 all_sync = all_sync && (stream->clock_base == clock_base);
1544 stream->clock_base = clock_base;
1546 /* may need init performed above later on, but nothing more to do now */
1547 if (client->nstreams <= 1)
1550 GST_DEBUG_OBJECT (bin, "client %p min delta %" G_GINT64_FORMAT
1551 " all sync %d", client, min, all_sync);
1552 GST_DEBUG_OBJECT (bin, "rtcp sync mode %d, use_rtp %d", rtcp_sync, use_rtp);
1554 switch (rtcp_sync) {
1555 case GST_RTP_BIN_RTCP_SYNC_RTP:
1558 GST_DEBUG_OBJECT (bin, "using rtp generated reports; "
1559 "client %p min rtp delta %" G_GINT64_FORMAT, client, rtp_min);
1561 case GST_RTP_BIN_RTCP_SYNC_INITIAL:
1562 /* if all have been synced already, do not bother further */
1564 GST_DEBUG_OBJECT (bin, "all streams already synced; done");
1572 /* bail out if we adjusted recently enough */
1573 if (all_sync && (ntpnstime - bin->priv->last_ntpnstime) <
1574 bin->rtcp_sync_interval * GST_MSECOND) {
1575 GST_DEBUG_OBJECT (bin, "discarding RTCP sender packet for sync; "
1576 "previous sender info too recent "
1577 "(previous NTP %" G_GUINT64_FORMAT ")", bin->priv->last_ntpnstime);
1580 bin->priv->last_ntpnstime = ntpnstime;
1582 /* calculate offsets for each stream */
1583 for (walk = client->streams; walk; walk = g_slist_next (walk)) {
1584 GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
1587 /* ignore streams for which we didn't receive an SR packet yet, we
1588 * can't synchronize them yet. We can however sync other streams just
1590 if (!ostream->have_sync)
1593 /* calculate offset to our reference stream, this should always give a
1594 * positive number. */
1596 ts_offset = ostream->rtp_delta - rtp_min;
1598 ts_offset = ostream->rt_delta - min;
1600 stream_set_ts_offset (bin, ostream, ts_offset, bin->max_ts_offset,
1601 MIN_TS_OFFSET, TRUE);
1604 gst_rtp_bin_send_sync_event (stream);
1609 #define GST_RTCP_BUFFER_FOR_PACKETS(b,buffer,packet) \
1610 for ((b) = gst_rtcp_buffer_get_first_packet ((buffer), (packet)); (b); \
1611 (b) = gst_rtcp_packet_move_to_next ((packet)))
1613 #define GST_RTCP_SDES_FOR_ITEMS(b,packet) \
1614 for ((b) = gst_rtcp_packet_sdes_first_item ((packet)); (b); \
1615 (b) = gst_rtcp_packet_sdes_next_item ((packet)))
1617 #define GST_RTCP_SDES_FOR_ENTRIES(b,packet) \
1618 for ((b) = gst_rtcp_packet_sdes_first_entry ((packet)); (b); \
1619 (b) = gst_rtcp_packet_sdes_next_entry ((packet)))
1622 gst_rtp_bin_handle_sync (GstElement * jitterbuffer, GstStructure * s,
1623 GstRtpBinStream * stream)
1626 GstRTCPPacket packet;
1629 gboolean have_sr, have_sdes;
1631 guint64 base_rtptime;
1637 GstRTCPBuffer rtcp = { NULL, };
1641 GST_DEBUG_OBJECT (bin, "sync handler called");
1643 /* get the last relation between the rtp timestamps and the gstreamer
1644 * timestamps. We get this info directly from the jitterbuffer which
1645 * constructs gstreamer timestamps from rtp timestamps and so it know exactly
1646 * what the current situation is. */
1648 g_value_get_uint64 (gst_structure_get_value (s, "base-rtptime"));
1649 base_time = g_value_get_uint64 (gst_structure_get_value (s, "base-time"));
1650 clock_rate = g_value_get_uint (gst_structure_get_value (s, "clock-rate"));
1651 clock_base = g_value_get_uint64 (gst_structure_get_value (s, "clock-base"));
1653 g_value_get_uint64 (gst_structure_get_value (s, "sr-ext-rtptime"));
1654 buffer = gst_value_get_buffer (gst_structure_get_value (s, "sr-buffer"));
1659 gst_rtcp_buffer_map (buffer, GST_MAP_READ, &rtcp);
1661 GST_RTCP_BUFFER_FOR_PACKETS (more, &rtcp, &packet) {
1662 /* first packet must be SR or RR or else the validate would have failed */
1663 switch (gst_rtcp_packet_get_type (&packet)) {
1664 case GST_RTCP_TYPE_SR:
1665 /* only parse first. There is only supposed to be one SR in the packet
1666 * but we will deal with malformed packets gracefully */
1669 /* get NTP and RTP times */
1670 gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, NULL,
1673 GST_DEBUG_OBJECT (bin, "received sync packet from SSRC %08x", ssrc);
1674 /* ignore SR that is not ours */
1675 if (ssrc != stream->ssrc)
1680 case GST_RTCP_TYPE_SDES:
1682 gboolean more_items, more_entries;
1684 /* only deal with first SDES, there is only supposed to be one SDES in
1685 * the RTCP packet but we deal with bad packets gracefully. Also bail
1686 * out if we have not seen an SR item yet. */
1687 if (have_sdes || !have_sr)
1690 GST_RTCP_SDES_FOR_ITEMS (more_items, &packet) {
1691 /* skip items that are not about the SSRC of the sender */
1692 if (gst_rtcp_packet_sdes_get_ssrc (&packet) != ssrc)
1695 /* find the CNAME entry */
1696 GST_RTCP_SDES_FOR_ENTRIES (more_entries, &packet) {
1697 GstRTCPSDESType type;
1701 gst_rtcp_packet_sdes_get_entry (&packet, &type, &len, &data);
1703 if (type == GST_RTCP_SDES_CNAME) {
1704 GST_RTP_BIN_LOCK (bin);
1705 /* associate the stream to CNAME */
1706 gst_rtp_bin_associate (bin, stream, len, data,
1707 ntptime, extrtptime, base_rtptime, base_time, clock_rate,
1709 GST_RTP_BIN_UNLOCK (bin);
1717 /* we can ignore these packets */
1721 gst_rtcp_buffer_unmap (&rtcp);
1724 /* create a new stream with @ssrc in @session. Must be called with
1725 * RTP_SESSION_LOCK. */
1726 static GstRtpBinStream *
1727 create_stream (GstRtpBinSession * session, guint32 ssrc)
1729 GstElement *buffer, *demux = NULL;
1730 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1731 GstElement *queue2 = NULL;
1733 GstRtpBinStream *stream;
1736 GObjectClass *jb_class;
1738 rtpbin = session->bin;
1740 if (g_slist_length (session->streams) >= rtpbin->max_streams)
1744 session_request_element (session, SIGNAL_REQUEST_JITTERBUFFER)))
1745 goto no_jitterbuffer;
1747 if (!rtpbin->ignore_pt) {
1748 if (!(demux = gst_element_factory_make ("rtpptdemux", NULL)))
1751 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1752 if (rtpbin->use_rtsp_buffering &&
1753 rtpbin->buffer_mode == RTP_JITTER_BUFFER_MODE_SLAVE) {
1754 if (!(queue2 = gst_element_factory_make ("queue2", NULL)))
1759 stream = g_new0 (GstRtpBinStream, 1);
1760 stream->ssrc = ssrc;
1761 stream->bin = rtpbin;
1762 stream->session = session;
1763 stream->buffer = gst_object_ref (buffer);
1764 stream->demux = demux;
1766 stream->have_sync = FALSE;
1767 stream->rt_delta = 0;
1768 stream->rtp_delta = 0;
1769 stream->percent = 100;
1770 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1771 stream->prev_percent = 0;
1773 stream->clock_base = -100 * GST_SECOND;
1774 session->streams = g_slist_prepend (session->streams, stream);
1776 jb_class = G_OBJECT_GET_CLASS (G_OBJECT (buffer));
1778 if (g_signal_lookup ("request-pt-map", G_OBJECT_TYPE (buffer)) != 0) {
1779 /* provide clock_rate to the jitterbuffer when needed */
1780 stream->buffer_ptreq_sig = g_signal_connect (buffer, "request-pt-map",
1781 (GCallback) pt_map_requested, session);
1783 if (g_signal_lookup ("on-npt-stop", G_OBJECT_TYPE (buffer)) != 0) {
1784 stream->buffer_ntpstop_sig = g_signal_connect (buffer, "on-npt-stop",
1785 (GCallback) on_npt_stop, stream);
1788 g_object_set_data (G_OBJECT (buffer), "GstRTPBin.session", session);
1789 g_object_set_data (G_OBJECT (buffer), "GstRTPBin.stream", stream);
1791 /* configure latency and packet lost */
1792 g_object_set (buffer, "latency", rtpbin->latency_ms, NULL);
1794 if (g_object_class_find_property (jb_class, "drop-on-latency"))
1795 g_object_set (buffer, "drop-on-latency", rtpbin->drop_on_latency, NULL);
1796 if (g_object_class_find_property (jb_class, "do-lost"))
1797 g_object_set (buffer, "do-lost", rtpbin->do_lost, NULL);
1798 if (g_object_class_find_property (jb_class, "mode"))
1799 g_object_set (buffer, "mode", rtpbin->buffer_mode, NULL);
1800 if (g_object_class_find_property (jb_class, "do-retransmission"))
1801 g_object_set (buffer, "do-retransmission", rtpbin->do_retransmission, NULL);
1802 if (g_object_class_find_property (jb_class, "max-rtcp-rtp-time-diff"))
1803 g_object_set (buffer, "max-rtcp-rtp-time-diff",
1804 rtpbin->max_rtcp_rtp_time_diff, NULL);
1805 if (g_object_class_find_property (jb_class, "max-dropout-time"))
1806 g_object_set (buffer, "max-dropout-time", rtpbin->max_dropout_time, NULL);
1807 if (g_object_class_find_property (jb_class, "max-misorder-time"))
1808 g_object_set (buffer, "max-misorder-time", rtpbin->max_misorder_time, NULL);
1809 if (g_object_class_find_property (jb_class, "rfc7273-sync"))
1810 g_object_set (buffer, "rfc7273-sync", rtpbin->rfc7273_sync, NULL);
1811 if (g_object_class_find_property (jb_class, "max-ts-offset-adjustment"))
1812 g_object_set (buffer, "max-ts-offset-adjustment",
1813 rtpbin->max_ts_offset_adjustment, NULL);
1815 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1816 /* configure queue2 to use live buffering */
1818 g_object_set_data (G_OBJECT (queue2), "GstRTPBin.stream", stream);
1819 g_object_set (queue2, "use-buffering", TRUE, NULL);
1820 g_object_set (queue2, "buffer-mode", GST_BUFFERING_LIVE, NULL);
1823 g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER], 0,
1824 buffer, session->id, ssrc);
1826 if (!rtpbin->ignore_pt)
1827 gst_bin_add (GST_BIN_CAST (rtpbin), demux);
1829 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1831 gst_bin_add (GST_BIN_CAST (rtpbin), queue2);
1835 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1837 gst_element_link_pads_full (buffer, "src", queue2, "sink",
1838 GST_PAD_LINK_CHECK_NOTHING);
1840 gst_element_link_pads_full (queue2, "src", demux, "sink",
1841 GST_PAD_LINK_CHECK_NOTHING);
1844 gst_element_link_pads_full (buffer, "src", demux, "sink",
1845 GST_PAD_LINK_CHECK_NOTHING);
1849 gst_element_link_pads_full (buffer, "src", demux, "sink",
1850 GST_PAD_LINK_CHECK_NOTHING);
1853 if (rtpbin->buffering) {
1856 if (g_signal_lookup ("set-active", G_OBJECT_TYPE (buffer)) != 0) {
1857 GST_INFO_OBJECT (rtpbin,
1858 "bin is buffering, set jitterbuffer as not active");
1859 g_signal_emit_by_name (buffer, "set-active", FALSE, (gint64) 0,
1865 GST_OBJECT_LOCK (rtpbin);
1866 target = GST_STATE_TARGET (rtpbin);
1867 GST_OBJECT_UNLOCK (rtpbin);
1869 /* from sink to source */
1871 gst_element_set_state (demux, target);
1873 gst_element_set_state (buffer, target);
1875 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1877 gst_element_set_state (queue2, target);
1885 GST_WARNING_OBJECT (rtpbin, "stream exceeds maximum (%d)",
1886 rtpbin->max_streams);
1891 g_warning ("rtpbin: could not create rtpjitterbuffer element");
1896 gst_object_unref (buffer);
1897 g_warning ("rtpbin: could not create rtpptdemux element");
1900 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1903 gst_object_unref (buffer);
1904 gst_object_unref (demux);
1905 g_warning ("rtpbin: could not create queue2 element");
1911 /* called with RTP_BIN_LOCK */
1913 free_stream (GstRtpBinStream * stream, GstRtpBin * bin)
1915 GstRtpBinSession *sess = stream->session;
1916 GSList *clients, *next_client;
1918 GST_DEBUG_OBJECT (bin, "freeing stream %p", stream);
1920 gst_element_set_locked_state (stream->buffer, TRUE);
1922 gst_element_set_locked_state (stream->demux, TRUE);
1924 gst_element_set_state (stream->buffer, GST_STATE_NULL);
1926 gst_element_set_state (stream->demux, GST_STATE_NULL);
1928 if (stream->demux) {
1929 g_signal_handler_disconnect (stream->demux, stream->demux_newpad_sig);
1930 g_signal_handler_disconnect (stream->demux, stream->demux_ptreq_sig);
1931 g_signal_handler_disconnect (stream->demux, stream->demux_ptchange_sig);
1932 g_signal_handler_disconnect (stream->demux, stream->demux_padremoved_sig);
1935 if (stream->buffer_handlesync_sig)
1936 g_signal_handler_disconnect (stream->buffer, stream->buffer_handlesync_sig);
1937 if (stream->buffer_ptreq_sig)
1938 g_signal_handler_disconnect (stream->buffer, stream->buffer_ptreq_sig);
1939 if (stream->buffer_ntpstop_sig)
1940 g_signal_handler_disconnect (stream->buffer, stream->buffer_ntpstop_sig);
1942 sess->elements = g_slist_remove (sess->elements, stream->buffer);
1943 remove_bin_element (stream->buffer, bin);
1944 gst_object_unref (stream->buffer);
1947 gst_bin_remove (GST_BIN_CAST (bin), stream->demux);
1949 for (clients = bin->clients; clients; clients = next_client) {
1950 GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
1951 GSList *streams, *next_stream;
1953 next_client = g_slist_next (clients);
1955 for (streams = client->streams; streams; streams = next_stream) {
1956 GstRtpBinStream *ostream = (GstRtpBinStream *) streams->data;
1958 next_stream = g_slist_next (streams);
1960 if (ostream == stream) {
1961 client->streams = g_slist_delete_link (client->streams, streams);
1962 /* If this was the last stream belonging to this client,
1963 * clean up the client. */
1964 if (--client->nstreams == 0) {
1965 bin->clients = g_slist_delete_link (bin->clients, clients);
1966 free_client (client, bin);
1975 /* GObject vmethods */
1976 static void gst_rtp_bin_dispose (GObject * object);
1977 static void gst_rtp_bin_finalize (GObject * object);
1978 static void gst_rtp_bin_set_property (GObject * object, guint prop_id,
1979 const GValue * value, GParamSpec * pspec);
1980 static void gst_rtp_bin_get_property (GObject * object, guint prop_id,
1981 GValue * value, GParamSpec * pspec);
1983 /* GstElement vmethods */
1984 static GstStateChangeReturn gst_rtp_bin_change_state (GstElement * element,
1985 GstStateChange transition);
1986 static GstPad *gst_rtp_bin_request_new_pad (GstElement * element,
1987 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
1988 static void gst_rtp_bin_release_pad (GstElement * element, GstPad * pad);
1989 static void gst_rtp_bin_handle_message (GstBin * bin, GstMessage * message);
1991 #define gst_rtp_bin_parent_class parent_class
1992 G_DEFINE_TYPE_WITH_PRIVATE (GstRtpBin, gst_rtp_bin, GST_TYPE_BIN);
1995 _gst_element_accumulator (GSignalInvocationHint * ihint,
1996 GValue * return_accu, const GValue * handler_return, gpointer dummy)
1998 GstElement *element;
2000 element = g_value_get_object (handler_return);
2001 GST_DEBUG ("got element %" GST_PTR_FORMAT, element);
2003 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
2004 g_value_set_object (return_accu, element);
2006 /* stop emission if we have an element */
2007 return (element == NULL);
2011 _gst_caps_accumulator (GSignalInvocationHint * ihint,
2012 GValue * return_accu, const GValue * handler_return, gpointer dummy)
2016 caps = g_value_get_boxed (handler_return);
2017 GST_DEBUG ("got caps %" GST_PTR_FORMAT, caps);
2019 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
2020 g_value_set_boxed (return_accu, caps);
2022 /* stop emission if we have a caps */
2023 return (caps == NULL);
2027 gst_rtp_bin_class_init (GstRtpBinClass * klass)
2029 GObjectClass *gobject_class;
2030 GstElementClass *gstelement_class;
2031 GstBinClass *gstbin_class;
2033 gobject_class = (GObjectClass *) klass;
2034 gstelement_class = (GstElementClass *) klass;
2035 gstbin_class = (GstBinClass *) klass;
2037 gobject_class->dispose = gst_rtp_bin_dispose;
2038 gobject_class->finalize = gst_rtp_bin_finalize;
2039 gobject_class->set_property = gst_rtp_bin_set_property;
2040 gobject_class->get_property = gst_rtp_bin_get_property;
2042 g_object_class_install_property (gobject_class, PROP_LATENCY,
2043 g_param_spec_uint ("latency", "Buffer latency in ms",
2044 "Default amount of ms to buffer in the jitterbuffers", 0,
2045 G_MAXUINT, DEFAULT_LATENCY_MS,
2046 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2048 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
2049 g_param_spec_boolean ("drop-on-latency",
2050 "Drop buffers when maximum latency is reached",
2051 "Tells the jitterbuffer to never exceed the given latency in size",
2052 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2055 * GstRtpBin::request-pt-map:
2056 * @rtpbin: the object which received the signal
2057 * @session: the session
2060 * Request the payload type as #GstCaps for @pt in @session.
2062 gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP] =
2063 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
2064 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, request_pt_map),
2065 _gst_caps_accumulator, NULL, NULL, GST_TYPE_CAPS, 2, G_TYPE_UINT,
2069 * GstRtpBin::payload-type-change:
2070 * @rtpbin: the object which received the signal
2071 * @session: the session
2074 * Signal that the current payload type changed to @pt in @session.
2076 gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE] =
2077 g_signal_new ("payload-type-change", G_TYPE_FROM_CLASS (klass),
2078 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, payload_type_change),
2079 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2082 * GstRtpBin::clear-pt-map:
2083 * @rtpbin: the object which received the signal
2085 * Clear all previously cached pt-mapping obtained with
2086 * #GstRtpBin::request-pt-map.
2088 gst_rtp_bin_signals[SIGNAL_CLEAR_PT_MAP] =
2089 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
2090 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2091 clear_pt_map), NULL, NULL, NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
2094 * GstRtpBin::reset-sync:
2095 * @rtpbin: the object which received the signal
2097 * Reset all currently configured lip-sync parameters and require new SR
2098 * packets for all streams before lip-sync is attempted again.
2100 gst_rtp_bin_signals[SIGNAL_RESET_SYNC] =
2101 g_signal_new ("reset-sync", G_TYPE_FROM_CLASS (klass),
2102 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2103 reset_sync), NULL, NULL, NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
2106 * GstRtpBin::get-session:
2107 * @rtpbin: the object which received the signal
2108 * @id: the session id
2110 * Request the related GstRtpSession as #GstElement related with session @id.
2114 gst_rtp_bin_signals[SIGNAL_GET_SESSION] =
2115 g_signal_new ("get-session", G_TYPE_FROM_CLASS (klass),
2116 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2117 get_session), NULL, NULL, NULL, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2120 * GstRtpBin::get-internal-session:
2121 * @rtpbin: the object which received the signal
2122 * @id: the session id
2124 * Request the internal RTPSession object as #GObject in session @id.
2126 gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_SESSION] =
2127 g_signal_new ("get-internal-session", G_TYPE_FROM_CLASS (klass),
2128 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2129 get_internal_session), NULL, NULL, NULL, RTP_TYPE_SESSION, 1,
2133 * GstRtpBin::get-internal-storage:
2134 * @rtpbin: the object which received the signal
2135 * @id: the session id
2137 * Request the internal RTPStorage object as #GObject in session @id. This
2138 * is the internal storage used by the RTPStorage element, which is used to
2139 * keep a backlog of received RTP packets for the session @id.
2143 gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_STORAGE] =
2144 g_signal_new ("get-internal-storage", G_TYPE_FROM_CLASS (klass),
2145 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2146 get_internal_storage), NULL, NULL, NULL, G_TYPE_OBJECT, 1,
2150 * GstRtpBin::get-storage:
2151 * @rtpbin: the object which received the signal
2152 * @id: the session id
2154 * Request the RTPStorage element as #GObject in session @id. This element
2155 * is used to keep a backlog of received RTP packets for the session @id.
2159 gst_rtp_bin_signals[SIGNAL_GET_STORAGE] =
2160 g_signal_new ("get-storage", G_TYPE_FROM_CLASS (klass),
2161 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
2162 get_storage), NULL, NULL, NULL, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2165 * GstRtpBin::on-new-ssrc:
2166 * @rtpbin: the object which received the signal
2167 * @session: the session
2170 * Notify of a new SSRC that entered @session.
2172 gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC] =
2173 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
2174 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_ssrc),
2175 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2177 * GstRtpBin::on-ssrc-collision:
2178 * @rtpbin: the object which received the signal
2179 * @session: the session
2182 * Notify when we have an SSRC collision
2184 gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION] =
2185 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
2186 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_collision),
2187 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2189 * GstRtpBin::on-ssrc-validated:
2190 * @rtpbin: the object which received the signal
2191 * @session: the session
2194 * Notify of a new SSRC that became validated.
2196 gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED] =
2197 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
2198 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_validated),
2199 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2201 * GstRtpBin::on-ssrc-active:
2202 * @rtpbin: the object which received the signal
2203 * @session: the session
2206 * Notify of a SSRC that is active, i.e., sending RTCP.
2208 gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE] =
2209 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
2210 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_active),
2211 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2213 * GstRtpBin::on-ssrc-sdes:
2214 * @rtpbin: the object which received the signal
2215 * @session: the session
2218 * Notify of a SSRC that is active, i.e., sending RTCP.
2220 gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES] =
2221 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
2222 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_sdes),
2223 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2226 * GstRtpBin::on-bye-ssrc:
2227 * @rtpbin: the object which received the signal
2228 * @session: the session
2231 * Notify of an SSRC that became inactive because of a BYE packet.
2233 gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC] =
2234 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
2235 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_ssrc),
2236 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2238 * GstRtpBin::on-bye-timeout:
2239 * @rtpbin: the object which received the signal
2240 * @session: the session
2243 * Notify of an SSRC that has timed out because of BYE
2245 gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT] =
2246 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
2247 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_timeout),
2248 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2250 * GstRtpBin::on-timeout:
2251 * @rtpbin: the object which received the signal
2252 * @session: the session
2255 * Notify of an SSRC that has timed out
2257 gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT] =
2258 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
2259 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_timeout),
2260 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2262 * GstRtpBin::on-sender-timeout:
2263 * @rtpbin: the object which received the signal
2264 * @session: the session
2267 * Notify of a sender SSRC that has timed out and became a receiver
2269 gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT] =
2270 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
2271 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_sender_timeout),
2272 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2275 * GstRtpBin::on-npt-stop:
2276 * @rtpbin: the object which received the signal
2277 * @session: the session
2280 * Notify that SSRC sender has sent data up to the configured NPT stop time.
2282 gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP] =
2283 g_signal_new ("on-npt-stop", G_TYPE_FROM_CLASS (klass),
2284 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_npt_stop),
2285 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2288 * GstRtpBin::request-rtp-encoder:
2289 * @rtpbin: the object which received the signal
2290 * @session: the session
2292 * Request an RTP encoder element for the given @session. The encoder
2293 * element will be added to the bin if not previously added.
2295 * If no handler is connected, no encoder will be used.
2299 gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_ENCODER] =
2300 g_signal_new ("request-rtp-encoder", G_TYPE_FROM_CLASS (klass),
2301 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2302 request_rtp_encoder), _gst_element_accumulator, NULL, NULL,
2303 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2306 * GstRtpBin::request-rtp-decoder:
2307 * @rtpbin: the object which received the signal
2308 * @session: the session
2310 * Request an RTP decoder element for the given @session. The decoder
2311 * element will be added to the bin if not previously added.
2313 * If no handler is connected, no encoder will be used.
2317 gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_DECODER] =
2318 g_signal_new ("request-rtp-decoder", G_TYPE_FROM_CLASS (klass),
2319 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2320 request_rtp_decoder), _gst_element_accumulator, NULL,
2321 NULL, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2324 * GstRtpBin::request-rtcp-encoder:
2325 * @rtpbin: the object which received the signal
2326 * @session: the session
2328 * Request an RTCP encoder element for the given @session. The encoder
2329 * element will be added to the bin if not previously added.
2331 * If no handler is connected, no encoder will be used.
2335 gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_ENCODER] =
2336 g_signal_new ("request-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
2337 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2338 request_rtcp_encoder), _gst_element_accumulator, NULL, NULL,
2339 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2342 * GstRtpBin::request-rtcp-decoder:
2343 * @rtpbin: the object which received the signal
2344 * @session: the session
2346 * Request an RTCP decoder element for the given @session. The decoder
2347 * element will be added to the bin if not previously added.
2349 * If no handler is connected, no encoder will be used.
2353 gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_DECODER] =
2354 g_signal_new ("request-rtcp-decoder", G_TYPE_FROM_CLASS (klass),
2355 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2356 request_rtcp_decoder), _gst_element_accumulator, NULL, NULL,
2357 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2360 * GstRtpBin::request-jitterbuffer:
2361 * @rtpbin: the object which received the signal
2362 * @session: the session
2364 * Request a jitterbuffer element for the given @session.
2366 * If no handler is connected, the default jitterbuffer will be used.
2368 * Note: The provided element is expected to conform to the API exposed
2369 * by the standard #GstRtpJitterBuffer. Runtime checks will be made to
2370 * determine whether it exposes properties and signals before attempting
2371 * to set, call or connect to them, and some functionalities of #GstRtpBin
2372 * may not be available when that is not the case.
2374 * This should be considered experimental API, as the standard jitterbuffer
2375 * API is susceptible to change, provided elements will have to update their
2376 * custom jitterbuffer's API to match the API of #GstRtpJitterBuffer if and
2381 gst_rtp_bin_signals[SIGNAL_REQUEST_JITTERBUFFER] =
2382 g_signal_new ("request-jitterbuffer", G_TYPE_FROM_CLASS (klass),
2383 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2384 request_jitterbuffer), _gst_element_accumulator, NULL,
2385 g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2388 * GstRtpBin::new-jitterbuffer:
2389 * @rtpbin: the object which received the signal
2390 * @jitterbuffer: the new jitterbuffer
2391 * @session: the session
2394 * Notify that a new @jitterbuffer was created for @session and @ssrc.
2395 * This signal can, for example, be used to configure @jitterbuffer.
2399 gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER] =
2400 g_signal_new ("new-jitterbuffer", G_TYPE_FROM_CLASS (klass),
2401 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2402 new_jitterbuffer), NULL, NULL, NULL,
2403 G_TYPE_NONE, 3, GST_TYPE_ELEMENT, G_TYPE_UINT, G_TYPE_UINT);
2406 * GstRtpBin::new-storage:
2407 * @rtpbin: the object which received the signal
2408 * @storage: the new storage
2409 * @session: the session
2411 * Notify that a new @storage was created for @session.
2412 * This signal can, for example, be used to configure @storage.
2416 gst_rtp_bin_signals[SIGNAL_NEW_STORAGE] =
2417 g_signal_new ("new-storage", G_TYPE_FROM_CLASS (klass),
2418 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2419 new_storage), NULL, NULL, NULL,
2420 G_TYPE_NONE, 2, GST_TYPE_ELEMENT, G_TYPE_UINT);
2423 * GstRtpBin::request-aux-sender:
2424 * @rtpbin: the object which received the signal
2425 * @session: the session
2427 * Request an AUX sender element for the given @session. The AUX
2428 * element will be added to the bin.
2430 * If no handler is connected, no AUX element will be used.
2434 gst_rtp_bin_signals[SIGNAL_REQUEST_AUX_SENDER] =
2435 g_signal_new ("request-aux-sender", G_TYPE_FROM_CLASS (klass),
2436 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2437 request_aux_sender), _gst_element_accumulator, NULL, NULL,
2438 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2441 * GstRtpBin::request-aux-receiver:
2442 * @rtpbin: the object which received the signal
2443 * @session: the session
2445 * Request an AUX receiver element for the given @session. The AUX
2446 * element will be added to the bin.
2448 * If no handler is connected, no AUX element will be used.
2452 gst_rtp_bin_signals[SIGNAL_REQUEST_AUX_RECEIVER] =
2453 g_signal_new ("request-aux-receiver", G_TYPE_FROM_CLASS (klass),
2454 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2455 request_aux_receiver), _gst_element_accumulator, NULL, NULL,
2456 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2459 * GstRtpBin::request-fec-decoder:
2460 * @rtpbin: the object which received the signal
2461 * @session: the session index
2463 * Request a FEC decoder element for the given @session. The element
2464 * will be added to the bin after the pt demuxer.
2466 * If no handler is connected, no FEC decoder will be used.
2470 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_DECODER] =
2471 g_signal_new ("request-fec-decoder", G_TYPE_FROM_CLASS (klass),
2472 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2473 request_fec_decoder), _gst_element_accumulator, NULL, NULL,
2474 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2477 * GstRtpBin::request-fec-encoder:
2478 * @rtpbin: the object which received the signal
2479 * @session: the session index
2481 * Request a FEC encoder element for the given @session. The element
2482 * will be added to the bin after the RTPSession.
2484 * If no handler is connected, no FEC encoder will be used.
2488 gst_rtp_bin_signals[SIGNAL_REQUEST_FEC_ENCODER] =
2489 g_signal_new ("request-fec-encoder", G_TYPE_FROM_CLASS (klass),
2490 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2491 request_fec_encoder), _gst_element_accumulator, NULL, NULL,
2492 GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
2495 * GstRtpBin::on-new-sender-ssrc:
2496 * @rtpbin: the object which received the signal
2497 * @session: the session
2498 * @ssrc: the sender SSRC
2500 * Notify of a new sender SSRC that entered @session.
2504 gst_rtp_bin_signals[SIGNAL_ON_NEW_SENDER_SSRC] =
2505 g_signal_new ("on-new-sender-ssrc", G_TYPE_FROM_CLASS (klass),
2506 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_sender_ssrc),
2507 NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2509 * GstRtpBin::on-sender-ssrc-active:
2510 * @rtpbin: the object which received the signal
2511 * @session: the session
2512 * @ssrc: the sender SSRC
2514 * Notify of a sender SSRC that is active, i.e., sending RTCP.
2518 gst_rtp_bin_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE] =
2519 g_signal_new ("on-sender-ssrc-active", G_TYPE_FROM_CLASS (klass),
2520 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
2521 on_sender_ssrc_active), NULL, NULL, NULL,
2522 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2524 g_object_class_install_property (gobject_class, PROP_SDES,
2525 g_param_spec_boxed ("sdes", "SDES",
2526 "The SDES items of this session",
2527 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
2528 #ifndef TIZEN_FEATURE_GST_UPSTREAM_AVOID_BUILD_BREAK
2529 | GST_PARAM_DOC_SHOW_DEFAULT));
2534 g_object_class_install_property (gobject_class, PROP_DO_LOST,
2535 g_param_spec_boolean ("do-lost", "Do Lost",
2536 "Send an event downstream when a packet is lost", DEFAULT_DO_LOST,
2537 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2539 g_object_class_install_property (gobject_class, PROP_AUTOREMOVE,
2540 g_param_spec_boolean ("autoremove", "Auto Remove",
2541 "Automatically remove timed out sources", DEFAULT_AUTOREMOVE,
2542 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2544 g_object_class_install_property (gobject_class, PROP_IGNORE_PT,
2545 g_param_spec_boolean ("ignore-pt", "Ignore PT",
2546 "Do not demultiplex based on PT values", DEFAULT_IGNORE_PT,
2547 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2549 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
2550 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
2551 "Use the pipeline running-time to set the NTP time in the RTCP SR messages "
2552 "(DEPRECATED: Use ntp-time-source property)",
2553 DEFAULT_USE_PIPELINE_CLOCK,
2554 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
2556 * GstRtpBin:buffer-mode:
2558 * Control the buffering and timestamping mode used by the jitterbuffer.
2560 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
2561 g_param_spec_enum ("buffer-mode", "Buffer Mode",
2562 "Control the buffering algorithm in use", RTP_TYPE_JITTER_BUFFER_MODE,
2563 DEFAULT_BUFFER_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2565 * GstRtpBin:ntp-sync:
2567 * Set the NTP time from the sender reports as the running-time on the
2568 * buffers. When both the sender and receiver have sychronized
2569 * running-time, i.e. when the clock and base-time is shared
2570 * between the receivers and the and the senders, this option can be
2571 * used to synchronize receivers on multiple machines.
2573 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
2574 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
2575 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
2576 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2579 * GstRtpBin:rtcp-sync:
2581 * If not synchronizing (directly) to the NTP clock, determines how to sync
2582 * the various streams.
2584 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC,
2585 g_param_spec_enum ("rtcp-sync", "RTCP Sync",
2586 "Use of RTCP SR in synchronization", GST_RTP_BIN_RTCP_SYNC_TYPE,
2587 DEFAULT_RTCP_SYNC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2590 * GstRtpBin:rtcp-sync-interval:
2592 * Determines how often to sync streams using RTCP data.
2594 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_INTERVAL,
2595 g_param_spec_uint ("rtcp-sync-interval", "RTCP Sync Interval",
2596 "RTCP SR interval synchronization (ms) (0 = always)",
2597 0, G_MAXUINT, DEFAULT_RTCP_SYNC_INTERVAL,
2598 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2600 g_object_class_install_property (gobject_class, PROP_DO_SYNC_EVENT,
2601 g_param_spec_boolean ("do-sync-event", "Do Sync Event",
2602 "Send event downstream when a stream is synchronized to the sender",
2603 DEFAULT_DO_SYNC_EVENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2606 * GstRtpBin:do-retransmission:
2608 * Enables RTP retransmission on all streams. To control retransmission on
2609 * a per-SSRC basis, connect to the #GstRtpBin::new-jitterbuffer signal and
2610 * set the #GstRtpJitterBuffer:do-retransmission property on the
2611 * #GstRtpJitterBuffer object instead.
2613 g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
2614 g_param_spec_boolean ("do-retransmission", "Do retransmission",
2615 "Enable retransmission on all streams",
2616 DEFAULT_DO_RETRANSMISSION,
2617 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2620 * GstRtpBin:rtp-profile:
2622 * Sets the default RTP profile of newly created RTP sessions. The
2623 * profile can be changed afterwards on a per-session basis.
2625 g_object_class_install_property (gobject_class, PROP_RTP_PROFILE,
2626 g_param_spec_enum ("rtp-profile", "RTP Profile",
2627 "Default RTP profile of newly created sessions",
2628 GST_TYPE_RTP_PROFILE, DEFAULT_RTP_PROFILE,
2629 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2631 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
2632 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
2633 "NTP time source for RTCP packets",
2634 gst_rtp_ntp_time_source_get_type (), DEFAULT_NTP_TIME_SOURCE,
2635 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2637 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_SEND_TIME,
2638 g_param_spec_boolean ("rtcp-sync-send-time", "RTCP Sync Send Time",
2639 "Use send time or capture time for RTCP sync "
2640 "(TRUE = send time, FALSE = capture time)",
2641 DEFAULT_RTCP_SYNC_SEND_TIME,
2642 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2644 g_object_class_install_property (gobject_class, PROP_MAX_RTCP_RTP_TIME_DIFF,
2645 g_param_spec_int ("max-rtcp-rtp-time-diff", "Max RTCP RTP Time Diff",
2646 "Maximum amount of time in ms that the RTP time in RTCP SRs "
2647 "is allowed to be ahead (-1 disabled)", -1, G_MAXINT,
2648 DEFAULT_MAX_RTCP_RTP_TIME_DIFF,
2649 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2651 g_object_class_install_property (gobject_class, PROP_MAX_DROPOUT_TIME,
2652 g_param_spec_uint ("max-dropout-time", "Max dropout time",
2653 "The maximum time (milliseconds) of missing packets tolerated.",
2654 0, G_MAXUINT, DEFAULT_MAX_DROPOUT_TIME,
2655 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2657 g_object_class_install_property (gobject_class, PROP_MAX_MISORDER_TIME,
2658 g_param_spec_uint ("max-misorder-time", "Max misorder time",
2659 "The maximum time (milliseconds) of misordered packets tolerated.",
2660 0, G_MAXUINT, DEFAULT_MAX_MISORDER_TIME,
2661 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2663 g_object_class_install_property (gobject_class, PROP_RFC7273_SYNC,
2664 g_param_spec_boolean ("rfc7273-sync", "Sync on RFC7273 clock",
2665 "Synchronize received streams to the RFC7273 clock "
2666 "(requires clock and offset to be provided)", DEFAULT_RFC7273_SYNC,
2667 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2669 g_object_class_install_property (gobject_class, PROP_MAX_STREAMS,
2670 g_param_spec_uint ("max-streams", "Max Streams",
2671 "The maximum number of streams to create for one session",
2672 0, G_MAXUINT, DEFAULT_MAX_STREAMS,
2673 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2676 * GstRtpBin:max-ts-offset-adjustment:
2678 * Syncing time stamps to NTP time adds a time offset. This parameter
2679 * specifies the maximum number of nanoseconds per frame that this time offset
2680 * may be adjusted with. This is used to avoid sudden large changes to time
2685 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET_ADJUSTMENT,
2686 g_param_spec_uint64 ("max-ts-offset-adjustment",
2687 "Max Timestamp Offset Adjustment",
2688 "The maximum number of nanoseconds per frame that time stamp offsets "
2689 "may be adjusted (0 = no limit).", 0, G_MAXUINT64,
2690 DEFAULT_MAX_TS_OFFSET_ADJUSTMENT, G_PARAM_READWRITE |
2691 G_PARAM_STATIC_STRINGS));
2694 * GstRtpBin:max-ts-offset:
2696 * Used to set an upper limit of how large a time offset may be. This
2697 * is used to protect against unrealistic values as a result of either
2698 * client,server or clock issues.
2702 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET,
2703 g_param_spec_int64 ("max-ts-offset", "Max TS Offset",
2704 "The maximum absolute value of the time offset in (nanoseconds). "
2705 "Note, if the ntp-sync parameter is set the default value is "
2706 "changed to 0 (no limit)", 0, G_MAXINT64, DEFAULT_MAX_TS_OFFSET,
2707 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2709 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
2710 g_object_class_install_property (gobject_class, PROP_USE_RTSP_BUFFERING,
2711 g_param_spec_boolean ("use-rtsp-buffering", "Use RTSP buffering",
2712 "Use RTSP buffering in RTP_JITTER_BUFFER_MODE_SLAVE buffer mode",
2713 DEFAULT_RTSP_USE_BUFFERING,
2714 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2717 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
2718 gstelement_class->request_new_pad =
2719 GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
2720 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_bin_release_pad);
2723 gst_element_class_add_static_pad_template (gstelement_class,
2724 &rtpbin_recv_rtp_sink_template);
2725 gst_element_class_add_static_pad_template (gstelement_class,
2726 &rtpbin_recv_rtcp_sink_template);
2727 gst_element_class_add_static_pad_template (gstelement_class,
2728 &rtpbin_send_rtp_sink_template);
2731 gst_element_class_add_static_pad_template (gstelement_class,
2732 &rtpbin_recv_rtp_src_template);
2733 gst_element_class_add_static_pad_template (gstelement_class,
2734 &rtpbin_send_rtcp_src_template);
2735 gst_element_class_add_static_pad_template (gstelement_class,
2736 &rtpbin_send_rtp_src_template);
2738 gst_element_class_set_static_metadata (gstelement_class, "RTP Bin",
2739 "Filter/Network/RTP",
2740 "Real-Time Transport Protocol bin",
2741 "Wim Taymans <wim.taymans@gmail.com>");
2743 gstbin_class->handle_message = GST_DEBUG_FUNCPTR (gst_rtp_bin_handle_message);
2745 klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_bin_clear_pt_map);
2746 klass->reset_sync = GST_DEBUG_FUNCPTR (gst_rtp_bin_reset_sync);
2747 klass->get_session = GST_DEBUG_FUNCPTR (gst_rtp_bin_get_session);
2748 klass->get_internal_session =
2749 GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_session);
2750 klass->get_storage = GST_DEBUG_FUNCPTR (gst_rtp_bin_get_storage);
2751 klass->get_internal_storage =
2752 GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_storage);
2753 klass->request_rtp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
2754 klass->request_rtp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
2755 klass->request_rtcp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
2756 klass->request_rtcp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
2757 klass->request_jitterbuffer =
2758 GST_DEBUG_FUNCPTR (gst_rtp_bin_request_jitterbuffer);
2760 GST_DEBUG_CATEGORY_INIT (gst_rtp_bin_debug, "rtpbin", 0, "RTP bin");
2762 #ifndef TIZEN_FEATURE_GST_UPSTREAM_AVOID_BUILD_BREAK
2763 gst_type_mark_as_plugin_api (GST_RTP_BIN_RTCP_SYNC_TYPE, 0);
2768 gst_rtp_bin_init (GstRtpBin * rtpbin)
2772 rtpbin->priv = gst_rtp_bin_get_instance_private (rtpbin);
2773 g_mutex_init (&rtpbin->priv->bin_lock);
2774 g_mutex_init (&rtpbin->priv->dyn_lock);
2776 rtpbin->latency_ms = DEFAULT_LATENCY_MS;
2777 rtpbin->latency_ns = DEFAULT_LATENCY_MS * GST_MSECOND;
2778 rtpbin->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
2779 rtpbin->do_lost = DEFAULT_DO_LOST;
2780 rtpbin->ignore_pt = DEFAULT_IGNORE_PT;
2781 rtpbin->ntp_sync = DEFAULT_NTP_SYNC;
2782 rtpbin->rtcp_sync = DEFAULT_RTCP_SYNC;
2783 rtpbin->rtcp_sync_interval = DEFAULT_RTCP_SYNC_INTERVAL;
2784 rtpbin->priv->autoremove = DEFAULT_AUTOREMOVE;
2785 rtpbin->buffer_mode = DEFAULT_BUFFER_MODE;
2786 rtpbin->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
2787 rtpbin->send_sync_event = DEFAULT_DO_SYNC_EVENT;
2788 rtpbin->do_retransmission = DEFAULT_DO_RETRANSMISSION;
2789 rtpbin->rtp_profile = DEFAULT_RTP_PROFILE;
2790 rtpbin->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
2791 rtpbin->rtcp_sync_send_time = DEFAULT_RTCP_SYNC_SEND_TIME;
2792 rtpbin->max_rtcp_rtp_time_diff = DEFAULT_MAX_RTCP_RTP_TIME_DIFF;
2793 rtpbin->max_dropout_time = DEFAULT_MAX_DROPOUT_TIME;
2794 rtpbin->max_misorder_time = DEFAULT_MAX_MISORDER_TIME;
2795 rtpbin->rfc7273_sync = DEFAULT_RFC7273_SYNC;
2796 rtpbin->max_streams = DEFAULT_MAX_STREAMS;
2797 rtpbin->max_ts_offset_adjustment = DEFAULT_MAX_TS_OFFSET_ADJUSTMENT;
2798 rtpbin->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
2799 rtpbin->max_ts_offset_is_set = FALSE;
2800 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
2801 rtpbin->use_rtsp_buffering = FALSE;
2804 /* some default SDES entries */
2805 cname = g_strdup_printf ("user%u@host-%x", g_random_int (), g_random_int ());
2806 rtpbin->sdes = gst_structure_new ("application/x-rtp-source-sdes",
2807 "cname", G_TYPE_STRING, cname, "tool", G_TYPE_STRING, "GStreamer", NULL);
2812 gst_rtp_bin_dispose (GObject * object)
2816 rtpbin = GST_RTP_BIN (object);
2818 GST_RTP_BIN_LOCK (rtpbin);
2819 GST_DEBUG_OBJECT (object, "freeing sessions");
2820 g_slist_foreach (rtpbin->sessions, (GFunc) free_session, rtpbin);
2821 g_slist_free (rtpbin->sessions);
2822 rtpbin->sessions = NULL;
2823 GST_RTP_BIN_UNLOCK (rtpbin);
2825 G_OBJECT_CLASS (parent_class)->dispose (object);
2829 gst_rtp_bin_finalize (GObject * object)
2833 rtpbin = GST_RTP_BIN (object);
2836 gst_structure_free (rtpbin->sdes);
2838 g_mutex_clear (&rtpbin->priv->bin_lock);
2839 g_mutex_clear (&rtpbin->priv->dyn_lock);
2841 G_OBJECT_CLASS (parent_class)->finalize (object);
2846 gst_rtp_bin_set_sdes_struct (GstRtpBin * bin, const GstStructure * sdes)
2853 GST_RTP_BIN_LOCK (bin);
2855 GST_OBJECT_LOCK (bin);
2857 gst_structure_free (bin->sdes);
2858 bin->sdes = gst_structure_copy (sdes);
2859 GST_OBJECT_UNLOCK (bin);
2861 /* store in all sessions */
2862 for (item = bin->sessions; item; item = g_slist_next (item)) {
2863 GstRtpBinSession *session = item->data;
2864 g_object_set (session->session, "sdes", sdes, NULL);
2867 GST_RTP_BIN_UNLOCK (bin);
2870 static GstStructure *
2871 gst_rtp_bin_get_sdes_struct (GstRtpBin * bin)
2873 GstStructure *result;
2875 GST_OBJECT_LOCK (bin);
2876 result = gst_structure_copy (bin->sdes);
2877 GST_OBJECT_UNLOCK (bin);
2883 gst_rtp_bin_set_property (GObject * object, guint prop_id,
2884 const GValue * value, GParamSpec * pspec)
2888 rtpbin = GST_RTP_BIN (object);
2891 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
2892 case PROP_USE_RTSP_BUFFERING:
2893 GST_RTP_BIN_LOCK (rtpbin);
2894 rtpbin->use_rtsp_buffering = g_value_get_boolean (value);
2895 GST_RTP_BIN_UNLOCK (rtpbin);
2899 GST_RTP_BIN_LOCK (rtpbin);
2900 rtpbin->latency_ms = g_value_get_uint (value);
2901 rtpbin->latency_ns = rtpbin->latency_ms * GST_MSECOND;
2902 GST_RTP_BIN_UNLOCK (rtpbin);
2903 /* propagate the property down to the jitterbuffer */
2904 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "latency", value);
2906 case PROP_DROP_ON_LATENCY:
2907 GST_RTP_BIN_LOCK (rtpbin);
2908 rtpbin->drop_on_latency = g_value_get_boolean (value);
2909 GST_RTP_BIN_UNLOCK (rtpbin);
2910 /* propagate the property down to the jitterbuffer */
2911 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
2912 "drop-on-latency", value);
2915 gst_rtp_bin_set_sdes_struct (rtpbin, g_value_get_boxed (value));
2918 GST_RTP_BIN_LOCK (rtpbin);
2919 rtpbin->do_lost = g_value_get_boolean (value);
2920 GST_RTP_BIN_UNLOCK (rtpbin);
2921 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "do-lost", value);
2924 rtpbin->ntp_sync = g_value_get_boolean (value);
2925 /* The default value of max_ts_offset depends on ntp_sync. If user
2926 * hasn't set it then change default value */
2927 if (!rtpbin->max_ts_offset_is_set) {
2928 if (rtpbin->ntp_sync) {
2929 rtpbin->max_ts_offset = 0;
2931 rtpbin->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
2935 case PROP_RTCP_SYNC:
2936 g_atomic_int_set (&rtpbin->rtcp_sync, g_value_get_enum (value));
2938 case PROP_RTCP_SYNC_INTERVAL:
2939 rtpbin->rtcp_sync_interval = g_value_get_uint (value);
2941 case PROP_IGNORE_PT:
2942 rtpbin->ignore_pt = g_value_get_boolean (value);
2944 case PROP_AUTOREMOVE:
2945 rtpbin->priv->autoremove = g_value_get_boolean (value);
2947 case PROP_USE_PIPELINE_CLOCK:
2950 GST_RTP_BIN_LOCK (rtpbin);
2951 rtpbin->use_pipeline_clock = g_value_get_boolean (value);
2952 for (sessions = rtpbin->sessions; sessions;
2953 sessions = g_slist_next (sessions)) {
2954 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
2956 g_object_set (G_OBJECT (session->session),
2957 "use-pipeline-clock", rtpbin->use_pipeline_clock, NULL);
2959 GST_RTP_BIN_UNLOCK (rtpbin);
2962 case PROP_DO_SYNC_EVENT:
2963 rtpbin->send_sync_event = g_value_get_boolean (value);
2965 case PROP_BUFFER_MODE:
2966 GST_RTP_BIN_LOCK (rtpbin);
2967 rtpbin->buffer_mode = g_value_get_enum (value);
2968 GST_RTP_BIN_UNLOCK (rtpbin);
2969 /* propagate the property down to the jitterbuffer */
2970 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "mode", value);
2972 case PROP_DO_RETRANSMISSION:
2973 GST_RTP_BIN_LOCK (rtpbin);
2974 rtpbin->do_retransmission = g_value_get_boolean (value);
2975 GST_RTP_BIN_UNLOCK (rtpbin);
2976 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
2977 "do-retransmission", value);
2979 case PROP_RTP_PROFILE:
2980 rtpbin->rtp_profile = g_value_get_enum (value);
2982 case PROP_NTP_TIME_SOURCE:{
2984 GST_RTP_BIN_LOCK (rtpbin);
2985 rtpbin->ntp_time_source = g_value_get_enum (value);
2986 for (sessions = rtpbin->sessions; sessions;
2987 sessions = g_slist_next (sessions)) {
2988 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
2990 g_object_set (G_OBJECT (session->session),
2991 "ntp-time-source", rtpbin->ntp_time_source, NULL);
2993 GST_RTP_BIN_UNLOCK (rtpbin);
2996 case PROP_RTCP_SYNC_SEND_TIME:{
2998 GST_RTP_BIN_LOCK (rtpbin);
2999 rtpbin->rtcp_sync_send_time = g_value_get_boolean (value);
3000 for (sessions = rtpbin->sessions; sessions;
3001 sessions = g_slist_next (sessions)) {
3002 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3004 g_object_set (G_OBJECT (session->session),
3005 "rtcp-sync-send-time", rtpbin->rtcp_sync_send_time, NULL);
3007 GST_RTP_BIN_UNLOCK (rtpbin);
3010 case PROP_MAX_RTCP_RTP_TIME_DIFF:
3011 GST_RTP_BIN_LOCK (rtpbin);
3012 rtpbin->max_rtcp_rtp_time_diff = g_value_get_int (value);
3013 GST_RTP_BIN_UNLOCK (rtpbin);
3014 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3015 "max-rtcp-rtp-time-diff", value);
3017 case PROP_MAX_DROPOUT_TIME:
3018 GST_RTP_BIN_LOCK (rtpbin);
3019 rtpbin->max_dropout_time = g_value_get_uint (value);
3020 GST_RTP_BIN_UNLOCK (rtpbin);
3021 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3022 "max-dropout-time", value);
3023 gst_rtp_bin_propagate_property_to_session (rtpbin, "max-dropout-time",
3026 case PROP_MAX_MISORDER_TIME:
3027 GST_RTP_BIN_LOCK (rtpbin);
3028 rtpbin->max_misorder_time = g_value_get_uint (value);
3029 GST_RTP_BIN_UNLOCK (rtpbin);
3030 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3031 "max-misorder-time", value);
3032 gst_rtp_bin_propagate_property_to_session (rtpbin, "max-misorder-time",
3035 case PROP_RFC7273_SYNC:
3036 rtpbin->rfc7273_sync = g_value_get_boolean (value);
3037 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3038 "rfc7273-sync", value);
3040 case PROP_MAX_STREAMS:
3041 rtpbin->max_streams = g_value_get_uint (value);
3043 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
3044 rtpbin->max_ts_offset_adjustment = g_value_get_uint64 (value);
3045 gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
3046 "max-ts-offset-adjustment", value);
3048 case PROP_MAX_TS_OFFSET:
3049 rtpbin->max_ts_offset = g_value_get_int64 (value);
3050 rtpbin->max_ts_offset_is_set = TRUE;
3053 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3059 gst_rtp_bin_get_property (GObject * object, guint prop_id,
3060 GValue * value, GParamSpec * pspec)
3064 rtpbin = GST_RTP_BIN (object);
3067 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3068 case PROP_USE_RTSP_BUFFERING:
3069 GST_RTP_BIN_LOCK (rtpbin);
3070 g_value_set_boolean (value, rtpbin->use_rtsp_buffering);
3071 GST_RTP_BIN_UNLOCK (rtpbin);
3075 GST_RTP_BIN_LOCK (rtpbin);
3076 g_value_set_uint (value, rtpbin->latency_ms);
3077 GST_RTP_BIN_UNLOCK (rtpbin);
3079 case PROP_DROP_ON_LATENCY:
3080 GST_RTP_BIN_LOCK (rtpbin);
3081 g_value_set_boolean (value, rtpbin->drop_on_latency);
3082 GST_RTP_BIN_UNLOCK (rtpbin);
3085 g_value_take_boxed (value, gst_rtp_bin_get_sdes_struct (rtpbin));
3088 GST_RTP_BIN_LOCK (rtpbin);
3089 g_value_set_boolean (value, rtpbin->do_lost);
3090 GST_RTP_BIN_UNLOCK (rtpbin);
3092 case PROP_IGNORE_PT:
3093 g_value_set_boolean (value, rtpbin->ignore_pt);
3096 g_value_set_boolean (value, rtpbin->ntp_sync);
3098 case PROP_RTCP_SYNC:
3099 g_value_set_enum (value, g_atomic_int_get (&rtpbin->rtcp_sync));
3101 case PROP_RTCP_SYNC_INTERVAL:
3102 g_value_set_uint (value, rtpbin->rtcp_sync_interval);
3104 case PROP_AUTOREMOVE:
3105 g_value_set_boolean (value, rtpbin->priv->autoremove);
3107 case PROP_BUFFER_MODE:
3108 g_value_set_enum (value, rtpbin->buffer_mode);
3110 case PROP_USE_PIPELINE_CLOCK:
3111 g_value_set_boolean (value, rtpbin->use_pipeline_clock);
3113 case PROP_DO_SYNC_EVENT:
3114 g_value_set_boolean (value, rtpbin->send_sync_event);
3116 case PROP_DO_RETRANSMISSION:
3117 GST_RTP_BIN_LOCK (rtpbin);
3118 g_value_set_boolean (value, rtpbin->do_retransmission);
3119 GST_RTP_BIN_UNLOCK (rtpbin);
3121 case PROP_RTP_PROFILE:
3122 g_value_set_enum (value, rtpbin->rtp_profile);
3124 case PROP_NTP_TIME_SOURCE:
3125 g_value_set_enum (value, rtpbin->ntp_time_source);
3127 case PROP_RTCP_SYNC_SEND_TIME:
3128 g_value_set_boolean (value, rtpbin->rtcp_sync_send_time);
3130 case PROP_MAX_RTCP_RTP_TIME_DIFF:
3131 GST_RTP_BIN_LOCK (rtpbin);
3132 g_value_set_int (value, rtpbin->max_rtcp_rtp_time_diff);
3133 GST_RTP_BIN_UNLOCK (rtpbin);
3135 case PROP_MAX_DROPOUT_TIME:
3136 g_value_set_uint (value, rtpbin->max_dropout_time);
3138 case PROP_MAX_MISORDER_TIME:
3139 g_value_set_uint (value, rtpbin->max_misorder_time);
3141 case PROP_RFC7273_SYNC:
3142 g_value_set_boolean (value, rtpbin->rfc7273_sync);
3144 case PROP_MAX_STREAMS:
3145 g_value_set_uint (value, rtpbin->max_streams);
3147 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
3148 g_value_set_uint64 (value, rtpbin->max_ts_offset_adjustment);
3150 case PROP_MAX_TS_OFFSET:
3151 g_value_set_int64 (value, rtpbin->max_ts_offset);
3154 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3160 gst_rtp_bin_handle_message (GstBin * bin, GstMessage * message)
3164 rtpbin = GST_RTP_BIN (bin);
3166 switch (GST_MESSAGE_TYPE (message)) {
3167 case GST_MESSAGE_ELEMENT:
3169 const GstStructure *s = gst_message_get_structure (message);
3171 /* we change the structure name and add the session ID to it */
3172 if (gst_structure_has_name (s, "application/x-rtp-source-sdes")) {
3173 GstRtpBinSession *sess;
3175 /* find the session we set it as object data */
3176 sess = g_object_get_data (G_OBJECT (GST_MESSAGE_SRC (message)),
3177 "GstRTPBin.session");
3179 if (G_LIKELY (sess)) {
3180 message = gst_message_make_writable (message);
3181 s = gst_message_get_structure (message);
3182 gst_structure_set ((GstStructure *) s, "session", G_TYPE_UINT,
3186 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3189 case GST_MESSAGE_BUFFERING:
3192 gint min_percent = 100;
3193 GSList *sessions, *streams;
3194 GstRtpBinStream *stream;
3195 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3196 gboolean buffering_flag = FALSE, update_buffering_status = TRUE;
3198 gboolean change = FALSE, active = FALSE;
3199 GstClockTime min_out_time;
3200 GstBufferingMode mode;
3201 gint avg_in, avg_out;
3202 gint64 buffering_left;
3204 gst_message_parse_buffering (message, &percent);
3205 gst_message_parse_buffering_stats (message, &mode, &avg_in, &avg_out,
3209 g_object_get_data (G_OBJECT (GST_MESSAGE_SRC (message)),
3210 "GstRTPBin.stream");
3212 GST_DEBUG_OBJECT (bin, "got percent %d from stream %p", percent, stream);
3214 /* get the stream */
3215 if (G_LIKELY (stream)) {
3216 GST_RTP_BIN_LOCK (rtpbin);
3217 /* fill in the percent */
3218 stream->percent = percent;
3220 /* calculate the min value for all streams */
3221 for (sessions = rtpbin->sessions; sessions;
3222 sessions = g_slist_next (sessions)) {
3223 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3225 GST_RTP_SESSION_LOCK (session);
3226 if (session->streams) {
3227 for (streams = session->streams; streams;
3228 streams = g_slist_next (streams)) {
3229 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
3231 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3232 if (rtpbin->use_rtsp_buffering &&
3233 rtpbin->buffer_mode == RTP_JITTER_BUFFER_MODE_SLAVE) {
3234 GstPad *temp_pad_src = NULL;
3235 GstCaps *temp_caps_src = NULL;
3236 GstStructure *caps_structure;
3237 const gchar *caps_str_media = NULL;
3238 temp_pad_src = gst_element_get_static_pad (stream->buffer, "src");
3239 temp_caps_src = gst_pad_get_current_caps (temp_pad_src);
3240 GST_DEBUG_OBJECT (bin,
3241 "stream %p percent %d : temp_caps_src=%" GST_PTR_FORMAT,
3242 stream, stream->percent, temp_caps_src);
3243 if (temp_caps_src) {
3244 caps_structure = gst_caps_get_structure (temp_caps_src, 0);
3246 gst_structure_get_string (caps_structure, "media");
3247 if (caps_str_media != NULL) {
3248 if ((strcmp (caps_str_media, "video") != 0)
3249 && (strcmp (caps_str_media, "audio") != 0)) {
3250 GST_DEBUG_OBJECT (bin,
3251 "Non Audio/Video Stream.. ignoring the same !!");
3252 gst_caps_unref (temp_caps_src);
3253 gst_object_unref (temp_pad_src);
3255 } else if (stream->percent >= 100) {
3256 /* Most of the time buffering icon displays in rtsp playback.
3257 Optimizing the buffering updation code. Whenever any stream percentage
3258 reaches 100 do not post buffering messages. */
3259 if (stream->prev_percent < 100)
3260 buffering_flag = TRUE;
3262 update_buffering_status = FALSE;
3265 gst_caps_unref (temp_caps_src);
3267 gst_object_unref (temp_pad_src);
3268 /* Updating prev stream percentage */
3269 stream->prev_percent = stream->percent;
3271 GST_DEBUG_OBJECT (bin, "stream %p percent %d", stream,
3275 GST_DEBUG_OBJECT (bin, "stream %p percent %d", stream,
3279 /* find min percent */
3280 if (min_percent > stream->percent)
3281 min_percent = stream->percent;
3284 GST_INFO_OBJECT (bin,
3285 "session has no streams, setting min_percent to 0");
3288 GST_RTP_SESSION_UNLOCK (session);
3290 GST_DEBUG_OBJECT (bin, "min percent %d", min_percent);
3292 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3293 if (!(rtpbin->use_rtsp_buffering &&
3294 rtpbin->buffer_mode == RTP_JITTER_BUFFER_MODE_SLAVE)) {
3296 if (rtpbin->buffering) {
3297 if (min_percent == 100) {
3298 rtpbin->buffering = FALSE;
3303 if (min_percent < 100) {
3304 /* pause the streams */
3305 rtpbin->buffering = TRUE;
3310 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3313 GST_RTP_BIN_UNLOCK (rtpbin);
3315 gst_message_unref (message);
3317 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3318 if (rtpbin->use_rtsp_buffering &&
3319 rtpbin->buffer_mode == RTP_JITTER_BUFFER_MODE_SLAVE) {
3320 if (update_buffering_status == FALSE)
3322 if (buffering_flag) {
3324 GST_DEBUG_OBJECT (bin, "forcefully change min_percent to 100!!!");
3328 /* make a new buffering message with the min value */
3330 gst_message_new_buffering (GST_OBJECT_CAST (bin), min_percent);
3331 gst_message_set_buffering_stats (message, mode, avg_in, avg_out,
3334 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3335 if (rtpbin->use_rtsp_buffering &&
3336 rtpbin->buffer_mode == RTP_JITTER_BUFFER_MODE_SLAVE)
3337 goto slave_buffering;
3339 if (G_UNLIKELY (change)) {
3341 guint64 running_time = 0;
3344 /* figure out the running time when we have a clock */
3345 if (G_LIKELY ((clock =
3346 gst_element_get_clock (GST_ELEMENT_CAST (bin))))) {
3347 guint64 now, base_time;
3349 now = gst_clock_get_time (clock);
3350 base_time = gst_element_get_base_time (GST_ELEMENT_CAST (bin));
3351 running_time = now - base_time;
3352 gst_object_unref (clock);
3354 GST_DEBUG_OBJECT (bin,
3355 "running time now %" GST_TIME_FORMAT,
3356 GST_TIME_ARGS (running_time));
3358 GST_RTP_BIN_LOCK (rtpbin);
3360 /* when we reactivate, calculate the offsets so that all streams have
3361 * an output time that is at least as big as the running_time */
3364 if (running_time > rtpbin->buffer_start) {
3365 offset = running_time - rtpbin->buffer_start;
3366 if (offset >= rtpbin->latency_ns)
3367 offset -= rtpbin->latency_ns;
3373 /* pause all streams */
3375 for (sessions = rtpbin->sessions; sessions;
3376 sessions = g_slist_next (sessions)) {
3377 GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
3379 GST_RTP_SESSION_LOCK (session);
3380 for (streams = session->streams; streams;
3381 streams = g_slist_next (streams)) {
3382 GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
3383 GstElement *element = stream->buffer;
3384 guint64 last_out = -1;
3386 if (g_signal_lookup ("set-active", G_OBJECT_TYPE (element)) != 0) {
3387 g_signal_emit_by_name (element, "set-active", active, offset,
3392 g_object_get (element, "percent", &stream->percent, NULL);
3396 if (min_out_time == -1 || last_out < min_out_time)
3397 min_out_time = last_out;
3400 GST_DEBUG_OBJECT (bin,
3401 "setting %p to %d, offset %" GST_TIME_FORMAT ", last %"
3402 GST_TIME_FORMAT ", percent %d", element, active,
3403 GST_TIME_ARGS (offset), GST_TIME_ARGS (last_out),
3406 GST_RTP_SESSION_UNLOCK (session);
3408 GST_DEBUG_OBJECT (bin,
3409 "min out time %" GST_TIME_FORMAT, GST_TIME_ARGS (min_out_time));
3411 /* the buffer_start is the min out time of all paused jitterbuffers */
3413 rtpbin->buffer_start = min_out_time;
3415 GST_RTP_BIN_UNLOCK (rtpbin);
3418 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3421 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3426 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
3432 static GstStateChangeReturn
3433 gst_rtp_bin_change_state (GstElement * element, GstStateChange transition)
3435 GstStateChangeReturn res;
3437 GstRtpBinPrivate *priv;
3439 rtpbin = GST_RTP_BIN (element);
3440 priv = rtpbin->priv;
3442 switch (transition) {
3443 case GST_STATE_CHANGE_NULL_TO_READY:
3445 case GST_STATE_CHANGE_READY_TO_PAUSED:
3446 priv->last_ntpnstime = 0;
3447 GST_LOG_OBJECT (rtpbin, "clearing shutdown flag");
3448 g_atomic_int_set (&priv->shutdown, 0);
3450 case GST_STATE_CHANGE_PAUSED_TO_READY:
3451 GST_LOG_OBJECT (rtpbin, "setting shutdown flag");
3452 g_atomic_int_set (&priv->shutdown, 1);
3453 /* wait for all callbacks to end by taking the lock. No new callbacks will
3454 * be able to happen as we set the shutdown flag. */
3455 GST_RTP_BIN_DYN_LOCK (rtpbin);
3456 GST_LOG_OBJECT (rtpbin, "dynamic lock taken, we can continue shutdown");
3457 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
3463 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3465 switch (transition) {
3466 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3468 case GST_STATE_CHANGE_PAUSED_TO_READY:
3470 case GST_STATE_CHANGE_READY_TO_NULL:
3479 session_request_element (GstRtpBinSession * session, guint signal)
3481 GstElement *element = NULL;
3482 GstRtpBin *bin = session->bin;
3484 g_signal_emit (bin, gst_rtp_bin_signals[signal], 0, session->id, &element);
3487 if (!bin_manage_element (bin, element))
3489 session->elements = g_slist_prepend (session->elements, element);
3496 GST_WARNING_OBJECT (bin, "unable to manage element");
3497 gst_object_unref (element);
3503 copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
3505 GstPad *gpad = GST_PAD_CAST (user_data);
3507 GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
3508 gst_pad_store_sticky_event (gpad, *event);
3514 expose_recv_src_pad (GstRtpBin * rtpbin, GstPad * pad, GstRtpBinStream * stream,
3517 GstElementClass *klass;
3518 GstPadTemplate *templ;
3522 gst_object_ref (pad);
3524 if (stream->session->storage) {
3525 GstElement *fec_decoder =
3526 session_request_element (stream->session, SIGNAL_REQUEST_FEC_DECODER);
3529 GstPad *sinkpad, *srcpad;
3530 GstPadLinkReturn ret;
3532 sinkpad = gst_element_get_static_pad (fec_decoder, "sink");
3535 goto fec_decoder_sink_failed;
3537 ret = gst_pad_link (pad, sinkpad);
3538 gst_object_unref (sinkpad);
3540 if (ret != GST_PAD_LINK_OK)
3541 goto fec_decoder_link_failed;
3543 srcpad = gst_element_get_static_pad (fec_decoder, "src");
3546 goto fec_decoder_src_failed;
3548 gst_pad_sticky_events_foreach (pad, copy_sticky_events, srcpad);
3549 gst_object_unref (pad);
3554 GST_RTP_BIN_SHUTDOWN_LOCK (rtpbin, shutdown);
3556 /* ghost the pad to the parent */
3557 klass = GST_ELEMENT_GET_CLASS (rtpbin);
3558 templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%u_%u_%u");
3559 padname = g_strdup_printf ("recv_rtp_src_%u_%u_%u",
3560 stream->session->id, stream->ssrc, pt);
3561 gpad = gst_ghost_pad_new_from_template (padname, pad, templ);
3563 g_object_set_data (G_OBJECT (pad), "GstRTPBin.ghostpad", gpad);
3565 gst_pad_set_active (gpad, TRUE);
3566 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3568 gst_pad_sticky_events_foreach (pad, copy_sticky_events, gpad);
3569 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3572 gst_object_unref (pad);
3578 GST_DEBUG ("ignoring, we are shutting down");
3581 fec_decoder_sink_failed:
3583 g_warning ("rtpbin: failed to get fec encoder sink pad for session %u",
3584 stream->session->id);
3587 fec_decoder_src_failed:
3589 g_warning ("rtpbin: failed to get fec encoder src pad for session %u",
3590 stream->session->id);
3593 fec_decoder_link_failed:
3595 g_warning ("rtpbin: failed to link fec decoder for session %u",
3596 stream->session->id);
3601 /* a new pad (SSRC) was created in @session. This signal is emitted from the
3602 * payload demuxer. */
3604 new_payload_found (GstElement * element, guint pt, GstPad * pad,
3605 GstRtpBinStream * stream)
3609 rtpbin = stream->bin;
3611 GST_DEBUG_OBJECT (rtpbin, "new payload pad %u", pt);
3613 expose_recv_src_pad (rtpbin, pad, stream, pt);
3617 payload_pad_removed (GstElement * element, GstPad * pad,
3618 GstRtpBinStream * stream)
3623 rtpbin = stream->bin;
3625 GST_DEBUG ("payload pad removed");
3627 GST_RTP_BIN_DYN_LOCK (rtpbin);
3628 if ((gpad = g_object_get_data (G_OBJECT (pad), "GstRTPBin.ghostpad"))) {
3629 g_object_set_data (G_OBJECT (pad), "GstRTPBin.ghostpad", NULL);
3631 gst_pad_set_active (gpad, FALSE);
3632 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin), gpad);
3634 GST_RTP_BIN_DYN_UNLOCK (rtpbin);
3638 pt_map_requested (GstElement * element, guint pt, GstRtpBinSession * session)
3643 rtpbin = session->bin;
3645 GST_DEBUG_OBJECT (rtpbin, "payload map requested for pt %u in session %u", pt,
3648 caps = get_pt_map (session, pt);
3657 GST_DEBUG_OBJECT (rtpbin, "could not get caps");
3663 ptdemux_pt_map_requested (GstElement * element, guint pt,
3664 GstRtpBinSession * session)
3666 GstCaps *ret = pt_map_requested (element, pt, session);
3668 if (ret && gst_caps_get_size (ret) == 1) {
3669 const GstStructure *s = gst_caps_get_structure (ret, 0);
3672 if (gst_structure_get_boolean (s, "is-fec", &is_fec) && is_fec) {
3673 GValue v = G_VALUE_INIT;
3674 GValue v2 = G_VALUE_INIT;
3676 GST_INFO_OBJECT (session->bin, "Will ignore FEC pt %u in session %u", pt,
3678 g_value_init (&v, GST_TYPE_ARRAY);
3679 g_value_init (&v2, G_TYPE_INT);
3680 g_object_get_property (G_OBJECT (element), "ignored-payload-types", &v);
3681 g_value_set_int (&v2, pt);
3682 gst_value_array_append_value (&v, &v2);
3683 g_value_unset (&v2);
3684 g_object_set_property (G_OBJECT (element), "ignored-payload-types", &v);
3693 payload_type_change (GstElement * element, guint pt, GstRtpBinSession * session)
3695 GST_DEBUG_OBJECT (session->bin,
3696 "emitting signal for pt type changed to %u in session %u", pt,
3699 g_signal_emit (session->bin, gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE],
3700 0, session->id, pt);
3703 /* emitted when caps changed for the session */
3705 caps_changed (GstPad * pad, GParamSpec * pspec, GstRtpBinSession * session)
3710 const GstStructure *s;
3714 g_object_get (pad, "caps", &caps, NULL);
3719 GST_DEBUG_OBJECT (bin, "got caps %" GST_PTR_FORMAT, caps);
3721 s = gst_caps_get_structure (caps, 0);
3723 /* get payload, finish when it's not there */
3724 if (!gst_structure_get_int (s, "payload", &payload)) {
3725 gst_caps_unref (caps);
3729 GST_RTP_SESSION_LOCK (session);
3730 GST_DEBUG_OBJECT (bin, "insert caps for payload %d", payload);
3731 g_hash_table_insert (session->ptmap, GINT_TO_POINTER (payload), caps);
3732 GST_RTP_SESSION_UNLOCK (session);
3735 /* a new pad (SSRC) was created in @session */
3737 new_ssrc_pad_found (GstElement * element, guint ssrc, GstPad * pad,
3738 GstRtpBinSession * session)
3741 GstRtpBinStream *stream;
3742 GstPad *sinkpad, *srcpad;
3745 rtpbin = session->bin;
3747 GST_DEBUG_OBJECT (rtpbin, "new SSRC pad %08x, %s:%s", ssrc,
3748 GST_DEBUG_PAD_NAME (pad));
3750 GST_RTP_BIN_SHUTDOWN_LOCK (rtpbin, shutdown);
3752 GST_RTP_SESSION_LOCK (session);
3754 /* create new stream */
3755 stream = create_stream (session, ssrc);
3759 /* get pad and link */
3760 GST_DEBUG_OBJECT (rtpbin, "linking jitterbuffer RTP");
3761 padname = g_strdup_printf ("src_%u", ssrc);
3762 srcpad = gst_element_get_static_pad (element, padname);
3764 sinkpad = gst_element_get_static_pad (stream->buffer, "sink");
3765 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
3766 gst_object_unref (sinkpad);
3767 gst_object_unref (srcpad);
3769 sinkpad = gst_element_get_request_pad (stream->buffer, "sink_rtcp");
3771 GST_DEBUG_OBJECT (rtpbin, "linking jitterbuffer RTCP");
3772 padname = g_strdup_printf ("rtcp_src_%u", ssrc);
3773 srcpad = gst_element_get_static_pad (element, padname);
3775 gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
3776 gst_object_unref (sinkpad);
3777 gst_object_unref (srcpad);
3780 if (g_signal_lookup ("handle-sync", G_OBJECT_TYPE (stream->buffer)) != 0) {
3781 /* connect to the RTCP sync signal from the jitterbuffer */
3782 GST_DEBUG_OBJECT (rtpbin, "connecting sync signal");
3783 stream->buffer_handlesync_sig = g_signal_connect (stream->buffer,
3784 "handle-sync", (GCallback) gst_rtp_bin_handle_sync, stream);
3787 if (stream->demux) {
3788 /* connect to the new-pad signal of the payload demuxer, this will expose the
3789 * new pad by ghosting it. */
3790 stream->demux_newpad_sig = g_signal_connect (stream->demux,
3791 "new-payload-type", (GCallback) new_payload_found, stream);
3792 stream->demux_padremoved_sig = g_signal_connect (stream->demux,
3793 "pad-removed", (GCallback) payload_pad_removed, stream);
3795 /* connect to the request-pt-map signal. This signal will be emitted by the
3796 * demuxer so that it can apply a proper caps on the buffers for the
3798 stream->demux_ptreq_sig = g_signal_connect (stream->demux,
3799 "request-pt-map", (GCallback) ptdemux_pt_map_requested, session);
3800 /* connect to the signal so it can be forwarded. */
3801 stream->demux_ptchange_sig = g_signal_connect (stream->demux,
3802 "payload-type-change", (GCallback) payload_type_change, session);
3804 GST_RTP_SESSION_UNLOCK (session);
3805 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3807 /* add rtpjitterbuffer src pad to pads */
3810 pad = gst_element_get_static_pad (stream->buffer, "src");
3812 GST_RTP_SESSION_UNLOCK (session);
3813 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3815 expose_recv_src_pad (rtpbin, pad, stream, 255);
3817 gst_object_unref (pad);
3825 GST_DEBUG_OBJECT (rtpbin, "we are shutting down");
3830 GST_RTP_SESSION_UNLOCK (session);
3831 GST_RTP_BIN_SHUTDOWN_UNLOCK (rtpbin);
3832 GST_DEBUG_OBJECT (rtpbin, "could not create stream");
3838 complete_session_sink (GstRtpBin * rtpbin, GstRtpBinSession * session)
3840 guint sessid = session->id;
3841 GstPad *recv_rtp_sink;
3842 GstElement *decoder;
3844 g_assert (!session->recv_rtp_sink);
3846 /* get recv_rtp pad and store */
3847 session->recv_rtp_sink =
3848 gst_element_get_request_pad (session->session, "recv_rtp_sink");
3849 if (session->recv_rtp_sink == NULL)
3852 g_signal_connect (session->recv_rtp_sink, "notify::caps",
3853 (GCallback) caps_changed, session);
3855 GST_DEBUG_OBJECT (rtpbin, "requesting RTP decoder");
3856 decoder = session_request_element (session, SIGNAL_REQUEST_RTP_DECODER);
3858 GstPad *decsrc, *decsink;
3859 GstPadLinkReturn ret;
3861 GST_DEBUG_OBJECT (rtpbin, "linking RTP decoder");
3862 decsink = gst_element_get_static_pad (decoder, "rtp_sink");
3863 if (decsink == NULL)
3864 goto dec_sink_failed;
3866 recv_rtp_sink = decsink;
3868 decsrc = gst_element_get_static_pad (decoder, "rtp_src");
3870 goto dec_src_failed;
3872 ret = gst_pad_link (decsrc, session->recv_rtp_sink);
3874 gst_object_unref (decsrc);
3876 if (ret != GST_PAD_LINK_OK)
3877 goto dec_link_failed;
3880 GST_DEBUG_OBJECT (rtpbin, "no RTP decoder given");
3881 recv_rtp_sink = gst_object_ref (session->recv_rtp_sink);
3884 return recv_rtp_sink;
3889 g_warning ("rtpbin: failed to get session recv_rtp_sink pad");
3894 g_warning ("rtpbin: failed to get decoder sink pad for session %u", sessid);
3899 g_warning ("rtpbin: failed to get decoder src pad for session %u", sessid);
3900 gst_object_unref (recv_rtp_sink);
3905 g_warning ("rtpbin: failed to link rtp decoder for session %u", sessid);
3906 gst_object_unref (recv_rtp_sink);
3912 complete_session_receiver (GstRtpBin * rtpbin, GstRtpBinSession * session,
3916 GstPad *recv_rtp_src;
3918 g_assert (!session->recv_rtp_src);
3920 session->recv_rtp_src =
3921 gst_element_get_static_pad (session->session, "recv_rtp_src");
3922 if (session->recv_rtp_src == NULL)
3925 /* find out if we need AUX elements */
3926 aux = session_request_element (session, SIGNAL_REQUEST_AUX_RECEIVER);
3930 GstPadLinkReturn ret;
3932 GST_DEBUG_OBJECT (rtpbin, "linking AUX receiver");
3934 pname = g_strdup_printf ("sink_%u", sessid);
3935 auxsink = gst_element_get_static_pad (aux, pname);
3937 if (auxsink == NULL)
3938 goto aux_sink_failed;
3940 ret = gst_pad_link (session->recv_rtp_src, auxsink);
3941 gst_object_unref (auxsink);
3942 if (ret != GST_PAD_LINK_OK)
3943 goto aux_link_failed;
3945 /* this can be NULL when this AUX element is not to be linked any further */
3946 pname = g_strdup_printf ("src_%u", sessid);
3947 recv_rtp_src = gst_element_get_static_pad (aux, pname);
3950 recv_rtp_src = gst_object_ref (session->recv_rtp_src);
3953 /* Add a storage element if needed */
3954 if (recv_rtp_src && session->storage) {
3955 GstPadLinkReturn ret;
3956 GstPad *sinkpad = gst_element_get_static_pad (session->storage, "sink");
3958 ret = gst_pad_link (recv_rtp_src, sinkpad);
3960 gst_object_unref (sinkpad);
3961 gst_object_unref (recv_rtp_src);
3963 if (ret != GST_PAD_LINK_OK)
3964 goto storage_link_failed;
3966 recv_rtp_src = gst_element_get_static_pad (session->storage, "src");
3972 GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTP sink pad");
3973 sinkdpad = gst_element_get_static_pad (session->demux, "sink");
3974 GST_DEBUG_OBJECT (rtpbin, "linking demuxer RTP sink pad");
3975 gst_pad_link_full (recv_rtp_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
3976 gst_object_unref (sinkdpad);
3977 gst_object_unref (recv_rtp_src);
3979 /* connect to the new-ssrc-pad signal of the SSRC demuxer */
3980 session->demux_newpad_sig = g_signal_connect (session->demux,
3981 "new-ssrc-pad", (GCallback) new_ssrc_pad_found, session);
3982 session->demux_padremoved_sig = g_signal_connect (session->demux,
3983 "removed-ssrc-pad", (GCallback) ssrc_demux_pad_removed, session);
3990 g_warning ("rtpbin: failed to get session recv_rtp_src pad");
3995 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
4000 g_warning ("rtpbin: failed to link AUX pad to session %u", sessid);
4003 storage_link_failed:
4005 g_warning ("rtpbin: failed to link storage");
4010 /* Create a pad for receiving RTP for the session in @name. Must be called with
4014 create_recv_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
4017 GstRtpBinSession *session;
4018 GstPad *recv_rtp_sink;
4020 /* first get the session number */
4021 if (name == NULL || sscanf (name, "recv_rtp_sink_%u", &sessid) != 1)
4024 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
4026 /* get or create session */
4027 session = find_session_by_id (rtpbin, sessid);
4029 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4030 /* create session now */
4031 session = create_session (rtpbin, sessid);
4032 if (session == NULL)
4036 /* check if pad was requested */
4037 if (session->recv_rtp_sink_ghost != NULL)
4038 return session->recv_rtp_sink_ghost;
4040 /* setup the session sink pad */
4041 recv_rtp_sink = complete_session_sink (rtpbin, session);
4043 goto session_sink_failed;
4045 GST_DEBUG_OBJECT (rtpbin, "ghosting session sink pad");
4046 session->recv_rtp_sink_ghost =
4047 gst_ghost_pad_new_from_template (name, recv_rtp_sink, templ);
4048 gst_object_unref (recv_rtp_sink);
4049 gst_pad_set_active (session->recv_rtp_sink_ghost, TRUE);
4050 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->recv_rtp_sink_ghost);
4052 complete_session_receiver (rtpbin, session, sessid);
4054 return session->recv_rtp_sink_ghost;
4059 g_warning ("rtpbin: cannot find session id for pad: %s",
4060 GST_STR_NULL (name));
4065 /* create_session already warned */
4068 session_sink_failed:
4070 /* warning already done */
4076 remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4078 if (session->demux_newpad_sig) {
4079 g_signal_handler_disconnect (session->demux, session->demux_newpad_sig);
4080 session->demux_newpad_sig = 0;
4082 if (session->demux_padremoved_sig) {
4083 g_signal_handler_disconnect (session->demux, session->demux_padremoved_sig);
4084 session->demux_padremoved_sig = 0;
4086 if (session->recv_rtp_src) {
4087 gst_object_unref (session->recv_rtp_src);
4088 session->recv_rtp_src = NULL;
4090 if (session->recv_rtp_sink) {
4091 gst_element_release_request_pad (session->session, session->recv_rtp_sink);
4092 gst_object_unref (session->recv_rtp_sink);
4093 session->recv_rtp_sink = NULL;
4095 if (session->recv_rtp_sink_ghost) {
4096 gst_pad_set_active (session->recv_rtp_sink_ghost, FALSE);
4097 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4098 session->recv_rtp_sink_ghost);
4099 session->recv_rtp_sink_ghost = NULL;
4104 complete_session_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session,
4107 GstElement *decoder;
4109 GstPad *decsink = NULL;
4111 /* get recv_rtp pad and store */
4112 GST_DEBUG_OBJECT (rtpbin, "getting RTCP sink pad");
4113 session->recv_rtcp_sink =
4114 gst_element_get_request_pad (session->session, "recv_rtcp_sink");
4115 if (session->recv_rtcp_sink == NULL)
4118 GST_DEBUG_OBJECT (rtpbin, "getting RTCP decoder");
4119 decoder = session_request_element (session, SIGNAL_REQUEST_RTCP_DECODER);
4122 GstPadLinkReturn ret;
4124 GST_DEBUG_OBJECT (rtpbin, "linking RTCP decoder");
4125 decsink = gst_element_get_static_pad (decoder, "rtcp_sink");
4126 decsrc = gst_element_get_static_pad (decoder, "rtcp_src");
4128 if (decsink == NULL)
4129 goto dec_sink_failed;
4132 goto dec_src_failed;
4134 ret = gst_pad_link (decsrc, session->recv_rtcp_sink);
4136 gst_object_unref (decsrc);
4138 if (ret != GST_PAD_LINK_OK)
4139 goto dec_link_failed;
4141 GST_DEBUG_OBJECT (rtpbin, "no RTCP decoder given");
4142 decsink = gst_object_ref (session->recv_rtcp_sink);
4145 /* get srcpad, link to SSRCDemux */
4146 GST_DEBUG_OBJECT (rtpbin, "getting sync src pad");
4147 session->sync_src = gst_element_get_static_pad (session->session, "sync_src");
4148 if (session->sync_src == NULL)
4149 goto src_pad_failed;
4151 GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTCP sink pad");
4152 sinkdpad = gst_element_get_static_pad (session->demux, "rtcp_sink");
4153 gst_pad_link_full (session->sync_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
4154 gst_object_unref (sinkdpad);
4160 g_warning ("rtpbin: failed to get session rtcp_sink pad");
4165 g_warning ("rtpbin: failed to get decoder sink pad for session %u", sessid);
4170 g_warning ("rtpbin: failed to get decoder src pad for session %u", sessid);
4175 g_warning ("rtpbin: failed to link rtcp decoder for session %u", sessid);
4180 g_warning ("rtpbin: failed to get session sync_src pad");
4184 gst_object_unref (decsink);
4188 /* Create a pad for receiving RTCP for the session in @name. Must be called with
4192 create_recv_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
4196 GstRtpBinSession *session;
4197 GstPad *decsink = NULL;
4199 /* first get the session number */
4200 if (name == NULL || sscanf (name, "recv_rtcp_sink_%u", &sessid) != 1)
4203 GST_DEBUG_OBJECT (rtpbin, "finding session %u", sessid);
4205 /* get or create the session */
4206 session = find_session_by_id (rtpbin, sessid);
4208 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4209 /* create session now */
4210 session = create_session (rtpbin, sessid);
4211 if (session == NULL)
4215 /* check if pad was requested */
4216 if (session->recv_rtcp_sink_ghost != NULL)
4217 return session->recv_rtcp_sink_ghost;
4219 decsink = complete_session_rtcp (rtpbin, session, sessid);
4223 session->recv_rtcp_sink_ghost =
4224 gst_ghost_pad_new_from_template (name, decsink, templ);
4225 gst_object_unref (decsink);
4226 gst_pad_set_active (session->recv_rtcp_sink_ghost, TRUE);
4227 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin),
4228 session->recv_rtcp_sink_ghost);
4230 return session->recv_rtcp_sink_ghost;
4235 g_warning ("rtpbin: cannot find session id for pad: %s",
4236 GST_STR_NULL (name));
4241 /* create_session already warned */
4247 remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4249 if (session->recv_rtcp_sink_ghost) {
4250 gst_pad_set_active (session->recv_rtcp_sink_ghost, FALSE);
4251 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4252 session->recv_rtcp_sink_ghost);
4253 session->recv_rtcp_sink_ghost = NULL;
4255 if (session->sync_src) {
4256 /* releasing the request pad should also unref the sync pad */
4257 gst_object_unref (session->sync_src);
4258 session->sync_src = NULL;
4260 if (session->recv_rtcp_sink) {
4261 gst_element_release_request_pad (session->session, session->recv_rtcp_sink);
4262 gst_object_unref (session->recv_rtcp_sink);
4263 session->recv_rtcp_sink = NULL;
4268 complete_session_src (GstRtpBin * rtpbin, GstRtpBinSession * session)
4271 guint sessid = session->id;
4272 GstPad *send_rtp_src;
4273 GstElement *encoder;
4274 GstElementClass *klass;
4275 GstPadTemplate *templ;
4276 gboolean ret = FALSE;
4279 send_rtp_src = gst_element_get_static_pad (session->session, "send_rtp_src");
4281 if (send_rtp_src == NULL)
4284 GST_DEBUG_OBJECT (rtpbin, "getting RTP encoder");
4285 encoder = session_request_element (session, SIGNAL_REQUEST_RTP_ENCODER);
4288 GstPad *encsrc, *encsink;
4289 GstPadLinkReturn ret;
4291 GST_DEBUG_OBJECT (rtpbin, "linking RTP encoder");
4292 ename = g_strdup_printf ("rtp_src_%u", sessid);
4293 encsrc = gst_element_get_static_pad (encoder, ename);
4297 goto enc_src_failed;
4299 ename = g_strdup_printf ("rtp_sink_%u", sessid);
4300 encsink = gst_element_get_static_pad (encoder, ename);
4302 if (encsink == NULL)
4303 goto enc_sink_failed;
4305 ret = gst_pad_link (send_rtp_src, encsink);
4306 gst_object_unref (encsink);
4307 gst_object_unref (send_rtp_src);
4309 send_rtp_src = encsrc;
4311 if (ret != GST_PAD_LINK_OK)
4312 goto enc_link_failed;
4314 GST_DEBUG_OBJECT (rtpbin, "no RTP encoder given");
4317 /* ghost the new source pad */
4318 klass = GST_ELEMENT_GET_CLASS (rtpbin);
4319 gname = g_strdup_printf ("send_rtp_src_%u", sessid);
4320 templ = gst_element_class_get_pad_template (klass, "send_rtp_src_%u");
4321 session->send_rtp_src_ghost =
4322 gst_ghost_pad_new_from_template (gname, send_rtp_src, templ);
4323 gst_pad_set_active (session->send_rtp_src_ghost, TRUE);
4324 gst_pad_sticky_events_foreach (send_rtp_src, copy_sticky_events,
4325 session->send_rtp_src_ghost);
4326 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_src_ghost);
4333 gst_object_unref (send_rtp_src);
4340 g_warning ("rtpbin: failed to get rtp source pad for session %u", sessid);
4345 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4346 " src pad for session %u", encoder, sessid);
4351 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4352 " sink pad for session %u", encoder, sessid);
4357 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4364 setup_aux_sender_fold (const GValue * item, GValue * result, gpointer user_data)
4369 GstRtpBinSession *session = user_data, *newsess;
4370 GstRtpBin *rtpbin = session->bin;
4371 GstPadLinkReturn ret;
4373 pad = g_value_get_object (item);
4374 name = gst_pad_get_name (pad);
4376 if (name == NULL || sscanf (name, "src_%u", &sessid) != 1)
4381 newsess = find_session_by_id (rtpbin, sessid);
4382 if (newsess == NULL) {
4383 /* create new session */
4384 newsess = create_session (rtpbin, sessid);
4385 if (newsess == NULL)
4387 } else if (newsess->send_rtp_sink != NULL)
4388 goto existing_session;
4390 /* get send_rtp pad and store */
4391 newsess->send_rtp_sink =
4392 gst_element_get_request_pad (newsess->session, "send_rtp_sink");
4393 if (newsess->send_rtp_sink == NULL)
4396 ret = gst_pad_link (pad, newsess->send_rtp_sink);
4397 if (ret != GST_PAD_LINK_OK)
4398 goto aux_link_failed;
4400 if (!complete_session_src (rtpbin, newsess))
4401 goto session_src_failed;
4408 GST_WARNING ("ignoring invalid pad name %s", GST_STR_NULL (name));
4414 /* create_session already warned */
4419 GST_DEBUG_OBJECT (rtpbin,
4420 "skipping src_%i setup, since it is already configured.", sessid);
4425 g_warning ("rtpbin: failed to get session pad for session %u", sessid);
4430 g_warning ("rtpbin: failed to link AUX for session %u", sessid);
4435 g_warning ("rtpbin: failed to complete AUX for session %u", sessid);
4441 setup_aux_sender (GstRtpBin * rtpbin, GstRtpBinSession * session,
4445 GValue result = { 0, };
4446 GstIteratorResult res;
4448 it = gst_element_iterate_src_pads (aux);
4449 res = gst_iterator_fold (it, setup_aux_sender_fold, &result, session);
4450 gst_iterator_free (it);
4452 return res == GST_ITERATOR_DONE;
4455 /* Create a pad for sending RTP for the session in @name. Must be called with
4459 create_send_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
4463 GstPad *send_rtp_sink;
4465 GstElement *encoder;
4466 GstElement *prev = NULL;
4467 GstRtpBinSession *session;
4469 /* first get the session number */
4470 if (name == NULL || sscanf (name, "send_rtp_sink_%u", &sessid) != 1)
4473 /* get or create session */
4474 session = find_session_by_id (rtpbin, sessid);
4476 /* create session now */
4477 session = create_session (rtpbin, sessid);
4478 if (session == NULL)
4482 /* check if pad was requested */
4483 if (session->send_rtp_sink_ghost != NULL)
4484 return session->send_rtp_sink_ghost;
4486 /* check if we are already using this session as a sender */
4487 if (session->send_rtp_sink != NULL)
4488 goto existing_session;
4490 encoder = session_request_element (session, SIGNAL_REQUEST_FEC_ENCODER);
4493 GST_DEBUG_OBJECT (rtpbin, "Linking FEC encoder");
4495 send_rtp_sink = gst_element_get_static_pad (encoder, "sink");
4498 goto enc_sink_failed;
4503 GST_DEBUG_OBJECT (rtpbin, "getting RTP AUX sender");
4504 aux = session_request_element (session, SIGNAL_REQUEST_AUX_SENDER);
4507 GST_DEBUG_OBJECT (rtpbin, "linking AUX sender");
4508 if (!setup_aux_sender (rtpbin, session, aux))
4509 goto aux_session_failed;
4511 pname = g_strdup_printf ("sink_%u", sessid);
4512 sinkpad = gst_element_get_static_pad (aux, pname);
4515 if (sinkpad == NULL)
4516 goto aux_sink_failed;
4519 send_rtp_sink = sinkpad;
4521 GstPad *srcpad = gst_element_get_static_pad (prev, "src");
4522 GstPadLinkReturn ret;
4524 ret = gst_pad_link (srcpad, sinkpad);
4525 gst_object_unref (srcpad);
4526 if (ret != GST_PAD_LINK_OK) {
4527 goto aux_link_failed;
4532 /* get send_rtp pad and store */
4533 session->send_rtp_sink =
4534 gst_element_get_request_pad (session->session, "send_rtp_sink");
4535 if (session->send_rtp_sink == NULL)
4538 if (!complete_session_src (rtpbin, session))
4539 goto session_src_failed;
4542 send_rtp_sink = gst_object_ref (session->send_rtp_sink);
4544 GstPad *srcpad = gst_element_get_static_pad (prev, "src");
4545 GstPadLinkReturn ret;
4547 ret = gst_pad_link (srcpad, session->send_rtp_sink);
4548 gst_object_unref (srcpad);
4549 if (ret != GST_PAD_LINK_OK)
4550 goto session_link_failed;
4554 session->send_rtp_sink_ghost =
4555 gst_ghost_pad_new_from_template (name, send_rtp_sink, templ);
4556 gst_object_unref (send_rtp_sink);
4557 gst_pad_set_active (session->send_rtp_sink_ghost, TRUE);
4558 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_sink_ghost);
4560 return session->send_rtp_sink_ghost;
4565 g_warning ("rtpbin: cannot find session id for pad: %s",
4566 GST_STR_NULL (name));
4571 /* create_session already warned */
4576 g_warning ("rtpbin: session %u is already in use", sessid);
4581 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
4586 g_warning ("rtpbin: failed to get AUX sink pad for session %u", sessid);
4591 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4597 g_warning ("rtpbin: failed to get session pad for session %u", sessid);
4602 g_warning ("rtpbin: failed to setup source pads for session %u", sessid);
4605 session_link_failed:
4607 g_warning ("rtpbin: failed to link %" GST_PTR_FORMAT " for session %u",
4613 g_warning ("rtpbin: failed to get %" GST_PTR_FORMAT
4614 " sink pad for session %u", encoder, sessid);
4620 remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4622 if (session->send_rtp_src_ghost) {
4623 gst_pad_set_active (session->send_rtp_src_ghost, FALSE);
4624 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4625 session->send_rtp_src_ghost);
4626 session->send_rtp_src_ghost = NULL;
4628 if (session->send_rtp_sink) {
4629 gst_element_release_request_pad (GST_ELEMENT_CAST (session->session),
4630 session->send_rtp_sink);
4631 gst_object_unref (session->send_rtp_sink);
4632 session->send_rtp_sink = NULL;
4634 if (session->send_rtp_sink_ghost) {
4635 gst_pad_set_active (session->send_rtp_sink_ghost, FALSE);
4636 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4637 session->send_rtp_sink_ghost);
4638 session->send_rtp_sink_ghost = NULL;
4642 /* Create a pad for sending RTCP for the session in @name. Must be called with
4646 create_send_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
4651 GstElement *encoder;
4652 GstRtpBinSession *session;
4654 /* first get the session number */
4655 if (name == NULL || sscanf (name, "send_rtcp_src_%u", &sessid) != 1)
4658 /* get or create session */
4659 session = find_session_by_id (rtpbin, sessid);
4661 GST_DEBUG_OBJECT (rtpbin, "creating session %u", sessid);
4662 /* create session now */
4663 session = create_session (rtpbin, sessid);
4664 if (session == NULL)
4668 /* check if pad was requested */
4669 if (session->send_rtcp_src_ghost != NULL)
4670 return session->send_rtcp_src_ghost;
4672 /* get rtcp_src pad and store */
4673 session->send_rtcp_src =
4674 gst_element_get_request_pad (session->session, "send_rtcp_src");
4675 if (session->send_rtcp_src == NULL)
4678 GST_DEBUG_OBJECT (rtpbin, "getting RTCP encoder");
4679 encoder = session_request_element (session, SIGNAL_REQUEST_RTCP_ENCODER);
4683 GstPadLinkReturn ret;
4685 GST_DEBUG_OBJECT (rtpbin, "linking RTCP encoder");
4687 ename = g_strdup_printf ("rtcp_src_%u", sessid);
4688 encsrc = gst_element_get_static_pad (encoder, ename);
4691 goto enc_src_failed;
4693 ename = g_strdup_printf ("rtcp_sink_%u", sessid);
4694 encsink = gst_element_get_static_pad (encoder, ename);
4696 if (encsink == NULL)
4697 goto enc_sink_failed;
4699 ret = gst_pad_link (session->send_rtcp_src, encsink);
4700 gst_object_unref (encsink);
4702 if (ret != GST_PAD_LINK_OK)
4703 goto enc_link_failed;
4705 GST_DEBUG_OBJECT (rtpbin, "no RTCP encoder given");
4706 encsrc = gst_object_ref (session->send_rtcp_src);
4709 session->send_rtcp_src_ghost =
4710 gst_ghost_pad_new_from_template (name, encsrc, templ);
4711 gst_object_unref (encsrc);
4712 gst_pad_set_active (session->send_rtcp_src_ghost, TRUE);
4713 gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtcp_src_ghost);
4715 return session->send_rtcp_src_ghost;
4720 g_warning ("rtpbin: cannot find session id for pad: %s",
4721 GST_STR_NULL (name));
4726 /* create_session already warned */
4731 g_warning ("rtpbin: failed to get rtcp pad for session %u", sessid);
4736 g_warning ("rtpbin: failed to get encoder src pad for session %u", sessid);
4741 g_warning ("rtpbin: failed to get encoder sink pad for session %u", sessid);
4742 gst_object_unref (encsrc);
4747 g_warning ("rtpbin: failed to link rtcp encoder for session %u", sessid);
4748 gst_object_unref (encsrc);
4754 remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session)
4756 if (session->send_rtcp_src_ghost) {
4757 gst_pad_set_active (session->send_rtcp_src_ghost, FALSE);
4758 gst_element_remove_pad (GST_ELEMENT_CAST (rtpbin),
4759 session->send_rtcp_src_ghost);
4760 session->send_rtcp_src_ghost = NULL;
4762 if (session->send_rtcp_src) {
4763 gst_element_release_request_pad (session->session, session->send_rtcp_src);
4764 gst_object_unref (session->send_rtcp_src);
4765 session->send_rtcp_src = NULL;
4769 /* If the requested name is NULL we should create a name with
4770 * the session number assuming we want the lowest possible session
4771 * with a free pad like the template */
4773 gst_rtp_bin_get_free_pad_name (GstElement * element, GstPadTemplate * templ)
4775 gboolean name_found = FALSE;
4777 GstIterator *pad_it = NULL;
4778 gchar *pad_name = NULL;
4779 GValue data = { 0, };
4781 GST_DEBUG_OBJECT (element, "find a free pad name for template");
4782 while (!name_found) {
4783 gboolean done = FALSE;
4786 pad_name = g_strdup_printf (templ->name_template, session++);
4787 pad_it = gst_element_iterate_pads (GST_ELEMENT (element));
4790 switch (gst_iterator_next (pad_it, &data)) {
4791 case GST_ITERATOR_OK:
4796 pad = g_value_get_object (&data);
4797 name = gst_pad_get_name (pad);
4799 if (strcmp (name, pad_name) == 0) {
4804 g_value_reset (&data);
4807 case GST_ITERATOR_ERROR:
4808 case GST_ITERATOR_RESYNC:
4809 /* restart iteration */
4814 case GST_ITERATOR_DONE:
4819 g_value_unset (&data);
4820 gst_iterator_free (pad_it);
4823 GST_DEBUG_OBJECT (element, "free pad name found: '%s'", pad_name);
4830 gst_rtp_bin_request_new_pad (GstElement * element,
4831 GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
4834 GstElementClass *klass;
4837 gchar *pad_name = NULL;
4839 g_return_val_if_fail (templ != NULL, NULL);
4840 g_return_val_if_fail (GST_IS_RTP_BIN (element), NULL);
4842 rtpbin = GST_RTP_BIN (element);
4843 klass = GST_ELEMENT_GET_CLASS (element);
4845 GST_RTP_BIN_LOCK (rtpbin);
4848 /* use a free pad name */
4849 pad_name = gst_rtp_bin_get_free_pad_name (element, templ);
4851 /* use the provided name */
4852 pad_name = g_strdup (name);
4855 GST_DEBUG_OBJECT (rtpbin, "Trying to request a pad with name %s", pad_name);
4857 /* figure out the template */
4858 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink_%u")) {
4859 result = create_recv_rtp (rtpbin, templ, pad_name);
4860 } else if (templ == gst_element_class_get_pad_template (klass,
4861 "recv_rtcp_sink_%u")) {
4862 result = create_recv_rtcp (rtpbin, templ, pad_name);
4863 } else if (templ == gst_element_class_get_pad_template (klass,
4864 "send_rtp_sink_%u")) {
4865 result = create_send_rtp (rtpbin, templ, pad_name);
4866 } else if (templ == gst_element_class_get_pad_template (klass,
4867 "send_rtcp_src_%u")) {
4868 result = create_send_rtcp (rtpbin, templ, pad_name);
4870 goto wrong_template;
4873 GST_RTP_BIN_UNLOCK (rtpbin);
4881 GST_RTP_BIN_UNLOCK (rtpbin);
4882 g_warning ("rtpbin: this is not our template");
4888 gst_rtp_bin_release_pad (GstElement * element, GstPad * pad)
4890 GstRtpBinSession *session;
4893 g_return_if_fail (GST_IS_GHOST_PAD (pad));
4894 g_return_if_fail (GST_IS_RTP_BIN (element));
4896 rtpbin = GST_RTP_BIN (element);
4898 GST_RTP_BIN_LOCK (rtpbin);
4899 GST_DEBUG_OBJECT (rtpbin, "Trying to release pad %s:%s",
4900 GST_DEBUG_PAD_NAME (pad));
4902 if (!(session = find_session_by_pad (rtpbin, pad)))
4905 if (session->recv_rtp_sink_ghost == pad) {
4906 remove_recv_rtp (rtpbin, session);
4907 } else if (session->recv_rtcp_sink_ghost == pad) {
4908 remove_recv_rtcp (rtpbin, session);
4909 } else if (session->send_rtp_sink_ghost == pad) {
4910 remove_send_rtp (rtpbin, session);
4911 } else if (session->send_rtcp_src_ghost == pad) {
4912 remove_rtcp (rtpbin, session);
4915 /* no more request pads, free the complete session */
4916 if (session->recv_rtp_sink_ghost == NULL
4917 && session->recv_rtcp_sink_ghost == NULL
4918 && session->send_rtp_sink_ghost == NULL
4919 && session->send_rtcp_src_ghost == NULL) {
4920 GST_DEBUG_OBJECT (rtpbin, "no more pads for session %p", session);
4921 rtpbin->sessions = g_slist_remove (rtpbin->sessions, session);
4922 free_session (session, rtpbin);
4924 GST_RTP_BIN_UNLOCK (rtpbin);
4931 GST_RTP_BIN_UNLOCK (rtpbin);
4932 g_warning ("rtpbin: %s:%s is not one of our request pads",
4933 GST_DEBUG_PAD_NAME (pad));