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 (*head == 0x2e736e64 || *head == 0x646e732e)
51 new = gst_caps_new ("au_type_find", "audio/au", NULL);
56 /* typefactory for 'au' */
57 static GstTypeDefinition audefinition = {
64 GST_PAD_TEMPLATE_FACTORY (sink_factory_templ,
76 GST_PAD_TEMPLATE_FACTORY (src_factory_templ,
83 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
84 "signed", GST_PROPS_LIST(
85 GST_PROPS_BOOLEAN (FALSE),
86 GST_PROPS_BOOLEAN (TRUE)
88 "width", GST_PROPS_LIST(
92 "depth", GST_PROPS_LIST(
96 "rate", GST_PROPS_INT_RANGE (8000,48000),
97 "channels", GST_PROPS_INT_RANGE (1, 2)
102 "rate", GST_PROPS_INT_RANGE (8000,48000),
103 "channels", GST_PROPS_INT_RANGE (1, 2)
107 /* AuParse signals and args */
118 static void gst_auparse_class_init (GstAuParseClass *klass);
119 static void gst_auparse_init (GstAuParse *auparse);
121 static void gst_auparse_chain (GstPad *pad,GstBuffer *buf);
123 static GstElementClass *parent_class = NULL;
124 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
127 gst_auparse_get_type (void)
129 static GType auparse_type = 0;
132 static const GTypeInfo auparse_info = {
133 sizeof(GstAuParseClass), NULL,
135 (GClassInitFunc) gst_auparse_class_init,
140 (GInstanceInitFunc) gst_auparse_init,
142 auparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info, 0);
148 gst_auparse_class_init (GstAuParseClass *klass)
150 GstElementClass *gstelement_class;
152 gstelement_class = (GstElementClass*) klass;
154 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
158 gst_auparse_init (GstAuParse *auparse)
160 auparse->sinkpad = gst_pad_new_from_template (
161 GST_PAD_TEMPLATE_GET (sink_factory_templ), "sink");
162 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
163 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
165 auparse->srcpad = gst_pad_new_from_template (
166 GST_PAD_TEMPLATE_GET (src_factory_templ), "src");
167 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
171 auparse->encoding = 0;
172 auparse->frequency = 0;
173 auparse->channels = 0;
177 gst_auparse_chain (GstPad *pad, GstBuffer *buf)
186 g_return_if_fail (pad != NULL);
187 g_return_if_fail (GST_IS_PAD (pad));
188 g_return_if_fail (buf != NULL);
190 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
192 GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
193 gst_element_get_name (GST_ELEMENT (auparse)));
195 data = GST_BUFFER_DATA (buf);
196 size = GST_BUFFER_SIZE (buf);
198 /* if we haven't seen any data yet... */
199 if (auparse->size == 0) {
201 guint32 *head = (guint32 *)data;
203 /* normal format is big endian (au is a Sparc format) */
204 if (GUINT32_FROM_BE (*head) == 0x2e736e64) {
207 auparse->offset = GUINT32_FROM_BE (*head);
209 auparse->size = GUINT32_FROM_BE (*head);
211 auparse->encoding = GUINT32_FROM_BE (*head);
213 auparse->frequency = GUINT32_FROM_BE (*head);
215 auparse->channels = GUINT32_FROM_BE (*head);
218 /* and of course, someone had to invent a little endian
219 * version. Used by DEC systems. */
220 } else if (GUINT32_FROM_LE (*head) == 0x0064732E) {
224 auparse->offset = GUINT32_FROM_LE (*head);
226 auparse->size = GUINT32_FROM_LE (*head);
228 auparse->encoding = GUINT32_FROM_LE (*head);
230 auparse->frequency = GUINT32_FROM_LE (*head);
232 auparse->channels = GUINT32_FROM_LE (*head);
236 g_warning ("help, dunno what I'm looking at!\n");
237 gst_buffer_unref(buf);
241 g_print ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
242 auparse->offset,auparse->size,auparse->encoding,
243 auparse->frequency,auparse->channels);
244 GST_DEBUG ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
245 auparse->offset,auparse->size,auparse->encoding,
246 auparse->frequency,auparse->channels);
248 switch (auparse->encoding) {
265 g_warning ("help!, dont know how to deal with this format yet\n");
270 tempcaps = GST_CAPS_NEW ("auparse_src",
272 "rate", GST_PROPS_INT (auparse->frequency),
273 "channels", GST_PROPS_INT (auparse->channels));
275 tempcaps = GST_CAPS_NEW ("auparse_src",
277 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
278 "rate", GST_PROPS_INT (auparse->frequency),
279 "channels", GST_PROPS_INT (auparse->channels),
280 "depth", GST_PROPS_INT (depth),
281 "width", GST_PROPS_INT (depth),
282 "signed", GST_PROPS_BOOLEAN (sign));
285 if (gst_pad_try_set_caps (auparse->srcpad, tempcaps) <= 0) {
286 gst_buffer_unref (buf);
287 gst_element_error (GST_ELEMENT (auparse), "could not set audio caps");
291 newbuf = gst_buffer_new ();
292 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size-(auparse->offset));
293 memcpy (GST_BUFFER_DATA (newbuf), data+24, size-(auparse->offset));
294 GST_BUFFER_SIZE (newbuf) = size-(auparse->offset);
296 gst_buffer_unref (buf);
298 gst_pad_push (auparse->srcpad, newbuf);
302 gst_pad_push (auparse->srcpad, buf);
307 plugin_init (GModule *module, GstPlugin *plugin)
309 GstElementFactory *factory;
310 GstTypeFactory *type;
312 /* create the plugin structure */
313 /* create an elementfactory for the auparse element and list it */
314 factory = gst_element_factory_new ("auparse", GST_TYPE_AUPARSE,
315 &gst_auparse_details);
316 g_return_val_if_fail (factory != NULL, FALSE);
317 gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_SECONDARY);
319 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_factory_templ));
320 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_factory_templ));
322 type = gst_type_factory_new (&audefinition);
324 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
325 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
330 GstPluginDesc plugin_desc = {