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;
284 guint recv_rtx_req_count;
285 guint sent_rtx_req_count;
288 /* callbacks to handle actions from the session manager */
289 static GstFlowReturn gst_rtp_session_process_rtp (RTPSession * sess,
290 RTPSource * src, GstBuffer * buffer, gpointer user_data);
291 static GstFlowReturn gst_rtp_session_send_rtp (RTPSession * sess,
292 RTPSource * src, gpointer data, gpointer user_data);
293 static GstFlowReturn gst_rtp_session_send_rtcp (RTPSession * sess,
294 RTPSource * src, GstBuffer * buffer, gboolean eos, gpointer user_data);
295 static GstFlowReturn gst_rtp_session_sync_rtcp (RTPSession * sess,
296 GstBuffer * buffer, gpointer user_data);
297 static gint gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
299 static void gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data);
300 static void gst_rtp_session_request_key_unit (RTPSession * sess, guint32 ssrc,
301 gboolean all_headers, gpointer user_data);
302 static GstClockTime gst_rtp_session_request_time (RTPSession * session,
304 static void gst_rtp_session_notify_nack (RTPSession * sess,
305 guint16 seqnum, guint16 blp, guint32 ssrc, gpointer user_data);
306 static void gst_rtp_session_reconfigure (RTPSession * sess, gpointer user_data);
307 static void gst_rtp_session_notify_early_rtcp (RTPSession * sess,
309 static GstFlowReturn gst_rtp_session_chain_recv_rtp (GstPad * pad,
310 GstObject * parent, GstBuffer * buffer);
311 static GstFlowReturn gst_rtp_session_chain_recv_rtcp (GstPad * pad,
312 GstObject * parent, GstBuffer * buffer);
313 static GstFlowReturn gst_rtp_session_chain_send_rtp (GstPad * pad,
314 GstObject * parent, GstBuffer * buffer);
315 static GstFlowReturn gst_rtp_session_chain_send_rtp_list (GstPad * pad,
316 GstObject * parent, GstBufferList * list);
318 static RTPSessionCallbacks callbacks = {
319 gst_rtp_session_process_rtp,
320 gst_rtp_session_send_rtp,
321 gst_rtp_session_sync_rtcp,
322 gst_rtp_session_send_rtcp,
323 gst_rtp_session_clock_rate,
324 gst_rtp_session_reconsider,
325 gst_rtp_session_request_key_unit,
326 gst_rtp_session_request_time,
327 gst_rtp_session_notify_nack,
328 gst_rtp_session_reconfigure,
329 gst_rtp_session_notify_early_rtcp
332 /* GObject vmethods */
333 static void gst_rtp_session_finalize (GObject * object);
334 static void gst_rtp_session_set_property (GObject * object, guint prop_id,
335 const GValue * value, GParamSpec * pspec);
336 static void gst_rtp_session_get_property (GObject * object, guint prop_id,
337 GValue * value, GParamSpec * pspec);
339 /* GstElement vmethods */
340 static GstStateChangeReturn gst_rtp_session_change_state (GstElement * element,
341 GstStateChange transition);
342 static GstPad *gst_rtp_session_request_new_pad (GstElement * element,
343 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
344 static void gst_rtp_session_release_pad (GstElement * element, GstPad * pad);
346 static gboolean gst_rtp_session_sink_setcaps (GstPad * pad,
347 GstRtpSession * rtpsession, GstCaps * caps);
348 static gboolean gst_rtp_session_setcaps_send_rtp (GstPad * pad,
349 GstRtpSession * rtpsession, GstCaps * caps);
351 static void gst_rtp_session_clear_pt_map (GstRtpSession * rtpsession);
353 static GstStructure *gst_rtp_session_create_stats (GstRtpSession * rtpsession);
355 static guint gst_rtp_session_signals[LAST_SIGNAL] = { 0 };
358 on_new_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
360 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_NEW_SSRC], 0,
365 on_ssrc_collision (RTPSession * session, RTPSource * src, GstRtpSession * sess)
367 GstPad *send_rtp_sink;
369 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_COLLISION], 0,
372 GST_RTP_SESSION_LOCK (sess);
373 if ((send_rtp_sink = sess->send_rtp_sink))
374 gst_object_ref (send_rtp_sink);
375 GST_RTP_SESSION_UNLOCK (sess);
378 GstStructure *structure;
380 RTPSource *internal_src;
381 guint32 suggested_ssrc;
383 structure = gst_structure_new ("GstRTPCollision", "ssrc", G_TYPE_UINT,
384 (guint) src->ssrc, NULL);
386 /* if there is no source using the suggested ssrc, most probably because
387 * this ssrc has just collided, suggest upstream to use it */
388 suggested_ssrc = rtp_session_suggest_ssrc (session, NULL);
389 internal_src = rtp_session_get_source_by_ssrc (session, suggested_ssrc);
391 gst_structure_set (structure, "suggested-ssrc", G_TYPE_UINT,
392 (guint) suggested_ssrc, NULL);
394 g_object_unref (internal_src);
396 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, structure);
397 gst_pad_push_event (send_rtp_sink, event);
398 gst_object_unref (send_rtp_sink);
403 on_ssrc_validated (RTPSession * session, RTPSource * src, GstRtpSession * sess)
405 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
410 on_ssrc_active (RTPSession * session, RTPSource * src, GstRtpSession * sess)
412 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
417 on_ssrc_sdes (RTPSession * session, RTPSource * src, GstRtpSession * sess)
422 /* convert the new SDES info into a message */
423 RTP_SESSION_LOCK (session);
424 g_object_get (src, "sdes", &s, NULL);
425 RTP_SESSION_UNLOCK (session);
427 m = gst_message_new_custom (GST_MESSAGE_ELEMENT, GST_OBJECT (sess), s);
428 gst_element_post_message (GST_ELEMENT_CAST (sess), m);
430 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_SDES], 0,
435 on_bye_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
437 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_BYE_SSRC], 0,
442 on_bye_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
444 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
449 on_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
451 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_TIMEOUT], 0,
456 on_sender_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
458 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
463 on_new_sender_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
465 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_NEW_SENDER_SSRC], 0,
470 on_sender_ssrc_active (RTPSession * session, RTPSource * src,
471 GstRtpSession * sess)
473 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE], 0,
478 on_notify_stats (RTPSession * session, GParamSpec * spec,
479 GstRtpSession * rtpsession)
481 g_object_notify (G_OBJECT (rtpsession), "stats");
484 #define gst_rtp_session_parent_class parent_class
485 G_DEFINE_TYPE_WITH_PRIVATE (GstRtpSession, gst_rtp_session, GST_TYPE_ELEMENT);
488 gst_rtp_session_class_init (GstRtpSessionClass * klass)
490 GObjectClass *gobject_class;
491 GstElementClass *gstelement_class;
493 gobject_class = (GObjectClass *) klass;
494 gstelement_class = (GstElementClass *) klass;
496 gobject_class->finalize = gst_rtp_session_finalize;
497 gobject_class->set_property = gst_rtp_session_set_property;
498 gobject_class->get_property = gst_rtp_session_get_property;
501 * GstRtpSession::request-pt-map:
502 * @sess: the object which received the signal
505 * Request the payload type as #GstCaps for @pt.
507 gst_rtp_session_signals[SIGNAL_REQUEST_PT_MAP] =
508 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
509 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, request_pt_map),
510 NULL, NULL, g_cclosure_marshal_generic, GST_TYPE_CAPS, 1, G_TYPE_UINT);
512 * GstRtpSession::clear-pt-map:
513 * @sess: the object which received the signal
515 * Clear the cached pt-maps requested with #GstRtpSession::request-pt-map.
517 gst_rtp_session_signals[SIGNAL_CLEAR_PT_MAP] =
518 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
519 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
520 G_STRUCT_OFFSET (GstRtpSessionClass, clear_pt_map),
521 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
524 * GstRtpSession::on-new-ssrc:
525 * @sess: the object which received the signal
528 * Notify of a new SSRC that entered @session.
530 gst_rtp_session_signals[SIGNAL_ON_NEW_SSRC] =
531 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
532 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_new_ssrc),
533 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
535 * GstRtpSession::on-ssrc_collision:
536 * @sess: the object which received the signal
539 * Notify when we have an SSRC collision
541 gst_rtp_session_signals[SIGNAL_ON_SSRC_COLLISION] =
542 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
543 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
544 on_ssrc_collision), NULL, NULL, g_cclosure_marshal_VOID__UINT,
545 G_TYPE_NONE, 1, G_TYPE_UINT);
547 * GstRtpSession::on-ssrc_validated:
548 * @sess: the object which received the signal
551 * Notify of a new SSRC that became validated.
553 gst_rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED] =
554 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
555 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
556 on_ssrc_validated), NULL, NULL, g_cclosure_marshal_VOID__UINT,
557 G_TYPE_NONE, 1, G_TYPE_UINT);
559 * GstRtpSession::on-ssrc-active:
560 * @sess: the object which received the signal
563 * Notify of a SSRC that is active, i.e., sending RTCP.
565 gst_rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE] =
566 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
567 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
568 on_ssrc_active), NULL, NULL, g_cclosure_marshal_VOID__UINT,
569 G_TYPE_NONE, 1, G_TYPE_UINT);
571 * GstRtpSession::on-ssrc-sdes:
572 * @session: the object which received the signal
575 * Notify that a new SDES was received for SSRC.
577 gst_rtp_session_signals[SIGNAL_ON_SSRC_SDES] =
578 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
579 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_ssrc_sdes),
580 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
583 * GstRtpSession::on-bye-ssrc:
584 * @sess: the object which received the signal
587 * Notify of an SSRC that became inactive because of a BYE packet.
589 gst_rtp_session_signals[SIGNAL_ON_BYE_SSRC] =
590 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
591 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_bye_ssrc),
592 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
594 * GstRtpSession::on-bye-timeout:
595 * @sess: the object which received the signal
598 * Notify of an SSRC that has timed out because of BYE
600 gst_rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT] =
601 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
602 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_bye_timeout),
603 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
605 * GstRtpSession::on-timeout:
606 * @sess: the object which received the signal
609 * Notify of an SSRC that has timed out
611 gst_rtp_session_signals[SIGNAL_ON_TIMEOUT] =
612 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
613 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_timeout),
614 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
616 * GstRtpSession::on-sender-timeout:
617 * @sess: the object which received the signal
620 * Notify of a sender SSRC that has timed out and became a receiver
622 gst_rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT] =
623 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
624 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
625 on_sender_timeout), NULL, NULL, g_cclosure_marshal_VOID__UINT,
626 G_TYPE_NONE, 1, G_TYPE_UINT);
629 * GstRtpSession::on-new-sender-ssrc:
630 * @sess: the object which received the signal
631 * @ssrc: the sender SSRC
633 * Notify of a new sender SSRC that entered @session.
637 gst_rtp_session_signals[SIGNAL_ON_NEW_SENDER_SSRC] =
638 g_signal_new ("on-new-sender-ssrc", G_TYPE_FROM_CLASS (klass),
639 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_new_ssrc),
640 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
643 * GstRtpSession::on-sender-ssrc-active:
644 * @sess: the object which received the signal
645 * @ssrc: the sender SSRC
647 * Notify of a sender SSRC that is active, i.e., sending RTCP.
651 gst_rtp_session_signals[SIGNAL_ON_SENDER_SSRC_ACTIVE] =
652 g_signal_new ("on-sender-ssrc-active", G_TYPE_FROM_CLASS (klass),
653 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
654 on_ssrc_active), NULL, NULL, g_cclosure_marshal_VOID__UINT,
655 G_TYPE_NONE, 1, G_TYPE_UINT);
657 g_object_class_install_property (gobject_class, PROP_BANDWIDTH,
658 g_param_spec_double ("bandwidth", "Bandwidth",
659 "The bandwidth of the session in bytes per second (0 for auto-discover)",
660 0.0, G_MAXDOUBLE, DEFAULT_BANDWIDTH,
661 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
663 g_object_class_install_property (gobject_class, PROP_RTCP_FRACTION,
664 g_param_spec_double ("rtcp-fraction", "RTCP Fraction",
665 "The RTCP bandwidth of the session in bytes per second "
666 "(or as a real fraction of the RTP bandwidth if < 1.0)",
667 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION,
668 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
670 g_object_class_install_property (gobject_class, PROP_RTCP_RR_BANDWIDTH,
671 g_param_spec_int ("rtcp-rr-bandwidth", "RTCP RR bandwidth",
672 "The RTCP bandwidth used for receivers in bytes per second (-1 = default)",
673 -1, G_MAXINT, DEFAULT_RTCP_RR_BANDWIDTH,
674 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
676 g_object_class_install_property (gobject_class, PROP_RTCP_RS_BANDWIDTH,
677 g_param_spec_int ("rtcp-rs-bandwidth", "RTCP RS bandwidth",
678 "The RTCP bandwidth used for senders in bytes per second (-1 = default)",
679 -1, G_MAXINT, DEFAULT_RTCP_RS_BANDWIDTH,
680 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
682 g_object_class_install_property (gobject_class, PROP_SDES,
683 g_param_spec_boxed ("sdes", "SDES",
684 "The SDES items of this session",
685 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
687 g_object_class_install_property (gobject_class, PROP_NUM_SOURCES,
688 g_param_spec_uint ("num-sources", "Num Sources",
689 "The number of sources in the session", 0, G_MAXUINT,
690 DEFAULT_NUM_SOURCES, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
692 g_object_class_install_property (gobject_class, PROP_NUM_ACTIVE_SOURCES,
693 g_param_spec_uint ("num-active-sources", "Num Active Sources",
694 "The number of active sources in the session", 0, G_MAXUINT,
695 DEFAULT_NUM_ACTIVE_SOURCES,
696 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
698 g_object_class_install_property (gobject_class, PROP_INTERNAL_SESSION,
699 g_param_spec_object ("internal-session", "Internal Session",
700 "The internal RTPSession object", RTP_TYPE_SESSION,
701 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
703 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
704 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
705 "Use the pipeline running-time to set the NTP time in the RTCP SR messages "
706 "(DEPRECATED: Use ntp-time-source property)",
707 DEFAULT_USE_PIPELINE_CLOCK,
708 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
710 g_object_class_install_property (gobject_class, PROP_RTCP_MIN_INTERVAL,
711 g_param_spec_uint64 ("rtcp-min-interval", "Minimum RTCP interval",
712 "Minimum interval between Regular RTCP packet (in ns)",
713 0, G_MAXUINT64, DEFAULT_RTCP_MIN_INTERVAL,
714 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
716 g_object_class_install_property (gobject_class, PROP_PROBATION,
717 g_param_spec_uint ("probation", "Number of probations",
718 "Consecutive packet sequence numbers to accept the source",
719 0, G_MAXUINT, DEFAULT_PROBATION,
720 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
722 g_object_class_install_property (gobject_class, PROP_MAX_DROPOUT_TIME,
723 g_param_spec_uint ("max-dropout-time", "Max dropout time",
724 "The maximum time (milliseconds) of missing packets tolerated.",
725 0, G_MAXUINT, DEFAULT_MAX_DROPOUT_TIME,
726 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
728 g_object_class_install_property (gobject_class, PROP_MAX_MISORDER_TIME,
729 g_param_spec_uint ("max-misorder-time", "Max misorder time",
730 "The maximum time (milliseconds) of misordered packets tolerated.",
731 0, G_MAXUINT, DEFAULT_MAX_MISORDER_TIME,
732 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
735 * GstRtpSession::stats:
737 * Various session statistics. This property returns a GstStructure
738 * with name application/x-rtp-session-stats with the following fields:
740 * "recv-rtx-req-count G_TYPE_UINT The number of retransmission event
741 * received from downstream (in receiver mode) (Since 1.16)
742 * "sent-rtx-req-count" G_TYPE_UINT The number of retransmission event
743 * sent downstream (in sender mode) (Since 1.16)
744 * "rtx-count" G_TYPE_UINT DEPRECATED Since 1.16, same as
745 * "recv-rtx-req-count".
746 * "rtx-drop-count" G_TYPE_UINT The number of retransmission events
747 * dropped (due to bandwidth constraints)
748 * "sent-nack-count" G_TYPE_UINT Number of NACKs sent
749 * "recv-nack-count" G_TYPE_UINT Number of NACKs received
750 * "source-stats" G_TYPE_BOXED GValueArray of #RTPSource::stats for all
751 * RTP sources (Since 1.8)
755 g_object_class_install_property (gobject_class, PROP_STATS,
756 g_param_spec_boxed ("stats", "Statistics",
757 "Various statistics", GST_TYPE_STRUCTURE,
758 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
760 g_object_class_install_property (gobject_class, PROP_RTP_PROFILE,
761 g_param_spec_enum ("rtp-profile", "RTP Profile",
762 "RTP profile to use", GST_TYPE_RTP_PROFILE, DEFAULT_RTP_PROFILE,
763 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
765 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
766 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
767 "NTP time source for RTCP packets",
768 gst_rtp_ntp_time_source_get_type (), DEFAULT_NTP_TIME_SOURCE,
769 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
771 g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_SEND_TIME,
772 g_param_spec_boolean ("rtcp-sync-send-time", "RTCP Sync Send Time",
773 "Use send time or capture time for RTCP sync "
774 "(TRUE = send time, FALSE = capture time)",
775 DEFAULT_RTCP_SYNC_SEND_TIME,
776 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
778 gstelement_class->change_state =
779 GST_DEBUG_FUNCPTR (gst_rtp_session_change_state);
780 gstelement_class->request_new_pad =
781 GST_DEBUG_FUNCPTR (gst_rtp_session_request_new_pad);
782 gstelement_class->release_pad =
783 GST_DEBUG_FUNCPTR (gst_rtp_session_release_pad);
785 klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_session_clear_pt_map);
788 gst_element_class_add_static_pad_template (gstelement_class,
789 &rtpsession_recv_rtp_sink_template);
790 gst_element_class_add_static_pad_template (gstelement_class,
791 &rtpsession_recv_rtcp_sink_template);
792 gst_element_class_add_static_pad_template (gstelement_class,
793 &rtpsession_send_rtp_sink_template);
796 gst_element_class_add_static_pad_template (gstelement_class,
797 &rtpsession_recv_rtp_src_template);
798 gst_element_class_add_static_pad_template (gstelement_class,
799 &rtpsession_sync_src_template);
800 gst_element_class_add_static_pad_template (gstelement_class,
801 &rtpsession_send_rtp_src_template);
802 gst_element_class_add_static_pad_template (gstelement_class,
803 &rtpsession_send_rtcp_src_template);
805 gst_element_class_set_static_metadata (gstelement_class, "RTP Session",
806 "Filter/Network/RTP",
807 "Implement an RTP session", "Wim Taymans <wim.taymans@gmail.com>");
809 GST_DEBUG_CATEGORY_INIT (gst_rtp_session_debug,
810 "rtpsession", 0, "RTP Session");
812 GST_DEBUG_REGISTER_FUNCPTR (gst_rtp_session_chain_recv_rtp);
813 GST_DEBUG_REGISTER_FUNCPTR (gst_rtp_session_chain_recv_rtcp);
814 GST_DEBUG_REGISTER_FUNCPTR (gst_rtp_session_chain_send_rtp);
815 GST_DEBUG_REGISTER_FUNCPTR (gst_rtp_session_chain_send_rtp_list);
820 gst_rtp_session_init (GstRtpSession * rtpsession)
822 rtpsession->priv = gst_rtp_session_get_instance_private (rtpsession);
823 g_mutex_init (&rtpsession->priv->lock);
824 g_cond_init (&rtpsession->priv->cond);
825 rtpsession->priv->sysclock = gst_system_clock_obtain ();
826 rtpsession->priv->session = rtp_session_new ();
827 rtpsession->priv->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
828 rtpsession->priv->rtcp_sync_send_time = DEFAULT_RTCP_SYNC_SEND_TIME;
830 /* configure callbacks */
831 rtp_session_set_callbacks (rtpsession->priv->session, &callbacks, rtpsession);
832 /* configure signals */
833 g_signal_connect (rtpsession->priv->session, "on-new-ssrc",
834 (GCallback) on_new_ssrc, rtpsession);
835 g_signal_connect (rtpsession->priv->session, "on-ssrc-collision",
836 (GCallback) on_ssrc_collision, rtpsession);
837 g_signal_connect (rtpsession->priv->session, "on-ssrc-validated",
838 (GCallback) on_ssrc_validated, rtpsession);
839 g_signal_connect (rtpsession->priv->session, "on-ssrc-active",
840 (GCallback) on_ssrc_active, rtpsession);
841 g_signal_connect (rtpsession->priv->session, "on-ssrc-sdes",
842 (GCallback) on_ssrc_sdes, rtpsession);
843 g_signal_connect (rtpsession->priv->session, "on-bye-ssrc",
844 (GCallback) on_bye_ssrc, rtpsession);
845 g_signal_connect (rtpsession->priv->session, "on-bye-timeout",
846 (GCallback) on_bye_timeout, rtpsession);
847 g_signal_connect (rtpsession->priv->session, "on-timeout",
848 (GCallback) on_timeout, rtpsession);
849 g_signal_connect (rtpsession->priv->session, "on-sender-timeout",
850 (GCallback) on_sender_timeout, rtpsession);
851 g_signal_connect (rtpsession->priv->session, "on-new-sender-ssrc",
852 (GCallback) on_new_sender_ssrc, rtpsession);
853 g_signal_connect (rtpsession->priv->session, "on-sender-ssrc-active",
854 (GCallback) on_sender_ssrc_active, rtpsession);
855 g_signal_connect (rtpsession->priv->session, "notify::stats",
856 (GCallback) on_notify_stats, rtpsession);
857 rtpsession->priv->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
858 (GDestroyNotify) gst_caps_unref);
860 rtpsession->recv_rtcp_segment_seqnum = GST_SEQNUM_INVALID;
862 gst_segment_init (&rtpsession->recv_rtp_seg, GST_FORMAT_UNDEFINED);
863 gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
865 rtpsession->priv->thread_stopped = TRUE;
867 rtpsession->priv->recv_rtx_req_count = 0;
868 rtpsession->priv->sent_rtx_req_count = 0;
870 rtpsession->priv->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
874 gst_rtp_session_finalize (GObject * object)
876 GstRtpSession *rtpsession;
878 rtpsession = GST_RTP_SESSION (object);
880 g_hash_table_destroy (rtpsession->priv->ptmap);
881 g_mutex_clear (&rtpsession->priv->lock);
882 g_cond_clear (&rtpsession->priv->cond);
883 g_object_unref (rtpsession->priv->sysclock);
884 g_object_unref (rtpsession->priv->session);
886 G_OBJECT_CLASS (parent_class)->finalize (object);
890 gst_rtp_session_set_property (GObject * object, guint prop_id,
891 const GValue * value, GParamSpec * pspec)
893 GstRtpSession *rtpsession;
894 GstRtpSessionPrivate *priv;
896 rtpsession = GST_RTP_SESSION (object);
897 priv = rtpsession->priv;
901 g_object_set_property (G_OBJECT (priv->session), "bandwidth", value);
903 case PROP_RTCP_FRACTION:
904 g_object_set_property (G_OBJECT (priv->session), "rtcp-fraction", value);
906 case PROP_RTCP_RR_BANDWIDTH:
907 g_object_set_property (G_OBJECT (priv->session), "rtcp-rr-bandwidth",
910 case PROP_RTCP_RS_BANDWIDTH:
911 g_object_set_property (G_OBJECT (priv->session), "rtcp-rs-bandwidth",
915 rtp_session_set_sdes_struct (priv->session, g_value_get_boxed (value));
917 case PROP_USE_PIPELINE_CLOCK:
918 priv->use_pipeline_clock = g_value_get_boolean (value);
920 case PROP_RTCP_MIN_INTERVAL:
921 g_object_set_property (G_OBJECT (priv->session), "rtcp-min-interval",
925 g_object_set_property (G_OBJECT (priv->session), "probation", value);
927 case PROP_MAX_DROPOUT_TIME:
928 g_object_set_property (G_OBJECT (priv->session), "max-dropout-time",
931 case PROP_MAX_MISORDER_TIME:
932 g_object_set_property (G_OBJECT (priv->session), "max-misorder-time",
935 case PROP_RTP_PROFILE:
936 g_object_set_property (G_OBJECT (priv->session), "rtp-profile", value);
938 case PROP_NTP_TIME_SOURCE:
939 priv->ntp_time_source = g_value_get_enum (value);
941 case PROP_RTCP_SYNC_SEND_TIME:
942 priv->rtcp_sync_send_time = g_value_get_boolean (value);
945 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
951 gst_rtp_session_get_property (GObject * object, guint prop_id,
952 GValue * value, GParamSpec * pspec)
954 GstRtpSession *rtpsession;
955 GstRtpSessionPrivate *priv;
957 rtpsession = GST_RTP_SESSION (object);
958 priv = rtpsession->priv;
962 g_object_get_property (G_OBJECT (priv->session), "bandwidth", value);
964 case PROP_RTCP_FRACTION:
965 g_object_get_property (G_OBJECT (priv->session), "rtcp-fraction", value);
967 case PROP_RTCP_RR_BANDWIDTH:
968 g_object_get_property (G_OBJECT (priv->session), "rtcp-rr-bandwidth",
971 case PROP_RTCP_RS_BANDWIDTH:
972 g_object_get_property (G_OBJECT (priv->session), "rtcp-rs-bandwidth",
976 g_value_take_boxed (value, rtp_session_get_sdes_struct (priv->session));
978 case PROP_NUM_SOURCES:
979 g_value_set_uint (value, rtp_session_get_num_sources (priv->session));
981 case PROP_NUM_ACTIVE_SOURCES:
982 g_value_set_uint (value,
983 rtp_session_get_num_active_sources (priv->session));
985 case PROP_INTERNAL_SESSION:
986 g_value_set_object (value, priv->session);
988 case PROP_USE_PIPELINE_CLOCK:
989 g_value_set_boolean (value, priv->use_pipeline_clock);
991 case PROP_RTCP_MIN_INTERVAL:
992 g_object_get_property (G_OBJECT (priv->session), "rtcp-min-interval",
996 g_object_get_property (G_OBJECT (priv->session), "probation", value);
998 case PROP_MAX_DROPOUT_TIME:
999 g_object_get_property (G_OBJECT (priv->session), "max-dropout-time",
1002 case PROP_MAX_MISORDER_TIME:
1003 g_object_get_property (G_OBJECT (priv->session), "max-misorder-time",
1007 g_value_take_boxed (value, gst_rtp_session_create_stats (rtpsession));
1009 case PROP_RTP_PROFILE:
1010 g_object_get_property (G_OBJECT (priv->session), "rtp-profile", value);
1012 case PROP_NTP_TIME_SOURCE:
1013 g_value_set_enum (value, priv->ntp_time_source);
1015 case PROP_RTCP_SYNC_SEND_TIME:
1016 g_value_set_boolean (value, priv->rtcp_sync_send_time);
1019 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1024 static GstStructure *
1025 gst_rtp_session_create_stats (GstRtpSession * rtpsession)
1029 g_object_get (rtpsession->priv->session, "stats", &s, NULL);
1030 gst_structure_set (s, "rtx-count", G_TYPE_UINT,
1031 rtpsession->priv->recv_rtx_req_count, "recv-rtx-req-count", G_TYPE_UINT,
1032 rtpsession->priv->recv_rtx_req_count, "sent-rtx-req-count", G_TYPE_UINT,
1033 rtpsession->priv->sent_rtx_req_count, NULL);
1039 get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
1040 guint64 * ntpnstime)
1044 GstClockTime base_time, rt, clock_time;
1046 GST_OBJECT_LOCK (rtpsession);
1047 if ((clock = GST_ELEMENT_CLOCK (rtpsession))) {
1048 base_time = GST_ELEMENT_CAST (rtpsession)->base_time;
1049 gst_object_ref (clock);
1050 GST_OBJECT_UNLOCK (rtpsession);
1052 /* get current clock time and convert to running time */
1053 clock_time = gst_clock_get_time (clock);
1054 rt = clock_time - base_time;
1056 if (rtpsession->priv->use_pipeline_clock) {
1058 /* add constant to convert from 1970 based time to 1900 based time */
1059 ntpns += (2208988800LL * GST_SECOND);
1061 switch (rtpsession->priv->ntp_time_source) {
1062 case GST_RTP_NTP_TIME_SOURCE_NTP:
1063 case GST_RTP_NTP_TIME_SOURCE_UNIX:{
1066 /* get current NTP time */
1067 g_get_current_time (¤t);
1068 ntpns = GST_TIMEVAL_TO_TIME (current);
1070 /* add constant to convert from 1970 based time to 1900 based time */
1071 if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
1072 ntpns += (2208988800LL * GST_SECOND);
1075 case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
1078 case GST_RTP_NTP_TIME_SOURCE_CLOCK_TIME:
1083 g_assert_not_reached ();
1088 gst_object_unref (clock);
1090 GST_OBJECT_UNLOCK (rtpsession);
1100 /* must be called with GST_RTP_SESSION_LOCK */
1102 signal_waiting_rtcp_thread_unlocked (GstRtpSession * rtpsession)
1104 if (rtpsession->priv->wait_send) {
1105 GST_LOG_OBJECT (rtpsession, "signal RTCP thread");
1106 rtpsession->priv->wait_send = FALSE;
1107 GST_RTP_SESSION_SIGNAL (rtpsession);
1112 rtcp_thread (GstRtpSession * rtpsession)
1115 GstClockTime current_time;
1116 GstClockTime next_timeout;
1118 GstClockTime running_time;
1119 RTPSession *session;
1122 GST_DEBUG_OBJECT (rtpsession, "entering RTCP thread");
1124 GST_RTP_SESSION_LOCK (rtpsession);
1126 while (rtpsession->priv->wait_send) {
1127 GST_LOG_OBJECT (rtpsession, "waiting for getting started");
1128 GST_RTP_SESSION_WAIT (rtpsession);
1129 GST_LOG_OBJECT (rtpsession, "signaled...");
1132 sysclock = rtpsession->priv->sysclock;
1133 current_time = gst_clock_get_time (sysclock);
1135 session = rtpsession->priv->session;
1137 GST_DEBUG_OBJECT (rtpsession, "starting at %" GST_TIME_FORMAT,
1138 GST_TIME_ARGS (current_time));
1139 session->start_time = current_time;
1141 while (!rtpsession->priv->stop_thread) {
1144 /* get initial estimate */
1145 next_timeout = rtp_session_next_timeout (session, current_time);
1147 GST_DEBUG_OBJECT (rtpsession, "next check time %" GST_TIME_FORMAT,
1148 GST_TIME_ARGS (next_timeout));
1150 /* leave if no more timeouts, the session ended */
1151 if (next_timeout == GST_CLOCK_TIME_NONE)
1154 id = rtpsession->priv->id =
1155 gst_clock_new_single_shot_id (sysclock, next_timeout);
1156 GST_RTP_SESSION_UNLOCK (rtpsession);
1158 res = gst_clock_id_wait (id, NULL);
1160 GST_RTP_SESSION_LOCK (rtpsession);
1161 gst_clock_id_unref (id);
1162 rtpsession->priv->id = NULL;
1164 if (rtpsession->priv->stop_thread)
1167 /* update current time */
1168 current_time = gst_clock_get_time (sysclock);
1170 /* get current NTP time */
1171 get_current_times (rtpsession, &running_time, &ntpnstime);
1173 /* we get unlocked because we need to perform reconsideration, don't perform
1174 * the timeout but get a new reporting estimate. */
1175 GST_DEBUG_OBJECT (rtpsession, "unlocked %d, current %" GST_TIME_FORMAT,
1176 res, GST_TIME_ARGS (current_time));
1178 /* perform actions, we ignore result. Release lock because it might push. */
1179 GST_RTP_SESSION_UNLOCK (rtpsession);
1180 rtp_session_on_timeout (session, current_time, ntpnstime, running_time);
1181 GST_RTP_SESSION_LOCK (rtpsession);
1183 /* mark the thread as stopped now */
1184 rtpsession->priv->thread_stopped = TRUE;
1185 GST_RTP_SESSION_UNLOCK (rtpsession);
1187 GST_DEBUG_OBJECT (rtpsession, "leaving RTCP thread");
1191 start_rtcp_thread (GstRtpSession * rtpsession)
1193 GError *error = NULL;
1196 GST_DEBUG_OBJECT (rtpsession, "starting RTCP thread");
1198 GST_RTP_SESSION_LOCK (rtpsession);
1199 rtpsession->priv->stop_thread = FALSE;
1200 if (rtpsession->priv->thread_stopped) {
1201 /* if the thread stopped, and we still have a handle to the thread, join it
1202 * now. We can safely join with the lock held, the thread will not take it
1204 if (rtpsession->priv->thread)
1205 g_thread_join (rtpsession->priv->thread);
1206 /* only create a new thread if the old one was stopped. Otherwise we can
1207 * just reuse the currently running one. */
1208 rtpsession->priv->thread = g_thread_try_new ("rtpsession-rtcp-thread",
1209 (GThreadFunc) rtcp_thread, rtpsession, &error);
1210 rtpsession->priv->thread_stopped = FALSE;
1212 GST_RTP_SESSION_UNLOCK (rtpsession);
1214 if (error != NULL) {
1216 GST_DEBUG_OBJECT (rtpsession, "failed to start thread, %s", error->message);
1217 g_error_free (error);
1225 stop_rtcp_thread (GstRtpSession * rtpsession)
1227 GST_DEBUG_OBJECT (rtpsession, "stopping RTCP thread");
1229 GST_RTP_SESSION_LOCK (rtpsession);
1230 rtpsession->priv->stop_thread = TRUE;
1231 signal_waiting_rtcp_thread_unlocked (rtpsession);
1232 if (rtpsession->priv->id)
1233 gst_clock_id_unschedule (rtpsession->priv->id);
1234 GST_RTP_SESSION_UNLOCK (rtpsession);
1238 join_rtcp_thread (GstRtpSession * rtpsession)
1240 GST_RTP_SESSION_LOCK (rtpsession);
1241 /* don't try to join when we have no thread */
1242 if (rtpsession->priv->thread != NULL) {
1243 GST_DEBUG_OBJECT (rtpsession, "joining RTCP thread");
1244 GST_RTP_SESSION_UNLOCK (rtpsession);
1246 g_thread_join (rtpsession->priv->thread);
1248 GST_RTP_SESSION_LOCK (rtpsession);
1249 /* after the join, take the lock and clear the thread structure. The caller
1250 * is supposed to not concurrently call start and join. */
1251 rtpsession->priv->thread = NULL;
1253 GST_RTP_SESSION_UNLOCK (rtpsession);
1256 static GstStateChangeReturn
1257 gst_rtp_session_change_state (GstElement * element, GstStateChange transition)
1259 GstStateChangeReturn res;
1260 GstRtpSession *rtpsession;
1262 rtpsession = GST_RTP_SESSION (element);
1264 switch (transition) {
1265 case GST_STATE_CHANGE_NULL_TO_READY:
1267 case GST_STATE_CHANGE_READY_TO_PAUSED:
1268 GST_RTP_SESSION_LOCK (rtpsession);
1269 rtpsession->priv->wait_send = TRUE;
1270 GST_RTP_SESSION_UNLOCK (rtpsession);
1272 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1274 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1275 case GST_STATE_CHANGE_PAUSED_TO_READY:
1276 /* no need to join yet, we might want to continue later. Also, the
1277 * dataflow could block downstream so that a join could just block
1279 stop_rtcp_thread (rtpsession);
1285 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1287 switch (transition) {
1288 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1289 if (!start_rtcp_thread (rtpsession))
1292 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1294 case GST_STATE_CHANGE_PAUSED_TO_READY:
1295 /* downstream is now releasing the dataflow and we can join. */
1296 join_rtcp_thread (rtpsession);
1297 rtp_session_reset (rtpsession->priv->session);
1299 case GST_STATE_CHANGE_READY_TO_NULL:
1309 return GST_STATE_CHANGE_FAILURE;
1314 return_true (gpointer key, gpointer value, gpointer user_data)
1320 gst_rtp_session_clear_pt_map (GstRtpSession * rtpsession)
1322 g_hash_table_foreach_remove (rtpsession->priv->ptmap, return_true, NULL);
1325 /* called when the session manager has an RTP packet or a list of packets
1326 * ready for further processing */
1327 static GstFlowReturn
1328 gst_rtp_session_process_rtp (RTPSession * sess, RTPSource * src,
1329 GstBuffer * buffer, gpointer user_data)
1331 GstFlowReturn result;
1332 GstRtpSession *rtpsession;
1335 rtpsession = GST_RTP_SESSION (user_data);
1337 GST_RTP_SESSION_LOCK (rtpsession);
1338 if ((rtp_src = rtpsession->recv_rtp_src))
1339 gst_object_ref (rtp_src);
1340 GST_RTP_SESSION_UNLOCK (rtpsession);
1343 GST_LOG_OBJECT (rtpsession, "pushing received RTP packet");
1344 result = gst_pad_push (rtp_src, buffer);
1345 gst_object_unref (rtp_src);
1347 GST_DEBUG_OBJECT (rtpsession, "dropping received RTP packet");
1348 gst_buffer_unref (buffer);
1349 result = GST_FLOW_OK;
1354 /* called when the session manager has an RTP packet ready for further
1356 static GstFlowReturn
1357 gst_rtp_session_send_rtp (RTPSession * sess, RTPSource * src,
1358 gpointer data, gpointer user_data)
1360 GstFlowReturn result;
1361 GstRtpSession *rtpsession;
1364 rtpsession = GST_RTP_SESSION (user_data);
1366 GST_RTP_SESSION_LOCK (rtpsession);
1367 if ((rtp_src = rtpsession->send_rtp_src))
1368 gst_object_ref (rtp_src);
1369 signal_waiting_rtcp_thread_unlocked (rtpsession);
1370 GST_RTP_SESSION_UNLOCK (rtpsession);
1373 if (GST_IS_BUFFER (data)) {
1374 GST_LOG_OBJECT (rtpsession, "sending RTP packet");
1375 result = gst_pad_push (rtp_src, GST_BUFFER_CAST (data));
1377 GST_LOG_OBJECT (rtpsession, "sending RTP list");
1378 result = gst_pad_push_list (rtp_src, GST_BUFFER_LIST_CAST (data));
1380 gst_object_unref (rtp_src);
1382 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
1383 result = GST_FLOW_OK;
1389 do_rtcp_events (GstRtpSession * rtpsession, GstPad * srcpad)
1395 gboolean have_group_id;
1399 g_strdup_printf ("%08x%08x%08x%08x", g_random_int (), g_random_int (),
1400 g_random_int (), g_random_int ());
1402 GST_RTP_SESSION_LOCK (rtpsession);
1403 if (rtpsession->recv_rtp_sink) {
1405 gst_pad_get_sticky_event (rtpsession->recv_rtp_sink,
1406 GST_EVENT_STREAM_START, 0);
1408 if (gst_event_parse_group_id (event, &group_id))
1409 have_group_id = TRUE;
1411 have_group_id = FALSE;
1412 gst_event_unref (event);
1414 have_group_id = TRUE;
1415 group_id = gst_util_group_id_next ();
1418 have_group_id = TRUE;
1419 group_id = gst_util_group_id_next ();
1421 GST_RTP_SESSION_UNLOCK (rtpsession);
1423 event = gst_event_new_stream_start (stream_id);
1424 rtpsession->recv_rtcp_segment_seqnum = gst_event_get_seqnum (event);
1425 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1427 gst_event_set_group_id (event, group_id);
1428 gst_pad_push_event (srcpad, event);
1431 caps = gst_caps_new_empty_simple ("application/x-rtcp");
1432 gst_pad_set_caps (srcpad, caps);
1433 gst_caps_unref (caps);
1435 gst_segment_init (&seg, GST_FORMAT_TIME);
1436 event = gst_event_new_segment (&seg);
1437 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1438 gst_pad_push_event (srcpad, event);
1441 /* called when the session manager has an RTCP packet ready for further
1442 * sending. The eos flag is set when an EOS event should be sent downstream as
1444 static GstFlowReturn
1445 gst_rtp_session_send_rtcp (RTPSession * sess, RTPSource * src,
1446 GstBuffer * buffer, gboolean all_sources_bye, gpointer user_data)
1448 GstFlowReturn result;
1449 GstRtpSession *rtpsession;
1452 rtpsession = GST_RTP_SESSION (user_data);
1454 GST_RTP_SESSION_LOCK (rtpsession);
1455 if (rtpsession->priv->stop_thread)
1458 if ((rtcp_src = rtpsession->send_rtcp_src)) {
1459 gst_object_ref (rtcp_src);
1460 GST_RTP_SESSION_UNLOCK (rtpsession);
1462 /* set rtcp caps on output pad */
1463 if (!gst_pad_has_current_caps (rtcp_src))
1464 do_rtcp_events (rtpsession, rtcp_src);
1466 GST_LOG_OBJECT (rtpsession, "sending RTCP");
1467 result = gst_pad_push (rtcp_src, buffer);
1469 /* Forward send an EOS on the RTCP sink if we received an EOS on the
1470 * send_rtp_sink. We don't need to check the recv_rtp_sink since in this
1471 * case the EOS event would already have been sent */
1472 if (all_sources_bye && rtpsession->send_rtp_sink &&
1473 GST_PAD_IS_EOS (rtpsession->send_rtp_sink)) {
1476 GST_LOG_OBJECT (rtpsession, "sending EOS");
1478 event = gst_event_new_eos ();
1479 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1480 gst_pad_push_event (rtcp_src, event);
1482 gst_object_unref (rtcp_src);
1484 GST_RTP_SESSION_UNLOCK (rtpsession);
1486 GST_DEBUG_OBJECT (rtpsession, "not sending RTCP, no output pad");
1487 gst_buffer_unref (buffer);
1488 result = GST_FLOW_OK;
1495 GST_DEBUG_OBJECT (rtpsession, "we are stopping");
1496 gst_buffer_unref (buffer);
1497 GST_RTP_SESSION_UNLOCK (rtpsession);
1502 /* called when the session manager has an SR RTCP packet ready for handling
1503 * inter stream synchronisation */
1504 static GstFlowReturn
1505 gst_rtp_session_sync_rtcp (RTPSession * sess,
1506 GstBuffer * buffer, gpointer user_data)
1508 GstFlowReturn result;
1509 GstRtpSession *rtpsession;
1512 rtpsession = GST_RTP_SESSION (user_data);
1514 GST_RTP_SESSION_LOCK (rtpsession);
1515 if (rtpsession->priv->stop_thread)
1518 if ((sync_src = rtpsession->sync_src)) {
1519 gst_object_ref (sync_src);
1520 GST_RTP_SESSION_UNLOCK (rtpsession);
1522 /* set rtcp caps on output pad, this happens
1523 * when we receive RTCP muxed with RTP according
1524 * to RFC5761. Otherwise we would have forwarded
1525 * the events from the recv_rtcp_sink pad already
1527 if (!gst_pad_has_current_caps (sync_src))
1528 do_rtcp_events (rtpsession, sync_src);
1530 GST_LOG_OBJECT (rtpsession, "sending Sync RTCP");
1531 result = gst_pad_push (sync_src, buffer);
1532 gst_object_unref (sync_src);
1534 GST_RTP_SESSION_UNLOCK (rtpsession);
1536 GST_DEBUG_OBJECT (rtpsession, "not sending Sync RTCP, no output pad");
1537 gst_buffer_unref (buffer);
1538 result = GST_FLOW_OK;
1545 GST_DEBUG_OBJECT (rtpsession, "we are stopping");
1546 gst_buffer_unref (buffer);
1547 GST_RTP_SESSION_UNLOCK (rtpsession);
1553 gst_rtp_session_cache_caps (GstRtpSession * rtpsession, GstCaps * caps)
1555 GstRtpSessionPrivate *priv;
1556 const GstStructure *s;
1559 priv = rtpsession->priv;
1561 GST_DEBUG_OBJECT (rtpsession, "parsing caps");
1563 s = gst_caps_get_structure (caps, 0);
1564 if (!gst_structure_get_int (s, "payload", &payload))
1567 if (g_hash_table_lookup (priv->ptmap, GINT_TO_POINTER (payload)))
1570 g_hash_table_insert (priv->ptmap, GINT_TO_POINTER (payload),
1571 gst_caps_ref (caps));
1575 gst_rtp_session_get_caps_for_pt (GstRtpSession * rtpsession, guint payload)
1577 GstCaps *caps = NULL;
1578 GValue args[2] = { {0}, {0} };
1581 GST_RTP_SESSION_LOCK (rtpsession);
1582 caps = g_hash_table_lookup (rtpsession->priv->ptmap,
1583 GINT_TO_POINTER (payload));
1585 gst_caps_ref (caps);
1589 /* not found in the cache, try to get it with a signal */
1590 g_value_init (&args[0], GST_TYPE_ELEMENT);
1591 g_value_set_object (&args[0], rtpsession);
1592 g_value_init (&args[1], G_TYPE_UINT);
1593 g_value_set_uint (&args[1], payload);
1595 g_value_init (&ret, GST_TYPE_CAPS);
1596 g_value_set_boxed (&ret, NULL);
1598 GST_RTP_SESSION_UNLOCK (rtpsession);
1600 g_signal_emitv (args, gst_rtp_session_signals[SIGNAL_REQUEST_PT_MAP], 0,
1603 GST_RTP_SESSION_LOCK (rtpsession);
1605 g_value_unset (&args[0]);
1606 g_value_unset (&args[1]);
1607 caps = (GstCaps *) g_value_dup_boxed (&ret);
1608 g_value_unset (&ret);
1612 gst_rtp_session_cache_caps (rtpsession, caps);
1615 GST_RTP_SESSION_UNLOCK (rtpsession);
1621 GST_DEBUG_OBJECT (rtpsession, "could not get caps");
1626 /* called when the session manager needs the clock rate */
1628 gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
1632 GstRtpSession *rtpsession;
1634 const GstStructure *s;
1636 rtpsession = GST_RTP_SESSION_CAST (user_data);
1638 caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload);
1643 s = gst_caps_get_structure (caps, 0);
1644 if (!gst_structure_get_int (s, "clock-rate", &result))
1647 gst_caps_unref (caps);
1649 GST_DEBUG_OBJECT (rtpsession, "parsed clock-rate %d", result);
1658 gst_caps_unref (caps);
1659 GST_DEBUG_OBJECT (rtpsession, "No clock-rate in caps!");
1664 /* called when the session manager asks us to reconsider the timeout */
1666 gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data)
1668 GstRtpSession *rtpsession;
1670 rtpsession = GST_RTP_SESSION_CAST (user_data);
1672 GST_RTP_SESSION_LOCK (rtpsession);
1673 GST_DEBUG_OBJECT (rtpsession, "unlock timer for reconsideration");
1674 if (rtpsession->priv->id)
1675 gst_clock_id_unschedule (rtpsession->priv->id);
1676 GST_RTP_SESSION_UNLOCK (rtpsession);
1680 gst_rtp_session_event_recv_rtp_sink (GstPad * pad, GstObject * parent,
1683 GstRtpSession *rtpsession;
1684 gboolean ret = FALSE;
1686 rtpsession = GST_RTP_SESSION (parent);
1688 GST_DEBUG_OBJECT (rtpsession, "received event %s",
1689 GST_EVENT_TYPE_NAME (event));
1691 switch (GST_EVENT_TYPE (event)) {
1692 case GST_EVENT_CAPS:
1697 gst_event_parse_caps (event, &caps);
1698 gst_rtp_session_sink_setcaps (pad, rtpsession, caps);
1699 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1702 case GST_EVENT_FLUSH_STOP:
1703 gst_segment_init (&rtpsession->recv_rtp_seg, GST_FORMAT_UNDEFINED);
1704 rtpsession->recv_rtcp_segment_seqnum = GST_SEQNUM_INVALID;
1705 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1707 case GST_EVENT_SEGMENT:
1709 GstSegment *segment, in_segment;
1711 segment = &rtpsession->recv_rtp_seg;
1713 /* the newsegment event is needed to convert the RTP timestamp to
1714 * running_time, which is needed to generate a mapping from RTP to NTP
1715 * timestamps in SR reports */
1716 gst_event_copy_segment (event, &in_segment);
1717 GST_DEBUG_OBJECT (rtpsession, "received segment %" GST_SEGMENT_FORMAT,
1720 /* accept upstream */
1721 gst_segment_copy_into (&in_segment, segment);
1723 /* push event forward */
1724 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1732 gst_pad_push_event (rtpsession->recv_rtp_src, gst_event_ref (event));
1734 GST_RTP_SESSION_LOCK (rtpsession);
1735 if ((rtcp_src = rtpsession->send_rtcp_src))
1736 gst_object_ref (rtcp_src);
1737 GST_RTP_SESSION_UNLOCK (rtpsession);
1739 gst_event_unref (event);
1742 event = gst_event_new_eos ();
1743 if (rtpsession->recv_rtcp_segment_seqnum != GST_SEQNUM_INVALID)
1744 gst_event_set_seqnum (event, rtpsession->recv_rtcp_segment_seqnum);
1745 ret = gst_pad_push_event (rtcp_src, event);
1746 gst_object_unref (rtcp_src);
1753 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1762 gst_rtp_session_request_remote_key_unit (GstRtpSession * rtpsession,
1763 guint32 ssrc, guint payload, gboolean all_headers, gint count)
1767 caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload);
1770 const GstStructure *s = gst_caps_get_structure (caps, 0);
1774 pli = gst_structure_has_field (s, "rtcp-fb-nack-pli");
1775 fir = gst_structure_has_field (s, "rtcp-fb-ccm-fir") && all_headers;
1777 /* Google Talk uses FIR for repair, so send it even if we just want a
1780 gst_structure_has_field (s, "rtcp-fb-x-gstreamer-fir-as-repair"))
1783 gst_caps_unref (caps);
1786 return rtp_session_request_key_unit (rtpsession->priv->session, ssrc,
1794 gst_rtp_session_event_recv_rtp_src (GstPad * pad, GstObject * parent,
1797 GstRtpSession *rtpsession;
1798 gboolean forward = TRUE;
1799 gboolean ret = TRUE;
1800 const GstStructure *s;
1804 rtpsession = GST_RTP_SESSION (parent);
1806 switch (GST_EVENT_TYPE (event)) {
1807 case GST_EVENT_CUSTOM_UPSTREAM:
1808 s = gst_event_get_structure (event);
1809 if (gst_structure_has_name (s, "GstForceKeyUnit") &&
1810 gst_structure_get_uint (s, "ssrc", &ssrc) &&
1811 gst_structure_get_uint (s, "payload", &pt)) {
1812 gboolean all_headers = FALSE;
1815 gst_structure_get_boolean (s, "all-headers", &all_headers);
1816 if (gst_structure_get_int (s, "count", &count) && count < 0)
1817 count += G_MAXINT; /* Make sure count is positive if present */
1818 if (gst_rtp_session_request_remote_key_unit (rtpsession, ssrc, pt,
1819 all_headers, count))
1821 } else if (gst_structure_has_name (s, "GstRTPRetransmissionRequest")) {
1822 guint seqnum, delay, deadline, max_delay, avg_rtt;
1824 GST_RTP_SESSION_LOCK (rtpsession);
1825 rtpsession->priv->recv_rtx_req_count++;
1826 GST_RTP_SESSION_UNLOCK (rtpsession);
1828 if (!gst_structure_get_uint (s, "ssrc", &ssrc))
1830 if (!gst_structure_get_uint (s, "seqnum", &seqnum))
1832 if (!gst_structure_get_uint (s, "delay", &delay))
1834 if (!gst_structure_get_uint (s, "deadline", &deadline))
1836 if (!gst_structure_get_uint (s, "avg-rtt", &avg_rtt))
1839 /* remaining time to receive the packet */
1840 max_delay = deadline;
1841 if (max_delay > delay)
1844 if (max_delay > avg_rtt)
1845 max_delay -= avg_rtt;
1849 if (rtp_session_request_nack (rtpsession->priv->session, ssrc, seqnum,
1850 max_delay * GST_MSECOND))
1859 GstPad *recv_rtp_sink;
1861 GST_RTP_SESSION_LOCK (rtpsession);
1862 if ((recv_rtp_sink = rtpsession->recv_rtp_sink))
1863 gst_object_ref (recv_rtp_sink);
1864 GST_RTP_SESSION_UNLOCK (rtpsession);
1866 if (recv_rtp_sink) {
1867 ret = gst_pad_push_event (recv_rtp_sink, event);
1868 gst_object_unref (recv_rtp_sink);
1870 gst_event_unref (event);
1872 gst_event_unref (event);
1879 static GstIterator *
1880 gst_rtp_session_iterate_internal_links (GstPad * pad, GstObject * parent)
1882 GstRtpSession *rtpsession;
1883 GstPad *otherpad = NULL;
1884 GstIterator *it = NULL;
1886 rtpsession = GST_RTP_SESSION (parent);
1888 GST_RTP_SESSION_LOCK (rtpsession);
1889 if (pad == rtpsession->recv_rtp_src) {
1890 otherpad = gst_object_ref (rtpsession->recv_rtp_sink);
1891 } else if (pad == rtpsession->recv_rtp_sink) {
1892 otherpad = gst_object_ref (rtpsession->recv_rtp_src);
1893 } else if (pad == rtpsession->send_rtp_src) {
1894 otherpad = gst_object_ref (rtpsession->send_rtp_sink);
1895 } else if (pad == rtpsession->send_rtp_sink) {
1896 otherpad = gst_object_ref (rtpsession->send_rtp_src);
1898 GST_RTP_SESSION_UNLOCK (rtpsession);
1901 GValue val = { 0, };
1903 g_value_init (&val, GST_TYPE_PAD);
1904 g_value_set_object (&val, otherpad);
1905 it = gst_iterator_new_single (GST_TYPE_PAD, &val);
1906 g_value_unset (&val);
1907 gst_object_unref (otherpad);
1909 it = gst_iterator_new_single (GST_TYPE_PAD, NULL);
1916 gst_rtp_session_sink_setcaps (GstPad * pad, GstRtpSession * rtpsession,
1919 GST_RTP_SESSION_LOCK (rtpsession);
1920 gst_rtp_session_cache_caps (rtpsession, caps);
1921 GST_RTP_SESSION_UNLOCK (rtpsession);
1926 /* receive a packet from a sender, send it to the RTP session manager and
1927 * forward the packet on the rtp_src pad
1929 static GstFlowReturn
1930 gst_rtp_session_chain_recv_rtp (GstPad * pad, GstObject * parent,
1933 GstRtpSession *rtpsession;
1934 GstRtpSessionPrivate *priv;
1936 GstClockTime current_time, running_time;
1937 GstClockTime timestamp;
1940 rtpsession = GST_RTP_SESSION (parent);
1941 priv = rtpsession->priv;
1943 GST_LOG_OBJECT (rtpsession, "received RTP packet");
1945 GST_RTP_SESSION_LOCK (rtpsession);
1946 signal_waiting_rtcp_thread_unlocked (rtpsession);
1947 GST_RTP_SESSION_UNLOCK (rtpsession);
1949 /* get NTP time when this packet was captured, this depends on the timestamp. */
1950 timestamp = GST_BUFFER_PTS (buffer);
1951 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1952 /* convert to running time using the segment values */
1954 gst_segment_to_running_time (&rtpsession->recv_rtp_seg, GST_FORMAT_TIME,
1956 ntpnstime = GST_CLOCK_TIME_NONE;
1958 get_current_times (rtpsession, &running_time, &ntpnstime);
1960 current_time = gst_clock_get_time (priv->sysclock);
1962 ret = rtp_session_process_rtp (priv->session, buffer, current_time,
1963 running_time, ntpnstime);
1964 if (ret != GST_FLOW_OK)
1974 GST_DEBUG_OBJECT (rtpsession, "process returned %s",
1975 gst_flow_get_name (ret));
1981 gst_rtp_session_event_recv_rtcp_sink (GstPad * pad, GstObject * parent,
1984 GstRtpSession *rtpsession;
1985 gboolean ret = FALSE;
1987 rtpsession = GST_RTP_SESSION (parent);
1989 GST_DEBUG_OBJECT (rtpsession, "received event %s",
1990 GST_EVENT_TYPE_NAME (event));
1992 switch (GST_EVENT_TYPE (event)) {
1993 case GST_EVENT_SEGMENT:
1994 /* Make sure that the sync_src pad has caps before the segment event.
1995 * Otherwise we might get a segment event before caps from the receive
1996 * RTCP pad, and then later when receiving RTCP packets will set caps.
1997 * This will results in a sticky event misordering warning
1999 if (!gst_pad_has_current_caps (rtpsession->sync_src)) {
2000 GstCaps *caps = gst_caps_new_empty_simple ("application/x-rtcp");
2001 gst_pad_set_caps (rtpsession->sync_src, caps);
2002 gst_caps_unref (caps);
2006 ret = gst_pad_push_event (rtpsession->sync_src, event);
2013 /* Receive an RTCP packet from a sender, send it to the RTP session manager and
2014 * forward the SR packets to the sync_src pad.
2016 static GstFlowReturn
2017 gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstObject * parent,
2020 GstRtpSession *rtpsession;
2021 GstRtpSessionPrivate *priv;
2022 GstClockTime current_time;
2023 GstClockTime running_time;
2026 rtpsession = GST_RTP_SESSION (parent);
2027 priv = rtpsession->priv;
2029 GST_LOG_OBJECT (rtpsession, "received RTCP packet");
2031 GST_RTP_SESSION_LOCK (rtpsession);
2032 signal_waiting_rtcp_thread_unlocked (rtpsession);
2033 GST_RTP_SESSION_UNLOCK (rtpsession);
2035 current_time = gst_clock_get_time (priv->sysclock);
2036 get_current_times (rtpsession, &running_time, &ntpnstime);
2038 rtp_session_process_rtcp (priv->session, buffer, current_time, running_time,
2041 return GST_FLOW_OK; /* always return OK */
2045 gst_rtp_session_query_send_rtcp_src (GstPad * pad, GstObject * parent,
2048 GstRtpSession *rtpsession;
2049 gboolean ret = FALSE;
2051 rtpsession = GST_RTP_SESSION (parent);
2053 GST_DEBUG_OBJECT (rtpsession, "received QUERY %s",
2054 GST_QUERY_TYPE_NAME (query));
2056 switch (GST_QUERY_TYPE (query)) {
2057 case GST_QUERY_LATENCY:
2059 /* use the defaults for the latency query. */
2060 gst_query_set_latency (query, FALSE, 0, -1);
2063 /* other queries simply fail for now */
2071 gst_rtp_session_event_send_rtcp_src (GstPad * pad, GstObject * parent,
2074 GstRtpSession *rtpsession;
2075 gboolean ret = TRUE;
2077 rtpsession = GST_RTP_SESSION (parent);
2078 GST_DEBUG_OBJECT (rtpsession, "received EVENT %s",
2079 GST_EVENT_TYPE_NAME (event));
2081 switch (GST_EVENT_TYPE (event)) {
2082 case GST_EVENT_SEEK:
2083 case GST_EVENT_LATENCY:
2084 gst_event_unref (event);
2088 /* other events simply fail for now */
2089 gst_event_unref (event);
2099 gst_rtp_session_event_send_rtp_sink (GstPad * pad, GstObject * parent,
2102 GstRtpSession *rtpsession;
2103 gboolean ret = FALSE;
2105 rtpsession = GST_RTP_SESSION (parent);
2107 GST_DEBUG_OBJECT (rtpsession, "received EVENT %s",
2108 GST_EVENT_TYPE_NAME (event));
2110 switch (GST_EVENT_TYPE (event)) {
2111 case GST_EVENT_CAPS:
2116 gst_event_parse_caps (event, &caps);
2117 gst_rtp_session_setcaps_send_rtp (pad, rtpsession, caps);
2118 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2121 case GST_EVENT_FLUSH_STOP:
2122 gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
2123 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2125 case GST_EVENT_SEGMENT:{
2126 GstSegment *segment, in_segment;
2128 segment = &rtpsession->send_rtp_seg;
2130 /* the newsegment event is needed to convert the RTP timestamp to
2131 * running_time, which is needed to generate a mapping from RTP to NTP
2132 * timestamps in SR reports */
2133 gst_event_copy_segment (event, &in_segment);
2134 GST_DEBUG_OBJECT (rtpsession, "received segment %" GST_SEGMENT_FORMAT,
2137 /* accept upstream */
2138 gst_segment_copy_into (&in_segment, segment);
2140 /* push event forward */
2141 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2144 case GST_EVENT_EOS:{
2145 GstClockTime current_time;
2147 /* push downstream FIXME, we are not supposed to leave the session just
2148 * because we stop sending. */
2149 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
2150 current_time = gst_clock_get_time (rtpsession->priv->sysclock);
2152 GST_DEBUG_OBJECT (rtpsession, "scheduling BYE message");
2153 rtp_session_mark_all_bye (rtpsession->priv->session, "End Of Stream");
2154 rtp_session_schedule_bye (rtpsession->priv->session, current_time);
2158 GstPad *send_rtp_src;
2160 GST_RTP_SESSION_LOCK (rtpsession);
2161 if ((send_rtp_src = rtpsession->send_rtp_src))
2162 gst_object_ref (send_rtp_src);
2163 GST_RTP_SESSION_UNLOCK (rtpsession);
2166 ret = gst_pad_push_event (send_rtp_src, event);
2167 gst_object_unref (send_rtp_src);
2169 gst_event_unref (event);
2179 gst_rtp_session_event_send_rtp_src (GstPad * pad, GstObject * parent,
2182 GstRtpSession *rtpsession;
2183 gboolean ret = FALSE;
2185 rtpsession = GST_RTP_SESSION (parent);
2187 GST_DEBUG_OBJECT (rtpsession, "received EVENT %s",
2188 GST_EVENT_TYPE_NAME (event));
2190 switch (GST_EVENT_TYPE (event)) {
2191 case GST_EVENT_LATENCY:
2192 /* save the latency, we need this to know when an RTP packet will be
2193 * rendered by the sink */
2194 gst_event_parse_latency (event, &rtpsession->priv->send_latency);
2196 ret = gst_pad_event_default (pad, parent, event);
2199 ret = gst_pad_event_default (pad, parent, event);
2206 gst_rtp_session_getcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
2209 GstRtpSessionPrivate *priv;
2211 GstStructure *s1, *s2;
2215 priv = rtpsession->priv;
2217 ssrc = rtp_session_suggest_ssrc (priv->session, &is_random);
2219 /* we can basically accept anything but we prefer to receive packets with our
2220 * internal SSRC so that we don't have to patch it. Create a structure with
2221 * the SSRC and another one without.
2222 * Only do this if the session actually decided on an ssrc already,
2223 * otherwise we give upstream the opportunity to select an ssrc itself */
2225 s1 = gst_structure_new ("application/x-rtp", "ssrc", G_TYPE_UINT, ssrc,
2227 s2 = gst_structure_new_empty ("application/x-rtp");
2229 result = gst_caps_new_full (s1, s2, NULL);
2231 result = gst_caps_new_empty_simple ("application/x-rtp");
2235 GstCaps *caps = result;
2237 result = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2238 gst_caps_unref (caps);
2241 GST_DEBUG_OBJECT (rtpsession, "getting caps %" GST_PTR_FORMAT, result);
2247 gst_rtp_session_query_send_rtp (GstPad * pad, GstObject * parent,
2250 gboolean res = FALSE;
2251 GstRtpSession *rtpsession;
2253 rtpsession = GST_RTP_SESSION (parent);
2255 switch (GST_QUERY_TYPE (query)) {
2256 case GST_QUERY_CAPS:
2258 GstCaps *filter, *caps;
2260 gst_query_parse_caps (query, &filter);
2261 caps = gst_rtp_session_getcaps_send_rtp (pad, rtpsession, filter);
2262 gst_query_set_caps_result (query, caps);
2263 gst_caps_unref (caps);
2268 res = gst_pad_query_default (pad, parent, query);
2276 gst_rtp_session_setcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
2279 GstRtpSessionPrivate *priv;
2281 priv = rtpsession->priv;
2283 rtp_session_update_send_caps (priv->session, caps);
2288 /* Receive an RTP packet or a list of packets to be sent to the receivers,
2289 * send to RTP session manager and forward to send_rtp_src.
2291 static GstFlowReturn
2292 gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
2293 gpointer data, gboolean is_list)
2295 GstRtpSessionPrivate *priv;
2297 GstClockTime timestamp, running_time;
2298 GstClockTime current_time;
2300 priv = rtpsession->priv;
2302 GST_LOG_OBJECT (rtpsession, "received RTP %s", is_list ? "list" : "packet");
2304 /* get NTP time when this packet was captured, this depends on the timestamp. */
2306 GstBuffer *buffer = NULL;
2308 /* All buffers in a list have the same timestamp.
2309 * So, just take it from the first buffer. */
2310 buffer = gst_buffer_list_get (GST_BUFFER_LIST_CAST (data), 0);
2312 timestamp = GST_BUFFER_PTS (buffer);
2316 timestamp = GST_BUFFER_PTS (GST_BUFFER_CAST (data));
2319 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
2320 /* convert to running time using the segment start value. */
2322 gst_segment_to_running_time (&rtpsession->send_rtp_seg, GST_FORMAT_TIME,
2324 if (priv->rtcp_sync_send_time)
2325 running_time += priv->send_latency;
2331 current_time = gst_clock_get_time (priv->sysclock);
2332 ret = rtp_session_send_rtp (priv->session, data, is_list, current_time,
2334 if (ret != GST_FLOW_OK)
2344 GST_DEBUG_OBJECT (rtpsession, "process returned %s",
2345 gst_flow_get_name (ret));
2350 static GstFlowReturn
2351 gst_rtp_session_chain_send_rtp (GstPad * pad, GstObject * parent,
2354 GstRtpSession *rtpsession = GST_RTP_SESSION (parent);
2356 return gst_rtp_session_chain_send_rtp_common (rtpsession, buffer, FALSE);
2359 static GstFlowReturn
2360 gst_rtp_session_chain_send_rtp_list (GstPad * pad, GstObject * parent,
2361 GstBufferList * list)
2363 GstRtpSession *rtpsession = GST_RTP_SESSION (parent);
2365 return gst_rtp_session_chain_send_rtp_common (rtpsession, list, TRUE);
2368 /* Create sinkpad to receive RTP packets from senders. This will also create a
2369 * srcpad for the RTP packets.
2372 create_recv_rtp_sink (GstRtpSession * rtpsession)
2374 GST_DEBUG_OBJECT (rtpsession, "creating RTP sink pad");
2376 rtpsession->recv_rtp_sink =
2377 gst_pad_new_from_static_template (&rtpsession_recv_rtp_sink_template,
2379 gst_pad_set_chain_function (rtpsession->recv_rtp_sink,
2380 gst_rtp_session_chain_recv_rtp);
2381 gst_pad_set_event_function (rtpsession->recv_rtp_sink,
2382 gst_rtp_session_event_recv_rtp_sink);
2383 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtp_sink,
2384 gst_rtp_session_iterate_internal_links);
2385 GST_PAD_SET_PROXY_ALLOCATION (rtpsession->recv_rtp_sink);
2386 gst_pad_set_active (rtpsession->recv_rtp_sink, TRUE);
2387 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2388 rtpsession->recv_rtp_sink);
2390 GST_DEBUG_OBJECT (rtpsession, "creating RTP src pad");
2391 rtpsession->recv_rtp_src =
2392 gst_pad_new_from_static_template (&rtpsession_recv_rtp_src_template,
2394 gst_pad_set_event_function (rtpsession->recv_rtp_src,
2395 gst_rtp_session_event_recv_rtp_src);
2396 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtp_src,
2397 gst_rtp_session_iterate_internal_links);
2398 gst_pad_use_fixed_caps (rtpsession->recv_rtp_src);
2399 gst_pad_set_active (rtpsession->recv_rtp_src, TRUE);
2400 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->recv_rtp_src);
2402 return rtpsession->recv_rtp_sink;
2405 /* Remove sinkpad to receive RTP packets from senders. This will also remove
2406 * the srcpad for the RTP packets.
2409 remove_recv_rtp_sink (GstRtpSession * rtpsession)
2411 GST_DEBUG_OBJECT (rtpsession, "removing RTP sink pad");
2413 /* deactivate from source to sink */
2414 gst_pad_set_active (rtpsession->recv_rtp_src, FALSE);
2415 gst_pad_set_active (rtpsession->recv_rtp_sink, FALSE);
2418 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2419 rtpsession->recv_rtp_sink);
2420 rtpsession->recv_rtp_sink = NULL;
2422 GST_DEBUG_OBJECT (rtpsession, "removing RTP src pad");
2423 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2424 rtpsession->recv_rtp_src);
2425 rtpsession->recv_rtp_src = NULL;
2428 /* Create a sinkpad to receive RTCP messages from senders, this will also create a
2429 * sync_src pad for the SR packets.
2432 create_recv_rtcp_sink (GstRtpSession * rtpsession)
2434 GST_DEBUG_OBJECT (rtpsession, "creating RTCP sink pad");
2436 rtpsession->recv_rtcp_sink =
2437 gst_pad_new_from_static_template (&rtpsession_recv_rtcp_sink_template,
2439 gst_pad_set_chain_function (rtpsession->recv_rtcp_sink,
2440 gst_rtp_session_chain_recv_rtcp);
2441 gst_pad_set_event_function (rtpsession->recv_rtcp_sink,
2442 gst_rtp_session_event_recv_rtcp_sink);
2443 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtcp_sink,
2444 gst_rtp_session_iterate_internal_links);
2445 gst_pad_set_active (rtpsession->recv_rtcp_sink, TRUE);
2446 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2447 rtpsession->recv_rtcp_sink);
2449 GST_DEBUG_OBJECT (rtpsession, "creating sync src pad");
2450 rtpsession->sync_src =
2451 gst_pad_new_from_static_template (&rtpsession_sync_src_template,
2453 gst_pad_set_iterate_internal_links_function (rtpsession->sync_src,
2454 gst_rtp_session_iterate_internal_links);
2455 gst_pad_use_fixed_caps (rtpsession->sync_src);
2456 gst_pad_set_active (rtpsession->sync_src, TRUE);
2457 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->sync_src);
2459 return rtpsession->recv_rtcp_sink;
2463 remove_recv_rtcp_sink (GstRtpSession * rtpsession)
2465 GST_DEBUG_OBJECT (rtpsession, "removing RTCP sink pad");
2467 gst_pad_set_active (rtpsession->sync_src, FALSE);
2468 gst_pad_set_active (rtpsession->recv_rtcp_sink, FALSE);
2470 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2471 rtpsession->recv_rtcp_sink);
2472 rtpsession->recv_rtcp_sink = NULL;
2474 GST_DEBUG_OBJECT (rtpsession, "removing sync src pad");
2475 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->sync_src);
2476 rtpsession->sync_src = NULL;
2479 /* Create a sinkpad to receive RTP packets for receivers. This will also create a
2483 create_send_rtp_sink (GstRtpSession * rtpsession)
2485 GST_DEBUG_OBJECT (rtpsession, "creating pad");
2487 rtpsession->send_rtp_sink =
2488 gst_pad_new_from_static_template (&rtpsession_send_rtp_sink_template,
2490 gst_pad_set_chain_function (rtpsession->send_rtp_sink,
2491 gst_rtp_session_chain_send_rtp);
2492 gst_pad_set_chain_list_function (rtpsession->send_rtp_sink,
2493 gst_rtp_session_chain_send_rtp_list);
2494 gst_pad_set_query_function (rtpsession->send_rtp_sink,
2495 gst_rtp_session_query_send_rtp);
2496 gst_pad_set_event_function (rtpsession->send_rtp_sink,
2497 gst_rtp_session_event_send_rtp_sink);
2498 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtp_sink,
2499 gst_rtp_session_iterate_internal_links);
2500 GST_PAD_SET_PROXY_CAPS (rtpsession->send_rtp_sink);
2501 GST_PAD_SET_PROXY_ALLOCATION (rtpsession->send_rtp_sink);
2502 gst_pad_set_active (rtpsession->send_rtp_sink, TRUE);
2503 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2504 rtpsession->send_rtp_sink);
2506 rtpsession->send_rtp_src =
2507 gst_pad_new_from_static_template (&rtpsession_send_rtp_src_template,
2509 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtp_src,
2510 gst_rtp_session_iterate_internal_links);
2511 gst_pad_set_event_function (rtpsession->send_rtp_src,
2512 gst_rtp_session_event_send_rtp_src);
2513 GST_PAD_SET_PROXY_CAPS (rtpsession->send_rtp_src);
2514 gst_pad_set_active (rtpsession->send_rtp_src, TRUE);
2515 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->send_rtp_src);
2517 return rtpsession->send_rtp_sink;
2521 remove_send_rtp_sink (GstRtpSession * rtpsession)
2523 GST_DEBUG_OBJECT (rtpsession, "removing pad");
2525 gst_pad_set_active (rtpsession->send_rtp_src, FALSE);
2526 gst_pad_set_active (rtpsession->send_rtp_sink, FALSE);
2528 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2529 rtpsession->send_rtp_sink);
2530 rtpsession->send_rtp_sink = NULL;
2532 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2533 rtpsession->send_rtp_src);
2534 rtpsession->send_rtp_src = NULL;
2537 /* Create a srcpad with the RTCP packets to send out.
2538 * This pad will be driven by the RTP session manager when it wants to send out
2542 create_send_rtcp_src (GstRtpSession * rtpsession)
2544 GST_DEBUG_OBJECT (rtpsession, "creating pad");
2546 rtpsession->send_rtcp_src =
2547 gst_pad_new_from_static_template (&rtpsession_send_rtcp_src_template,
2549 gst_pad_use_fixed_caps (rtpsession->send_rtcp_src);
2550 gst_pad_set_active (rtpsession->send_rtcp_src, TRUE);
2551 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtcp_src,
2552 gst_rtp_session_iterate_internal_links);
2553 gst_pad_set_query_function (rtpsession->send_rtcp_src,
2554 gst_rtp_session_query_send_rtcp_src);
2555 gst_pad_set_event_function (rtpsession->send_rtcp_src,
2556 gst_rtp_session_event_send_rtcp_src);
2557 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2558 rtpsession->send_rtcp_src);
2560 return rtpsession->send_rtcp_src;
2564 remove_send_rtcp_src (GstRtpSession * rtpsession)
2566 GST_DEBUG_OBJECT (rtpsession, "removing pad");
2568 gst_pad_set_active (rtpsession->send_rtcp_src, FALSE);
2570 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2571 rtpsession->send_rtcp_src);
2572 rtpsession->send_rtcp_src = NULL;
2576 gst_rtp_session_request_new_pad (GstElement * element,
2577 GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
2579 GstRtpSession *rtpsession;
2580 GstElementClass *klass;
2583 g_return_val_if_fail (templ != NULL, NULL);
2584 g_return_val_if_fail (GST_IS_RTP_SESSION (element), NULL);
2586 rtpsession = GST_RTP_SESSION (element);
2587 klass = GST_ELEMENT_GET_CLASS (element);
2589 GST_DEBUG_OBJECT (element, "requesting pad %s", GST_STR_NULL (name));
2591 GST_RTP_SESSION_LOCK (rtpsession);
2593 /* figure out the template */
2594 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink")) {
2595 if (rtpsession->recv_rtp_sink != NULL)
2598 result = create_recv_rtp_sink (rtpsession);
2599 } else if (templ == gst_element_class_get_pad_template (klass,
2600 "recv_rtcp_sink")) {
2601 if (rtpsession->recv_rtcp_sink != NULL)
2604 result = create_recv_rtcp_sink (rtpsession);
2605 } else if (templ == gst_element_class_get_pad_template (klass,
2607 if (rtpsession->send_rtp_sink != NULL)
2610 result = create_send_rtp_sink (rtpsession);
2611 } else if (templ == gst_element_class_get_pad_template (klass,
2613 if (rtpsession->send_rtcp_src != NULL)
2616 result = create_send_rtcp_src (rtpsession);
2618 goto wrong_template;
2620 GST_RTP_SESSION_UNLOCK (rtpsession);
2627 GST_RTP_SESSION_UNLOCK (rtpsession);
2628 g_warning ("rtpsession: this is not our template");
2633 GST_RTP_SESSION_UNLOCK (rtpsession);
2634 g_warning ("rtpsession: pad already requested");
2640 gst_rtp_session_release_pad (GstElement * element, GstPad * pad)
2642 GstRtpSession *rtpsession;
2644 g_return_if_fail (GST_IS_RTP_SESSION (element));
2645 g_return_if_fail (GST_IS_PAD (pad));
2647 rtpsession = GST_RTP_SESSION (element);
2649 GST_DEBUG_OBJECT (element, "releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2651 GST_RTP_SESSION_LOCK (rtpsession);
2653 if (rtpsession->recv_rtp_sink == pad) {
2654 remove_recv_rtp_sink (rtpsession);
2655 } else if (rtpsession->recv_rtcp_sink == pad) {
2656 remove_recv_rtcp_sink (rtpsession);
2657 } else if (rtpsession->send_rtp_sink == pad) {
2658 remove_send_rtp_sink (rtpsession);
2659 } else if (rtpsession->send_rtcp_src == pad) {
2660 remove_send_rtcp_src (rtpsession);
2664 GST_RTP_SESSION_UNLOCK (rtpsession);
2671 GST_RTP_SESSION_UNLOCK (rtpsession);
2672 g_warning ("rtpsession: asked to release an unknown pad");
2678 gst_rtp_session_request_key_unit (RTPSession * sess,
2679 guint32 ssrc, gboolean all_headers, gpointer user_data)
2681 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2683 GstPad *send_rtp_sink;
2685 GST_RTP_SESSION_LOCK (rtpsession);
2686 if ((send_rtp_sink = rtpsession->send_rtp_sink))
2687 gst_object_ref (send_rtp_sink);
2688 GST_RTP_SESSION_UNLOCK (rtpsession);
2690 if (send_rtp_sink) {
2691 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
2692 gst_structure_new ("GstForceKeyUnit", "ssrc", G_TYPE_UINT, ssrc,
2693 "all-headers", G_TYPE_BOOLEAN, all_headers, NULL));
2694 gst_pad_push_event (send_rtp_sink, event);
2695 gst_object_unref (send_rtp_sink);
2700 gst_rtp_session_request_time (RTPSession * session, gpointer user_data)
2702 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2704 return gst_clock_get_time (rtpsession->priv->sysclock);
2708 gst_rtp_session_notify_nack (RTPSession * sess, guint16 seqnum,
2709 guint16 blp, guint32 ssrc, gpointer user_data)
2711 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2713 GstPad *send_rtp_sink;
2715 GST_RTP_SESSION_LOCK (rtpsession);
2716 if ((send_rtp_sink = rtpsession->send_rtp_sink))
2717 gst_object_ref (send_rtp_sink);
2718 GST_RTP_SESSION_UNLOCK (rtpsession);
2720 if (send_rtp_sink) {
2722 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
2723 gst_structure_new ("GstRTPRetransmissionRequest",
2724 "seqnum", G_TYPE_UINT, (guint) seqnum,
2725 "ssrc", G_TYPE_UINT, (guint) ssrc, NULL));
2726 gst_pad_push_event (send_rtp_sink, event);
2728 GST_RTP_SESSION_LOCK (rtpsession);
2729 rtpsession->priv->sent_rtx_req_count++;
2730 GST_RTP_SESSION_UNLOCK (rtpsession);
2736 while ((blp & 1) == 0) {
2742 gst_object_unref (send_rtp_sink);
2747 gst_rtp_session_reconfigure (RTPSession * sess, gpointer user_data)
2749 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2750 GstPad *send_rtp_sink;
2752 GST_RTP_SESSION_LOCK (rtpsession);
2753 if ((send_rtp_sink = rtpsession->send_rtp_sink))
2754 gst_object_ref (send_rtp_sink);
2755 GST_RTP_SESSION_UNLOCK (rtpsession);
2757 if (send_rtp_sink) {
2758 gst_pad_push_event (send_rtp_sink, gst_event_new_reconfigure ());
2759 gst_object_unref (send_rtp_sink);
2764 gst_rtp_session_notify_early_rtcp (RTPSession * sess, gpointer user_data)
2766 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2768 GST_DEBUG_OBJECT (rtpsession, "Notified of early RTCP");
2769 /* with an early RTCP request, we might have to start the RTCP thread */
2770 GST_RTP_SESSION_LOCK (rtpsession);
2771 signal_waiting_rtcp_thread_unlocked (rtpsession);
2772 GST_RTP_SESSION_UNLOCK (rtpsession);