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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:element-gstrtpsession
22 * @see_also: gstrtpjitterbuffer, gstrtpbin, gstrtpptdemux, gstrtpssrcdemux
24 * The RTP session manager models one participant with a 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>
45 * The gstrtpsession will not demux packets based on SSRC or payload type, nor will
46 * it correct for packet reordering and jitter. Use #GstRtpsSrcDemux,
47 * #GstRtpPtDemux and GstRtpJitterBuffer in addition to #GstRtpSession to
48 * perform these tasks. It is usually a good idea to use #GstRtpBin, which
49 * combines all these features in one element.
51 * To use #GstRtpSession as an RTP receiver, request a recv_rtp_sink pad, which will
52 * automatically create recv_rtp_src pad. Data received on the recv_rtp_sink pad
53 * will be processed in the session and after being validated forwarded on the
56 * To also use #GstRtpSession as an RTCP receiver, request a recv_rtcp_sink pad,
57 * which will automatically create a sync_src pad. Packets received on the RTCP
58 * pad will be used by the session manager to update the stats and database of
59 * the other participants. SR packets will be forwarded on the sync_src pad
60 * so that they can be used to perform inter-stream synchronisation when needed.
62 * If you want the session manager to generate and send RTCP packets, request
63 * the send_rtcp_src pad. Packet pushed on this pad contain SR/RR RTCP reports
64 * that should be sent to all participants in the session.
66 * To use #GstRtpSession as a sender, request a send_rtp_sink pad, which will
67 * automatically create a send_rtp_src pad. The session manager will modify the
68 * SSRC in the RTP packets to its own SSRC and wil forward the packets on the
69 * send_rtp_src pad after updating its internal state.
71 * The session manager needs the clock-rate of the payload types it is handling
72 * and will signal the #GstRtpSession::request-pt-map signal when it needs such a
73 * mapping. One can clear the cached values with the #GstRtpSession::clear-pt-map
77 * <title>Example pipelines</title>
79 * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink gstrtpsession .recv_rtp_src ! rtptheoradepay ! theoradec ! xvimagesink
80 * ]| Receive theora RTP packets from port 5000 and send them to the depayloader,
81 * decoder and display. Note that the application/x-rtp caps on udpsrc should be
82 * configured based on some negotiation process such as RTSP for this pipeline
85 * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink gstrtpsession name=session \
86 * .recv_rtp_src ! rtptheoradepay ! theoradec ! xvimagesink \
87 * udpsrc port=5001 caps="application/x-rtcp" ! session.recv_rtcp_sink
88 * ]| Receive theora RTP packets from port 5000 and send them to the depayloader,
89 * decoder and display. Receive RTCP packets from port 5001 and process them in
90 * the session manager.
91 * Note that the application/x-rtp caps on udpsrc should be
92 * configured based on some negotiation process such as RTSP for this pipeline
95 * gst-launch-1.0 videotestsrc ! theoraenc ! rtptheorapay ! .send_rtp_sink gstrtpsession .send_rtp_src ! udpsink port=5000
96 * ]| Send theora RTP packets through the session manager and out on UDP port
99 * gst-launch-1.0 videotestsrc ! theoraenc ! rtptheorapay ! .send_rtp_sink gstrtpsession name=session .send_rtp_src \
100 * ! udpsink port=5000 session.send_rtcp_src ! udpsink port=5001
101 * ]| Send theora RTP packets through the session manager and out on UDP port
102 * 5000. Send RTCP packets on port 5001. Note that this pipeline will not preroll
103 * correctly because the second udpsink will not preroll correctly (no RTCP
104 * packets are sent in the PAUSED state). Applications should manually set and
105 * keep (see gst_element_set_locked_state()) the RTCP udpsink to the PLAYING state.
108 * Last reviewed on 2007-05-28 (0.10.5)
115 #include <gst/rtp/gstrtpbuffer.h>
117 #include <gst/glib-compat-private.h>
119 #include "gstrtpbin-marshal.h"
120 #include "gstrtpsession.h"
121 #include "rtpsession.h"
123 GST_DEBUG_CATEGORY_STATIC (gst_rtp_session_debug);
124 #define GST_CAT_DEFAULT gst_rtp_session_debug
127 static GstStaticPadTemplate rtpsession_recv_rtp_sink_template =
128 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink",
131 GST_STATIC_CAPS ("application/x-rtp")
134 static GstStaticPadTemplate rtpsession_recv_rtcp_sink_template =
135 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink",
138 GST_STATIC_CAPS ("application/x-rtcp")
141 static GstStaticPadTemplate rtpsession_send_rtp_sink_template =
142 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink",
145 GST_STATIC_CAPS ("application/x-rtp")
149 static GstStaticPadTemplate rtpsession_recv_rtp_src_template =
150 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src",
153 GST_STATIC_CAPS ("application/x-rtp")
156 static GstStaticPadTemplate rtpsession_sync_src_template =
157 GST_STATIC_PAD_TEMPLATE ("sync_src",
160 GST_STATIC_CAPS ("application/x-rtcp")
163 static GstStaticPadTemplate rtpsession_send_rtp_src_template =
164 GST_STATIC_PAD_TEMPLATE ("send_rtp_src",
167 GST_STATIC_CAPS ("application/x-rtp")
170 static GstStaticPadTemplate rtpsession_send_rtcp_src_template =
171 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src",
174 GST_STATIC_CAPS ("application/x-rtcp")
177 /* signals and args */
180 SIGNAL_REQUEST_PT_MAP,
184 SIGNAL_ON_SSRC_COLLISION,
185 SIGNAL_ON_SSRC_VALIDATED,
186 SIGNAL_ON_SSRC_ACTIVE,
189 SIGNAL_ON_BYE_TIMEOUT,
191 SIGNAL_ON_SENDER_TIMEOUT,
195 #define DEFAULT_BANDWIDTH RTP_STATS_BANDWIDTH
196 #define DEFAULT_RTCP_FRACTION (RTP_STATS_BANDWIDTH * RTP_STATS_RTCP_FRACTION)
197 #define DEFAULT_RTCP_RR_BANDWIDTH -1
198 #define DEFAULT_RTCP_RS_BANDWIDTH -1
199 #define DEFAULT_SDES NULL
200 #define DEFAULT_NUM_SOURCES 0
201 #define DEFAULT_NUM_ACTIVE_SOURCES 0
202 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
203 #define DEFAULT_RTCP_MIN_INTERVAL (RTP_STATS_MIN_INTERVAL * GST_SECOND)
204 #define DEFAULT_PROBATION RTP_DEFAULT_PROBATION
211 PROP_RTCP_RR_BANDWIDTH,
212 PROP_RTCP_RS_BANDWIDTH,
215 PROP_NUM_ACTIVE_SOURCES,
216 PROP_INTERNAL_SESSION,
217 PROP_USE_PIPELINE_CLOCK,
218 PROP_RTCP_MIN_INTERVAL,
223 #define GST_RTP_SESSION_GET_PRIVATE(obj) \
224 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_SESSION, GstRtpSessionPrivate))
226 #define GST_RTP_SESSION_LOCK(sess) g_mutex_lock (&(sess)->priv->lock)
227 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock (&(sess)->priv->lock)
229 struct _GstRtpSessionPrivate
236 /* thread for sending out RTCP */
238 gboolean stop_thread;
240 gboolean thread_stopped;
245 gboolean use_pipeline_clock;
248 /* callbacks to handle actions from the session manager */
249 static GstFlowReturn gst_rtp_session_process_rtp (RTPSession * sess,
250 RTPSource * src, GstBuffer * buffer, gpointer user_data);
251 static GstFlowReturn gst_rtp_session_send_rtp (RTPSession * sess,
252 RTPSource * src, gpointer data, gpointer user_data);
253 static GstFlowReturn gst_rtp_session_send_rtcp (RTPSession * sess,
254 RTPSource * src, GstBuffer * buffer, gboolean eos, gpointer user_data);
255 static GstFlowReturn gst_rtp_session_sync_rtcp (RTPSession * sess,
256 RTPSource * src, GstBuffer * buffer, gpointer user_data);
257 static gint gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
259 static void gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data);
260 static void gst_rtp_session_request_key_unit (RTPSession * sess,
261 gboolean all_headers, gpointer user_data);
262 static GstClockTime gst_rtp_session_request_time (RTPSession * session,
265 static RTPSessionCallbacks callbacks = {
266 gst_rtp_session_process_rtp,
267 gst_rtp_session_send_rtp,
268 gst_rtp_session_sync_rtcp,
269 gst_rtp_session_send_rtcp,
270 gst_rtp_session_clock_rate,
271 gst_rtp_session_reconsider,
272 gst_rtp_session_request_key_unit,
273 gst_rtp_session_request_time
276 /* GObject vmethods */
277 static void gst_rtp_session_finalize (GObject * object);
278 static void gst_rtp_session_set_property (GObject * object, guint prop_id,
279 const GValue * value, GParamSpec * pspec);
280 static void gst_rtp_session_get_property (GObject * object, guint prop_id,
281 GValue * value, GParamSpec * pspec);
283 /* GstElement vmethods */
284 static GstStateChangeReturn gst_rtp_session_change_state (GstElement * element,
285 GstStateChange transition);
286 static GstPad *gst_rtp_session_request_new_pad (GstElement * element,
287 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
288 static void gst_rtp_session_release_pad (GstElement * element, GstPad * pad);
290 static gboolean gst_rtp_session_sink_setcaps (GstPad * pad,
291 GstRtpSession * rtpsession, GstCaps * caps);
292 static gboolean gst_rtp_session_setcaps_send_rtp (GstPad * pad,
293 GstRtpSession * rtpsession, GstCaps * caps);
295 static void gst_rtp_session_clear_pt_map (GstRtpSession * rtpsession);
297 static guint gst_rtp_session_signals[LAST_SIGNAL] = { 0 };
300 on_new_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
302 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_NEW_SSRC], 0,
307 on_ssrc_collision (RTPSession * session, RTPSource * src, GstRtpSession * sess)
309 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_COLLISION], 0,
314 on_ssrc_validated (RTPSession * session, RTPSource * src, GstRtpSession * sess)
316 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
321 on_ssrc_active (RTPSession * session, RTPSource * src, GstRtpSession * sess)
323 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
328 on_ssrc_sdes (RTPSession * session, RTPSource * src, GstRtpSession * sess)
333 /* convert the new SDES info into a message */
334 RTP_SESSION_LOCK (session);
335 g_object_get (src, "sdes", &s, NULL);
336 RTP_SESSION_UNLOCK (session);
338 m = gst_message_new_custom (GST_MESSAGE_ELEMENT, GST_OBJECT (sess), s);
339 gst_element_post_message (GST_ELEMENT_CAST (sess), m);
341 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SSRC_SDES], 0,
346 on_bye_ssrc (RTPSession * session, RTPSource * src, GstRtpSession * sess)
348 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_BYE_SSRC], 0,
353 on_bye_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
355 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
360 on_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
362 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_TIMEOUT], 0,
367 on_sender_timeout (RTPSession * session, RTPSource * src, GstRtpSession * sess)
369 g_signal_emit (sess, gst_rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
373 #define gst_rtp_session_parent_class parent_class
374 G_DEFINE_TYPE (GstRtpSession, gst_rtp_session, GST_TYPE_ELEMENT);
377 gst_rtp_session_class_init (GstRtpSessionClass * klass)
379 GObjectClass *gobject_class;
380 GstElementClass *gstelement_class;
382 gobject_class = (GObjectClass *) klass;
383 gstelement_class = (GstElementClass *) klass;
385 g_type_class_add_private (klass, sizeof (GstRtpSessionPrivate));
387 gobject_class->finalize = gst_rtp_session_finalize;
388 gobject_class->set_property = gst_rtp_session_set_property;
389 gobject_class->get_property = gst_rtp_session_get_property;
392 * GstRtpSession::request-pt-map:
393 * @sess: the object which received the signal
396 * Request the payload type as #GstCaps for @pt.
398 gst_rtp_session_signals[SIGNAL_REQUEST_PT_MAP] =
399 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
400 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, request_pt_map),
401 NULL, NULL, gst_rtp_bin_marshal_BOXED__UINT, GST_TYPE_CAPS, 1,
404 * GstRtpSession::clear-pt-map:
405 * @sess: the object which received the signal
407 * Clear the cached pt-maps requested with #GstRtpSession::request-pt-map.
409 gst_rtp_session_signals[SIGNAL_CLEAR_PT_MAP] =
410 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
411 G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpSessionClass, clear_pt_map),
412 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
415 * GstRtpSession::on-new-ssrc:
416 * @sess: the object which received the signal
419 * Notify of a new SSRC that entered @session.
421 gst_rtp_session_signals[SIGNAL_ON_NEW_SSRC] =
422 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
423 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_new_ssrc),
424 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
426 * GstRtpSession::on-ssrc_collision:
427 * @sess: the object which received the signal
430 * Notify when we have an SSRC collision
432 gst_rtp_session_signals[SIGNAL_ON_SSRC_COLLISION] =
433 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
434 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
435 on_ssrc_collision), NULL, NULL, g_cclosure_marshal_VOID__UINT,
436 G_TYPE_NONE, 1, G_TYPE_UINT);
438 * GstRtpSession::on-ssrc_validated:
439 * @sess: the object which received the signal
442 * Notify of a new SSRC that became validated.
444 gst_rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED] =
445 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
446 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
447 on_ssrc_validated), NULL, NULL, g_cclosure_marshal_VOID__UINT,
448 G_TYPE_NONE, 1, G_TYPE_UINT);
450 * GstRtpSession::on-ssrc_active:
451 * @sess: the object which received the signal
454 * Notify of a SSRC that is active, i.e., sending RTCP.
456 gst_rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE] =
457 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
458 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
459 on_ssrc_active), NULL, NULL, g_cclosure_marshal_VOID__UINT,
460 G_TYPE_NONE, 1, G_TYPE_UINT);
462 * GstRtpSession::on-ssrc-sdes:
463 * @session: the object which received the signal
466 * Notify that a new SDES was received for SSRC.
468 gst_rtp_session_signals[SIGNAL_ON_SSRC_SDES] =
469 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
470 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_ssrc_sdes),
471 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
474 * GstRtpSession::on-bye-ssrc:
475 * @sess: the object which received the signal
478 * Notify of an SSRC that became inactive because of a BYE packet.
480 gst_rtp_session_signals[SIGNAL_ON_BYE_SSRC] =
481 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
482 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_bye_ssrc),
483 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
485 * GstRtpSession::on-bye-timeout:
486 * @sess: the object which received the signal
489 * Notify of an SSRC that has timed out because of BYE
491 gst_rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT] =
492 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
493 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_bye_timeout),
494 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
496 * GstRtpSession::on-timeout:
497 * @sess: the object which received the signal
500 * Notify of an SSRC that has timed out
502 gst_rtp_session_signals[SIGNAL_ON_TIMEOUT] =
503 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
504 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass, on_timeout),
505 NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
507 * GstRtpSession::on-sender-timeout:
508 * @sess: the object which received the signal
511 * Notify of a sender SSRC that has timed out and became a receiver
513 gst_rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT] =
514 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
515 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpSessionClass,
516 on_sender_timeout), NULL, NULL, g_cclosure_marshal_VOID__UINT,
517 G_TYPE_NONE, 1, G_TYPE_UINT);
519 g_object_class_install_property (gobject_class, PROP_BANDWIDTH,
520 g_param_spec_double ("bandwidth", "Bandwidth",
521 "The bandwidth of the session in bytes per second (0 for auto-discover)",
522 0.0, G_MAXDOUBLE, DEFAULT_BANDWIDTH,
523 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
525 g_object_class_install_property (gobject_class, PROP_RTCP_FRACTION,
526 g_param_spec_double ("rtcp-fraction", "RTCP Fraction",
527 "The RTCP bandwidth of the session in bytes per second "
528 "(or as a real fraction of the RTP bandwidth if < 1.0)",
529 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION,
530 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
532 g_object_class_install_property (gobject_class, PROP_RTCP_RR_BANDWIDTH,
533 g_param_spec_int ("rtcp-rr-bandwidth", "RTCP RR bandwidth",
534 "The RTCP bandwidth used for receivers in bytes per second (-1 = default)",
535 -1, G_MAXINT, DEFAULT_RTCP_RR_BANDWIDTH,
536 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
538 g_object_class_install_property (gobject_class, PROP_RTCP_RS_BANDWIDTH,
539 g_param_spec_int ("rtcp-rs-bandwidth", "RTCP RS bandwidth",
540 "The RTCP bandwidth used for senders in bytes per second (-1 = default)",
541 -1, G_MAXINT, DEFAULT_RTCP_RS_BANDWIDTH,
542 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
544 g_object_class_install_property (gobject_class, PROP_SDES,
545 g_param_spec_boxed ("sdes", "SDES",
546 "The SDES items of this session",
547 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
549 g_object_class_install_property (gobject_class, PROP_NUM_SOURCES,
550 g_param_spec_uint ("num-sources", "Num Sources",
551 "The number of sources in the session", 0, G_MAXUINT,
552 DEFAULT_NUM_SOURCES, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
554 g_object_class_install_property (gobject_class, PROP_NUM_ACTIVE_SOURCES,
555 g_param_spec_uint ("num-active-sources", "Num Active Sources",
556 "The number of active sources in the session", 0, G_MAXUINT,
557 DEFAULT_NUM_ACTIVE_SOURCES,
558 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
560 g_object_class_install_property (gobject_class, PROP_INTERNAL_SESSION,
561 g_param_spec_object ("internal-session", "Internal Session",
562 "The internal RTPSession object", RTP_TYPE_SESSION,
563 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
565 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
566 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
567 "Use the pipeline running-time to set the NTP time in the RTCP SR messages",
568 DEFAULT_USE_PIPELINE_CLOCK,
569 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
571 g_object_class_install_property (gobject_class, PROP_RTCP_MIN_INTERVAL,
572 g_param_spec_uint64 ("rtcp-min-interval", "Minimum RTCP interval",
573 "Minimum interval between Regular RTCP packet (in ns)",
574 0, G_MAXUINT64, DEFAULT_RTCP_MIN_INTERVAL,
575 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
577 g_object_class_install_property (gobject_class, PROP_PROBATION,
578 g_param_spec_uint ("probation", "Number of probations",
579 "Consecutive packet sequence numbers to accept the source",
580 0, G_MAXUINT, DEFAULT_PROBATION,
581 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
583 gstelement_class->change_state =
584 GST_DEBUG_FUNCPTR (gst_rtp_session_change_state);
585 gstelement_class->request_new_pad =
586 GST_DEBUG_FUNCPTR (gst_rtp_session_request_new_pad);
587 gstelement_class->release_pad =
588 GST_DEBUG_FUNCPTR (gst_rtp_session_release_pad);
590 klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_session_clear_pt_map);
593 gst_element_class_add_pad_template (gstelement_class,
594 gst_static_pad_template_get (&rtpsession_recv_rtp_sink_template));
595 gst_element_class_add_pad_template (gstelement_class,
596 gst_static_pad_template_get (&rtpsession_recv_rtcp_sink_template));
597 gst_element_class_add_pad_template (gstelement_class,
598 gst_static_pad_template_get (&rtpsession_send_rtp_sink_template));
601 gst_element_class_add_pad_template (gstelement_class,
602 gst_static_pad_template_get (&rtpsession_recv_rtp_src_template));
603 gst_element_class_add_pad_template (gstelement_class,
604 gst_static_pad_template_get (&rtpsession_sync_src_template));
605 gst_element_class_add_pad_template (gstelement_class,
606 gst_static_pad_template_get (&rtpsession_send_rtp_src_template));
607 gst_element_class_add_pad_template (gstelement_class,
608 gst_static_pad_template_get (&rtpsession_send_rtcp_src_template));
610 gst_element_class_set_static_metadata (gstelement_class, "RTP Session",
611 "Filter/Network/RTP",
612 "Implement an RTP session", "Wim Taymans <wim.taymans@gmail.com>");
614 GST_DEBUG_CATEGORY_INIT (gst_rtp_session_debug,
615 "rtpsession", 0, "RTP Session");
619 gst_rtp_session_init (GstRtpSession * rtpsession)
621 rtpsession->priv = GST_RTP_SESSION_GET_PRIVATE (rtpsession);
622 g_mutex_init (&rtpsession->priv->lock);
623 rtpsession->priv->sysclock = gst_system_clock_obtain ();
624 rtpsession->priv->session = rtp_session_new ();
625 rtpsession->priv->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
627 /* configure callbacks */
628 rtp_session_set_callbacks (rtpsession->priv->session, &callbacks, rtpsession);
629 /* configure signals */
630 g_signal_connect (rtpsession->priv->session, "on-new-ssrc",
631 (GCallback) on_new_ssrc, rtpsession);
632 g_signal_connect (rtpsession->priv->session, "on-ssrc-collision",
633 (GCallback) on_ssrc_collision, rtpsession);
634 g_signal_connect (rtpsession->priv->session, "on-ssrc-validated",
635 (GCallback) on_ssrc_validated, rtpsession);
636 g_signal_connect (rtpsession->priv->session, "on-ssrc-active",
637 (GCallback) on_ssrc_active, rtpsession);
638 g_signal_connect (rtpsession->priv->session, "on-ssrc-sdes",
639 (GCallback) on_ssrc_sdes, rtpsession);
640 g_signal_connect (rtpsession->priv->session, "on-bye-ssrc",
641 (GCallback) on_bye_ssrc, rtpsession);
642 g_signal_connect (rtpsession->priv->session, "on-bye-timeout",
643 (GCallback) on_bye_timeout, rtpsession);
644 g_signal_connect (rtpsession->priv->session, "on-timeout",
645 (GCallback) on_timeout, rtpsession);
646 g_signal_connect (rtpsession->priv->session, "on-sender-timeout",
647 (GCallback) on_sender_timeout, rtpsession);
648 rtpsession->priv->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
649 (GDestroyNotify) gst_caps_unref);
651 gst_segment_init (&rtpsession->recv_rtp_seg, GST_FORMAT_UNDEFINED);
652 gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
654 rtpsession->priv->thread_stopped = TRUE;
658 gst_rtp_session_finalize (GObject * object)
660 GstRtpSession *rtpsession;
662 rtpsession = GST_RTP_SESSION (object);
664 g_hash_table_destroy (rtpsession->priv->ptmap);
665 g_mutex_clear (&rtpsession->priv->lock);
666 g_object_unref (rtpsession->priv->sysclock);
667 g_object_unref (rtpsession->priv->session);
669 G_OBJECT_CLASS (parent_class)->finalize (object);
673 gst_rtp_session_set_property (GObject * object, guint prop_id,
674 const GValue * value, GParamSpec * pspec)
676 GstRtpSession *rtpsession;
677 GstRtpSessionPrivate *priv;
679 rtpsession = GST_RTP_SESSION (object);
680 priv = rtpsession->priv;
684 g_object_set_property (G_OBJECT (priv->session), "bandwidth", value);
686 case PROP_RTCP_FRACTION:
687 g_object_set_property (G_OBJECT (priv->session), "rtcp-fraction", value);
689 case PROP_RTCP_RR_BANDWIDTH:
690 g_object_set_property (G_OBJECT (priv->session), "rtcp-rr-bandwidth",
693 case PROP_RTCP_RS_BANDWIDTH:
694 g_object_set_property (G_OBJECT (priv->session), "rtcp-rs-bandwidth",
698 rtp_session_set_sdes_struct (priv->session, g_value_get_boxed (value));
700 case PROP_USE_PIPELINE_CLOCK:
701 priv->use_pipeline_clock = g_value_get_boolean (value);
703 case PROP_RTCP_MIN_INTERVAL:
704 g_object_set_property (G_OBJECT (priv->session), "rtcp-min-interval",
708 g_object_set_property (G_OBJECT (priv->session), "probation", value);
711 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
717 gst_rtp_session_get_property (GObject * object, guint prop_id,
718 GValue * value, GParamSpec * pspec)
720 GstRtpSession *rtpsession;
721 GstRtpSessionPrivate *priv;
723 rtpsession = GST_RTP_SESSION (object);
724 priv = rtpsession->priv;
728 g_object_get_property (G_OBJECT (priv->session), "bandwidth", value);
730 case PROP_RTCP_FRACTION:
731 g_object_get_property (G_OBJECT (priv->session), "rtcp-fraction", value);
733 case PROP_RTCP_RR_BANDWIDTH:
734 g_object_get_property (G_OBJECT (priv->session), "rtcp-rr-bandwidth",
737 case PROP_RTCP_RS_BANDWIDTH:
738 g_object_get_property (G_OBJECT (priv->session), "rtcp-rs-bandwidth",
742 g_value_take_boxed (value, rtp_session_get_sdes_struct (priv->session));
744 case PROP_NUM_SOURCES:
745 g_value_set_uint (value, rtp_session_get_num_sources (priv->session));
747 case PROP_NUM_ACTIVE_SOURCES:
748 g_value_set_uint (value,
749 rtp_session_get_num_active_sources (priv->session));
751 case PROP_INTERNAL_SESSION:
752 g_value_set_object (value, priv->session);
754 case PROP_USE_PIPELINE_CLOCK:
755 g_value_set_boolean (value, priv->use_pipeline_clock);
757 case PROP_RTCP_MIN_INTERVAL:
758 g_object_get_property (G_OBJECT (priv->session), "rtcp-min-interval",
762 g_object_get_property (G_OBJECT (priv->session), "probation", value);
765 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
771 get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
776 GstClockTime base_time, rt, clock_time;
778 GST_OBJECT_LOCK (rtpsession);
779 if ((clock = GST_ELEMENT_CLOCK (rtpsession))) {
780 base_time = GST_ELEMENT_CAST (rtpsession)->base_time;
781 gst_object_ref (clock);
782 GST_OBJECT_UNLOCK (rtpsession);
784 clock_time = gst_clock_get_time (clock);
786 if (rtpsession->priv->use_pipeline_clock) {
787 ntpns = clock_time - base_time;
791 /* get current NTP time */
792 g_get_current_time (¤t);
793 ntpns = GST_TIMEVAL_TO_TIME (current);
796 /* add constant to convert from 1970 based time to 1900 based time */
797 ntpns += (2208988800LL * GST_SECOND);
799 /* get current clock time and convert to running time */
800 rt = clock_time - base_time;
802 gst_object_unref (clock);
804 GST_OBJECT_UNLOCK (rtpsession);
815 rtcp_thread (GstRtpSession * rtpsession)
818 GstClockTime current_time;
819 GstClockTime next_timeout;
821 GstClockTime running_time;
825 GST_DEBUG_OBJECT (rtpsession, "entering RTCP thread");
827 GST_RTP_SESSION_LOCK (rtpsession);
829 sysclock = rtpsession->priv->sysclock;
830 current_time = gst_clock_get_time (sysclock);
832 session = rtpsession->priv->session;
834 GST_DEBUG_OBJECT (rtpsession, "starting at %" GST_TIME_FORMAT,
835 GST_TIME_ARGS (current_time));
836 session->start_time = current_time;
838 while (!rtpsession->priv->stop_thread) {
841 /* get initial estimate */
842 next_timeout = rtp_session_next_timeout (session, current_time);
844 GST_DEBUG_OBJECT (rtpsession, "next check time %" GST_TIME_FORMAT,
845 GST_TIME_ARGS (next_timeout));
847 /* leave if no more timeouts, the session ended */
848 if (next_timeout == GST_CLOCK_TIME_NONE)
851 id = rtpsession->priv->id =
852 gst_clock_new_single_shot_id (sysclock, next_timeout);
853 GST_RTP_SESSION_UNLOCK (rtpsession);
855 res = gst_clock_id_wait (id, NULL);
857 GST_RTP_SESSION_LOCK (rtpsession);
858 gst_clock_id_unref (id);
859 rtpsession->priv->id = NULL;
861 if (rtpsession->priv->stop_thread)
864 /* update current time */
865 current_time = gst_clock_get_time (sysclock);
867 /* get current NTP time */
868 get_current_times (rtpsession, &running_time, &ntpnstime);
870 /* we get unlocked because we need to perform reconsideration, don't perform
871 * the timeout but get a new reporting estimate. */
872 GST_DEBUG_OBJECT (rtpsession, "unlocked %d, current %" GST_TIME_FORMAT,
873 res, GST_TIME_ARGS (current_time));
875 /* perform actions, we ignore result. Release lock because it might push. */
876 GST_RTP_SESSION_UNLOCK (rtpsession);
877 rtp_session_on_timeout (session, current_time, ntpnstime, running_time);
878 GST_RTP_SESSION_LOCK (rtpsession);
880 /* mark the thread as stopped now */
881 rtpsession->priv->thread_stopped = TRUE;
882 GST_RTP_SESSION_UNLOCK (rtpsession);
884 GST_DEBUG_OBJECT (rtpsession, "leaving RTCP thread");
888 start_rtcp_thread (GstRtpSession * rtpsession)
890 GError *error = NULL;
893 GST_DEBUG_OBJECT (rtpsession, "starting RTCP thread");
895 GST_RTP_SESSION_LOCK (rtpsession);
896 rtpsession->priv->stop_thread = FALSE;
897 if (rtpsession->priv->thread_stopped) {
898 /* if the thread stopped, and we still have a handle to the thread, join it
899 * now. We can safely join with the lock held, the thread will not take it
901 if (rtpsession->priv->thread)
902 g_thread_join (rtpsession->priv->thread);
903 /* only create a new thread if the old one was stopped. Otherwise we can
904 * just reuse the currently running one. */
905 rtpsession->priv->thread = g_thread_try_new ("rtpsession-rtcp-thread",
906 (GThreadFunc) rtcp_thread, rtpsession, &error);
907 rtpsession->priv->thread_stopped = FALSE;
909 GST_RTP_SESSION_UNLOCK (rtpsession);
913 GST_DEBUG_OBJECT (rtpsession, "failed to start thread, %s", error->message);
914 g_error_free (error);
922 stop_rtcp_thread (GstRtpSession * rtpsession)
924 GST_DEBUG_OBJECT (rtpsession, "stopping RTCP thread");
926 GST_RTP_SESSION_LOCK (rtpsession);
927 rtpsession->priv->stop_thread = TRUE;
928 if (rtpsession->priv->id)
929 gst_clock_id_unschedule (rtpsession->priv->id);
930 GST_RTP_SESSION_UNLOCK (rtpsession);
934 join_rtcp_thread (GstRtpSession * rtpsession)
936 GST_RTP_SESSION_LOCK (rtpsession);
937 /* don't try to join when we have no thread */
938 if (rtpsession->priv->thread != NULL) {
939 GST_DEBUG_OBJECT (rtpsession, "joining RTCP thread");
940 GST_RTP_SESSION_UNLOCK (rtpsession);
942 g_thread_join (rtpsession->priv->thread);
944 GST_RTP_SESSION_LOCK (rtpsession);
945 /* after the join, take the lock and clear the thread structure. The caller
946 * is supposed to not concurrently call start and join. */
947 rtpsession->priv->thread = NULL;
949 GST_RTP_SESSION_UNLOCK (rtpsession);
952 static GstStateChangeReturn
953 gst_rtp_session_change_state (GstElement * element, GstStateChange transition)
955 GstStateChangeReturn res;
956 GstRtpSession *rtpsession;
958 rtpsession = GST_RTP_SESSION (element);
960 switch (transition) {
961 case GST_STATE_CHANGE_NULL_TO_READY:
963 case GST_STATE_CHANGE_READY_TO_PAUSED:
965 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
967 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
968 case GST_STATE_CHANGE_PAUSED_TO_READY:
969 /* no need to join yet, we might want to continue later. Also, the
970 * dataflow could block downstream so that a join could just block
972 stop_rtcp_thread (rtpsession);
978 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
980 switch (transition) {
981 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
982 if (!start_rtcp_thread (rtpsession))
985 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
987 case GST_STATE_CHANGE_PAUSED_TO_READY:
988 /* downstream is now releasing the dataflow and we can join. */
989 join_rtcp_thread (rtpsession);
991 case GST_STATE_CHANGE_READY_TO_NULL:
1001 return GST_STATE_CHANGE_FAILURE;
1006 return_true (gpointer key, gpointer value, gpointer user_data)
1012 gst_rtp_session_clear_pt_map (GstRtpSession * rtpsession)
1014 g_hash_table_foreach_remove (rtpsession->priv->ptmap, return_true, NULL);
1017 /* called when the session manager has an RTP packet or a list of packets
1018 * ready for further processing */
1019 static GstFlowReturn
1020 gst_rtp_session_process_rtp (RTPSession * sess, RTPSource * src,
1021 GstBuffer * buffer, gpointer user_data)
1023 GstFlowReturn result;
1024 GstRtpSession *rtpsession;
1027 rtpsession = GST_RTP_SESSION (user_data);
1029 GST_RTP_SESSION_LOCK (rtpsession);
1030 if ((rtp_src = rtpsession->recv_rtp_src))
1031 gst_object_ref (rtp_src);
1032 GST_RTP_SESSION_UNLOCK (rtpsession);
1035 GST_LOG_OBJECT (rtpsession, "pushing received RTP packet");
1036 result = gst_pad_push (rtp_src, buffer);
1037 gst_object_unref (rtp_src);
1039 GST_DEBUG_OBJECT (rtpsession, "dropping received RTP packet");
1040 gst_buffer_unref (buffer);
1041 result = GST_FLOW_OK;
1046 /* called when the session manager has an RTP packet ready for further
1048 static GstFlowReturn
1049 gst_rtp_session_send_rtp (RTPSession * sess, RTPSource * src,
1050 gpointer data, gpointer user_data)
1052 GstFlowReturn result;
1053 GstRtpSession *rtpsession;
1056 rtpsession = GST_RTP_SESSION (user_data);
1058 GST_RTP_SESSION_LOCK (rtpsession);
1059 if ((rtp_src = rtpsession->send_rtp_src))
1060 gst_object_ref (rtp_src);
1061 GST_RTP_SESSION_UNLOCK (rtpsession);
1064 if (GST_IS_BUFFER (data)) {
1065 GST_LOG_OBJECT (rtpsession, "sending RTP packet");
1066 result = gst_pad_push (rtp_src, GST_BUFFER_CAST (data));
1068 GST_LOG_OBJECT (rtpsession, "sending RTP list");
1069 result = gst_pad_push_list (rtp_src, GST_BUFFER_LIST_CAST (data));
1071 gst_object_unref (rtp_src);
1073 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
1074 result = GST_FLOW_OK;
1079 /* called when the session manager has an RTCP packet ready for further
1080 * sending. The eos flag is set when an EOS event should be sent downstream as
1082 static GstFlowReturn
1083 gst_rtp_session_send_rtcp (RTPSession * sess, RTPSource * src,
1084 GstBuffer * buffer, gboolean eos, gpointer user_data)
1086 GstFlowReturn result;
1087 GstRtpSession *rtpsession;
1090 rtpsession = GST_RTP_SESSION (user_data);
1092 GST_RTP_SESSION_LOCK (rtpsession);
1093 if (rtpsession->priv->stop_thread)
1096 if ((rtcp_src = rtpsession->send_rtcp_src)) {
1099 gst_object_ref (rtcp_src);
1100 GST_RTP_SESSION_UNLOCK (rtpsession);
1102 /* set rtcp caps on output pad */
1103 if (!(caps = gst_pad_get_current_caps (rtcp_src))) {
1104 caps = gst_caps_new_empty_simple ("application/x-rtcp");
1105 gst_pad_set_caps (rtcp_src, caps);
1107 gst_caps_unref (caps);
1109 GST_LOG_OBJECT (rtpsession, "sending RTCP");
1110 result = gst_pad_push (rtcp_src, buffer);
1112 /* we have to send EOS after this packet */
1114 GST_LOG_OBJECT (rtpsession, "sending EOS");
1115 gst_pad_push_event (rtcp_src, gst_event_new_eos ());
1117 gst_object_unref (rtcp_src);
1119 GST_RTP_SESSION_UNLOCK (rtpsession);
1121 GST_DEBUG_OBJECT (rtpsession, "not sending RTCP, no output pad");
1122 gst_buffer_unref (buffer);
1123 result = GST_FLOW_OK;
1130 GST_DEBUG_OBJECT (rtpsession, "we are stopping");
1131 gst_buffer_unref (buffer);
1132 GST_RTP_SESSION_UNLOCK (rtpsession);
1137 /* called when the session manager has an SR RTCP packet ready for handling
1138 * inter stream synchronisation */
1139 static GstFlowReturn
1140 gst_rtp_session_sync_rtcp (RTPSession * sess, RTPSource * src,
1141 GstBuffer * buffer, gpointer user_data)
1143 GstFlowReturn result;
1144 GstRtpSession *rtpsession;
1147 rtpsession = GST_RTP_SESSION (user_data);
1149 GST_RTP_SESSION_LOCK (rtpsession);
1150 if (rtpsession->priv->stop_thread)
1153 if ((sync_src = rtpsession->sync_src)) {
1156 gst_object_ref (sync_src);
1157 GST_RTP_SESSION_UNLOCK (rtpsession);
1159 /* set rtcp caps on output pad */
1160 if (!(caps = gst_pad_get_current_caps (sync_src))) {
1161 caps = gst_caps_new_empty_simple ("application/x-rtcp");
1162 gst_pad_set_caps (sync_src, caps);
1164 gst_caps_unref (caps);
1166 GST_LOG_OBJECT (rtpsession, "sending Sync RTCP");
1167 result = gst_pad_push (sync_src, buffer);
1168 gst_object_unref (sync_src);
1170 GST_RTP_SESSION_UNLOCK (rtpsession);
1172 GST_DEBUG_OBJECT (rtpsession, "not sending Sync RTCP, no output pad");
1173 gst_buffer_unref (buffer);
1174 result = GST_FLOW_OK;
1181 GST_DEBUG_OBJECT (rtpsession, "we are stopping");
1182 gst_buffer_unref (buffer);
1183 GST_RTP_SESSION_UNLOCK (rtpsession);
1189 gst_rtp_session_cache_caps (GstRtpSession * rtpsession, GstCaps * caps)
1191 GstRtpSessionPrivate *priv;
1192 const GstStructure *s;
1195 priv = rtpsession->priv;
1197 GST_DEBUG_OBJECT (rtpsession, "parsing caps");
1199 s = gst_caps_get_structure (caps, 0);
1200 if (!gst_structure_get_int (s, "payload", &payload))
1203 if (g_hash_table_lookup (priv->ptmap, GINT_TO_POINTER (payload)))
1206 g_hash_table_insert (priv->ptmap, GINT_TO_POINTER (payload),
1207 gst_caps_ref (caps));
1211 gst_rtp_session_get_caps_for_pt (GstRtpSession * rtpsession, guint payload)
1213 GstCaps *caps = NULL;
1214 GValue args[2] = { {0}, {0} };
1217 GST_RTP_SESSION_LOCK (rtpsession);
1218 caps = g_hash_table_lookup (rtpsession->priv->ptmap,
1219 GINT_TO_POINTER (payload));
1221 gst_caps_ref (caps);
1225 /* not found in the cache, try to get it with a signal */
1226 g_value_init (&args[0], GST_TYPE_ELEMENT);
1227 g_value_set_object (&args[0], rtpsession);
1228 g_value_init (&args[1], G_TYPE_UINT);
1229 g_value_set_uint (&args[1], payload);
1231 g_value_init (&ret, GST_TYPE_CAPS);
1232 g_value_set_boxed (&ret, NULL);
1234 GST_RTP_SESSION_UNLOCK (rtpsession);
1236 g_signal_emitv (args, gst_rtp_session_signals[SIGNAL_REQUEST_PT_MAP], 0,
1239 GST_RTP_SESSION_LOCK (rtpsession);
1241 g_value_unset (&args[0]);
1242 g_value_unset (&args[1]);
1243 caps = (GstCaps *) g_value_dup_boxed (&ret);
1244 g_value_unset (&ret);
1248 gst_rtp_session_cache_caps (rtpsession, caps);
1251 GST_RTP_SESSION_UNLOCK (rtpsession);
1257 GST_DEBUG_OBJECT (rtpsession, "could not get caps");
1262 /* called when the session manager needs the clock rate */
1264 gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
1268 GstRtpSession *rtpsession;
1270 const GstStructure *s;
1272 rtpsession = GST_RTP_SESSION_CAST (user_data);
1274 caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload);
1279 s = gst_caps_get_structure (caps, 0);
1280 if (!gst_structure_get_int (s, "clock-rate", &result))
1283 gst_caps_unref (caps);
1285 GST_DEBUG_OBJECT (rtpsession, "parsed clock-rate %d", result);
1294 gst_caps_unref (caps);
1295 GST_DEBUG_OBJECT (rtpsession, "No clock-rate in caps!");
1300 /* called when the session manager asks us to reconsider the timeout */
1302 gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data)
1304 GstRtpSession *rtpsession;
1306 rtpsession = GST_RTP_SESSION_CAST (user_data);
1308 GST_RTP_SESSION_LOCK (rtpsession);
1309 GST_DEBUG_OBJECT (rtpsession, "unlock timer for reconsideration");
1310 if (rtpsession->priv->id)
1311 gst_clock_id_unschedule (rtpsession->priv->id);
1312 GST_RTP_SESSION_UNLOCK (rtpsession);
1316 gst_rtp_session_event_recv_rtp_sink (GstPad * pad, GstObject * parent,
1319 GstRtpSession *rtpsession;
1320 gboolean ret = FALSE;
1322 rtpsession = GST_RTP_SESSION (parent);
1324 GST_DEBUG_OBJECT (rtpsession, "received event %s",
1325 GST_EVENT_TYPE_NAME (event));
1327 switch (GST_EVENT_TYPE (event)) {
1328 case GST_EVENT_CAPS:
1333 gst_event_parse_caps (event, &caps);
1334 gst_rtp_session_sink_setcaps (pad, rtpsession, caps);
1335 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1338 case GST_EVENT_FLUSH_STOP:
1339 gst_segment_init (&rtpsession->recv_rtp_seg, GST_FORMAT_UNDEFINED);
1340 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1342 case GST_EVENT_SEGMENT:
1344 GstSegment *segment, in_segment;
1346 segment = &rtpsession->recv_rtp_seg;
1348 /* the newsegment event is needed to convert the RTP timestamp to
1349 * running_time, which is needed to generate a mapping from RTP to NTP
1350 * timestamps in SR reports */
1351 gst_event_copy_segment (event, &in_segment);
1352 GST_DEBUG_OBJECT (rtpsession, "received segment %" GST_SEGMENT_FORMAT,
1355 /* accept upstream */
1356 gst_segment_copy_into (&in_segment, segment);
1358 /* push event forward */
1359 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1363 ret = gst_pad_push_event (rtpsession->recv_rtp_src, event);
1372 gst_rtp_session_request_remote_key_unit (GstRtpSession * rtpsession,
1373 guint32 ssrc, guint payload, gboolean all_headers, gint count)
1377 caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload);
1380 const GstStructure *s = gst_caps_get_structure (caps, 0);
1384 pli = gst_structure_has_field (s, "rtcp-fb-nack-pli");
1385 fir = gst_structure_has_field (s, "rtcp-fb-ccm-fir") && all_headers;
1387 /* Google Talk uses FIR for repair, so send it even if we just want a
1390 gst_structure_has_field (s, "rtcp-fb-x-gstreamer-fir-as-repair"))
1393 gst_caps_unref (caps);
1396 return rtp_session_request_key_unit (rtpsession->priv->session, ssrc,
1397 gst_clock_get_time (rtpsession->priv->sysclock), fir, count);
1404 gst_rtp_session_event_recv_rtp_src (GstPad * pad, GstObject * parent,
1407 GstRtpSession *rtpsession;
1408 gboolean forward = TRUE;
1409 gboolean ret = TRUE;
1410 const GstStructure *s;
1414 rtpsession = GST_RTP_SESSION (parent);
1416 switch (GST_EVENT_TYPE (event)) {
1417 case GST_EVENT_CUSTOM_UPSTREAM:
1418 s = gst_event_get_structure (event);
1419 if (gst_structure_has_name (s, "GstForceKeyUnit") &&
1420 gst_structure_get_uint (s, "ssrc", &ssrc) &&
1421 gst_structure_get_uint (s, "payload", &pt)) {
1422 gboolean all_headers = FALSE;
1425 gst_structure_get_boolean (s, "all-headers", &all_headers);
1426 if (gst_structure_get_int (s, "count", &count) && count < 0)
1427 count += G_MAXINT; /* Make sure count is positive if present */
1428 if (gst_rtp_session_request_remote_key_unit (rtpsession, ssrc, pt,
1429 all_headers, count))
1438 ret = gst_pad_push_event (rtpsession->recv_rtp_sink, event);
1444 static GstIterator *
1445 gst_rtp_session_iterate_internal_links (GstPad * pad, GstObject * parent)
1447 GstRtpSession *rtpsession;
1448 GstPad *otherpad = NULL;
1449 GstIterator *it = NULL;
1451 rtpsession = GST_RTP_SESSION (parent);
1453 GST_RTP_SESSION_LOCK (rtpsession);
1454 if (pad == rtpsession->recv_rtp_src) {
1455 otherpad = gst_object_ref (rtpsession->recv_rtp_sink);
1456 } else if (pad == rtpsession->recv_rtp_sink) {
1457 otherpad = gst_object_ref (rtpsession->recv_rtp_src);
1458 } else if (pad == rtpsession->send_rtp_src) {
1459 otherpad = gst_object_ref (rtpsession->send_rtp_sink);
1460 } else if (pad == rtpsession->send_rtp_sink) {
1461 otherpad = gst_object_ref (rtpsession->send_rtp_src);
1463 GST_RTP_SESSION_UNLOCK (rtpsession);
1466 GValue val = { 0, };
1468 g_value_init (&val, GST_TYPE_PAD);
1469 g_value_set_object (&val, otherpad);
1470 it = gst_iterator_new_single (GST_TYPE_PAD, &val);
1471 g_value_unset (&val);
1472 gst_object_unref (otherpad);
1479 gst_rtp_session_sink_setcaps (GstPad * pad, GstRtpSession * rtpsession,
1482 GST_RTP_SESSION_LOCK (rtpsession);
1483 gst_rtp_session_cache_caps (rtpsession, caps);
1484 GST_RTP_SESSION_UNLOCK (rtpsession);
1489 /* receive a packet from a sender, send it to the RTP session manager and
1490 * forward the packet on the rtp_src pad
1492 static GstFlowReturn
1493 gst_rtp_session_chain_recv_rtp (GstPad * pad, GstObject * parent,
1496 GstRtpSession *rtpsession;
1497 GstRtpSessionPrivate *priv;
1499 GstClockTime current_time, running_time;
1500 GstClockTime timestamp;
1502 rtpsession = GST_RTP_SESSION (parent);
1503 priv = rtpsession->priv;
1505 GST_LOG_OBJECT (rtpsession, "received RTP packet");
1507 /* get NTP time when this packet was captured, this depends on the timestamp. */
1508 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1509 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1510 /* convert to running time using the segment values */
1512 gst_segment_to_running_time (&rtpsession->recv_rtp_seg, GST_FORMAT_TIME,
1515 get_current_times (rtpsession, &running_time, NULL);
1517 current_time = gst_clock_get_time (priv->sysclock);
1519 ret = rtp_session_process_rtp (priv->session, buffer, current_time,
1521 if (ret != GST_FLOW_OK)
1531 GST_DEBUG_OBJECT (rtpsession, "process returned %s",
1532 gst_flow_get_name (ret));
1538 gst_rtp_session_event_recv_rtcp_sink (GstPad * pad, GstObject * parent,
1541 GstRtpSession *rtpsession;
1542 gboolean ret = FALSE;
1544 rtpsession = GST_RTP_SESSION (parent);
1546 GST_DEBUG_OBJECT (rtpsession, "received event %s",
1547 GST_EVENT_TYPE_NAME (event));
1549 switch (GST_EVENT_TYPE (event)) {
1551 ret = gst_pad_push_event (rtpsession->sync_src, event);
1558 /* Receive an RTCP packet from a sender, send it to the RTP session manager and
1559 * forward the SR packets to the sync_src pad.
1561 static GstFlowReturn
1562 gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstObject * parent,
1565 GstRtpSession *rtpsession;
1566 GstRtpSessionPrivate *priv;
1567 GstClockTime current_time;
1570 rtpsession = GST_RTP_SESSION (parent);
1571 priv = rtpsession->priv;
1573 GST_LOG_OBJECT (rtpsession, "received RTCP packet");
1575 current_time = gst_clock_get_time (priv->sysclock);
1576 get_current_times (rtpsession, NULL, &ntpnstime);
1578 rtp_session_process_rtcp (priv->session, buffer, current_time, ntpnstime);
1580 return GST_FLOW_OK; /* always return OK */
1584 gst_rtp_session_query_send_rtcp_src (GstPad * pad, GstObject * parent,
1587 GstRtpSession *rtpsession;
1588 gboolean ret = FALSE;
1590 rtpsession = GST_RTP_SESSION (parent);
1592 GST_DEBUG_OBJECT (rtpsession, "received QUERY");
1594 switch (GST_QUERY_TYPE (query)) {
1595 case GST_QUERY_LATENCY:
1597 /* use the defaults for the latency query. */
1598 gst_query_set_latency (query, FALSE, 0, -1);
1601 /* other queries simply fail for now */
1609 gst_rtp_session_event_send_rtcp_src (GstPad * pad, GstObject * parent,
1612 GstRtpSession *rtpsession;
1613 gboolean ret = TRUE;
1615 rtpsession = GST_RTP_SESSION (parent);
1616 GST_DEBUG_OBJECT (rtpsession, "received EVENT");
1618 switch (GST_EVENT_TYPE (event)) {
1619 case GST_EVENT_SEEK:
1620 case GST_EVENT_LATENCY:
1621 gst_event_unref (event);
1625 /* other events simply fail for now */
1626 gst_event_unref (event);
1636 gst_rtp_session_event_send_rtp_sink (GstPad * pad, GstObject * parent,
1639 GstRtpSession *rtpsession;
1640 gboolean ret = FALSE;
1642 rtpsession = GST_RTP_SESSION (parent);
1644 GST_DEBUG_OBJECT (rtpsession, "received event");
1646 switch (GST_EVENT_TYPE (event)) {
1647 case GST_EVENT_CAPS:
1652 gst_event_parse_caps (event, &caps);
1653 gst_rtp_session_setcaps_send_rtp (pad, rtpsession, caps);
1654 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
1657 case GST_EVENT_FLUSH_STOP:
1658 gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
1659 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
1661 case GST_EVENT_SEGMENT:{
1662 GstSegment *segment, in_segment;
1664 segment = &rtpsession->send_rtp_seg;
1666 /* the newsegment event is needed to convert the RTP timestamp to
1667 * running_time, which is needed to generate a mapping from RTP to NTP
1668 * timestamps in SR reports */
1669 gst_event_copy_segment (event, &in_segment);
1670 GST_DEBUG_OBJECT (rtpsession, "received segment %" GST_SEGMENT_FORMAT,
1673 /* accept upstream */
1674 gst_segment_copy_into (&in_segment, segment);
1676 /* push event forward */
1677 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
1680 case GST_EVENT_EOS:{
1681 GstClockTime current_time;
1683 /* push downstream FIXME, we are not supposed to leave the session just
1684 * because we stop sending. */
1685 ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
1686 current_time = gst_clock_get_time (rtpsession->priv->sysclock);
1687 GST_DEBUG_OBJECT (rtpsession, "scheduling BYE message");
1688 rtp_session_schedule_bye (rtpsession->priv->session, "End of stream",
1693 GstPad *send_rtp_src = NULL;
1694 GST_RTP_SESSION_LOCK (rtpsession);
1695 if (rtpsession->send_rtp_src)
1696 send_rtp_src = gst_object_ref (rtpsession->send_rtp_src);
1697 GST_RTP_SESSION_UNLOCK (rtpsession);
1700 ret = gst_pad_push_event (send_rtp_src, event);
1701 gst_object_unref (send_rtp_src);
1703 gst_event_unref (event);
1713 gst_rtp_session_getcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
1716 GstRtpSessionPrivate *priv;
1718 GstStructure *s1, *s2;
1721 priv = rtpsession->priv;
1723 ssrc = rtp_session_get_internal_ssrc (priv->session);
1725 /* we can basically accept anything but we prefer to receive packets with our
1726 * internal SSRC so that we don't have to patch it. Create a structure with
1727 * the SSRC and another one without. */
1728 s1 = gst_structure_new ("application/x-rtp", "ssrc", G_TYPE_UINT, ssrc, NULL);
1729 s2 = gst_structure_new_empty ("application/x-rtp");
1731 result = gst_caps_new_full (s1, s2, NULL);
1734 GstCaps *caps = result;
1736 result = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
1737 gst_caps_unref (caps);
1740 GST_DEBUG_OBJECT (rtpsession, "getting caps %" GST_PTR_FORMAT, result);
1746 gst_rtp_session_query_send_rtp (GstPad * pad, GstObject * parent,
1749 gboolean res = FALSE;
1750 GstRtpSession *rtpsession;
1752 rtpsession = GST_RTP_SESSION (parent);
1754 switch (GST_QUERY_TYPE (query)) {
1755 case GST_QUERY_CAPS:
1757 GstCaps *filter, *caps;
1759 gst_query_parse_caps (query, &filter);
1760 caps = gst_rtp_session_getcaps_send_rtp (pad, rtpsession, filter);
1761 gst_query_set_caps_result (query, caps);
1762 gst_caps_unref (caps);
1767 res = gst_pad_query_default (pad, parent, query);
1775 gst_rtp_session_setcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
1778 GstRtpSessionPrivate *priv;
1779 GstStructure *s = gst_caps_get_structure (caps, 0);
1782 priv = rtpsession->priv;
1784 if (gst_structure_get_uint (s, "ssrc", &ssrc)) {
1785 GST_DEBUG_OBJECT (rtpsession, "setting internal SSRC to %08x", ssrc);
1786 rtp_session_set_internal_ssrc (priv->session, ssrc);
1791 /* Recieve an RTP packet or a list of packets to be send to the receivers,
1792 * send to RTP session manager and forward to send_rtp_src.
1794 static GstFlowReturn
1795 gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
1796 gpointer data, gboolean is_list)
1798 GstRtpSessionPrivate *priv;
1800 GstClockTime timestamp, running_time;
1801 GstClockTime current_time;
1803 priv = rtpsession->priv;
1805 GST_LOG_OBJECT (rtpsession, "received RTP %s", is_list ? "list" : "packet");
1807 /* get NTP time when this packet was captured, this depends on the timestamp. */
1809 GstBuffer *buffer = NULL;
1811 /* All groups in an list have the same timestamp.
1812 * So, just take it from the first group. */
1813 buffer = gst_buffer_list_get (GST_BUFFER_LIST_CAST (data), 0);
1815 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1819 timestamp = GST_BUFFER_TIMESTAMP (GST_BUFFER_CAST (data));
1822 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1823 /* convert to running time using the segment start value. */
1825 gst_segment_to_running_time (&rtpsession->send_rtp_seg, GST_FORMAT_TIME,
1832 current_time = gst_clock_get_time (priv->sysclock);
1833 ret = rtp_session_send_rtp (priv->session, data, is_list, current_time,
1835 if (ret != GST_FLOW_OK)
1845 GST_DEBUG_OBJECT (rtpsession, "process returned %s",
1846 gst_flow_get_name (ret));
1851 static GstFlowReturn
1852 gst_rtp_session_chain_send_rtp (GstPad * pad, GstObject * parent,
1855 GstRtpSession *rtpsession = GST_RTP_SESSION (parent);
1857 return gst_rtp_session_chain_send_rtp_common (rtpsession, buffer, FALSE);
1860 static GstFlowReturn
1861 gst_rtp_session_chain_send_rtp_list (GstPad * pad, GstObject * parent,
1862 GstBufferList * list)
1864 GstRtpSession *rtpsession = GST_RTP_SESSION (parent);
1866 return gst_rtp_session_chain_send_rtp_common (rtpsession, list, TRUE);
1869 /* Create sinkpad to receive RTP packets from senders. This will also create a
1870 * srcpad for the RTP packets.
1873 create_recv_rtp_sink (GstRtpSession * rtpsession)
1875 GST_DEBUG_OBJECT (rtpsession, "creating RTP sink pad");
1877 rtpsession->recv_rtp_sink =
1878 gst_pad_new_from_static_template (&rtpsession_recv_rtp_sink_template,
1880 gst_pad_set_chain_function (rtpsession->recv_rtp_sink,
1881 gst_rtp_session_chain_recv_rtp);
1882 gst_pad_set_event_function (rtpsession->recv_rtp_sink,
1883 (GstPadEventFunction) gst_rtp_session_event_recv_rtp_sink);
1884 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtp_sink,
1885 gst_rtp_session_iterate_internal_links);
1886 gst_pad_set_active (rtpsession->recv_rtp_sink, TRUE);
1887 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
1888 rtpsession->recv_rtp_sink);
1890 GST_DEBUG_OBJECT (rtpsession, "creating RTP src pad");
1891 rtpsession->recv_rtp_src =
1892 gst_pad_new_from_static_template (&rtpsession_recv_rtp_src_template,
1894 gst_pad_set_event_function (rtpsession->recv_rtp_src,
1895 (GstPadEventFunction) gst_rtp_session_event_recv_rtp_src);
1896 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtp_src,
1897 gst_rtp_session_iterate_internal_links);
1898 gst_pad_use_fixed_caps (rtpsession->recv_rtp_src);
1899 gst_pad_set_active (rtpsession->recv_rtp_src, TRUE);
1900 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->recv_rtp_src);
1902 return rtpsession->recv_rtp_sink;
1905 /* Remove sinkpad to receive RTP packets from senders. This will also remove
1906 * the srcpad for the RTP packets.
1909 remove_recv_rtp_sink (GstRtpSession * rtpsession)
1911 GST_DEBUG_OBJECT (rtpsession, "removing RTP sink pad");
1913 /* deactivate from source to sink */
1914 gst_pad_set_active (rtpsession->recv_rtp_src, FALSE);
1915 gst_pad_set_active (rtpsession->recv_rtp_sink, FALSE);
1918 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
1919 rtpsession->recv_rtp_sink);
1920 rtpsession->recv_rtp_sink = NULL;
1922 GST_DEBUG_OBJECT (rtpsession, "removing RTP src pad");
1923 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
1924 rtpsession->recv_rtp_src);
1925 rtpsession->recv_rtp_src = NULL;
1928 /* Create a sinkpad to receive RTCP messages from senders, this will also create a
1929 * sync_src pad for the SR packets.
1932 create_recv_rtcp_sink (GstRtpSession * rtpsession)
1934 GST_DEBUG_OBJECT (rtpsession, "creating RTCP sink pad");
1936 rtpsession->recv_rtcp_sink =
1937 gst_pad_new_from_static_template (&rtpsession_recv_rtcp_sink_template,
1939 gst_pad_set_chain_function (rtpsession->recv_rtcp_sink,
1940 gst_rtp_session_chain_recv_rtcp);
1941 gst_pad_set_event_function (rtpsession->recv_rtcp_sink,
1942 (GstPadEventFunction) gst_rtp_session_event_recv_rtcp_sink);
1943 gst_pad_set_iterate_internal_links_function (rtpsession->recv_rtcp_sink,
1944 gst_rtp_session_iterate_internal_links);
1945 gst_pad_set_active (rtpsession->recv_rtcp_sink, TRUE);
1946 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
1947 rtpsession->recv_rtcp_sink);
1949 GST_DEBUG_OBJECT (rtpsession, "creating sync src pad");
1950 rtpsession->sync_src =
1951 gst_pad_new_from_static_template (&rtpsession_sync_src_template,
1953 gst_pad_set_iterate_internal_links_function (rtpsession->sync_src,
1954 gst_rtp_session_iterate_internal_links);
1955 gst_pad_use_fixed_caps (rtpsession->sync_src);
1956 gst_pad_set_active (rtpsession->sync_src, TRUE);
1957 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->sync_src);
1959 return rtpsession->recv_rtcp_sink;
1963 remove_recv_rtcp_sink (GstRtpSession * rtpsession)
1965 GST_DEBUG_OBJECT (rtpsession, "removing RTCP sink pad");
1967 gst_pad_set_active (rtpsession->sync_src, FALSE);
1968 gst_pad_set_active (rtpsession->recv_rtcp_sink, FALSE);
1970 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
1971 rtpsession->recv_rtcp_sink);
1972 rtpsession->recv_rtcp_sink = NULL;
1974 GST_DEBUG_OBJECT (rtpsession, "removing sync src pad");
1975 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->sync_src);
1976 rtpsession->sync_src = NULL;
1979 /* Create a sinkpad to receive RTP packets for receivers. This will also create a
1983 create_send_rtp_sink (GstRtpSession * rtpsession)
1985 GST_DEBUG_OBJECT (rtpsession, "creating pad");
1987 rtpsession->send_rtp_sink =
1988 gst_pad_new_from_static_template (&rtpsession_send_rtp_sink_template,
1990 gst_pad_set_chain_function (rtpsession->send_rtp_sink,
1991 gst_rtp_session_chain_send_rtp);
1992 gst_pad_set_chain_list_function (rtpsession->send_rtp_sink,
1993 gst_rtp_session_chain_send_rtp_list);
1994 gst_pad_set_query_function (rtpsession->send_rtp_sink,
1995 gst_rtp_session_query_send_rtp);
1996 gst_pad_set_event_function (rtpsession->send_rtp_sink,
1997 (GstPadEventFunction) gst_rtp_session_event_send_rtp_sink);
1998 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtp_sink,
1999 gst_rtp_session_iterate_internal_links);
2000 gst_pad_set_active (rtpsession->send_rtp_sink, TRUE);
2001 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2002 rtpsession->send_rtp_sink);
2004 rtpsession->send_rtp_src =
2005 gst_pad_new_from_static_template (&rtpsession_send_rtp_src_template,
2007 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtp_src,
2008 gst_rtp_session_iterate_internal_links);
2009 gst_pad_set_active (rtpsession->send_rtp_src, TRUE);
2010 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession), rtpsession->send_rtp_src);
2012 return rtpsession->send_rtp_sink;
2016 remove_send_rtp_sink (GstRtpSession * rtpsession)
2018 GST_DEBUG_OBJECT (rtpsession, "removing pad");
2020 gst_pad_set_active (rtpsession->send_rtp_src, FALSE);
2021 gst_pad_set_active (rtpsession->send_rtp_sink, FALSE);
2023 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2024 rtpsession->send_rtp_sink);
2025 rtpsession->send_rtp_sink = NULL;
2027 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2028 rtpsession->send_rtp_src);
2029 rtpsession->send_rtp_src = NULL;
2032 /* Create a srcpad with the RTCP packets to send out.
2033 * This pad will be driven by the RTP session manager when it wants to send out
2037 create_send_rtcp_src (GstRtpSession * rtpsession)
2039 GST_DEBUG_OBJECT (rtpsession, "creating pad");
2041 rtpsession->send_rtcp_src =
2042 gst_pad_new_from_static_template (&rtpsession_send_rtcp_src_template,
2044 gst_pad_use_fixed_caps (rtpsession->send_rtcp_src);
2045 gst_pad_set_active (rtpsession->send_rtcp_src, TRUE);
2046 gst_pad_set_iterate_internal_links_function (rtpsession->send_rtcp_src,
2047 gst_rtp_session_iterate_internal_links);
2048 gst_pad_set_query_function (rtpsession->send_rtcp_src,
2049 gst_rtp_session_query_send_rtcp_src);
2050 gst_pad_set_event_function (rtpsession->send_rtcp_src,
2051 gst_rtp_session_event_send_rtcp_src);
2052 gst_element_add_pad (GST_ELEMENT_CAST (rtpsession),
2053 rtpsession->send_rtcp_src);
2055 return rtpsession->send_rtcp_src;
2059 remove_send_rtcp_src (GstRtpSession * rtpsession)
2061 GST_DEBUG_OBJECT (rtpsession, "removing pad");
2063 gst_pad_set_active (rtpsession->send_rtcp_src, FALSE);
2065 gst_element_remove_pad (GST_ELEMENT_CAST (rtpsession),
2066 rtpsession->send_rtcp_src);
2067 rtpsession->send_rtcp_src = NULL;
2071 gst_rtp_session_request_new_pad (GstElement * element,
2072 GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
2074 GstRtpSession *rtpsession;
2075 GstElementClass *klass;
2078 g_return_val_if_fail (templ != NULL, NULL);
2079 g_return_val_if_fail (GST_IS_RTP_SESSION (element), NULL);
2081 rtpsession = GST_RTP_SESSION (element);
2082 klass = GST_ELEMENT_GET_CLASS (element);
2084 GST_DEBUG_OBJECT (element, "requesting pad %s", GST_STR_NULL (name));
2086 GST_RTP_SESSION_LOCK (rtpsession);
2088 /* figure out the template */
2089 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink")) {
2090 if (rtpsession->recv_rtp_sink != NULL)
2093 result = create_recv_rtp_sink (rtpsession);
2094 } else if (templ == gst_element_class_get_pad_template (klass,
2095 "recv_rtcp_sink")) {
2096 if (rtpsession->recv_rtcp_sink != NULL)
2099 result = create_recv_rtcp_sink (rtpsession);
2100 } else if (templ == gst_element_class_get_pad_template (klass,
2102 if (rtpsession->send_rtp_sink != NULL)
2105 result = create_send_rtp_sink (rtpsession);
2106 } else if (templ == gst_element_class_get_pad_template (klass,
2108 if (rtpsession->send_rtcp_src != NULL)
2111 result = create_send_rtcp_src (rtpsession);
2113 goto wrong_template;
2115 GST_RTP_SESSION_UNLOCK (rtpsession);
2122 GST_RTP_SESSION_UNLOCK (rtpsession);
2123 g_warning ("gstrtpsession: this is not our template");
2128 GST_RTP_SESSION_UNLOCK (rtpsession);
2129 g_warning ("gstrtpsession: pad already requested");
2135 gst_rtp_session_release_pad (GstElement * element, GstPad * pad)
2137 GstRtpSession *rtpsession;
2139 g_return_if_fail (GST_IS_RTP_SESSION (element));
2140 g_return_if_fail (GST_IS_PAD (pad));
2142 rtpsession = GST_RTP_SESSION (element);
2144 GST_DEBUG_OBJECT (element, "releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2146 GST_RTP_SESSION_LOCK (rtpsession);
2148 if (rtpsession->recv_rtp_sink == pad) {
2149 remove_recv_rtp_sink (rtpsession);
2150 } else if (rtpsession->recv_rtcp_sink == pad) {
2151 remove_recv_rtcp_sink (rtpsession);
2152 } else if (rtpsession->send_rtp_sink == pad) {
2153 remove_send_rtp_sink (rtpsession);
2154 } else if (rtpsession->send_rtcp_src == pad) {
2155 remove_send_rtcp_src (rtpsession);
2159 GST_RTP_SESSION_UNLOCK (rtpsession);
2166 GST_RTP_SESSION_UNLOCK (rtpsession);
2167 g_warning ("gstrtpsession: asked to release an unknown pad");
2173 gst_rtp_session_request_key_unit (RTPSession * sess,
2174 gboolean all_headers, gpointer user_data)
2176 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2179 event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
2180 gst_structure_new ("GstForceKeyUnit",
2181 "all-headers", G_TYPE_BOOLEAN, all_headers, NULL));
2182 gst_pad_push_event (rtpsession->send_rtp_sink, event);
2186 gst_rtp_session_request_time (RTPSession * session, gpointer user_data)
2188 GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
2190 return gst_clock_get_time (rtpsession->priv->sysclock);