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
27 #include <gstauparse.h>
30 /* elementfactory information */
31 static GstElementDetails gst_auparse_details = {
34 "Parse an .au file into raw audio",
36 "Erik Walthinsen <omega@cse.ogi.edu>",
41 au_typefind (GstBuffer *buf, gpointer private)
44 gulong *head = (gulong *) GST_BUFFER_DATA (buf);
46 if (*head == 0x2e736e64 || *head == 0x646e732e)
47 new = gst_caps_new ("au_typefind", "audio/au", NULL);
52 /* typefactory for 'au' */
53 static GstTypeDefinition audefinition = {
60 GST_PADTEMPLATE_FACTORY (sink_factory_templ,
72 GST_PADTEMPLATE_FACTORY (src_factory_templ,
79 "format", GST_PROPS_STRING ("int"),
80 "law", GST_PROPS_INT_RANGE (0, 1),
81 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
82 "signed", GST_PROPS_LIST(
83 GST_PROPS_BOOLEAN (FALSE),
84 GST_PROPS_BOOLEAN (TRUE)
86 "width", GST_PROPS_LIST(
90 "depth", GST_PROPS_LIST(
94 "rate", GST_PROPS_INT_RANGE (8000,48000),
95 "channels", GST_PROPS_INT_RANGE (1, 2)
99 /* AuParse signals and args */
110 static void gst_auparse_class_init (GstAuParseClass *klass);
111 static void gst_auparse_init (GstAuParse *auparse);
113 static void gst_auparse_chain (GstPad *pad,GstBuffer *buf);
115 static GstElementClass *parent_class = NULL;
116 /*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
119 gst_auparse_get_type (void)
121 static GType auparse_type = 0;
124 static const GTypeInfo auparse_info = {
125 sizeof(GstAuParseClass), NULL,
127 (GClassInitFunc) gst_auparse_class_init,
132 (GInstanceInitFunc) gst_auparse_init,
134 auparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info, 0);
140 gst_auparse_class_init (GstAuParseClass *klass)
142 GstElementClass *gstelement_class;
144 gstelement_class = (GstElementClass*) klass;
146 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
150 gst_auparse_init (GstAuParse *auparse)
152 auparse->sinkpad = gst_pad_new_from_template (
153 GST_PADTEMPLATE_GET (sink_factory_templ), "sink");
154 gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
155 gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
157 auparse->srcpad = gst_pad_new_from_template (
158 GST_PADTEMPLATE_GET (src_factory_templ), "src");
159 gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
163 auparse->encoding = 0;
164 auparse->frequency = 0;
165 auparse->channels = 0;
169 gst_auparse_chain (GstPad *pad, GstBuffer *buf)
178 g_return_if_fail (pad != NULL);
179 g_return_if_fail (GST_IS_PAD (pad));
180 g_return_if_fail (buf != NULL);
182 auparse = GST_AUPARSE (gst_pad_get_parent (pad));
184 GST_DEBUG (0, "gst_auparse_chain: got buffer in '%s'",
185 gst_element_get_name (GST_ELEMENT (auparse)));
187 data = GST_BUFFER_DATA (buf);
188 size = GST_BUFFER_SIZE (buf);
190 /* if we haven't seen any data yet... */
191 if (auparse->size == 0) {
193 gulong *head = (gulong *)data;
195 /* normal format is big endian (au is a Sparc format) */
196 if (GULONG_FROM_BE (*(head++)) == 0x2e736e64) {
198 auparse->offset = GULONG_FROM_BE (*(head++));
199 auparse->size = GULONG_FROM_BE (*(head++));
200 auparse->encoding = GULONG_FROM_BE (*(head++));
201 auparse->frequency = GULONG_FROM_BE (*(head++));
202 auparse->channels = GULONG_FROM_BE (*(head++));
204 /* but I wouldn't be surprised by a little endian version */
205 } else if (GULONG_FROM_LE (*(head++)) == 0x2e736e64) {
207 auparse->offset = GULONG_FROM_LE(*(head++));
208 auparse->size = GULONG_FROM_LE(*(head++));
209 auparse->encoding = GULONG_FROM_LE(*(head++));
210 auparse->frequency = GULONG_FROM_LE(*(head++));
211 auparse->channels = GULONG_FROM_LE(*(head++));
214 g_warning ("help, dunno what I'm looking at!\n");
215 gst_buffer_unref(buf);
219 g_print ("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
220 auparse->offset,auparse->size,auparse->encoding,
221 auparse->frequency,auparse->channels);
222 GST_DEBUG (0, "offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
223 auparse->offset,auparse->size,auparse->encoding,
224 auparse->frequency,auparse->channels);
226 switch (auparse->encoding) {
243 g_warning ("help!, dont know how to deal with this format yet\n");
247 tempcaps = GST_CAPS_NEW ("auparse_src",
249 "format", GST_PROPS_STRING ("int"),
250 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
251 "rate", GST_PROPS_INT (auparse->frequency),
252 "channels", GST_PROPS_INT (auparse->channels),
253 "law", GST_PROPS_INT (law),
254 "depth", GST_PROPS_INT (depth),
255 "width", GST_PROPS_INT (depth),
256 "signed", GST_PROPS_BOOLEAN (sign));
258 if (!gst_pad_try_set_caps (auparse->srcpad, tempcaps)) {
259 gst_buffer_unref (buf);
260 gst_element_error (GST_ELEMENT (auparse), "could not set audio caps");
264 newbuf = gst_buffer_new ();
265 GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size-(auparse->offset));
266 memcpy (GST_BUFFER_DATA (newbuf), data+24, size-(auparse->offset));
267 GST_BUFFER_SIZE (newbuf) = size-(auparse->offset);
269 gst_buffer_unref (buf);
271 gst_pad_push (auparse->srcpad, newbuf);
275 gst_pad_push (auparse->srcpad, buf);
280 plugin_init (GModule *module, GstPlugin *plugin)
282 GstElementFactory *factory;
283 GstTypeFactory *type;
285 /* create the plugin structure */
286 /* create an elementfactory for the auparse element and list it */
287 factory = gst_elementfactory_new ("auparse", GST_TYPE_AUPARSE,
288 &gst_auparse_details);
289 g_return_val_if_fail (factory != NULL, FALSE);
291 gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (sink_factory_templ));
292 gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (src_factory_templ));
294 type = gst_typefactory_new (&audefinition);
296 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
297 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
302 GstPluginDesc plugin_desc = {