2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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.
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.
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.
19 /* Element-Checklist-Version: 5 */
21 /* 2001/04/03 - Updated parseau to use caps nego
22 * Zaheer Merali <zaheer@grid9.net
31 #include <gstauparse.h>
32 #include <gst/audio/audio.h>
34 /* elementfactory information */
35 static GstElementDetails gst_auparse_details =
36 GST_ELEMENT_DETAILS (".au parser",
38 "Parse an .au file into raw audio",
39 "Erik Walthinsen <omega@cse.ogi.edu>");
41 static GstStaticPadTemplate gst_auparse_sink_template =
42 GST_STATIC_PAD_TEMPLATE ("sink",
45 GST_STATIC_CAPS ("audio/x-au")
48 static GstStaticPadTemplate gst_auparse_src_template =
49 GST_STATIC_PAD_TEMPLATE ("src",
51 GST_PAD_SOMETIMES, /* FIXME: spider */
52 GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; " /* 24-bit PCM is barely supported by gstreamer actually */
53 GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS "; " /* 64-bit float is barely supported by gstreamer actually */
55 "rate = (int) [ 8000, 192000 ], "
56 "channels = (int) [ 1, 2 ]; "
58 "rate = (int) [ 8000, 192000 ], " "channels = (int) [ 1, 2 ]")
61 /* AuParse signals and args */
74 static void gst_auparse_base_init (gpointer g_class);
75 static void gst_auparse_class_init (GstAuParseClass * klass);
76 static void gst_auparse_init (GstAuParse * auparse);
78 static void gst_auparse_chain (GstPad * pad, GstData * _data);
80 static GstElementStateReturn gst_auparse_change_state (GstElement * element);
82 static GstElementClass *parent_class = NULL;
84 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
87 gst_auparse_get_type (void)
89 static GType auparse_type = 0;
92 static const GTypeInfo auparse_info = {
93 sizeof (GstAuParseClass),
94 gst_auparse_base_init,
96 (GClassInitFunc) gst_auparse_class_init,
101 (GInstanceInitFunc) gst_auparse_init,
105 g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info,
112 gst_auparse_base_init (gpointer g_class)
114 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
116 gst_element_class_add_pad_template (element_class,
117 gst_static_pad_template_get (&gst_auparse_sink_template));
118 gst_element_class_add_pad_template (element_class,
119 gst_static_pad_template_get (&gst_auparse_src_template));
120 gst_element_class_set_details (element_class, &gst_auparse_details);
125 gst_auparse_class_init (GstAuParseClass * klass)
127 GstElementClass *gstelement_class;
129 gstelement_class = (GstElementClass *) klass;
131 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
133 gstelement_class->change_state = gst_auparse_change_state;
137 gst_auparse_init (GstAuParse * auparse)
140 gst_pad_new_from_template (gst_static_pad_template_get
141 (&gst_auparse_sink_template), "sink");
142 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
143 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
145 auparse->srcpad = NULL;
146 #if 0 /* FIXME: spider */
147 gst_pad_new_from_template (gst_static_pad_template_get
148 (&gst_auparse_src_template), "src");
149 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
150 gst_pad_use_explicit_caps (auparse->srcpad);
155 auparse->encoding = 0;
156 auparse->frequency = 0;
157 auparse->channels = 0;
161 gst_auparse_chain (GstPad * pad, GstData * _data)
163 GstBuffer *buf = GST_BUFFER (_data);
168 gint law = 0, depth, ieee = 0;
170 g_return_if_fail (pad != NULL);
171 g_return_if_fail (GST_IS_PAD (pad));
172 g_return_if_fail (buf != NULL);
174 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
176 GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
177 gst_element_get_name (GST_ELEMENT (auparse)));
179 data = GST_BUFFER_DATA (buf);
180 size = GST_BUFFER_SIZE (buf);
182 /* if we haven't seen any data yet... */
183 if (auparse->size == 0) {
185 guint32 *head = (guint32 *) data;
187 /* normal format is big endian (au is a Sparc format) */
188 if (GUINT32_FROM_BE (*head) == 0x2e736e64) { /* ".snd" */
191 auparse->offset = GUINT32_FROM_BE (*head);
193 auparse->size = GUINT32_FROM_BE (*head); /* Do not trust size, could be set to -1 : unknown */
195 auparse->encoding = GUINT32_FROM_BE (*head);
197 auparse->frequency = GUINT32_FROM_BE (*head);
199 auparse->channels = GUINT32_FROM_BE (*head);
202 /* and of course, someone had to invent a little endian
203 * version. Used by DEC systems. */
204 } else if (GUINT32_FROM_LE (*head) == 0x0064732E) { /* other source say it is "dns." */
207 auparse->offset = GUINT32_FROM_LE (*head);
209 auparse->size = GUINT32_FROM_LE (*head); /* Do not trust size, could be set to -1 : unknown */
211 auparse->encoding = GUINT32_FROM_LE (*head);
213 auparse->frequency = GUINT32_FROM_LE (*head);
215 auparse->channels = GUINT32_FROM_LE (*head);
219 g_warning ("help, dunno what I'm looking at!\n");
220 gst_buffer_unref (buf);
225 ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
226 auparse->offset, auparse->size, auparse->encoding, auparse->frequency,
231 http://www.opengroup.org/public/pubs/external/auformat.html
232 http://astronomy.swin.edu.au/~pbourke/dataformats/au/
233 Solaris headers : /usr/include/audio/au.h
234 libsndfile : src/au.c
236 http://www.tsp.ece.mcgill.ca/MMSP/Documents/AudioFormats/AU/Samples.html
239 switch (auparse->encoding) {
241 case 1: /* 8-bit ISDN mu-law G.711 */
245 case 27: /* 8-bit ISDN A-law G.711 */
250 case 2: /* 8-bit linear PCM */
253 case 3: /* 16-bit linear PCM */
256 case 4: /* 24-bit linear PCM */
259 case 5: /* 32-bit linear PCM */
263 case 6: /* 32-bit IEEE floating point */
267 case 7: /* 64-bit IEEE floating point */
272 case 8: /* Fragmented sample data */
273 case 9: /* AU_ENCODING_NESTED */
275 case 10: /* DSP program */
276 case 11: /* DSP 8-bit fixed point */
277 case 12: /* DSP 16-bit fixed point */
278 case 13: /* DSP 24-bit fixed point */
279 case 14: /* DSP 32-bit fixed point */
281 case 16: /* AU_ENCODING_DISPLAY : non-audio display data */
282 case 17: /* AU_ENCODING_MULAW_SQUELCH */
284 case 18: /* 16-bit linear with emphasis */
285 case 19: /* 16-bit linear compressed (NeXT) */
286 case 20: /* 16-bit linear with emphasis and compression */
288 case 21: /* Music kit DSP commands */
289 case 22: /* Music kit DSP commands samples */
291 case 23: /* 4-bit CCITT G.721 ADPCM 32kbps -> modplug/libsndfile (compressed 8-bit mu-law) */
292 case 24: /* 8-bit CCITT G.722 ADPCM -> rtp */
293 case 25: /* 3-bit CCITT G.723.3 ADPCM 24kbps -> rtp/xine/modplug/libsndfile */
294 case 26: /* 5-bit CCITT G.723.5 ADPCM 40kbps -> rtp/xine/modplug/libsndfile */
297 GST_ELEMENT_ERROR (auparse, STREAM, FORMAT, (NULL), (NULL));
298 gst_buffer_unref (buf);
303 gst_pad_new_from_template (gst_static_pad_template_get
304 (&gst_auparse_src_template), "src");
305 gst_pad_use_explicit_caps (auparse->srcpad);
309 gst_caps_new_simple ((law == 1) ? "audio/x-mulaw" : "audio/x-alaw",
310 "rate", G_TYPE_INT, auparse->frequency, "channels", G_TYPE_INT,
311 auparse->channels, NULL);
313 tempcaps = gst_caps_new_simple ("audio/x-raw-float",
314 "width", G_TYPE_INT, depth,
315 "endianness", G_TYPE_INT,
316 auparse->le ? G_LITTLE_ENDIAN : G_BIG_ENDIAN, NULL);
318 tempcaps = gst_caps_new_simple ("audio/x-raw-int",
319 "endianness", G_TYPE_INT,
320 auparse->le ? G_LITTLE_ENDIAN : G_BIG_ENDIAN, "rate", G_TYPE_INT,
321 auparse->frequency, "channels", G_TYPE_INT, auparse->channels,
322 "depth", G_TYPE_INT, depth, "width", G_TYPE_INT, depth, "signed",
323 G_TYPE_BOOLEAN, TRUE, NULL);
326 if (!gst_pad_set_explicit_caps (auparse->srcpad, tempcaps)) {
327 gst_buffer_unref (buf);
328 gst_object_unref (GST_OBJECT (auparse->srcpad));
329 auparse->srcpad = NULL;
333 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
335 newbuf = gst_buffer_new ();
336 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size - (auparse->offset));
337 memcpy (GST_BUFFER_DATA (newbuf), data + (auparse->offset),
338 size - (auparse->offset));
339 GST_BUFFER_SIZE (newbuf) = size - (auparse->offset);
341 gst_buffer_unref (buf);
343 gst_pad_push (auparse->srcpad, GST_DATA (newbuf));
347 gst_pad_push (auparse->srcpad, GST_DATA (buf));
350 static GstElementStateReturn
351 gst_auparse_change_state (GstElement * element)
353 GstAuParse *auparse = GST_AUPARSE (element);
355 switch (GST_STATE_TRANSITION (element)) {
356 case GST_STATE_PAUSED_TO_READY:
357 if (auparse->srcpad) {
358 gst_element_remove_pad (element, auparse->srcpad);
359 auparse->srcpad = NULL;
366 if (parent_class->change_state)
367 return parent_class->change_state (element);
369 return GST_STATE_SUCCESS;
373 plugin_init (GstPlugin * plugin)
375 if (!gst_element_register (plugin, "auparse", GST_RANK_SECONDARY,
383 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
386 "parses au streams", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)