jitterbuffer: signal timestamp discont
[platform/upstream/gstreamer.git] / gst / rtpmanager / gstrtpptdemux.c
1 /* 
2  * RTP Demux element
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  * @author Kai Vehmanen <kai.vehmanen@nokia.com>
6  *
7  * Loosely based on GStreamer gstdecodebin
8  * Copyright (C) <2004> Wim Taymans <wim.taymans@gmail.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  */
25
26 /**
27  * SECTION:element-gstrtpptdemux
28  *
29  * gstrtpptdemux acts as a demuxer for RTP packets based on the payload type of
30  * the packets. Its main purpose is to allow an application to easily receive
31  * and decode an RTP stream with multiple payload types.
32  * 
33  * For each payload type that is detected, a new pad will be created and the
34  * #GstRtpPtDemux::new-payload-type signal will be emitted. When the payload for
35  * the RTP stream changes, the #GstRtpPtDemux::payload-type-change signal will be
36  * emitted.
37  * 
38  * The element will try to set complete and unique application/x-rtp caps on the
39  * outgoing buffers and pads based on the result of the
40  * #GstRtpPtDemux::request-pt-map signal.
41  * 
42  * <refsect2>
43  * <title>Example pipelines</title>
44  * |[
45  * gst-launch-1.0 udpsrc caps="application/x-rtp" ! gstrtpptdemux ! fakesink
46  * ]| Takes an RTP stream and send the RTP packets with the first detected
47  * payload type to fakesink, discarding the other payload types.
48  * </refsect2>
49  *
50  * Last reviewed on 2007-05-28 (0.10.5)
51  */
52
53 /*
54  * Contributors:
55  * Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
56  */
57 /*
58  * Status:
59  *  - works with the test_rtpdemux.c tool
60  *
61  * Check:
62  *  - is emitting a signal enough, or should we
63  *    use GstEvent to notify downstream elements
64  *    of the new packet... no?
65  *
66  * Notes:
67  *  - emits event both for new PTs, and whenever
68  *    a PT is changed
69  */
70
71 #ifdef HAVE_CONFIG_H
72 #include "config.h"
73 #endif
74
75 #include <string.h>
76 #include <gst/gst.h>
77 #include <gst/rtp/gstrtpbuffer.h>
78
79 #include "gstrtpbin-marshal.h"
80 #include "gstrtpptdemux.h"
81
82 /* generic templates */
83 static GstStaticPadTemplate rtp_pt_demux_sink_template =
84 GST_STATIC_PAD_TEMPLATE ("sink",
85     GST_PAD_SINK,
86     GST_PAD_ALWAYS,
87     GST_STATIC_CAPS ("application/x-rtp")
88     );
89
90 static GstStaticPadTemplate rtp_pt_demux_src_template =
91 GST_STATIC_PAD_TEMPLATE ("src_%u",
92     GST_PAD_SRC,
93     GST_PAD_SOMETIMES,
94     GST_STATIC_CAPS ("application/x-rtp, " "payload = (int) [ 0, 255 ]")
95     );
96
97 GST_DEBUG_CATEGORY_STATIC (gst_rtp_pt_demux_debug);
98 #define GST_CAT_DEFAULT gst_rtp_pt_demux_debug
99
100 /*
101  * Item for storing GstPad<->pt pairs.
102  */
103 struct _GstRtpPtDemuxPad
104 {
105   GstPad *pad;        /**< pointer to the actual pad */
106   gint pt;             /**< RTP payload-type attached to pad */
107   gboolean newcaps;
108 };
109
110 /* signals */
111 enum
112 {
113   SIGNAL_REQUEST_PT_MAP,
114   SIGNAL_NEW_PAYLOAD_TYPE,
115   SIGNAL_PAYLOAD_TYPE_CHANGE,
116   SIGNAL_CLEAR_PT_MAP,
117   LAST_SIGNAL
118 };
119
120 #define gst_rtp_pt_demux_parent_class parent_class
121 G_DEFINE_TYPE (GstRtpPtDemux, gst_rtp_pt_demux, GST_TYPE_ELEMENT);
122
123 static void gst_rtp_pt_demux_finalize (GObject * object);
124
125 static void gst_rtp_pt_demux_release (GstRtpPtDemux * ptdemux);
126 static gboolean gst_rtp_pt_demux_setup (GstRtpPtDemux * ptdemux);
127
128 static gboolean gst_rtp_pt_demux_sink_event (GstPad * pad, GstObject * parent,
129     GstEvent * event);
130 static GstFlowReturn gst_rtp_pt_demux_chain (GstPad * pad, GstObject * parent,
131     GstBuffer * buf);
132 static GstStateChangeReturn gst_rtp_pt_demux_change_state (GstElement * element,
133     GstStateChange transition);
134 static void gst_rtp_pt_demux_clear_pt_map (GstRtpPtDemux * rtpdemux);
135
136 static GstPad *find_pad_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt);
137
138 static gboolean gst_rtp_pt_demux_src_event (GstPad * pad, GstObject * parent,
139     GstEvent * event);
140
141
142 static guint gst_rtp_pt_demux_signals[LAST_SIGNAL] = { 0 };
143
144 static void
145 gst_rtp_pt_demux_class_init (GstRtpPtDemuxClass * klass)
146 {
147   GObjectClass *gobject_klass;
148   GstElementClass *gstelement_klass;
149
150   gobject_klass = (GObjectClass *) klass;
151   gstelement_klass = (GstElementClass *) klass;
152
153   /**
154    * GstRtpPtDemux::request-pt-map:
155    * @demux: the object which received the signal
156    * @pt: the payload type
157    *
158    * Request the payload type as #GstCaps for @pt.
159    */
160   gst_rtp_pt_demux_signals[SIGNAL_REQUEST_PT_MAP] =
161       g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
162       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpPtDemuxClass, request_pt_map),
163       NULL, NULL, gst_rtp_bin_marshal_BOXED__UINT, GST_TYPE_CAPS, 1,
164       G_TYPE_UINT);
165
166   /**
167    * GstRtpPtDemux::new-payload-type:
168    * @demux: the object which received the signal
169    * @pt: the payload type
170    * @pad: the pad with the new payload
171    *
172    * Emited when a new payload type pad has been created in @demux.
173    */
174   gst_rtp_pt_demux_signals[SIGNAL_NEW_PAYLOAD_TYPE] =
175       g_signal_new ("new-payload-type", G_TYPE_FROM_CLASS (klass),
176       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpPtDemuxClass, new_payload_type),
177       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_OBJECT, G_TYPE_NONE, 2,
178       G_TYPE_UINT, GST_TYPE_PAD);
179
180   /**
181    * GstRtpPtDemux::payload-type-change:
182    * @demux: the object which received the signal
183    * @pt: the new payload type
184    *
185    * Emited when the payload type changed.
186    */
187   gst_rtp_pt_demux_signals[SIGNAL_PAYLOAD_TYPE_CHANGE] =
188       g_signal_new ("payload-type-change", G_TYPE_FROM_CLASS (klass),
189       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpPtDemuxClass,
190           payload_type_change), NULL, NULL, g_cclosure_marshal_VOID__UINT,
191       G_TYPE_NONE, 1, G_TYPE_UINT);
192
193   /**
194    * GstRtpPtDemux::clear-pt-map:
195    * @demux: the object which received the signal
196    *
197    * The application can call this signal to instruct the element to discard the
198    * currently cached payload type map.
199    */
200   gst_rtp_pt_demux_signals[SIGNAL_CLEAR_PT_MAP] =
201       g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
202       G_SIGNAL_ACTION | G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpPtDemuxClass,
203           clear_pt_map), NULL, NULL, g_cclosure_marshal_VOID__VOID,
204       G_TYPE_NONE, 0, G_TYPE_NONE);
205
206   gobject_klass->finalize = gst_rtp_pt_demux_finalize;
207
208   gstelement_klass->change_state =
209       GST_DEBUG_FUNCPTR (gst_rtp_pt_demux_change_state);
210
211   klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_pt_demux_clear_pt_map);
212
213   gst_element_class_add_pad_template (gstelement_klass,
214       gst_static_pad_template_get (&rtp_pt_demux_sink_template));
215   gst_element_class_add_pad_template (gstelement_klass,
216       gst_static_pad_template_get (&rtp_pt_demux_src_template));
217
218   gst_element_class_set_static_metadata (gstelement_klass, "RTP Demux",
219       "Demux/Network/RTP",
220       "Parses codec streams transmitted in the same RTP session",
221       "Kai Vehmanen <kai.vehmanen@nokia.com>");
222
223   GST_DEBUG_CATEGORY_INIT (gst_rtp_pt_demux_debug,
224       "rtpptdemux", 0, "RTP codec demuxer");
225 }
226
227 static void
228 gst_rtp_pt_demux_init (GstRtpPtDemux * ptdemux)
229 {
230   GstElementClass *klass = GST_ELEMENT_GET_CLASS (ptdemux);
231
232   ptdemux->sink =
233       gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
234           "sink"), "sink");
235   g_assert (ptdemux->sink != NULL);
236
237   gst_pad_set_chain_function (ptdemux->sink, gst_rtp_pt_demux_chain);
238   gst_pad_set_event_function (ptdemux->sink, gst_rtp_pt_demux_sink_event);
239
240   gst_element_add_pad (GST_ELEMENT (ptdemux), ptdemux->sink);
241 }
242
243 static void
244 gst_rtp_pt_demux_finalize (GObject * object)
245 {
246   gst_rtp_pt_demux_release (GST_RTP_PT_DEMUX (object));
247
248   G_OBJECT_CLASS (parent_class)->finalize (object);
249 }
250
251 static GstCaps *
252 gst_rtp_pt_demux_get_caps (GstRtpPtDemux * rtpdemux, guint pt)
253 {
254   GstCaps *caps;
255   GValue ret = { 0 };
256   GValue args[2] = { {0}, {0} };
257
258   /* figure out the caps */
259   g_value_init (&args[0], GST_TYPE_ELEMENT);
260   g_value_set_object (&args[0], rtpdemux);
261   g_value_init (&args[1], G_TYPE_UINT);
262   g_value_set_uint (&args[1], pt);
263
264   g_value_init (&ret, GST_TYPE_CAPS);
265   g_value_set_boxed (&ret, NULL);
266
267   g_signal_emitv (args, gst_rtp_pt_demux_signals[SIGNAL_REQUEST_PT_MAP], 0,
268       &ret);
269
270   g_value_unset (&args[0]);
271   g_value_unset (&args[1]);
272   caps = g_value_dup_boxed (&ret);
273   g_value_unset (&ret);
274   if (caps == NULL) {
275     caps = gst_pad_get_current_caps (rtpdemux->sink);
276   }
277
278   GST_DEBUG ("pt %d, got caps %" GST_PTR_FORMAT, pt, caps);
279
280   return caps;
281 }
282
283 static void
284 gst_rtp_pt_demux_clear_pt_map (GstRtpPtDemux * rtpdemux)
285 {
286   GSList *walk;
287
288   GST_OBJECT_LOCK (rtpdemux);
289   GST_DEBUG ("clearing pt map");
290   for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
291     GstRtpPtDemuxPad *pad = walk->data;
292
293     pad->newcaps = TRUE;
294   }
295   GST_OBJECT_UNLOCK (rtpdemux);
296 }
297
298 static gboolean
299 need_caps_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt)
300 {
301   GSList *walk;
302   gboolean ret = FALSE;
303
304   GST_OBJECT_LOCK (rtpdemux);
305   for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
306     GstRtpPtDemuxPad *pad = walk->data;
307
308     if (pad->pt == pt) {
309       ret = pad->newcaps;
310     }
311   }
312   GST_OBJECT_UNLOCK (rtpdemux);
313
314   return ret;
315 }
316
317
318 static void
319 clear_newcaps_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt)
320 {
321   GSList *walk;
322
323   GST_OBJECT_LOCK (rtpdemux);
324   for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
325     GstRtpPtDemuxPad *pad = walk->data;
326
327     if (pad->pt == pt) {
328       pad->newcaps = FALSE;
329       break;
330     }
331   }
332   GST_OBJECT_UNLOCK (rtpdemux);
333 }
334
335 static gboolean
336 forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
337 {
338   GstPad *srcpad = GST_PAD_CAST (user_data);
339
340   /* Stream start and caps have already been pushed */
341   if (GST_EVENT_TYPE (*event) >= GST_EVENT_SEGMENT)
342     gst_pad_push_event (srcpad, gst_event_ref (*event));
343
344   return TRUE;
345 }
346
347 static GstFlowReturn
348 gst_rtp_pt_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
349 {
350   GstFlowReturn ret = GST_FLOW_OK;
351   GstRtpPtDemux *rtpdemux;
352   guint8 pt;
353   GstPad *srcpad;
354   GstCaps *caps;
355   GstRTPBuffer rtp = { NULL };
356
357   rtpdemux = GST_RTP_PT_DEMUX (parent);
358
359   if (!gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp))
360     goto invalid_buffer;
361
362   pt = gst_rtp_buffer_get_payload_type (&rtp);
363   gst_rtp_buffer_unmap (&rtp);
364
365   GST_DEBUG_OBJECT (rtpdemux, "received buffer for pt %d", pt);
366
367   srcpad = find_pad_for_pt (rtpdemux, pt);
368   if (srcpad == NULL) {
369     /* new PT, create a src pad */
370     GstRtpPtDemuxPad *rtpdemuxpad;
371     GstElementClass *klass;
372     GstPadTemplate *templ;
373     gchar *padname;
374
375     caps = gst_rtp_pt_demux_get_caps (rtpdemux, pt);
376     if (!caps)
377       goto no_caps;
378
379     klass = GST_ELEMENT_GET_CLASS (rtpdemux);
380     templ = gst_element_class_get_pad_template (klass, "src_%u");
381     padname = g_strdup_printf ("src_%u", pt);
382     srcpad = gst_pad_new_from_template (templ, padname);
383     gst_pad_use_fixed_caps (srcpad);
384     g_free (padname);
385     gst_pad_set_event_function (srcpad, gst_rtp_pt_demux_src_event);
386
387     GST_DEBUG ("Adding pt=%d to the list.", pt);
388     rtpdemuxpad = g_slice_new0 (GstRtpPtDemuxPad);
389     rtpdemuxpad->pt = pt;
390     rtpdemuxpad->newcaps = FALSE;
391     rtpdemuxpad->pad = srcpad;
392     gst_object_ref (srcpad);
393     GST_OBJECT_LOCK (rtpdemux);
394     rtpdemux->srcpads = g_slist_append (rtpdemux->srcpads, rtpdemuxpad);
395     GST_OBJECT_UNLOCK (rtpdemux);
396
397     gst_pad_set_active (srcpad, TRUE);
398
399
400     /* First push the stream-start event, it must always come first */
401     gst_pad_push_event (srcpad,
402         gst_pad_get_sticky_event (rtpdemux->sink, GST_EVENT_STREAM_START, 0));
403
404     /* Then caps event is sent */
405     caps = gst_caps_make_writable (caps);
406     gst_caps_set_simple (caps, "payload", G_TYPE_INT, pt, NULL);
407     gst_pad_set_caps (srcpad, caps);
408     gst_caps_unref (caps);
409
410     /* First sticky events on sink pad are forwarded to the new src pad */
411     gst_pad_sticky_events_foreach (rtpdemux->sink, forward_sticky_events,
412         srcpad);
413
414     gst_element_add_pad (GST_ELEMENT_CAST (rtpdemux), srcpad);
415
416     GST_DEBUG ("emitting new-payload-type for pt %d", pt);
417     g_signal_emit (G_OBJECT (rtpdemux),
418         gst_rtp_pt_demux_signals[SIGNAL_NEW_PAYLOAD_TYPE], 0, pt, srcpad);
419   }
420
421   if (pt != rtpdemux->last_pt) {
422     gint emit_pt = pt;
423
424     /* our own signal with an extra flag that this is the only pad */
425     rtpdemux->last_pt = pt;
426     GST_DEBUG ("emitting payload-type-changed for pt %d", emit_pt);
427     g_signal_emit (G_OBJECT (rtpdemux),
428         gst_rtp_pt_demux_signals[SIGNAL_PAYLOAD_TYPE_CHANGE], 0, emit_pt);
429   }
430
431   while (need_caps_for_pt (rtpdemux, pt)) {
432     GST_DEBUG ("need new caps for %d", pt);
433     caps = gst_rtp_pt_demux_get_caps (rtpdemux, pt);
434     if (!caps)
435       goto no_caps;
436
437     clear_newcaps_for_pt (rtpdemux, pt);
438
439     caps = gst_caps_make_writable (caps);
440     gst_caps_set_simple (caps, "payload", G_TYPE_INT, pt, NULL);
441     gst_pad_set_caps (srcpad, caps);
442     gst_caps_unref (caps);
443   }
444
445   /* push to srcpad */
446   ret = gst_pad_push (srcpad, buf);
447
448   gst_object_unref (srcpad);
449
450   return ret;
451
452   /* ERRORS */
453 invalid_buffer:
454   {
455     /* this is fatal and should be filtered earlier */
456     GST_ELEMENT_ERROR (rtpdemux, STREAM, DECODE, (NULL),
457         ("Dropping invalid RTP payload"));
458     gst_buffer_unref (buf);
459     return GST_FLOW_ERROR;
460   }
461 no_caps:
462   {
463     GST_ELEMENT_ERROR (rtpdemux, STREAM, DECODE, (NULL),
464         ("Could not get caps for payload"));
465     gst_buffer_unref (buf);
466     if (srcpad)
467       gst_object_unref (srcpad);
468     return GST_FLOW_ERROR;
469   }
470 }
471
472 static GstPad *
473 find_pad_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt)
474 {
475   GstPad *respad = NULL;
476   GSList *walk;
477
478   GST_OBJECT_LOCK (rtpdemux);
479   for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
480     GstRtpPtDemuxPad *pad = walk->data;
481
482     if (pad->pt == pt) {
483       respad = gst_object_ref (pad->pad);
484       break;
485     }
486   }
487   GST_OBJECT_UNLOCK (rtpdemux);
488
489   return respad;
490 }
491
492 static gboolean
493 gst_rtp_pt_demux_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
494 {
495   GstRtpPtDemux *rtpdemux;
496   gboolean res = FALSE;
497
498   rtpdemux = GST_RTP_PT_DEMUX (parent);
499
500   switch (GST_EVENT_TYPE (event)) {
501     case GST_EVENT_CAPS:
502     {
503       gst_rtp_pt_demux_clear_pt_map (rtpdemux);
504       /* don't forward the event, we cleared the ptmap and on the next buffer we
505        * will add the pt to the caps and push a new caps event */
506       gst_event_unref (event);
507       res = TRUE;
508       break;
509     }
510     case GST_EVENT_CUSTOM_DOWNSTREAM:
511     {
512       const GstStructure *s;
513
514       s = gst_event_get_structure (event);
515
516       if (gst_structure_has_name (s, "GstRTPPacketLost")) {
517         GstPad *srcpad = find_pad_for_pt (rtpdemux, rtpdemux->last_pt);
518
519         if (srcpad) {
520           res = gst_pad_push_event (srcpad, event);
521           gst_object_unref (srcpad);
522         } else {
523           gst_event_unref (event);
524         }
525
526       } else {
527         res = gst_pad_event_default (pad, parent, event);
528       }
529       break;
530     }
531     default:
532       res = gst_pad_event_default (pad, parent, event);
533       break;
534   }
535
536   return res;
537 }
538
539
540 static gboolean
541 gst_rtp_pt_demux_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
542 {
543   GstRtpPtDemux *demux;
544   const GstStructure *s;
545
546   demux = GST_RTP_PT_DEMUX (parent);
547
548   switch (GST_EVENT_TYPE (event)) {
549     case GST_EVENT_CUSTOM_UPSTREAM:
550     case GST_EVENT_CUSTOM_BOTH:
551     case GST_EVENT_CUSTOM_BOTH_OOB:
552       s = gst_event_get_structure (event);
553       if (s && !gst_structure_has_field (s, "payload")) {
554         GSList *walk;
555
556         GST_OBJECT_LOCK (demux);
557         for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
558           GstRtpPtDemuxPad *dpad = (GstRtpPtDemuxPad *) walk->data;
559
560           if (dpad->pad == pad) {
561             GstStructure *ws;
562
563             event =
564                 GST_EVENT_CAST (gst_mini_object_make_writable
565                 (GST_MINI_OBJECT_CAST (event)));
566             ws = gst_event_writable_structure (event);
567             gst_structure_set (ws, "payload", G_TYPE_UINT, dpad->pt, NULL);
568             break;
569           }
570         }
571         GST_OBJECT_UNLOCK (demux);
572       }
573       break;
574     default:
575       break;
576   }
577
578   return gst_pad_event_default (pad, parent, event);
579 }
580
581 /*
582  * Reserves resources for the object.
583  */
584 static gboolean
585 gst_rtp_pt_demux_setup (GstRtpPtDemux * ptdemux)
586 {
587   ptdemux->srcpads = NULL;
588   ptdemux->last_pt = 0xFFFF;
589
590   return TRUE;
591 }
592
593 /*
594  * Free resources for the object.
595  */
596 static void
597 gst_rtp_pt_demux_release (GstRtpPtDemux * ptdemux)
598 {
599   GSList *tmppads;
600   GSList *walk;
601
602   GST_OBJECT_LOCK (ptdemux);
603   tmppads = ptdemux->srcpads;
604   ptdemux->srcpads = NULL;
605   GST_OBJECT_UNLOCK (ptdemux);
606
607   for (walk = tmppads; walk; walk = g_slist_next (walk)) {
608     GstRtpPtDemuxPad *pad = walk->data;
609
610     gst_pad_set_active (pad->pad, FALSE);
611     gst_element_remove_pad (GST_ELEMENT_CAST (ptdemux), pad->pad);
612     g_slice_free (GstRtpPtDemuxPad, pad);
613   }
614   g_slist_free (tmppads);
615 }
616
617 static GstStateChangeReturn
618 gst_rtp_pt_demux_change_state (GstElement * element, GstStateChange transition)
619 {
620   GstStateChangeReturn ret;
621   GstRtpPtDemux *ptdemux;
622
623   ptdemux = GST_RTP_PT_DEMUX (element);
624
625   switch (transition) {
626     case GST_STATE_CHANGE_NULL_TO_READY:
627       if (gst_rtp_pt_demux_setup (ptdemux) != TRUE)
628         ret = GST_STATE_CHANGE_FAILURE;
629       break;
630     case GST_STATE_CHANGE_READY_TO_PAUSED:
631     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
632     default:
633       break;
634   }
635
636   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
637
638   switch (transition) {
639     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
640     case GST_STATE_CHANGE_PAUSED_TO_READY:
641       break;
642     case GST_STATE_CHANGE_READY_TO_NULL:
643       gst_rtp_pt_demux_release (ptdemux);
644       break;
645     default:
646       break;
647   }
648
649   return ret;
650 }