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 = {
37 "Parse an .au file into raw audio",
39 "Erik Walthinsen <omega@cse.ogi.edu>",
43 GST_PAD_TEMPLATE_FACTORY (sink_factory_templ,
55 GST_PAD_TEMPLATE_FACTORY (src_factory_templ,
62 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
63 "signed", GST_PROPS_LIST(
64 GST_PROPS_BOOLEAN (FALSE),
65 GST_PROPS_BOOLEAN (TRUE)
67 "width", GST_PROPS_LIST(
71 "depth", GST_PROPS_LIST(
75 "rate", GST_PROPS_INT_RANGE (8000,48000),
76 "channels", GST_PROPS_INT_RANGE (1, 2)
81 "rate", GST_PROPS_INT_RANGE (8000,48000),
82 "channels", GST_PROPS_INT_RANGE (1, 2)
86 /* AuParse signals and args */
97 static void gst_auparse_class_init (GstAuParseClass *klass);
98 static void gst_auparse_init (GstAuParse *auparse);
100 static void gst_auparse_chain (GstPad *pad,GstData *_data);
102 static GstElementClass *parent_class = NULL;
103 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
106 gst_auparse_get_type (void)
108 static GType auparse_type = 0;
111 static const GTypeInfo auparse_info = {
112 sizeof(GstAuParseClass), NULL,
114 (GClassInitFunc) gst_auparse_class_init,
119 (GInstanceInitFunc) gst_auparse_init,
121 auparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info, 0);
127 gst_auparse_class_init (GstAuParseClass *klass)
129 GstElementClass *gstelement_class;
131 gstelement_class = (GstElementClass*) klass;
133 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
137 gst_auparse_init (GstAuParse *auparse)
139 auparse->sinkpad = gst_pad_new_from_template (
140 GST_PAD_TEMPLATE_GET (sink_factory_templ), "sink");
141 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
142 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
144 auparse->srcpad = gst_pad_new_from_template (
145 GST_PAD_TEMPLATE_GET (src_factory_templ), "src");
146 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
150 auparse->encoding = 0;
151 auparse->frequency = 0;
152 auparse->channels = 0;
156 gst_auparse_chain (GstPad *pad, GstData *_data)
158 GstBuffer *buf = GST_BUFFER (_data);
166 g_return_if_fail (pad != NULL);
167 g_return_if_fail (GST_IS_PAD (pad));
168 g_return_if_fail (buf != NULL);
170 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
172 GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
173 gst_element_get_name (GST_ELEMENT (auparse)));
175 data = GST_BUFFER_DATA (buf);
176 size = GST_BUFFER_SIZE (buf);
178 /* if we haven't seen any data yet... */
179 if (auparse->size == 0) {
181 guint32 *head = (guint32 *)data;
183 /* normal format is big endian (au is a Sparc format) */
184 if (GUINT32_FROM_BE (*head) == 0x2e736e64) {
187 auparse->offset = GUINT32_FROM_BE (*head);
189 auparse->size = GUINT32_FROM_BE (*head);
191 auparse->encoding = GUINT32_FROM_BE (*head);
193 auparse->frequency = GUINT32_FROM_BE (*head);
195 auparse->channels = GUINT32_FROM_BE (*head);
198 /* and of course, someone had to invent a little endian
199 * version. Used by DEC systems. */
200 } else if (GUINT32_FROM_LE (*head) == 0x0064732E) {
204 auparse->offset = GUINT32_FROM_LE (*head);
206 auparse->size = GUINT32_FROM_LE (*head);
208 auparse->encoding = GUINT32_FROM_LE (*head);
210 auparse->frequency = GUINT32_FROM_LE (*head);
212 auparse->channels = GUINT32_FROM_LE (*head);
216 g_warning ("help, dunno what I'm looking at!\n");
217 gst_buffer_unref(buf);
221 g_print ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
222 auparse->offset,auparse->size,auparse->encoding,
223 auparse->frequency,auparse->channels);
224 GST_DEBUG ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
225 auparse->offset,auparse->size,auparse->encoding,
226 auparse->frequency,auparse->channels);
228 switch (auparse->encoding) {
245 g_warning ("help!, dont know how to deal with this format yet\n");
250 tempcaps = GST_CAPS_NEW ("auparse_src",
252 "rate", GST_PROPS_INT (auparse->frequency),
253 "channels", GST_PROPS_INT (auparse->channels));
255 tempcaps = GST_CAPS_NEW ("auparse_src",
257 "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
258 "rate", GST_PROPS_INT (auparse->frequency),
259 "channels", GST_PROPS_INT (auparse->channels),
260 "depth", GST_PROPS_INT (depth),
261 "width", GST_PROPS_INT (depth),
262 "signed", GST_PROPS_BOOLEAN (sign));
265 if (gst_pad_try_set_caps (auparse->srcpad, tempcaps) <= 0) {
266 gst_buffer_unref (buf);
267 gst_element_error (GST_ELEMENT (auparse), "could not set audio caps");
271 newbuf = gst_buffer_new ();
272 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size-(auparse->offset));
273 memcpy (GST_BUFFER_DATA (newbuf), data+24, size-(auparse->offset));
274 GST_BUFFER_SIZE (newbuf) = size-(auparse->offset);
276 gst_buffer_unref (buf);
278 gst_pad_push (auparse->srcpad, GST_DATA (newbuf));
282 gst_pad_push (auparse->srcpad, GST_DATA (buf));
287 plugin_init (GModule *module, GstPlugin *plugin)
289 GstElementFactory *factory;
291 /* create the plugin structure */
292 /* create an elementfactory for the auparse element and list it */
293 factory = gst_element_factory_new ("auparse", GST_TYPE_AUPARSE,
294 &gst_auparse_details);
295 g_return_val_if_fail (factory != NULL, FALSE);
296 gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_SECONDARY);
298 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_factory_templ));
299 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_factory_templ));
301 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
306 GstPluginDesc plugin_desc = {