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-rtpsession
22 * @see_also: rtpjitterbuffer, rtpbin, rtpptdemux, rtpssrcdemux
24 * The RTP session manager models participants with unique SSRC in an RTP
25 * session. This session can be used to send and receive RTP and RTCP packets.
26 * Based on what REQUEST pads are requested from the session manager, specific
27 * functionality can be activated.
29 * The session manager currently implements RFC 3550 including:
32 * <para>RTP packet validation based on consecutive sequence numbers.</para>
35 * <para>Maintainance of the SSRC participant database.</para>
38 * <para>Keeping per participant statistics based on received RTCP packets.</para>
41 * <para>Scheduling of RR/SR RTCP packets.</para>
44 * <para>Support for multiple sender SSRC.</para>
48 * The rtpsession will not demux packets based on SSRC or payload type, nor will
49 * it correct for packet reordering and jitter. Use #GstRtpsSrcDemux,
50 * #GstRtpPtDemux and GstRtpJitterBuffer in addition to #GstRtpSession to
51 * perform these tasks. It is usually a good idea to use #GstRtpBin, which
52 * combines all these features in one element.
54 * To use #GstRtpSession as an RTP receiver, request a recv_rtp_sink pad, which will
55 * automatically create recv_rtp_src pad. Data received on the recv_rtp_sink pad
56 * will be processed in the session and after being validated forwarded on the
59 * To also use #GstRtpSession as an RTCP receiver, request a recv_rtcp_sink pad,
60 * which will automatically create a sync_src pad. Packets received on the RTCP
61 * pad will be used by the session manager to update the stats and database of
62 * the other participants. SR packets will be forwarded on the sync_src pad
63 * so that they can be used to perform inter-stream synchronisation when needed.
65 * If you want the session manager to generate and send RTCP packets, request
66 * the send_rtcp_src pad. Packet pushed on this pad contain SR/RR RTCP reports
67 * that should be sent to all participants in the session.
69 * To use #GstRtpSession as a sender, request a send_rtp_sink pad, which will
70 * automatically create a send_rtp_src pad. The session manager will
71 * forward the packets on the send_rtp_src pad after updating its internal state.
73 * The session manager needs the clock-rate of the payload types it is handling
74 * and will signal the #GstRtpSession::request-pt-map signal when it needs such a
75 * mapping. One can clear the cached values with the #GstRtpSession::clear-pt-map
79 * <title>Example pipelines</title>
81 * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink rtpsession .recv_rtp_src ! rtptheoradepay ! theoradec ! xvimagesink
82 * ]| Receive theora RTP packets from port 5000 and send them to the depayloader,
83 * decoder and display. Note that the application/x-rtp caps on udpsrc should be
84 * configured based on some negotiation process such as RTSP for this pipeline
87 * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink rtpsession name=session \
88 * .recv_rtp_src ! rtptheoradepay ! theoradec ! xvimagesink \
89 * udpsrc port=5001 caps="application/x-rtcp" ! session.recv_rtcp_sink
90 * ]| Receive theora RTP packets from port 5000 and send them to the depayloader,
91 * decoder and display. Receive RTCP packets from port 5001 and process them in
92 * the session manager.
93 * Note that the application/x-rtp caps on udpsrc should be
94 * configured based on some negotiation process such as RTSP for this pipeline
97 * gst-launch-1.0 videotestsrc ! theoraenc ! rtptheorapay ! .send_rtp_sink rtpsession .send_rtp_src ! udpsink port=5000
98 * ]| Send theora RTP packets through the session manager and out on UDP port
101 * gst-launch-1.0 videotestsrc ! theoraenc ! rtptheorapay ! .send_rtp_sink rtpsession name=session .send_rtp_src \
102 * ! udpsink port=5000 session.send_rtcp_src ! udpsink port=5001
103 * ]| Send theora RTP packets through the session manager and out on UDP port
104 * 5000. Send RTCP packets on port 5001. Note that this pipeline will not preroll
105 * correctly because the second udpsink will not preroll correctly (no RTCP
106 * packets are sent in the PAUSED state). Applications should manually set and
107 * keep (see gst_element_set_locked_state()) the RTCP udpsink to the PLAYING state.
115 #include <gst/rtp/gstrtpbuffer.h>
117 #include <gst/glib-compat-private.h>
119 #include "gstrtpsession.h"
120 #include "rtpsession.h"
122 GST_DEBUG_CATEGORY_STATIC (gst_rtp_session_debug);
123 #define GST_CAT_DEFAULT gst_rtp_session_debug
126 gst_rtp_ntp_time_source_get_type (void)
128 static GType type = 0;
129 static const GEnumValue values[] = {
130 {GST_RTP_NTP_TIME_SOURCE_NTP, "NTP time based on realtime clock", "ntp"},
131 {GST_RTP_NTP_TIME_SOURCE_UNIX, "UNIX time based on realtime clock", "unix"},
132 {GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME,
133 "Running time based on pipeline clock",
135 {GST_RTP_NTP_TIME_SOURCE_CLOCK_TIME, "Pipeline clock time", "clock-time"},
140 type = g_enum_register_static ("GstRtpNtpTimeSource", values);
146 static GstStaticPadTemplate rtpsession_recv_rtp_sink_template =
147 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink",
150 GST_STATIC_CAPS ("application/x-rtp")
153 static GstStaticPadTemplate rtpsession_recv_rtcp_sink_template =
154 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink",
157 GST_STATIC_CAPS ("application/x-rtcp")
160 static GstStaticPadTemplate rtpsession_send_rtp_sink_template =
161 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink",
164 GST_STATIC_CAPS ("application/x-rtp")
168 static GstStaticPadTemplate rtpsession_recv_rtp_src_template =
169 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src",
172 GST_STATIC_CAPS ("application/x-rtp")
175 static GstStaticPadTemplate rtpsession_sync_src_template =
176 GST_STATIC_PAD_TEMPLATE ("sync_src",
179 GST_STATIC_CAPS ("application/x-rtcp")
182 static GstStaticPadTemplate rtpsession_send_rtp_src_template =
183 GST_STATIC_PAD_TEMPLATE ("send_rtp_src",
186 GST_STATIC_CAPS ("application/x-rtp")
189 static GstStaticPadTemplate rtpsession_send_rtcp_src_template =
190 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src",
193 GST_STATIC_CAPS ("application/x-rtcp")
196 /* signals and args */
199 SIGNAL_REQUEST_PT_MAP,
203 SIGNAL_ON_SSRC_COLLISION,
204 SIGNAL_ON_SSRC_VALIDATED,
205 SIGNAL_ON_SSRC_ACTIVE,
208 SIGNAL_ON_BYE_TIMEOUT,
210 SIGNAL_ON_SENDER_TIMEOUT,
211 SIGNAL_ON_NEW_SENDER_SSRC,
212 SIGNAL_ON_SENDER_SSRC_ACTIVE,
216 #define DEFAULT_BANDWIDTH 0
217 #define DEFAULT_RTCP_FRACTION RTP_STATS_RTCP_FRACTION
218 #define DEFAULT_RTCP_RR_BANDWIDTH -1
219 #define DEFAULT_RTCP_RS_BANDWIDTH -1
220 #define DEFAULT_SDES NULL
221 #define DEFAULT_NUM_SOURCES 0
222 #define DEFAULT_NUM_ACTIVE_SOURCES 0
223 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
224 #define DEFAULT_RTCP_MIN_INTERVAL (RTP_STATS_MIN_INTERVAL * GST_SECOND)
225 #define DEFAULT_PROBATION RTP_DEFAULT_PROBATION
226 #define DEFAULT_MAX_DROPOUT_TIME 60000
227 #define DEFAULT_MAX_MISORDER_TIME 2000
228 #define DEFAULT_RTP_PROFILE GST_RTP_PROFILE_AVP
229 #define DEFAULT_NTP_TIME_SOURCE GST_RTP_NTP_TIME_SOURCE_NTP
230 #define DEFAULT_RTCP_SYNC_SEND_TIME TRUE
237 PROP_RTCP_RR_BANDWIDTH,
238 PROP_RTCP_RS_BANDWIDTH,
241 PROP_NUM_ACTIVE_SOURCES,
242 PROP_INTERNAL_SESSION,
243 PROP_USE_PIPELINE_CLOCK,
244 PROP_RTCP_MIN_INTERVAL,
246 PROP_MAX_DROPOUT_TIME,
247 PROP_MAX_MISORDER_TIME,
250 PROP_NTP_TIME_SOURCE,
251 PROP_RTCP_SYNC_SEND_TIME
254 #define GST_RTP_SESSION_LOCK(sess) g_mutex_lock (&(sess)->priv->lock)
255 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock (&(sess)->priv->lock)
257 #define GST_RTP_SESSION_WAIT(sess) g_cond_wait (&(sess)->priv->cond, &(sess)->priv->lock)
258 #define GST_RTP_SESSION_SIGNAL(sess) g_cond_signal (&(sess)->priv->cond)
260 struct _GstRtpSessionPrivate
268 /* thread for sending out RTCP */
270 gboolean stop_thread;
272 gboolean thread_stopped;
278 GstClockTime send_latency;
280 gboolean use_pipeline_clock;
281 GstRtpNtpTimeSource ntp_time_source;
282 gboolean rtcp_sync_send_time;
287 /* callbacks to handle actions from the session manager */
288 static GstFlowReturn gst_rtp_session_process_rtp (RTPSession * sess,
289 RTPSource * src, GstBuffer * buffer, gpointer user_data);
290 static GstFlowReturn gst_rtp_session_send_rtp (RTPSession * sess,
291 RTPSource * src, gpointer data, gpointer user_data);
292 static GstFlowReturn gst_rtp_session_send_rtcp (RTPSession * sess,
293 RTPSource * src, GstBuffer * buffer, gboolean eos, gpointer user_data);
294 static GstFlowReturn gst_rtp_session_sync_rtcp (RTPSession * sess,
295 GstBuffer * buffer, gpointer user_data);
296 static gint gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
298 static void gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data);
299 static void gst_rtp_session_request_key_unit (RTPSession * sess, guint32 ssrc,
300 gboolean all_headers, gpointer user_data);
301 static GstClockTime gst_rtp_session_request_time (RTPSession * session,
303 static void gst_rtp_session_notify_nack (RTPSession * sess,
304 guint16 seqnum, guint16 blp, guint32 ssrc, gpointer user_data);
305 static void gst_rtp_session_reconfigure (RTPSession * sess, gpointer user_data);
306 static void gst_rtp_session_notify_early_rtcp (RTPSession * sess,
309 static RTPSessionCallbacks callbacks = {
310 gst_rtp_session_process_rtp,
311 gst_rtp_session_send_rtp,
312 gst_rtp_session_sync_rtcp,
313 gst_rtp_session_send_rtcp,
314 gst_rtp_session_clock_rate,
315 gst_rtp_session_reconsider,
316 gst_rtp_session_request_key_unit,
317 gst_rtp_session_request_time,
318 gst_rtp_session_notify_nack,
319 gst_rtp_session_reconfigure,
320 gst_rtp_session_notify_early_rtcp
323 /* GObject vmethods */
324 static void gst_rtp_session_finalize (GObject * object);
325 static void gst_rtp_session_set_property (GObject * object, guint prop_id,
326 const GValue * value, GParamSpec * pspec);
327 static void gst_rtp_session_get_property (GObject * object, guint prop_id,
328 GValue * value, GParamSpec * pspec);
330 /* GstElement vmethods */
331 static GstStateChangeReturn gst_rtp_session_change_state (GstElement * element,
332 GstStateChange transition);
333 static GstPad *gst_rtp_session_request_new_pad (GstElement * element,
334 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
335 static void gst_rtp_session_release_pad (GstElement * element, GstPad * pad);
337 static gboolean gst_rtp_session_sink_setcaps (GstPad * pad,
338 GstRtpSession * rtpsession, GstCaps * caps);
339 static gboolean gst_rtp_session_setcaps_send_rtp (GstPad * pad,
340 GstRtpSession * rtpsession, GstCaps * caps);
342 static void gst_rtp_session_clear_pt_map (GstRtpSession * rtpsession);
344 static GstStructure *gst_rtp_session_create_stats (GstRtpSession * rtpsession);
346 static guint gst_rtp_session_signals[LAST_SIGNAL] = { 0 };
349 on_new_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
351 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_NEW_SSRC], 0,
356 on_ssrc_collision (RTPSession * session, RTPSource * src, GstRtpSession * sess)
358 GstPad *send_rtp_sink;
360 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_COLLISION], 0,
363 GST_RTP_SESSION_LOCK (sess);
364 if ((send_rtp_sink = sess->send_rtp_sink))
365 gst_object_ref (send_rtp_sink);
366 GST_RTP_SESSION_UNLOCK (sess);
369 GstStructure *structure;
371 RTPSource *internal_src;
372 guint32 suggested_ssrc;
374 structure = gst_structure_new ("GstRTPCollision", "ssrc", G_TYPE_UINT,
375 (guint) src->ssrc, NULL);
377 /* if there is no source using the suggested ssrc, most probably because
378 * this ssrc has just collided, suggest upstream to use it */
379 suggested_ssrc = rtp_session_suggest_ssrc (session, NULL);
380 internal_src = rtp_session_get_source_by_ssrc (session, suggested_ssrc);
382 gst_structure_set (structure, "suggested-ssrc", G_TYPE_UINT,
383 (guint) suggested_ssrc, NULL);
385 g_object_unref (internal_src);
387 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, structure);
388 gst_pad_push_event (send_rtp_sink, event);
389 gst_object_unref (send_rtp_sink);
394 on_ssrc_validated (RTPSession * session, RTPSource * src, GstRtpSession * sess)
396 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
401 on_ssrc_active (RTPSession * session, RTPSource * src, GstRtpSession * sess)
403 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
408 on_ssrc_sdes (RTPSession * session, RTPSource * src, GstRtpSession * sess)
413 /* convert the new SDES info into a message */
414 RTP_SESSION_LOCK (session);
415 g_object_get (src, "sdes", &s, NULL);
416 RTP_SESSION_UNLOCK (session);
418 m = gst_message_new_custom (GST_MESSAGE_ELEMENT, GST_OBJECT (sess), s);
419 gst_element_post_message (GST_ELEMENT_CAST (sess), m);
421 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_SDES], 0,
426 on_bye_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
428 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_BYE_SSRC], 0,
433 on_bye_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
435 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
440 on_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
442 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_TIMEOUT], 0,
447 on_sender_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
449 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
454 on_new_sender_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
456 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_NEW_SENDER_SSRC], 0,
461 on_sender_ssrc_active (RTPSession * session, RTPSource * src,
462 GstRtpSession * sess)
464 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE], 0,
469 on_notify_stats (RTPSession * session, GParamSpec * spec,
470 GstRtpSession * rtpsession)
472 g_object_notify (G_OBJECT (rtpsession), "stats");
475 #define gst_rtp_session_parent_class parent_class
476 G_DEFINE_TYPE_WITH_PRIVATE (GstRtpSession, gst_rtp_session, GST_TYPE_ELEMENT);
479 gst_rtp_session_class_init (GstRtpSessionClass * klass)
481 GObjectClass *gobject_class;
482 GstElementClass *gstelement_class;
484 gobject_class = (GObjectClass *) klass;
485 gstelement_class = (GstElementClass *) klass;
487 gobject_class->finalize = gst_rtp_session_finalize;
488 gobject_class->set_property = gst_rtp_session_set_property;
489 gobject_class->get_property = gst_rtp_session_get_property;
492 * GstRtpSession::request-pt-map:
493 * @sess: the object which received the signal
496 * Request the payload type as #GstCaps for @pt.
498 gst_rtp_session_signals[SIGNAL_REQUEST_PT_MAP] =
499 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
500 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, request_pt_map),
501 NULL, NULL, g_cclosure_marshal_generic, GST_TYPE_CAPS, 1, G_TYPE_UINT);
503 * GstRtpSession::clear-pt-map:
504 * @sess: the object which received the signal
506 * Clear the cached pt-maps requested with #GstRtpSession::request-pt-map.
508 gst_rtp_session_signals[SIGNAL_CLEAR_PT_MAP] =
509 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
510 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
511 G_STRUCT_OFFSET (GstRtpSessionClass, clear_pt_map),
512 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
515 * GstRtpSession::on-new-ssrc:
516 * @sess: the object which received the signal
519 * Notify of a new SSRC that entered @session.
521 gst_rtp_session_signals[SIGNAL_ON_NEW_SSRC] =
522 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
523 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_new_ssrc),
524 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
526 * GstRtpSession::on-ssrc_collision:
527 * @sess: the object which received the signal
530 * Notify when we have an SSRC collision
532 gst_rtp_session_signals[SIGNAL_ON_SSRC_COLLISION] =
533 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
534 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
535 on_ssrc_collision), NULL, NULL, g_cclosure_marshal_VOID__UINT,
536 G_TYPE_NONE, 1, G_TYPE_UINT);
538 * GstRtpSession::on-ssrc_validated:
539 * @sess: the object which received the signal
542 * Notify of a new SSRC that became validated.
544 gst_rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED] =
545 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
546 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
547 on_ssrc_validated), NULL, NULL, g_cclosure_marshal_VOID__UINT,
548 G_TYPE_NONE, 1, G_TYPE_UINT);
550 * GstRtpSession::on-ssrc-active:
551 * @sess: the object which received the signal
554 * Notify of a SSRC that is active, i.e., sending RTCP.
556 gst_rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE] =
557 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
558 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
559 on_ssrc_active), NULL, NULL, g_cclosure_marshal_VOID__UINT,
560 G_TYPE_NONE, 1, G_TYPE_UINT);
562 * GstRtpSession::on-ssrc-sdes:
563 * @session: the object which received the signal
566 * Notify that a new SDES was received for SSRC.
568 gst_rtp_session_signals[SIGNAL_ON_SSRC_SDES] =
569 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
570 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_ssrc_sdes),
571 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
574 * GstRtpSession::on-bye-ssrc:
575 * @sess: the object which received the signal
578 * Notify of an SSRC that became inactive because of a BYE packet.
580 gst_rtp_session_signals[SIGNAL_ON_BYE_SSRC] =
581 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
582 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_bye_ssrc),
583 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
585 * GstRtpSession::on-bye-timeout:
586 * @sess: the object which received the signal
589 * Notify of an SSRC that has timed out because of BYE
591 gst_rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT] =
592 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
593 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_bye_timeout),
594 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
596 * GstRtpSession::on-timeout:
597 * @sess: the object which received the signal
600 * Notify of an SSRC that has timed out
602 gst_rtp_session_signals[SIGNAL_ON_TIMEOUT] =
603 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
604 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_timeout),
605 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
607 * GstRtpSession::on-sender-timeout:
608 * @sess: the object which received the signal
611 * Notify of a sender SSRC that has timed out and became a receiver
613 gst_rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT] =
614 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
615 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
616 on_sender_timeout), NULL, NULL, g_cclosure_marshal_VOID__UINT,
617 G_TYPE_NONE, 1, G_TYPE_UINT);
620 * GstRtpSession::on-new-sender-ssrc:
621 * @sess: the object which received the signal
622 * @ssrc: the sender SSRC
624 * Notify of a new sender SSRC that entered @session.
628 gst_rtp_session_signals[SIGNAL_ON_NEW_SENDER_SSRC] =
629 g_signal_new ("on-new-sender-ssrc", G_TYPE_FROM_CLASS (klass),
630 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_new_ssrc),
631 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
634 * GstRtpSession::on-sender-ssrc-active:
635 * @sess: the object which received the signal
636 * @ssrc: the sender SSRC
638 * Notify of a sender SSRC that is active, i.e., sending RTCP.
642 gst_rtp_session_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE] =
643 g_signal_new ("on-sender-ssrc-active", G_TYPE_FROM_CLASS (klass),
644 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
645 on_ssrc_active), NULL, NULL, g_cclosure_marshal_VOID__UINT,
646 G_TYPE_NONE, 1, G_TYPE_UINT);
648 g_object_class_install_property (gobject_class, PROP_BANDWIDTH,
649 g_param_spec_double ("bandwidth", "Bandwidth",
650 "The bandwidth of the session in bytes per second (0 for auto-discover)",
651 0.0, G_MAXDOUBLE, DEFAULT_BANDWIDTH,
652 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
654 g_object_class_install_property (gobject_class, PROP_RTCP_FRACTION,
655 g_param_spec_double ("rtcp-fraction", "RTCP Fraction",
656 "The RTCP bandwidth of the session in bytes per second "
657 "(or as a real fraction of the RTP bandwidth if < 1.0)",
658 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION,
659 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
661 g_object_class_install_property (gobject_class, PROP_RTCP_RR_BANDWIDTH,
662 g_param_spec_int ("rtcp-rr-bandwidth", "RTCP RR bandwidth",
663 "The RTCP bandwidth used for receivers in bytes per second (-1 = default)",
664 -1, G_MAXINT, DEFAULT_RTCP_RR_BANDWIDTH,
665 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
667 g_object_class_install_property (gobject_class, PROP_RTCP_RS_BANDWIDTH,
668 g_param_spec_int ("rtcp-rs-bandwidth", "RTCP RS bandwidth",
669 "The RTCP bandwidth used for senders in bytes per second (-1 = default)",
670 -1, G_MAXINT, DEFAULT_RTCP_RS_BANDWIDTH,
671 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
673 g_object_class_install_property (gobject_class, PROP_SDES,
674 g_param_spec_boxed ("sdes", "SDES",
675 "The SDES items of this session",
676 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
678 g_object_class_install_property (gobject_class, PROP_NUM_SOURCES,
679 g_param_spec_uint ("num-sources", "Num Sources",
680 "The number of sources in the session", 0, G_MAXUINT,
681 DEFAULT_NUM_SOURCES, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
683 g_object_class_install_property (gobject_class, PROP_NUM_ACTIVE_SOURCES,
684 g_param_spec_uint ("num-active-sources", "Num Active Sources",
685 "The number of active sources in the session", 0, G_MAXUINT,
686 DEFAULT_NUM_ACTIVE_SOURCES,
687 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
689 g_object_class_install_property (gobject_class, PROP_INTERNAL_SESSION,
690 g_param_spec_object ("internal-session", "Internal Session",
691 "The internal RTPSession object", RTP_TYPE_SESSION,
692 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
694 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
695 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
696 "Use the pipeline running-time to set the NTP time in the RTCP SR messages "
697 "(DEPRECATED: Use ntp-time-source property)",
698 DEFAULT_USE_PIPELINE_CLOCK,
699 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
701 g_object_class_install_property (gobject_class, PROP_RTCP_MIN_INTERVAL,
702 g_param_spec_uint64 ("rtcp-min-interval", "Minimum RTCP interval",
703 "Minimum interval between Regular RTCP packet (in ns)",
704 0, G_MAXUINT64, DEFAULT_RTCP_MIN_INTERVAL,
705 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
707 g_object_class_install_property (gobject_class, PROP_PROBATION,
708 g_param_spec_uint ("probation", "Number of probations",
709 "Consecutive packet sequence numbers to accept the source",
710 0, G_MAXUINT, DEFAULT_PROBATION,
711 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
713 g_object_class_install_property (gobject_class, PROP_MAX_DROPOUT_TIME,
714 g_param_spec_uint ("max-dropout-time", "Max dropout time",
715 "The maximum time (milliseconds) of missing packets tolerated.",
716 0, G_MAXUINT, DEFAULT_MAX_DROPOUT_TIME,
717 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
719 g_object_class_install_property (gobject_class, PROP_MAX_MISORDER_TIME,
720 g_param_spec_uint ("max-misorder-time", "Max misorder time",
721 "The maximum time (milliseconds) of misordered packets tolerated.",
722 0, G_MAXUINT, DEFAULT_MAX_MISORDER_TIME,
723 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
726 * GstRtpSession::stats:
728 * Various session statistics. This property returns a GstStructure
729 * with name application/x-rtp-session-stats with the following fields:
731 * "rtx-count" G_TYPE_UINT The number of retransmission events
732 * received from downstream (in receiver mode)
733 * "rtx-drop-count" G_TYPE_UINT The number of retransmission events
734 * dropped (due to bandwidth constraints)
735 * "sent-nack-count" G_TYPE_UINT Number of NACKs sent
736 * "recv-nack-count" G_TYPE_UINT Number of NACKs received
737 * "source-stats" G_TYPE_BOXED GValueArray of #RTPSource::stats for all
738 * RTP sources (Since 1.8)
742 g_object_class_install_property (gobject_class, PROP_STATS,
743 g_param_spec_boxed ("stats", "Statistics",
744 "Various statistics", GST_TYPE_STRUCTURE,
745 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
747 g_object_class_install_property (gobject_class, PROP_RTP_PROFILE,
748 g_param_spec_enum ("rtp-profile", "RTP Profile",
749 "RTP profile to use", GST_TYPE_RTP_PROFILE, DEFAULT_RTP_PROFILE,
750 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
752 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
753 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
754 "NTP time source for RTCP packets",
755 gst_rtp_ntp_time_source_get_type (), DEFAULT_NTP_TIME_SOURCE,
756 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
758 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_SEND_TIME,
759 g_param_spec_boolean ("rtcp-sync-send-time", "RTCP Sync Send Time",
760 "Use send time or capture time for RTCP sync "
761 "(TRUE = send time, FALSE = capture time)",
762 DEFAULT_RTCP_SYNC_SEND_TIME,
763 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
765 gstelement_class->change_state =
766 GST_DEBUG_FUNCPTR (gst_rtp_session_change_state);
767 gstelement_class->request_new_pad =
768 GST_DEBUG_FUNCPTR (gst_rtp_session_request_new_pad);
769 gstelement_class->release_pad =
770 GST_DEBUG_FUNCPTR (gst_rtp_session_release_pad);
772 klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_session_clear_pt_map);
775 gst_element_class_add_static_pad_template (gstelement_class,
776 &rtpsession_recv_rtp_sink_template);
777 gst_element_class_add_static_pad_template (gstelement_class,
778 &rtpsession_recv_rtcp_sink_template);
779 gst_element_class_add_static_pad_template (gstelement_class,
780 &rtpsession_send_rtp_sink_template);
783 gst_element_class_add_static_pad_template (gstelement_class,
784 &rtpsession_recv_rtp_src_template);
785 gst_element_class_add_static_pad_template (gstelement_class,
786 &rtpsession_sync_src_template);
787 gst_element_class_add_static_pad_template (gstelement_class,
788 &rtpsession_send_rtp_src_template);
789 gst_element_class_add_static_pad_template (gstelement_class,
790 &rtpsession_send_rtcp_src_template);
792 gst_element_class_set_static_metadata (gstelement_class, "RTP Session",
793 "Filter/Network/RTP",
794 "Implement an RTP session", "Wim Taymans <wim.taymans@gmail.com>");
796 GST_DEBUG_CATEGORY_INIT (gst_rtp_session_debug,
797 "rtpsession", 0, "RTP Session");
801 gst_rtp_session_init (GstRtpSession * rtpsession)
803 rtpsession->priv = gst_rtp_session_get_instance_private (rtpsession);
804 g_mutex_init (&rtpsession->priv->lock);
805 g_cond_init (&rtpsession->priv->cond);
806 rtpsession->priv->sysclock = gst_system_clock_obtain ();
807 rtpsession->priv->session = rtp_session_new ();
808 rtpsession->priv->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
809 rtpsession->priv->rtcp_sync_send_time = DEFAULT_RTCP_SYNC_SEND_TIME;
811 /* configure callbacks */
812 rtp_session_set_callbacks (rtpsession->priv->session, &callbacks, rtpsession);
813 /* configure signals */
814 g_signal_connect (rtpsession->priv->session, "on-new-ssrc",
815 (GCallback) on_new_ssrc, rtpsession);
816 g_signal_connect (rtpsession->priv->session, "on-ssrc-collision",
817 (GCallback) on_ssrc_collision, rtpsession);
818 g_signal_connect (rtpsession->priv->session, "on-ssrc-validated",
819 (GCallback) on_ssrc_validated, rtpsession);
820 g_signal_connect (rtpsession->priv->session, "on-ssrc-active",
821 (GCallback) on_ssrc_active, rtpsession);
822 g_signal_connect (rtpsession->priv->session, "on-ssrc-sdes",
823 (GCallback) on_ssrc_sdes, rtpsession);
824 g_signal_connect (rtpsession->priv->session, "on-bye-ssrc",
825 (GCallback) on_bye_ssrc, rtpsession);
826 g_signal_connect (rtpsession->priv->session, "on-bye-timeout",
827 (GCallback) on_bye_timeout, rtpsession);
828 g_signal_connect (rtpsession->priv->session, "on-timeout",
829 (GCallback) on_timeout, rtpsession);
830 g_signal_connect (rtpsession->priv->session, "on-sender-timeout",
831 (GCallback) on_sender_timeout, rtpsession);
832 g_signal_connect (rtpsession->priv->session, "on-new-sender-ssrc",
833 (GCallback) on_new_sender_ssrc, rtpsession);
834 g_signal_connect (rtpsession->priv->session, "on-sender-ssrc-active",
835 (GCallback) on_sender_ssrc_active, rtpsession);
836 g_signal_connect (rtpsession->priv->session, "notify::stats",
837 (GCallback) on_notify_stats, rtpsession);
838 rtpsession->priv->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
839 (GDestroyNotify) gst_caps_unref);
841 rtpsession->recv_rtcp_segment_seqnum = GST_SEQNUM_INVALID;
843 gst_segment_init (&rtpsession->recv_rtp_seg, GST_FORMAT_UNDEFINED);
844 gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
846 rtpsession->priv->thread_stopped = TRUE;
848 rtpsession->priv->rtx_count = 0;
850 rtpsession->priv->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
854 gst_rtp_session_finalize (GObject * object)
856 GstRtpSession *rtpsession;
858 rtpsession = GST_RTP_SESSION (object);
860 g_hash_table_destroy (rtpsession->priv->ptmap);
861 g_mutex_clear (&rtpsession->priv->lock);
862 g_cond_clear (&rtpsession->priv->cond);
863 g_object_unref (rtpsession->priv->sysclock);
864 g_object_unref (rtpsession->priv->session);
866 G_OBJECT_CLASS (parent_class)->finalize (object);
870 gst_rtp_session_set_property (GObject * object, guint prop_id,
871 const GValue * value, GParamSpec * pspec)
873 GstRtpSession *rtpsession;
874 GstRtpSessionPrivate *priv;
876 rtpsession = GST_RTP_SESSION (object);
877 priv = rtpsession->priv;
881 g_object_set_property (G_OBJECT (priv->session), "bandwidth", value);
883 case PROP_RTCP_FRACTION:
884 g_object_set_property (G_OBJECT (priv->session), "rtcp-fraction", value);
886 case PROP_RTCP_RR_BANDWIDTH:
887 g_object_set_property (G_OBJECT (priv->session), "rtcp-rr-bandwidth",
890 case PROP_RTCP_RS_BANDWIDTH:
891 g_object_set_property (G_OBJECT (priv->session), "rtcp-rs-bandwidth",
895 rtp_session_set_sdes_struct (priv->session, g_value_get_boxed (value));
897 case PROP_USE_PIPELINE_CLOCK:
898 priv->use_pipeline_clock = g_value_get_boolean (value);
900 case PROP_RTCP_MIN_INTERVAL:
901 g_object_set_property (G_OBJECT (priv->session), "rtcp-min-interval",
905 g_object_set_property (G_OBJECT (priv->session), "probation", value);
907 case PROP_MAX_DROPOUT_TIME:
908 g_object_set_property (G_OBJECT (priv->session), "max-dropout-time",
911 case PROP_MAX_MISORDER_TIME:
912 g_object_set_property (G_OBJECT (priv->session), "max-misorder-time",
915 case PROP_RTP_PROFILE:
916 g_object_set_property (G_OBJECT (priv->session), "rtp-profile", value);
918 case PROP_NTP_TIME_SOURCE:
919 priv->ntp_time_source = g_value_get_enum (value);
921 case PROP_RTCP_SYNC_SEND_TIME:
922 priv->rtcp_sync_send_time = g_value_get_boolean (value);
925 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
931 gst_rtp_session_get_property (GObject * object, guint prop_id,
932 GValue * value, GParamSpec * pspec)
934 GstRtpSession *rtpsession;
935 GstRtpSessionPrivate *priv;
937 rtpsession = GST_RTP_SESSION (object);
938 priv = rtpsession->priv;
942 g_object_get_property (G_OBJECT (priv->session), "bandwidth", value);
944 case PROP_RTCP_FRACTION:
945 g_object_get_property (G_OBJECT (priv->session), "rtcp-fraction", value);
947 case PROP_RTCP_RR_BANDWIDTH:
948 g_object_get_property (G_OBJECT (priv->session), "rtcp-rr-bandwidth",
951 case PROP_RTCP_RS_BANDWIDTH:
952 g_object_get_property (G_OBJECT (priv->session), "rtcp-rs-bandwidth",
956 g_value_take_boxed (value, rtp_session_get_sdes_struct (priv->session));
958 case PROP_NUM_SOURCES:
959 g_value_set_uint (value, rtp_session_get_num_sources (priv->session));
961 case PROP_NUM_ACTIVE_SOURCES:
962 g_value_set_uint (value,
963 rtp_session_get_num_active_sources (priv->session));
965 case PROP_INTERNAL_SESSION:
966 g_value_set_object (value, priv->session);
968 case PROP_USE_PIPELINE_CLOCK:
969 g_value_set_boolean (value, priv->use_pipeline_clock);
971 case PROP_RTCP_MIN_INTERVAL:
972 g_object_get_property (G_OBJECT (priv->session), "rtcp-min-interval",
976 g_object_get_property (G_OBJECT (priv->session), "probation", value);
978 case PROP_MAX_DROPOUT_TIME:
979 g_object_get_property (G_OBJECT (priv->session), "max-dropout-time",
982 case PROP_MAX_MISORDER_TIME:
983 g_object_get_property (G_OBJECT (priv->session), "max-misorder-time",
987 g_value_take_boxed (value, gst_rtp_session_create_stats (rtpsession));
989 case PROP_RTP_PROFILE:
990 g_object_get_property (G_OBJECT (priv->session), "rtp-profile", value);
992 case PROP_NTP_TIME_SOURCE:
993 g_value_set_enum (value, priv->ntp_time_source);
995 case PROP_RTCP_SYNC_SEND_TIME:
996 g_value_set_boolean (value, priv->rtcp_sync_send_time);
999 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1004 static GstStructure *
1005 gst_rtp_session_create_stats (GstRtpSession * rtpsession)
1009 g_object_get (rtpsession->priv->session, "stats", &s, NULL);
1010 gst_structure_set (s, "rtx-count", G_TYPE_UINT, rtpsession->priv->rtx_count,
1017 get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
1018 guint64 * ntpnstime)
1022 GstClockTime base_time, rt, clock_time;
1024 GST_OBJECT_LOCK (rtpsession);
1025 if ((clock = GST_ELEMENT_CLOCK (rtpsession))) {
1026 base_time = GST_ELEMENT_CAST (rtpsession)->base_time;
1027 gst_object_ref (clock);
1028 GST_OBJECT_UNLOCK (rtpsession);
1030 /* get current clock time and convert to running time */
1031 clock_time = gst_clock_get_time (clock);
1032 rt = clock_time - base_time;
1034 if (rtpsession->priv->use_pipeline_clock) {
1036 /* add constant to convert from 1970 based time to 1900 based time */
1037 ntpns += (2208988800LL * GST_SECOND);
1039 switch (rtpsession->priv->ntp_time_source) {
1040 case GST_RTP_NTP_TIME_SOURCE_NTP:
1041 case GST_RTP_NTP_TIME_SOURCE_UNIX:{
1044 /* get current NTP time */
1045 g_get_current_time (¤t);
1046 ntpns = GST_TIMEVAL_TO_TIME (current);
1048 /* add constant to convert from 1970 based time to 1900 based time */
1049 if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
1050 ntpns += (2208988800LL * GST_SECOND);
1053 case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
1056 case GST_RTP_NTP_TIME_SOURCE_CLOCK_TIME:
1061 g_assert_not_reached ();
1066 gst_object_unref (clock);
1068 GST_OBJECT_UNLOCK (rtpsession);
1078 /* must be called with GST_RTP_SESSION_LOCK */
1080 signal_waiting_rtcp_thread_unlocked (GstRtpSession * rtpsession)
1082 if (rtpsession->priv->wait_send) {
1083 GST_LOG_OBJECT (rtpsession, "signal RTCP thread");
1084 rtpsession->priv->wait_send = FALSE;
1085 GST_RTP_SESSION_SIGNAL (rtpsession);
1090 rtcp_thread (GstRtpSession * rtpsession)
1093 GstClockTime current_time;
1094 GstClockTime next_timeout;
1096 GstClockTime running_time;
1097 RTPSession *session;
1100 GST_DEBUG_OBJECT (rtpsession, "entering RTCP thread");
1102 GST_RTP_SESSION_LOCK (rtpsession);
1104 while (rtpsession->priv->wait_send) {
1105 GST_LOG_OBJECT (rtpsession, "waiting for getting started");
1106 GST_RTP_SESSION_WAIT (rtpsession);
1107 GST_LOG_OBJECT (rtpsession, "signaled...");
1110 sysclock = rtpsession->priv->sysclock;
1111 current_time = gst_clock_get_time (sysclock);
1113 session = rtpsession->priv->session;
1115 GST_DEBUG_OBJECT (rtpsession, "starting at %" GST_TIME_FORMAT,
1116 GST_TIME_ARGS (current_time));
1117 session->start_time = current_time;
1119 while (!rtpsession->priv->stop_thread) {
1122 /* get initial estimate */
1123 next_timeout = rtp_session_next_timeout (session, current_time);
1125 GST_DEBUG_OBJECT (rtpsession, "next check time %" GST_TIME_FORMAT,
1126 GST_TIME_ARGS (next_timeout));
1128 /* leave if no more timeouts, the session ended */
1129 if (next_timeout == GST_CLOCK_TIME_NONE)
1132 id = rtpsession->priv->id =
1133 gst_clock_new_single_shot_id (sysclock, next_timeout);
1134 GST_RTP_SESSION_UNLOCK (rtpsession);
1136 res = gst_clock_id_wait (id, NULL);
1138 GST_RTP_SESSION_LOCK (rtpsession);
1139 gst_clock_id_unref (id);
1140 rtpsession->priv->id = NULL;
1142 if (rtpsession->priv->stop_thread)
1145 /* update current time */
1146 current_time = gst_clock_get_time (sysclock);
1148 /* get current NTP time */
1149 get_current_times (rtpsession, &running_time, &ntpnstime);
1151 /* we get unlocked because we need to perform reconsideration, don't perform
1152 * the timeout but get a new reporting estimate. */
1153 GST_DEBUG_OBJECT (rtpsession, "unlocked %d, current %" GST_TIME_FORMAT,
1154 res, GST_TIME_ARGS (current_time));
1156 /* perform actions, we ignore result. Release lock because it might push. */
1157 GST_RTP_SESSION_UNLOCK (rtpsession);
1158 rtp_session_on_timeout (session, current_time, ntpnstime, running_time);
1159 GST_RTP_SESSION_LOCK (rtpsession);
1161 /* mark the thread as stopped now */
1162 rtpsession->priv->thread_stopped = TRUE;
1163 GST_RTP_SESSION_UNLOCK (rtpsession);
1165 GST_DEBUG_OBJECT (rtpsession, "leaving RTCP thread");
1169 start_rtcp_thread (GstRtpSession * rtpsession)
1171 GError *error = NULL;
1174 GST_DEBUG_OBJECT (rtpsession, "starting RTCP thread");
1176 GST_RTP_SESSION_LOCK (rtpsession);
1177 rtpsession->priv->stop_thread = FALSE;
1178 if (rtpsession->priv->thread_stopped) {
1179 /* if the thread stopped, and we still have a handle to the thread, join it
1180 * now. We can safely join with the lock held, the thread will not take it
1182 if (rtpsession->priv->thread)
1183 g_thread_join (rtpsession->priv->thread);
1184 /* only create a new thread if the old one was stopped. Otherwise we can
1185 * just reuse the currently running one. */
1186 rtpsession->priv->thread = g_thread_try_new ("rtpsession-rtcp-thread",
1187 (GThreadFunc) rtcp_thread, rtpsession, &error);
1188 rtpsession->priv->thread_stopped = FALSE;
1190 GST_RTP_SESSION_UNLOCK (rtpsession);
1192 if (error != NULL) {
1194 GST_DEBUG_OBJECT (rtpsession, "failed to start thread, %s", error->message);
1195 g_error_free (error);
1203 stop_rtcp_thread (GstRtpSession * rtpsession)
1205 GST_DEBUG_OBJECT (rtpsession, "stopping RTCP thread");
1207 GST_RTP_SESSION_LOCK (rtpsession);
1208 rtpsession->priv->stop_thread = TRUE;
1209 signal_waiting_rtcp_thread_unlocked (rtpsession);
1210 if (rtpsession->priv->id)
1211 gst_clock_id_unschedule (rtpsession->priv->id);
1212 GST_RTP_SESSION_UNLOCK (rtpsession);
1216 join_rtcp_thread (GstRtpSession * rtpsession)
1218 GST_RTP_SESSION_LOCK (rtpsession);
1219 /* don't try to join when we have no thread */
1220 if (rtpsession->priv->thread != NULL) {
1221 GST_DEBUG_OBJECT (rtpsession, "joining RTCP thread");
1222 GST_RTP_SESSION_UNLOCK (rtpsession);
1224 g_thread_join (rtpsession->priv->thread);
1226 GST_RTP_SESSION_LOCK (rtpsession);
1227 /* after the join, take the lock and clear the thread structure. The caller
1228 * is supposed to not concurrently call start and join. */
1229 rtpsession->priv->thread = NULL;
1231 GST_RTP_SESSION_UNLOCK (rtpsession);
1234 static GstStateChangeReturn
1235 gst_rtp_session_change_state (GstElement * element, GstStateChange transition)
1237 GstStateChangeReturn res;
1238 GstRtpSession *rtpsession;
1240 rtpsession = GST_RTP_SESSION (element);
1242 switch (transition) {
1243 case GST_STATE_CHANGE_NULL_TO_READY:
1245 case GST_STATE_CHANGE_READY_TO_PAUSED:
1246 GST_RTP_SESSION_LOCK (rtpsession);
1247 rtpsession->priv->wait_send = TRUE;
1248 GST_RTP_SESSION_UNLOCK (rtpsession);
1250 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1252 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1253 case GST_STATE_CHANGE_PAUSED_TO_READY:
1254 /* no need to join yet, we might want to continue later. Also, the
1255 * dataflow could block downstream so that a join could just block
1257 stop_rtcp_thread (rtpsession);
1263 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1265 switch (transition) {
1266 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1267 if (!start_rtcp_thread (rtpsession))
1270 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1272 case GST_STATE_CHANGE_PAUSED_TO_READY:
1273 /* downstream is now releasing the dataflow and we can join. */
1274 join_rtcp_thread (rtpsession);
1275 rtp_session_reset (rtpsession->priv->session);
1277 case GST_STATE_CHANGE_READY_TO_NULL:
1287 return GST_STATE_CHANGE_FAILURE;
1292 return_true (gpointer key, gpointer value, gpointer user_data)
1298 gst_rtp_session_clear_pt_map (GstRtpSession * rtpsession)
1300 g_hash_table_foreach_remove (rtpsession->priv->ptmap, return_true, NULL);
1303 /* called when the session manager has an RTP packet or a list of packets
1304 * ready for further processing */
1305 static GstFlowReturn
1306 gst_rtp_session_process_rtp (RTPSession * sess, RTPSource * src,
1307 GstBuffer * buffer, gpointer user_data)
1309 GstFlowReturn result;
1310 GstRtpSession *rtpsession;
1313 rtpsession = GST_RTP_SESSION (user_data);
1315 GST_RTP_SESSION_LOCK (rtpsession);
1316 if ((rtp_src = rtpsession->recv_rtp_src))
1317 gst_object_ref (rtp_src);
1318 GST_RTP_SESSION_UNLOCK (rtpsession);
1321 GST_LOG_OBJECT (rtpsession, "pushing received RTP packet");
1322 result = gst_pad_push (rtp_src, buffer);
1323 gst_object_unref (rtp_src);
1325 GST_DEBUG_OBJECT (rtpsession, "dropping received RTP packet");
1326 gst_buffer_unref (buffer);
1327 result = GST_FLOW_OK;
1332 /* called when the session manager has an RTP packet ready for further
1334 static GstFlowReturn
1335 gst_rtp_session_send_rtp (RTPSession * sess, RTPSource * src,
1336 gpointer data, gpointer user_data)
1338 GstFlowReturn result;
1339 GstRtpSession *rtpsession;
1342 rtpsession = GST_RTP_SESSION (user_data);
1344 GST_RTP_SESSION_LOCK (rtpsession);
1345 if ((rtp_src = rtpsession->send_rtp_src))
1346 gst_object_ref (rtp_src);
1347 signal_waiting_rtcp_thread_unlocked (rtpsession);
1348 GST_RTP_SESSION_UNLOCK (rtpsession);
1351 if (GST_IS_BUFFER (data)) {
1352 GST_LOG_OBJECT (rtpsession, "sending RTP packet");
1353 result = gst_pad_push (rtp_src, GST_BUFFER_CAST (data));
1355 GST_LOG_OBJECT (rtpsession, "sending RTP list");
1356 result = gst_pad_push_list (rtp_src, GST_BUFFER_LIST_CAST (data));
1358 gst_object_unref (rtp_src);
1360 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
1361 result = GST_FLOW_OK;
1367 do_rtcp_events (GstRtpSession * rtpsession, GstPad * srcpad)
1373 gboolean have_group_id;
1377 g_strdup_printf ("%08x%08x%08x%08x", g_random_int (), g_random_int (),
1378 g_random_int (), g_random_int ());
1380 GST_RTP_SESSION_LOCK (rtpsession);
1381 if (rtpsession->recv_rtp_sink) {
1383 gst_pad_get_sticky_event (rtpsession->recv_rtp_sink,
1384 GST_EVENT_STREAM_START, 0);
1386 if (gst_event_parse_group_id (event, &group_id))
1387 have_group_id = TRUE;
1389 have_group_id = FALSE;
1390 gst_event_unref (event);
1392 have_group_id = TRUE;
1393 group_id = gst_util_group_id_next ();
1396 have_group_id = TRUE;
1397 group_id = gst_util_group_id_next ();
1399 GST_RTP_SESSION_UNLOCK (rtpsession);
1401 event = gst_event_new_stream_start (stream_id);
1402 rtpsession->recv_rtcp_segment_seqnum = gst_event_get_seqnum (event);
1403 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1405 gst_event_set_group_id (event, group_id);
1406 gst_pad_push_event (srcpad, event);
1409 caps = gst_caps_new_empty_simple ("application/x-rtcp");
1410 gst_pad_set_caps (srcpad, caps);
1411 gst_caps_unref (caps);
1413 gst_segment_init (&seg, GST_FORMAT_TIME);
1414 event = gst_event_new_segment (&seg);
1415 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1416 gst_pad_push_event (srcpad, event);
1419 /* called when the session manager has an RTCP packet ready for further
1420 * sending. The eos flag is set when an EOS event should be sent downstream as
1422 static GstFlowReturn
1423 gst_rtp_session_send_rtcp (RTPSession * sess, RTPSource * src,
1424 GstBuffer * buffer, gboolean all_sources_bye, gpointer user_data)
1426 GstFlowReturn result;
1427 GstRtpSession *rtpsession;
1430 rtpsession = GST_RTP_SESSION (user_data);
1432 GST_RTP_SESSION_LOCK (rtpsession);
1433 if (rtpsession->priv->stop_thread)
1436 if ((rtcp_src = rtpsession->send_rtcp_src)) {
1437 gst_object_ref (rtcp_src);
1438 GST_RTP_SESSION_UNLOCK (rtpsession);
1440 /* set rtcp caps on output pad */
1441 if (!gst_pad_has_current_caps (rtcp_src))
1442 do_rtcp_events (rtpsession, rtcp_src);
1444 GST_LOG_OBJECT (rtpsession, "sending RTCP");
1445 result = gst_pad_push (rtcp_src, buffer);
1447 /* Forward send an EOS on the RTCP sink if we received an EOS on the
1448 * send_rtp_sink. We don't need to check the recv_rtp_sink since in this
1449 * case the EOS event would already have been sent */
1450 if (all_sources_bye && rtpsession->send_rtp_sink &&
1451 GST_PAD_IS_EOS (rtpsession->send_rtp_sink)) {
1454 GST_LOG_OBJECT (rtpsession, "sending EOS");
1456 event = gst_event_new_eos ();
1457 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1458 gst_pad_push_event (rtcp_src, event);
1460 gst_object_unref (rtcp_src);
1462 GST_RTP_SESSION_UNLOCK (rtpsession);
1464 GST_DEBUG_OBJECT (rtpsession, "not sending RTCP, no output pad");
1465 gst_buffer_unref (buffer);
1466 result = GST_FLOW_OK;
1473 GST_DEBUG_OBJECT (rtpsession, "we are stopping");
1474 gst_buffer_unref (buffer);
1475 GST_RTP_SESSION_UNLOCK (rtpsession);
1480 /* called when the session manager has an SR RTCP packet ready for handling
1481 * inter stream synchronisation */
1482 static GstFlowReturn
1483 gst_rtp_session_sync_rtcp (RTPSession * sess,
1484 GstBuffer * buffer, gpointer user_data)
1486 GstFlowReturn result;
1487 GstRtpSession *rtpsession;
1490 rtpsession = GST_RTP_SESSION (user_data);
1492 GST_RTP_SESSION_LOCK (rtpsession);
1493 if (rtpsession->priv->stop_thread)
1496 if ((sync_src = rtpsession->sync_src)) {
1497 gst_object_ref (sync_src);
1498 GST_RTP_SESSION_UNLOCK (rtpsession);
1500 /* set rtcp caps on output pad, this happens
1501 * when we receive RTCP muxed with RTP according
1502 * to RFC5761. Otherwise we would have forwarded
1503 * the events from the recv_rtcp_sink pad already
1505 if (!gst_pad_has_current_caps (sync_src))
1506 do_rtcp_events (rtpsession, sync_src);
1508 GST_LOG_OBJECT (rtpsession, "sending Sync RTCP");
1509 result = gst_pad_push (sync_src, buffer);
1510 gst_object_unref (sync_src);
1512 GST_RTP_SESSION_UNLOCK (rtpsession);
1514 GST_DEBUG_OBJECT (rtpsession, "not sending Sync RTCP, no output pad");
1515 gst_buffer_unref (buffer);
1516 result = GST_FLOW_OK;
1523 GST_DEBUG_OBJECT (rtpsession, "we are stopping");
1524 gst_buffer_unref (buffer);
1525 GST_RTP_SESSION_UNLOCK (rtpsession);
1531 gst_rtp_session_cache_caps (GstRtpSession * rtpsession, GstCaps * caps)
1533 GstRtpSessionPrivate *priv;
1534 const GstStructure *s;
1537 priv = rtpsession->priv;
1539 GST_DEBUG_OBJECT (rtpsession, "parsing caps");
1541 s = gst_caps_get_structure (caps, 0);
1542 if (!gst_structure_get_int (s, "payload", &payload))
1545 if (g_hash_table_lookup (priv->ptmap, GINT_TO_POINTER (payload)))
1548 g_hash_table_insert (priv->ptmap, GINT_TO_POINTER (payload),
1549 gst_caps_ref (caps));
1553 gst_rtp_session_get_caps_for_pt (GstRtpSession * rtpsession, guint payload)
1555 GstCaps *caps = NULL;
1556 GValue args[2] = { {0}, {0} };
1559 GST_RTP_SESSION_LOCK (rtpsession);
1560 caps = g_hash_table_lookup (rtpsession->priv->ptmap,
1561 GINT_TO_POINTER (payload));
1563 gst_caps_ref (caps);
1567 /* not found in the cache, try to get it with a signal */
1568 g_value_init (&args[0], GST_TYPE_ELEMENT);
1569 g_value_set_object (&args[0], rtpsession);
1570 g_value_init (&args[1], G_TYPE_UINT);
1571 g_value_set_uint (&args[1], payload);
1573 g_value_init (&ret, GST_TYPE_CAPS);
1574 g_value_set_boxed (&ret, NULL);
1576 GST_RTP_SESSION_UNLOCK (rtpsession);
1578 g_signal_emitv (args, gst_rtp_session_signals[SIGNAL_REQUEST_PT_MAP], 0,
1581 GST_RTP_SESSION_LOCK (rtpsession);
1583 g_value_unset (&args[0]);
1584 g_value_unset (&args[1]);
1585 caps = (GstCaps *) g_value_dup_boxed (&ret);
1586 g_value_unset (&ret);
1590 gst_rtp_session_cache_caps (rtpsession, caps);
1593 GST_RTP_SESSION_UNLOCK (rtpsession);
1599 GST_DEBUG_OBJECT (rtpsession, "could not get caps");
1604 /* called when the session manager needs the clock rate */
1606 gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
1610 GstRtpSession *rtpsession;
1612 const GstStructure *s;
1614 rtpsession = GST_RTP_SESSION_CAST (user_data);
1616 caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload);
1621 s = gst_caps_get_structure (caps, 0);
1622 if (!gst_structure_get_int (s, "clock-rate", &result))
1625 gst_caps_unref (caps);
1627 GST_DEBUG_OBJECT (rtpsession, "parsed clock-rate %d", result);
1636 gst_caps_unref (caps);
1637 GST_DEBUG_OBJECT (rtpsession, "No clock-rate in caps!");
1642 /* called when the session manager asks us to reconsider the timeout */
1644 gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data)
1646 GstRtpSession *rtpsession;
1648 rtpsession = GST_RTP_SESSION_CAST (user_data);
1650 GST_RTP_SESSION_LOCK (rtpsession);
1651 GST_DEBUG_OBJECT (rtpsession, "unlock timer for reconsideration");
1652 if (rtpsession->priv->id)
1653 gst_clock_id_unschedule (rtpsession->priv->id);
1654 GST_RTP_SESSION_UNLOCK (rtpsession);
1658 gst_rtp_session_event_recv_rtp_sink (GstPad * pad, GstObject * parent,
1661 GstRtpSession *rtpsession;
1662 gboolean ret = FALSE;
1664 rtpsession = GST_RTP_SESSION (parent);
1666 GST_DEBUG_OBJECT (rtpsession, "received event %s",
1667 GST_EVENT_TYPE_NAME (event));
1669 switch (GST_EVENT_TYPE (event)) {
1670 case GST_EVENT_CAPS:
1675 gst_event_parse_caps (event, &caps);
1676 gst_rtp_session_sink_setcaps (pad, rtpsession, caps);
1677 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1680 case GST_EVENT_FLUSH_STOP:
1681 gst_segment_init (&rtpsession->recv_rtp_seg, GST_FORMAT_UNDEFINED);
1682 rtpsession->recv_rtcp_segment_seqnum = GST_SEQNUM_INVALID;
1683 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1685 case GST_EVENT_SEGMENT:
1687 GstSegment *segment, in_segment;
1689 segment = &rtpsession->recv_rtp_seg;
1691 /* the newsegment event is needed to convert the RTP timestamp to
1692 * running_time, which is needed to generate a mapping from RTP to NTP
1693 * timestamps in SR reports */
1694 gst_event_copy_segment (event, &in_segment);
1695 GST_DEBUG_OBJECT (rtpsession, "received segment %" GST_SEGMENT_FORMAT,
1698 /* accept upstream */
1699 gst_segment_copy_into (&in_segment, segment);
1701 /* push event forward */
1702 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1710 gst_pad_push_event (rtpsession->recv_rtp_src, gst_event_ref (event));
1712 GST_RTP_SESSION_LOCK (rtpsession);
1713 if ((rtcp_src = rtpsession->send_rtcp_src))
1714 gst_object_ref (rtcp_src);
1715 GST_RTP_SESSION_UNLOCK (rtpsession);
1717 gst_event_unref (event);
1720 event = gst_event_new_eos ();
1721 if (rtpsession->recv_rtcp_segment_seqnum != GST_SEQNUM_INVALID)
1722 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1723 ret = gst_pad_push_event (rtcp_src, event);
1724 gst_object_unref (rtcp_src);
1731 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1740 gst_rtp_session_request_remote_key_unit (GstRtpSession * rtpsession,
1741 guint32 ssrc, guint payload, gboolean all_headers, gint count)
1745 caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload);
1748 const GstStructure *s = gst_caps_get_structure (caps, 0);
1752 pli = gst_structure_has_field (s, "rtcp-fb-nack-pli");
1753 fir = gst_structure_has_field (s, "rtcp-fb-ccm-fir") && all_headers;
1755 /* Google Talk uses FIR for repair, so send it even if we just want a
1758 gst_structure_has_field (s, "rtcp-fb-x-gstreamer-fir-as-repair"))
1761 gst_caps_unref (caps);
1764 return rtp_session_request_key_unit (rtpsession->priv->session, ssrc,
1772 gst_rtp_session_event_recv_rtp_src (GstPad * pad, GstObject * parent,
1775 GstRtpSession *rtpsession;
1776 gboolean forward = TRUE;
1777 gboolean ret = TRUE;
1778 const GstStructure *s;
1782 rtpsession = GST_RTP_SESSION (parent);
1784 switch (GST_EVENT_TYPE (event)) {
1785 case GST_EVENT_CUSTOM_UPSTREAM:
1786 s = gst_event_get_structure (event);
1787 if (gst_structure_has_name (s, "GstForceKeyUnit") &&
1788 gst_structure_get_uint (s, "ssrc", &ssrc) &&
1789 gst_structure_get_uint (s, "payload", &pt)) {
1790 gboolean all_headers = FALSE;
1793 gst_structure_get_boolean (s, "all-headers", &all_headers);
1794 if (gst_structure_get_int (s, "count", &count) && count < 0)
1795 count += G_MAXINT; /* Make sure count is positive if present */
1796 if (gst_rtp_session_request_remote_key_unit (rtpsession, ssrc, pt,
1797 all_headers, count))
1799 } else if (gst_structure_has_name (s, "GstRTPRetransmissionRequest")) {
1800 GstClockTime running_time;
1801 guint seqnum, delay, deadline, max_delay, avg_rtt;
1803 GST_RTP_SESSION_LOCK (rtpsession);
1804 rtpsession->priv->rtx_count++;
1805 GST_RTP_SESSION_UNLOCK (rtpsession);
1807 if (!gst_structure_get_clock_time (s, "running-time", &running_time))
1809 if (!gst_structure_get_uint (s, "ssrc", &ssrc))
1811 if (!gst_structure_get_uint (s, "seqnum", &seqnum))
1813 if (!gst_structure_get_uint (s, "delay", &delay))
1815 if (!gst_structure_get_uint (s, "deadline", &deadline))
1817 if (!gst_structure_get_uint (s, "avg-rtt", &avg_rtt))
1820 /* remaining time to receive the packet */
1821 max_delay = deadline;
1822 if (max_delay > delay)
1825 if (max_delay > avg_rtt)
1826 max_delay -= avg_rtt;
1830 if (rtp_session_request_nack (rtpsession->priv->session, ssrc, seqnum,
1831 max_delay * GST_MSECOND))
1840 GstPad *recv_rtp_sink;
1842 GST_RTP_SESSION_LOCK (rtpsession);
1843 if ((recv_rtp_sink = rtpsession->recv_rtp_sink))
1844 gst_object_ref (recv_rtp_sink);
1845 GST_RTP_SESSION_UNLOCK (rtpsession);
1847 if (recv_rtp_sink) {
1848 ret = gst_pad_push_event (recv_rtp_sink, event);
1849 gst_object_unref (recv_rtp_sink);
1851 gst_event_unref (event);
1853 gst_event_unref (event);
1860 static GstIterator *
1861 gst_rtp_session_iterate_internal_links (GstPad * pad, GstObject * parent)
1863 GstRtpSession *rtpsession;
1864 GstPad *otherpad = NULL;
1865 GstIterator *it = NULL;
1867 rtpsession = GST_RTP_SESSION (parent);
1869 GST_RTP_SESSION_LOCK (rtpsession);
1870 if (pad == rtpsession->recv_rtp_src) {
1871 otherpad = gst_object_ref (rtpsession->recv_rtp_sink);
1872 } else if (pad == rtpsession->recv_rtp_sink) {
1873 otherpad = gst_object_ref (rtpsession->recv_rtp_src);
1874 } else if (pad == rtpsession->send_rtp_src) {
1875 otherpad = gst_object_ref (rtpsession->send_rtp_sink);
1876 } else if (pad == rtpsession->send_rtp_sink) {
1877 otherpad = gst_object_ref (rtpsession->send_rtp_src);
1879 GST_RTP_SESSION_UNLOCK (rtpsession);
1882 GValue val = { 0, };
1884 g_value_init (&val, GST_TYPE_PAD);
1885 g_value_set_object (&val, otherpad);
1886 it = gst_iterator_new_single (GST_TYPE_PAD, &val);
1887 g_value_unset (&val);
1888 gst_object_unref (otherpad);
1890 it = gst_iterator_new_single (GST_TYPE_PAD, NULL);
1897 gst_rtp_session_sink_setcaps (GstPad * pad, GstRtpSession * rtpsession,
1900 GST_RTP_SESSION_LOCK (rtpsession);
1901 gst_rtp_session_cache_caps (rtpsession, caps);
1902 GST_RTP_SESSION_UNLOCK (rtpsession);
1907 /* receive a packet from a sender, send it to the RTP session manager and
1908 * forward the packet on the rtp_src pad
1910 static GstFlowReturn
1911 gst_rtp_session_chain_recv_rtp (GstPad * pad, GstObject * parent,
1914 GstRtpSession *rtpsession;
1915 GstRtpSessionPrivate *priv;
1917 GstClockTime current_time, running_time;
1918 GstClockTime timestamp;
1921 rtpsession = GST_RTP_SESSION (parent);
1922 priv = rtpsession->priv;
1924 GST_LOG_OBJECT (rtpsession, "received RTP packet");
1926 GST_RTP_SESSION_LOCK (rtpsession);
1927 signal_waiting_rtcp_thread_unlocked (rtpsession);
1928 GST_RTP_SESSION_UNLOCK (rtpsession);
1930 /* get NTP time when this packet was captured, this depends on the timestamp. */
1931 timestamp = GST_BUFFER_PTS (buffer);
1932 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1933 /* convert to running time using the segment values */
1935 gst_segment_to_running_time (&rtpsession->recv_rtp_seg, GST_FORMAT_TIME,
1937 ntpnstime = GST_CLOCK_TIME_NONE;
1939 get_current_times (rtpsession, &running_time, &ntpnstime);
1941 current_time = gst_clock_get_time (priv->sysclock);
1943 ret = rtp_session_process_rtp (priv->session, buffer, current_time,
1944 running_time, ntpnstime);
1945 if (ret != GST_FLOW_OK)
1955 GST_DEBUG_OBJECT (rtpsession, "process returned %s",
1956 gst_flow_get_name (ret));
1962 gst_rtp_session_event_recv_rtcp_sink (GstPad * pad, GstObject * parent,
1965 GstRtpSession *rtpsession;
1966 gboolean ret = FALSE;
1968 rtpsession = GST_RTP_SESSION (parent);
1970 GST_DEBUG_OBJECT (rtpsession, "received event %s",
1971 GST_EVENT_TYPE_NAME (event));
1973 switch (GST_EVENT_TYPE (event)) {
1974 case GST_EVENT_SEGMENT:
1975 /* Make sure that the sync_src pad has caps before the segment event.
1976 * Otherwise we might get a segment event before caps from the receive
1977 * RTCP pad, and then later when receiving RTCP packets will set caps.
1978 * This will results in a sticky event misordering warning
1980 if (!gst_pad_has_current_caps (rtpsession->sync_src)) {
1981 GstCaps *caps = gst_caps_new_empty_simple ("application/x-rtcp");
1982 gst_pad_set_caps (rtpsession->sync_src, caps);
1983 gst_caps_unref (caps);
1987 ret = gst_pad_push_event (rtpsession->sync_src, event);
1994 /* Receive an RTCP packet from a sender, send it to the RTP session manager and
1995 * forward the SR packets to the sync_src pad.
1997 static GstFlowReturn
1998 gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstObject * parent,
2001 GstRtpSession *rtpsession;
2002 GstRtpSessionPrivate *priv;
2003 GstClockTime current_time;
2004 GstClockTime running_time;
2007 rtpsession = GST_RTP_SESSION (parent);
2008 priv = rtpsession->priv;
2010 GST_LOG_OBJECT (rtpsession, "received RTCP packet");
2012 GST_RTP_SESSION_LOCK (rtpsession);
2013 signal_waiting_rtcp_thread_unlocked (rtpsession);
2014 GST_RTP_SESSION_UNLOCK (rtpsession);
2016 current_time = gst_clock_get_time (priv->sysclock);
2017 get_current_times (rtpsession, &running_time, &ntpnstime);
2019 rtp_session_process_rtcp (priv->session, buffer, current_time, running_time,
2022 return GST_FLOW_OK; /* always return OK */
2026 gst_rtp_session_query_send_rtcp_src (GstPad * pad, GstObject * parent,
2029 GstRtpSession *rtpsession;
2030 gboolean ret = FALSE;
2032 rtpsession = GST_RTP_SESSION (parent);
2034 GST_DEBUG_OBJECT (rtpsession, "received QUERY %s",
2035 GST_QUERY_TYPE_NAME (query));
2037 switch (GST_QUERY_TYPE (query)) {
2038 case GST_QUERY_LATENCY:
2040 /* use the defaults for the latency query. */
2041 gst_query_set_latency (query, FALSE, 0, -1);
2044 /* other queries simply fail for now */
2052 gst_rtp_session_event_send_rtcp_src (GstPad * pad, GstObject * parent,
2055 GstRtpSession *rtpsession;
2056 gboolean ret = TRUE;
2058 rtpsession = GST_RTP_SESSION (parent);
2059 GST_DEBUG_OBJECT (rtpsession, "received EVENT %s",
2060 GST_EVENT_TYPE_NAME (event));
2062 switch (GST_EVENT_TYPE (event)) {
2063 case GST_EVENT_SEEK:
2064 case GST_EVENT_LATENCY:
2065 gst_event_unref (event);
2069 /* other events simply fail for now */
2070 gst_event_unref (event);
2080 gst_rtp_session_event_send_rtp_sink (GstPad * pad, GstObject * parent,
2083 GstRtpSession *rtpsession;
2084 gboolean ret = FALSE;
2086 rtpsession = GST_RTP_SESSION (parent);
2088 GST_DEBUG_OBJECT (rtpsession, "received EVENT %s",
2089 GST_EVENT_TYPE_NAME (event));
2091 switch (GST_EVENT_TYPE (event)) {
2092 case GST_EVENT_CAPS:
2097 gst_event_parse_caps (event, &caps);
2098 gst_rtp_session_setcaps_send_rtp (pad, rtpsession, caps);
2099 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2102 case GST_EVENT_FLUSH_STOP:
2103 gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
2104 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2106 case GST_EVENT_SEGMENT:{
2107 GstSegment *segment, in_segment;
2109 segment = &rtpsession->send_rtp_seg;
2111 /* the newsegment event is needed to convert the RTP timestamp to
2112 * running_time, which is needed to generate a mapping from RTP to NTP
2113 * timestamps in SR reports */
2114 gst_event_copy_segment (event, &in_segment);
2115 GST_DEBUG_OBJECT (rtpsession, "received segment %" GST_SEGMENT_FORMAT,
2118 /* accept upstream */
2119 gst_segment_copy_into (&in_segment, segment);
2121 /* push event forward */
2122 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2125 case GST_EVENT_EOS:{
2126 GstClockTime current_time;
2128 /* push downstream FIXME, we are not supposed to leave the session just
2129 * because we stop sending. */
2130 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2131 current_time = gst_clock_get_time (rtpsession->priv->sysclock);
2133 GST_DEBUG_OBJECT (rtpsession, "scheduling BYE message");
2134 rtp_session_mark_all_bye (rtpsession->priv->session, "End Of Stream");
2135 rtp_session_schedule_bye (rtpsession->priv->session, current_time);
2139 GstPad *send_rtp_src;
2141 GST_RTP_SESSION_LOCK (rtpsession);
2142 if ((send_rtp_src = rtpsession->send_rtp_src))
2143 gst_object_ref (send_rtp_src);
2144 GST_RTP_SESSION_UNLOCK (rtpsession);
2147 ret = gst_pad_push_event (send_rtp_src, event);
2148 gst_object_unref (send_rtp_src);
2150 gst_event_unref (event);
2160 gst_rtp_session_event_send_rtp_src (GstPad * pad, GstObject * parent,
2163 GstRtpSession *rtpsession;
2164 gboolean ret = FALSE;
2166 rtpsession = GST_RTP_SESSION (parent);
2168 GST_DEBUG_OBJECT (rtpsession, "received EVENT %s",
2169 GST_EVENT_TYPE_NAME (event));
2171 switch (GST_EVENT_TYPE (event)) {
2172 case GST_EVENT_LATENCY:
2173 /* save the latency, we need this to know when an RTP packet will be
2174 * rendered by the sink */
2175 gst_event_parse_latency (event, &rtpsession->priv->send_latency);
2177 ret = gst_pad_event_default (pad, parent, event);
2180 ret = gst_pad_event_default (pad, parent, event);
2187 gst_rtp_session_getcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
2190 GstRtpSessionPrivate *priv;
2192 GstStructure *s1, *s2;
2196 priv = rtpsession->priv;
2198 ssrc = rtp_session_suggest_ssrc (priv->session, &is_random);
2200 /* we can basically accept anything but we prefer to receive packets with our
2201 * internal SSRC so that we don't have to patch it. Create a structure with
2202 * the SSRC and another one without.
2203 * Only do this if the session actually decided on an ssrc already,
2204 * otherwise we give upstream the opportunity to select an ssrc itself */
2206 s1 = gst_structure_new ("application/x-rtp", "ssrc", G_TYPE_UINT, ssrc,
2208 s2 = gst_structure_new_empty ("application/x-rtp");
2210 result = gst_caps_new_full (s1, s2, NULL);
2212 result = gst_caps_new_empty_simple ("application/x-rtp");
2216 GstCaps *caps = result;
2218 result = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2219 gst_caps_unref (caps);
2222 GST_DEBUG_OBJECT (rtpsession, "getting caps %" GST_PTR_FORMAT, result);
2228 gst_rtp_session_query_send_rtp (GstPad * pad, GstObject * parent,
2231 gboolean res = FALSE;
2232 GstRtpSession *rtpsession;
2234 rtpsession = GST_RTP_SESSION (parent);
2236 switch (GST_QUERY_TYPE (query)) {
2237 case GST_QUERY_CAPS:
2239 GstCaps *filter, *caps;
2241 gst_query_parse_caps (query, &filter);
2242 caps = gst_rtp_session_getcaps_send_rtp (pad, rtpsession, filter);
2243 gst_query_set_caps_result (query, caps);
2244 gst_caps_unref (caps);
2249 res = gst_pad_query_default (pad, parent, query);
2257 gst_rtp_session_setcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
2260 GstRtpSessionPrivate *priv;
2262 priv = rtpsession->priv;
2264 rtp_session_update_send_caps (priv->session, caps);
2269 /* Recieve an RTP packet or a list of packets to be send to the receivers,
2270 * send to RTP session manager and forward to send_rtp_src.
2272 static GstFlowReturn
2273 gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
2274 gpointer data, gboolean is_list)
2276 GstRtpSessionPrivate *priv;
2278 GstClockTime timestamp, running_time;
2279 GstClockTime current_time;
2281 priv = rtpsession->priv;
2283 GST_LOG_OBJECT (rtpsession, "received RTP %s", is_list ? "list" : "packet");
2285 /* get NTP time when this packet was captured, this depends on the timestamp. */
2287 GstBuffer *buffer = NULL;
2289 /* All groups in an list have the same timestamp.
2290 * So, just take it from the first group. */
2291 buffer = gst_buffer_list_get (GST_BUFFER_LIST_CAST (data), 0);
2293 timestamp = GST_BUFFER_PTS (buffer);
2297 timestamp = GST_BUFFER_PTS (GST_BUFFER_CAST (data));
2300 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
2301 /* convert to running time using the segment start value. */
2303 gst_segment_to_running_time (&rtpsession->send_rtp_seg, GST_FORMAT_TIME,
2305 if (priv->rtcp_sync_send_time)
2306 running_time += priv->send_latency;
2312 current_time = gst_clock_get_time (priv->sysclock);
2313 ret = rtp_session_send_rtp (priv->session, data, is_list, current_time,
2315 if (ret != GST_FLOW_OK)
2325 GST_DEBUG_OBJECT (rtpsession, "process returned %s",
2326 gst_flow_get_name (ret));
2331 static GstFlowReturn
2332 gst_rtp_session_chain_send_rtp (GstPad * pad, GstObject * parent,
2335 GstRtpSession *rtpsession = GST_RTP_SESSION (parent);
2337 return gst_rtp_session_chain_send_rtp_common (rtpsession, buffer, FALSE);
2340 static GstFlowReturn
2341 gst_rtp_session_chain_send_rtp_list (GstPad * pad, GstObject * parent,
2342 GstBufferList * list)
2344 GstRtpSession *rtpsession = GST_RTP_SESSION (parent);
2346 return gst_rtp_session_chain_send_rtp_common (rtpsession, list, TRUE);
2349 /* Create sinkpad to receive RTP packets from senders. This will also create a
2350 * srcpad for the RTP packets.
2353 create_recv_rtp_sink (GstRtpSession * rtpsession)
2355 GST_DEBUG_OBJECT (rtpsession, "creating RTP sink pad");
2357 rtpsession->recv_rtp_sink =
2358 gst_pad_new_from_static_template (&rtpsession_recv_rtp_sink_template,
2360 gst_pad_set_chain_function (rtpsession->recv_rtp_sink,
2361 gst_rtp_session_chain_recv_rtp);
2362 gst_pad_set_event_function (rtpsession->recv_rtp_sink,
2363 gst_rtp_session_event_recv_rtp_sink);
2364 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtp_sink,
2365 gst_rtp_session_iterate_internal_links);
2366 GST_PAD_SET_PROXY_ALLOCATION (rtpsession->recv_rtp_sink);
2367 gst_pad_set_active (rtpsession->recv_rtp_sink, TRUE);
2368 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2369 rtpsession->recv_rtp_sink);
2371 GST_DEBUG_OBJECT (rtpsession, "creating RTP src pad");
2372 rtpsession->recv_rtp_src =
2373 gst_pad_new_from_static_template (&rtpsession_recv_rtp_src_template,
2375 gst_pad_set_event_function (rtpsession->recv_rtp_src,
2376 gst_rtp_session_event_recv_rtp_src);
2377 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtp_src,
2378 gst_rtp_session_iterate_internal_links);
2379 gst_pad_use_fixed_caps (rtpsession->recv_rtp_src);
2380 gst_pad_set_active (rtpsession->recv_rtp_src, TRUE);
2381 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->recv_rtp_src);
2383 return rtpsession->recv_rtp_sink;
2386 /* Remove sinkpad to receive RTP packets from senders. This will also remove
2387 * the srcpad for the RTP packets.
2390 remove_recv_rtp_sink (GstRtpSession * rtpsession)
2392 GST_DEBUG_OBJECT (rtpsession, "removing RTP sink pad");
2394 /* deactivate from source to sink */
2395 gst_pad_set_active (rtpsession->recv_rtp_src, FALSE);
2396 gst_pad_set_active (rtpsession->recv_rtp_sink, FALSE);
2399 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2400 rtpsession->recv_rtp_sink);
2401 rtpsession->recv_rtp_sink = NULL;
2403 GST_DEBUG_OBJECT (rtpsession, "removing RTP src pad");
2404 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2405 rtpsession->recv_rtp_src);
2406 rtpsession->recv_rtp_src = NULL;
2409 /* Create a sinkpad to receive RTCP messages from senders, this will also create a
2410 * sync_src pad for the SR packets.
2413 create_recv_rtcp_sink (GstRtpSession * rtpsession)
2415 GST_DEBUG_OBJECT (rtpsession, "creating RTCP sink pad");
2417 rtpsession->recv_rtcp_sink =
2418 gst_pad_new_from_static_template (&rtpsession_recv_rtcp_sink_template,
2420 gst_pad_set_chain_function (rtpsession->recv_rtcp_sink,
2421 gst_rtp_session_chain_recv_rtcp);
2422 gst_pad_set_event_function (rtpsession->recv_rtcp_sink,
2423 gst_rtp_session_event_recv_rtcp_sink);
2424 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtcp_sink,
2425 gst_rtp_session_iterate_internal_links);
2426 gst_pad_set_active (rtpsession->recv_rtcp_sink, TRUE);
2427 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2428 rtpsession->recv_rtcp_sink);
2430 GST_DEBUG_OBJECT (rtpsession, "creating sync src pad");
2431 rtpsession->sync_src =
2432 gst_pad_new_from_static_template (&rtpsession_sync_src_template,
2434 gst_pad_set_iterate_internal_links_function (rtpsession->sync_src,
2435 gst_rtp_session_iterate_internal_links);
2436 gst_pad_use_fixed_caps (rtpsession->sync_src);
2437 gst_pad_set_active (rtpsession->sync_src, TRUE);
2438 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->sync_src);
2440 return rtpsession->recv_rtcp_sink;
2444 remove_recv_rtcp_sink (GstRtpSession * rtpsession)
2446 GST_DEBUG_OBJECT (rtpsession, "removing RTCP sink pad");
2448 gst_pad_set_active (rtpsession->sync_src, FALSE);
2449 gst_pad_set_active (rtpsession->recv_rtcp_sink, FALSE);
2451 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2452 rtpsession->recv_rtcp_sink);
2453 rtpsession->recv_rtcp_sink = NULL;
2455 GST_DEBUG_OBJECT (rtpsession, "removing sync src pad");
2456 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->sync_src);
2457 rtpsession->sync_src = NULL;
2460 /* Create a sinkpad to receive RTP packets for receivers. This will also create a
2464 create_send_rtp_sink (GstRtpSession * rtpsession)
2466 GST_DEBUG_OBJECT (rtpsession, "creating pad");
2468 rtpsession->send_rtp_sink =
2469 gst_pad_new_from_static_template (&rtpsession_send_rtp_sink_template,
2471 gst_pad_set_chain_function (rtpsession->send_rtp_sink,
2472 gst_rtp_session_chain_send_rtp);
2473 gst_pad_set_chain_list_function (rtpsession->send_rtp_sink,
2474 gst_rtp_session_chain_send_rtp_list);
2475 gst_pad_set_query_function (rtpsession->send_rtp_sink,
2476 gst_rtp_session_query_send_rtp);
2477 gst_pad_set_event_function (rtpsession->send_rtp_sink,
2478 gst_rtp_session_event_send_rtp_sink);
2479 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtp_sink,
2480 gst_rtp_session_iterate_internal_links);
2481 GST_PAD_SET_PROXY_CAPS (rtpsession->send_rtp_sink);
2482 GST_PAD_SET_PROXY_ALLOCATION (rtpsession->send_rtp_sink);
2483 gst_pad_set_active (rtpsession->send_rtp_sink, TRUE);
2484 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2485 rtpsession->send_rtp_sink);
2487 rtpsession->send_rtp_src =
2488 gst_pad_new_from_static_template (&rtpsession_send_rtp_src_template,
2490 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtp_src,
2491 gst_rtp_session_iterate_internal_links);
2492 gst_pad_set_event_function (rtpsession->send_rtp_src,
2493 gst_rtp_session_event_send_rtp_src);
2494 GST_PAD_SET_PROXY_CAPS (rtpsession->send_rtp_src);
2495 gst_pad_set_active (rtpsession->send_rtp_src, TRUE);
2496 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->send_rtp_src);
2498 return rtpsession->send_rtp_sink;
2502 remove_send_rtp_sink (GstRtpSession * rtpsession)
2504 GST_DEBUG_OBJECT (rtpsession, "removing pad");
2506 gst_pad_set_active (rtpsession->send_rtp_src, FALSE);
2507 gst_pad_set_active (rtpsession->send_rtp_sink, FALSE);
2509 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2510 rtpsession->send_rtp_sink);
2511 rtpsession->send_rtp_sink = NULL;
2513 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2514 rtpsession->send_rtp_src);
2515 rtpsession->send_rtp_src = NULL;
2518 /* Create a srcpad with the RTCP packets to send out.
2519 * This pad will be driven by the RTP session manager when it wants to send out
2523 create_send_rtcp_src (GstRtpSession * rtpsession)
2525 GST_DEBUG_OBJECT (rtpsession, "creating pad");
2527 rtpsession->send_rtcp_src =
2528 gst_pad_new_from_static_template (&rtpsession_send_rtcp_src_template,
2530 gst_pad_use_fixed_caps (rtpsession->send_rtcp_src);
2531 gst_pad_set_active (rtpsession->send_rtcp_src, TRUE);
2532 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtcp_src,
2533 gst_rtp_session_iterate_internal_links);
2534 gst_pad_set_query_function (rtpsession->send_rtcp_src,
2535 gst_rtp_session_query_send_rtcp_src);
2536 gst_pad_set_event_function (rtpsession->send_rtcp_src,
2537 gst_rtp_session_event_send_rtcp_src);
2538 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2539 rtpsession->send_rtcp_src);
2541 return rtpsession->send_rtcp_src;
2545 remove_send_rtcp_src (GstRtpSession * rtpsession)
2547 GST_DEBUG_OBJECT (rtpsession, "removing pad");
2549 gst_pad_set_active (rtpsession->send_rtcp_src, FALSE);
2551 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2552 rtpsession->send_rtcp_src);
2553 rtpsession->send_rtcp_src = NULL;
2557 gst_rtp_session_request_new_pad (GstElement * element,
2558 GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
2560 GstRtpSession *rtpsession;
2561 GstElementClass *klass;
2564 g_return_val_if_fail (templ != NULL, NULL);
2565 g_return_val_if_fail (GST_IS_RTP_SESSION (element), NULL);
2567 rtpsession = GST_RTP_SESSION (element);
2568 klass = GST_ELEMENT_GET_CLASS (element);
2570 GST_DEBUG_OBJECT (element, "requesting pad %s", GST_STR_NULL (name));
2572 GST_RTP_SESSION_LOCK (rtpsession);
2574 /* figure out the template */
2575 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink")) {
2576 if (rtpsession->recv_rtp_sink != NULL)
2579 result = create_recv_rtp_sink (rtpsession);
2580 } else if (templ == gst_element_class_get_pad_template (klass,
2581 "recv_rtcp_sink")) {
2582 if (rtpsession->recv_rtcp_sink != NULL)
2585 result = create_recv_rtcp_sink (rtpsession);
2586 } else if (templ == gst_element_class_get_pad_template (klass,
2588 if (rtpsession->send_rtp_sink != NULL)
2591 result = create_send_rtp_sink (rtpsession);
2592 } else if (templ == gst_element_class_get_pad_template (klass,
2594 if (rtpsession->send_rtcp_src != NULL)
2597 result = create_send_rtcp_src (rtpsession);
2599 goto wrong_template;
2601 GST_RTP_SESSION_UNLOCK (rtpsession);
2608 GST_RTP_SESSION_UNLOCK (rtpsession);
2609 g_warning ("rtpsession: this is not our template");
2614 GST_RTP_SESSION_UNLOCK (rtpsession);
2615 g_warning ("rtpsession: pad already requested");
2621 gst_rtp_session_release_pad (GstElement * element, GstPad * pad)
2623 GstRtpSession *rtpsession;
2625 g_return_if_fail (GST_IS_RTP_SESSION (element));
2626 g_return_if_fail (GST_IS_PAD (pad));
2628 rtpsession = GST_RTP_SESSION (element);
2630 GST_DEBUG_OBJECT (element, "releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2632 GST_RTP_SESSION_LOCK (rtpsession);
2634 if (rtpsession->recv_rtp_sink == pad) {
2635 remove_recv_rtp_sink (rtpsession);
2636 } else if (rtpsession->recv_rtcp_sink == pad) {
2637 remove_recv_rtcp_sink (rtpsession);
2638 } else if (rtpsession->send_rtp_sink == pad) {
2639 remove_send_rtp_sink (rtpsession);
2640 } else if (rtpsession->send_rtcp_src == pad) {
2641 remove_send_rtcp_src (rtpsession);
2645 GST_RTP_SESSION_UNLOCK (rtpsession);
2652 GST_RTP_SESSION_UNLOCK (rtpsession);
2653 g_warning ("rtpsession: asked to release an unknown pad");
2659 gst_rtp_session_request_key_unit (RTPSession * sess,
2660 guint32 ssrc, gboolean all_headers, gpointer user_data)
2662 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2664 GstPad *send_rtp_sink;
2666 GST_RTP_SESSION_LOCK (rtpsession);
2667 if ((send_rtp_sink = rtpsession->send_rtp_sink))
2668 gst_object_ref (send_rtp_sink);
2669 GST_RTP_SESSION_UNLOCK (rtpsession);
2671 if (send_rtp_sink) {
2672 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
2673 gst_structure_new ("GstForceKeyUnit", "ssrc", G_TYPE_UINT, ssrc,
2674 "all-headers", G_TYPE_BOOLEAN, all_headers, NULL));
2675 gst_pad_push_event (send_rtp_sink, event);
2676 gst_object_unref (send_rtp_sink);
2681 gst_rtp_session_request_time (RTPSession * session, gpointer user_data)
2683 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2685 return gst_clock_get_time (rtpsession->priv->sysclock);
2689 gst_rtp_session_notify_nack (RTPSession * sess, guint16 seqnum,
2690 guint16 blp, guint32 ssrc, gpointer user_data)
2692 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2694 GstPad *send_rtp_sink;
2696 GST_RTP_SESSION_LOCK (rtpsession);
2697 if ((send_rtp_sink = rtpsession->send_rtp_sink))
2698 gst_object_ref (send_rtp_sink);
2699 GST_RTP_SESSION_UNLOCK (rtpsession);
2701 if (send_rtp_sink) {
2703 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
2704 gst_structure_new ("GstRTPRetransmissionRequest",
2705 "seqnum", G_TYPE_UINT, (guint) seqnum,
2706 "ssrc", G_TYPE_UINT, (guint) ssrc, NULL));
2707 gst_pad_push_event (send_rtp_sink, event);
2713 while ((blp & 1) == 0) {
2719 gst_object_unref (send_rtp_sink);
2724 gst_rtp_session_reconfigure (RTPSession * sess, gpointer user_data)
2726 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2727 GstPad *send_rtp_sink;
2729 GST_RTP_SESSION_LOCK (rtpsession);
2730 if ((send_rtp_sink = rtpsession->send_rtp_sink))
2731 gst_object_ref (send_rtp_sink);
2732 GST_RTP_SESSION_UNLOCK (rtpsession);
2734 if (send_rtp_sink) {
2735 gst_pad_push_event (send_rtp_sink, gst_event_new_reconfigure ());
2736 gst_object_unref (send_rtp_sink);
2741 gst_rtp_session_notify_early_rtcp (RTPSession * sess, gpointer user_data)
2743 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2745 GST_DEBUG_OBJECT (rtpsession, "Notified of early RTCP");
2746 /* with an early RTCP request, we might have to start the RTCP thread */
2747 GST_RTP_SESSION_LOCK (rtpsession);
2748 signal_waiting_rtcp_thread_unlocked (rtpsession);
2749 GST_RTP_SESSION_UNLOCK (rtpsession);