2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:22:05 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2004-01-27 09:00:01 +00:00
|
|
|
/* Element-Checklist-Version: 5 */
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* 2001/04/03 - Updated parseau to use caps nego
|
|
|
|
* Zaheer Merali <zaheer@grid9.net
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:22:05 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
#include <gstauparse.h>
|
2003-12-22 01:47:09 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_auparse_details =
|
|
|
|
GST_ELEMENT_DETAILS (".au parser",
|
|
|
|
"Codec/Parser/Audio",
|
|
|
|
"Parse an .au file into raw audio",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_auparse_sink_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-au")
|
|
|
|
);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_auparse_src_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
|
2004-03-15 19:32:27 +00:00
|
|
|
"audio/x-alaw, "
|
|
|
|
"rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
/* AuParse signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:22:05 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:22:05 +00:00
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_auparse_base_init (gpointer g_class);
|
|
|
|
static void gst_auparse_class_init (GstAuParseClass * klass);
|
|
|
|
static void gst_auparse_init (GstAuParse * auparse);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_auparse_chain (GstPad * pad, GstData * _data);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-19 04:10:05 +00:00
|
|
|
/*static guint gst_auparse_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_auparse_get_type (void)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2002-02-17 02:06:04 +00:00
|
|
|
static GType auparse_type = 0;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
if (!auparse_type) {
|
|
|
|
static const GTypeInfo auparse_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstAuParseClass),
|
2003-11-01 01:32:29 +00:00
|
|
|
gst_auparse_base_init,
|
2001-12-22 23:22:05 +00:00
|
|
|
NULL,
|
2002-02-17 02:06:04 +00:00
|
|
|
(GClassInitFunc) gst_auparse_class_init,
|
2001-12-22 23:22:05 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstAuParse),
|
2001-12-22 23:22:05 +00:00
|
|
|
0,
|
2002-02-17 02:06:04 +00:00
|
|
|
(GInstanceInitFunc) gst_auparse_init,
|
2001-12-22 23:22:05 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstAuParse", &auparse_info,
|
|
|
|
0);
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
2002-02-17 02:06:04 +00:00
|
|
|
return auparse_type;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2003-11-01 01:32:29 +00:00
|
|
|
static void
|
|
|
|
gst_auparse_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&gst_auparse_sink_template));
|
2003-11-01 01:32:29 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&gst_auparse_src_template));
|
2003-11-01 01:32:29 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_auparse_details);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:22:05 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_auparse_class_init (GstAuParseClass * klass)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_auparse_init (GstAuParse * auparse)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_auparse_sink_template), "sink");
|
2002-02-17 02:06:04 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (auparse), auparse->sinkpad);
|
|
|
|
gst_pad_set_chain_function (auparse->sinkpad, gst_auparse_chain);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_auparse_src_template), "src");
|
2002-02-17 02:06:04 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (auparse), auparse->srcpad);
|
2004-01-02 07:09:23 +00:00
|
|
|
gst_pad_use_explicit_caps (auparse->srcpad);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse->offset = 0;
|
|
|
|
auparse->size = 0;
|
|
|
|
auparse->encoding = 0;
|
|
|
|
auparse->frequency = 0;
|
|
|
|
auparse->channels = 0;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_auparse_chain (GstPad * pad, GstData * _data)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2003-10-08 16:08:18 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2002-02-17 02:06:04 +00:00
|
|
|
GstAuParse *auparse;
|
2001-12-22 23:22:05 +00:00
|
|
|
gchar *data;
|
|
|
|
glong size;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstCaps *tempcaps;
|
2002-01-13 22:27:25 +00:00
|
|
|
gint law, depth;
|
|
|
|
gboolean sign;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse = GST_AUPARSE (gst_pad_get_parent (pad));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_auparse_chain: got buffer in '%s'",
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (auparse)));
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
data = GST_BUFFER_DATA (buf);
|
|
|
|
size = GST_BUFFER_SIZE (buf);
|
|
|
|
|
|
|
|
/* if we haven't seen any data yet... */
|
2002-02-17 02:06:04 +00:00
|
|
|
if (auparse->size == 0) {
|
2001-12-22 23:22:05 +00:00
|
|
|
GstBuffer *newbuf;
|
2004-03-14 22:34:33 +00:00
|
|
|
guint32 *head = (guint32 *) data;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* normal format is big endian (au is a Sparc format) */
|
2003-04-07 18:43:20 +00:00
|
|
|
if (GUINT32_FROM_BE (*head) == 0x2e736e64) {
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse->le = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->offset = GUINT32_FROM_BE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->size = GUINT32_FROM_BE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->encoding = GUINT32_FROM_BE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->frequency = GUINT32_FROM_BE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->channels = GUINT32_FROM_BE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
/* and of course, someone had to invent a little endian
|
|
|
|
* version. Used by DEC systems. */
|
2003-05-20 21:19:42 +00:00
|
|
|
} else if (GUINT32_FROM_LE (*head) == 0x0064732E) {
|
2002-02-17 02:06:04 +00:00
|
|
|
auparse->le = 1;
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
|
|
|
auparse->le = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->offset = GUINT32_FROM_LE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->size = GUINT32_FROM_LE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->encoding = GUINT32_FROM_LE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->frequency = GUINT32_FROM_LE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2004-03-14 22:34:33 +00:00
|
|
|
auparse->channels = GUINT32_FROM_LE (*head);
|
2002-04-06 03:40:14 +00:00
|
|
|
head++;
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
g_warning ("help, dunno what I'm looking at!\n");
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_buffer_unref (buf);
|
2001-12-22 23:22:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_print
|
2004-03-15 19:32:27 +00:00
|
|
|
("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld\n",
|
|
|
|
auparse->offset, auparse->size, auparse->encoding, auparse->frequency,
|
|
|
|
auparse->channels);
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG
|
2004-03-15 19:32:27 +00:00
|
|
|
("offset %ld, size %ld, encoding %ld, frequency %ld, channels %ld",
|
|
|
|
auparse->offset, auparse->size, auparse->encoding, auparse->frequency,
|
|
|
|
auparse->channels);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
switch (auparse->encoding) {
|
2001-12-22 23:22:05 +00:00
|
|
|
case 1:
|
2004-03-15 19:32:27 +00:00
|
|
|
law = 1;
|
|
|
|
depth = 8;
|
|
|
|
sign = FALSE;
|
|
|
|
break;
|
2001-12-22 23:22:05 +00:00
|
|
|
case 2:
|
2004-03-15 19:32:27 +00:00
|
|
|
law = 0;
|
|
|
|
depth = 8;
|
|
|
|
sign = FALSE;
|
|
|
|
break;
|
2001-12-22 23:22:05 +00:00
|
|
|
case 3:
|
2004-03-15 19:32:27 +00:00
|
|
|
law = 0;
|
|
|
|
depth = 16;
|
|
|
|
sign = TRUE;
|
|
|
|
break;
|
2001-12-22 23:22:05 +00:00
|
|
|
default:
|
2004-03-15 19:32:27 +00:00
|
|
|
g_warning ("help!, dont know how to deal with this format yet\n");
|
|
|
|
return;
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
if (law) {
|
2003-12-22 01:47:09 +00:00
|
|
|
tempcaps = gst_caps_new_simple ("audio/x-alaw",
|
2004-03-15 19:32:27 +00:00
|
|
|
"rate", G_TYPE_INT, auparse->frequency,
|
|
|
|
"channels", G_TYPE_INT, auparse->channels, NULL);
|
2003-07-06 20:49:52 +00:00
|
|
|
} else {
|
2003-12-22 01:47:09 +00:00
|
|
|
tempcaps = gst_caps_new_simple ("audio/x-raw-int",
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
|
|
|
|
"rate", G_TYPE_INT, auparse->frequency,
|
|
|
|
"channels", G_TYPE_INT, auparse->channels,
|
|
|
|
"depth", G_TYPE_INT, depth,
|
|
|
|
"width", G_TYPE_INT, depth, "signed", G_TYPE_BOOLEAN, sign, NULL);
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2004-01-02 07:09:23 +00:00
|
|
|
if (!gst_pad_set_explicit_caps (auparse->srcpad, tempcaps)) {
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
return;
|
|
|
|
}
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
newbuf = gst_buffer_new ();
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_DATA (newbuf) = (gpointer) malloc (size - (auparse->offset));
|
|
|
|
memcpy (GST_BUFFER_DATA (newbuf), data + 24, size - (auparse->offset));
|
|
|
|
GST_BUFFER_SIZE (newbuf) = size - (auparse->offset);
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (auparse->srcpad, GST_DATA (newbuf));
|
2001-12-22 23:22:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (auparse->srcpad, GST_DATA (buf));
|
2001-12-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:22:05 +00:00
|
|
|
{
|
2003-11-01 01:32:29 +00:00
|
|
|
if (!gst_element_register (plugin, "auparse", GST_RANK_SECONDARY,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_AUPARSE)) {
|
2003-11-01 01:32:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-22 23:22:05 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"auparse",
|
|
|
|
"parses au streams", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)
|