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