Merge branch 'master' 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   guint8 *data;
185   gsize size;
186   guint8 objectType = 0;
187   guint8 samplingIdx = 0;
188   guint8 channelCfg = 0;
189   GstBitReader br;
190
191   data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
192
193   gst_bit_reader_init (&br, data, size);
194
195   /* any object type is fine, we need to copy it to the profile-level-id field. */
196   if (!gst_bit_reader_get_bits_uint8 (&br, &objectType, 5))
197     goto too_short;
198   if (objectType == 0)
199     goto invalid_object;
200
201   if (!gst_bit_reader_get_bits_uint8 (&br, &samplingIdx, 4))
202     goto too_short;
203   /* only fixed values for now */
204   if (samplingIdx > 12 && samplingIdx != 15)
205     goto wrong_freq;
206
207   if (!gst_bit_reader_get_bits_uint8 (&br, &channelCfg, 4))
208     goto too_short;
209   if (channelCfg > 7)
210     goto wrong_channels;
211
212   /* rtp rate depends on sampling rate of the audio */
213   if (samplingIdx == 15) {
214     guint32 rate = 0;
215
216     /* index of 15 means we get the rate in the next 24 bits */
217     if (!gst_bit_reader_get_bits_uint32 (&br, &rate, 24))
218       goto too_short;
219
220     rtpmp4gpay->rate = rate;
221   } else {
222     /* else use the rate from the table */
223     rtpmp4gpay->rate = sampling_table[samplingIdx];
224   }
225
226   rtpmp4gpay->frame_len = 1024;
227
228   switch (objectType) {
229     case 1:
230     case 2:
231     case 3:
232     case 4:
233     case 6:
234     case 7:
235     {
236       guint8 frameLenFlag = 0;
237
238       if (gst_bit_reader_get_bits_uint8 (&br, &frameLenFlag, 1))
239         if (frameLenFlag)
240           rtpmp4gpay->frame_len = 960;
241
242       break;
243     }
244     default:
245       break;
246   }
247
248   /* extra rtp params contain the number of channels */
249   g_free (rtpmp4gpay->params);
250   rtpmp4gpay->params = g_strdup_printf ("%d", channelCfg);
251   /* audio stream type */
252   rtpmp4gpay->streamtype = "5";
253   /* mode only high bitrate for now */
254   rtpmp4gpay->mode = "AAC-hbr";
255   /* profile */
256   g_free (rtpmp4gpay->profile);
257   rtpmp4gpay->profile = g_strdup_printf ("%d", objectType);
258
259   GST_DEBUG_OBJECT (rtpmp4gpay,
260       "objectType: %d, samplingIdx: %d (%d), channelCfg: %d, frame_len %d",
261       objectType, samplingIdx, rtpmp4gpay->rate, channelCfg,
262       rtpmp4gpay->frame_len);
263
264   gst_buffer_unmap (buffer, data, -1);
265   return TRUE;
266
267   /* ERROR */
268 too_short:
269   {
270     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, FORMAT,
271         (NULL), ("config string too short"));
272     gst_buffer_unmap (buffer, data, -1);
273     return FALSE;
274   }
275 invalid_object:
276   {
277     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, FORMAT,
278         (NULL), ("invalid object type"));
279     gst_buffer_unmap (buffer, data, -1);
280     return FALSE;
281   }
282 wrong_freq:
283   {
284     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, NOT_IMPLEMENTED,
285         (NULL), ("unsupported frequency index %d", samplingIdx));
286     gst_buffer_unmap (buffer, data, -1);
287     return FALSE;
288   }
289 wrong_channels:
290   {
291     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, NOT_IMPLEMENTED,
292         (NULL), ("unsupported number of channels %d, must < 8", channelCfg));
293     gst_buffer_unmap (buffer, data, -1);
294     return FALSE;
295   }
296 }
297
298 #define VOS_STARTCODE                   0x000001B0
299
300 static gboolean
301 gst_rtp_mp4g_pay_parse_video_config (GstRtpMP4GPay * rtpmp4gpay,
302     GstBuffer * buffer)
303 {
304   guint8 *data;
305   gsize size;
306   guint32 code;
307
308   data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
309
310   if (size < 5)
311     goto too_short;
312
313   code = GST_READ_UINT32_BE (data);
314
315   g_free (rtpmp4gpay->profile);
316   if (code == VOS_STARTCODE) {
317     /* get profile */
318     rtpmp4gpay->profile = g_strdup_printf ("%d", (gint) data[4]);
319   } else {
320     GST_ELEMENT_WARNING (rtpmp4gpay, STREAM, FORMAT,
321         (NULL), ("profile not found in config string, assuming \'1\'"));
322     rtpmp4gpay->profile = g_strdup ("1");
323   }
324
325   /* fixed rate */
326   rtpmp4gpay->rate = 90000;
327   /* video stream type */
328   rtpmp4gpay->streamtype = "4";
329   /* no params for video */
330   rtpmp4gpay->params = NULL;
331   /* mode */
332   rtpmp4gpay->mode = "generic";
333
334   GST_LOG_OBJECT (rtpmp4gpay, "profile %s", rtpmp4gpay->profile);
335
336   gst_buffer_unmap (buffer, data, -1);
337
338   return TRUE;
339
340   /* ERROR */
341 too_short:
342   {
343     GST_ELEMENT_ERROR (rtpmp4gpay, STREAM, FORMAT,
344         (NULL), ("config string too short"));
345     gst_buffer_unmap (buffer, data, -1);
346     return FALSE;
347   }
348 }
349
350 static gboolean
351 gst_rtp_mp4g_pay_new_caps (GstRtpMP4GPay * rtpmp4gpay)
352 {
353   gchar *config;
354   GValue v = { 0 };
355   gboolean res;
356
357 #define MP4GCAPS                                                \
358   "streamtype", G_TYPE_STRING, rtpmp4gpay->streamtype,          \
359   "profile-level-id", G_TYPE_STRING, rtpmp4gpay->profile,       \
360   "mode", G_TYPE_STRING, rtpmp4gpay->mode,                      \
361   "config", G_TYPE_STRING, config,                              \
362   "sizelength", G_TYPE_STRING, "13",                            \
363   "indexlength", G_TYPE_STRING, "3",                            \
364   "indexdeltalength", G_TYPE_STRING, "3",                       \
365   NULL
366
367   g_value_init (&v, GST_TYPE_BUFFER);
368   gst_value_set_buffer (&v, rtpmp4gpay->config);
369   config = gst_value_serialize (&v);
370
371   /* hmm, silly */
372   if (rtpmp4gpay->params) {
373     res = gst_rtp_base_payload_set_outcaps (GST_RTP_BASE_PAYLOAD (rtpmp4gpay),
374         "encoding-params", G_TYPE_STRING, rtpmp4gpay->params, MP4GCAPS);
375   } else {
376     res = gst_rtp_base_payload_set_outcaps (GST_RTP_BASE_PAYLOAD (rtpmp4gpay),
377         MP4GCAPS);
378   }
379
380   g_value_unset (&v);
381   g_free (config);
382
383 #undef MP4GCAPS
384   return res;
385 }
386
387 static gboolean
388 gst_rtp_mp4g_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
389 {
390   GstRtpMP4GPay *rtpmp4gpay;
391   GstStructure *structure;
392   const GValue *codec_data;
393   const gchar *media_type = NULL;
394   gboolean res;
395
396   rtpmp4gpay = GST_RTP_MP4G_PAY (payload);
397
398   structure = gst_caps_get_structure (caps, 0);
399
400   codec_data = gst_structure_get_value (structure, "codec_data");
401   if (codec_data) {
402     GST_LOG_OBJECT (rtpmp4gpay, "got codec_data");
403     if (G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) {
404       GstBuffer *buffer;
405       const gchar *name;
406
407       buffer = gst_value_get_buffer (codec_data);
408       GST_LOG_OBJECT (rtpmp4gpay, "configuring codec_data");
409
410       name = gst_structure_get_name (structure);
411
412       /* parse buffer */
413       if (!strcmp (name, "audio/mpeg")) {
414         res = gst_rtp_mp4g_pay_parse_audio_config (rtpmp4gpay, buffer);
415         media_type = "audio";
416       } else if (!strcmp (name, "video/mpeg")) {
417         res = gst_rtp_mp4g_pay_parse_video_config (rtpmp4gpay, buffer);
418         media_type = "video";
419       } else {
420         res = FALSE;
421       }
422       if (!res)
423         goto config_failed;
424
425       /* now we can configure the buffer */
426       if (rtpmp4gpay->config)
427         gst_buffer_unref (rtpmp4gpay->config);
428
429       rtpmp4gpay->config = gst_buffer_copy (buffer);
430     }
431   }
432   if (media_type == NULL)
433     goto config_failed;
434
435   gst_rtp_base_payload_set_options (payload, media_type, TRUE, "MPEG4-GENERIC",
436       rtpmp4gpay->rate);
437
438   res = gst_rtp_mp4g_pay_new_caps (rtpmp4gpay);
439
440   return res;
441
442   /* ERRORS */
443 config_failed:
444   {
445     GST_DEBUG_OBJECT (rtpmp4gpay, "failed to parse config");
446     return FALSE;
447   }
448 }
449
450 static GstFlowReturn
451 gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay)
452 {
453   guint avail, total;
454   GstBuffer *outbuf;
455   GstFlowReturn ret;
456   guint mtu;
457
458   /* the data available in the adapter is either smaller
459    * than the MTU or bigger. In the case it is smaller, the complete
460    * adapter contents can be put in one packet. In the case the
461    * adapter has more than one MTU, we need to fragment the MPEG data
462    * over multiple packets. */
463   total = avail = gst_adapter_available (rtpmp4gpay->adapter);
464
465   ret = GST_FLOW_OK;
466   mtu = GST_RTP_BASE_PAYLOAD_MTU (rtpmp4gpay);
467
468   while (avail > 0) {
469     guint towrite;
470     guint8 *payload;
471     guint payload_len;
472     guint packet_len;
473     GstRTPBuffer rtp = { NULL };
474
475     /* this will be the total lenght of the packet */
476     packet_len = gst_rtp_buffer_calc_packet_len (avail, 0, 0);
477
478     /* fill one MTU or all available bytes, we need 4 spare bytes for
479      * the AU header. */
480     towrite = MIN (packet_len, mtu - 4);
481
482     /* this is the payload length */
483     payload_len = gst_rtp_buffer_calc_payload_len (towrite, 0, 0);
484
485     GST_DEBUG_OBJECT (rtpmp4gpay,
486         "avail %d, towrite %d, packet_len %d, payload_len %d", avail, towrite,
487         packet_len, payload_len);
488
489     /* create buffer to hold the payload, also make room for the 4 header bytes. */
490     outbuf = gst_rtp_buffer_new_allocate (payload_len + 4, 0, 0);
491
492     gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
493
494     /* copy payload */
495     payload = gst_rtp_buffer_get_payload (&rtp);
496
497     /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
498      * |AU-headers-length|AU-header|AU-header|      |AU-header|padding|
499      * |                 |   (1)   |   (2)   |      |   (n)   | bits  |
500      * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
501      */
502     /* AU-headers-length, we only have 1 AU-header */
503     payload[0] = 0x00;
504     payload[1] = 0x10;          /* we use 16 bits for the header */
505
506     /* +---------------------------------------+
507      * |     AU-size                           |
508      * +---------------------------------------+
509      * |     AU-Index / AU-Index-delta         |
510      * +---------------------------------------+
511      * |     CTS-flag                          |
512      * +---------------------------------------+
513      * |     CTS-delta                         |
514      * +---------------------------------------+
515      * |     DTS-flag                          |
516      * +---------------------------------------+
517      * |     DTS-delta                         |
518      * +---------------------------------------+
519      * |     RAP-flag                          |
520      * +---------------------------------------+
521      * |     Stream-state                      |
522      * +---------------------------------------+
523      */
524     /* The AU-header, no CTS, DTS, RAP, Stream-state 
525      *
526      * AU-size is always the total size of the AU, not the fragmented size 
527      */
528     payload[2] = (total & 0x1fe0) >> 5;
529     payload[3] = (total & 0x1f) << 3;   /* we use 13 bits for the size, 3 bits index */
530
531     /* copy stuff from adapter to payload */
532     gst_adapter_copy (rtpmp4gpay->adapter, &payload[4], 0, payload_len);
533     gst_adapter_flush (rtpmp4gpay->adapter, payload_len);
534
535     /* marker only if the packet is complete */
536     gst_rtp_buffer_set_marker (&rtp, avail <= payload_len);
537
538     gst_rtp_buffer_unmap (&rtp);
539
540     GST_BUFFER_TIMESTAMP (outbuf) = rtpmp4gpay->first_timestamp;
541     GST_BUFFER_DURATION (outbuf) = rtpmp4gpay->first_duration;
542
543     if (rtpmp4gpay->frame_len) {
544       GST_BUFFER_OFFSET (outbuf) = rtpmp4gpay->offset;
545       rtpmp4gpay->offset += rtpmp4gpay->frame_len;
546     }
547
548     ret = gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (rtpmp4gpay), outbuf);
549
550     avail -= payload_len;
551   }
552
553   return ret;
554 }
555
556 /* we expect buffers as exactly one complete AU
557  */
558 static GstFlowReturn
559 gst_rtp_mp4g_pay_handle_buffer (GstRTPBasePayload * basepayload,
560     GstBuffer * buffer)
561 {
562   GstRtpMP4GPay *rtpmp4gpay;
563
564   rtpmp4gpay = GST_RTP_MP4G_PAY (basepayload);
565
566   rtpmp4gpay->first_timestamp = GST_BUFFER_TIMESTAMP (buffer);
567   rtpmp4gpay->first_duration = GST_BUFFER_DURATION (buffer);
568
569   /* we always encode and flush a full AU */
570   gst_adapter_push (rtpmp4gpay->adapter, buffer);
571
572   return gst_rtp_mp4g_pay_flush (rtpmp4gpay);
573 }
574
575 static gboolean
576 gst_rtp_mp4g_pay_sink_event (GstRTPBasePayload * payload, GstEvent * event)
577 {
578   GstRtpMP4GPay *rtpmp4gpay;
579
580   rtpmp4gpay = GST_RTP_MP4G_PAY (payload);
581
582   GST_DEBUG ("Got event: %s", GST_EVENT_TYPE_NAME (event));
583
584   switch (GST_EVENT_TYPE (event)) {
585     case GST_EVENT_SEGMENT:
586     case GST_EVENT_EOS:
587       /* This flush call makes sure that the last buffer is always pushed
588        * to the base payloader */
589       gst_rtp_mp4g_pay_flush (rtpmp4gpay);
590       break;
591     case GST_EVENT_FLUSH_STOP:
592       gst_rtp_mp4g_pay_reset (rtpmp4gpay);
593       break;
594     default:
595       break;
596   }
597
598   /* let parent handle event too */
599   return GST_RTP_BASE_PAYLOAD_CLASS (parent_class)->sink_event (payload, event);
600 }
601
602 static GstStateChangeReturn
603 gst_rtp_mp4g_pay_change_state (GstElement * element, GstStateChange transition)
604 {
605   GstStateChangeReturn ret;
606   GstRtpMP4GPay *rtpmp4gpay;
607
608   rtpmp4gpay = GST_RTP_MP4G_PAY (element);
609
610   switch (transition) {
611     case GST_STATE_CHANGE_READY_TO_PAUSED:
612       gst_rtp_mp4g_pay_cleanup (rtpmp4gpay);
613       break;
614     default:
615       break;
616   }
617
618   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
619
620   switch (transition) {
621     case GST_STATE_CHANGE_PAUSED_TO_READY:
622       gst_rtp_mp4g_pay_cleanup (rtpmp4gpay);
623       break;
624     default:
625       break;
626   }
627
628   return ret;
629 }
630
631 gboolean
632 gst_rtp_mp4g_pay_plugin_init (GstPlugin * plugin)
633 {
634   return gst_element_register (plugin, "rtpmp4gpay",
635       GST_RANK_SECONDARY, GST_TYPE_RTP_MP4G_PAY);
636 }