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