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