Merge commit '38516ad367128d83f9e156529018adb4433cd328' into 0.11
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpmp4gpay.c
1 /* GStreamer
2  * Copyright (C) <2006> Wim Taymans <wim.taymans@gmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <string.h>
25
26 #include <gst/base/gstbitreader.h>
27 #include <gst/rtp/gstrtpbuffer.h>
28
29 #include "gstrtpmp4gpay.h"
30
31 GST_DEBUG_CATEGORY_STATIC (rtpmp4gpay_debug);
32 #define GST_CAT_DEFAULT (rtpmp4gpay_debug)
33
34 static GstStaticPadTemplate gst_rtp_mp4g_pay_sink_template =
35     GST_STATIC_PAD_TEMPLATE ("sink",
36     GST_PAD_SINK,
37     GST_PAD_ALWAYS,
38     GST_STATIC_CAPS ("video/mpeg,"
39         "mpegversion=(int) 4,"
40         "systemstream=(boolean)false;"
41         "audio/mpeg," "mpegversion=(int) 4, " "stream-format=(string) raw")
42     );
43
44 static GstStaticPadTemplate gst_rtp_mp4g_pay_src_template =
45 GST_STATIC_PAD_TEMPLATE ("src",
46     GST_PAD_SRC,
47     GST_PAD_ALWAYS,
48     GST_STATIC_CAPS ("application/x-rtp, "
49         "media = (string) { \"video\", \"audio\", \"application\" }, "
50         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
51         "clock-rate = (int) [1, MAX ], "
52         "encoding-name = (string) \"MPEG4-GENERIC\", "
53         /* required string params */
54         "streamtype = (string) { \"4\", \"5\" }, "      /* 4 = video, 5 = audio */
55         /* "profile-level-id = (string) [1,MAX], " */
56         /* "config = (string) [1,MAX]" */
57         "mode = (string) { \"generic\", \"CELP-cbr\", \"CELP-vbr\", \"AAC-lbr\", \"AAC-hbr\" } "
58         /* Optional general parameters */
59         /* "objecttype = (string) [1,MAX], " */
60         /* "constantsize = (string) [1,MAX], " *//* constant size of each AU */
61         /* "constantduration = (string) [1,MAX], " *//* constant duration of each AU */
62         /* "maxdisplacement = (string) [1,MAX], " */
63         /* "de-interleavebuffersize = (string) [1,MAX], " */
64         /* Optional configuration parameters */
65         /* "sizelength = (string) [1, 16], " *//* max 16 bits, should be enough... */
66         /* "indexlength = (string) [1, 8], " */
67         /* "indexdeltalength = (string) [1, 8], " */
68         /* "ctsdeltalength = (string) [1, 64], " */
69         /* "dtsdeltalength = (string) [1, 64], " */
70         /* "randomaccessindication = (string) {0, 1}, " */
71         /* "streamstateindication = (string) [0, 64], " */
72         /* "auxiliarydatasizelength = (string) [0, 64]" */ )
73     );
74
75
76 static void gst_rtp_mp4g_pay_finalize (GObject * object);
77
78 static GstStateChangeReturn gst_rtp_mp4g_pay_change_state (GstElement * element,
79     GstStateChange transition);
80
81 static gboolean gst_rtp_mp4g_pay_setcaps (GstRTPBasePayload * payload,
82     GstCaps * caps);
83 static GstFlowReturn gst_rtp_mp4g_pay_handle_buffer (GstRTPBasePayload *
84     payload, GstBuffer * buffer);
85 static gboolean gst_rtp_mp4g_pay_sink_event (GstRTPBasePayload * payload,
86     GstEvent * event);
87
88 #define gst_rtp_mp4g_pay_parent_class parent_class
89 G_DEFINE_TYPE (GstRtpMP4GPay, gst_rtp_mp4g_pay, GST_TYPE_RTP_BASE_PAYLOAD)
90
91      static void gst_rtp_mp4g_pay_class_init (GstRtpMP4GPayClass * klass)
92 {
93   GObjectClass *gobject_class;
94   GstElementClass *gstelement_class;
95   GstRTPBasePayloadClass *gstrtpbasepayload_class;
96
97   gobject_class = (GObjectClass *) klass;
98   gstelement_class = (GstElementClass *) klass;
99   gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
100
101   gobject_class->finalize = gst_rtp_mp4g_pay_finalize;
102
103   gstelement_class->change_state = gst_rtp_mp4g_pay_change_state;
104
105   gstrtpbasepayload_class->set_caps = gst_rtp_mp4g_pay_setcaps;
106   gstrtpbasepayload_class->handle_buffer = gst_rtp_mp4g_pay_handle_buffer;
107   gstrtpbasepayload_class->sink_event = gst_rtp_mp4g_pay_sink_event;
108
109   gst_element_class_add_pad_template (gstelement_class,
110       gst_static_pad_template_get (&gst_rtp_mp4g_pay_src_template));
111   gst_element_class_add_pad_template (gstelement_class,
112       gst_static_pad_template_get (&gst_rtp_mp4g_pay_sink_template));
113
114   gst_element_class_set_details_simple (gstelement_class,
115       "RTP MPEG4 ES payloader",
116       "Codec/Payloader/Network/RTP",
117       "Payload MPEG4 elementary streams as RTP packets (RFC 3640)",
118       "Wim Taymans <wim.taymans@gmail.com>");
119
120   GST_DEBUG_CATEGORY_INIT (rtpmp4gpay_debug, "rtpmp4gpay", 0,
121       "MP4-generic RTP Payloader");
122 }
123
124 static void
125 gst_rtp_mp4g_pay_init (GstRtpMP4GPay * rtpmp4gpay)
126 {
127   rtpmp4gpay->adapter = gst_adapter_new ();
128 }
129
130 static void
131 gst_rtp_mp4g_pay_reset (GstRtpMP4GPay * rtpmp4gpay)
132 {
133   GST_DEBUG_OBJECT (rtpmp4gpay, "reset");
134
135   gst_adapter_clear (rtpmp4gpay->adapter);
136   rtpmp4gpay->offset = 0;
137 }
138
139 static void
140 gst_rtp_mp4g_pay_cleanup (GstRtpMP4GPay * rtpmp4gpay)
141 {
142   gst_rtp_mp4g_pay_reset (rtpmp4gpay);
143
144   g_free (rtpmp4gpay->params);
145   rtpmp4gpay->params = NULL;
146
147   if (rtpmp4gpay->config)
148     gst_buffer_unref (rtpmp4gpay->config);
149   rtpmp4gpay->config = NULL;
150
151   g_free (rtpmp4gpay->profile);
152   rtpmp4gpay->profile = NULL;
153
154   rtpmp4gpay->streamtype = NULL;
155   rtpmp4gpay->mode = NULL;
156
157   rtpmp4gpay->frame_len = 0;
158 }
159
160 static void
161 gst_rtp_mp4g_pay_finalize (GObject * object)
162 {
163   GstRtpMP4GPay *rtpmp4gpay;
164
165   rtpmp4gpay = GST_RTP_MP4G_PAY (object);
166
167   gst_rtp_mp4g_pay_cleanup (rtpmp4gpay);
168
169   g_object_unref (rtpmp4gpay->adapter);
170   rtpmp4gpay->adapter = NULL;
171
172   G_OBJECT_CLASS (parent_class)->finalize (object);
173 }
174
175 static const unsigned int sampling_table[16] = {
176   96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
177   16000, 12000, 11025, 8000, 7350, 0, 0, 0
178 };
179
180 static gboolean
181 gst_rtp_mp4g_pay_parse_audio_config (GstRtpMP4GPay * rtpmp4gpay,
182     GstBuffer * buffer)
183 {
184   GstMapInfo map;
185   guint8 objectType = 0;
186   guint8 samplingIdx = 0;
187   guint8 channelCfg = 0;
188   GstBitReader br;
189
190   gst_buffer_map (buffer, &map, GST_MAP_READ);
191
192   gst_bit_reader_init (&br, map.data, map.size);
193
194   /* any object type is fine, we need to copy it to the profile-level-id field. */
195   if (!gst_bit_reader_get_bits_uint8 (&br, &objectType, 5))
196     goto too_short;
197   if (objectType == 0)
198     goto invalid_object;
199
200   if (!gst_bit_reader_get_bits_uint8 (&br, &samplingIdx, 4))
201     goto too_short;
202   /* only fixed values for now */
203   if (samplingIdx > 12 && samplingIdx != 15)
204     goto wrong_freq;
205
206   if (!gst_bit_reader_get_bits_uint8 (&br, &channelCfg, 4))
207     goto too_short;
208   if (channelCfg > 7)
209     goto wrong_channels;
210
211   /* rtp rate depends on sampling rate of the audio */
212   if (samplingIdx == 15) {
213     guint32 rate = 0;
214
215     /* index of 15 means we get the rate in the next 24 bits */
216     if (!gst_bit_reader_get_bits_uint32 (&br, &rate, 24))
217       goto too_short;
218
219     rtpmp4gpay->rate = rate;
220   } else {
221     /* else use the rate from the table */
222     rtpmp4gpay->rate = sampling_table[samplingIdx];
223   }
224
225   rtpmp4gpay->frame_len = 1024;
226
227   switch (objectType) {
228     case 1:
229     case 2:
230     case 3:
231     case 4:
232     case 6:
233     case 7:
234     {
235       guint8 frameLenFlag = 0;
236
237       if (gst_bit_reader_get_bits_uint8 (&br, &frameLenFlag, 1))
238         if (frameLenFlag)
239           rtpmp4gpay->frame_len = 960;
240
241       break;
242     }
243     default:
244       break;
245   }
246
247   /* extra rtp params contain the number of channels */
248   g_free (rtpmp4gpay->params);
249   rtpmp4gpay->params = g_strdup_printf ("%d", channelCfg);
250   /* audio stream type */
251   rtpmp4gpay->streamtype = "5";
252   /* mode only high bitrate for now */
253   rtpmp4gpay->mode = "AAC-hbr";
254   /* profile */
255   g_free (rtpmp4gpay->profile);
256   rtpmp4gpay->profile = g_strdup_printf ("%d", objectType);
257
258   GST_DEBUG_OBJECT (rtpmp4gpay,
259       "objectType: %d, samplingIdx: %d (%d), channelCfg: %d, frame_len %d",
260       objectType, samplingIdx, rtpmp4gpay->rate, channelCfg,
261       rtpmp4gpay->frame_len);
262
263   gst_buffer_unmap (buffer, &map);
264   return TRUE;
265
266   /* ERROR */
267 too_short:
268   {
269     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, FORMAT,
270         (NULL), ("config string too short"));
271     gst_buffer_unmap (buffer, &map);
272     return FALSE;
273   }
274 invalid_object:
275   {
276     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, FORMAT,
277         (NULL), ("invalid object type"));
278     gst_buffer_unmap (buffer, &map);
279     return FALSE;
280   }
281 wrong_freq:
282   {
283     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, NOT_IMPLEMENTED,
284         (NULL), ("unsupported frequency index %d", samplingIdx));
285     gst_buffer_unmap (buffer, &map);
286     return FALSE;
287   }
288 wrong_channels:
289   {
290     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, NOT_IMPLEMENTED,
291         (NULL), ("unsupported number of channels %d, must < 8", channelCfg));
292     gst_buffer_unmap (buffer, &map);
293     return FALSE;
294   }
295 }
296
297 #define VOS_STARTCODE                   0x000001B0
298
299 static gboolean
300 gst_rtp_mp4g_pay_parse_video_config (GstRtpMP4GPay * rtpmp4gpay,
301     GstBuffer * buffer)
302 {
303   GstMapInfo map;
304   guint32 code;
305
306   gst_buffer_map (buffer, &map, GST_MAP_READ);
307
308   if (map.size < 5)
309     goto too_short;
310
311   code = GST_READ_UINT32_BE (map.data);
312
313   g_free (rtpmp4gpay->profile);
314   if (code == VOS_STARTCODE) {
315     /* get profile */
316     rtpmp4gpay->profile = g_strdup_printf ("%d", (gint) map.data[4]);
317   } else {
318     GST_ELEMENT_WARNING (rtpmp4gpay, STREAM, FORMAT,
319         (NULL), ("profile not found in config string, assuming \'1\'"));
320     rtpmp4gpay->profile = g_strdup ("1");
321   }
322
323   /* fixed rate */
324   rtpmp4gpay->rate = 90000;
325   /* video stream type */
326   rtpmp4gpay->streamtype = "4";
327   /* no params for video */
328   rtpmp4gpay->params = NULL;
329   /* mode */
330   rtpmp4gpay->mode = "generic";
331
332   GST_LOG_OBJECT (rtpmp4gpay, "profile %s", rtpmp4gpay->profile);
333
334   gst_buffer_unmap (buffer, &map);
335
336   return TRUE;
337
338   /* ERROR */
339 too_short:
340   {
341     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, FORMAT,
342         (NULL), ("config string too short"));
343     gst_buffer_unmap (buffer, &map);
344     return FALSE;
345   }
346 }
347
348 static gboolean
349 gst_rtp_mp4g_pay_new_caps (GstRtpMP4GPay * rtpmp4gpay)
350 {
351   gchar *config;
352   GValue v = { 0 };
353   gboolean res;
354
355 #define MP4GCAPS                                                \
356   "streamtype", G_TYPE_STRING, rtpmp4gpay->streamtype,          \
357   "profile-level-id", G_TYPE_STRING, rtpmp4gpay->profile,       \
358   "mode", G_TYPE_STRING, rtpmp4gpay->mode,                      \
359   "config", G_TYPE_STRING, config,                              \
360   "sizelength", G_TYPE_STRING, "13",                            \
361   "indexlength", G_TYPE_STRING, "3",                            \
362   "indexdeltalength", G_TYPE_STRING, "3",                       \
363   NULL
364
365   g_value_init (&v, GST_TYPE_BUFFER);
366   gst_value_set_buffer (&v, rtpmp4gpay->config);
367   config = gst_value_serialize (&v);
368
369   /* hmm, silly */
370   if (rtpmp4gpay->params) {
371     res = gst_rtp_base_payload_set_outcaps (GST_RTP_BASE_PAYLOAD (rtpmp4gpay),
372         "encoding-params", G_TYPE_STRING, rtpmp4gpay->params, MP4GCAPS);
373   } else {
374     res = gst_rtp_base_payload_set_outcaps (GST_RTP_BASE_PAYLOAD (rtpmp4gpay),
375         MP4GCAPS);
376   }
377
378   g_value_unset (&v);
379   g_free (config);
380
381 #undef MP4GCAPS
382   return res;
383 }
384
385 static gboolean
386 gst_rtp_mp4g_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
387 {
388   GstRtpMP4GPay *rtpmp4gpay;
389   GstStructure *structure;
390   const GValue *codec_data;
391   const gchar *media_type = NULL;
392   gboolean res;
393
394   rtpmp4gpay = GST_RTP_MP4G_PAY (payload);
395
396   structure = gst_caps_get_structure (caps, 0);
397
398   codec_data = gst_structure_get_value (structure, "codec_data");
399   if (codec_data) {
400     GST_LOG_OBJECT (rtpmp4gpay, "got codec_data");
401     if (G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) {
402       GstBuffer *buffer;
403       const gchar *name;
404
405       buffer = gst_value_get_buffer (codec_data);
406       GST_LOG_OBJECT (rtpmp4gpay, "configuring codec_data");
407
408       name = gst_structure_get_name (structure);
409
410       /* parse buffer */
411       if (!strcmp (name, "audio/mpeg")) {
412         res = gst_rtp_mp4g_pay_parse_audio_config (rtpmp4gpay, buffer);
413         media_type = "audio";
414       } else if (!strcmp (name, "video/mpeg")) {
415         res = gst_rtp_mp4g_pay_parse_video_config (rtpmp4gpay, buffer);
416         media_type = "video";
417       } else {
418         res = FALSE;
419       }
420       if (!res)
421         goto config_failed;
422
423       /* now we can configure the buffer */
424       if (rtpmp4gpay->config)
425         gst_buffer_unref (rtpmp4gpay->config);
426
427       rtpmp4gpay->config = gst_buffer_copy (buffer);
428     }
429   }
430   if (media_type == NULL)
431     goto config_failed;
432
433   gst_rtp_base_payload_set_options (payload, media_type, TRUE, "MPEG4-GENERIC",
434       rtpmp4gpay->rate);
435
436   res = gst_rtp_mp4g_pay_new_caps (rtpmp4gpay);
437
438   return res;
439
440   /* ERRORS */
441 config_failed:
442   {
443     GST_DEBUG_OBJECT (rtpmp4gpay, "failed to parse config");
444     return FALSE;
445   }
446 }
447
448 static GstFlowReturn
449 gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay)
450 {
451   guint avail, total;
452   GstBuffer *outbuf;
453   GstFlowReturn ret;
454   guint mtu;
455
456   /* the data available in the adapter is either smaller
457    * than the MTU or bigger. In the case it is smaller, the complete
458    * adapter contents can be put in one packet. In the case the
459    * adapter has more than one MTU, we need to fragment the MPEG data
460    * over multiple packets. */
461   total = avail = gst_adapter_available (rtpmp4gpay->adapter);
462
463   ret = GST_FLOW_OK;
464   mtu = GST_RTP_BASE_PAYLOAD_MTU (rtpmp4gpay);
465
466   while (avail > 0) {
467     guint towrite;
468     guint8 *payload;
469     guint payload_len;
470     guint packet_len;
471     GstRTPBuffer rtp = { NULL };
472
473     /* this will be the total lenght of the packet */
474     packet_len = gst_rtp_buffer_calc_packet_len (avail, 0, 0);
475
476     /* fill one MTU or all available bytes, we need 4 spare bytes for
477      * the AU header. */
478     towrite = MIN (packet_len, mtu - 4);
479
480     /* this is the payload length */
481     payload_len = gst_rtp_buffer_calc_payload_len (towrite, 0, 0);
482
483     GST_DEBUG_OBJECT (rtpmp4gpay,
484         "avail %d, towrite %d, packet_len %d, payload_len %d", avail, towrite,
485         packet_len, payload_len);
486
487     /* create buffer to hold the payload, also make room for the 4 header bytes. */
488     outbuf = gst_rtp_buffer_new_allocate (payload_len + 4, 0, 0);
489
490     gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
491
492     /* copy payload */
493     payload = gst_rtp_buffer_get_payload (&rtp);
494
495     /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
496      * |AU-headers-length|AU-header|AU-header|      |AU-header|padding|
497      * |                 |   (1)   |   (2)   |      |   (n)   | bits  |
498      * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
499      */
500     /* AU-headers-length, we only have 1 AU-header */
501     payload[0] = 0x00;
502     payload[1] = 0x10;          /* we use 16 bits for the header */
503
504     /* +---------------------------------------+
505      * |     AU-size                           |
506      * +---------------------------------------+
507      * |     AU-Index / AU-Index-delta         |
508      * +---------------------------------------+
509      * |     CTS-flag                          |
510      * +---------------------------------------+
511      * |     CTS-delta                         |
512      * +---------------------------------------+
513      * |     DTS-flag                          |
514      * +---------------------------------------+
515      * |     DTS-delta                         |
516      * +---------------------------------------+
517      * |     RAP-flag                          |
518      * +---------------------------------------+
519      * |     Stream-state                      |
520      * +---------------------------------------+
521      */
522     /* The AU-header, no CTS, DTS, RAP, Stream-state 
523      *
524      * AU-size is always the total size of the AU, not the fragmented size 
525      */
526     payload[2] = (total & 0x1fe0) >> 5;
527     payload[3] = (total & 0x1f) << 3;   /* we use 13 bits for the size, 3 bits index */
528
529     /* copy stuff from adapter to payload */
530     gst_adapter_copy (rtpmp4gpay->adapter, &payload[4], 0, payload_len);
531     gst_adapter_flush (rtpmp4gpay->adapter, payload_len);
532
533     /* marker only if the packet is complete */
534     gst_rtp_buffer_set_marker (&rtp, avail <= payload_len);
535
536     gst_rtp_buffer_unmap (&rtp);
537
538     GST_BUFFER_TIMESTAMP (outbuf) = rtpmp4gpay->first_timestamp;
539     GST_BUFFER_DURATION (outbuf) = rtpmp4gpay->first_duration;
540
541     if (rtpmp4gpay->frame_len) {
542       GST_BUFFER_OFFSET (outbuf) = rtpmp4gpay->offset;
543       rtpmp4gpay->offset += rtpmp4gpay->frame_len;
544     }
545
546     ret = gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (rtpmp4gpay), outbuf);
547
548     avail -= payload_len;
549   }
550
551   return ret;
552 }
553
554 /* we expect buffers as exactly one complete AU
555  */
556 static GstFlowReturn
557 gst_rtp_mp4g_pay_handle_buffer (GstRTPBasePayload * basepayload,
558     GstBuffer * buffer)
559 {
560   GstRtpMP4GPay *rtpmp4gpay;
561
562   rtpmp4gpay = GST_RTP_MP4G_PAY (basepayload);
563
564   rtpmp4gpay->first_timestamp = GST_BUFFER_TIMESTAMP (buffer);
565   rtpmp4gpay->first_duration = GST_BUFFER_DURATION (buffer);
566
567   /* we always encode and flush a full AU */
568   gst_adapter_push (rtpmp4gpay->adapter, buffer);
569
570   return gst_rtp_mp4g_pay_flush (rtpmp4gpay);
571 }
572
573 static gboolean
574 gst_rtp_mp4g_pay_sink_event (GstRTPBasePayload * payload, GstEvent * event)
575 {
576   GstRtpMP4GPay *rtpmp4gpay;
577
578   rtpmp4gpay = GST_RTP_MP4G_PAY (payload);
579
580   GST_DEBUG ("Got event: %s", GST_EVENT_TYPE_NAME (event));
581
582   switch (GST_EVENT_TYPE (event)) {
583     case GST_EVENT_SEGMENT:
584     case GST_EVENT_EOS:
585       /* This flush call makes sure that the last buffer is always pushed
586        * to the base payloader */
587       gst_rtp_mp4g_pay_flush (rtpmp4gpay);
588       break;
589     case GST_EVENT_FLUSH_STOP:
590       gst_rtp_mp4g_pay_reset (rtpmp4gpay);
591       break;
592     default:
593       break;
594   }
595
596   /* let parent handle event too */
597   return GST_RTP_BASE_PAYLOAD_CLASS (parent_class)->sink_event (payload, event);
598 }
599
600 static GstStateChangeReturn
601 gst_rtp_mp4g_pay_change_state (GstElement * element, GstStateChange transition)
602 {
603   GstStateChangeReturn ret;
604   GstRtpMP4GPay *rtpmp4gpay;
605
606   rtpmp4gpay = GST_RTP_MP4G_PAY (element);
607
608   switch (transition) {
609     case GST_STATE_CHANGE_READY_TO_PAUSED:
610       gst_rtp_mp4g_pay_cleanup (rtpmp4gpay);
611       break;
612     default:
613       break;
614   }
615
616   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
617
618   switch (transition) {
619     case GST_STATE_CHANGE_PAUSED_TO_READY:
620       gst_rtp_mp4g_pay_cleanup (rtpmp4gpay);
621       break;
622     default:
623       break;
624   }
625
626   return ret;
627 }
628
629 gboolean
630 gst_rtp_mp4g_pay_plugin_init (GstPlugin * plugin)
631 {
632   return gst_element_register (plugin, "rtpmp4gpay",
633       GST_RANK_SECONDARY, GST_TYPE_RTP_MP4G_PAY);
634 }