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.
20 /* 2001/04/03 - Updated parseau to use caps nego
21 * Zaheer Merali <zaheer@grid9.net
30 #include <gstauparse.h>
32 /* elementfactory information */
33 static GstElementDetails gst_auparse_details = GST_ELEMENT_DETAILS (
36 "Parse an .au file into raw audio",
37 "Erik Walthinsen <omega@cse.ogi.edu>"
40 GST_PAD_TEMPLATE_FACTORY (sink_factory_templ,
51 GST_PAD_TEMPLATE_FACTORY (src_factory_templ,
58 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
59 "signed", GST_PROPS_LIST(
60 GST_PROPS_BOOLEAN (FALSE),
61 GST_PROPS_BOOLEAN (TRUE)
63 "width", GST_PROPS_LIST(
67 "depth", GST_PROPS_LIST(
71 "rate", GST_PROPS_INT_RANGE (8000,48000),
72 "channels", GST_PROPS_INT_RANGE (1, 2)
77 "rate", GST_PROPS_INT_RANGE (8000,48000),
78 "channels", GST_PROPS_INT_RANGE (1, 2)
82 /* AuParse signals and args */
93 static void gst_auparse_base_init (gpointer g_class);
94 static void gst_auparse_class_init (GstAuParseClass *klass);
95 static void gst_auparse_init (GstAuParse *auparse);
97 static void gst_auparse_chain (GstPad *pad,GstData *_data);
99 static GstElementClass *parent_class = NULL;
100 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
103 gst_auparse_get_type (void)
105 static GType auparse_type = 0;
108 static const GTypeInfo auparse_info = {
109 sizeof(GstAuParseClass),
110 gst_auparse_base_init,
112 (GClassInitFunc) gst_auparse_class_init,
117 (GInstanceInitFunc) gst_auparse_init,
119 auparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info, 0);
125 gst_auparse_base_init (gpointer g_class)
127 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
129 gst_element_class_add_pad_template (element_class,
130 GST_PAD_TEMPLATE_GET (sink_factory_templ));
131 gst_element_class_add_pad_template (element_class,
132 GST_PAD_TEMPLATE_GET (src_factory_templ));
133 gst_element_class_set_details (element_class, &gst_auparse_details);
138 gst_auparse_class_init (GstAuParseClass *klass)
140 GstElementClass *gstelement_class;
142 gstelement_class = (GstElementClass*) klass;
144 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
148 gst_auparse_init (GstAuParse *auparse)
150 auparse->sinkpad = gst_pad_new_from_template (
151 GST_PAD_TEMPLATE_GET (sink_factory_templ), "sink");
152 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
153 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
155 auparse->srcpad = gst_pad_new_from_template (
156 GST_PAD_TEMPLATE_GET (src_factory_templ), "src");
157 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
161 auparse->encoding = 0;
162 auparse->frequency = 0;
163 auparse->channels = 0;
167 gst_auparse_chain (GstPad *pad, GstData *_data)
169 GstBuffer *buf = GST_BUFFER (_data);
177 g_return_if_fail (pad != NULL);
178 g_return_if_fail (GST_IS_PAD (pad));
179 g_return_if_fail (buf != NULL);
181 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
183 GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
184 gst_element_get_name (GST_ELEMENT (auparse)));
186 data = GST_BUFFER_DATA (buf);
187 size = GST_BUFFER_SIZE (buf);
189 /* if we haven't seen any data yet... */
190 if (auparse->size == 0) {
192 guint32 *head = (guint32 *)data;
194 /* normal format is big endian (au is a Sparc format) */
195 if (GUINT32_FROM_BE (*head) == 0x2e736e64) {
198 auparse->offset = GUINT32_FROM_BE (*head);
200 auparse->size = GUINT32_FROM_BE (*head);
202 auparse->encoding = GUINT32_FROM_BE (*head);
204 auparse->frequency = GUINT32_FROM_BE (*head);
206 auparse->channels = GUINT32_FROM_BE (*head);
209 /* and of course, someone had to invent a little endian
210 * version. Used by DEC systems. */
211 } else if (GUINT32_FROM_LE (*head) == 0x0064732E) {
215 auparse->offset = GUINT32_FROM_LE (*head);
217 auparse->size = GUINT32_FROM_LE (*head);
219 auparse->encoding = GUINT32_FROM_LE (*head);
221 auparse->frequency = GUINT32_FROM_LE (*head);
223 auparse->channels = GUINT32_FROM_LE (*head);
227 g_warning ("help, dunno what I'm looking at!\n");
228 gst_buffer_unref(buf);
232 g_print ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
233 auparse->offset,auparse->size,auparse->encoding,
234 auparse->frequency,auparse->channels);
235 GST_DEBUG ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
236 auparse->offset,auparse->size,auparse->encoding,
237 auparse->frequency,auparse->channels);
239 switch (auparse->encoding) {
256 g_warning ("help!, dont know how to deal with this format yet\n");
261 tempcaps = GST_CAPS_NEW ("auparse_src",
263 "rate", GST_PROPS_INT (auparse->frequency),
264 "channels", GST_PROPS_INT (auparse->channels));
266 tempcaps = GST_CAPS_NEW ("auparse_src",
268 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
269 "rate", GST_PROPS_INT (auparse->frequency),
270 "channels", GST_PROPS_INT (auparse->channels),
271 "depth", GST_PROPS_INT (depth),
272 "width", GST_PROPS_INT (depth),
273 "signed", GST_PROPS_BOOLEAN (sign));
276 if (gst_pad_try_set_caps (auparse->srcpad, tempcaps) <= 0) {
277 gst_buffer_unref (buf);
278 gst_element_error (GST_ELEMENT (auparse), "could not set audio caps");
282 newbuf = gst_buffer_new ();
283 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size-(auparse->offset));
284 memcpy (GST_BUFFER_DATA (newbuf), data+24, size-(auparse->offset));
285 GST_BUFFER_SIZE (newbuf) = size-(auparse->offset);
287 gst_buffer_unref (buf);
289 gst_pad_push (auparse->srcpad, GST_DATA (newbuf));
293 gst_pad_push (auparse->srcpad, GST_DATA (buf));
298 plugin_init (GstPlugin *plugin)
300 if (!gst_element_register (plugin, "auparse", GST_RANK_SECONDARY,