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>
33 /* elementfactory information */
34 static GstElementDetails gst_auparse_details = {
38 "Parse an .au file into raw audio",
40 "Erik Walthinsen <omega@cse.ogi.edu>",
45 au_type_find (GstBuffer *buf, gpointer private)
48 gulong *head = (gulong *) GST_BUFFER_DATA (buf);
50 if (GST_BUFFER_SIZE (buf) < 4)
53 if (*head == 0x2e736e64 || *head == 0x646e732e)
54 new = gst_caps_new ("au_type_find", "audio/x-au", NULL);
59 /* typefactory for 'au' */
60 static GstTypeDefinition audefinition = {
67 GST_PAD_TEMPLATE_FACTORY (sink_factory_templ,
79 GST_PAD_TEMPLATE_FACTORY (src_factory_templ,
86 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
87 "signed", GST_PROPS_LIST(
88 GST_PROPS_BOOLEAN (FALSE),
89 GST_PROPS_BOOLEAN (TRUE)
91 "width", GST_PROPS_LIST(
95 "depth", GST_PROPS_LIST(
99 "rate", GST_PROPS_INT_RANGE (8000,48000),
100 "channels", GST_PROPS_INT_RANGE (1, 2)
105 "rate", GST_PROPS_INT_RANGE (8000,48000),
106 "channels", GST_PROPS_INT_RANGE (1, 2)
110 /* AuParse signals and args */
121 static void gst_auparse_class_init (GstAuParseClass *klass);
122 static void gst_auparse_init (GstAuParse *auparse);
124 static void gst_auparse_chain (GstPad *pad,GstBuffer *buf);
126 static GstElementClass *parent_class = NULL;
127 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
130 gst_auparse_get_type (void)
132 static GType auparse_type = 0;
135 static const GTypeInfo auparse_info = {
136 sizeof(GstAuParseClass), NULL,
138 (GClassInitFunc) gst_auparse_class_init,
143 (GInstanceInitFunc) gst_auparse_init,
145 auparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info, 0);
151 gst_auparse_class_init (GstAuParseClass *klass)
153 GstElementClass *gstelement_class;
155 gstelement_class = (GstElementClass*) klass;
157 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
161 gst_auparse_init (GstAuParse *auparse)
163 auparse->sinkpad = gst_pad_new_from_template (
164 GST_PAD_TEMPLATE_GET (sink_factory_templ), "sink");
165 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
166 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
168 auparse->srcpad = gst_pad_new_from_template (
169 GST_PAD_TEMPLATE_GET (src_factory_templ), "src");
170 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
174 auparse->encoding = 0;
175 auparse->frequency = 0;
176 auparse->channels = 0;
180 gst_auparse_chain (GstPad *pad, GstBuffer *buf)
189 g_return_if_fail (pad != NULL);
190 g_return_if_fail (GST_IS_PAD (pad));
191 g_return_if_fail (buf != NULL);
193 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
195 GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
196 gst_element_get_name (GST_ELEMENT (auparse)));
198 data = GST_BUFFER_DATA (buf);
199 size = GST_BUFFER_SIZE (buf);
201 /* if we haven't seen any data yet... */
202 if (auparse->size == 0) {
204 guint32 *head = (guint32 *)data;
206 /* normal format is big endian (au is a Sparc format) */
207 if (GUINT32_FROM_BE (*head) == 0x2e736e64) {
210 auparse->offset = GUINT32_FROM_BE (*head);
212 auparse->size = GUINT32_FROM_BE (*head);
214 auparse->encoding = GUINT32_FROM_BE (*head);
216 auparse->frequency = GUINT32_FROM_BE (*head);
218 auparse->channels = GUINT32_FROM_BE (*head);
221 /* and of course, someone had to invent a little endian
222 * version. Used by DEC systems. */
223 } else if (GUINT32_FROM_LE (*head) == 0x0064732E) {
227 auparse->offset = GUINT32_FROM_LE (*head);
229 auparse->size = GUINT32_FROM_LE (*head);
231 auparse->encoding = GUINT32_FROM_LE (*head);
233 auparse->frequency = GUINT32_FROM_LE (*head);
235 auparse->channels = GUINT32_FROM_LE (*head);
239 g_warning ("help, dunno what I'm looking at!\n");
240 gst_buffer_unref(buf);
244 g_print ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
245 auparse->offset,auparse->size,auparse->encoding,
246 auparse->frequency,auparse->channels);
247 GST_DEBUG ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
248 auparse->offset,auparse->size,auparse->encoding,
249 auparse->frequency,auparse->channels);
251 switch (auparse->encoding) {
268 g_warning ("help!, dont know how to deal with this format yet\n");
273 tempcaps = GST_CAPS_NEW ("auparse_src",
275 "rate", GST_PROPS_INT (auparse->frequency),
276 "channels", GST_PROPS_INT (auparse->channels));
278 tempcaps = GST_CAPS_NEW ("auparse_src",
280 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
281 "rate", GST_PROPS_INT (auparse->frequency),
282 "channels", GST_PROPS_INT (auparse->channels),
283 "depth", GST_PROPS_INT (depth),
284 "width", GST_PROPS_INT (depth),
285 "signed", GST_PROPS_BOOLEAN (sign));
288 if (gst_pad_try_set_caps (auparse->srcpad, tempcaps) <= 0) {
289 gst_buffer_unref (buf);
290 gst_element_gerror(GST_ELEMENT (auparse), GST_ERROR_UNKNOWN,
291 g_strdup ("unconverted error, file a bug"),
292 g_strdup_printf("could not set audio caps"));
296 newbuf = gst_buffer_new ();
297 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size-(auparse->offset));
298 memcpy (GST_BUFFER_DATA (newbuf), data+24, size-(auparse->offset));
299 GST_BUFFER_SIZE (newbuf) = size-(auparse->offset);
301 gst_buffer_unref (buf);
303 gst_pad_push (auparse->srcpad, newbuf);
307 gst_pad_push (auparse->srcpad, buf);
312 plugin_init (GModule *module, GstPlugin *plugin)
314 GstElementFactory *factory;
315 GstTypeFactory *type;
317 /* create the plugin structure */
318 /* create an elementfactory for the auparse element and list it */
319 factory = gst_element_factory_new ("auparse", GST_TYPE_AUPARSE,
320 &gst_auparse_details);
321 g_return_val_if_fail (factory != NULL, FALSE);
322 gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_SECONDARY);
324 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_factory_templ));
325 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_factory_templ));
327 type = gst_type_factory_new (&audefinition);
329 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
330 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
335 GstPluginDesc plugin_desc = {