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, GstBuffer * buf);
114 static gboolean gst_rtp_ssrc_demux_sink_event (GstPad * pad, GstEvent * event);
116 static GstFlowReturn gst_rtp_ssrc_demux_rtcp_chain (GstPad * pad,
118 static gboolean gst_rtp_ssrc_demux_rtcp_sink_event (GstPad * pad,
120 static GstIterator *gst_rtp_ssrc_demux_iterate_internal_links_sink (GstPad *
124 static gboolean gst_rtp_ssrc_demux_src_event (GstPad * pad, GstEvent * event);
125 static GstIterator *gst_rtp_ssrc_demux_iterate_internal_links_src (GstPad *
127 static gboolean gst_rtp_ssrc_demux_src_query (GstPad * pad, GstQuery * query);
129 static guint gst_rtp_ssrc_demux_signals[LAST_SIGNAL] = { 0 };
132 * Item for storing GstPad <-> SSRC pairs.
134 struct _GstRtpSsrcDemuxPad
142 /* find a src pad for a given SSRC, returns NULL if the SSRC was not found
144 static GstRtpSsrcDemuxPad *
145 find_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
149 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
150 GstRtpSsrcDemuxPad *pad = (GstRtpSsrcDemuxPad *) walk->data;
152 if (pad->ssrc == ssrc)
159 static GstRtpSsrcDemuxPad *
160 find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
162 GstPad *rtp_pad, *rtcp_pad;
163 GstElementClass *klass;
164 GstPadTemplate *templ;
166 GstRtpSsrcDemuxPad *demuxpad;
169 GST_DEBUG_OBJECT (demux, "creating pad for SSRC %08x", ssrc);
171 demuxpad = find_demux_pad_for_ssrc (demux, ssrc);
172 if (demuxpad != NULL) {
176 klass = GST_ELEMENT_GET_CLASS (demux);
177 templ = gst_element_class_get_pad_template (klass, "src_%u");
178 padname = g_strdup_printf ("src_%u", ssrc);
179 rtp_pad = gst_pad_new_from_template (templ, padname);
182 templ = gst_element_class_get_pad_template (klass, "rtcp_src_%u");
183 padname = g_strdup_printf ("rtcp_src_%u", ssrc);
184 rtcp_pad = gst_pad_new_from_template (templ, padname);
187 /* wrap in structure and add to list */
188 demuxpad = g_new0 (GstRtpSsrcDemuxPad, 1);
189 demuxpad->ssrc = ssrc;
190 demuxpad->rtp_pad = rtp_pad;
191 demuxpad->rtcp_pad = rtcp_pad;
193 gst_pad_set_element_private (rtp_pad, demuxpad);
194 gst_pad_set_element_private (rtcp_pad, demuxpad);
196 demux->srcpads = g_slist_prepend (demux->srcpads, demuxpad);
198 /* copy caps from input */
199 caps = gst_pad_get_current_caps (demux->rtp_sink);
200 gst_pad_set_caps (rtp_pad, caps);
201 gst_caps_unref (caps);
202 gst_pad_use_fixed_caps (rtp_pad);
203 caps = gst_pad_get_current_caps (demux->rtcp_sink);
204 gst_pad_set_caps (rtcp_pad, caps);
205 gst_caps_unref (caps);
206 gst_pad_use_fixed_caps (rtcp_pad);
208 gst_pad_set_event_function (rtp_pad, gst_rtp_ssrc_demux_src_event);
209 gst_pad_set_query_function (rtp_pad, gst_rtp_ssrc_demux_src_query);
210 gst_pad_set_iterate_internal_links_function (rtp_pad,
211 gst_rtp_ssrc_demux_iterate_internal_links_src);
212 gst_pad_set_active (rtp_pad, TRUE);
214 gst_pad_set_event_function (rtcp_pad, gst_rtp_ssrc_demux_src_event);
215 gst_pad_set_iterate_internal_links_function (rtcp_pad,
216 gst_rtp_ssrc_demux_iterate_internal_links_src);
217 gst_pad_set_active (rtcp_pad, TRUE);
219 gst_element_add_pad (GST_ELEMENT_CAST (demux), rtp_pad);
220 gst_element_add_pad (GST_ELEMENT_CAST (demux), rtcp_pad);
222 g_signal_emit (G_OBJECT (demux),
223 gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD], 0, ssrc, rtp_pad);
229 gst_rtp_ssrc_demux_class_init (GstRtpSsrcDemuxClass * klass)
231 GObjectClass *gobject_klass;
232 GstElementClass *gstelement_klass;
233 GstRtpSsrcDemuxClass *gstrtpssrcdemux_klass;
235 gobject_klass = (GObjectClass *) klass;
236 gstelement_klass = (GstElementClass *) klass;
237 gstrtpssrcdemux_klass = (GstRtpSsrcDemuxClass *) klass;
239 gobject_klass->dispose = gst_rtp_ssrc_demux_dispose;
240 gobject_klass->finalize = gst_rtp_ssrc_demux_finalize;
243 * GstRtpSsrcDemux::new-ssrc-pad:
244 * @demux: the object which received the signal
245 * @ssrc: the SSRC of the pad
248 * Emited when a new SSRC pad has been created.
250 gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD] =
251 g_signal_new ("new-ssrc-pad",
252 G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
253 G_STRUCT_OFFSET (GstRtpSsrcDemuxClass, new_ssrc_pad),
254 NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_OBJECT,
255 G_TYPE_NONE, 2, G_TYPE_UINT, GST_TYPE_PAD);
258 * GstRtpSsrcDemux::removed-ssrc-pad:
259 * @demux: the object which received the signal
260 * @ssrc: the SSRC of the pad
261 * @pad: the removed pad.
263 * Emited when a SSRC pad has been removed.
265 gst_rtp_ssrc_demux_signals[SIGNAL_REMOVED_SSRC_PAD] =
266 g_signal_new ("removed-ssrc-pad",
267 G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
268 G_STRUCT_OFFSET (GstRtpSsrcDemuxClass, removed_ssrc_pad),
269 NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_OBJECT,
270 G_TYPE_NONE, 2, G_TYPE_UINT, GST_TYPE_PAD);
273 * GstRtpSsrcDemux::clear-ssrc:
274 * @demux: the object which received the signal
275 * @ssrc: the SSRC of the pad
277 * Action signal to remove the pad for SSRC.
279 gst_rtp_ssrc_demux_signals[SIGNAL_CLEAR_SSRC] =
280 g_signal_new ("clear-ssrc",
281 G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
282 G_STRUCT_OFFSET (GstRtpSsrcDemuxClass, clear_ssrc),
283 NULL, NULL, gst_rtp_bin_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
285 gstelement_klass->change_state =
286 GST_DEBUG_FUNCPTR (gst_rtp_ssrc_demux_change_state);
287 gstrtpssrcdemux_klass->clear_ssrc =
288 GST_DEBUG_FUNCPTR (gst_rtp_ssrc_demux_clear_ssrc);
290 gst_element_class_add_pad_template (gstelement_klass,
291 gst_static_pad_template_get (&rtp_ssrc_demux_sink_template));
292 gst_element_class_add_pad_template (gstelement_klass,
293 gst_static_pad_template_get (&rtp_ssrc_demux_rtcp_sink_template));
294 gst_element_class_add_pad_template (gstelement_klass,
295 gst_static_pad_template_get (&rtp_ssrc_demux_src_template));
296 gst_element_class_add_pad_template (gstelement_klass,
297 gst_static_pad_template_get (&rtp_ssrc_demux_rtcp_src_template));
299 gst_element_class_set_details_simple (gstelement_klass, "RTP SSRC Demux",
301 "Splits RTP streams based on the SSRC",
302 "Wim Taymans <wim.taymans@gmail.com>");
304 GST_DEBUG_CATEGORY_INIT (gst_rtp_ssrc_demux_debug,
305 "rtpssrcdemux", 0, "RTP SSRC demuxer");
309 gst_rtp_ssrc_demux_init (GstRtpSsrcDemux * demux)
311 GstElementClass *klass = GST_ELEMENT_GET_CLASS (demux);
314 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
316 gst_pad_set_chain_function (demux->rtp_sink, gst_rtp_ssrc_demux_chain);
317 gst_pad_set_event_function (demux->rtp_sink, gst_rtp_ssrc_demux_sink_event);
318 gst_pad_set_iterate_internal_links_function (demux->rtp_sink,
319 gst_rtp_ssrc_demux_iterate_internal_links_sink);
320 gst_element_add_pad (GST_ELEMENT_CAST (demux), demux->rtp_sink);
323 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
324 "rtcp_sink"), "rtcp_sink");
325 gst_pad_set_chain_function (demux->rtcp_sink, gst_rtp_ssrc_demux_rtcp_chain);
326 gst_pad_set_event_function (demux->rtcp_sink,
327 gst_rtp_ssrc_demux_rtcp_sink_event);
328 gst_pad_set_iterate_internal_links_function (demux->rtcp_sink,
329 gst_rtp_ssrc_demux_iterate_internal_links_sink);
330 gst_element_add_pad (GST_ELEMENT_CAST (demux), demux->rtcp_sink);
332 g_static_rec_mutex_init (&demux->padlock);
334 gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
338 gst_rtp_ssrc_demux_reset (GstRtpSsrcDemux * demux)
342 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
343 GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) walk->data;
345 gst_pad_set_active (dpad->rtp_pad, FALSE);
346 gst_pad_set_active (dpad->rtcp_pad, FALSE);
348 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtp_pad);
349 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtcp_pad);
352 g_slist_free (demux->srcpads);
353 demux->srcpads = NULL;
357 gst_rtp_ssrc_demux_dispose (GObject * object)
359 GstRtpSsrcDemux *demux;
361 demux = GST_RTP_SSRC_DEMUX (object);
363 gst_rtp_ssrc_demux_reset (demux);
365 G_OBJECT_CLASS (parent_class)->dispose (object);
369 gst_rtp_ssrc_demux_finalize (GObject * object)
371 GstRtpSsrcDemux *demux;
373 demux = GST_RTP_SSRC_DEMUX (object);
374 g_static_rec_mutex_free (&demux->padlock);
376 G_OBJECT_CLASS (parent_class)->finalize (object);
380 gst_rtp_ssrc_demux_clear_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
382 GstRtpSsrcDemuxPad *dpad;
384 GST_PAD_LOCK (demux);
385 dpad = find_demux_pad_for_ssrc (demux, ssrc);
387 GST_PAD_UNLOCK (demux);
391 GST_DEBUG_OBJECT (demux, "clearing pad for SSRC %08x", ssrc);
393 demux->srcpads = g_slist_remove (demux->srcpads, dpad);
394 GST_PAD_UNLOCK (demux);
396 gst_pad_set_active (dpad->rtp_pad, FALSE);
397 gst_pad_set_active (dpad->rtcp_pad, FALSE);
399 g_signal_emit (G_OBJECT (demux),
400 gst_rtp_ssrc_demux_signals[SIGNAL_REMOVED_SSRC_PAD], 0, ssrc,
403 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtp_pad);
404 gst_element_remove_pad (GST_ELEMENT_CAST (demux), dpad->rtcp_pad);
413 GST_WARNING_OBJECT (demux, "unknown SSRC %08x", ssrc);
419 gst_rtp_ssrc_demux_sink_event (GstPad * pad, GstEvent * event)
421 GstRtpSsrcDemux *demux;
422 gboolean res = FALSE;
424 demux = GST_RTP_SSRC_DEMUX (gst_pad_get_parent (pad));
425 if (G_UNLIKELY (demux == NULL)) {
426 gst_event_unref (event);
430 switch (GST_EVENT_TYPE (event)) {
431 case GST_EVENT_FLUSH_STOP:
432 gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
439 /* need local snapshot of pads;
440 * should not push downstream while holding lock as that might deadlock
441 * with stuff traveling upstream tyring to get this lock while holding
442 * other (stream)lock */
443 GST_PAD_LOCK (demux);
444 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
445 GstRtpSsrcDemuxPad *pad = (GstRtpSsrcDemuxPad *) walk->data;
447 pads = g_slist_prepend (pads, gst_object_ref (pad->rtp_pad));
449 GST_PAD_UNLOCK (demux);
450 for (walk = pads; walk; walk = g_slist_next (walk)) {
451 GstPad *pad = (GstPad *) walk->data;
453 gst_event_ref (event);
454 res &= gst_pad_push_event (pad, event);
455 gst_object_unref (pad);
458 gst_event_unref (event);
463 gst_object_unref (demux);
468 gst_rtp_ssrc_demux_rtcp_sink_event (GstPad * pad, GstEvent * event)
470 GstRtpSsrcDemux *demux;
471 gboolean res = FALSE;
473 demux = GST_RTP_SSRC_DEMUX (gst_pad_get_parent (pad));
475 switch (GST_EVENT_TYPE (event)) {
482 GST_PAD_LOCK (demux);
483 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
484 GstRtpSsrcDemuxPad *pad = (GstRtpSsrcDemuxPad *) walk->data;
486 pads = g_slist_prepend (pads, gst_object_ref (pad->rtcp_pad));
488 GST_PAD_UNLOCK (demux);
489 for (walk = pads; walk; walk = g_slist_next (walk)) {
490 GstPad *pad = (GstPad *) walk->data;
492 gst_event_ref (event);
493 res &= gst_pad_push_event (pad, event);
494 gst_object_unref (pad);
497 gst_event_unref (event);
501 gst_object_unref (demux);
506 gst_rtp_ssrc_demux_chain (GstPad * pad, GstBuffer * buf)
509 GstRtpSsrcDemux *demux;
511 GstRtpSsrcDemuxPad *dpad;
515 demux = GST_RTP_SSRC_DEMUX (GST_OBJECT_PARENT (pad));
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, GstBuffer * buf)
564 GstRtpSsrcDemux *demux;
566 GstRtpSsrcDemuxPad *dpad;
567 GstRTCPPacket packet;
571 demux = GST_RTP_SSRC_DEMUX (GST_OBJECT_PARENT (pad));
573 if (!gst_rtcp_buffer_validate (buf))
576 gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
577 if (!gst_rtcp_buffer_get_first_packet (&rtcp, &packet)) {
578 gst_rtcp_buffer_unmap (&rtcp);
582 /* first packet must be SR or RR or else the validate would have failed */
583 switch (gst_rtcp_packet_get_type (&packet)) {
584 case GST_RTCP_TYPE_SR:
585 /* get the ssrc so that we can route it to the right source pad */
586 gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, NULL, NULL, NULL,
590 goto unexpected_rtcp;
592 gst_rtcp_buffer_unmap (&rtcp);
594 GST_DEBUG_OBJECT (demux, "received RTCP of SSRC %08x", ssrc);
596 GST_PAD_LOCK (demux);
597 dpad = find_or_create_demux_pad_for_ssrc (demux, ssrc);
599 GST_PAD_UNLOCK (demux);
602 srcpad = gst_object_ref (dpad->rtcp_pad);
603 GST_PAD_UNLOCK (demux);
606 ret = gst_pad_push (srcpad, buf);
608 gst_object_unref (srcpad);
615 /* this is fatal and should be filtered earlier */
616 GST_ELEMENT_ERROR (demux, STREAM, DECODE, (NULL),
617 ("Dropping invalid RTCP packet"));
618 gst_buffer_unref (buf);
619 return GST_FLOW_ERROR;
623 GST_DEBUG_OBJECT (demux, "dropping unexpected RTCP packet");
624 gst_buffer_unref (buf);
629 GST_ELEMENT_ERROR (demux, STREAM, DECODE, (NULL),
630 ("Could not create new pad"));
631 gst_buffer_unref (buf);
632 return GST_FLOW_ERROR;
637 gst_rtp_ssrc_demux_src_event (GstPad * pad, GstEvent * event)
639 GstRtpSsrcDemux *demux;
640 const GstStructure *s;
642 demux = GST_RTP_SSRC_DEMUX (gst_pad_get_parent (pad));
644 switch (GST_EVENT_TYPE (event)) {
645 case GST_EVENT_CUSTOM_UPSTREAM:
646 case GST_EVENT_CUSTOM_BOTH:
647 case GST_EVENT_CUSTOM_BOTH_OOB:
648 s = gst_event_get_structure (event);
649 if (s && !gst_structure_has_field (s, "ssrc")) {
652 for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
653 GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) walk->data;
655 if (dpad->rtp_pad == pad || dpad->rtcp_pad == pad) {
659 GST_EVENT_CAST (gst_mini_object_make_writable
660 (GST_MINI_OBJECT_CAST (event)));
661 ws = gst_event_writable_structure (event);
662 gst_structure_set (ws, "ssrc", G_TYPE_UINT, dpad->ssrc, NULL);
672 gst_object_unref (demux);
674 return gst_pad_event_default (pad, event);
678 gst_rtp_ssrc_demux_iterate_internal_links_src (GstPad * pad)
680 GstRtpSsrcDemux *demux;
681 GstPad *otherpad = NULL;
682 GstIterator *it = NULL;
685 demux = GST_RTP_SSRC_DEMUX (gst_pad_get_parent (pad));
690 GST_PAD_LOCK (demux);
691 for (current = demux->srcpads; current; current = g_slist_next (current)) {
692 GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) current->data;
694 if (pad == dpad->rtp_pad) {
695 otherpad = demux->rtp_sink;
697 } else if (pad == dpad->rtcp_pad) {
698 otherpad = demux->rtcp_sink;
705 g_value_init (&val, GST_TYPE_PAD);
706 g_value_set_object (&val, otherpad);
707 it = gst_iterator_new_single (GST_TYPE_PAD, &val);
708 g_value_unset (&val);
709 gst_object_unref (otherpad);
711 GST_PAD_UNLOCK (demux);
713 gst_object_unref (demux);
717 /* Should return 0 for elements to be included */
719 src_pad_compare_func (gconstpointer a, gconstpointer b)
721 GstPad *pad = GST_PAD (a);
722 const gchar *prefix = b;
725 GST_OBJECT_LOCK (pad);
726 res = !GST_PAD_NAME (pad) || g_str_has_prefix (GST_PAD_NAME (pad), prefix);
727 GST_OBJECT_UNLOCK (pad);
733 gst_rtp_ssrc_demux_iterate_internal_links_sink (GstPad * pad)
735 GstRtpSsrcDemux *demux;
736 GstIterator *it = NULL;
737 GValue gval = { 0, };
739 demux = GST_RTP_SSRC_DEMUX (gst_pad_get_parent (pad));
744 g_value_init (&gval, G_TYPE_STRING);
745 if (pad == demux->rtp_sink)
746 g_value_set_static_string (&gval, "src_");
747 else if (pad == demux->rtcp_sink)
748 g_value_set_static_string (&gval, "rtcp_src_");
750 g_assert_not_reached ();
752 it = gst_element_iterate_src_pads (GST_ELEMENT (demux));
754 it = gst_iterator_filter (it, src_pad_compare_func, &gval);
756 gst_object_unref (demux);
763 gst_rtp_ssrc_demux_src_query (GstPad * pad, GstQuery * query)
765 GstRtpSsrcDemux *demux;
766 gboolean res = FALSE;
768 demux = GST_RTP_SSRC_DEMUX (gst_pad_get_parent (pad));
769 if (G_UNLIKELY (demux == NULL))
772 switch (GST_QUERY_TYPE (query)) {
773 case GST_QUERY_LATENCY:
776 if ((res = gst_pad_peer_query (demux->rtp_sink, query))) {
778 GstClockTime min_latency, max_latency;
779 GstRtpSsrcDemuxPad *demuxpad;
781 demuxpad = gst_pad_get_element_private (pad);
783 gst_query_parse_latency (query, &live, &min_latency, &max_latency);
785 GST_DEBUG_OBJECT (demux, "peer min latency %" GST_TIME_FORMAT,
786 GST_TIME_ARGS (min_latency));
788 GST_DEBUG_OBJECT (demux, "latency for SSRC %08x", demuxpad->ssrc);
790 gst_query_set_latency (query, live, min_latency, max_latency);
795 res = gst_pad_query_default (pad, query);
798 gst_object_unref (demux);
803 static GstStateChangeReturn
804 gst_rtp_ssrc_demux_change_state (GstElement * element,
805 GstStateChange transition)
807 GstStateChangeReturn ret;
808 GstRtpSsrcDemux *demux;
810 demux = GST_RTP_SSRC_DEMUX (element);
812 switch (transition) {
813 case GST_STATE_CHANGE_NULL_TO_READY:
814 case GST_STATE_CHANGE_READY_TO_PAUSED:
815 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
820 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
822 switch (transition) {
823 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
825 case GST_STATE_CHANGE_PAUSED_TO_READY:
826 gst_rtp_ssrc_demux_reset (demux);
828 case GST_STATE_CHANGE_READY_TO_NULL: