Small cleanups
[platform/upstream/gst-plugins-good.git] / ext / flac / gstflacdec.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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 #include <string.h>
21 #include <sys/soundcard.h>
22
23 /*#define DEBUG_ENABLED */
24 #include "gstflacdec.h"
25
26
27 extern GstPadTemplate *gst_flacdec_src_template, *gst_flacdec_sink_template;
28
29 /* elementfactory information */
30 GstElementDetails flacdec_details = {
31   "FLAC decoder",
32   "Codec/Audio/Decoder",
33   "Decodes FLAC lossless audio streams",
34   VERSION,
35   "Wim Taymans <wim.taymans@chello.be>",
36   "(C) 2001",
37 };
38
39 /* FlacDec signals and args */
40 enum {
41   /* FILL ME */
42   LAST_SIGNAL
43 };
44
45 enum {
46   ARG_0,
47 };
48
49 static void             gst_flacdec_class_init          (FlacDecClass *klass);
50 static void             gst_flacdec_init                (FlacDec *flacdec);
51
52 static void             gst_flacdec_loop                (GstElement *element);
53 static GstElementStateReturn
54                         gst_flacdec_change_state        (GstElement *element);
55 static const GstFormat* gst_flacdec_get_src_formats     (GstPad *pad);
56 static gboolean         gst_flacdec_convert_src         (GstPad *pad, GstFormat src_format, gint64 src_value,
57                                                          GstFormat *dest_format, gint64 *dest_value);
58 static const GstPadQueryType* 
59                         gst_flacdec_get_src_query_types (GstPad *pad);
60 static gboolean         gst_flacdec_src_query           (GstPad *pad, GstPadQueryType type,
61                                                          GstFormat *format, gint64 *value);
62 static const GstEventMask* 
63                         gst_flacdec_get_src_event_masks (GstPad *pad);
64 static gboolean         gst_flacdec_src_event           (GstPad *pad, GstEvent *event);
65
66 static FLAC__SeekableStreamDecoderReadStatus    
67                         gst_flacdec_read                (const FLAC__SeekableStreamDecoder *decoder, 
68                                                          FLAC__byte buffer[], unsigned *bytes, 
69                                                          void *client_data);
70 static FLAC__SeekableStreamDecoderSeekStatus    
71                         gst_flacdec_seek                (const FLAC__SeekableStreamDecoder *decoder, 
72                                                          FLAC__uint64 position, void *client_data);
73 static FLAC__SeekableStreamDecoderTellStatus    
74                         gst_flacdec_tell                (const FLAC__SeekableStreamDecoder *decoder, 
75                                                          FLAC__uint64 *position, void *client_data);
76 static FLAC__SeekableStreamDecoderLengthStatus  
77                         gst_flacdec_length              (const FLAC__SeekableStreamDecoder *decoder, 
78                                                          FLAC__uint64 *length, void *client_data);
79 static FLAC__bool       gst_flacdec_eof                 (const FLAC__SeekableStreamDecoder *decoder, 
80                                                          void *client_data);
81 static FLAC__StreamDecoderWriteStatus   
82                         gst_flacdec_write               (const FLAC__SeekableStreamDecoder *decoder, 
83                                                          const FLAC__Frame *frame, 
84                                                          const FLAC__int32 * const buffer[], 
85                                                          void *client_data);
86 static void             gst_flacdec_metadata_callback   (const FLAC__SeekableStreamDecoder *decoder, 
87                                                          const FLAC__StreamMetadata *metadata, 
88                                                          void *client_data);
89 static void             gst_flacdec_error_callback      (const FLAC__SeekableStreamDecoder *decoder, 
90                                                          FLAC__StreamDecoderErrorStatus status, 
91                                                          void *client_data);
92
93 static GstElementClass *parent_class = NULL;
94 /*static guint gst_flacdec_signals[LAST_SIGNAL] = { 0 }; */
95
96 GType
97 flacdec_get_type(void) {
98   static GType flacdec_type = 0;
99
100   if (!flacdec_type) {
101     static const GTypeInfo flacdec_info = {
102       sizeof(FlacDecClass),
103       NULL,
104       NULL,
105       (GClassInitFunc)gst_flacdec_class_init,
106       NULL,
107       NULL,
108       sizeof(FlacDec),
109       0,
110       (GInstanceInitFunc)gst_flacdec_init,
111     };
112     flacdec_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacDec", &flacdec_info, 0);
113   }
114   return flacdec_type;
115 }
116
117 static void
118 gst_flacdec_class_init (FlacDecClass *klass) 
119 {
120   GstElementClass *gstelement_class;
121
122   gstelement_class = (GstElementClass*)klass;
123
124   parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
125
126   gstelement_class->change_state = gst_flacdec_change_state;
127 }
128
129 static void 
130 gst_flacdec_init (FlacDec *flacdec) 
131 {
132   flacdec->sinkpad = gst_pad_new_from_template (gst_flacdec_sink_template, "sink");
133   gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->sinkpad);
134   gst_pad_set_convert_function (flacdec->sinkpad, NULL);
135
136   gst_element_set_loop_function (GST_ELEMENT (flacdec), gst_flacdec_loop);
137   flacdec->srcpad = gst_pad_new_from_template (gst_flacdec_src_template, "src");
138   gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->srcpad);
139   gst_pad_set_formats_function (flacdec->srcpad, gst_flacdec_get_src_formats);
140   gst_pad_set_convert_function (flacdec->srcpad, gst_flacdec_convert_src);
141   gst_pad_set_query_type_function (flacdec->srcpad, gst_flacdec_get_src_query_types);
142   gst_pad_set_query_function (flacdec->srcpad, gst_flacdec_src_query);
143   gst_pad_set_event_mask_function (flacdec->srcpad, gst_flacdec_get_src_event_masks);
144   gst_pad_set_event_function (flacdec->srcpad, gst_flacdec_src_event);
145
146   flacdec->decoder = FLAC__seekable_stream_decoder_new ();
147   flacdec->total_samples = 0;
148   flacdec->init = TRUE;
149   flacdec->eos = FALSE;
150   flacdec->seek_pending = FALSE;
151
152   FLAC__seekable_stream_decoder_set_read_callback (flacdec->decoder, gst_flacdec_read);
153   FLAC__seekable_stream_decoder_set_seek_callback (flacdec->decoder, gst_flacdec_seek);
154   FLAC__seekable_stream_decoder_set_tell_callback (flacdec->decoder, gst_flacdec_tell);
155   FLAC__seekable_stream_decoder_set_length_callback (flacdec->decoder, gst_flacdec_length);
156   FLAC__seekable_stream_decoder_set_eof_callback (flacdec->decoder, gst_flacdec_eof);
157   FLAC__seekable_stream_decoder_set_write_callback (flacdec->decoder, gst_flacdec_write);
158   FLAC__seekable_stream_decoder_set_metadata_callback (flacdec->decoder, gst_flacdec_metadata_callback);
159   FLAC__seekable_stream_decoder_set_error_callback (flacdec->decoder, gst_flacdec_error_callback);
160   FLAC__seekable_stream_decoder_set_client_data (flacdec->decoder, flacdec);
161 }
162
163 static void 
164 gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder *decoder,
165                                const FLAC__StreamMetadata *metadata, void *client_data)
166 {
167   FlacDec *flacdec;
168
169   flacdec = GST_FLACDEC (client_data);
170
171   flacdec->stream_samples = metadata->data.stream_info.total_samples;
172 }
173
174 static void 
175 gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder *decoder, 
176                             FLAC__StreamDecoderErrorStatus status, void *client_data)
177 {
178   FlacDec *flacdec;
179   gchar *error;
180
181   flacdec = GST_FLACDEC (client_data);
182
183   switch (status) {
184     case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
185       error = "lost sync";
186       break;
187     case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
188       error = "bad header";
189       break;
190     case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
191       error = "CRC mismatch";
192       break;
193     default:
194       error = "unkown error";
195       break;
196   }
197
198   GST_DEBUG (0, error);
199                                   
200   gst_element_error (GST_ELEMENT (flacdec), error);
201 }
202
203 static FLAC__SeekableStreamDecoderSeekStatus    
204 gst_flacdec_seek (const FLAC__SeekableStreamDecoder *decoder, 
205                   FLAC__uint64 position, void *client_data)
206 {
207   FlacDec *flacdec;
208
209   flacdec = GST_FLACDEC (client_data);
210
211   GST_DEBUG (0, "seek %lld\n", position);
212   if (!gst_bytestream_seek (flacdec->bs, position, GST_SEEK_METHOD_SET)) {
213     return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
214   }
215   return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
216 }
217
218 static FLAC__SeekableStreamDecoderTellStatus    
219 gst_flacdec_tell (const FLAC__SeekableStreamDecoder *decoder, 
220                   FLAC__uint64 *position, void *client_data)
221 {
222   FlacDec *flacdec;
223
224   flacdec = GST_FLACDEC (client_data);
225
226   *position = gst_bytestream_tell (flacdec->bs);
227   if (*position == -1)
228     return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
229
230   GST_DEBUG (0, "tell %lld\n", *position);
231
232   return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
233 }
234
235 static FLAC__SeekableStreamDecoderLengthStatus  
236 gst_flacdec_length (const FLAC__SeekableStreamDecoder *decoder, 
237                     FLAC__uint64 *length, void *client_data)
238 {
239   FlacDec *flacdec;
240
241   flacdec = GST_FLACDEC (client_data);
242
243   *length = gst_bytestream_length (flacdec->bs);
244   if (*length == -1)
245     return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
246
247   GST_DEBUG (0, "length %lld\n", *length);
248
249   return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
250 }
251
252 static FLAC__bool
253 gst_flacdec_eof (const FLAC__SeekableStreamDecoder *decoder, 
254                  void *client_data)
255 {
256   FlacDec *flacdec;
257
258   flacdec = GST_FLACDEC (client_data);
259   GST_DEBUG (0, "eof %d\n", flacdec->eos);
260
261   return flacdec->eos;
262 }
263
264 static FLAC__SeekableStreamDecoderReadStatus
265 gst_flacdec_read (const FLAC__SeekableStreamDecoder *decoder, 
266                   FLAC__byte buffer[], unsigned *bytes, 
267                   void *client_data)
268 {
269   FlacDec *flacdec;
270   gint insize = 0;
271   guint8 *indata;
272
273   flacdec = GST_FLACDEC (client_data);
274
275   //g_print ("read %u\n", *bytes);
276   
277   while (insize == 0) {
278     insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, *bytes);
279     if (insize < *bytes) {
280       GstEvent *event;
281       guint32 avail;
282                             
283       gst_bytestream_get_status (flacdec->bs, &avail, &event);
284
285       switch (GST_EVENT_TYPE (event)) {
286         case GST_EVENT_EOS:
287           GST_DEBUG (0, "eos");
288           flacdec->eos = TRUE; 
289           gst_event_unref (event);
290           if (avail == 0) {
291             return 0;
292           }
293           break;
294         case GST_EVENT_DISCONTINUOUS:
295           GST_DEBUG (0, "discont");
296
297           /* we are not yet sending the discont, we'll do that in the next write operation */
298           flacdec->need_discont = TRUE;
299           gst_event_unref (event);
300           break;
301         default:
302           gst_pad_event_default (flacdec->sinkpad, event);
303           break;
304       }
305       if (avail > 0)
306         insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, avail);
307       else
308         insize = 0;
309     }
310   }
311
312   memcpy (buffer, indata, insize);
313   *bytes = insize;
314   gst_bytestream_flush_fast (flacdec->bs, insize);
315
316   return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
317 }
318
319 static FLAC__StreamDecoderWriteStatus
320 gst_flacdec_write (const FLAC__SeekableStreamDecoder *decoder, 
321                    const FLAC__Frame *frame, 
322                    const FLAC__int32 * const buffer[], 
323                    void *client_data)
324 {
325   FlacDec *flacdec;
326   GstBuffer *outbuf;
327   guint depth = frame->header.bits_per_sample;
328   guint channels = frame->header.channels;
329   guint samples = frame->header.blocksize;
330   guint j, i;
331
332   flacdec = GST_FLACDEC (client_data);
333
334   if (flacdec->need_discont) {
335     gint64 time = 0, bytes = 0;
336     GstFormat format;
337     GstEvent *discont;
338
339     flacdec->need_discont = FALSE;
340
341     if (flacdec->seek_pending) {
342       flacdec->total_samples = flacdec->seek_value;
343     }
344
345     GST_DEBUG (0, "send discont");
346
347     format = GST_FORMAT_TIME;
348     gst_pad_convert (flacdec->srcpad, GST_FORMAT_UNITS, flacdec->total_samples,
349                   &format, &time);
350     format = GST_FORMAT_BYTES;
351     gst_pad_convert (flacdec->srcpad, GST_FORMAT_UNITS, flacdec->total_samples,
352                   &format, &bytes);
353     discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time,
354                                          GST_FORMAT_BYTES, bytes,
355                                          GST_FORMAT_UNITS, flacdec->total_samples, 
356                                          NULL);
357           
358     gst_pad_push (flacdec->srcpad, GST_BUFFER (discont));
359   }
360   
361   if (!GST_PAD_CAPS (flacdec->srcpad)) {
362     gst_pad_try_set_caps (flacdec->srcpad,
363                     GST_CAPS_NEW (
364                       "flac_caps",
365                       "audio/raw",
366                         "format",       GST_PROPS_STRING ("int"),
367                          "law",         GST_PROPS_INT (0),
368                          "endianness",  GST_PROPS_INT (G_BYTE_ORDER),
369                          "signed",      GST_PROPS_BOOLEAN (TRUE),
370                          "width",       GST_PROPS_INT (depth),
371                          "depth",       GST_PROPS_INT (depth),
372                          "rate",        GST_PROPS_INT (frame->header.sample_rate),
373                          "channels",    GST_PROPS_INT (channels)
374                     ));
375
376     flacdec->depth = depth;
377     flacdec->channels = channels;
378     flacdec->frequency = frame->header.sample_rate;
379   }
380
381   outbuf = gst_buffer_new ();
382   GST_BUFFER_SIZE (outbuf) = samples * channels * ((depth+7)>>3);
383   GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
384   GST_BUFFER_TIMESTAMP (outbuf) = flacdec->total_samples * GST_SECOND / frame->header.sample_rate;
385
386   if (depth == 8) {
387     guint8 *outbuffer = (guint8 *)GST_BUFFER_DATA (outbuf);
388
389     for (i=0; i<samples; i++) {
390       for (j=0; j < channels; j++) {
391         *outbuffer++ = (guint8) buffer[j][i];
392       }
393     }
394   }
395   else if (depth == 16) {
396     guint16 *outbuffer = (guint16 *)GST_BUFFER_DATA (outbuf);
397
398     for (i=0; i<samples; i++) {
399       for (j=0; j < channels; j++) {
400         *outbuffer++ = (guint16) buffer[j][i];
401       }
402     }
403   }
404   else {
405     g_warning ("flacdec: invalid depth %d found\n", depth);
406     return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
407   }
408
409   flacdec->total_samples += samples;
410
411   gst_pad_push (flacdec->srcpad, outbuf);
412
413   return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
414 }
415
416 static void 
417 gst_flacdec_loop (GstElement *element) 
418 {
419   FlacDec *flacdec;
420   gboolean res;
421
422   flacdec = GST_FLACDEC (element);
423
424   if (flacdec->init) {
425     FLAC__seekable_stream_decoder_init (flacdec->decoder);
426     FLAC__seekable_stream_decoder_process_metadata (flacdec->decoder);
427     flacdec->init = FALSE;
428   }
429
430   if (flacdec->seek_pending) {
431     GST_DEBUG (GST_CAT_EVENT, "perform seek to sample %lld\n", 
432                               flacdec->seek_value);
433
434     if (FLAC__seekable_stream_decoder_seek_absolute (flacdec->decoder, 
435                                                      flacdec->seek_value)) 
436     {
437       flacdec->total_samples = flacdec->seek_value;
438       GST_DEBUG (GST_CAT_EVENT, "seek done\n");
439     }
440     else {
441       GST_DEBUG (GST_CAT_EVENT, "seek failed\n");
442     }
443     flacdec->seek_pending = FALSE;
444   }
445
446   res = FLAC__seekable_stream_decoder_process_one_frame (flacdec->decoder);
447   if (FLAC__seekable_stream_decoder_get_state (flacdec->decoder) == 
448                   FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM) 
449   {
450     GstEvent *event;
451
452     FLAC__seekable_stream_decoder_finish(flacdec->decoder);
453     flacdec->init = TRUE;
454
455     event = gst_event_new(GST_EVENT_EOS);
456     gst_pad_push (flacdec->srcpad, GST_BUFFER (event));
457     gst_element_set_eos (element);
458   }
459 }
460
461 GST_FORMATS_FUNCTION (gst_flacdec_get_src_formats,
462   GST_FORMAT_UNITS,
463   GST_FORMAT_BYTES,
464   GST_FORMAT_TIME
465 )
466
467 static gboolean
468 gst_flacdec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
469                          GstFormat *dest_format, gint64 *dest_value)
470 {
471   gboolean res = TRUE;
472   FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad));
473   guint scale = 1;
474   gint bytes_per_sample;
475
476   bytes_per_sample = flacdec->channels * ((flacdec->depth+7)>>3);
477
478   switch (src_format) {
479     case GST_FORMAT_BYTES:
480       switch (*dest_format) {
481         case GST_FORMAT_UNITS:
482           if (bytes_per_sample == 0)
483             return FALSE;
484           *dest_value = src_value / bytes_per_sample;
485           break;
486         case GST_FORMAT_DEFAULT:
487           *dest_format = GST_FORMAT_TIME;
488         case GST_FORMAT_TIME:
489         {
490           gint byterate = bytes_per_sample * flacdec->frequency;
491
492           if (byterate == 0)
493             return FALSE;
494           *dest_value = src_value * GST_SECOND / byterate;
495           break;
496         }
497         default:
498           res = FALSE;
499       }
500       break;
501     case GST_FORMAT_UNITS:
502       switch (*dest_format) {
503         case GST_FORMAT_BYTES:
504           *dest_value = src_value * bytes_per_sample;
505           break;
506         case GST_FORMAT_DEFAULT:
507           *dest_format = GST_FORMAT_TIME;
508         case GST_FORMAT_TIME:
509           if (flacdec->frequency == 0)
510             return FALSE;
511           *dest_value = src_value * GST_SECOND / flacdec->frequency;
512           break;
513         default:
514           res = FALSE;
515       }
516       break;
517     case GST_FORMAT_TIME:
518       switch (*dest_format) {
519         case GST_FORMAT_DEFAULT:
520           *dest_format = GST_FORMAT_BYTES;
521         case GST_FORMAT_BYTES:
522           scale = bytes_per_sample;
523         case GST_FORMAT_UNITS:
524           *dest_value = src_value * scale * flacdec->frequency / GST_SECOND;
525           break;
526         default:
527           res = FALSE;
528       }
529       break;
530     default:
531       res = FALSE;
532   }
533   return res;
534 }
535
536 GST_PAD_QUERY_TYPE_FUNCTION (gst_flacdec_get_src_query_types,
537   GST_PAD_QUERY_TOTAL,
538   GST_PAD_QUERY_POSITION
539 )
540
541 static gboolean
542 gst_flacdec_src_query (GstPad *pad, GstPadQueryType type,
543                        GstFormat *format, gint64 *value)
544 {
545   gboolean res = TRUE;
546   FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad));
547
548   switch (type) {
549     case GST_PAD_QUERY_TOTAL:
550     {
551       guint64 samples;
552
553       if (flacdec->stream_samples == 0)
554         samples = flacdec->total_samples;
555       else
556         samples = flacdec->stream_samples;
557
558       gst_pad_convert (flacdec->srcpad, 
559                        GST_FORMAT_UNITS, 
560                        samples, 
561                        format, value);
562       break;
563     }
564     case GST_PAD_QUERY_POSITION:
565       gst_pad_convert (flacdec->srcpad, 
566                        GST_FORMAT_UNITS, 
567                        flacdec->total_samples, 
568                        format, value);
569       break;
570     default:
571       res = FALSE;
572       break;
573   }
574
575   return res;
576 }
577           
578 GST_EVENT_MASK_FUNCTION (gst_flacdec_get_src_event_masks,
579     { GST_EVENT_SEEK, GST_SEEK_FLAG_ACCURATE }
580 );
581
582 static gboolean
583 gst_flacdec_src_event (GstPad *pad, GstEvent *event)
584
585   gboolean res = TRUE;
586   FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad));
587   GstFormat format;
588
589   switch (GST_EVENT_TYPE (event)) {
590     case GST_EVENT_SEEK:
591       format = GST_FORMAT_UNITS;
592
593       if (gst_pad_convert (flacdec->srcpad, 
594                            GST_EVENT_SEEK_FORMAT (event), 
595                            GST_EVENT_SEEK_OFFSET (event), 
596                            &format, &flacdec->seek_value))
597         flacdec->seek_pending = TRUE;
598       else
599         res = FALSE;
600       break;
601     default:
602       res = FALSE;
603       break;
604   }
605   gst_event_unref (event);
606   return res;
607 }
608
609 static GstElementStateReturn
610 gst_flacdec_change_state (GstElement *element)
611 {
612   FlacDec *flacdec = GST_FLACDEC (element);
613
614   switch (GST_STATE_TRANSITION (element)) {
615     case GST_STATE_NULL_TO_READY:
616     case GST_STATE_READY_TO_PAUSED:
617       flacdec->bs = gst_bytestream_new (flacdec->sinkpad);
618       flacdec->seek_pending = FALSE;
619       flacdec->total_samples = 0;
620       flacdec->init = TRUE;
621       flacdec->eos = FALSE;
622       break;
623     case GST_STATE_PAUSED_TO_PLAYING:
624       flacdec->eos = FALSE;
625     case GST_STATE_PLAYING_TO_PAUSED:
626       break;
627     case GST_STATE_PAUSED_TO_READY:
628       gst_bytestream_destroy (flacdec->bs);
629       break;
630     case GST_STATE_READY_TO_NULL:
631     default:
632       break;
633   }
634
635   if (GST_ELEMENT_CLASS (parent_class)->change_state)
636     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
637
638   return GST_STATE_SUCCESS;
639 }
640