2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:element-gstrtpssrcdemux
25 * gstrtpssrcdemux acts as a demuxer for RTP packets based on the SSRC of the
26 * packets. Its main purpose is to allow an application to easily receive and
27 * decode an RTP stream with multiple SSRCs.
29 * For each SSRC that is detected, a new pad will be created and the
30 * #GstRtpSsrcDemux::new-ssrc-pad signal will be emitted.
33 * <title>Example pipelines</title>
35 * gst-launch udpsrc caps="application/x-rtp" ! gstrtpssrcdemux ! fakesink
36 * ]| Takes an RTP stream and send the RTP packets with the first detected SSRC
37 * to fakesink, discarding the other SSRCs.
40 * Last reviewed on 2007-05-28 (0.10.5)
48 #include <gst/rtp/gstrtpbuffer.h>
49 #include <gst/rtp/gstrtcpbuffer.h>
51 #include "gstrtpbin-marshal.h"
52 #include "gstrtpssrcdemux.h"
54 GST_DEBUG_CATEGORY_STATIC (gst_rtp_ssrc_demux_debug);
55 #define GST_CAT_DEFAULT gst_rtp_ssrc_demux_debug
57 /* generic templates */
58 static GstStaticPadTemplate rtp_ssrc_demux_sink_template =
59 GST_STATIC_PAD_TEMPLATE ("sink",
62 GST_STATIC_CAPS ("application/x-rtp")
65 static GstStaticPadTemplate rtp_ssrc_demux_rtcp_sink_template =
66 GST_STATIC_PAD_TEMPLATE ("rtcp_sink",
69 GST_STATIC_CAPS ("application/x-rtcp")
72 static GstStaticPadTemplate rtp_ssrc_demux_src_template =
73 GST_STATIC_PAD_TEMPLATE ("src_%u",
76 GST_STATIC_CAPS ("application/x-rtp")
79 static GstStaticPadTemplate rtp_ssrc_demux_rtcp_src_template =
80 GST_STATIC_PAD_TEMPLATE ("rtcp_src_%u",
83 GST_STATIC_CAPS ("application/x-rtcp")
86 #define GST_PAD_LOCK(obj) (g_static_rec_mutex_lock (&(obj)->padlock))
87 #define GST_PAD_UNLOCK(obj) (g_static_rec_mutex_unlock (&(obj)->padlock))
93 SIGNAL_REMOVED_SSRC_PAD,
98 #define gst_rtp_ssrc_demux_parent_class parent_class
99 G_DEFINE_TYPE (GstRtpSsrcDemux, gst_rtp_ssrc_demux, GST_TYPE_ELEMENT);
101 /* GObject vmethods */
102 static void gst_rtp_ssrc_demux_dispose (GObject * object);
103 static void gst_rtp_ssrc_demux_finalize (GObject * object);
105 /* GstElement vmethods */
106 static GstStateChangeReturn gst_rtp_ssrc_demux_change_state (GstElement *
107 element, GstStateChange transition);
109 static void gst_rtp_ssrc_demux_clear_ssrc (GstRtpSsrcDemux * demux,
113 static GstFlowReturn gst_rtp_ssrc_demux_chain (GstPad * pad, GstObject * parent,
115 static gboolean gst_rtp_ssrc_demux_sink_event (GstPad * pad, GstObject * parent,
118 static GstFlowReturn gst_rtp_ssrc_demux_rtcp_chain (GstPad * pad,
119 GstObject * parent, GstBuffer * buf);
120 static gboolean gst_rtp_ssrc_demux_rtcp_sink_event (GstPad * pad,
121 GstObject * parent, GstEvent * event);
122 static GstIterator *gst_rtp_ssrc_demux_iterate_internal_links_sink (GstPad *
123 pad, GstObject * parent);
126 static gboolean gst_rtp_ssrc_demux_src_event (GstPad * pad, GstObject * parent,
128 static GstIterator *gst_rtp_ssrc_demux_iterate_internal_links_src (GstPad * pad,
130 static gboolean gst_rtp_ssrc_demux_src_query (GstPad * pad, GstObject * parent,
133 static guint gst_rtp_ssrc_demux_signals[LAST_SIGNAL] = { 0 };
136 * Item for storing GstPad <-> SSRC pairs.
138 struct _GstRtpSsrcDemuxPad
146 /* find a src pad for a given SSRC, returns NULL if the SSRC was not found
148 static GstRtpSsrcDemuxPad *
149 find_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
153 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
154 GstRtpSsrcDemuxPad *pad = (GstRtpSsrcDemuxPad *) walk->data;
156 if (pad->ssrc == ssrc)
163 static GstRtpSsrcDemuxPad *
164 find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
166 GstPad *rtp_pad, *rtcp_pad;
167 GstElementClass *klass;
168 GstPadTemplate *templ;
170 GstRtpSsrcDemuxPad *demuxpad;
173 GST_DEBUG_OBJECT (demux, "creating pad for SSRC %08x", ssrc);
175 demuxpad = find_demux_pad_for_ssrc (demux, ssrc);
176 if (demuxpad != NULL) {
180 klass = GST_ELEMENT_GET_CLASS (demux);
181 templ = gst_element_class_get_pad_template (klass, "src_%u");
182 padname = g_strdup_printf ("src_%u", ssrc);
183 rtp_pad = gst_pad_new_from_template (templ, padname);
186 templ = gst_element_class_get_pad_template (klass, "rtcp_src_%u");
187 padname = g_strdup_printf ("rtcp_src_%u", ssrc);
188 rtcp_pad = gst_pad_new_from_template (templ, padname);
191 /* wrap in structure and add to list */
192 demuxpad = g_new0 (GstRtpSsrcDemuxPad, 1);
193 demuxpad->ssrc = ssrc;
194 demuxpad->rtp_pad = rtp_pad;
195 demuxpad->rtcp_pad = rtcp_pad;
197 gst_pad_set_element_private (rtp_pad, demuxpad);
198 gst_pad_set_element_private (rtcp_pad, demuxpad);
200 demux->srcpads = g_slist_prepend (demux->srcpads, demuxpad);
202 /* copy caps from input */
203 caps = gst_pad_get_current_caps (demux->rtp_sink);
204 gst_pad_set_caps (rtp_pad, caps);
205 gst_caps_unref (caps);
206 gst_pad_use_fixed_caps (rtp_pad);
207 caps = gst_pad_get_current_caps (demux->rtcp_sink);
208 gst_pad_set_caps (rtcp_pad, caps);
209 gst_caps_unref (caps);
210 gst_pad_use_fixed_caps (rtcp_pad);
212 gst_pad_set_event_function (rtp_pad, gst_rtp_ssrc_demux_src_event);
213 gst_pad_set_query_function (rtp_pad, gst_rtp_ssrc_demux_src_query);
214 gst_pad_set_iterate_internal_links_function (rtp_pad,
215 gst_rtp_ssrc_demux_iterate_internal_links_src);
216 gst_pad_set_active (rtp_pad, TRUE);
218 gst_pad_set_event_function (rtcp_pad, gst_rtp_ssrc_demux_src_event);
219 gst_pad_set_iterate_internal_links_function (rtcp_pad,
220 gst_rtp_ssrc_demux_iterate_internal_links_src);
221 gst_pad_set_active (rtcp_pad, TRUE);
223 gst_element_add_pad (GST_ELEMENT_CAST (demux), rtp_pad);
224 gst_element_add_pad (GST_ELEMENT_CAST (demux), rtcp_pad);
226 g_signal_emit (G_OBJECT (demux),
227 gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD], 0, ssrc, rtp_pad);
233 gst_rtp_ssrc_demux_class_init (GstRtpSsrcDemuxClass * klass)
235 GObjectClass *gobject_klass;
236 GstElementClass *gstelement_klass;
237 GstRtpSsrcDemuxClass *gstrtpssrcdemux_klass;
239 gobject_klass = (GObjectClass *) klass;
240 gstelement_klass = (GstElementClass *) klass;
241 gstrtpssrcdemux_klass = (GstRtpSsrcDemuxClass *) klass;
243 gobject_klass->dispose = gst_rtp_ssrc_demux_dispose;
244 gobject_klass->finalize = gst_rtp_ssrc_demux_finalize;
247 * GstRtpSsrcDemux::new-ssrc-pad:
248 * @demux: the object which received the signal
249 * @ssrc: the SSRC of the pad
252 * Emited when a new SSRC pad has been created.
254 gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD] =
255 g_signal_new ("new-ssrc-pad",
256 G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
257 G_STRUCT_OFFSET (GstRtpSsrcDemuxClass, new_ssrc_pad),
258 NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_OBJECT,
259 G_TYPE_NONE, 2, G_TYPE_UINT, GST_TYPE_PAD);
262 * GstRtpSsrcDemux::removed-ssrc-pad:
263 * @demux: the object which received the signal
264 * @ssrc: the SSRC of the pad
265 * @pad: the removed pad.
267 * Emited when a SSRC pad has been removed.
269 gst_rtp_ssrc_demux_signals[SIGNAL_REMOVED_SSRC_PAD] =
270 g_signal_new ("removed-ssrc-pad",
271 G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
272 G_STRUCT_OFFSET (GstRtpSsrcDemuxClass, removed_ssrc_pad),
273 NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_OBJECT,
274 G_TYPE_NONE, 2, G_TYPE_UINT, GST_TYPE_PAD);
277 * GstRtpSsrcDemux::clear-ssrc:
278 * @demux: the object which received the signal
279 * @ssrc: the SSRC of the pad
281 * Action signal to remove the pad for SSRC.
283 gst_rtp_ssrc_demux_signals[SIGNAL_CLEAR_SSRC] =
284 g_signal_new ("clear-ssrc",
285 G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
286 G_STRUCT_OFFSET (GstRtpSsrcDemuxClass, clear_ssrc),
287 NULL, NULL, gst_rtp_bin_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
289 gstelement_klass->change_state =
290 GST_DEBUG_FUNCPTR (gst_rtp_ssrc_demux_change_state);
291 gstrtpssrcdemux_klass->clear_ssrc =
292 GST_DEBUG_FUNCPTR (gst_rtp_ssrc_demux_clear_ssrc);
294 gst_element_class_add_pad_template (gstelement_klass,
295 gst_static_pad_template_get (&rtp_ssrc_demux_sink_template));
296 gst_element_class_add_pad_template (gstelement_klass,
297 gst_static_pad_template_get (&rtp_ssrc_demux_rtcp_sink_template));
298 gst_element_class_add_pad_template (gstelement_klass,
299 gst_static_pad_template_get (&rtp_ssrc_demux_src_template));
300 gst_element_class_add_pad_template (gstelement_klass,
301 gst_static_pad_template_get (&rtp_ssrc_demux_rtcp_src_template));
303 gst_element_class_set_details_simple (gstelement_klass, "RTP SSRC Demux",
305 "Splits RTP streams based on the SSRC",
306 "Wim Taymans <wim.taymans@gmail.com>");
308 GST_DEBUG_CATEGORY_INIT (gst_rtp_ssrc_demux_debug,
309 "rtpssrcdemux", 0, "RTP SSRC demuxer");
313 gst_rtp_ssrc_demux_init (GstRtpSsrcDemux * demux)
315 GstElementClass *klass = GST_ELEMENT_GET_CLASS (demux);
318 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
320 gst_pad_set_chain_function (demux->rtp_sink, gst_rtp_ssrc_demux_chain);
321 gst_pad_set_event_function (demux->rtp_sink, gst_rtp_ssrc_demux_sink_event);
322 gst_pad_set_iterate_internal_links_function (demux->rtp_sink,
323 gst_rtp_ssrc_demux_iterate_internal_links_sink);
324 gst_element_add_pad (GST_ELEMENT_CAST (demux), demux->rtp_sink);
327 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
328 "rtcp_sink"), "rtcp_sink");
329 gst_pad_set_chain_function (demux->rtcp_sink, gst_rtp_ssrc_demux_rtcp_chain);
330 gst_pad_set_event_function (demux->rtcp_sink,
331 gst_rtp_ssrc_demux_rtcp_sink_event);
332 gst_pad_set_iterate_internal_links_function (demux->rtcp_sink,
333 gst_rtp_ssrc_demux_iterate_internal_links_sink);
334 gst_element_add_pad (GST_ELEMENT_CAST (demux), demux->rtcp_sink);
336 g_static_rec_mutex_init (&demux->padlock);
338 gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
342 gst_rtp_ssrc_demux_reset (GstRtpSsrcDemux * demux)
346 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
347 GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) walk->data;
349 gst_pad_set_active (dpad->rtp_pad, FALSE);
350 gst_pad_set_active (dpad->rtcp_pad, FALSE);
352 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtp_pad);
353 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtcp_pad);
356 g_slist_free (demux->srcpads);
357 demux->srcpads = NULL;
361 gst_rtp_ssrc_demux_dispose (GObject * object)
363 GstRtpSsrcDemux *demux;
365 demux = GST_RTP_SSRC_DEMUX (object);
367 gst_rtp_ssrc_demux_reset (demux);
369 G_OBJECT_CLASS (parent_class)->dispose (object);
373 gst_rtp_ssrc_demux_finalize (GObject * object)
375 GstRtpSsrcDemux *demux;
377 demux = GST_RTP_SSRC_DEMUX (object);
378 g_static_rec_mutex_free (&demux->padlock);
380 G_OBJECT_CLASS (parent_class)->finalize (object);
384 gst_rtp_ssrc_demux_clear_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
386 GstRtpSsrcDemuxPad *dpad;
388 GST_PAD_LOCK (demux);
389 dpad = find_demux_pad_for_ssrc (demux, ssrc);
391 GST_PAD_UNLOCK (demux);
395 GST_DEBUG_OBJECT (demux, "clearing pad for SSRC %08x", ssrc);
397 demux->srcpads = g_slist_remove (demux->srcpads, dpad);
398 GST_PAD_UNLOCK (demux);
400 gst_pad_set_active (dpad->rtp_pad, FALSE);
401 gst_pad_set_active (dpad->rtcp_pad, FALSE);
403 g_signal_emit (G_OBJECT (demux),
404 gst_rtp_ssrc_demux_signals[SIGNAL_REMOVED_SSRC_PAD], 0, ssrc,
407 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtp_pad);
408 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtcp_pad);
417 GST_WARNING_OBJECT (demux, "unknown SSRC %08x", ssrc);
423 gst_rtp_ssrc_demux_sink_event (GstPad * pad, GstObject * parent,
426 GstRtpSsrcDemux *demux;
427 gboolean res = FALSE;
429 demux = GST_RTP_SSRC_DEMUX (parent);
431 switch (GST_EVENT_TYPE (event)) {
432 case GST_EVENT_FLUSH_STOP:
433 gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
440 /* need local snapshot of pads;
441 * should not push downstream while holding lock as that might deadlock
442 * with stuff traveling upstream tyring to get this lock while holding
443 * other (stream)lock */
444 GST_PAD_LOCK (demux);
445 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
446 GstRtpSsrcDemuxPad *pad = (GstRtpSsrcDemuxPad *) walk->data;
448 pads = g_slist_prepend (pads, gst_object_ref (pad->rtp_pad));
450 GST_PAD_UNLOCK (demux);
451 for (walk = pads; walk; walk = g_slist_next (walk)) {
452 GstPad *pad = (GstPad *) walk->data;
454 gst_event_ref (event);
455 res &= gst_pad_push_event (pad, event);
456 gst_object_unref (pad);
459 gst_event_unref (event);
468 gst_rtp_ssrc_demux_rtcp_sink_event (GstPad * pad, GstObject * parent,
471 GstRtpSsrcDemux *demux;
472 gboolean res = FALSE;
474 demux = GST_RTP_SSRC_DEMUX (parent);
476 switch (GST_EVENT_TYPE (event)) {
483 GST_PAD_LOCK (demux);
484 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
485 GstRtpSsrcDemuxPad *pad = (GstRtpSsrcDemuxPad *) walk->data;
487 pads = g_slist_prepend (pads, gst_object_ref (pad->rtcp_pad));
489 GST_PAD_UNLOCK (demux);
490 for (walk = pads; walk; walk = g_slist_next (walk)) {
491 GstPad *pad = (GstPad *) walk->data;
493 gst_event_ref (event);
494 res &= gst_pad_push_event (pad, event);
495 gst_object_unref (pad);
498 gst_event_unref (event);
506 gst_rtp_ssrc_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
509 GstRtpSsrcDemux *demux;
511 GstRtpSsrcDemuxPad *dpad;
512 GstRTPBuffer rtp = {NULL};
515 demux = GST_RTP_SSRC_DEMUX (parent);
517 if (!gst_rtp_buffer_validate (buf))
518 goto invalid_payload;
520 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
521 ssrc = gst_rtp_buffer_get_ssrc (&rtp);
522 gst_rtp_buffer_unmap (&rtp);
524 GST_DEBUG_OBJECT (demux, "received buffer of SSRC %08x", ssrc);
526 GST_PAD_LOCK (demux);
527 dpad = find_or_create_demux_pad_for_ssrc (demux, ssrc);
529 GST_PAD_UNLOCK (demux);
532 srcpad = gst_object_ref (dpad->rtp_pad);
533 GST_PAD_UNLOCK (demux);
536 ret = gst_pad_push (srcpad, buf);
538 gst_object_unref (srcpad);
545 /* this is fatal and should be filtered earlier */
546 GST_ELEMENT_ERROR (demux, STREAM, DECODE, (NULL),
547 ("Dropping invalid RTP payload"));
548 gst_buffer_unref (buf);
549 return GST_FLOW_ERROR;
553 GST_ELEMENT_ERROR (demux, STREAM, DECODE, (NULL),
554 ("Could not create new pad"));
555 gst_buffer_unref (buf);
556 return GST_FLOW_ERROR;
561 gst_rtp_ssrc_demux_rtcp_chain (GstPad * pad, GstObject * parent,
565 GstRtpSsrcDemux *demux;
567 GstRtpSsrcDemuxPad *dpad;
568 GstRTCPPacket packet;
572 demux = GST_RTP_SSRC_DEMUX (parent);
574 if (!gst_rtcp_buffer_validate (buf))
577 gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
578 if (!gst_rtcp_buffer_get_first_packet (&rtcp, &packet)) {
579 gst_rtcp_buffer_unmap (&rtcp);
583 /* first packet must be SR or RR or else the validate would have failed */
584 switch (gst_rtcp_packet_get_type (&packet)) {
585 case GST_RTCP_TYPE_SR:
586 /* get the ssrc so that we can route it to the right source pad */
587 gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, NULL, NULL, NULL,
591 goto unexpected_rtcp;
593 gst_rtcp_buffer_unmap (&rtcp);
595 GST_DEBUG_OBJECT (demux, "received RTCP of SSRC %08x", ssrc);
597 GST_PAD_LOCK (demux);
598 dpad = find_or_create_demux_pad_for_ssrc (demux, ssrc);
600 GST_PAD_UNLOCK (demux);
603 srcpad = gst_object_ref (dpad->rtcp_pad);
604 GST_PAD_UNLOCK (demux);
607 ret = gst_pad_push (srcpad, buf);
609 gst_object_unref (srcpad);
616 /* this is fatal and should be filtered earlier */
617 GST_ELEMENT_ERROR (demux, STREAM, DECODE, (NULL),
618 ("Dropping invalid RTCP packet"));
619 gst_buffer_unref (buf);
620 return GST_FLOW_ERROR;
624 GST_DEBUG_OBJECT (demux, "dropping unexpected RTCP packet");
625 gst_buffer_unref (buf);
630 GST_ELEMENT_ERROR (demux, STREAM, DECODE, (NULL),
631 ("Could not create new pad"));
632 gst_buffer_unref (buf);
633 return GST_FLOW_ERROR;
638 gst_rtp_ssrc_demux_src_event (GstPad * pad, GstObject * parent,
641 GstRtpSsrcDemux *demux;
642 const GstStructure *s;
644 demux = GST_RTP_SSRC_DEMUX (parent);
646 switch (GST_EVENT_TYPE (event)) {
647 case GST_EVENT_CUSTOM_UPSTREAM:
648 case GST_EVENT_CUSTOM_BOTH:
649 case GST_EVENT_CUSTOM_BOTH_OOB:
650 s = gst_event_get_structure (event);
651 if (s && !gst_structure_has_field (s, "ssrc")) {
654 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
655 GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) walk->data;
657 if (dpad->rtp_pad == pad || dpad->rtcp_pad == pad) {
661 GST_EVENT_CAST (gst_mini_object_make_writable
662 (GST_MINI_OBJECT_CAST (event)));
663 ws = gst_event_writable_structure (event);
664 gst_structure_set (ws, "ssrc", G_TYPE_UINT, dpad->ssrc, NULL);
674 return gst_pad_event_default (pad, parent, event);
678 gst_rtp_ssrc_demux_iterate_internal_links_src (GstPad * pad, GstObject * parent)
680 GstRtpSsrcDemux *demux;
681 GstPad *otherpad = NULL;
682 GstIterator *it = NULL;
685 demux = GST_RTP_SSRC_DEMUX (parent);
687 GST_PAD_LOCK (demux);
688 for (current = demux->srcpads; current; current = g_slist_next (current)) {
689 GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) current->data;
691 if (pad == dpad->rtp_pad) {
692 otherpad = demux->rtp_sink;
694 } else if (pad == dpad->rtcp_pad) {
695 otherpad = demux->rtcp_sink;
702 g_value_init (&val, GST_TYPE_PAD);
703 g_value_set_object (&val, otherpad);
704 it = gst_iterator_new_single (GST_TYPE_PAD, &val);
705 g_value_unset (&val);
706 gst_object_unref (otherpad);
708 GST_PAD_UNLOCK (demux);
713 /* Should return 0 for elements to be included */
715 src_pad_compare_func (gconstpointer a, gconstpointer b)
717 GstPad *pad = GST_PAD (a);
718 const gchar *prefix = b;
721 GST_OBJECT_LOCK (pad);
722 res = !GST_PAD_NAME (pad) || g_str_has_prefix (GST_PAD_NAME (pad), prefix);
723 GST_OBJECT_UNLOCK (pad);
729 gst_rtp_ssrc_demux_iterate_internal_links_sink (GstPad * pad,
732 GstRtpSsrcDemux *demux;
733 GstIterator *it = NULL;
734 GValue gval = { 0, };
736 demux = GST_RTP_SSRC_DEMUX (parent);
738 g_value_init (&gval, G_TYPE_STRING);
739 if (pad == demux->rtp_sink)
740 g_value_set_static_string (&gval, "src_");
741 else if (pad == demux->rtcp_sink)
742 g_value_set_static_string (&gval, "rtcp_src_");
744 g_assert_not_reached ();
746 it = gst_element_iterate_src_pads (GST_ELEMENT_CAST (demux));
748 it = gst_iterator_filter (it, src_pad_compare_func, &gval);
755 gst_rtp_ssrc_demux_src_query (GstPad * pad, GstObject * parent,
758 GstRtpSsrcDemux *demux;
759 gboolean res = FALSE;
761 demux = GST_RTP_SSRC_DEMUX (parent);
763 switch (GST_QUERY_TYPE (query)) {
764 case GST_QUERY_LATENCY:
767 if ((res = gst_pad_peer_query (demux->rtp_sink, query))) {
769 GstClockTime min_latency, max_latency;
770 GstRtpSsrcDemuxPad *demuxpad;
772 demuxpad = gst_pad_get_element_private (pad);
774 gst_query_parse_latency (query, &live, &min_latency, &max_latency);
776 GST_DEBUG_OBJECT (demux, "peer min latency %" GST_TIME_FORMAT,
777 GST_TIME_ARGS (min_latency));
779 GST_DEBUG_OBJECT (demux, "latency for SSRC %08x", demuxpad->ssrc);
781 gst_query_set_latency (query, live, min_latency, max_latency);
786 res = gst_pad_query_default (pad, parent, query);
793 static GstStateChangeReturn
794 gst_rtp_ssrc_demux_change_state (GstElement * element,
795 GstStateChange transition)
797 GstStateChangeReturn ret;
798 GstRtpSsrcDemux *demux;
800 demux = GST_RTP_SSRC_DEMUX (element);
802 switch (transition) {
803 case GST_STATE_CHANGE_NULL_TO_READY:
804 case GST_STATE_CHANGE_READY_TO_PAUSED:
805 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
810 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
812 switch (transition) {
813 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
815 case GST_STATE_CHANGE_PAUSED_TO_READY:
816 gst_rtp_ssrc_demux_reset (demux);
818 case GST_STATE_CHANGE_READY_TO_NULL: