configure.ac: Require gst-plugins-base CVS for audioconvert with non-native float...
[platform/upstream/gst-plugins-good.git] / gst / auparse / gstauparse.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * SECTION:element-auparse
23  * @short_description: .au file parser
24  * 
25  * <refsect2>
26  * <para>
27  * Parses .au files.
28  * </para>
29  * </refsect2>
30  */
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "gstauparse.h"
40 #include <gst/audio/audio.h>
41
42 GST_DEBUG_CATEGORY_STATIC (auparse_debug);
43 #define GST_CAT_DEFAULT (auparse_debug)
44
45 static const GstElementDetails gst_au_parse_details =
46 GST_ELEMENT_DETAILS ("AU audio demuxer",
47     "Codec/Demuxer/Audio",
48     "Parse an .au file into raw audio",
49     "Erik Walthinsen <omega@cse.ogi.edu>");
50
51 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
52     GST_PAD_SINK,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS ("audio/x-au")
55     );
56
57 #define GST_AU_PARSE_ALAW_PAD_TEMPLATE_CAPS \
58     "audio/x-alaw, "                        \
59     "rate = (int) [ 8000, 192000 ], "       \
60     "channels = (int) [ 1, 2 ]"
61
62 #define GST_AU_PARSE_MULAW_PAD_TEMPLATE_CAPS \
63     "audio/x-mulaw, "                        \
64     "rate = (int) [ 8000, 192000 ], "        \
65     "channels = (int) [ 1, 2 ]"
66
67 /* Nothing to decode those ADPCM streams for now */
68 #define GST_AU_PARSE_ADPCM_PAD_TEMPLATE_CAPS \
69     "audio/x-adpcm, "                        \
70     "layout = (string) { g721, g722, g723_3, g723_5 }"
71
72 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
73     GST_PAD_SRC,
74     GST_PAD_SOMETIMES,
75     GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
76         GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS ";"
77         GST_AU_PARSE_ALAW_PAD_TEMPLATE_CAPS ";"
78         GST_AU_PARSE_MULAW_PAD_TEMPLATE_CAPS ";"
79         GST_AU_PARSE_ADPCM_PAD_TEMPLATE_CAPS));
80
81
82 static void gst_au_parse_dispose (GObject * object);
83 static GstFlowReturn gst_au_parse_chain (GstPad * pad, GstBuffer * buf);
84 static GstStateChangeReturn gst_au_parse_change_state (GstElement * element,
85     GstStateChange transition);
86 static void gst_au_parse_reset (GstAuParse * auparse);
87 static gboolean gst_au_parse_remove_srcpad (GstAuParse * auparse);
88 static gboolean gst_au_parse_add_srcpad (GstAuParse * auparse, GstCaps * caps);
89 static gboolean gst_au_parse_src_query (GstPad * pad, GstQuery * query);
90 static gboolean gst_au_parse_src_event (GstPad * pad, GstEvent * event);
91 static gboolean gst_au_parse_sink_event (GstPad * pad, GstEvent * event);
92
93 GST_BOILERPLATE (GstAuParse, gst_au_parse, GstElement, GST_TYPE_ELEMENT);
94
95 static void
96 gst_au_parse_base_init (gpointer g_class)
97 {
98   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
99
100   gst_element_class_add_pad_template (element_class,
101       gst_static_pad_template_get (&sink_template));
102   gst_element_class_add_pad_template (element_class,
103       gst_static_pad_template_get (&src_template));
104   gst_element_class_set_details (element_class, &gst_au_parse_details);
105
106   GST_DEBUG_CATEGORY_INIT (auparse_debug, "auparse", 0, ".au parser");
107 }
108
109 static void
110 gst_au_parse_class_init (GstAuParseClass * klass)
111 {
112   GObjectClass *gobject_class;
113   GstElementClass *gstelement_class;
114
115   gobject_class = (GObjectClass *) klass;
116   gstelement_class = (GstElementClass *) klass;
117
118   gobject_class->dispose = gst_au_parse_dispose;
119
120   gstelement_class->change_state =
121       GST_DEBUG_FUNCPTR (gst_au_parse_change_state);
122 }
123
124 static void
125 gst_au_parse_init (GstAuParse * auparse, GstAuParseClass * klass)
126 {
127   auparse->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
128   gst_pad_set_chain_function (auparse->sinkpad,
129       GST_DEBUG_FUNCPTR (gst_au_parse_chain));
130   gst_pad_set_event_function (auparse->sinkpad,
131       GST_DEBUG_FUNCPTR (gst_au_parse_sink_event));
132   gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
133
134   auparse->srcpad = NULL;
135   auparse->adapter = gst_adapter_new ();
136   gst_au_parse_reset (auparse);
137 }
138
139 static void
140 gst_au_parse_dispose (GObject * object)
141 {
142   GstAuParse *au = GST_AU_PARSE (object);
143
144   if (au->adapter != NULL) {
145     g_object_unref (au->adapter);
146     au->adapter = NULL;
147   }
148   G_OBJECT_CLASS (parent_class)->dispose (object);
149 }
150
151 static void
152 gst_au_parse_reset (GstAuParse * auparse)
153 {
154   gst_au_parse_remove_srcpad (auparse);
155
156   auparse->offset = 0;
157   auparse->buffer_offset = 0;
158   auparse->encoding = 0;
159   auparse->samplerate = 0;
160   auparse->channels = 0;
161
162   gst_adapter_clear (auparse->adapter);
163
164   /* gst_segment_init (&auparse->segment, GST_FORMAT_TIME); */
165 }
166
167 static gboolean
168 gst_au_parse_add_srcpad (GstAuParse * auparse, GstCaps * new_caps)
169 {
170   GstPad *srcpad = NULL;
171
172   if (auparse->src_caps && gst_caps_is_equal (new_caps, auparse->src_caps)) {
173     GST_LOG_OBJECT (auparse, "same caps, nothing to do");
174     return TRUE;
175   }
176
177   gst_caps_replace (&auparse->src_caps, new_caps);
178   if (auparse->srcpad != NULL) {
179     GST_DEBUG_OBJECT (auparse, "Changing src pad caps to %" GST_PTR_FORMAT,
180         auparse->src_caps);
181     gst_pad_set_caps (auparse->srcpad, auparse->src_caps);
182   }
183
184   if (auparse->srcpad == NULL) {
185     srcpad = auparse->srcpad =
186         gst_pad_new_from_static_template (&src_template, "src");
187     g_return_val_if_fail (auparse->srcpad != NULL, FALSE);
188
189 #if 0
190     gst_pad_set_query_type_function (auparse->srcpad,
191         GST_DEBUG_FUNCPTR (gst_au_parse_src_get_query_types));
192 #endif
193     gst_pad_set_query_function (auparse->srcpad,
194         GST_DEBUG_FUNCPTR (gst_au_parse_src_query));
195     gst_pad_set_event_function (auparse->srcpad,
196         GST_DEBUG_FUNCPTR (gst_au_parse_src_event));
197
198     gst_pad_use_fixed_caps (auparse->srcpad);
199     gst_pad_set_active (auparse->srcpad, TRUE);
200
201     if (auparse->src_caps)
202       gst_pad_set_caps (auparse->srcpad, auparse->src_caps);
203
204     GST_DEBUG_OBJECT (auparse, "Adding src pad with caps %" GST_PTR_FORMAT,
205         auparse->src_caps);
206
207     gst_object_ref (auparse->srcpad);
208     if (!gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad))
209       return FALSE;
210     gst_element_no_more_pads (GST_ELEMENT (auparse));
211   }
212
213   return TRUE;
214 }
215
216 static gboolean
217 gst_au_parse_remove_srcpad (GstAuParse * auparse)
218 {
219   gboolean res = TRUE;
220
221   if (auparse->srcpad != NULL) {
222     GST_DEBUG_OBJECT (auparse, "Removing src pad");
223     res = gst_element_remove_pad (GST_ELEMENT (auparse), auparse->srcpad);
224     g_return_val_if_fail (res != FALSE, FALSE);
225     gst_object_unref (auparse->srcpad);
226     auparse->srcpad = NULL;
227   }
228
229   return res;
230 }
231
232 static GstFlowReturn
233 gst_au_parse_parse_header (GstAuParse * auparse)
234 {
235   GstCaps *tempcaps;
236   guint32 size;
237   guint8 *head;
238   gchar layout[7] = { 0, };
239   gint law = 0, depth = 0, ieee = 0;
240
241   head = (guint8 *) gst_adapter_peek (auparse->adapter, 24);
242   g_assert (head != NULL);
243
244   GST_DEBUG_OBJECT (auparse, "[%c%c%c%c]", head[0], head[1], head[2], head[3]);
245
246   switch (GST_READ_UINT32_BE (head)) {
247       /* normal format is big endian (au is a Sparc format) */
248     case 0x2e736e64:{          /* ".snd" */
249       auparse->endianness = G_BIG_ENDIAN;
250       break;
251     }
252       /* and of course, someone had to invent a little endian
253        * version.  Used by DEC systems. */
254     case 0x646e732e:           /* dns.                          */
255     case 0x0064732e:{          /* other source say it is "dns." */
256       auparse->endianness = G_LITTLE_ENDIAN;
257       break;
258     }
259     default:{
260       goto unknown_header;
261     }
262   }
263
264   auparse->offset = GST_READ_UINT32_BE (head + 4);
265   /* Do not trust size, could be set to -1 : unknown */
266   size = GST_READ_UINT32_BE (head + 8);
267   auparse->encoding = GST_READ_UINT32_BE (head + 12);
268   auparse->samplerate = GST_READ_UINT32_BE (head + 16);
269   auparse->channels = GST_READ_UINT32_BE (head + 20);
270
271   GST_DEBUG_OBJECT (auparse, "offset %" G_GINT64_FORMAT ", size %u, "
272       "encoding %u, frequency %u, channels %u", auparse->offset, size,
273       auparse->encoding, auparse->samplerate, auparse->channels);
274
275   /* Docs:
276    * http://www.opengroup.org/public/pubs/external/auformat.html
277    * http://astronomy.swin.edu.au/~pbourke/dataformats/au/
278    * Solaris headers : /usr/include/audio/au.h
279    * libsndfile : src/au.c
280    *
281    * Samples :
282    * http://www.tsp.ece.mcgill.ca/MMSP/Documents/AudioFormats/AU/Samples.html
283    */
284
285   switch (auparse->encoding) {
286     case 1:                    /* 8-bit ISDN mu-law G.711 */
287       law = 1;
288       depth = 8;
289       break;
290     case 27:                   /* 8-bit ISDN  A-law G.711 */
291       law = 2;
292       depth = 8;
293       break;
294
295     case 2:                    /*  8-bit linear PCM */
296       depth = 8;
297       break;
298     case 3:                    /* 16-bit linear PCM */
299       depth = 16;
300       break;
301     case 4:                    /* 24-bit linear PCM */
302       depth = 24;
303       break;
304     case 5:                    /* 32-bit linear PCM */
305       depth = 32;
306       break;
307
308     case 6:                    /* 32-bit IEEE floating point */
309       ieee = 1;
310       depth = 32;
311       break;
312     case 7:                    /* 64-bit IEEE floating point */
313       ieee = 1;
314       depth = 64;
315       break;
316
317     case 23:                   /* 4-bit CCITT G.721   ADPCM 32kbps -> modplug/libsndfile (compressed 8-bit mu-law) */
318       strcpy (layout, "g721");
319       break;
320     case 24:                   /* 8-bit CCITT G.722   ADPCM        -> rtp */
321       strcpy (layout, "g722");
322       break;
323     case 25:                   /* 3-bit CCITT G.723.3 ADPCM 24kbps -> rtp/xine/modplug/libsndfile */
324       strcpy (layout, "g723_3");
325       break;
326     case 26:                   /* 5-bit CCITT G.723.5 ADPCM 40kbps -> rtp/xine/modplug/libsndfile */
327       strcpy (layout, "g723_5");
328       break;
329
330     case 8:                    /* Fragmented sample data */
331     case 9:                    /* AU_ENCODING_NESTED */
332
333     case 10:                   /* DSP program */
334     case 11:                   /* DSP  8-bit fixed point */
335     case 12:                   /* DSP 16-bit fixed point */
336     case 13:                   /* DSP 24-bit fixed point */
337     case 14:                   /* DSP 32-bit fixed point */
338
339     case 16:                   /* AU_ENCODING_DISPLAY : non-audio display data */
340     case 17:                   /* AU_ENCODING_MULAW_SQUELCH */
341
342     case 18:                   /* 16-bit linear with emphasis */
343     case 19:                   /* 16-bit linear compressed (NeXT) */
344     case 20:                   /* 16-bit linear with emphasis and compression */
345
346     case 21:                   /* Music kit DSP commands */
347     case 22:                   /* Music kit DSP commands samples */
348
349     default:
350       goto unknown_format;
351   }
352
353   if (law) {
354     tempcaps =
355         gst_caps_new_simple ((law == 1) ? "audio/x-mulaw" : "audio/x-alaw",
356         "rate", G_TYPE_INT, auparse->samplerate,
357         "channels", G_TYPE_INT, auparse->channels, NULL);
358     auparse->sample_size = auparse->channels;
359   } else if (ieee) {
360     tempcaps = gst_caps_new_simple ("audio/x-raw-float",
361         "rate", G_TYPE_INT, auparse->samplerate,
362         "channels", G_TYPE_INT, auparse->channels,
363         "endianness", G_TYPE_INT, auparse->endianness,
364         "width", G_TYPE_INT, depth, NULL);
365     auparse->sample_size = auparse->channels * depth / 8;
366   } else if (layout[0]) {
367     tempcaps = gst_caps_new_simple ("audio/x-adpcm",
368         "layout", G_TYPE_STRING, layout, NULL);
369     auparse->sample_size = 0;
370   } else {
371     tempcaps = gst_caps_new_simple ("audio/x-raw-int",
372         "rate", G_TYPE_INT, auparse->samplerate,
373         "channels", G_TYPE_INT, auparse->channels,
374         "endianness", G_TYPE_INT, auparse->endianness,
375         "depth", G_TYPE_INT, depth, "width", G_TYPE_INT, depth,
376         /* FIXME: signed TRUE even for 8-bit PCM? */
377         "signed", G_TYPE_BOOLEAN, TRUE, NULL);
378     auparse->sample_size = auparse->channels * depth / 8;
379   }
380
381   GST_DEBUG_OBJECT (auparse, "sample_size=%d", auparse->sample_size);
382
383   if (!gst_au_parse_add_srcpad (auparse, tempcaps))
384     goto add_pad_failed;
385
386   GST_DEBUG_OBJECT (auparse, "offset=%" G_GINT64_FORMAT, auparse->offset);
387   gst_adapter_flush (auparse->adapter, auparse->offset);
388
389   gst_caps_unref (tempcaps);
390   return GST_FLOW_OK;
391
392   /* ERRORS */
393 unknown_header:
394   {
395     GST_ELEMENT_ERROR (auparse, STREAM, WRONG_TYPE, (NULL), (NULL));
396     return GST_FLOW_ERROR;
397   }
398 unknown_format:
399   {
400     GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL), (NULL));
401     return GST_FLOW_ERROR;
402   }
403 add_pad_failed:
404   {
405     GST_ELEMENT_ERROR (auparse, STREAM, FAILED, (NULL),
406         ("Failed to add srcpad"));
407     gst_caps_unref (tempcaps);
408     return GST_FLOW_ERROR;
409   }
410 }
411
412 #define AU_HEADER_SIZE 24
413
414 static GstFlowReturn
415 gst_au_parse_chain (GstPad * pad, GstBuffer * buf)
416 {
417   GstFlowReturn ret = GST_FLOW_OK;
418   GstAuParse *auparse;
419   gint avail, sendnow = 0;
420
421   auparse = GST_AU_PARSE (gst_pad_get_parent (pad));
422
423   GST_LOG_OBJECT (auparse, "got buffer of size %u", GST_BUFFER_SIZE (buf));
424
425   gst_adapter_push (auparse->adapter, buf);
426   buf = NULL;
427
428   /* if we haven't seen any data yet... */
429   if (auparse->srcpad == NULL) {
430     if (gst_adapter_available (auparse->adapter) < AU_HEADER_SIZE) {
431       GST_DEBUG_OBJECT (auparse, "need more data to parse header");
432       ret = GST_FLOW_OK;
433       goto out;
434     }
435
436     ret = gst_au_parse_parse_header (auparse);
437     if (ret != GST_FLOW_OK)
438       goto out;
439
440     gst_pad_push_event (auparse->srcpad,
441         gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_DEFAULT,
442             0, GST_CLOCK_TIME_NONE, 0));
443   }
444
445   avail = gst_adapter_available (auparse->adapter);
446
447   if (auparse->sample_size > 0) {
448     /* Ensure we push a buffer that's a multiple of the frame size downstream */
449     sendnow = avail - (avail % auparse->sample_size);
450   } else {
451     /* It's something non-trivial (such as ADPCM), we don't understand it, so
452      * just push downstream and assume it will know what to do with it */
453     sendnow = avail;
454   }
455
456   if (sendnow > 0) {
457     GstBuffer *outbuf;
458     const guint8 *data;
459
460     ret = gst_pad_alloc_buffer_and_set_caps (auparse->srcpad,
461         auparse->buffer_offset, sendnow, GST_PAD_CAPS (auparse->srcpad),
462         &outbuf);
463
464     if (ret != GST_FLOW_OK) {
465       GST_DEBUG_OBJECT (auparse, "pad alloc flow: %s", gst_flow_get_name (ret));
466       goto out;
467     }
468
469     data = gst_adapter_peek (auparse->adapter, sendnow);
470     memcpy (GST_BUFFER_DATA (outbuf), data, sendnow);
471     gst_adapter_flush (auparse->adapter, sendnow);
472
473     auparse->buffer_offset += sendnow;
474
475     ret = gst_pad_push (auparse->srcpad, outbuf);
476   }
477
478 out:
479
480   gst_object_unref (auparse);
481   return ret;
482 }
483
484 static gboolean
485 gst_au_parse_src_convert (GstAuParse * auparse, GstFormat src_format,
486     gint64 srcval, GstFormat dest_format, gint64 * destval)
487 {
488   gboolean ret = TRUE;
489   gint64 offset;
490   guint samplesize, rate;
491
492   if (dest_format == src_format) {
493     *destval = srcval;
494     return TRUE;
495   }
496
497   GST_OBJECT_LOCK (auparse);
498   samplesize = auparse->sample_size;
499   offset = auparse->offset;
500   rate = auparse->samplerate;
501   GST_OBJECT_UNLOCK (auparse);
502
503   if (samplesize == 0 || rate == 0) {
504     GST_LOG_OBJECT (auparse, "cannot convert, sample_size or rate unknown");
505     return FALSE;
506   }
507
508   switch (src_format) {
509     case GST_FORMAT_BYTES:
510       srcval /= samplesize;
511       /* fallthrough */
512     case GST_FORMAT_DEFAULT:{
513       switch (dest_format) {
514         case GST_FORMAT_BYTES:
515           *destval = srcval * samplesize;
516           break;
517         case GST_FORMAT_TIME:
518           *destval = gst_util_uint64_scale_int (srcval, GST_SECOND, rate);
519           break;
520         default:
521           ret = FALSE;
522           break;
523       }
524       break;
525     }
526     case GST_FORMAT_TIME:{
527       switch (dest_format) {
528         case GST_FORMAT_BYTES:
529           *destval =
530               gst_util_uint64_scale_int (srcval, rate * samplesize, GST_SECOND);
531           break;
532         case GST_FORMAT_DEFAULT:
533           *destval = gst_util_uint64_scale_int (srcval, rate, GST_SECOND);
534           break;
535         default:
536           ret = FALSE;
537           break;
538       }
539       break;
540     }
541     default:{
542       ret = FALSE;
543       break;
544     }
545   }
546
547   if (!ret) {
548     GST_DEBUG_OBJECT (auparse, "could not convert from %s to %s format",
549         gst_format_get_name (src_format), gst_format_get_name (dest_format));
550   }
551
552   return ret;
553 }
554
555 static gboolean
556 gst_au_parse_src_query (GstPad * pad, GstQuery * query)
557 {
558   GstAuParse *auparse;
559   gboolean ret = FALSE;
560
561   auparse = GST_AU_PARSE (gst_pad_get_parent (pad));
562
563   switch (GST_QUERY_TYPE (query)) {
564     case GST_QUERY_DURATION:{
565       GstFormat bformat = GST_FORMAT_BYTES;
566       GstFormat format;
567       gint64 len, val;
568
569       gst_query_parse_duration (query, &format, NULL);
570       if (!gst_pad_query_peer_duration (auparse->sinkpad, &bformat, &len)) {
571         GST_DEBUG_OBJECT (auparse, "failed to query upstream length");
572         break;
573       }
574       GST_OBJECT_LOCK (auparse);
575       len -= auparse->offset;
576       GST_OBJECT_UNLOCK (auparse);
577
578       ret = gst_au_parse_src_convert (auparse, GST_FORMAT_BYTES, len,
579           format, &val);
580
581       if (ret) {
582         gst_query_set_duration (query, format, val);
583       }
584       break;
585     }
586     case GST_QUERY_POSITION:{
587       GstFormat bformat = GST_FORMAT_BYTES;
588       GstFormat format;
589       gint64 pos, val;
590
591       gst_query_parse_position (query, &format, NULL);
592       if (!gst_pad_query_peer_position (auparse->sinkpad, &bformat, &pos)) {
593         GST_DEBUG_OBJECT (auparse, "failed to query upstream position");
594         break;
595       }
596       GST_OBJECT_LOCK (auparse);
597       pos -= auparse->offset;
598       GST_OBJECT_UNLOCK (auparse);
599
600       ret = gst_au_parse_src_convert (auparse, GST_FORMAT_BYTES, pos,
601           format, &val);
602
603       if (ret) {
604         gst_query_set_position (query, format, val);
605       }
606       break;
607     }
608     default:
609       ret = gst_pad_query_default (pad, query);
610       break;
611   }
612
613   gst_object_unref (auparse);
614   return ret;
615 }
616
617 static gboolean
618 gst_au_parse_handle_seek (GstAuParse * auparse, GstEvent * event)
619 {
620   GstSeekType start_type, stop_type;
621   GstSeekFlags flags;
622   GstFormat format;
623   gdouble rate;
624   gint64 start, stop;
625
626   gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
627       &stop_type, &stop);
628
629   if (format != GST_FORMAT_TIME) {
630     GST_DEBUG_OBJECT (auparse, "only support seeks in TIME format");
631     return FALSE;
632   }
633
634   /* FIXME: implement seeking */
635   return FALSE;
636 }
637
638 static gboolean
639 gst_au_parse_sink_event (GstPad * pad, GstEvent * event)
640 {
641   GstAuParse *auparse;
642   gboolean ret;
643
644   auparse = GST_AU_PARSE (gst_pad_get_parent (pad));
645
646   switch (GST_EVENT_TYPE (event)) {
647     default:
648       ret = gst_pad_event_default (pad, event);
649       break;
650   }
651
652   gst_object_unref (auparse);
653   return ret;
654 }
655
656 static gboolean
657 gst_au_parse_src_event (GstPad * pad, GstEvent * event)
658 {
659   GstAuParse *auparse;
660   gboolean ret;
661
662   auparse = GST_AU_PARSE (gst_pad_get_parent (pad));
663
664   switch (GST_EVENT_TYPE (event)) {
665     case GST_EVENT_SEEK:
666       ret = gst_au_parse_handle_seek (auparse, event);
667       break;
668     default:
669       ret = gst_pad_event_default (pad, event);
670       break;
671   }
672
673   gst_object_unref (auparse);
674   return ret;
675 }
676
677 static GstStateChangeReturn
678 gst_au_parse_change_state (GstElement * element, GstStateChange transition)
679 {
680   GstAuParse *auparse = GST_AU_PARSE (element);
681   GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
682
683   ret = parent_class->change_state (element, transition);
684   if (ret == GST_STATE_CHANGE_FAILURE)
685     return ret;
686
687   switch (transition) {
688     case GST_STATE_CHANGE_PAUSED_TO_READY:
689       gst_au_parse_reset (auparse);
690     default:
691       break;
692   }
693
694   return ret;
695 }
696
697 static gboolean
698 plugin_init (GstPlugin * plugin)
699 {
700   if (!gst_element_register (plugin, "auparse", GST_RANK_SECONDARY,
701           GST_TYPE_AU_PARSE)) {
702     return FALSE;
703   }
704
705   return TRUE;
706 }
707
708 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
709     GST_VERSION_MINOR,
710     "auparse",
711     "parses au streams", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
712     GST_PACKAGE_ORIGIN)