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",
52 GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
54 "rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ]")
57 /* AuParse signals and args */
70 static void gst_auparse_base_init (gpointer g_class);
71 static void gst_auparse_class_init (GstAuParseClass * klass);
72 static void gst_auparse_init (GstAuParse * auparse);
74 static void gst_auparse_chain (GstPad * pad, GstData * _data);
76 static GstElementClass *parent_class = NULL;
78 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
81 gst_auparse_get_type (void)
83 static GType auparse_type = 0;
86 static const GTypeInfo auparse_info = {
87 sizeof (GstAuParseClass),
88 gst_auparse_base_init,
90 (GClassInitFunc) gst_auparse_class_init,
95 (GInstanceInitFunc) gst_auparse_init,
98 g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info,
105 gst_auparse_base_init (gpointer g_class)
107 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
109 gst_element_class_add_pad_template (element_class,
110 gst_static_pad_template_get (&gst_auparse_sink_template));
111 gst_element_class_add_pad_template (element_class,
112 gst_static_pad_template_get (&gst_auparse_src_template));
113 gst_element_class_set_details (element_class, &gst_auparse_details);
118 gst_auparse_class_init (GstAuParseClass * klass)
120 GstElementClass *gstelement_class;
122 gstelement_class = (GstElementClass *) klass;
124 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
128 gst_auparse_init (GstAuParse * auparse)
131 gst_pad_new_from_template (gst_static_pad_template_get
132 (&gst_auparse_sink_template), "sink");
133 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
134 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
137 gst_pad_new_from_template (gst_static_pad_template_get
138 (&gst_auparse_src_template), "src");
139 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
140 gst_pad_use_explicit_caps (auparse->srcpad);
144 auparse->encoding = 0;
145 auparse->frequency = 0;
146 auparse->channels = 0;
150 gst_auparse_chain (GstPad * pad, GstData * _data)
152 GstBuffer *buf = GST_BUFFER (_data);
160 g_return_if_fail (pad != NULL);
161 g_return_if_fail (GST_IS_PAD (pad));
162 g_return_if_fail (buf != NULL);
164 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
166 GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
167 gst_element_get_name (GST_ELEMENT (auparse)));
169 data = GST_BUFFER_DATA (buf);
170 size = GST_BUFFER_SIZE (buf);
172 /* if we haven't seen any data yet... */
173 if (auparse->size == 0) {
175 guint32 *head = (guint32 *) data;
177 /* normal format is big endian (au is a Sparc format) */
178 if (GUINT32_FROM_BE (*head) == 0x2e736e64) {
181 auparse->offset = GUINT32_FROM_BE (*head);
183 auparse->size = GUINT32_FROM_BE (*head);
185 auparse->encoding = GUINT32_FROM_BE (*head);
187 auparse->frequency = GUINT32_FROM_BE (*head);
189 auparse->channels = GUINT32_FROM_BE (*head);
192 /* and of course, someone had to invent a little endian
193 * version. Used by DEC systems. */
194 } else if (GUINT32_FROM_LE (*head) == 0x0064732E) {
198 auparse->offset = GUINT32_FROM_LE (*head);
200 auparse->size = GUINT32_FROM_LE (*head);
202 auparse->encoding = GUINT32_FROM_LE (*head);
204 auparse->frequency = GUINT32_FROM_LE (*head);
206 auparse->channels = GUINT32_FROM_LE (*head);
210 g_warning ("help, dunno what I'm looking at!\n");
211 gst_buffer_unref (buf);
216 ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
217 auparse->offset, auparse->size, auparse->encoding, auparse->frequency,
220 ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
221 auparse->offset, auparse->size, auparse->encoding, auparse->frequency,
224 switch (auparse->encoding) {
241 g_warning ("help!, dont know how to deal with this format yet\n");
246 tempcaps = gst_caps_new_simple ("audio/x-alaw",
247 "rate", G_TYPE_INT, auparse->frequency,
248 "channels", G_TYPE_INT, auparse->channels, NULL);
250 tempcaps = gst_caps_new_simple ("audio/x-raw-int",
251 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
252 "rate", G_TYPE_INT, auparse->frequency,
253 "channels", G_TYPE_INT, auparse->channels,
254 "depth", G_TYPE_INT, depth,
255 "width", G_TYPE_INT, depth, "signed", G_TYPE_BOOLEAN, sign, NULL);
258 if (!gst_pad_set_explicit_caps (auparse->srcpad, tempcaps)) {
259 gst_buffer_unref (buf);
263 newbuf = gst_buffer_new ();
264 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size - (auparse->offset));
265 memcpy (GST_BUFFER_DATA (newbuf), data + 24, size - (auparse->offset));
266 GST_BUFFER_SIZE (newbuf) = size - (auparse->offset);
268 gst_buffer_unref (buf);
270 gst_pad_push (auparse->srcpad, GST_DATA (newbuf));
274 gst_pad_push (auparse->srcpad, GST_DATA (buf));
279 plugin_init (GstPlugin * plugin)
281 if (!gst_element_register (plugin, "auparse", GST_RANK_SECONDARY,
289 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
292 "parses au streams", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)